annotate src/png.c @ 2104:3e7e5395f0bc

non-ASCII keybindings Alexander Voigt has kindly done some testing, and it seems that this makes bindings to most keys on a German keyboard possible -- except those that need AltGr don't work yet.
author corvid <corvid@lavabit.com>
date Thu, 23 Jun 2011 19:24:11 +0000
parents 7c7ff4d0202b
children
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 * The png decoder for Dillo. It is responsible for decoding PNG data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3 * and transferring it to the dicache.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
4 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 * Geoff Lane nov 1999 zzassgl@twirl.mcc.ac.uk
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 * Luca Rota, Jorge Arellano Cid, Eric Gaudet 2000
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
7 * Jorge Arellano Cid 2009
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 * "PNG: The Definitive Guide" by Greg Roelofs, O'Reilly
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 * ISBN 1-56592-542-4
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13 #include <config.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14 #ifdef ENABLE_PNG
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
15
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16 #include <stdlib.h> /* For abort() */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 #ifdef HAVE_LIBPNG_PNG_H
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19 #include <libpng/png.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20 #else
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21 #include <png.h>
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 #endif
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 #include "msg.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25 #include "image.hh"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 #include "cache.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 #include "dicache.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29 enum prog_state {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 IS_finished, IS_init, IS_nextdata
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31 };
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32
359
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
33 #if 0
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34 static char *prog_state_name[] =
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
36 "IS_finished", "IS_init", "IS_nextdata"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
37 };
359
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
38 #endif
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41 * This holds the data that must be saved between calls to this module.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
42 * Each time it is called it is supplied with a vector of data bytes
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43 * obtained from the web server. The module can process any amount of the
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
44 * supplied data. The next time the module is called, the vector may be
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45 * extended with additional data bytes to be processed. The module must
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46 * keep track of the current start and cursor position of the input data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 * vector. As complete output rasters are determined they are sent out of
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 * the module for additional processing.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 * NOTE: There is no external control of the splitting of the input data
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51 * vector (only this module understands PNG format data.) This means that
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52 * the complete state of a PNG image being processed must be held in the
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53 * structure below so that processing can be suspended or resumed at any
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
54 * point within an input image.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55 *
1669
92ce2288042a spelling
corvid <corvid@lavabit.com>
parents: 1563
diff changeset
56 * In the case of the libpng library, it maintains its own state in
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57 * png_ptr and into_ptr so the FSM is very simple - much simpler than the
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
58 * ones for XBM and PNM are.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
60
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
61 typedef
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
62 struct _DilloPng {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
63 DilloImage *Image; /* Image meta data */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
64 DilloUrl *url; /* Primary Key for the dicache */
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
65 int version; /* Secondary Key for the dicache */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
66
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
67 double display_exponent; /* gamma correction */
1702
341debc7a62c use png_uint_32 for png width and height
corvid <corvid@lavabit.com>
parents: 1669
diff changeset
68 png_uint_32 width; /* png image width */
341debc7a62c use png_uint_32 for png width and height
corvid <corvid@lavabit.com>
parents: 1669
diff changeset
69 png_uint_32 height; /* png image height */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
70 png_structp png_ptr; /* libpng private data */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
71 png_infop info_ptr; /* libpng private info */
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
72 uchar_t *image_data; /* decoded image data */
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
73 uchar_t **row_pointers; /* pntr to row starts */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74 jmp_buf jmpbuf; /* png error processing */
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
75 int error; /* error flag */
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 0
diff changeset
76 png_uint_32 previous_row;
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
77 int rowbytes; /* No. bytes in image row */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
78 short passes;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
79 short channels; /* No. image channels */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
81 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
82 * 0 last byte
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83 * +-------+-+-----------------------------------+-+
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84 * | | | -- data to be processed -- | |
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85 * +-------+-+-----------------------------------+-+
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86 * ^ ^ ^
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 * ipbuf ipbufstart ipbufsize
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
88 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
89
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
90 uchar_t *ipbuf; /* image data in buffer */
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
91 int ipbufstart; /* first valid image byte */
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
92 int ipbufsize; /* size of valid data in */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
93
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
94 enum prog_state state; /* FSM current state */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
95
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
96 uchar_t *linebuf; /* o/p raster data */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
97
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
98 } DilloPng;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
99
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
100 #define DATASIZE (png->ipbufsize - png->ipbufstart)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
101 #define BLACK 0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
102 #define WHITE 255
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
103
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
104
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
105 static
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
106 void Png_error_handling(png_structp png_ptr, png_const_charp msg)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
107 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
108 DilloPng *png;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
109
359
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
110 MSG("Png_error_handling: %s\n", msg);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
111 png = png_get_error_ptr(png_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
112
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
113 png->error = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
114 png->state = IS_finished;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
115
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 longjmp(png->jmpbuf, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
117 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
118
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
119 static void
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
120 Png_datainfo_callback(png_structp png_ptr, png_infop info_ptr)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
121 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
122 DilloPng *png;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
123 int color_type;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
124 int bit_depth;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
125 int interlace_type;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
126 uint_t i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
127 double gamma;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
128
359
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
129 _MSG("Png_datainfo_callback:\n");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
130
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
131 png = png_get_progressive_ptr(png_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
132 dReturn_if_fail (png != NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
133
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
134 png_get_IHDR(png_ptr, info_ptr, &png->width, &png->height,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
135 &bit_depth, &color_type, &interlace_type, NULL, NULL);
1180
e02128d96c8a Added image size sanity checks
Jorge Arellano Cid <jcid@dillo.org>
parents: 1178
diff changeset
136
e02128d96c8a Added image size sanity checks
Jorge Arellano Cid <jcid@dillo.org>
parents: 1178
diff changeset
137 /* check max image size */
1702
341debc7a62c use png_uint_32 for png width and height
corvid <corvid@lavabit.com>
parents: 1669
diff changeset
138 if (png->width == 0 || png->height == 0 ||
1202
f77f7973534e use IMAGE_MAX_AREA instead of IMAGE_MAX_W and IMAGE_MAX_H
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1199
diff changeset
139 png->width > IMAGE_MAX_AREA / png->height) {
1964
7c7ff4d0202b clearer MSG for suspicious image size
corvid <corvid@lavabit.com>
parents: 1702
diff changeset
140 MSG("Png_datainfo_callback: suspicious image size request %lu x %lu\n",
1702
341debc7a62c use png_uint_32 for png width and height
corvid <corvid@lavabit.com>
parents: 1669
diff changeset
141 (ulong_t) png->width, (ulong_t) png->height);
1178
97b68213b58e Added a limit for PNG image size
Jorge Arellano Cid <jcid@dillo.org>
parents: 1094
diff changeset
142 Png_error_handling(png_ptr, "Aborting...");
97b68213b58e Added a limit for PNG image size
Jorge Arellano Cid <jcid@dillo.org>
parents: 1094
diff changeset
143 return; /* not reached */
97b68213b58e Added a limit for PNG image size
Jorge Arellano Cid <jcid@dillo.org>
parents: 1094
diff changeset
144 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
145
1702
341debc7a62c use png_uint_32 for png width and height
corvid <corvid@lavabit.com>
parents: 1669
diff changeset
146 _MSG("Png_datainfo_callback: png->width = %lu\n"
341debc7a62c use png_uint_32 for png width and height
corvid <corvid@lavabit.com>
parents: 1669
diff changeset
147 "Png_datainfo_callback: png->height = %lu\n",
341debc7a62c use png_uint_32 for png width and height
corvid <corvid@lavabit.com>
parents: 1669
diff changeset
148 (ulong_t) png->width, (ulong_t) png->height);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
149
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
150 /* we need RGB/RGBA in the end */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
151 if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth <= 8) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
152 /* Convert indexed images to RGB */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
153 png_set_expand (png_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
154 } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
155 /* Convert grayscale to RGB */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
156 png_set_expand (png_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
157 } else if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
158 /* We have transparency header, convert it to alpha channel */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
159 png_set_expand(png_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
160 } else if (bit_depth < 8) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
161 png_set_expand(png_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
162 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
163
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
164 if (bit_depth == 16) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
165 png_set_strip_16(png_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
166 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
167
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
168 /* Get and set gamma information. Beware: gamma correction 2.2 will
368
2242da885677 - s/todo:/TODO:/g
jcid
parents: 359
diff changeset
169 only work on PC's. TODO: select screen gamma correction for other
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
170 platforms. */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
171 if (png_get_gAMA(png_ptr, info_ptr, &gamma))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
172 png_set_gamma(png_ptr, 2.2, gamma);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
173
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
174 /* Convert gray scale to RGB */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
175 if (color_type == PNG_COLOR_TYPE_GRAY ||
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
176 color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
177 png_set_gray_to_rgb(png_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
178 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
179
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
180 /* Interlaced */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
181 if (interlace_type != PNG_INTERLACE_NONE) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
182 png->passes = png_set_interlace_handling(png_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
183 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
184
1669
92ce2288042a spelling
corvid <corvid@lavabit.com>
parents: 1563
diff changeset
185 /* get libpng to update its state */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
186 png_read_update_info(png_ptr, info_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
187
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
188 png_get_IHDR(png_ptr, info_ptr, &png->width, &png->height,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
189 &bit_depth, &color_type, &interlace_type, NULL, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
190
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
191 png->rowbytes = png_get_rowbytes(png_ptr, info_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
192 png->channels = png_get_channels(png_ptr, info_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
193
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
194 /* init Dillo specifics */
359
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
195 _MSG("Png_datainfo_callback: rowbytes = %d\n"
1702
341debc7a62c use png_uint_32 for png width and height
corvid <corvid@lavabit.com>
parents: 1669
diff changeset
196 "Png_datainfo_callback: width = %lu\n"
341debc7a62c use png_uint_32 for png width and height
corvid <corvid@lavabit.com>
parents: 1669
diff changeset
197 "Png_datainfo_callback: height = %lu\n",
341debc7a62c use png_uint_32 for png width and height
corvid <corvid@lavabit.com>
parents: 1669
diff changeset
198 png->rowbytes, (ulong_t) png->width, (ulong_t) png->height);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
199
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
200 png->image_data = (uchar_t *) dMalloc(png->rowbytes * png->height);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
201 png->row_pointers = (uchar_t **) dMalloc(png->height * sizeof(uchar_t *));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
202
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
203 for (i = 0; i < png->height; i++)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
204 png->row_pointers[i] = png->image_data + (i * png->rowbytes);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
205
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
206 png->linebuf = dMalloc(3 * png->width);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
207
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
208 /* Initialize the dicache-entry here */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
209 a_Dicache_set_parms(png->url, png->version, png->Image,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
210 (uint_t)png->width, (uint_t)png->height,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
211 DILLO_IMG_TYPE_RGB);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
212 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
213
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
214 static void
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
215 Png_datarow_callback(png_structp png_ptr, png_bytep new_row,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
216 png_uint_32 row_num, int pass)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
217 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
218 DilloPng *png;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
219 uint_t i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
220
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
221 if (!new_row) /* work to do? */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
222 return;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
223
359
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
224 _MSG("Png_datarow_callback: row_num = %ld\n", row_num);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
225
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
226 png = png_get_progressive_ptr(png_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
227
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
228 png_progressive_combine_row(png_ptr, png->row_pointers[row_num], new_row);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
229
703
e2b30a2f4654 [mq]: dicache-cleanup1
Jorge Arellano Cid <jcid@dillo.org>
parents: 480
diff changeset
230 _MSG("png: row_num=%u previous_row=%u\n", row_num, png->previous_row);
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 0
diff changeset
231 if (row_num < png->previous_row) {
703
e2b30a2f4654 [mq]: dicache-cleanup1
Jorge Arellano Cid <jcid@dillo.org>
parents: 480
diff changeset
232 a_Dicache_new_scan(png->url, png->version);
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 0
diff changeset
233 }
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 0
diff changeset
234 png->previous_row = row_num;
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 0
diff changeset
235
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
236 switch (png->channels) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
237 case 3:
1050
6a270ab021ce Remove unused parameter in a_Dicache_write()
corvid <corvid@lavabit.com>
parents: 991
diff changeset
238 a_Dicache_write(png->url, png->version,
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
239 png->image_data + (row_num * png->rowbytes),
335
4a6db4341660 - Made several cleanups according to compiler warnings with "-W -Wall".
jcid
parents: 126
diff changeset
240 (uint_t)row_num);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
241 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
242 case 4:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
243 {
368
2242da885677 - s/todo:/TODO:/g
jcid
parents: 359
diff changeset
244 /* TODO: get the backgound color from the parent
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
245 * of the image widget -- Livio. */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
246 int a, bg_red, bg_green, bg_blue;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
247 uchar_t *pl = png->linebuf;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
248 uchar_t *data = png->image_data + (row_num * png->rowbytes);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
249
368
2242da885677 - s/todo:/TODO:/g
jcid
parents: 359
diff changeset
250 /* TODO: maybe change prefs.bg_color to `a_Dw_widget_get_bg_color`,
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
251 * when background colors are correctly implementated */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
252 bg_blue = (png->Image->bg_color) & 0xFF;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
253 bg_green = (png->Image->bg_color>>8) & 0xFF;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
254 bg_red = (png->Image->bg_color>>16) & 0xFF;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
255
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
256 for (i = 0; i < png->width; i++) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
257 a = *(data+3);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
258
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
259 if (a == 255) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
260 *(pl++) = *(data++);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
261 *(pl++) = *(data++);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
262 *(pl++) = *(data++);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
263 data++;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
264 } else if (a == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
265 *(pl++) = bg_red;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
266 *(pl++) = bg_green;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
267 *(pl++) = bg_blue;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
268 data += 4;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
269 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
270 png_composite(*(pl++), *(data++), a, bg_red);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
271 png_composite(*(pl++), *(data++), a, bg_green);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
272 png_composite(*(pl++), *(data++), a, bg_blue);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
273 data++;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
274 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
275 }
1050
6a270ab021ce Remove unused parameter in a_Dicache_write()
corvid <corvid@lavabit.com>
parents: 991
diff changeset
276 a_Dicache_write(png->url, png->version, png->linebuf, (uint_t)row_num);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
277 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
278 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
279 default:
880
65f4c7c12c5e Minor tricks to avoid a couple compiler warnings in png.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
280 MSG("Png_datarow_callback: unexpected number of channels=%d pass=%d\n",
65f4c7c12c5e Minor tricks to avoid a couple compiler warnings in png.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
281 png->channels, pass);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
282 abort();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
283 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
284 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
285
880
65f4c7c12c5e Minor tricks to avoid a couple compiler warnings in png.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
286 static void Png_dataend_callback(png_structp png_ptr, png_infop info_ptr)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
287 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
288 DilloPng *png;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
289
359
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
290 _MSG("Png_dataend_callback:\n");
880
65f4c7c12c5e Minor tricks to avoid a couple compiler warnings in png.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
291 if (!info_ptr)
65f4c7c12c5e Minor tricks to avoid a couple compiler warnings in png.c
Jorge Arellano Cid <jcid@dillo.org>
parents: 874
diff changeset
292 MSG("Png_dataend_callback: info_ptr = NULL\n");
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
293
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
294 png = png_get_progressive_ptr(png_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
295 png->state = IS_finished;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
296 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
297
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
298 /*
1085
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
299 * Free up the resources for this image.
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
300 */
1085
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
301 static void Png_free(DilloPng *png)
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
302 {
1094
7401c51915da Silence the last image-debugging messages
Jorge Arellano Cid <jcid@dillo.org>
parents: 1092
diff changeset
303 _MSG("Png_free: png=%p\n", png);
710
43e46533be39 imported patch dicache-cleanup5
Jorge Arellano Cid <jcid@dillo.org>
parents: 703
diff changeset
304
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
305 dFree(png->image_data);
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
306 dFree(png->row_pointers);
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
307 dFree(png->linebuf);
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
308 if (setjmp(png->jmpbuf))
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
309 MSG_WARN("PNG: can't destroy read structure\n");
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
310 else if (png->png_ptr)
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
311 png_destroy_read_struct(&png->png_ptr, &png->info_ptr, NULL);
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
312 dFree(png);
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
313 }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
314
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
315 /*
1085
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
316 * Finish the decoding process (and free the memory)
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
317 */
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
318 static void Png_close(DilloPng *png, CacheClient_t *Client)
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
319 {
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
320 _MSG("Png_close\n");
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
321 /* Let dicache know decoding is over */
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
322 a_Dicache_close(png->url, png->version, Client);
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
323 Png_free(png);
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
324 }
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
325
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
326 /*
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
327 * Receive and process new chunks of PNG image data
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
328 */
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
329 static void Png_write(DilloPng *png, void *Buf, uint_t BufSize)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
330 {
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
331 dReturn_if_fail ( Buf != NULL && BufSize > 0 );
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
332
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
333 /* Keep local copies so we don't have to pass multiple args to
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
334 * a number of functions. */
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
335 png->ipbuf = Buf;
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
336 png->ipbufsize = BufSize;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
337
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
338 /* start/resume the FSM here */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
339 while (png->state != IS_finished && DATASIZE) {
359
b9142bae5429 - Switched from DEBUG_MSG to MSG.
jcid
parents: 335
diff changeset
340 _MSG("State = %s\n", prog_state_name[png->state]);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
341
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
342 switch (png->state) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
343 case IS_init:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
344 if (DATASIZE < 8) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
345 return; /* need MORE data */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
346 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
347 /* check the image signature - DON'T update ipbufstart! */
1563
436fc58eba1b use png_sig_cmp()
corvid <corvid@lavabit.com>
parents: 1202
diff changeset
348 if (png_sig_cmp(png->ipbuf, 0, DATASIZE)) {
126
660373853951 + Added a MSG_WARN to non-png URLs served as png.
jcid
parents: 104
diff changeset
349 MSG_WARN("\"%s\" is not a PNG file.\n", URL_STR(png->url));
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
350 png->state = IS_finished;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
351 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
352 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
353 /* OK, it looks like a PNG image, lets do some set up stuff */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
354 png->png_ptr = png_create_read_struct(
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
355 PNG_LIBPNG_VER_STRING,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
356 png,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
357 (png_error_ptr)Png_error_handling,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
358 (png_error_ptr)Png_error_handling);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
359 dReturn_if_fail (png->png_ptr != NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
360 png->info_ptr = png_create_info_struct(png->png_ptr);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
361 dReturn_if_fail (png->info_ptr != NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
362
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
363 setjmp(png->jmpbuf);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
364 if (!png->error) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
365 png_set_progressive_read_fn(
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
366 png->png_ptr,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
367 png,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
368 Png_datainfo_callback, /* performs local init functions */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
369 Png_datarow_callback, /* performs per row action */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
370 Png_dataend_callback); /* performs cleanup actions */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
371 png->state = IS_nextdata;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
372 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
373 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
374
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
375 case IS_nextdata:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
376 if (setjmp(png->jmpbuf)) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
377 png->state = IS_finished;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
378 } else if (!png->error) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
379 png_process_data( png->png_ptr,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
380 png->info_ptr,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
381 png->ipbuf + png->ipbufstart,
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
382 (png_size_t)DATASIZE);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
383
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
384 png->ipbufstart += DATASIZE;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
385 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
386 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
387
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
388 default:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
389 MSG_WARN("PNG decoder: bad state = %d\n", png->state);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
390 abort();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
391 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
392 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
393 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
394
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
395 /*
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
396 * Op: Operation to perform.
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
397 * If (Op == 0)
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
398 * start or continue processing an image if image data exists.
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
399 * else
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
400 * terminate processing, cleanup any allocated memory,
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
401 * close down the decoding process.
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
402 *
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
403 * Client->CbData : pointer to previously allocated DilloPng work area.
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
404 * This holds the current state of the image processing and is kept
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
405 * across calls to this routine.
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
406 * Client->Buf : Pointer to data start.
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
407 * Client->BufSize : the size of the data buffer.
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
408 *
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
409 * You have to keep track of where you are in the image data and
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
410 * how much has been processed.
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
411 *
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
412 * It's entirely possible that you will not see the end of the data. The
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
413 * user may terminate transfer via a Stop button or there may be a network
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
414 * failure. This means that you can't just wait for all the data to be
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
415 * presented before starting conversion and display.
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
416 */
1085
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
417 void a_Png_callback(int Op, void *data)
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
418 {
1085
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
419 if (Op == CA_Send) {
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
420 CacheClient_t *Client = data;
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
421 Png_write(Client->CbData, Client->Buf, Client->BufSize);
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
422 } else if (Op == CA_Close) {
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
423 CacheClient_t *Client = data;
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
424 Png_close(Client->CbData, Client);
1085
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
425 } else if (Op == CA_Abort) {
d6767b7bdf93 Fix a memory leak when stopping an image-decoding process
Jorge Arellano Cid <jcid@dillo.org>
parents: 1050
diff changeset
426 Png_free(data);
480
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
427 }
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
428 }
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
429
0b47756eeb13 Started code cleanup of the image code mainly in dicache.c. part#1
Jorge Arellano Cid <jcid@dillo.org>
parents: 368
diff changeset
430 /*
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
431 * Create the image state data that must be kept between calls
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
432 */
874
6828b4d19d69 Set dicache as MIME dispatcher for image/{gif,jpg,png}. +refactor and cleanups
Jorge Arellano Cid <jcid@dillo.org>
parents: 768
diff changeset
433 void *a_Png_new(DilloImage *Image, DilloUrl *url, int version)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
434 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
435 DilloPng *png = dNew0(DilloPng, 1);
1094
7401c51915da Silence the last image-debugging messages
Jorge Arellano Cid <jcid@dillo.org>
parents: 1092
diff changeset
436 _MSG("a_Png_new: png=%p\n", png);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
437
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
438 png->Image = Image;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
439 png->url = url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
440 png->version = version;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
441 png->error = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
442 png->ipbuf = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
443 png->ipbufstart = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
444 png->ipbufsize = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
445 png->state = IS_init;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
446 png->linebuf = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
447 png->image_data = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
448 png->row_pointers = NULL;
104
ed71c7b5ea92 - Added support for progressive display of progressive jpegs.
jcid
parents: 0
diff changeset
449 png->previous_row = 0;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
450
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
451 return png;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
452 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
453
874
6828b4d19d69 Set dicache as MIME dispatcher for image/{gif,jpg,png}. +refactor and cleanups
Jorge Arellano Cid <jcid@dillo.org>
parents: 768
diff changeset
454 #else /* ENABLE_PNG */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
455
874
6828b4d19d69 Set dicache as MIME dispatcher for image/{gif,jpg,png}. +refactor and cleanups
Jorge Arellano Cid <jcid@dillo.org>
parents: 768
diff changeset
456 void *a_Png_new() { return 0; }
6828b4d19d69 Set dicache as MIME dispatcher for image/{gif,jpg,png}. +refactor and cleanups
Jorge Arellano Cid <jcid@dillo.org>
parents: 768
diff changeset
457 void a_Png_callback() { return; }
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
458
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
459 #endif /* ENABLE_PNG */