1 // Copyright 2011 Google Inc. All Rights Reserved.
3 // This code is licensed under the same terms as WebM:
4 // Software License Agreement: http://www.webmproject.org/license/software/
5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/
6 // -----------------------------------------------------------------------------
8 // Coding tools configuration
10 // Author: Skal (pascal.massimino@gmail.com)
12 #include "../webp/encode.h"
14 #if defined(__cplusplus) || defined(c_plusplus)
18 //------------------------------------------------------------------------------
20 //------------------------------------------------------------------------------
22 int WebPConfigInitInternal(WebPConfig* config,
23 WebPPreset preset, float quality, int version) {
24 if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_ENCODER_ABI_VERSION)) {
25 return 0; // caller/system version mismatch!
27 if (config == NULL) return 0;
29 config->quality = quality;
30 config->target_size = 0;
31 config->target_PSNR = 0.;
33 config->sns_strength = 50;
34 config->filter_strength = 60; // rather high filtering, helps w/ gradients.
35 config->filter_sharpness = 0;
36 config->filter_type = 1; // default: strong (so U/V is filtered too)
37 config->partitions = 0;
40 config->show_compressed = 0;
41 config->preprocessing = 0;
42 config->autofilter = 0;
43 config->partition_limit = 0;
44 config->alpha_compression = 1;
45 config->alpha_filtering = 1;
46 config->alpha_quality = 100;
48 config->image_hint = WEBP_HINT_DEFAULT;
49 config->emulate_jpeg_size = 0;
50 config->thread_level = 0;
51 config->low_memory = 0;
55 case WEBP_PRESET_PICTURE:
56 config->sns_strength = 80;
57 config->filter_sharpness = 4;
58 config->filter_strength = 35;
60 case WEBP_PRESET_PHOTO:
61 config->sns_strength = 80;
62 config->filter_sharpness = 3;
63 config->filter_strength = 30;
65 case WEBP_PRESET_DRAWING:
66 config->sns_strength = 25;
67 config->filter_sharpness = 6;
68 config->filter_strength = 10;
70 case WEBP_PRESET_ICON:
71 config->sns_strength = 0;
72 config->filter_strength = 0; // disable filtering to retain sharpness
74 case WEBP_PRESET_TEXT:
75 config->sns_strength = 0;
76 config->filter_strength = 0; // disable filtering to retain sharpness
79 case WEBP_PRESET_DEFAULT:
83 return WebPValidateConfig(config);
86 int WebPValidateConfig(const WebPConfig* config) {
87 if (config == NULL) return 0;
88 if (config->quality < 0 || config->quality > 100)
90 if (config->target_size < 0)
92 if (config->target_PSNR < 0)
94 if (config->method < 0 || config->method > 6)
96 if (config->segments < 1 || config->segments > 4)
98 if (config->sns_strength < 0 || config->sns_strength > 100)
100 if (config->filter_strength < 0 || config->filter_strength > 100)
102 if (config->filter_sharpness < 0 || config->filter_sharpness > 7)
104 if (config->filter_type < 0 || config->filter_type > 1)
106 if (config->autofilter < 0 || config->autofilter > 1)
108 if (config->pass < 1 || config->pass > 10)
110 if (config->show_compressed < 0 || config->show_compressed > 1)
112 if (config->preprocessing < 0 || config->preprocessing > 1)
114 if (config->partitions < 0 || config->partitions > 3)
116 if (config->partition_limit < 0 || config->partition_limit > 100)
118 if (config->alpha_compression < 0)
120 if (config->alpha_filtering < 0)
122 if (config->alpha_quality < 0 || config->alpha_quality > 100)
124 if (config->lossless < 0 || config->lossless > 1)
126 if (config->image_hint >= WEBP_HINT_LAST)
128 if (config->emulate_jpeg_size < 0 || config->emulate_jpeg_size > 1)
130 if (config->thread_level < 0 || config->thread_level > 1)
132 if (config->low_memory < 0 || config->low_memory > 1)
137 //------------------------------------------------------------------------------
139 #if defined(__cplusplus) || defined(c_plusplus)