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

Unified Diff: third_party/WebKit/Source/platform/image-encoders/ImageEncoder.cpp

Issue 2878333004: Use SkJpegEncoder in WebKit platform (Closed)
Patch Set: Create instead of Make Created 3 years, 7 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: third_party/WebKit/Source/platform/image-encoders/ImageEncoder.cpp
diff --git a/third_party/WebKit/Source/platform/image-encoders/ImageEncoder.cpp b/third_party/WebKit/Source/platform/image-encoders/ImageEncoder.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..708aa5a257c823d7bfe06f6a427981ad1780cd05
--- /dev/null
+++ b/third_party/WebKit/Source/platform/image-encoders/ImageEncoder.cpp
@@ -0,0 +1,57 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "platform/image-encoders/ImageEncoder.h"
+
+namespace blink {
+
+bool ImageEncoder::Encode(Vector<unsigned char>* dst,
+ const SkPixmap& src,
+ const SkJpegEncoder::Options& options) {
+ VectorWStream dst_stream(dst);
+ return SkJpegEncoder::Encode(&dst_stream, src, options);
+}
+
+bool ImageEncoder::Encode(Vector<unsigned char>* dst,
+ const SkPixmap& src,
+ const SkPngEncoder::Options& options) {
+ VectorWStream dst_stream(dst);
+ return SkPngEncoder::Encode(&dst_stream, src, options);
+}
+
+std::unique_ptr<ImageEncoder> ImageEncoder::Create(
+ Vector<unsigned char>* dst,
+ const SkPixmap& src,
+ const SkJpegEncoder::Options& options) {
+ std::unique_ptr<ImageEncoder> image_encoder(new ImageEncoder(dst));
+ image_encoder->encoder_ =
+ SkJpegEncoder::Make(&image_encoder->dst_, src, options);
+ if (!image_encoder->encoder_) {
+ return nullptr;
+ }
+
+ return image_encoder;
+}
+
+std::unique_ptr<ImageEncoder> ImageEncoder::Create(
+ Vector<unsigned char>* dst,
+ const SkPixmap& src,
+ const SkPngEncoder::Options& options) {
+ std::unique_ptr<ImageEncoder> image_encoder(new ImageEncoder(dst));
+ image_encoder->encoder_ =
+ SkPngEncoder::Make(&image_encoder->dst_, src, options);
+ if (!image_encoder->encoder_) {
+ return nullptr;
+ }
+
+ return image_encoder;
+}
+
+int ImageEncoder::ComputeJpegQuality(double quality) {
+ int compression_quality = 92; // Default value
+ if (quality >= 0.0 && quality <= 1.0)
+ compression_quality = static_cast<int>(quality * 100 + 0.5);
+ return compression_quality;
+}
+};

Powered by Google App Engine
This is Rietveld 408576698