blob: f671be379cf9edcf5967d0d2db081f918216160c [file] [log] [blame]
Matt Sarett04c37312017-05-05 14:02:13 -04001/*
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
13class SkWStream;
14
Matt Saretteb7a6932017-05-11 13:10:06 -040015namespace SkWebpEncoder {
Matt Sarett04c37312017-05-05 14:02:13 -040016
Mike Reeda281dd32017-05-17 06:09:25 -040017 enum class Compression {
Matt Sarettd5a16912017-05-16 17:06:52 -040018 kLossy,
19 kLossless,
20 };
21
Matt Saretteb7a6932017-05-11 13:10:06 -040022 struct SK_API Options {
Matt Sarett04c37312017-05-05 14:02:13 -040023 /**
Matt Sarettd5a16912017-05-16 17:06:52 -040024 * |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 Sarett04c37312017-05-05 14:02:13 -040034 */
Matt Sarettd5a16912017-05-16 17:06:52 -040035 Compression fCompression = Compression::kLossy;
Matt Sarett04c37312017-05-05 14:02:13 -040036 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 Saretteb7a6932017-05-11 13:10:06 -040052 SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options);
Matt Sarett04c37312017-05-05 14:02:13 -040053};
54
55#endif