42 ptr = (
void *)mem->stream_ptr;
43 offset = mem->stream_len;
44 memcpy(data, ptr + offset, length);
45 mem->stream_len += length;
64 int interlace, color, compres, filter, bit_depth;
65 g2int j, k, n, bytes, clen;
67 png_infop info_ptr, end_info;
68 png_bytepp row_pointers;
73 if (png_sig_cmp(pngbuf, 0, 8) != 0)
77 if (!(png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
81 if (!(info_ptr = png_create_info_struct(png_ptr)))
83 png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
87 if (!(end_info = png_create_info_struct(png_ptr)))
89 png_destroy_read_struct(&png_ptr, (png_infopp)info_ptr, (png_infopp)NULL);
94 if (setjmp(png_jmpbuf(png_ptr)))
96 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
101 read_io_ptr.stream_ptr = (png_voidp)pngbuf;
102 read_io_ptr.stream_len = 0;
105 png_set_read_fn(png_ptr, (png_voidp)&read_io_ptr, (png_rw_ptr)
user_read_data);
108 png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
111 row_pointers = png_get_rows(png_ptr, info_ptr);
116 (void)png_get_IHDR(png_ptr, info_ptr, &w32, &h32,
117 &bit_depth, &color, &interlace, &compres, &filter);
128 if (color == PNG_COLOR_TYPE_RGB)
130 else if (color == PNG_COLOR_TYPE_RGB_ALPHA)
135 bytes = bit_depth / 8;
136 clen = (*width) * bytes;
137 for (j = 0; j < *height; j++)
139 for (k = 0; k < clen; k++)
141 cout[n] = *(row_pointers[j] + k);
147 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
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...