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 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 | 724 |
725 bool InternalEncodeSkBitmap(const SkBitmap& input, | 725 bool InternalEncodeSkBitmap(const SkBitmap& input, |
726 bool discard_transparency, | 726 bool discard_transparency, |
727 int compression_level, | 727 int compression_level, |
728 std::vector<unsigned char>* output) { | 728 std::vector<unsigned char>* output) { |
729 if (input.empty() || input.isNull()) | 729 if (input.empty() || input.isNull()) |
730 return false; | 730 return false; |
731 int bpp = input.bytesPerPixel(); | 731 int bpp = input.bytesPerPixel(); |
732 DCHECK(bpp == 1 || bpp == 4); // We support kA8_Config and kARGB_8888_Config. | 732 DCHECK(bpp == 1 || bpp == 4); // We support kA8_Config and kARGB_8888_Config. |
733 | 733 |
734 SkAutoLockPixels lock_input(input); | |
735 unsigned char* inputAddr = bpp == 1 ? | 734 unsigned char* inputAddr = bpp == 1 ? |
736 reinterpret_cast<unsigned char*>(input.getAddr8(0, 0)) : | 735 reinterpret_cast<unsigned char*>(input.getAddr8(0, 0)) : |
737 reinterpret_cast<unsigned char*>(input.getAddr32(0, 0)); // bpp = 4 | 736 reinterpret_cast<unsigned char*>(input.getAddr32(0, 0)); // bpp = 4 |
738 return EncodeWithCompressionLevel( | 737 return EncodeWithCompressionLevel( |
739 inputAddr, | 738 inputAddr, |
740 PNGCodec::FORMAT_SkBitmap, | 739 PNGCodec::FORMAT_SkBitmap, |
741 Size(input.width(), input.height()), | 740 Size(input.width(), input.height()), |
742 static_cast<int>(input.rowBytes()), | 741 static_cast<int>(input.rowBytes()), |
743 discard_transparency, | 742 discard_transparency, |
744 std::vector<PNGCodec::Comment>(), | 743 std::vector<PNGCodec::Comment>(), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 } | 796 } |
798 | 797 |
799 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) | 798 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) |
800 : key(k), text(t) { | 799 : key(k), text(t) { |
801 } | 800 } |
802 | 801 |
803 PNGCodec::Comment::~Comment() { | 802 PNGCodec::Comment::~Comment() { |
804 } | 803 } |
805 | 804 |
806 } // namespace gfx | 805 } // namespace gfx |
OLD | NEW |