aboutsummaryrefslogtreecommitdiff
path: root/src/deps/skia/include/encode
diff options
context:
space:
mode:
Diffstat (limited to 'src/deps/skia/include/encode')
-rw-r--r--src/deps/skia/include/encode/BUILD.bazel36
-rw-r--r--src/deps/skia/include/encode/SkEncoder.h42
-rw-r--r--src/deps/skia/include/encode/SkJpegEncoder.h97
-rw-r--r--src/deps/skia/include/encode/SkPngEncoder.h99
-rw-r--r--src/deps/skia/include/encode/SkWebpEncoder.h48
5 files changed, 322 insertions, 0 deletions
diff --git a/src/deps/skia/include/encode/BUILD.bazel b/src/deps/skia/include/encode/BUILD.bazel
new file mode 100644
index 000000000..fc728d0d0
--- /dev/null
+++ b/src/deps/skia/include/encode/BUILD.bazel
@@ -0,0 +1,36 @@
+load("//bazel:macros.bzl", "generated_cc_atom")
+
+generated_cc_atom(
+ name = "SkEncoder_hdr",
+ hdrs = ["SkEncoder.h"],
+ visibility = ["//:__subpackages__"],
+ deps = [
+ "//include/core:SkPixmap_hdr",
+ "//include/private:SkNoncopyable_hdr",
+ "//include/private:SkTemplates_hdr",
+ ],
+)
+
+generated_cc_atom(
+ name = "SkJpegEncoder_hdr",
+ hdrs = ["SkJpegEncoder.h"],
+ visibility = ["//:__subpackages__"],
+ deps = [":SkEncoder_hdr"],
+)
+
+generated_cc_atom(
+ name = "SkPngEncoder_hdr",
+ hdrs = ["SkPngEncoder.h"],
+ visibility = ["//:__subpackages__"],
+ deps = [
+ ":SkEncoder_hdr",
+ "//include/core:SkDataTable_hdr",
+ ],
+)
+
+generated_cc_atom(
+ name = "SkWebpEncoder_hdr",
+ hdrs = ["SkWebpEncoder.h"],
+ visibility = ["//:__subpackages__"],
+ deps = [":SkEncoder_hdr"],
+)
diff --git a/src/deps/skia/include/encode/SkEncoder.h b/src/deps/skia/include/encode/SkEncoder.h
new file mode 100644
index 000000000..1a9c37e7f
--- /dev/null
+++ b/src/deps/skia/include/encode/SkEncoder.h
@@ -0,0 +1,42 @@
+/*
+ * 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 SkEncoder_DEFINED
+#define SkEncoder_DEFINED
+
+#include "include/core/SkPixmap.h"
+#include "include/private/SkNoncopyable.h"
+#include "include/private/SkTemplates.h"
+
+class SK_API SkEncoder : SkNoncopyable {
+public:
+
+ /**
+ * Encode |numRows| rows of input. If the caller requests more rows than are remaining
+ * in the src, this will encode all of the remaining rows. |numRows| must be greater
+ * than zero.
+ */
+ bool encodeRows(int numRows);
+
+ virtual ~SkEncoder() {}
+
+protected:
+
+ virtual bool onEncodeRows(int numRows) = 0;
+
+ SkEncoder(const SkPixmap& src, size_t storageBytes)
+ : fSrc(src)
+ , fCurrRow(0)
+ , fStorage(storageBytes)
+ {}
+
+ const SkPixmap& fSrc;
+ int fCurrRow;
+ SkAutoTMalloc<uint8_t> fStorage;
+};
+
+#endif
diff --git a/src/deps/skia/include/encode/SkJpegEncoder.h b/src/deps/skia/include/encode/SkJpegEncoder.h
new file mode 100644
index 000000000..f2107f126
--- /dev/null
+++ b/src/deps/skia/include/encode/SkJpegEncoder.h
@@ -0,0 +1,97 @@
+/*
+ * 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 "include/encode/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;
+ };
+
+ /**
+ * 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;
+ using INHERITED = SkEncoder;
+};
+
+#endif
diff --git a/src/deps/skia/include/encode/SkPngEncoder.h b/src/deps/skia/include/encode/SkPngEncoder.h
new file mode 100644
index 000000000..ccfa292f7
--- /dev/null
+++ b/src/deps/skia/include/encode/SkPngEncoder.h
@@ -0,0 +1,99 @@
+/*
+ * 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 SkPngEncoder_DEFINED
+#define SkPngEncoder_DEFINED
+
+#include "include/core/SkDataTable.h"
+#include "include/encode/SkEncoder.h"
+
+class SkPngEncoderMgr;
+class SkWStream;
+
+class SK_API SkPngEncoder : public SkEncoder {
+public:
+
+ enum class FilterFlag : int {
+ kZero = 0x00,
+ kNone = 0x08,
+ kSub = 0x10,
+ kUp = 0x20,
+ kAvg = 0x40,
+ kPaeth = 0x80,
+ kAll = kNone | kSub | kUp | kAvg | kPaeth,
+ };
+
+ struct Options {
+ /**
+ * Selects which filtering strategies to use.
+ *
+ * If a single filter is chosen, libpng will use that filter for every row.
+ *
+ * If multiple filters are chosen, libpng will use a heuristic to guess which filter
+ * will encode smallest, then apply that filter. This happens on a per row basis,
+ * different rows can use different filters.
+ *
+ * Using a single filter (or less filters) is typically faster. Trying all of the
+ * filters may help minimize the output file size.
+ *
+ * Our default value matches libpng's default.
+ */
+ FilterFlag fFilterFlags = FilterFlag::kAll;
+
+ /**
+ * Must be in [0, 9] where 9 corresponds to maximal compression. This value is passed
+ * directly to zlib. 0 is a special case to skip zlib entirely, creating dramatically
+ * larger pngs.
+ *
+ * Our default value matches libpng's default.
+ */
+ int fZLibLevel = 6;
+
+ /**
+ * Represents comments in the tEXt ancillary chunk of the png.
+ * The 2i-th entry is the keyword for the i-th comment,
+ * and the (2i + 1)-th entry is the text for the i-th comment.
+ */
+ sk_sp<SkDataTable> fComments;
+ };
+
+ /**
+ * 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 png 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);
+
+ ~SkPngEncoder() override;
+
+protected:
+ bool onEncodeRows(int numRows) override;
+
+ SkPngEncoder(std::unique_ptr<SkPngEncoderMgr>, const SkPixmap& src);
+
+ std::unique_ptr<SkPngEncoderMgr> fEncoderMgr;
+ using INHERITED = SkEncoder;
+};
+
+static inline SkPngEncoder::FilterFlag operator|(SkPngEncoder::FilterFlag x,
+ SkPngEncoder::FilterFlag y) {
+ return (SkPngEncoder::FilterFlag)((int)x | (int)y);
+}
+
+#endif
diff --git a/src/deps/skia/include/encode/SkWebpEncoder.h b/src/deps/skia/include/encode/SkWebpEncoder.h
new file mode 100644
index 000000000..6d1c85689
--- /dev/null
+++ b/src/deps/skia/include/encode/SkWebpEncoder.h
@@ -0,0 +1,48 @@
+/*
+ * 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 "include/encode/SkEncoder.h"
+
+class SkWStream;
+
+namespace SkWebpEncoder {
+
+ enum class Compression {
+ kLossy,
+ kLossless,
+ };
+
+ struct SK_API Options {
+ /**
+ * |fCompression| determines whether we will use webp lossy or lossless compression.
+ *
+ * |fQuality| must be in [0.0f, 100.0f].
+ * If |fCompression| is kLossy, |fQuality| corresponds to the visual quality of the
+ * encoding. Decreasing the quality will result in a smaller encoded image.
+ * If |fCompression| is kLossless, |fQuality| corresponds to the amount of effort
+ * put into the encoding. Lower values will compress faster into larger files,
+ * while larger values will compress slower into smaller files.
+ *
+ * This scheme is designed to match the libwebp API.
+ */
+ Compression fCompression = Compression::kLossy;
+ float fQuality = 100.0f;
+ };
+
+ /**
+ * 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|.
+ */
+ SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options);
+} // namespace SkWebpEncoder
+
+#endif