Matt Sarett | 04c3731 | 2017-05-05 14:02:13 -0400 | [diff] [blame] | 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 | |
Matt Sarett | eb7a693 | 2017-05-11 13:10:06 -0400 | [diff] [blame] | 15 | namespace SkWebpEncoder { |
Matt Sarett | 04c3731 | 2017-05-05 14:02:13 -0400 | [diff] [blame] | 16 | |
Mike Reed | a281dd3 | 2017-05-17 06:09:25 -0400 | [diff] [blame] | 17 | enum class Compression { |
Matt Sarett | d5a1691 | 2017-05-16 17:06:52 -0400 | [diff] [blame] | 18 | kLossy, |
| 19 | kLossless, |
| 20 | }; |
| 21 | |
Matt Sarett | eb7a693 | 2017-05-11 13:10:06 -0400 | [diff] [blame] | 22 | struct SK_API Options { |
Matt Sarett | 04c3731 | 2017-05-05 14:02:13 -0400 | [diff] [blame] | 23 | /** |
Matt Sarett | d5a1691 | 2017-05-16 17:06:52 -0400 | [diff] [blame] | 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. |
Matt Sarett | 04c3731 | 2017-05-05 14:02:13 -0400 | [diff] [blame] | 34 | */ |
Matt Sarett | d5a1691 | 2017-05-16 17:06:52 -0400 | [diff] [blame] | 35 | Compression fCompression = Compression::kLossy; |
Matt Sarett | 04c3731 | 2017-05-05 14:02:13 -0400 | [diff] [blame] | 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 | */ |
Matt Sarett | eb7a693 | 2017-05-11 13:10:06 -0400 | [diff] [blame] | 52 | SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options); |
Matt Sarett | 04c3731 | 2017-05-05 14:02:13 -0400 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | #endif |