Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkWebpEncoder.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkWebpEncoder_DEFINED
9#define SkWebpEncoder_DEFINED
10
12#include "include/core/SkSpan.h" // IWYU pragma: keep
15
16class SkPixmap;
17class SkWStream;
18class SkData;
19class GrDirectContext;
20class SkImage;
21struct skcms_ICCProfile;
22
23namespace SkWebpEncoder {
24
25enum class Compression {
26 kLossy,
28};
29
31 /**
32 * |fCompression| determines whether we will use webp lossy or lossless compression.
33 *
34 * |fQuality| must be in [0.0f, 100.0f].
35 * If |fCompression| is kLossy, |fQuality| corresponds to the visual quality of the
36 * encoding. Decreasing the quality will result in a smaller encoded image.
37 * If |fCompression| is kLossless, |fQuality| corresponds to the amount of effort
38 * put into the encoding. Lower values will compress faster into larger files,
39 * while larger values will compress slower into smaller files.
40 *
41 * This scheme is designed to match the libwebp API.
42 */
43 Compression fCompression = Compression::kLossy;
44 float fQuality = 100.0f;
45
46 /**
47 * An optional ICC profile to override the default behavior.
48 *
49 * The default behavior is to generate an ICC profile using a primary matrix and
50 * analytic transfer function. If the color space of |src| cannot be represented
51 * in this way (e.g, it is HLG or PQ), then no profile will be embedded.
52 */
53 const skcms_ICCProfile* fICCProfile = nullptr;
54 const char* fICCProfileDescription = nullptr;
55};
56
57/**
58 * Encode the |src| pixels to the |dst| stream.
59 * |options| may be used to control the encoding behavior.
60 *
61 * Returns true on success. Returns false on an invalid or unsupported |src|.
62 */
63SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options);
64
65/**
66* Encode the provided image and return the resulting bytes. If the image was created as
67* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels
68* can be read before being encoded. For raster-backed images, |ctx| can be nullptr.
69* |options| may be used to control the encoding behavior.
70*
71* Returns nullptr if the pixels could not be read or encoding otherwise fails.
72*/
74
75/**
76 * Encode the |src| frames to the |dst| stream.
77 * |options| may be used to control the encoding behavior.
78 *
79 * The size of the first frame will be used as the canvas size. If any other frame does
80 * not match the canvas size, this is an error.
81 *
82 * Returns true on success. Returns false on an invalid or unsupported |src|.
83 *
84 * Note: libwebp API also supports set background color, loop limit and customize
85 * lossy/lossless for each frame. These could be added later as needed.
86 */
89 const Options& options);
90} // namespace SkWebpEncoder
91
92#endif
const char * options
#define SK_API
Definition SkAPI.h:35
SK_API bool EncodeAnimated(SkWStream *dst, SkSpan< const SkEncoder::Frame > src, const Options &options)
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)