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