istereo2

annotate libs/libpng/pngwtran.c @ 3:dc735bdeeb8a

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