| OLD | NEW |
| 1 | 1 |
| 2 /* pngwtran.c - transforms the data in a row for PNG writers | 2 /* pngwtran.c - transforms the data in a row for PNG writers |
| 3 * | 3 * |
| 4 * Last changed in libpng 1.2.9 April 14, 2006 | 4 * Last changed in libpng 1.2.37 [June 4, 2009] |
| 5 * For conditions of distribution and use, see copyright notice in png.h | 5 * For conditions of distribution and use, see copyright notice in png.h |
| 6 * Copyright (c) 1998-2006 Glenn Randers-Pehrson | 6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson |
| 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
| 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #define PNG_INTERNAL | 11 #define PNG_INTERNAL |
| 12 #include "png.h" | 12 #include "png.h" |
| 13 #ifdef PNG_WRITE_SUPPORTED | 13 #ifdef PNG_WRITE_SUPPORTED |
| 14 | 14 |
| 15 /* Transform the data according to the user's wishes. The order of | 15 /* Transform the data according to the user's wishes. The order of |
| 16 * transformations is significant. | 16 * transformations is significant. |
| 17 */ | 17 */ |
| 18 void /* PRIVATE */ | 18 void /* PRIVATE */ |
| 19 png_do_write_transformations(png_structp png_ptr) | 19 png_do_write_transformations(png_structp png_ptr) |
| 20 { | 20 { |
| 21 png_debug(1, "in png_do_write_transformations"); | 21 png_debug(1, "in png_do_write_transformations"); |
| 22 | 22 |
| 23 if (png_ptr == NULL) | 23 if (png_ptr == NULL) |
| 24 return; | 24 return; |
| 25 | 25 |
| 26 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) | 26 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
| 27 if (png_ptr->transformations & PNG_USER_TRANSFORM) | 27 if (png_ptr->transformations & PNG_USER_TRANSFORM) |
| 28 if (png_ptr->write_user_transform_fn != NULL) | 28 if (png_ptr->write_user_transform_fn != NULL) |
| 29 (*(png_ptr->write_user_transform_fn)) /* user write transform function *
/ | 29 (*(png_ptr->write_user_transform_fn)) /* User write transform function *
/ |
| 30 (png_ptr, /* png_ptr */ | 30 (png_ptr, /* png_ptr */ |
| 31 &(png_ptr->row_info), /* row_info: */ | 31 &(png_ptr->row_info), /* row_info: */ |
| 32 /* png_uint_32 width; width of row */ | 32 /* png_uint_32 width; width of row */ |
| 33 /* png_uint_32 rowbytes; number of bytes in row */ | 33 /* png_uint_32 rowbytes; number of bytes in row */ |
| 34 /* png_byte color_type; color type of pixels */ | 34 /* png_byte color_type; color type of pixels */ |
| 35 /* png_byte bit_depth; bit depth of samples */ | 35 /* png_byte bit_depth; bit depth of samples */ |
| 36 /* png_byte channels; number of channels (1-4) */ | 36 /* png_byte channels; number of channels (1-4) */ |
| 37 /* png_byte pixel_depth; bits per pixel (depth*channels) */ | 37 /* png_byte pixel_depth; bits per pixel (depth*channels) */ |
| 38 png_ptr->row_buf + 1); /* start of pixel data for row */ | 38 png_ptr->row_buf + 1); /* start of pixel data for row */ |
| 39 #endif | 39 #endif |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 shift_dec[channels] = bit_depth->gray; | 241 shift_dec[channels] = bit_depth->gray; |
| 242 channels++; | 242 channels++; |
| 243 } | 243 } |
| 244 if (row_info->color_type & PNG_COLOR_MASK_ALPHA) | 244 if (row_info->color_type & PNG_COLOR_MASK_ALPHA) |
| 245 { | 245 { |
| 246 shift_start[channels] = row_info->bit_depth - bit_depth->alpha; | 246 shift_start[channels] = row_info->bit_depth - bit_depth->alpha; |
| 247 shift_dec[channels] = bit_depth->alpha; | 247 shift_dec[channels] = bit_depth->alpha; |
| 248 channels++; | 248 channels++; |
| 249 } | 249 } |
| 250 | 250 |
| 251 /* with low row depths, could only be grayscale, so one channel */ | 251 /* With low row depths, could only be grayscale, so one channel */ |
| 252 if (row_info->bit_depth < 8) | 252 if (row_info->bit_depth < 8) |
| 253 { | 253 { |
| 254 png_bytep bp = row; | 254 png_bytep bp = row; |
| 255 png_uint_32 i; | 255 png_uint_32 i; |
| 256 png_byte mask; | 256 png_byte mask; |
| 257 png_uint_32 row_bytes = row_info->rowbytes; | 257 png_uint_32 row_bytes = row_info->rowbytes; |
| 258 | 258 |
| 259 if (bit_depth->gray == 1 && row_info->bit_depth == 2) | 259 if (bit_depth->gray == 1 && row_info->bit_depth == 2) |
| 260 mask = 0x55; | 260 mask = 0x55; |
| 261 else if (row_info->bit_depth == 4 && bit_depth->gray == 3) | 261 else if (row_info->bit_depth == 4 && bit_depth->gray == 3) |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | 432 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
| 433 { | 433 { |
| 434 /* This inverts the alpha channel in RGBA */ | 434 /* This inverts the alpha channel in RGBA */ |
| 435 if (row_info->bit_depth == 8) | 435 if (row_info->bit_depth == 8) |
| 436 { | 436 { |
| 437 png_bytep sp, dp; | 437 png_bytep sp, dp; |
| 438 png_uint_32 i; | 438 png_uint_32 i; |
| 439 png_uint_32 row_width = row_info->width; | 439 png_uint_32 row_width = row_info->width; |
| 440 for (i = 0, sp = dp = row; i < row_width; i++) | 440 for (i = 0, sp = dp = row; i < row_width; i++) |
| 441 { | 441 { |
| 442 /* does nothing | 442 /* Does nothing |
| 443 *(dp++) = *(sp++); | 443 *(dp++) = *(sp++); |
| 444 *(dp++) = *(sp++); | 444 *(dp++) = *(sp++); |
| 445 *(dp++) = *(sp++); | 445 *(dp++) = *(sp++); |
| 446 */ | 446 */ |
| 447 sp+=3; dp = sp; | 447 sp+=3; dp = sp; |
| 448 *(dp++) = (png_byte)(255 - *(sp++)); | 448 *(dp++) = (png_byte)(255 - *(sp++)); |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 /* This inverts the alpha channel in RRGGBBAA */ | 451 /* This inverts the alpha channel in RRGGBBAA */ |
| 452 else | 452 else |
| 453 { | 453 { |
| 454 png_bytep sp, dp; | 454 png_bytep sp, dp; |
| 455 png_uint_32 i; | 455 png_uint_32 i; |
| 456 png_uint_32 row_width = row_info->width; | 456 png_uint_32 row_width = row_info->width; |
| 457 | 457 |
| 458 for (i = 0, sp = dp = row; i < row_width; i++) | 458 for (i = 0, sp = dp = row; i < row_width; i++) |
| 459 { | 459 { |
| 460 /* does nothing | 460 /* Does nothing |
| 461 *(dp++) = *(sp++); | 461 *(dp++) = *(sp++); |
| 462 *(dp++) = *(sp++); | 462 *(dp++) = *(sp++); |
| 463 *(dp++) = *(sp++); | 463 *(dp++) = *(sp++); |
| 464 *(dp++) = *(sp++); | 464 *(dp++) = *(sp++); |
| 465 *(dp++) = *(sp++); | 465 *(dp++) = *(sp++); |
| 466 *(dp++) = *(sp++); | 466 *(dp++) = *(sp++); |
| 467 */ | 467 */ |
| 468 sp+=6; dp = sp; | 468 sp+=6; dp = sp; |
| 469 *(dp++) = (png_byte)(255 - *(sp++)); | 469 *(dp++) = (png_byte)(255 - *(sp++)); |
| 470 *(dp++) = (png_byte)(255 - *(sp++)); | 470 *(dp++) = (png_byte)(255 - *(sp++)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 488 } | 488 } |
| 489 /* This inverts the alpha channel in GGAA */ | 489 /* This inverts the alpha channel in GGAA */ |
| 490 else | 490 else |
| 491 { | 491 { |
| 492 png_bytep sp, dp; | 492 png_bytep sp, dp; |
| 493 png_uint_32 i; | 493 png_uint_32 i; |
| 494 png_uint_32 row_width = row_info->width; | 494 png_uint_32 row_width = row_info->width; |
| 495 | 495 |
| 496 for (i = 0, sp = dp = row; i < row_width; i++) | 496 for (i = 0, sp = dp = row; i < row_width; i++) |
| 497 { | 497 { |
| 498 /* does nothing | 498 /* Does nothing |
| 499 *(dp++) = *(sp++); | 499 *(dp++) = *(sp++); |
| 500 *(dp++) = *(sp++); | 500 *(dp++) = *(sp++); |
| 501 */ | 501 */ |
| 502 sp+=2; dp = sp; | 502 sp+=2; dp = sp; |
| 503 *(dp++) = (png_byte)(255 - *(sp++)); | 503 *(dp++) = (png_byte)(255 - *(sp++)); |
| 504 *(dp++) = (png_byte)(255 - *(sp++)); | 504 *(dp++) = (png_byte)(255 - *(sp++)); |
| 505 } | 505 } |
| 506 } | 506 } |
| 507 } | 507 } |
| 508 } | 508 } |
| 509 } | 509 } |
| 510 #endif | 510 #endif |
| 511 | 511 |
| 512 #if defined(PNG_MNG_FEATURES_SUPPORTED) | 512 #if defined(PNG_MNG_FEATURES_SUPPORTED) |
| 513 /* undoes intrapixel differencing */ | 513 /* Undoes intrapixel differencing */ |
| 514 void /* PRIVATE */ | 514 void /* PRIVATE */ |
| 515 png_do_write_intrapixel(png_row_infop row_info, png_bytep row) | 515 png_do_write_intrapixel(png_row_infop row_info, png_bytep row) |
| 516 { | 516 { |
| 517 png_debug(1, "in png_do_write_intrapixel"); | 517 png_debug(1, "in png_do_write_intrapixel"); |
| 518 if ( | 518 if ( |
| 519 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 519 #if defined(PNG_USELESS_TESTS_SUPPORTED) |
| 520 row != NULL && row_info != NULL && | 520 row != NULL && row_info != NULL && |
| 521 #endif | 521 #endif |
| 522 (row_info->color_type & PNG_COLOR_MASK_COLOR)) | 522 (row_info->color_type & PNG_COLOR_MASK_COLOR)) |
| 523 { | 523 { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 *(rp ) = (png_byte)((red >> 8) & 0xff); | 563 *(rp ) = (png_byte)((red >> 8) & 0xff); |
| 564 *(rp+1) = (png_byte)(red & 0xff); | 564 *(rp+1) = (png_byte)(red & 0xff); |
| 565 *(rp+4) = (png_byte)((blue >> 8) & 0xff); | 565 *(rp+4) = (png_byte)((blue >> 8) & 0xff); |
| 566 *(rp+5) = (png_byte)(blue & 0xff); | 566 *(rp+5) = (png_byte)(blue & 0xff); |
| 567 } | 567 } |
| 568 } | 568 } |
| 569 } | 569 } |
| 570 } | 570 } |
| 571 #endif /* PNG_MNG_FEATURES_SUPPORTED */ | 571 #endif /* PNG_MNG_FEATURES_SUPPORTED */ |
| 572 #endif /* PNG_WRITE_SUPPORTED */ | 572 #endif /* PNG_WRITE_SUPPORTED */ |
| OLD | NEW |