istereo

annotate libs/libpng/pngwtran.c @ 43:73813c1176de

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