Chromium Code Reviews| Index: ui/gfx/codec/png_codec.cc |
| diff --git a/ui/gfx/codec/png_codec.cc b/ui/gfx/codec/png_codec.cc |
| index fe4020596fc9c3ba32609719060a727554b07e81..deb78b395951d2ce34e1c622bc555e95750bfa6d 100644 |
| --- a/ui/gfx/codec/png_codec.cc |
| +++ b/ui/gfx/codec/png_codec.cc |
| @@ -3,6 +3,7 @@ |
| // found in the LICENSE file. |
| #include "ui/gfx/codec/png_codec.h" |
| +#include "ui/gfx/codec/codec_priv.h" |
| #include <stdint.h> |
| @@ -13,6 +14,7 @@ |
| #include "third_party/skia/include/core/SkBitmap.h" |
| #include "third_party/skia/include/core/SkColorPriv.h" |
| #include "third_party/skia/include/core/SkUnPreMultiply.h" |
| +#include "third_party/skia/include/encode/SkPngEncoder.h" |
| #include "third_party/zlib/zlib.h" |
| #include "ui/gfx/geometry/size.h" |
| #include "ui/gfx/skia_util.h" |
| @@ -732,25 +734,33 @@ bool InternalEncodeSkBitmap(const SkBitmap& input, |
| output); |
| } |
| +static void AddComments(SkPngEncoder::Options& options, |
| + const std::vector<PNGCodec::Comment>& comments) { |
| + std::vector<const char*> commentPointers; |
| + std::vector<size_t> commentSizes; |
| + for (const auto& comment : comments) { |
| + commentPointers.push_back(comment.key.c_str()); |
| + commentPointers.push_back(comment.text.c_str()); |
| + commentSizes.push_back(comment.key.length() + 1); |
| + commentSizes.push_back(comment.text.length() + 1); |
| + } |
| + options.fComments = |
| + SkDataTable::MakeCopyArrays((void const* const*)commentPointers.data(), |
| + commentSizes.data(), commentPointers.size()); |
| +} |
| } // namespace |
| // static |
| -bool PNGCodec::Encode(const unsigned char* input, |
| - ColorFormat format, |
| - const Size& size, |
| - int row_byte_width, |
| - bool discard_transparency, |
|
msarett1
2017/06/16 21:29:56
As we discussed in person, you'll have to find a w
liyuqian
2017/06/23 13:54:25
Done.
|
| +bool PNGCodec::Encode(const SkPixmap& src, |
| const std::vector<Comment>& comments, |
| std::vector<unsigned char>* output) { |
| - return EncodeWithCompressionLevel(input, |
| - format, |
| - size, |
| - row_byte_width, |
| - discard_transparency, |
| - comments, |
| - Z_DEFAULT_COMPRESSION, |
| - output); |
| + output->clear(); |
| + VectorWStream dst(output); |
| + |
| + SkPngEncoder::Options options; |
| + AddComments(options, comments); |
| + return SkPngEncoder::Encode(&dst, src, options); |
| } |
| // static |