14 #include "../blenlib/BLI_sys_types.h"
17 #if !defined(WIN32) || defined(FREEWINDOWS)
25 # include "../blenlib/BLI_winstuff.h"
39 int len = strlen(
string);
42 string[
len + 1] =
'\0';
50 const size_t a = strlen(
str);
51 const size_t b = strlen(ext);
52 return !(
a == 0 ||
b == 0 ||
b >=
a) && (strcmp(ext,
str +
a -
b) == 0);
58 *val = ((tval >> 24)) | ((tval << 8) & 0x00ff0000) | ((tval >> 8) & 0x0000ff00) | ((tval << 24));
63 const char *
const lfslash = strrchr(
string,
'/');
64 const char *
const lbslash = strrchr(
string,
'\\');
73 return (lfslash > lbslash) ? lfslash : lbslash;
79 return filename ? filename + 1 : path;
89 png_bytepp row_pointers =
NULL;
93 const int bytesperpixel = 4;
94 const int compression = 9;
97 fp = fopen(name,
"wb");
99 printf(
"%s: Cannot open file for writing '%s'\n", __func__, name);
103 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL,
NULL,
NULL);
104 if (png_ptr ==
NULL) {
105 printf(
"%s: Cannot png_create_write_struct for file: '%s'\n", __func__, name);
110 info_ptr = png_create_info_struct(png_ptr);
111 if (info_ptr ==
NULL) {
112 png_destroy_write_struct(&png_ptr, (png_infopp)
NULL);
113 printf(
"%s: Cannot png_create_info_struct for file: '%s'\n", __func__, name);
118 if (setjmp(png_jmpbuf(png_ptr))) {
119 png_destroy_write_struct(&png_ptr, &info_ptr);
120 printf(
"%s: Cannot setjmp for file: '%s'\n", __func__, name);
126 png_init_io(png_ptr, fp);
128 png_set_compression_level(png_ptr, compression);
131 png_set_IHDR(png_ptr,
138 PNG_COMPRESSION_TYPE_DEFAULT,
139 PNG_FILTER_TYPE_DEFAULT);
142 png_write_info(png_ptr, info_ptr);
144 #ifdef __LITTLE_ENDIAN__
145 png_set_swap(png_ptr);
149 row_pointers = (png_bytepp)malloc(
height *
sizeof(png_bytep));
150 if (row_pointers ==
NULL) {
151 printf(
"%s: Cannot allocate row-pointers array for file '%s'\n", __func__, name);
152 png_destroy_write_struct(&png_ptr, &info_ptr);
160 for (i = 0; i <
height; i++) {
161 row_pointers[
height - 1 - i] = (png_bytep)(((
const unsigned char *)pixels) +
162 (i *
width) * bytesperpixel *
163 sizeof(
unsigned char));
167 png_write_image(png_ptr, row_pointers);
170 png_write_end(png_ptr, info_ptr);
174 png_destroy_write_struct(&png_ptr, &info_ptr);
220 for (
int i = 0; i <
context->num_read_icons; i++) {
222 const struct IconHead *read_icon_head = &read_icon_info->
head;
225 return read_icon_info;
233 const char *file_name,
240 icon_info->
head = *icon_head;
249 for (
int i = 0; i <
context->num_read_icons; i++) {
258 if (fread(r_head, 1,
sizeof(*r_head), f_src) ==
sizeof(*r_head)) {
259 #ifndef __LITTLE_ENDIAN__
282 printf(
"%s: failed to read header\n", __func__);
286 pixels_size =
sizeof(
char[4]) * r_head->
icon_w * r_head->
icon_h;
287 pixels = malloc(pixels_size);
288 if (pixels ==
NULL) {
289 printf(
"%s: failed to allocate pixels\n", __func__);
293 if (fread(pixels, 1, pixels_size, f_src) != pixels_size) {
294 printf(
"%s: failed to read pixels\n", __func__);
308 f_src = fopen(file_src,
"rb");
310 printf(
"%s: failed to open '%s'\n", __func__, file_src);
321 const char *file_src,
335 if (!
icon_read(file_src, &head, &pixels)) {
340 if (read_icon_info !=
NULL) {
348 if (*r_canvas_w == 0) {
355 canvas_w = *r_canvas_w;
356 canvas_h = *r_canvas_h;
357 pixels_canvas = *r_pixels_canvas;
374 pixel_xy_dst = (dst_y * canvas_w) + dst_x;
375 assert(pixel_xy_dst < (canvas_w * canvas_h));
376 pixels_canvas[pixel_xy_dst] = pixel;
393 const struct dirent *fname;
397 int found = 0, fail = 0;
402 uint canvas_w = 0, canvas_h = 0;
407 dirn = scandir(path_src, &namelist,
NULL, alphasort);
410 "%s: failed to dir '%s', (%s)\n", __func__, path_src, errno ? strerror(errno) :
"unknown");
414 strcpy(filepath, path_src);
416 filename = &filepath[path_str_len];
419 fname = namelist[dirn];
422 strcpy(filename, fname->
d_name);
439 printf(
"%s: dir '%s' has no icons\n", __func__, path_src);
443 printf(
"%s: dir '%s' failed %d icons\n", __func__, path_src, fail);
447 write_png(file_dst, pixels_canvas, canvas_w, canvas_h);
457 int main(
int argc,
char **argv)
459 const char *path_src;
460 const char *file_dst;
463 printf(
"Usage: datatoc_icon <dir_icons> <data_icon_to.png>\n");
void BLI_kdtree_nd_() free(KDTree *tree)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
static bool icon_merge(struct IconMergeContext *context, const char *file_src, uint32_t **r_pixels_canvas, uint *r_canvas_w, uint *r_canvas_h)
static void endian_switch_uint32(uint *val)
static const char * path_slash_rfind(const char *string)
static void icon_merge_context_register_icon(struct IconMergeContext *context, const char *file_name, const struct IconHead *icon_head)
static void icon_merge_context_free(struct IconMergeContext *context)
static const char * path_basename(const char *path)
static bool icondir_to_png(const char *path_src, const char *file_dst)
static struct IconInfo * icon_merge_context_info_for_icon_head(struct IconMergeContext *context, struct IconHead *icon_head)
int main(int argc, char **argv)
static void icon_merge_context_init(struct IconMergeContext *context)
static int path_ensure_slash(char *string)
static bool icon_decode_head(FILE *f_src, struct IconHead *r_head)
static bool path_test_extension(const char *str, const char *ext)
static bool icon_decode(FILE *f_src, struct IconHead *r_head, uint **r_pixels)
static bool icon_read(const char *file_src, struct IconHead *r_head, uint **r_pixels)
static bool write_png(const char *name, const uint *pixels, const int width, const int height)
SyclQueue void void size_t num_bytes void
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
struct IconInfo * read_icons