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