| 1 | // Aseprite
|
| 2 | // Copyright (C) 2018 David Capello
|
| 3 | // Copyright (C) 2015 Gabriel Rauter
|
| 4 | //
|
| 5 | // This program is distributed under the terms of
|
| 6 | // the End-User License Agreement for Aseprite.
|
| 7 |
|
| 8 | #ifndef APP_FILE_WEBP_OPTIONS_H_INCLUDED
|
| 9 | #define APP_FILE_WEBP_OPTIONS_H_INCLUDED
|
| 10 | #pragma once
|
| 11 |
|
| 12 | #include "app/file/format_options.h"
|
| 13 |
|
| 14 | #include <webp/decode.h>
|
| 15 | #include <webp/encode.h>
|
| 16 |
|
| 17 | namespace app {
|
| 18 |
|
| 19 | // Data for WebP files
|
| 20 | class WebPOptions : public FormatOptions {
|
| 21 | public:
|
| 22 | enum Type { Simple, Lossless, Lossy };
|
| 23 |
|
| 24 | // By default we use 6, because 9 is too slow
|
| 25 | const int kDefaultCompression = 6;
|
| 26 |
|
| 27 | WebPOptions() : m_loop(true),
|
| 28 | m_type(Type::Simple),
|
| 29 | m_compression(kDefaultCompression),
|
| 30 | m_imageHint(WEBP_HINT_DEFAULT),
|
| 31 | m_quality(100),
|
| 32 | m_imagePreset(WEBP_PRESET_DEFAULT) { }
|
| 33 |
|
| 34 | bool loop() const { return m_loop; }
|
| 35 | Type type() const { return m_type; }
|
| 36 | int compression() const { return m_compression; }
|
| 37 | WebPImageHint imageHint() const { return m_imageHint; }
|
| 38 | int quality() const { return m_quality; }
|
| 39 | WebPPreset imagePreset() const { return m_imagePreset; }
|
| 40 |
|
| 41 | void setLoop(const bool loop) {
|
| 42 | m_loop = loop;
|
| 43 | }
|
| 44 |
|
| 45 | void setType(const Type type) {
|
| 46 | m_type = type;
|
| 47 |
|
| 48 | if (m_type == Type::Simple) {
|
| 49 | m_compression = kDefaultCompression;
|
| 50 | m_imageHint = WEBP_HINT_DEFAULT;
|
| 51 | }
|
| 52 | }
|
| 53 |
|
| 54 | void setCompression(const int compression) {
|
| 55 | ASSERT(m_type == Type::Lossless);
|
| 56 | m_compression = compression;
|
| 57 | }
|
| 58 |
|
| 59 | void setImageHint(const WebPImageHint imageHint) {
|
| 60 | ASSERT(m_type == Type::Lossless);
|
| 61 | m_imageHint = imageHint;
|
| 62 | }
|
| 63 |
|
| 64 | void setQuality(const int quality) {
|
| 65 | ASSERT(m_type == Type::Lossy);
|
| 66 | m_quality = quality;
|
| 67 | }
|
| 68 |
|
| 69 | void setImagePreset(const WebPPreset imagePreset) {
|
| 70 | ASSERT(m_type == Type::Lossy);
|
| 71 | m_imagePreset = imagePreset;
|
| 72 | }
|
| 73 |
|
| 74 | private:
|
| 75 | bool m_loop;
|
| 76 | Type m_type;
|
| 77 | // Lossless options
|
| 78 | int m_compression; // Quality/speed trade-off (0=fast, 9=slower-better)
|
| 79 | WebPImageHint m_imageHint; // Hint for image type (lossless only for now).
|
| 80 | // Lossy options
|
| 81 | int m_quality; // Between 0 (smallest file) and 100 (biggest)
|
| 82 | WebPPreset m_imagePreset; // Image Preset for lossy webp.
|
| 83 | };
|
| 84 |
|
| 85 | } // namespace app
|
| 86 |
|
| 87 | #endif
|
| 88 | |