• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
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 // -----------------------------------------------------------------------------
7 //
8 // Coding tools configuration
9 //
10 // Author: Skal (pascal.massimino@gmail.com)
11 
12 #include "webp/encode.h"
13 
14 #if defined(__cplusplus) || defined(c_plusplus)
15 extern "C" {
16 #endif
17 
18 //------------------------------------------------------------------------------
19 // WebPConfig
20 //------------------------------------------------------------------------------
21 
WebPConfigInitInternal(WebPConfig * config,WebPPreset preset,float quality,int version)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!
26   }
27   if (config == NULL) return 0;
28 
29   config->quality = quality;
30   config->target_size = 0;
31   config->target_PSNR = 0.;
32   config->method = 4;
33   config->sns_strength = 50;
34   config->filter_strength = 20;   // default: light filtering
35   config->filter_sharpness = 0;
36   config->filter_type = 0;        // default: simple
37   config->partitions = 0;
38   config->segments = 4;
39   config->pass = 1;
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;
47   config->lossless = 0;
48   config->image_hint = WEBP_HINT_DEFAULT;
49 
50   // TODO(skal): tune.
51   switch (preset) {
52     case WEBP_PRESET_PICTURE:
53       config->sns_strength = 80;
54       config->filter_sharpness = 4;
55       config->filter_strength = 35;
56       break;
57     case WEBP_PRESET_PHOTO:
58       config->sns_strength = 80;
59       config->filter_sharpness = 3;
60       config->filter_strength = 30;
61       break;
62     case WEBP_PRESET_DRAWING:
63       config->sns_strength = 25;
64       config->filter_sharpness = 6;
65       config->filter_strength = 10;
66       break;
67     case WEBP_PRESET_ICON:
68       config->sns_strength = 0;
69       config->filter_strength = 0;   // disable filtering to retain sharpness
70       break;
71     case WEBP_PRESET_TEXT:
72       config->sns_strength = 0;
73       config->filter_strength = 0;   // disable filtering to retain sharpness
74       config->segments = 2;
75       break;
76     case WEBP_PRESET_DEFAULT:
77     default:
78       break;
79   }
80   return WebPValidateConfig(config);
81 }
82 
WebPValidateConfig(const WebPConfig * config)83 int WebPValidateConfig(const WebPConfig* config) {
84   if (config == NULL) return 0;
85   if (config->quality < 0 || config->quality > 100)
86     return 0;
87   if (config->target_size < 0)
88     return 0;
89   if (config->target_PSNR < 0)
90     return 0;
91   if (config->method < 0 || config->method > 6)
92     return 0;
93   if (config->segments < 1 || config->segments > 4)
94     return 0;
95   if (config->sns_strength < 0 || config->sns_strength > 100)
96     return 0;
97   if (config->filter_strength < 0 || config->filter_strength > 100)
98     return 0;
99   if (config->filter_sharpness < 0 || config->filter_sharpness > 7)
100     return 0;
101   if (config->filter_type < 0 || config->filter_type > 1)
102     return 0;
103   if (config->autofilter < 0 || config->autofilter > 1)
104     return 0;
105   if (config->pass < 1 || config->pass > 10)
106     return 0;
107   if (config->show_compressed < 0 || config->show_compressed > 1)
108     return 0;
109   if (config->preprocessing < 0 || config->preprocessing > 1)
110     return 0;
111   if (config->partitions < 0 || config->partitions > 3)
112     return 0;
113   if (config->partition_limit < 0 || config->partition_limit > 100)
114     return 0;
115   if (config->alpha_compression < 0)
116     return 0;
117   if (config->alpha_filtering < 0)
118     return 0;
119   if (config->alpha_quality < 0 || config->alpha_quality > 100)
120     return 0;
121   if (config->lossless < 0 || config->lossless > 1)
122     return 0;
123   if (config->image_hint >= WEBP_HINT_LAST)
124     return 0;
125   return 1;
126 }
127 
128 //------------------------------------------------------------------------------
129 
130 #if defined(__cplusplus) || defined(c_plusplus)
131 }    // extern "C"
132 #endif
133