OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/codec/png_codec.h" | 5 #include "ui/gfx/codec/png_codec.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 input_has_alpha = true; | 199 input_has_alpha = true; |
200 } | 200 } |
201 | 201 |
202 // Convert 16-bit to 8-bit. | 202 // Convert 16-bit to 8-bit. |
203 if (bit_depth == 16) | 203 if (bit_depth == 16) |
204 png_set_strip_16(png_ptr); | 204 png_set_strip_16(png_ptr); |
205 | 205 |
206 // Pick our row format converter necessary for this data. | 206 // Pick our row format converter necessary for this data. |
207 if (!input_has_alpha) { | 207 if (!input_has_alpha) { |
208 switch (state->output_format) { | 208 switch (state->output_format) { |
209 case PNGCodec::FORMAT_RGB: | |
210 state->output_channels = 3; | |
211 break; | |
212 case PNGCodec::FORMAT_RGBA: | 209 case PNGCodec::FORMAT_RGBA: |
213 state->output_channels = 4; | 210 state->output_channels = 4; |
214 png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER); | 211 png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER); |
215 break; | 212 break; |
216 case PNGCodec::FORMAT_BGRA: | 213 case PNGCodec::FORMAT_BGRA: |
217 state->output_channels = 4; | 214 state->output_channels = 4; |
218 png_set_bgr(png_ptr); | 215 png_set_bgr(png_ptr); |
219 png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER); | 216 png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER); |
220 break; | 217 break; |
221 case PNGCodec::FORMAT_SkBitmap: | 218 case PNGCodec::FORMAT_SkBitmap: |
222 state->output_channels = 4; | 219 state->output_channels = 4; |
223 png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER); | 220 png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER); |
224 break; | 221 break; |
225 } | 222 } |
226 } else { | 223 } else { |
227 switch (state->output_format) { | 224 switch (state->output_format) { |
228 case PNGCodec::FORMAT_RGB: | |
229 state->output_channels = 3; | |
230 png_set_strip_alpha(png_ptr); | |
231 break; | |
232 case PNGCodec::FORMAT_RGBA: | 225 case PNGCodec::FORMAT_RGBA: |
233 state->output_channels = 4; | 226 state->output_channels = 4; |
234 break; | 227 break; |
235 case PNGCodec::FORMAT_BGRA: | 228 case PNGCodec::FORMAT_BGRA: |
236 state->output_channels = 4; | 229 state->output_channels = 4; |
237 png_set_bgr(png_ptr); | 230 png_set_bgr(png_ptr); |
238 break; | 231 break; |
239 case PNGCodec::FORMAT_SkBitmap: | 232 case PNGCodec::FORMAT_SkBitmap: |
240 state->output_channels = 4; | 233 state->output_channels = 4; |
241 break; | 234 break; |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 const std::vector<PNGCodec::Comment>& comments, | 620 const std::vector<PNGCodec::Comment>& comments, |
628 int compression_level, | 621 int compression_level, |
629 std::vector<unsigned char>* output) { | 622 std::vector<unsigned char>* output) { |
630 // Run to convert an input row into the output row format, NULL means no | 623 // Run to convert an input row into the output row format, NULL means no |
631 // conversion is necessary. | 624 // conversion is necessary. |
632 FormatConverter converter = NULL; | 625 FormatConverter converter = NULL; |
633 | 626 |
634 int input_color_components, output_color_components; | 627 int input_color_components, output_color_components; |
635 int png_output_color_type; | 628 int png_output_color_type; |
636 switch (format) { | 629 switch (format) { |
637 case PNGCodec::FORMAT_RGB: | |
638 input_color_components = 3; | |
639 output_color_components = 3; | |
640 png_output_color_type = PNG_COLOR_TYPE_RGB; | |
641 break; | |
642 | |
643 case PNGCodec::FORMAT_RGBA: | 630 case PNGCodec::FORMAT_RGBA: |
644 input_color_components = 4; | 631 input_color_components = 4; |
645 if (discard_transparency) { | 632 if (discard_transparency) { |
646 output_color_components = 3; | 633 output_color_components = 3; |
647 png_output_color_type = PNG_COLOR_TYPE_RGB; | 634 png_output_color_type = PNG_COLOR_TYPE_RGB; |
648 converter = ConvertRGBAtoRGB; | 635 converter = ConvertRGBAtoRGB; |
649 } else { | 636 } else { |
650 output_color_components = 4; | 637 output_color_components = 4; |
651 png_output_color_type = PNG_COLOR_TYPE_RGB_ALPHA; | 638 png_output_color_type = PNG_COLOR_TYPE_RGB_ALPHA; |
652 converter = NULL; | 639 converter = NULL; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 } | 783 } |
797 | 784 |
798 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) | 785 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) |
799 : key(k), text(t) { | 786 : key(k), text(t) { |
800 } | 787 } |
801 | 788 |
802 PNGCodec::Comment::~Comment() { | 789 PNGCodec::Comment::~Comment() { |
803 } | 790 } |
804 | 791 |
805 } // namespace gfx | 792 } // namespace gfx |
OLD | NEW |