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