21 unsigned char *stream_ptr;
48 ptr = mem->stream_ptr;
49 offset = mem->stream_len;
50 memcpy(ptr + offset, data, length);
51 mem->stream_len += length;
84 g2int j, bytes, pnglen, bit_depth;
87 png_bytep **row_pointers;
91 if (!(png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
94 if (!(info_ptr = png_create_info_struct(png_ptr)))
96 png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
101 if (setjmp(png_jmpbuf(png_ptr)))
103 png_destroy_write_struct(&png_ptr, &info_ptr);
108 write_io_ptr.stream_ptr = (png_voidp)pngbuf;
109 write_io_ptr.stream_len = 0;
112 png_set_write_fn(png_ptr, (png_voidp)&write_io_ptr, (png_rw_ptr)
user_write_data,
117 color_type = PNG_COLOR_TYPE_GRAY;
121 color_type = PNG_COLOR_TYPE_RGB;
123 else if (nbits == 32)
126 color_type = PNG_COLOR_TYPE_RGB_ALPHA;
128 png_set_IHDR(png_ptr, info_ptr, width, height,
129 bit_depth, color_type, PNG_INTERLACE_NONE,
130 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
134 row_pointers = malloc(height *
sizeof(png_bytep));
135 for (j = 0; j < height; j++)
136 row_pointers[j] = (png_bytep *)(data + (j * width * bytes));
137 png_set_rows(png_ptr, info_ptr, (png_bytepp)row_pointers);
140 png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
143 png_destroy_write_struct(&png_ptr, &info_ptr);
145 pnglen = write_io_ptr.stream_len;
int enc_png(char *data, g2int width, g2int height, g2int nbits, char *pngbuf)
Encode PNG.
struct png_stream png_stream
Typedef for PNG stream.
void user_flush_data(png_structp)
Dummy Custom flush function.
void user_write_data(png_structp, png_bytep, png_uint_32)
Custom write function used to that libpng will write to memory location instead of a file on disk.
Header file for NCEPLIBS-g2c library.
int64_t g2int
Long integer type.