• 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 "SkEncoder.h"
12 
13 class SkWStream;
14 
15 namespace SkWebpEncoder {
16 
17     enum class Compression {
18         kLossy,
19         kLossless,
20     };
21 
22     struct SK_API Options {
23         /**
24          *  |fCompression| determines whether we will use webp lossy or lossless compression.
25          *
26          *  |fQuality| must be in [0.0f, 100.0f].
27          *  If |fCompression| is kLossy, |fQuality| corresponds to the visual quality of the
28          *  encoding.  Decreasing the quality will result in a smaller encoded image.
29          *  If |fCompression| is kLossless, |fQuality| corresponds to the amount of effort
30          *  put into the encoding.  Lower values will compress faster into larger files,
31          *  while larger values will compress slower into smaller files.
32          *
33          *  This scheme is designed to match the libwebp API.
34          */
35         Compression fCompression = Compression::kLossy;
36         float fQuality = 100.0f;
37 
38         /**
39          *  If the input is premultiplied, this controls the unpremultiplication behavior.
40          *  The encoder can convert to linear before unpremultiplying or ignore the transfer
41          *  function and unpremultiply the input as is.
42          */
43         SkTransferFunctionBehavior fUnpremulBehavior = SkTransferFunctionBehavior::kRespect;
44     };
45 
46     /**
47      *  Encode the |src| pixels to the |dst| stream.
48      *  |options| may be used to control the encoding behavior.
49      *
50      *  Returns true on success.  Returns false on an invalid or unsupported |src|.
51      */
52     SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options);
53 };
54 
55 #endif
56