75
75
* data in the provided out parameters.
78
* TRUE if successful, FALSE otherwise.
81
* Reads PNG from disk.
81
* Reads a PNG image from memory.
83
83
*----------------------------------------------------------------------------
108
memset(image, 0, sizeof *image);
107
110
pngData = Util_SafeCalloc(1, sizeof *pngData);
108
111
pngData->data = (char *) data;
109
112
pngData->offset = 0;
150
153
bytes_per_line = png_get_rowbytes(png_ptr, info_ptr);
152
155
if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
156
png_set_strip_alpha(png_ptr);
158
/* Update the bytes_per_line now that we've eliminated the alpha channel */
159
png_read_update_info(png_ptr, info_ptr);
160
bytes_per_line = png_get_rowbytes(png_ptr, info_ptr);
162
png_get_IHDR(png_ptr, info_ptr,
164
&channel_depth, &color_type, &interlace_type,
165
&compression_type, &filter_type);
157
if (pngReadFlags & IMAGE_PNG_READ_KEEP_ALPHA) {
160
png_set_strip_alpha(png_ptr);
162
/* Update the bytes_per_line now that we've eliminated the alpha channel */
163
png_read_update_info(png_ptr, info_ptr);
164
bytes_per_line = png_get_rowbytes(png_ptr, info_ptr);
166
png_get_IHDR(png_ptr, info_ptr,
168
&channel_depth, &color_type, &interlace_type,
169
&compression_type, &filter_type);
167
174
} else if (color_type == PNG_COLOR_TYPE_RGB) {
175
image->depth = image->bpp = 24;
169
176
} else if (color_type == PNG_COLOR_TYPE_PALETTE) {
176
183
bytes_per_line = png_get_rowbytes(png_ptr, info_ptr);
186
image->depth = image->bpp = 8;
181
188
png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
182
189
ASSERT(num_palette <= 256);
320
ImageUtil_ConstructPNGBufferEx(const ImageInfo *image, // IN
321
const ImagePngOptions *options, // IN
322
DynBuf *imageData) // OUT
329
ImageUtil_ConstructPNGBufferEx(const ImageInfo *image, // IN
330
const ImagePngWriteOptions *options, // IN
331
DynBuf *imageData) // OUT
324
333
png_structp png_ptr;
325
334
png_infop info_ptr;
475
484
data = Util_SafeMalloc(bytes_per_line * image->height);
477
486
Raster_ConvertPixels(data, bytes_per_line, 24,
478
image->data, image->bytesPerLine, image->depth,
487
image->data, image->bytesPerLine,
488
Raster_GetBPPDepth(image->depth, image->bpp),
479
489
FALSE, NULL, 0, 0, 0, 0,
480
490
image->width, image->height);