Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: ui/gfx/codec/png_codec.cc

Issue 2944633002: Use SkPngEncoder in gfx jpeg_codec (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698