From a87508008dfa1604baf2d4e39bf44704c00f261c Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 3 Apr 2022 16:34:10 -0700 Subject: skia WIP --- src/deps/skia/include/encode/BUILD.bazel | 36 ++++++++++ src/deps/skia/include/encode/SkEncoder.h | 42 ++++++++++++ src/deps/skia/include/encode/SkJpegEncoder.h | 97 +++++++++++++++++++++++++++ src/deps/skia/include/encode/SkPngEncoder.h | 99 ++++++++++++++++++++++++++++ src/deps/skia/include/encode/SkWebpEncoder.h | 48 ++++++++++++++ 5 files changed, 322 insertions(+) create mode 100644 src/deps/skia/include/encode/BUILD.bazel create mode 100644 src/deps/skia/include/encode/SkEncoder.h create mode 100644 src/deps/skia/include/encode/SkJpegEncoder.h create mode 100644 src/deps/skia/include/encode/SkPngEncoder.h create mode 100644 src/deps/skia/include/encode/SkWebpEncoder.h (limited to 'src/deps/skia/include/encode') 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 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 Make(SkWStream* dst, const SkPixmap& src, + const Options& options); + + ~SkJpegEncoder() override; + +protected: + bool onEncodeRows(int numRows) override; + +private: + SkJpegEncoder(std::unique_ptr, const SkPixmap& src); + + std::unique_ptr 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 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 Make(SkWStream* dst, const SkPixmap& src, + const Options& options); + + ~SkPngEncoder() override; + +protected: + bool onEncodeRows(int numRows) override; + + SkPngEncoder(std::unique_ptr, const SkPixmap& src); + + std::unique_ptr 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 -- cgit v1.2.3 n> Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
AgeCommit message (Expand)AuthorFilesLines
2023-07-29Update wtf-bindings.cppGravatar Jarred Sumner 1-13/+1
2023-07-29experiment: use bmalloc/libpas instead of mimalloc in most placesGravatar Jarred Sumner 13-82/+165
2023-07-29typo spawn.md (#3875)Gravatar Jhorman Tito 1-1/+1
2023-07-28Update nodejs-apis.mdGravatar Jarred Sumner 1-4/+4
2023-07-28Update nodejs-apis.mdGravatar Jarred Sumner 1-5/+5
2023-07-28Defer task destructionbun-v0.7.1Gravatar Jarred Sumner 1-1/+17
2023-07-28Stat largefile test (#3870)Gravatar Jarred Sumner 1-0/+22
2023-07-28Ignore when printing to stdout errors (#3869)Gravatar Jarred Sumner 1-2/+4
2023-07-28Fix bug with `/path/to/absolute/bun.lockb`Gravatar Jarred Sumner 1-10/+13
2023-07-28markBindingGravatar Dylan Conway 1-0/+1
2023-07-28optional parameterGravatar Dylan Conway 1-3/+3
2023-07-28Fixes #3868Gravatar Jarred Sumner 1-2/+3
2023-07-28Fix assertion failure and possible infinite loop when printing as yarn lock f...Gravatar Jarred Sumner 2-3/+16
2023-07-28Mark broken test as todoGravatar Jarred Sumner 2-1/+5
2023-07-28fix types and add message channel/port gc testGravatar Dylan Conway 2-62/+18
2023-07-28`MessageChannel` and `MessagePort` (#3860)Gravatar Dylan Conway 57-247/+3752
2023-07-28mark tests as todoGravatar Jarred Sumner 2-81/+75
2023-07-28add fork to child_process (#3851)Gravatar Vlad Sirenko 7-19/+446
2023-07-28feat(bun/test): Impl. expect().pass() & expect().fail() (#3843)Gravatar Tiramify (A.K. Daniel) 6-5/+212
2023-07-28fix the chunk boundary (`node:stream:createReadStream`) (#3853)Gravatar Ai Hoshino 3-8/+90
2023-07-28Support file: URLs in `fetch` (#3858)Gravatar Jarred Sumner 6-183/+281
2023-07-28fix(tls) exposes native canonicalizeIP and fix rootCertificates (#3866)Gravatar Ciro Spaciari 7-29/+125
2023-07-28Fixes #3795 (#3856)Gravatar Jarred Sumner 11-6/+140
2023-07-28Add todoGravatar Jarred Sumner 2-0/+8
2023-07-28Update pull_request_template.mdGravatar Jarred Sumner 1-1/+1
2023-07-28Update pull_request_template.mdGravatar Jarred Sumner 1-11/+16
2023-07-27Fix bug with // @bun annotation in main thread (#3855)Gravatar Jarred Sumner 4-2/+53
2023-07-27Add `Bun.isMainThread`Gravatar Jarred Sumner 7-3/+48
2023-07-27Uncomment testGravatar Jarred Sumner 1-1/+1
2023-07-27Resolve watch directories outside main thread + async iterator and symlink fi...Gravatar Ciro Spaciari 8-197/+523
2023-07-27Update pull_request_template.mdGravatar Jarred Sumner 1-1/+1
2023-07-27Update pull_request_template.mdGravatar Jarred Sumner 1-1/+1
2023-07-27Update pull_request_template.mdGravatar Jarred Sumner 1-1/+1
2023-07-27Update pull_request_template.mdGravatar Jarred Sumner 1-2/+2
2023-07-27Update pull_request_template.mdGravatar Jarred Sumner 1-0/+4
2023-07-27Update pull_request_template.mdGravatar Jarred Sumner 1-5/+11