| 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; |
| 209 case PNGCodec::FORMAT_RGBA: | 212 case PNGCodec::FORMAT_RGBA: |
| 210 state->output_channels = 4; | 213 state->output_channels = 4; |
| 211 png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER); | 214 png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER); |
| 212 break; | 215 break; |
| 213 case PNGCodec::FORMAT_BGRA: | 216 case PNGCodec::FORMAT_BGRA: |
| 214 state->output_channels = 4; | 217 state->output_channels = 4; |
| 215 png_set_bgr(png_ptr); | 218 png_set_bgr(png_ptr); |
| 216 png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER); | 219 png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER); |
| 217 break; | 220 break; |
| 218 case PNGCodec::FORMAT_SkBitmap: | 221 case PNGCodec::FORMAT_SkBitmap: |
| 219 state->output_channels = 4; | 222 state->output_channels = 4; |
| 220 png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER); | 223 png_set_add_alpha(png_ptr, 0xFF, PNG_FILLER_AFTER); |
| 221 break; | 224 break; |
| 222 } | 225 } |
| 223 } else { | 226 } else { |
| 224 switch (state->output_format) { | 227 switch (state->output_format) { |
| 228 case PNGCodec::FORMAT_RGB: |
| 229 state->output_channels = 3; |
| 230 png_set_strip_alpha(png_ptr); |
| 231 break; |
| 225 case PNGCodec::FORMAT_RGBA: | 232 case PNGCodec::FORMAT_RGBA: |
| 226 state->output_channels = 4; | 233 state->output_channels = 4; |
| 227 break; | 234 break; |
| 228 case PNGCodec::FORMAT_BGRA: | 235 case PNGCodec::FORMAT_BGRA: |
| 229 state->output_channels = 4; | 236 state->output_channels = 4; |
| 230 png_set_bgr(png_ptr); | 237 png_set_bgr(png_ptr); |
| 231 break; | 238 break; |
| 232 case PNGCodec::FORMAT_SkBitmap: | 239 case PNGCodec::FORMAT_SkBitmap: |
| 233 state->output_channels = 4; | 240 state->output_channels = 4; |
| 234 break; | 241 break; |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 const std::vector<PNGCodec::Comment>& comments, | 627 const std::vector<PNGCodec::Comment>& comments, |
| 621 int compression_level, | 628 int compression_level, |
| 622 std::vector<unsigned char>* output) { | 629 std::vector<unsigned char>* output) { |
| 623 // Run to convert an input row into the output row format, NULL means no | 630 // Run to convert an input row into the output row format, NULL means no |
| 624 // conversion is necessary. | 631 // conversion is necessary. |
| 625 FormatConverter converter = NULL; | 632 FormatConverter converter = NULL; |
| 626 | 633 |
| 627 int input_color_components, output_color_components; | 634 int input_color_components, output_color_components; |
| 628 int png_output_color_type; | 635 int png_output_color_type; |
| 629 switch (format) { | 636 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 |
| 630 case PNGCodec::FORMAT_RGBA: | 643 case PNGCodec::FORMAT_RGBA: |
| 631 input_color_components = 4; | 644 input_color_components = 4; |
| 632 if (discard_transparency) { | 645 if (discard_transparency) { |
| 633 output_color_components = 3; | 646 output_color_components = 3; |
| 634 png_output_color_type = PNG_COLOR_TYPE_RGB; | 647 png_output_color_type = PNG_COLOR_TYPE_RGB; |
| 635 converter = ConvertRGBAtoRGB; | 648 converter = ConvertRGBAtoRGB; |
| 636 } else { | 649 } else { |
| 637 output_color_components = 4; | 650 output_color_components = 4; |
| 638 png_output_color_type = PNG_COLOR_TYPE_RGB_ALPHA; | 651 png_output_color_type = PNG_COLOR_TYPE_RGB_ALPHA; |
| 639 converter = NULL; | 652 converter = NULL; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 } | 796 } |
| 784 | 797 |
| 785 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) | 798 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) |
| 786 : key(k), text(t) { | 799 : key(k), text(t) { |
| 787 } | 800 } |
| 788 | 801 |
| 789 PNGCodec::Comment::~Comment() { | 802 PNGCodec::Comment::~Comment() { |
| 790 } | 803 } |
| 791 | 804 |
| 792 } // namespace gfx | 805 } // namespace gfx |
| OLD | NEW |