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.37 [June 4, 2009] |
4 * Last changed in libpng 1.4.0 [January 3, 2010] |
5 * Copyright (c) 1998-2009 Glenn Randers-Pehrson |
5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson |
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
8 * |
8 * |
9 * This code is released under the libpng license. |
9 * This code is released under the libpng license. |
10 * For conditions of distribution and use, see the disclaimer |
10 * For conditions of distribution and use, see the disclaimer |
11 * and license in png.h |
11 * and license in png.h |
12 */ |
12 */ |
13 |
13 |
14 #define PNG_INTERNAL |
14 #define PNG_NO_PEDANTIC_WARNINGS |
15 #include "png.h" |
15 #include "png.h" |
16 #ifdef PNG_WRITE_SUPPORTED |
16 #ifdef PNG_WRITE_SUPPORTED |
|
17 #include "pngpriv.h" |
17 |
18 |
18 /* Transform the data according to the user's wishes. The order of |
19 /* Transform the data according to the user's wishes. The order of |
19 * transformations is significant. |
20 * transformations is significant. |
20 */ |
21 */ |
21 void /* PRIVATE */ |
22 void /* PRIVATE */ |
38 /* png_byte bit_depth; bit depth of samples */ |
39 /* png_byte bit_depth; bit depth of samples */ |
39 /* png_byte channels; number of channels (1-4) */ |
40 /* png_byte channels; number of channels (1-4) */ |
40 /* png_byte pixel_depth; bits per pixel (depth*channels) */ |
41 /* png_byte pixel_depth; bits per pixel (depth*channels) */ |
41 png_ptr->row_buf + 1); /* start of pixel data for row */ |
42 png_ptr->row_buf + 1); /* start of pixel data for row */ |
42 #endif |
43 #endif |
43 #if defined(PNG_WRITE_FILLER_SUPPORTED) |
44 #ifdef PNG_WRITE_FILLER_SUPPORTED |
44 if (png_ptr->transformations & PNG_FILLER) |
45 if (png_ptr->transformations & PNG_FILLER) |
45 png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, |
46 png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, |
46 png_ptr->flags); |
47 png_ptr->flags); |
47 #endif |
48 #endif |
48 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) |
49 #ifdef PNG_WRITE_PACKSWAP_SUPPORTED |
49 if (png_ptr->transformations & PNG_PACKSWAP) |
50 if (png_ptr->transformations & PNG_PACKSWAP) |
50 png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1); |
51 png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1); |
51 #endif |
52 #endif |
52 #if defined(PNG_WRITE_PACK_SUPPORTED) |
53 #ifdef PNG_WRITE_PACK_SUPPORTED |
53 if (png_ptr->transformations & PNG_PACK) |
54 if (png_ptr->transformations & PNG_PACK) |
54 png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1, |
55 png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1, |
55 (png_uint_32)png_ptr->bit_depth); |
56 (png_uint_32)png_ptr->bit_depth); |
56 #endif |
57 #endif |
57 #if defined(PNG_WRITE_SWAP_SUPPORTED) |
58 #ifdef PNG_WRITE_SWAP_SUPPORTED |
58 if (png_ptr->transformations & PNG_SWAP_BYTES) |
59 if (png_ptr->transformations & PNG_SWAP_BYTES) |
59 png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); |
60 png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); |
60 #endif |
61 #endif |
61 #if defined(PNG_WRITE_SHIFT_SUPPORTED) |
62 #ifdef PNG_WRITE_SHIFT_SUPPORTED |
62 if (png_ptr->transformations & PNG_SHIFT) |
63 if (png_ptr->transformations & PNG_SHIFT) |
63 png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1, |
64 png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1, |
64 &(png_ptr->shift)); |
65 &(png_ptr->shift)); |
65 #endif |
66 #endif |
66 #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) |
67 #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED |
67 if (png_ptr->transformations & PNG_SWAP_ALPHA) |
68 if (png_ptr->transformations & PNG_SWAP_ALPHA) |
68 png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); |
69 png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); |
69 #endif |
70 #endif |
70 #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) |
71 #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED |
71 if (png_ptr->transformations & PNG_INVERT_ALPHA) |
72 if (png_ptr->transformations & PNG_INVERT_ALPHA) |
72 png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); |
73 png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); |
73 #endif |
74 #endif |
74 #if defined(PNG_WRITE_BGR_SUPPORTED) |
75 #ifdef PNG_WRITE_BGR_SUPPORTED |
75 if (png_ptr->transformations & PNG_BGR) |
76 if (png_ptr->transformations & PNG_BGR) |
76 png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1); |
77 png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1); |
77 #endif |
78 #endif |
78 #if defined(PNG_WRITE_INVERT_SUPPORTED) |
79 #ifdef PNG_WRITE_INVERT_SUPPORTED |
79 if (png_ptr->transformations & PNG_INVERT_MONO) |
80 if (png_ptr->transformations & PNG_INVERT_MONO) |
80 png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1); |
81 png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1); |
81 #endif |
82 #endif |
82 } |
83 } |
83 |
84 |
84 #if defined(PNG_WRITE_PACK_SUPPORTED) |
85 #ifdef PNG_WRITE_PACK_SUPPORTED |
85 /* Pack pixels into bytes. Pass the true bit depth in bit_depth. The |
86 /* Pack pixels into bytes. Pass the true bit depth in bit_depth. The |
86 * row_info bit depth should be 8 (one pixel per byte). The channels |
87 * row_info bit depth should be 8 (one pixel per byte). The channels |
87 * should be 1 (this only happens on grayscale and paletted images). |
88 * should be 1 (this only happens on grayscale and paletted images). |
88 */ |
89 */ |
89 void /* PRIVATE */ |
90 void /* PRIVATE */ |
90 png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) |
91 png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) |
91 { |
92 { |
92 png_debug(1, "in png_do_pack"); |
93 png_debug(1, "in png_do_pack"); |
|
94 |
93 if (row_info->bit_depth == 8 && |
95 if (row_info->bit_depth == 8 && |
94 #if defined(PNG_USELESS_TESTS_SUPPORTED) |
|
95 row != NULL && row_info != NULL && |
|
96 #endif |
|
97 row_info->channels == 1) |
96 row_info->channels == 1) |
98 { |
97 { |
99 switch ((int)bit_depth) |
98 switch ((int)bit_depth) |
100 { |
99 { |
101 case 1: |
100 case 1: |