diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwtran.c')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwtran.c | 1266 |
1 files changed, 633 insertions, 633 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwtran.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwtran.c index b598149..96608ef 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwtran.c +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwtran.c | |||
@@ -1,633 +1,633 @@ | |||
1 | 1 | ||
2 | /* pngwtran.c - transforms the data in a row for PNG writers | 2 | /* pngwtran.c - transforms the data in a row for PNG writers |
3 | * | 3 | * |
4 | * Last changed in libpng 1.5.6 [November 3, 2011] | 4 | * Last changed in libpng 1.5.6 [November 3, 2011] |
5 | * Copyright (c) 1998-2011 Glenn Randers-Pehrson | 5 | * Copyright (c) 1998-2011 Glenn Randers-Pehrson |
6 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 6 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
7 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | 7 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
8 | * | 8 | * |
9 | * This code is released under the libpng license. | 9 | * This code is released under the libpng license. |
10 | * For conditions of distribution and use, see the disclaimer | 10 | * For conditions of distribution and use, see the disclaimer |
11 | * and license in png.h | 11 | * and license in png.h |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include "pngpriv.h" | 14 | #include "pngpriv.h" |
15 | 15 | ||
16 | #ifdef PNG_WRITE_SUPPORTED | 16 | #ifdef PNG_WRITE_SUPPORTED |
17 | 17 | ||
18 | #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED | 18 | #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED |
19 | /* Transform the data according to the user's wishes. The order of | 19 | /* Transform the data according to the user's wishes. The order of |
20 | * transformations is significant. | 20 | * transformations is significant. |
21 | */ | 21 | */ |
22 | void /* PRIVATE */ | 22 | void /* PRIVATE */ |
23 | png_do_write_transformations(png_structp png_ptr, png_row_infop row_info) | 23 | png_do_write_transformations(png_structp png_ptr, png_row_infop row_info) |
24 | { | 24 | { |
25 | png_debug(1, "in png_do_write_transformations"); | 25 | png_debug(1, "in png_do_write_transformations"); |
26 | 26 | ||
27 | if (png_ptr == NULL) | 27 | if (png_ptr == NULL) |
28 | return; | 28 | return; |
29 | 29 | ||
30 | #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED | 30 | #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED |
31 | if (png_ptr->transformations & PNG_USER_TRANSFORM) | 31 | if (png_ptr->transformations & PNG_USER_TRANSFORM) |
32 | if (png_ptr->write_user_transform_fn != NULL) | 32 | if (png_ptr->write_user_transform_fn != NULL) |
33 | (*(png_ptr->write_user_transform_fn)) /* User write transform | 33 | (*(png_ptr->write_user_transform_fn)) /* User write transform |
34 | function */ | 34 | function */ |
35 | (png_ptr, /* png_ptr */ | 35 | (png_ptr, /* png_ptr */ |
36 | row_info, /* row_info: */ | 36 | row_info, /* row_info: */ |
37 | /* png_uint_32 width; width of row */ | 37 | /* png_uint_32 width; width of row */ |
38 | /* png_size_t rowbytes; number of bytes in row */ | 38 | /* png_size_t rowbytes; number of bytes in row */ |
39 | /* png_byte color_type; color type of pixels */ | 39 | /* png_byte color_type; color type of pixels */ |
40 | /* png_byte bit_depth; bit depth of samples */ | 40 | /* png_byte bit_depth; bit depth of samples */ |
41 | /* png_byte channels; number of channels (1-4) */ | 41 | /* png_byte channels; number of channels (1-4) */ |
42 | /* png_byte pixel_depth; bits per pixel (depth*channels) */ | 42 | /* png_byte pixel_depth; bits per pixel (depth*channels) */ |
43 | png_ptr->row_buf + 1); /* start of pixel data for row */ | 43 | png_ptr->row_buf + 1); /* start of pixel data for row */ |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | #ifdef PNG_WRITE_FILLER_SUPPORTED | 46 | #ifdef PNG_WRITE_FILLER_SUPPORTED |
47 | if (png_ptr->transformations & PNG_FILLER) | 47 | if (png_ptr->transformations & PNG_FILLER) |
48 | png_do_strip_channel(row_info, png_ptr->row_buf + 1, | 48 | png_do_strip_channel(row_info, png_ptr->row_buf + 1, |
49 | !(png_ptr->flags & PNG_FLAG_FILLER_AFTER)); | 49 | !(png_ptr->flags & PNG_FLAG_FILLER_AFTER)); |
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | #ifdef PNG_WRITE_PACKSWAP_SUPPORTED | 52 | #ifdef PNG_WRITE_PACKSWAP_SUPPORTED |
53 | if (png_ptr->transformations & PNG_PACKSWAP) | 53 | if (png_ptr->transformations & PNG_PACKSWAP) |
54 | png_do_packswap(row_info, png_ptr->row_buf + 1); | 54 | png_do_packswap(row_info, png_ptr->row_buf + 1); |
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | #ifdef PNG_WRITE_PACK_SUPPORTED | 57 | #ifdef PNG_WRITE_PACK_SUPPORTED |
58 | if (png_ptr->transformations & PNG_PACK) | 58 | if (png_ptr->transformations & PNG_PACK) |
59 | png_do_pack(row_info, png_ptr->row_buf + 1, | 59 | png_do_pack(row_info, png_ptr->row_buf + 1, |
60 | (png_uint_32)png_ptr->bit_depth); | 60 | (png_uint_32)png_ptr->bit_depth); |
61 | #endif | 61 | #endif |
62 | 62 | ||
63 | #ifdef PNG_WRITE_SWAP_SUPPORTED | 63 | #ifdef PNG_WRITE_SWAP_SUPPORTED |
64 | if (png_ptr->transformations & PNG_SWAP_BYTES) | 64 | if (png_ptr->transformations & PNG_SWAP_BYTES) |
65 | png_do_swap(row_info, png_ptr->row_buf + 1); | 65 | png_do_swap(row_info, png_ptr->row_buf + 1); |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | #ifdef PNG_WRITE_SHIFT_SUPPORTED | 68 | #ifdef PNG_WRITE_SHIFT_SUPPORTED |
69 | if (png_ptr->transformations & PNG_SHIFT) | 69 | if (png_ptr->transformations & PNG_SHIFT) |
70 | png_do_shift(row_info, png_ptr->row_buf + 1, | 70 | png_do_shift(row_info, png_ptr->row_buf + 1, |
71 | &(png_ptr->shift)); | 71 | &(png_ptr->shift)); |
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED | 74 | #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED |
75 | if (png_ptr->transformations & PNG_SWAP_ALPHA) | 75 | if (png_ptr->transformations & PNG_SWAP_ALPHA) |
76 | png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1); | 76 | png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1); |
77 | #endif | 77 | #endif |
78 | 78 | ||
79 | #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED | 79 | #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED |
80 | if (png_ptr->transformations & PNG_INVERT_ALPHA) | 80 | if (png_ptr->transformations & PNG_INVERT_ALPHA) |
81 | png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1); | 81 | png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1); |
82 | #endif | 82 | #endif |
83 | 83 | ||
84 | #ifdef PNG_WRITE_BGR_SUPPORTED | 84 | #ifdef PNG_WRITE_BGR_SUPPORTED |
85 | if (png_ptr->transformations & PNG_BGR) | 85 | if (png_ptr->transformations & PNG_BGR) |
86 | png_do_bgr(row_info, png_ptr->row_buf + 1); | 86 | png_do_bgr(row_info, png_ptr->row_buf + 1); |
87 | #endif | 87 | #endif |
88 | 88 | ||
89 | #ifdef PNG_WRITE_INVERT_SUPPORTED | 89 | #ifdef PNG_WRITE_INVERT_SUPPORTED |
90 | if (png_ptr->transformations & PNG_INVERT_MONO) | 90 | if (png_ptr->transformations & PNG_INVERT_MONO) |
91 | png_do_invert(row_info, png_ptr->row_buf + 1); | 91 | png_do_invert(row_info, png_ptr->row_buf + 1); |
92 | #endif | 92 | #endif |
93 | } | 93 | } |
94 | 94 | ||
95 | #ifdef PNG_WRITE_PACK_SUPPORTED | 95 | #ifdef PNG_WRITE_PACK_SUPPORTED |
96 | /* Pack pixels into bytes. Pass the true bit depth in bit_depth. The | 96 | /* Pack pixels into bytes. Pass the true bit depth in bit_depth. The |
97 | * row_info bit depth should be 8 (one pixel per byte). The channels | 97 | * row_info bit depth should be 8 (one pixel per byte). The channels |
98 | * should be 1 (this only happens on grayscale and paletted images). | 98 | * should be 1 (this only happens on grayscale and paletted images). |
99 | */ | 99 | */ |
100 | void /* PRIVATE */ | 100 | void /* PRIVATE */ |
101 | png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) | 101 | png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) |
102 | { | 102 | { |
103 | png_debug(1, "in png_do_pack"); | 103 | png_debug(1, "in png_do_pack"); |
104 | 104 | ||
105 | if (row_info->bit_depth == 8 && | 105 | if (row_info->bit_depth == 8 && |
106 | row_info->channels == 1) | 106 | row_info->channels == 1) |
107 | { | 107 | { |
108 | switch ((int)bit_depth) | 108 | switch ((int)bit_depth) |
109 | { | 109 | { |
110 | case 1: | 110 | case 1: |
111 | { | 111 | { |
112 | png_bytep sp, dp; | 112 | png_bytep sp, dp; |
113 | int mask, v; | 113 | int mask, v; |
114 | png_uint_32 i; | 114 | png_uint_32 i; |
115 | png_uint_32 row_width = row_info->width; | 115 | png_uint_32 row_width = row_info->width; |
116 | 116 | ||
117 | sp = row; | 117 | sp = row; |
118 | dp = row; | 118 | dp = row; |
119 | mask = 0x80; | 119 | mask = 0x80; |
120 | v = 0; | 120 | v = 0; |
121 | 121 | ||
122 | for (i = 0; i < row_width; i++) | 122 | for (i = 0; i < row_width; i++) |
123 | { | 123 | { |
124 | if (*sp != 0) | 124 | if (*sp != 0) |
125 | v |= mask; | 125 | v |= mask; |
126 | 126 | ||
127 | sp++; | 127 | sp++; |
128 | 128 | ||
129 | if (mask > 1) | 129 | if (mask > 1) |
130 | mask >>= 1; | 130 | mask >>= 1; |
131 | 131 | ||
132 | else | 132 | else |
133 | { | 133 | { |
134 | mask = 0x80; | 134 | mask = 0x80; |
135 | *dp = (png_byte)v; | 135 | *dp = (png_byte)v; |
136 | dp++; | 136 | dp++; |
137 | v = 0; | 137 | v = 0; |
138 | } | 138 | } |
139 | } | 139 | } |
140 | 140 | ||
141 | if (mask != 0x80) | 141 | if (mask != 0x80) |
142 | *dp = (png_byte)v; | 142 | *dp = (png_byte)v; |
143 | 143 | ||
144 | break; | 144 | break; |
145 | } | 145 | } |
146 | 146 | ||
147 | case 2: | 147 | case 2: |
148 | { | 148 | { |
149 | png_bytep sp, dp; | 149 | png_bytep sp, dp; |
150 | int shift, v; | 150 | int shift, v; |
151 | png_uint_32 i; | 151 | png_uint_32 i; |
152 | png_uint_32 row_width = row_info->width; | 152 | png_uint_32 row_width = row_info->width; |
153 | 153 | ||
154 | sp = row; | 154 | sp = row; |
155 | dp = row; | 155 | dp = row; |
156 | shift = 6; | 156 | shift = 6; |
157 | v = 0; | 157 | v = 0; |
158 | 158 | ||
159 | for (i = 0; i < row_width; i++) | 159 | for (i = 0; i < row_width; i++) |
160 | { | 160 | { |
161 | png_byte value; | 161 | png_byte value; |
162 | 162 | ||
163 | value = (png_byte)(*sp & 0x03); | 163 | value = (png_byte)(*sp & 0x03); |
164 | v |= (value << shift); | 164 | v |= (value << shift); |
165 | 165 | ||
166 | if (shift == 0) | 166 | if (shift == 0) |
167 | { | 167 | { |
168 | shift = 6; | 168 | shift = 6; |
169 | *dp = (png_byte)v; | 169 | *dp = (png_byte)v; |
170 | dp++; | 170 | dp++; |
171 | v = 0; | 171 | v = 0; |
172 | } | 172 | } |
173 | 173 | ||
174 | else | 174 | else |
175 | shift -= 2; | 175 | shift -= 2; |
176 | 176 | ||
177 | sp++; | 177 | sp++; |
178 | } | 178 | } |
179 | 179 | ||
180 | if (shift != 6) | 180 | if (shift != 6) |
181 | *dp = (png_byte)v; | 181 | *dp = (png_byte)v; |
182 | 182 | ||
183 | break; | 183 | break; |
184 | } | 184 | } |
185 | 185 | ||
186 | case 4: | 186 | case 4: |
187 | { | 187 | { |
188 | png_bytep sp, dp; | 188 | png_bytep sp, dp; |
189 | int shift, v; | 189 | int shift, v; |
190 | png_uint_32 i; | 190 | png_uint_32 i; |
191 | png_uint_32 row_width = row_info->width; | 191 | png_uint_32 row_width = row_info->width; |
192 | 192 | ||
193 | sp = row; | 193 | sp = row; |
194 | dp = row; | 194 | dp = row; |
195 | shift = 4; | 195 | shift = 4; |
196 | v = 0; | 196 | v = 0; |
197 | 197 | ||
198 | for (i = 0; i < row_width; i++) | 198 | for (i = 0; i < row_width; i++) |
199 | { | 199 | { |
200 | png_byte value; | 200 | png_byte value; |
201 | 201 | ||
202 | value = (png_byte)(*sp & 0x0f); | 202 | value = (png_byte)(*sp & 0x0f); |
203 | v |= (value << shift); | 203 | v |= (value << shift); |
204 | 204 | ||
205 | if (shift == 0) | 205 | if (shift == 0) |
206 | { | 206 | { |
207 | shift = 4; | 207 | shift = 4; |
208 | *dp = (png_byte)v; | 208 | *dp = (png_byte)v; |
209 | dp++; | 209 | dp++; |
210 | v = 0; | 210 | v = 0; |
211 | } | 211 | } |
212 | 212 | ||
213 | else | 213 | else |
214 | shift -= 4; | 214 | shift -= 4; |
215 | 215 | ||
216 | sp++; | 216 | sp++; |
217 | } | 217 | } |
218 | 218 | ||
219 | if (shift != 4) | 219 | if (shift != 4) |
220 | *dp = (png_byte)v; | 220 | *dp = (png_byte)v; |
221 | 221 | ||
222 | break; | 222 | break; |
223 | } | 223 | } |
224 | 224 | ||
225 | default: | 225 | default: |
226 | break; | 226 | break; |
227 | } | 227 | } |
228 | 228 | ||
229 | row_info->bit_depth = (png_byte)bit_depth; | 229 | row_info->bit_depth = (png_byte)bit_depth; |
230 | row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels); | 230 | row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels); |
231 | row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, | 231 | row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, |
232 | row_info->width); | 232 | row_info->width); |
233 | } | 233 | } |
234 | } | 234 | } |
235 | #endif | 235 | #endif |
236 | 236 | ||
237 | #ifdef PNG_WRITE_SHIFT_SUPPORTED | 237 | #ifdef PNG_WRITE_SHIFT_SUPPORTED |
238 | /* Shift pixel values to take advantage of whole range. Pass the | 238 | /* Shift pixel values to take advantage of whole range. Pass the |
239 | * true number of bits in bit_depth. The row should be packed | 239 | * true number of bits in bit_depth. The row should be packed |
240 | * according to row_info->bit_depth. Thus, if you had a row of | 240 | * according to row_info->bit_depth. Thus, if you had a row of |
241 | * bit depth 4, but the pixels only had values from 0 to 7, you | 241 | * bit depth 4, but the pixels only had values from 0 to 7, you |
242 | * would pass 3 as bit_depth, and this routine would translate the | 242 | * would pass 3 as bit_depth, and this routine would translate the |
243 | * data to 0 to 15. | 243 | * data to 0 to 15. |
244 | */ | 244 | */ |
245 | void /* PRIVATE */ | 245 | void /* PRIVATE */ |
246 | png_do_shift(png_row_infop row_info, png_bytep row, | 246 | png_do_shift(png_row_infop row_info, png_bytep row, |
247 | png_const_color_8p bit_depth) | 247 | png_const_color_8p bit_depth) |
248 | { | 248 | { |
249 | png_debug(1, "in png_do_shift"); | 249 | png_debug(1, "in png_do_shift"); |
250 | 250 | ||
251 | if (row_info->color_type != PNG_COLOR_TYPE_PALETTE) | 251 | if (row_info->color_type != PNG_COLOR_TYPE_PALETTE) |
252 | { | 252 | { |
253 | int shift_start[4], shift_dec[4]; | 253 | int shift_start[4], shift_dec[4]; |
254 | int channels = 0; | 254 | int channels = 0; |
255 | 255 | ||
256 | if (row_info->color_type & PNG_COLOR_MASK_COLOR) | 256 | if (row_info->color_type & PNG_COLOR_MASK_COLOR) |
257 | { | 257 | { |
258 | shift_start[channels] = row_info->bit_depth - bit_depth->red; | 258 | shift_start[channels] = row_info->bit_depth - bit_depth->red; |
259 | shift_dec[channels] = bit_depth->red; | 259 | shift_dec[channels] = bit_depth->red; |
260 | channels++; | 260 | channels++; |
261 | 261 | ||
262 | shift_start[channels] = row_info->bit_depth - bit_depth->green; | 262 | shift_start[channels] = row_info->bit_depth - bit_depth->green; |
263 | shift_dec[channels] = bit_depth->green; | 263 | shift_dec[channels] = bit_depth->green; |
264 | channels++; | 264 | channels++; |
265 | 265 | ||
266 | shift_start[channels] = row_info->bit_depth - bit_depth->blue; | 266 | shift_start[channels] = row_info->bit_depth - bit_depth->blue; |
267 | shift_dec[channels] = bit_depth->blue; | 267 | shift_dec[channels] = bit_depth->blue; |
268 | channels++; | 268 | channels++; |
269 | } | 269 | } |
270 | 270 | ||
271 | else | 271 | else |
272 | { | 272 | { |
273 | shift_start[channels] = row_info->bit_depth - bit_depth->gray; | 273 | shift_start[channels] = row_info->bit_depth - bit_depth->gray; |
274 | shift_dec[channels] = bit_depth->gray; | 274 | shift_dec[channels] = bit_depth->gray; |
275 | channels++; | 275 | channels++; |
276 | } | 276 | } |
277 | 277 | ||
278 | if (row_info->color_type & PNG_COLOR_MASK_ALPHA) | 278 | if (row_info->color_type & PNG_COLOR_MASK_ALPHA) |
279 | { | 279 | { |
280 | shift_start[channels] = row_info->bit_depth - bit_depth->alpha; | 280 | shift_start[channels] = row_info->bit_depth - bit_depth->alpha; |
281 | shift_dec[channels] = bit_depth->alpha; | 281 | shift_dec[channels] = bit_depth->alpha; |
282 | channels++; | 282 | channels++; |
283 | } | 283 | } |
284 | 284 | ||
285 | /* With low row depths, could only be grayscale, so one channel */ | 285 | /* With low row depths, could only be grayscale, so one channel */ |
286 | if (row_info->bit_depth < 8) | 286 | if (row_info->bit_depth < 8) |
287 | { | 287 | { |
288 | png_bytep bp = row; | 288 | png_bytep bp = row; |
289 | png_size_t i; | 289 | png_size_t i; |
290 | png_byte mask; | 290 | png_byte mask; |
291 | png_size_t row_bytes = row_info->rowbytes; | 291 | png_size_t row_bytes = row_info->rowbytes; |
292 | 292 | ||
293 | if (bit_depth->gray == 1 && row_info->bit_depth == 2) | 293 | if (bit_depth->gray == 1 && row_info->bit_depth == 2) |
294 | mask = 0x55; | 294 | mask = 0x55; |
295 | 295 | ||
296 | else if (row_info->bit_depth == 4 && bit_depth->gray == 3) | 296 | else if (row_info->bit_depth == 4 && bit_depth->gray == 3) |
297 | mask = 0x11; | 297 | mask = 0x11; |
298 | 298 | ||
299 | else | 299 | else |
300 | mask = 0xff; | 300 | mask = 0xff; |
301 | 301 | ||
302 | for (i = 0; i < row_bytes; i++, bp++) | 302 | for (i = 0; i < row_bytes; i++, bp++) |
303 | { | 303 | { |
304 | png_uint_16 v; | 304 | png_uint_16 v; |
305 | int j; | 305 | int j; |
306 | 306 | ||
307 | v = *bp; | 307 | v = *bp; |
308 | *bp = 0; | 308 | *bp = 0; |
309 | 309 | ||
310 | for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0]) | 310 | for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0]) |
311 | { | 311 | { |
312 | if (j > 0) | 312 | if (j > 0) |
313 | *bp |= (png_byte)((v << j) & 0xff); | 313 | *bp |= (png_byte)((v << j) & 0xff); |
314 | 314 | ||
315 | else | 315 | else |
316 | *bp |= (png_byte)((v >> (-j)) & mask); | 316 | *bp |= (png_byte)((v >> (-j)) & mask); |
317 | } | 317 | } |
318 | } | 318 | } |
319 | } | 319 | } |
320 | 320 | ||
321 | else if (row_info->bit_depth == 8) | 321 | else if (row_info->bit_depth == 8) |
322 | { | 322 | { |
323 | png_bytep bp = row; | 323 | png_bytep bp = row; |
324 | png_uint_32 i; | 324 | png_uint_32 i; |
325 | png_uint_32 istop = channels * row_info->width; | 325 | png_uint_32 istop = channels * row_info->width; |
326 | 326 | ||
327 | for (i = 0; i < istop; i++, bp++) | 327 | for (i = 0; i < istop; i++, bp++) |
328 | { | 328 | { |
329 | 329 | ||
330 | png_uint_16 v; | 330 | png_uint_16 v; |
331 | int j; | 331 | int j; |
332 | int c = (int)(i%channels); | 332 | int c = (int)(i%channels); |
333 | 333 | ||
334 | v = *bp; | 334 | v = *bp; |
335 | *bp = 0; | 335 | *bp = 0; |
336 | 336 | ||
337 | for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) | 337 | for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) |
338 | { | 338 | { |
339 | if (j > 0) | 339 | if (j > 0) |
340 | *bp |= (png_byte)((v << j) & 0xff); | 340 | *bp |= (png_byte)((v << j) & 0xff); |
341 | 341 | ||
342 | else | 342 | else |
343 | *bp |= (png_byte)((v >> (-j)) & 0xff); | 343 | *bp |= (png_byte)((v >> (-j)) & 0xff); |
344 | } | 344 | } |
345 | } | 345 | } |
346 | } | 346 | } |
347 | 347 | ||
348 | else | 348 | else |
349 | { | 349 | { |
350 | png_bytep bp; | 350 | png_bytep bp; |
351 | png_uint_32 i; | 351 | png_uint_32 i; |
352 | png_uint_32 istop = channels * row_info->width; | 352 | png_uint_32 istop = channels * row_info->width; |
353 | 353 | ||
354 | for (bp = row, i = 0; i < istop; i++) | 354 | for (bp = row, i = 0; i < istop; i++) |
355 | { | 355 | { |
356 | int c = (int)(i%channels); | 356 | int c = (int)(i%channels); |
357 | png_uint_16 value, v; | 357 | png_uint_16 value, v; |
358 | int j; | 358 | int j; |
359 | 359 | ||
360 | v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1)); | 360 | v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1)); |
361 | value = 0; | 361 | value = 0; |
362 | 362 | ||
363 | for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) | 363 | for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c]) |
364 | { | 364 | { |
365 | if (j > 0) | 365 | if (j > 0) |
366 | value |= (png_uint_16)((v << j) & (png_uint_16)0xffff); | 366 | value |= (png_uint_16)((v << j) & (png_uint_16)0xffff); |
367 | 367 | ||
368 | else | 368 | else |
369 | value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff); | 369 | value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff); |
370 | } | 370 | } |
371 | *bp++ = (png_byte)(value >> 8); | 371 | *bp++ = (png_byte)(value >> 8); |
372 | *bp++ = (png_byte)(value & 0xff); | 372 | *bp++ = (png_byte)(value & 0xff); |
373 | } | 373 | } |
374 | } | 374 | } |
375 | } | 375 | } |
376 | } | 376 | } |
377 | #endif | 377 | #endif |
378 | 378 | ||
379 | #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED | 379 | #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED |
380 | void /* PRIVATE */ | 380 | void /* PRIVATE */ |
381 | png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) | 381 | png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) |
382 | { | 382 | { |
383 | png_debug(1, "in png_do_write_swap_alpha"); | 383 | png_debug(1, "in png_do_write_swap_alpha"); |
384 | 384 | ||
385 | { | 385 | { |
386 | if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | 386 | if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
387 | { | 387 | { |
388 | if (row_info->bit_depth == 8) | 388 | if (row_info->bit_depth == 8) |
389 | { | 389 | { |
390 | /* This converts from ARGB to RGBA */ | 390 | /* This converts from ARGB to RGBA */ |
391 | png_bytep sp, dp; | 391 | png_bytep sp, dp; |
392 | png_uint_32 i; | 392 | png_uint_32 i; |
393 | png_uint_32 row_width = row_info->width; | 393 | png_uint_32 row_width = row_info->width; |
394 | 394 | ||
395 | for (i = 0, sp = dp = row; i < row_width; i++) | 395 | for (i = 0, sp = dp = row; i < row_width; i++) |
396 | { | 396 | { |
397 | png_byte save = *(sp++); | 397 | png_byte save = *(sp++); |
398 | *(dp++) = *(sp++); | 398 | *(dp++) = *(sp++); |
399 | *(dp++) = *(sp++); | 399 | *(dp++) = *(sp++); |
400 | *(dp++) = *(sp++); | 400 | *(dp++) = *(sp++); |
401 | *(dp++) = save; | 401 | *(dp++) = save; |
402 | } | 402 | } |
403 | } | 403 | } |
404 | 404 | ||
405 | #ifdef PNG_WRITE_16BIT_SUPPORTED | 405 | #ifdef PNG_WRITE_16BIT_SUPPORTED |
406 | else | 406 | else |
407 | { | 407 | { |
408 | /* This converts from AARRGGBB to RRGGBBAA */ | 408 | /* This converts from AARRGGBB to RRGGBBAA */ |
409 | png_bytep sp, dp; | 409 | png_bytep sp, dp; |
410 | png_uint_32 i; | 410 | png_uint_32 i; |
411 | png_uint_32 row_width = row_info->width; | 411 | png_uint_32 row_width = row_info->width; |
412 | 412 | ||
413 | for (i = 0, sp = dp = row; i < row_width; i++) | 413 | for (i = 0, sp = dp = row; i < row_width; i++) |
414 | { | 414 | { |
415 | png_byte save[2]; | 415 | png_byte save[2]; |
416 | save[0] = *(sp++); | 416 | save[0] = *(sp++); |
417 | save[1] = *(sp++); | 417 | save[1] = *(sp++); |
418 | *(dp++) = *(sp++); | 418 | *(dp++) = *(sp++); |
419 | *(dp++) = *(sp++); | 419 | *(dp++) = *(sp++); |
420 | *(dp++) = *(sp++); | 420 | *(dp++) = *(sp++); |
421 | *(dp++) = *(sp++); | 421 | *(dp++) = *(sp++); |
422 | *(dp++) = *(sp++); | 422 | *(dp++) = *(sp++); |
423 | *(dp++) = *(sp++); | 423 | *(dp++) = *(sp++); |
424 | *(dp++) = save[0]; | 424 | *(dp++) = save[0]; |
425 | *(dp++) = save[1]; | 425 | *(dp++) = save[1]; |
426 | } | 426 | } |
427 | } | 427 | } |
428 | #endif /* PNG_WRITE_16BIT_SUPPORTED */ | 428 | #endif /* PNG_WRITE_16BIT_SUPPORTED */ |
429 | } | 429 | } |
430 | 430 | ||
431 | else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) | 431 | else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) |
432 | { | 432 | { |
433 | if (row_info->bit_depth == 8) | 433 | if (row_info->bit_depth == 8) |
434 | { | 434 | { |
435 | /* This converts from AG to GA */ | 435 | /* This converts from AG to GA */ |
436 | png_bytep sp, dp; | 436 | png_bytep sp, dp; |
437 | png_uint_32 i; | 437 | png_uint_32 i; |
438 | png_uint_32 row_width = row_info->width; | 438 | png_uint_32 row_width = row_info->width; |
439 | 439 | ||
440 | for (i = 0, sp = dp = row; i < row_width; i++) | 440 | for (i = 0, sp = dp = row; i < row_width; i++) |
441 | { | 441 | { |
442 | png_byte save = *(sp++); | 442 | png_byte save = *(sp++); |
443 | *(dp++) = *(sp++); | 443 | *(dp++) = *(sp++); |
444 | *(dp++) = save; | 444 | *(dp++) = save; |
445 | } | 445 | } |
446 | } | 446 | } |
447 | 447 | ||
448 | #ifdef PNG_WRITE_16BIT_SUPPORTED | 448 | #ifdef PNG_WRITE_16BIT_SUPPORTED |
449 | else | 449 | else |
450 | { | 450 | { |
451 | /* This converts from AAGG to GGAA */ | 451 | /* This converts from AAGG to GGAA */ |
452 | png_bytep sp, dp; | 452 | png_bytep sp, dp; |
453 | png_uint_32 i; | 453 | png_uint_32 i; |
454 | png_uint_32 row_width = row_info->width; | 454 | png_uint_32 row_width = row_info->width; |
455 | 455 | ||
456 | for (i = 0, sp = dp = row; i < row_width; i++) | 456 | for (i = 0, sp = dp = row; i < row_width; i++) |
457 | { | 457 | { |
458 | png_byte save[2]; | 458 | png_byte save[2]; |
459 | save[0] = *(sp++); | 459 | save[0] = *(sp++); |
460 | save[1] = *(sp++); | 460 | save[1] = *(sp++); |
461 | *(dp++) = *(sp++); | 461 | *(dp++) = *(sp++); |
462 | *(dp++) = *(sp++); | 462 | *(dp++) = *(sp++); |
463 | *(dp++) = save[0]; | 463 | *(dp++) = save[0]; |
464 | *(dp++) = save[1]; | 464 | *(dp++) = save[1]; |
465 | } | 465 | } |
466 | } | 466 | } |
467 | #endif /* PNG_WRITE_16BIT_SUPPORTED */ | 467 | #endif /* PNG_WRITE_16BIT_SUPPORTED */ |
468 | } | 468 | } |
469 | } | 469 | } |
470 | } | 470 | } |
471 | #endif | 471 | #endif |
472 | 472 | ||
473 | #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED | 473 | #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED |
474 | void /* PRIVATE */ | 474 | void /* PRIVATE */ |
475 | png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) | 475 | png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) |
476 | { | 476 | { |
477 | png_debug(1, "in png_do_write_invert_alpha"); | 477 | png_debug(1, "in png_do_write_invert_alpha"); |
478 | 478 | ||
479 | { | 479 | { |
480 | if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | 480 | if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
481 | { | 481 | { |
482 | if (row_info->bit_depth == 8) | 482 | if (row_info->bit_depth == 8) |
483 | { | 483 | { |
484 | /* This inverts the alpha channel in RGBA */ | 484 | /* This inverts the alpha channel in RGBA */ |
485 | png_bytep sp, dp; | 485 | png_bytep sp, dp; |
486 | png_uint_32 i; | 486 | png_uint_32 i; |
487 | png_uint_32 row_width = row_info->width; | 487 | png_uint_32 row_width = row_info->width; |
488 | 488 | ||
489 | for (i = 0, sp = dp = row; i < row_width; i++) | 489 | for (i = 0, sp = dp = row; i < row_width; i++) |
490 | { | 490 | { |
491 | /* Does nothing | 491 | /* Does nothing |
492 | *(dp++) = *(sp++); | 492 | *(dp++) = *(sp++); |
493 | *(dp++) = *(sp++); | 493 | *(dp++) = *(sp++); |
494 | *(dp++) = *(sp++); | 494 | *(dp++) = *(sp++); |
495 | */ | 495 | */ |
496 | sp+=3; dp = sp; | 496 | sp+=3; dp = sp; |
497 | *(dp++) = (png_byte)(255 - *(sp++)); | 497 | *(dp++) = (png_byte)(255 - *(sp++)); |
498 | } | 498 | } |
499 | } | 499 | } |
500 | 500 | ||
501 | #ifdef PNG_WRITE_16BIT_SUPPORTED | 501 | #ifdef PNG_WRITE_16BIT_SUPPORTED |
502 | else | 502 | else |
503 | { | 503 | { |
504 | /* This inverts the alpha channel in RRGGBBAA */ | 504 | /* This inverts the alpha channel in RRGGBBAA */ |
505 | png_bytep sp, dp; | 505 | png_bytep sp, dp; |
506 | png_uint_32 i; | 506 | png_uint_32 i; |
507 | png_uint_32 row_width = row_info->width; | 507 | png_uint_32 row_width = row_info->width; |
508 | 508 | ||
509 | for (i = 0, sp = dp = row; i < row_width; i++) | 509 | for (i = 0, sp = dp = row; i < row_width; i++) |
510 | { | 510 | { |
511 | /* Does nothing | 511 | /* Does nothing |
512 | *(dp++) = *(sp++); | 512 | *(dp++) = *(sp++); |
513 | *(dp++) = *(sp++); | 513 | *(dp++) = *(sp++); |
514 | *(dp++) = *(sp++); | 514 | *(dp++) = *(sp++); |
515 | *(dp++) = *(sp++); | 515 | *(dp++) = *(sp++); |
516 | *(dp++) = *(sp++); | 516 | *(dp++) = *(sp++); |
517 | *(dp++) = *(sp++); | 517 | *(dp++) = *(sp++); |
518 | */ | 518 | */ |
519 | sp+=6; dp = sp; | 519 | sp+=6; dp = sp; |
520 | *(dp++) = (png_byte)(255 - *(sp++)); | 520 | *(dp++) = (png_byte)(255 - *(sp++)); |
521 | *(dp++) = (png_byte)(255 - *(sp++)); | 521 | *(dp++) = (png_byte)(255 - *(sp++)); |
522 | } | 522 | } |
523 | } | 523 | } |
524 | #endif /* PNG_WRITE_16BIT_SUPPORTED */ | 524 | #endif /* PNG_WRITE_16BIT_SUPPORTED */ |
525 | } | 525 | } |
526 | 526 | ||
527 | else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) | 527 | else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) |
528 | { | 528 | { |
529 | if (row_info->bit_depth == 8) | 529 | if (row_info->bit_depth == 8) |
530 | { | 530 | { |
531 | /* This inverts the alpha channel in GA */ | 531 | /* This inverts the alpha channel in GA */ |
532 | png_bytep sp, dp; | 532 | png_bytep sp, dp; |
533 | png_uint_32 i; | 533 | png_uint_32 i; |
534 | png_uint_32 row_width = row_info->width; | 534 | png_uint_32 row_width = row_info->width; |
535 | 535 | ||
536 | for (i = 0, sp = dp = row; i < row_width; i++) | 536 | for (i = 0, sp = dp = row; i < row_width; i++) |
537 | { | 537 | { |
538 | *(dp++) = *(sp++); | 538 | *(dp++) = *(sp++); |
539 | *(dp++) = (png_byte)(255 - *(sp++)); | 539 | *(dp++) = (png_byte)(255 - *(sp++)); |
540 | } | 540 | } |
541 | } | 541 | } |
542 | 542 | ||
543 | #ifdef PNG_WRITE_16BIT_SUPPORTED | 543 | #ifdef PNG_WRITE_16BIT_SUPPORTED |
544 | else | 544 | else |
545 | { | 545 | { |
546 | /* This inverts the alpha channel in GGAA */ | 546 | /* This inverts the alpha channel in GGAA */ |
547 | png_bytep sp, dp; | 547 | png_bytep sp, dp; |
548 | png_uint_32 i; | 548 | png_uint_32 i; |
549 | png_uint_32 row_width = row_info->width; | 549 | png_uint_32 row_width = row_info->width; |
550 | 550 | ||
551 | for (i = 0, sp = dp = row; i < row_width; i++) | 551 | for (i = 0, sp = dp = row; i < row_width; i++) |
552 | { | 552 | { |
553 | /* Does nothing | 553 | /* Does nothing |
554 | *(dp++) = *(sp++); | 554 | *(dp++) = *(sp++); |
555 | *(dp++) = *(sp++); | 555 | *(dp++) = *(sp++); |
556 | */ | 556 | */ |
557 | sp+=2; dp = sp; | 557 | sp+=2; dp = sp; |
558 | *(dp++) = (png_byte)(255 - *(sp++)); | 558 | *(dp++) = (png_byte)(255 - *(sp++)); |
559 | *(dp++) = (png_byte)(255 - *(sp++)); | 559 | *(dp++) = (png_byte)(255 - *(sp++)); |
560 | } | 560 | } |
561 | } | 561 | } |
562 | #endif /* PNG_WRITE_16BIT_SUPPORTED */ | 562 | #endif /* PNG_WRITE_16BIT_SUPPORTED */ |
563 | } | 563 | } |
564 | } | 564 | } |
565 | } | 565 | } |
566 | #endif | 566 | #endif |
567 | #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */ | 567 | #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */ |
568 | 568 | ||
569 | #ifdef PNG_MNG_FEATURES_SUPPORTED | 569 | #ifdef PNG_MNG_FEATURES_SUPPORTED |
570 | /* Undoes intrapixel differencing */ | 570 | /* Undoes intrapixel differencing */ |
571 | void /* PRIVATE */ | 571 | void /* PRIVATE */ |
572 | png_do_write_intrapixel(png_row_infop row_info, png_bytep row) | 572 | png_do_write_intrapixel(png_row_infop row_info, png_bytep row) |
573 | { | 573 | { |
574 | png_debug(1, "in png_do_write_intrapixel"); | 574 | png_debug(1, "in png_do_write_intrapixel"); |
575 | 575 | ||
576 | if ((row_info->color_type & PNG_COLOR_MASK_COLOR)) | 576 | if ((row_info->color_type & PNG_COLOR_MASK_COLOR)) |
577 | { | 577 | { |
578 | int bytes_per_pixel; | 578 | int bytes_per_pixel; |
579 | png_uint_32 row_width = row_info->width; | 579 | png_uint_32 row_width = row_info->width; |
580 | if (row_info->bit_depth == 8) | 580 | if (row_info->bit_depth == 8) |
581 | { | 581 | { |
582 | png_bytep rp; | 582 | png_bytep rp; |
583 | png_uint_32 i; | 583 | png_uint_32 i; |
584 | 584 | ||
585 | if (row_info->color_type == PNG_COLOR_TYPE_RGB) | 585 | if (row_info->color_type == PNG_COLOR_TYPE_RGB) |
586 | bytes_per_pixel = 3; | 586 | bytes_per_pixel = 3; |
587 | 587 | ||
588 | else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | 588 | else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
589 | bytes_per_pixel = 4; | 589 | bytes_per_pixel = 4; |
590 | 590 | ||
591 | else | 591 | else |
592 | return; | 592 | return; |
593 | 593 | ||
594 | for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) | 594 | for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) |
595 | { | 595 | { |
596 | *(rp) = (png_byte)((*rp - *(rp + 1)) & 0xff); | 596 | *(rp) = (png_byte)((*rp - *(rp + 1)) & 0xff); |
597 | *(rp + 2) = (png_byte)((*(rp + 2) - *(rp + 1)) & 0xff); | 597 | *(rp + 2) = (png_byte)((*(rp + 2) - *(rp + 1)) & 0xff); |
598 | } | 598 | } |
599 | } | 599 | } |
600 | 600 | ||
601 | #ifdef PNG_WRITE_16BIT_SUPPORTED | 601 | #ifdef PNG_WRITE_16BIT_SUPPORTED |
602 | else if (row_info->bit_depth == 16) | 602 | else if (row_info->bit_depth == 16) |
603 | { | 603 | { |
604 | png_bytep rp; | 604 | png_bytep rp; |
605 | png_uint_32 i; | 605 | png_uint_32 i; |
606 | 606 | ||
607 | if (row_info->color_type == PNG_COLOR_TYPE_RGB) | 607 | if (row_info->color_type == PNG_COLOR_TYPE_RGB) |
608 | bytes_per_pixel = 6; | 608 | bytes_per_pixel = 6; |
609 | 609 | ||
610 | else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | 610 | else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
611 | bytes_per_pixel = 8; | 611 | bytes_per_pixel = 8; |
612 | 612 | ||
613 | else | 613 | else |
614 | return; | 614 | return; |
615 | 615 | ||
616 | for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) | 616 | for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) |
617 | { | 617 | { |
618 | png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1); | 618 | png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1); |
619 | png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3); | 619 | png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3); |
620 | png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5); | 620 | png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5); |
621 | png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL); | 621 | png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL); |
622 | png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL); | 622 | png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL); |
623 | *(rp ) = (png_byte)((red >> 8) & 0xff); | 623 | *(rp ) = (png_byte)((red >> 8) & 0xff); |
624 | *(rp + 1) = (png_byte)(red & 0xff); | 624 | *(rp + 1) = (png_byte)(red & 0xff); |
625 | *(rp + 4) = (png_byte)((blue >> 8) & 0xff); | 625 | *(rp + 4) = (png_byte)((blue >> 8) & 0xff); |
626 | *(rp + 5) = (png_byte)(blue & 0xff); | 626 | *(rp + 5) = (png_byte)(blue & 0xff); |
627 | } | 627 | } |
628 | } | 628 | } |
629 | #endif /* PNG_WRITE_16BIT_SUPPORTED */ | 629 | #endif /* PNG_WRITE_16BIT_SUPPORTED */ |
630 | } | 630 | } |
631 | } | 631 | } |
632 | #endif /* PNG_MNG_FEATURES_SUPPORTED */ | 632 | #endif /* PNG_MNG_FEATURES_SUPPORTED */ |
633 | #endif /* PNG_WRITE_SUPPORTED */ | 633 | #endif /* PNG_WRITE_SUPPORTED */ |