aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/encode
diff options
context:
space:
mode:
authorGravatar Matt Sarett <msarett@google.com>2017-05-11 09:32:59 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-11 14:36:56 +0000
commit6a4dc66990f73b9443816e69054f101386197593 (patch)
tree59d27654eb67ae982f21cd52c52551353754934b /include/encode
parentbc09d29a732cc6df1d6a132965cb46ba62b580b3 (diff)
Add SkJpegEncoder and SkWebpEncoder to public API
Bug: 713862 Change-Id: I05d8b3a506f817d63b0bc3ab3f9233e24bbe3be0 Reviewed-on: https://skia-review.googlesource.com/16233 Commit-Queue: Matt Sarett <msarett@google.com> Reviewed-by: Leon Scroggins <scroggo@google.com> Reviewed-by: Mike Reed <reed@google.com>
Diffstat (limited to 'include/encode')
-rw-r--r--include/encode/SkJpegEncoder.h98
-rw-r--r--include/encode/SkPngEncoder.h4
-rw-r--r--include/encode/SkWebpEncoder.h40
3 files changed, 140 insertions, 2 deletions
diff --git a/include/encode/SkJpegEncoder.h b/include/encode/SkJpegEncoder.h
new file mode 100644
index 0000000000..fd7c204161
--- /dev/null
+++ b/include/encode/SkJpegEncoder.h
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkJpegEncoder_DEFINED
+#define SkJpegEncoder_DEFINED
+
+#include "SkEncoder.h"
+
+class SkJpegEncoderMgr;
+class SkWStream;
+
+class SK_API SkJpegEncoder : public SkEncoder {
+public:
+
+ enum class AlphaOption {
+ kIgnore,
+ kBlendOnBlack,
+ };
+
+ enum class Downsample {
+ /**
+ * Reduction by a factor of two in both the horizontal and vertical directions.
+ */
+ k420,
+
+ /**
+ * Reduction by a factor of two in the horizontal direction.
+ */
+ k422,
+
+ /**
+ * No downsampling.
+ */
+ k444,
+ };
+
+ struct Options {
+ /**
+ * |fQuality| must be in [0, 100] where 0 corresponds to the lowest quality.
+ */
+ int fQuality = 100;
+
+ /**
+ * Choose the downsampling factor for the U and V components. This is only
+ * meaningful if the |src| is not kGray, since kGray will not be encoded as YUV.
+ *
+ * Our default value matches the libjpeg-turbo default.
+ */
+ Downsample fDownsample = Downsample::k420;
+
+ /**
+ * Jpegs must be opaque. This instructs the encoder on how to handle input
+ * images with alpha.
+ *
+ * The default is to ignore the alpha channel and treat the image as opaque.
+ * Another option is to blend the pixels onto a black background before encoding.
+ * In the second case, the encoder supports linear or legacy blending.
+ */
+ AlphaOption fAlphaOption = AlphaOption::kIgnore;
+ SkTransferFunctionBehavior fBlendBehavior = SkTransferFunctionBehavior::kRespect;
+ };
+
+ /**
+ * Encode the |src| pixels to the |dst| stream.
+ * |options| may be used to control the encoding behavior.
+ *
+ * Returns true on success. Returns false on an invalid or unsupported |src|.
+ */
+ static bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options);
+
+ /**
+ * Create a jpeg encoder that will encode the |src| pixels to the |dst| stream.
+ * |options| may be used to control the encoding behavior.
+ *
+ * |dst| is unowned but must remain valid for the lifetime of the object.
+ *
+ * This returns nullptr on an invalid or unsupported |src|.
+ */
+ static std::unique_ptr<SkEncoder> Make(SkWStream* dst, const SkPixmap& src,
+ const Options& options);
+
+ ~SkJpegEncoder() override;
+
+protected:
+ bool onEncodeRows(int numRows) override;
+
+private:
+ SkJpegEncoder(std::unique_ptr<SkJpegEncoderMgr>, const SkPixmap& src);
+
+ std::unique_ptr<SkJpegEncoderMgr> fEncoderMgr;
+ typedef SkEncoder INHERITED;
+};
+
+#endif
diff --git a/include/encode/SkPngEncoder.h b/include/encode/SkPngEncoder.h
index adcc061113..6de800f367 100644
--- a/include/encode/SkPngEncoder.h
+++ b/include/encode/SkPngEncoder.h
@@ -76,8 +76,8 @@ public:
*
* This returns nullptr on an invalid or unsupported |src|.
*/
- static std::unique_ptr<SkPngEncoder> Make(SkWStream* dst, const SkPixmap& src,
- const Options& options);
+ static std::unique_ptr<SkEncoder> Make(SkWStream* dst, const SkPixmap& src,
+ const Options& options);
~SkPngEncoder() override;
diff --git a/include/encode/SkWebpEncoder.h b/include/encode/SkWebpEncoder.h
new file mode 100644
index 0000000000..58ee06d1c6
--- /dev/null
+++ b/include/encode/SkWebpEncoder.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkWebpEncoder_DEFINED
+#define SkWebpEncoder_DEFINED
+
+#include "SkEncoder.h"
+
+class SkWStream;
+
+namespace SK_API SkWebpEncoder {
+
+ struct Options {
+ /**
+ * |fQuality| must be in [0.0f, 100.0f] where 0.0f corresponds to the lowest quality.
+ */
+ float fQuality = 100.0f;
+
+ /**
+ * If the input is premultiplied, this controls the unpremultiplication behavior.
+ * The encoder can convert to linear before unpremultiplying or ignore the transfer
+ * function and unpremultiply the input as is.
+ */
+ SkTransferFunctionBehavior fUnpremulBehavior = SkTransferFunctionBehavior::kRespect;
+ };
+
+ /**
+ * Encode the |src| pixels to the |dst| stream.
+ * |options| may be used to control the encoding behavior.
+ *
+ * Returns true on success. Returns false on an invalid or unsupported |src|.
+ */
+ bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options);
+};
+
+#endif