17 unsigned char *stream_ptr;
44 ptr = mem->stream_ptr;
45 offset = mem->stream_len;
46 memcpy(ptr + offset, data, length);
47 mem->stream_len += length;
76 unsigned char *pngbuf)
79 g2int j, bytes, pnglen, bit_depth;
82 png_bytep **row_pointers;
86 if (!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
89 if (!(info_ptr = png_create_info_struct(png_ptr)))
91 png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
96 if (setjmp(png_jmpbuf(png_ptr)))
98 png_destroy_write_struct(&png_ptr, &info_ptr);
103 write_io_ptr.stream_ptr = (png_voidp)pngbuf;
104 write_io_ptr.stream_len = 0;
107 png_set_write_fn(png_ptr, (png_voidp)&write_io_ptr, (png_rw_ptr)
user_write_data,
112 color_type = PNG_COLOR_TYPE_GRAY;
116 color_type = PNG_COLOR_TYPE_RGB;
118 else if (nbits == 32)
121 color_type = PNG_COLOR_TYPE_RGB_ALPHA;
123 png_set_IHDR(png_ptr, info_ptr, width, height,
124 bit_depth, color_type, PNG_INTERLACE_NONE,
125 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
129 row_pointers = malloc(height *
sizeof(png_bytep));
130 for (j = 0; j < height; j++)
131 row_pointers[j] = (png_bytep *)(data + (j * width * bytes));
132 png_set_rows(png_ptr, info_ptr, (png_bytepp)row_pointers);
135 png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
138 png_destroy_write_struct(&png_ptr, &info_ptr);
140 pnglen = write_io_ptr.stream_len;