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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "ui/gfx/size.h" | 9 #include "ui/gfx/size.h" |
10 #include "ui/gfx/skia_util.h" | 10 #include "ui/gfx/skia_util.h" |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 // static | 761 // static |
762 bool PNGCodec::EncodeBGRASkBitmap(const SkBitmap& input, | 762 bool PNGCodec::EncodeBGRASkBitmap(const SkBitmap& input, |
763 bool discard_transparency, | 763 bool discard_transparency, |
764 std::vector<unsigned char>* output) { | 764 std::vector<unsigned char>* output) { |
765 static const int bbp = 4; | 765 static const int bbp = 4; |
766 | 766 |
767 SkAutoLockPixels lock_input(input); | 767 SkAutoLockPixels lock_input(input); |
768 if (input.empty()) | 768 if (input.empty()) |
769 return false; | 769 return false; |
770 DCHECK(input.bytesPerPixel() == bbp); | 770 DCHECK(input.bytesPerPixel() == bbp); |
| 771 DCHECK(static_cast<int>(input.rowBytes()) >= input.width() * bbp); |
771 | 772 |
772 return Encode(reinterpret_cast<unsigned char*>(input.getAddr32(0, 0)), | 773 return Encode(reinterpret_cast<unsigned char*>(input.getAddr32(0, 0)), |
773 FORMAT_SkBitmap, Size(input.width(), input.height()), | 774 FORMAT_SkBitmap, Size(input.width(), input.height()), |
774 input.width() * bbp, discard_transparency, | 775 static_cast<int>(input.rowBytes()), discard_transparency, |
775 std::vector<Comment>(), output); | 776 std::vector<Comment>(), output); |
776 } | 777 } |
777 | 778 |
778 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) | 779 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) |
779 : key(k), text(t) { | 780 : key(k), text(t) { |
780 } | 781 } |
781 | 782 |
782 PNGCodec::Comment::~Comment() { | 783 PNGCodec::Comment::~Comment() { |
783 } | 784 } |
784 | 785 |
785 } // namespace gfx | 786 } // namespace gfx |
OLD | NEW |