blob: 8d5f4a6c75d5ce3c018a9dd9f4271d0ea15d692e [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;
Matt Sarett04c37312017-05-05 14:02:13 -040037 };
38
39 /**
40 * Encode the |src| pixels to the |dst| stream.
41 * |options| may be used to control the encoding behavior.
42 *
43 * Returns true on success. Returns false on an invalid or unsupported |src|.
44 */
Matt Saretteb7a6932017-05-11 13:10:06 -040045 SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options);
Matt Sarett04c37312017-05-05 14:02:13 -040046};
47
48#endif