134 double file_gamma = 1 / 2.2;
136 _MSG(
"Png_datainfo_callback:\n");
138 png = png_get_progressive_ptr(png_ptr);
141 png_get_IHDR(png_ptr, info_ptr, &png->width, &png->height,
142 &bit_depth, &color_type, &interlace_type, NULL, NULL);
145 if (png->width == 0 || png->height == 0 ||
147 MSG(
"Png_datainfo_callback: suspicious image size request %lu x %lu\n",
153 _MSG(
"Png_datainfo_callback: png->width = %lu\n"
154 "Png_datainfo_callback: png->height = %lu\n",
158 if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth <= 8) {
160 png_set_expand (png_ptr);
161 }
else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
163 png_set_expand (png_ptr);
164 }
else if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) {
166 png_set_expand(png_ptr);
167 }
else if (bit_depth < 8) {
168 png_set_expand(png_ptr);
171 if (bit_depth == 16) {
172 png_set_strip_16(png_ptr);
178 if (png_get_gAMA(png_ptr, info_ptr, &file_gamma))
179 png_set_gamma(png_ptr, 2.2, file_gamma);
182 if (color_type == PNG_COLOR_TYPE_GRAY ||
183 color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
184 png_set_gray_to_rgb(png_ptr);
188 if (interlace_type != PNG_INTERLACE_NONE) {
189 png_set_interlace_handling(png_ptr);
193 png_read_update_info(png_ptr, info_ptr);
195 png_get_IHDR(png_ptr, info_ptr, &png->width, &png->height,
196 &bit_depth, &color_type, &interlace_type, NULL, NULL);
198 png->rowbytes = png_get_rowbytes(png_ptr, info_ptr);
199 png->channels = png_get_channels(png_ptr, info_ptr);
202 _MSG(
"Png_datainfo_callback: rowbytes = %d\n"
203 "Png_datainfo_callback: width = %lu\n"
204 "Png_datainfo_callback: height = %lu\n",
207 png->image_data = (
uchar_t *)
dMalloc(png->rowbytes * png->height);
210 for (i = 0; i < png->height; i++)
211 png->row_pointers[i] = png->image_data + (i * png->rowbytes);
213 png->linebuf =
dMalloc(3 * png->width);
224 png_uint_32 row_num,
int pass)
232 _MSG(
"Png_datarow_callback: row_num = %ld\n", row_num);
234 png = png_get_progressive_ptr(png_ptr);
236 png_progressive_combine_row(png_ptr, png->row_pointers[row_num], new_row);
238 _MSG(
"png: row_num=%u previous_row=%u\n", row_num, png->previous_row);
239 if (row_num < png->previous_row) {
242 png->previous_row = row_num;
244 switch (png->channels) {
247 png->image_data + (row_num * png->rowbytes),
254 int a, bg_red, bg_green, bg_blue;
256 uchar_t *data = png->image_data + (row_num * png->rowbytes);
260 bg_blue = (png->bgcolor) & 0xFF;
261 bg_green = (png->bgcolor>>8) & 0xFF;
262 bg_red = (png->bgcolor>>16) & 0xFF;
264 for (i = 0; i < png->width; i++) {
278 png_composite(*(pl++), *(data++), a, bg_red);
279 png_composite(*(pl++), *(data++), a, bg_green);
280 png_composite(*(pl++), *(data++), a, bg_blue);
288 MSG(
"Png_datarow_callback: unexpected number of channels=%d pass=%d\n",
289 png->channels, pass);
344 png->ipbufsize = BufSize;
348 _MSG(
"State = %s\n", prog_state_name[png->state]);
350 switch (png->state) {
356 if (png_sig_cmp(png->ipbuf, 0,
DATASIZE)) {
362 png->png_ptr = png_create_read_struct(
363 PNG_LIBPNG_VER_STRING,
368 png->info_ptr = png_create_info_struct(png->png_ptr);
373 png_set_progressive_read_fn(
384 if (setjmp(png->jmpbuf)) {
386 }
else if (!png->error) {
387 png_process_data( png->png_ptr,
389 png->ipbuf + png->ipbufstart,
397 MSG_WARN(
"PNG decoder: bad state = %d\n", png->state);
void a_Dicache_set_parms(DilloUrl *url, int version, DilloImage *Image, uint_t width, uint_t height, DilloImgType type, double gamma)
Set image's width, height & type.
void a_Dicache_close(DilloUrl *url, int version, CacheClient_t *Client)
Implement the close method of the decoding process.
void a_Dicache_write(DilloUrl *url, int version, const uchar_t *buf, uint_t Y)
Implement the write method (Write a scan line into the Dicache entry) buf: row buffer Y : row number.
static void Png_write(DilloPng *png, void *Buf, uint_t BufSize)
Receive and process new chunks of PNG image data.
void * a_Png_new(DilloImage *Image, DilloUrl *url, int version)
Create the image state data that must be kept between calls.