1
// Copyright 2011 Google Inc. All Rights Reserved.
3
// Use of this source code is governed by a BSD-style license
4
// that can be found in the COPYING file in the root of the source
5
// tree. An additional intellectual property rights grant can be found
6
// in the file PATENTS. All contributing project authors may
7
// be found in the AUTHORS file in the root of the source tree.
8
// -----------------------------------------------------------------------------
10
// Coding tools configuration
12
// Author: Skal (pascal.massimino@gmail.com)
14
#include "../webp/encode.h"
16
#if defined(__cplusplus) || defined(c_plusplus)
20
//------------------------------------------------------------------------------
22
//------------------------------------------------------------------------------
24
int WebPConfigInitInternal(WebPConfig* config,
25
WebPPreset preset, float quality, int version) {
26
if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_ENCODER_ABI_VERSION)) {
27
return 0; // caller/system version mismatch!
29
if (config == NULL) return 0;
31
config->quality = quality;
32
config->target_size = 0;
33
config->target_PSNR = 0.;
35
config->sns_strength = 50;
36
config->filter_strength = 60; // rather high filtering, helps w/ gradients.
37
config->filter_sharpness = 0;
38
config->filter_type = 1; // default: strong (so U/V is filtered too)
39
config->partitions = 0;
42
config->show_compressed = 0;
43
config->preprocessing = 0;
44
config->autofilter = 0;
45
config->partition_limit = 0;
46
config->alpha_compression = 1;
47
config->alpha_filtering = 1;
48
config->alpha_quality = 100;
50
config->image_hint = WEBP_HINT_DEFAULT;
51
config->emulate_jpeg_size = 0;
52
config->thread_level = 0;
53
config->low_memory = 0;
57
case WEBP_PRESET_PICTURE:
58
config->sns_strength = 80;
59
config->filter_sharpness = 4;
60
config->filter_strength = 35;
62
case WEBP_PRESET_PHOTO:
63
config->sns_strength = 80;
64
config->filter_sharpness = 3;
65
config->filter_strength = 30;
67
case WEBP_PRESET_DRAWING:
68
config->sns_strength = 25;
69
config->filter_sharpness = 6;
70
config->filter_strength = 10;
72
case WEBP_PRESET_ICON:
73
config->sns_strength = 0;
74
config->filter_strength = 0; // disable filtering to retain sharpness
76
case WEBP_PRESET_TEXT:
77
config->sns_strength = 0;
78
config->filter_strength = 0; // disable filtering to retain sharpness
81
case WEBP_PRESET_DEFAULT:
85
return WebPValidateConfig(config);
88
int WebPValidateConfig(const WebPConfig* config) {
89
if (config == NULL) return 0;
90
if (config->quality < 0 || config->quality > 100)
92
if (config->target_size < 0)
94
if (config->target_PSNR < 0)
96
if (config->method < 0 || config->method > 6)
98
if (config->segments < 1 || config->segments > 4)
100
if (config->sns_strength < 0 || config->sns_strength > 100)
102
if (config->filter_strength < 0 || config->filter_strength > 100)
104
if (config->filter_sharpness < 0 || config->filter_sharpness > 7)
106
if (config->filter_type < 0 || config->filter_type > 1)
108
if (config->autofilter < 0 || config->autofilter > 1)
110
if (config->pass < 1 || config->pass > 10)
112
if (config->show_compressed < 0 || config->show_compressed > 1)
114
if (config->preprocessing < 0 || config->preprocessing > 1)
116
if (config->partitions < 0 || config->partitions > 3)
118
if (config->partition_limit < 0 || config->partition_limit > 100)
120
if (config->alpha_compression < 0)
122
if (config->alpha_filtering < 0)
124
if (config->alpha_quality < 0 || config->alpha_quality > 100)
126
if (config->lossless < 0 || config->lossless > 1)
128
if (config->image_hint >= WEBP_HINT_LAST)
130
if (config->emulate_jpeg_size < 0 || config->emulate_jpeg_size > 1)
132
if (config->thread_level < 0 || config->thread_level > 1)
134
if (config->low_memory < 0 || config->low_memory > 1)
139
//------------------------------------------------------------------------------
141
#if defined(__cplusplus) || defined(c_plusplus)