26 unsigned char *stream_ptr;
51 ptr = (
void *)mem->stream_ptr;
52 offset = mem->stream_len;
54 memcpy(data, ptr + offset, length);
55 mem->stream_len += length;
73 int interlace, color, compres, filter, bit_depth;
74 g2int j, k, n, bytes, clen;
76 png_infop info_ptr, end_info;
77 png_bytepp row_pointers;
82 if (png_sig_cmp(pngbuf, 0, 8) != 0)
86 if (!(png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
90 if (!(info_ptr = png_create_info_struct(png_ptr)))
92 png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
96 if (!(end_info = png_create_info_struct(png_ptr)))
98 png_destroy_read_struct(&png_ptr, (png_infopp)info_ptr, (png_infopp)NULL);
103 if (setjmp(png_jmpbuf(png_ptr)))
105 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
110 read_io_ptr.stream_ptr = (png_voidp)pngbuf;
111 read_io_ptr.stream_len = 0;
114 png_set_read_fn(png_ptr, (png_voidp)&read_io_ptr, (png_rw_ptr)
user_read_data);
117 png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
120 row_pointers = png_get_rows(png_ptr, info_ptr);
125 (void)png_get_IHDR(png_ptr, info_ptr, &w32, &h32,
126 &bit_depth, &color, &interlace, &compres, &filter);
137 if (color == PNG_COLOR_TYPE_RGB)
139 else if (color == PNG_COLOR_TYPE_RGB_ALPHA)
144 bytes = bit_depth / 8;
145 clen = (*width) * bytes;
146 for (j = 0; j < *height; j++)
148 for (k = 0; k < clen; k++)
150 cout[n] = *(row_pointers[j] + k);
156 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
int dec_png(unsigned char *pngbuf, g2int *width, g2int *height, char *cout)
Decode PNG.
struct png_stream png_stream
Typedef for PNG stream.
void user_read_data(png_structp, png_bytep, png_uint_32)
Custom read function used so that libpng will read a PNG stream from memory instead of a file on disk...
Header file for NCEPLIBS-g2c library.
int64_t g2int
Long integer type.