28 #include "../blenlib/BLI_sys_types.h"
31 #if !defined(WIN32) || defined(FREEWINDOWS)
39 # include "../blenlib/BLI_winstuff.h"
53 int len = strlen(
string);
56 string[
len + 1] =
'\0';
64 const size_t a = strlen(
str);
65 const size_t b = strlen(ext);
66 return !(
a == 0 || b == 0 || b >=
a) && (strcmp(ext,
str +
a - b) == 0);
71 unsigned int tval = *val;
72 *val = ((tval >> 24)) | ((tval << 8) & 0x00ff0000) | ((tval >> 8) & 0x0000ff00) | ((tval << 24));
77 const char *
const lfslash = strrchr(
string,
'/');
78 const char *
const lbslash = strrchr(
string,
'\\');
87 return (lfslash > lbslash) ? lfslash : lbslash;
93 return filename ? filename + 1 : path;
100 const unsigned int *pixels,
106 png_bytepp row_pointers =
NULL;
110 const int bytesperpixel = 4;
111 const int compression = 9;
114 fp = fopen(name,
"wb");
116 printf(
"%s: Cannot open file for writing '%s'\n", __func__, name);
120 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL,
NULL,
NULL);
121 if (png_ptr ==
NULL) {
122 printf(
"%s: Cannot png_create_write_struct for file: '%s'\n", __func__, name);
127 info_ptr = png_create_info_struct(png_ptr);
128 if (info_ptr ==
NULL) {
129 png_destroy_write_struct(&png_ptr, (png_infopp)
NULL);
130 printf(
"%s: Cannot png_create_info_struct for file: '%s'\n", __func__, name);
135 if (setjmp(png_jmpbuf(png_ptr))) {
136 png_destroy_write_struct(&png_ptr, &info_ptr);
137 printf(
"%s: Cannot setjmp for file: '%s'\n", __func__, name);
143 png_init_io(png_ptr, fp);
145 png_set_compression_level(png_ptr, compression);
148 png_set_IHDR(png_ptr,
155 PNG_COMPRESSION_TYPE_DEFAULT,
156 PNG_FILTER_TYPE_DEFAULT);
159 png_write_info(png_ptr, info_ptr);
161 #ifdef __LITTLE_ENDIAN__
162 png_set_swap(png_ptr);
166 row_pointers = (png_bytepp)malloc(
height *
sizeof(png_bytep));
167 if (row_pointers ==
NULL) {
168 printf(
"%s: Cannot allocate row-pointers array for file '%s'\n", __func__, name);
169 png_destroy_write_struct(&png_ptr, &info_ptr);
177 for (i = 0; i <
height; i++) {
178 row_pointers[
height - 1 - i] = (png_bytep)(
179 ((
const unsigned char *)pixels) + (i *
width) * bytesperpixel *
sizeof(
unsigned char));
183 png_write_image(png_ptr, row_pointers);
186 png_write_end(png_ptr, info_ptr);
190 png_destroy_write_struct(&png_ptr, &info_ptr);
236 for (
int i = 0; i <
context->num_read_icons; i++) {
238 const struct IconHead *read_icon_head = &read_icon_info->
head;
241 return read_icon_info;
249 const char *file_name,
256 icon_info->
head = *icon_head;
265 for (
int i = 0; i <
context->num_read_icons; i++) {
274 if (fread(r_head, 1,
sizeof(*r_head), f_src) ==
sizeof(*r_head)) {
275 #ifndef __LITTLE_ENDIAN__
294 unsigned int *pixels;
295 unsigned int pixels_size;
298 printf(
"%s: failed to read header\n", __func__);
302 pixels_size =
sizeof(
char[4]) * r_head->
icon_w * r_head->
icon_h;
303 pixels = malloc(pixels_size);
304 if (pixels ==
NULL) {
305 printf(
"%s: failed to allocate pixels\n", __func__);
309 if (fread(pixels, 1, pixels_size, f_src) != pixels_size) {
310 printf(
"%s: failed to read pixels\n", __func__);
324 f_src = fopen(file_src,
"rb");
326 printf(
"%s: failed to open '%s'\n", __func__, file_src);
337 const char *file_src,
338 unsigned int **r_pixels_canvas,
339 unsigned int *r_canvas_w,
340 unsigned int *r_canvas_h)
343 unsigned int *pixels;
348 unsigned int *pixels_canvas;
351 if (!
icon_read(file_src, &head, &pixels)) {
356 if (read_icon_info !=
NULL) {
364 if (*r_canvas_w == 0) {
371 canvas_w = *r_canvas_w;
372 canvas_h = *r_canvas_h;
373 pixels_canvas = *r_pixels_canvas;
381 unsigned int dst_x, dst_y;
382 unsigned int pixel_xy_dst;
390 pixel_xy_dst = (dst_y * canvas_w) + dst_x;
391 assert(pixel_xy_dst < (canvas_w * canvas_h));
392 pixels_canvas[pixel_xy_dst] = pixel;
409 const struct dirent *fname;
413 int found = 0, fail = 0;
417 unsigned int *pixels_canvas =
NULL;
418 unsigned int canvas_w = 0, canvas_h = 0;
423 dirn = scandir(path_src, &namelist,
NULL, alphasort);
426 "%s: failed to dir '%s', (%s)\n", __func__, path_src, errno ? strerror(errno) :
"unknown");
430 strcpy(filepath, path_src);
432 filename = &filepath[path_str_len];
435 fname = namelist[dirn];
438 strcpy(filename, fname->
d_name);
455 printf(
"%s: dir '%s' has no icons\n", __func__, path_src);
459 printf(
"%s: dir '%s' failed %d icons\n", __func__, path_src, fail);
463 write_png(file_dst, pixels_canvas, canvas_w, canvas_h);
473 int main(
int argc,
char **argv)
475 const char *path_src;
476 const char *file_dst;
479 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 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
_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
static bool icon_decode(FILE *f_src, struct IconHead *r_head, unsigned int **r_pixels)
static const char * path_slash_rfind(const char *string)
static void icon_merge_context_free(struct IconMergeContext *context)
static const char * path_basename(const char *path)
static bool icon_read(const char *file_src, struct IconHead *r_head, unsigned int **r_pixels)
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)
static void endian_switch_uint32(unsigned int *val)
int main(int argc, char **argv)
static void icon_merge_context_init(struct IconMergeContext *context)
static void icon_merge_context_register_icon(struct IconMergeContext *context, const char *file_name, struct IconHead *icon_head)
static bool icon_merge(struct IconMergeContext *context, const char *file_src, unsigned int **r_pixels_canvas, unsigned int *r_canvas_w, unsigned int *r_canvas_h)
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 write_png(const char *name, const unsigned int *pixels, const int width, const int height)
struct SELECTID_Context context
struct IconInfo * read_icons