diff options
author | Matt Sarett <msarett@google.com> | 2017-05-11 09:32:59 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-11 14:36:56 +0000 |
commit | 6a4dc66990f73b9443816e69054f101386197593 (patch) | |
tree | 59d27654eb67ae982f21cd52c52551353754934b /src/images | |
parent | bc09d29a732cc6df1d6a132965cb46ba62b580b3 (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 'src/images')
-rw-r--r-- | src/images/SkJpegEncoder.cpp | 4 | ||||
-rw-r--r-- | src/images/SkJpegEncoder.h | 98 | ||||
-rw-r--r-- | src/images/SkPngEncoder.cpp | 4 | ||||
-rw-r--r-- | src/images/SkWebpEncoder.h | 40 |
4 files changed, 4 insertions, 142 deletions
diff --git a/src/images/SkJpegEncoder.cpp b/src/images/SkJpegEncoder.cpp index 4b37cd3be3..8b1dd960e2 100644 --- a/src/images/SkJpegEncoder.cpp +++ b/src/images/SkJpegEncoder.cpp @@ -188,8 +188,8 @@ bool SkJpegEncoderMgr::setParams(const SkImageInfo& srcInfo, const SkJpegEncoder return true; } -std::unique_ptr<SkJpegEncoder> SkJpegEncoder::Make(SkWStream* dst, const SkPixmap& src, - const Options& options) { +std::unique_ptr<SkEncoder> SkJpegEncoder::Make(SkWStream* dst, const SkPixmap& src, + const Options& options) { if (!SkPixmapIsValid(src, options.fBlendBehavior)) { return nullptr; } diff --git a/src/images/SkJpegEncoder.h b/src/images/SkJpegEncoder.h deleted file mode 100644 index a8b9dfb540..0000000000 --- a/src/images/SkJpegEncoder.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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 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<SkJpegEncoder> 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/src/images/SkPngEncoder.cpp b/src/images/SkPngEncoder.cpp index 6c14f50930..d28657f008 100644 --- a/src/images/SkPngEncoder.cpp +++ b/src/images/SkPngEncoder.cpp @@ -382,8 +382,8 @@ void SkPngEncoderMgr::chooseProc(const SkImageInfo& srcInfo, fProc = choose_proc(srcInfo, unpremulBehavior); } -std::unique_ptr<SkPngEncoder> SkPngEncoder::Make(SkWStream* dst, const SkPixmap& src, - const Options& options) { +std::unique_ptr<SkEncoder> SkPngEncoder::Make(SkWStream* dst, const SkPixmap& src, + const Options& options) { if (!SkPixmapIsValid(src, options.fUnpremulBehavior)) { return nullptr; } diff --git a/src/images/SkWebpEncoder.h b/src/images/SkWebpEncoder.h deleted file mode 100644 index 07fcdd7de7..0000000000 --- a/src/images/SkWebpEncoder.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 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 |