• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include "include/core/SkSpan.h" // IWYU pragma: keep
12 #include "include/encode/SkEncoder.h"
13 #include "include/private/base/SkAPI.h"
14 
15 class SkPixmap;
16 class SkWStream;
17 struct skcms_ICCProfile;
18 
19 namespace SkWebpEncoder {
20 
21     enum class Compression {
22         kLossy,
23         kLossless,
24     };
25 
26     struct SK_API Options {
27         /**
28          *  |fCompression| determines whether we will use webp lossy or lossless compression.
29          *
30          *  |fQuality| must be in [0.0f, 100.0f].
31          *  If |fCompression| is kLossy, |fQuality| corresponds to the visual quality of the
32          *  encoding.  Decreasing the quality will result in a smaller encoded image.
33          *  If |fCompression| is kLossless, |fQuality| corresponds to the amount of effort
34          *  put into the encoding.  Lower values will compress faster into larger files,
35          *  while larger values will compress slower into smaller files.
36          *
37          *  This scheme is designed to match the libwebp API.
38          */
39         Compression fCompression = Compression::kLossy;
40         float fQuality = 100.0f;
41 
42         /**
43          * An optional ICC profile to override the default behavior.
44          *
45          * The default behavior is to generate an ICC profile using a primary matrix and
46          * analytic transfer function. If the color space of |src| cannot be represented
47          * in this way (e.g, it is HLG or PQ), then no profile will be embedded.
48          */
49         const skcms_ICCProfile* fICCProfile = nullptr;
50         const char* fICCProfileDescription = nullptr;
51     };
52 
53     /**
54      *  Encode the |src| pixels to the |dst| stream.
55      *  |options| may be used to control the encoding behavior.
56      *
57      *  Returns true on success.  Returns false on an invalid or unsupported |src|.
58      */
59     SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options);
60 
61     /**
62      *  Encode the |src| frames to the |dst| stream.
63      *  |options| may be used to control the encoding behavior.
64      *
65      *  The size of the first frame will be used as the canvas size. If any other frame does
66      *  not match the canvas size, this is an error.
67      *
68      *  Returns true on success.  Returns false on an invalid or unsupported |src|.
69      *
70      *  Note: libwebp API also supports set background color, loop limit and customize
71      *  lossy/lossless for each frame. These could be added later as needed.
72      */
73     SK_API bool EncodeAnimated(SkWStream* dst,
74                                SkSpan<const SkEncoder::Frame> src,
75                                const Options& options);
76 } // namespace SkWebpEncoder
77 
78 #endif
79