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