• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011 Google Inc.
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 <assert.h>
13 #include "webp/encode.h"
14 
15 #if defined(__cplusplus) || defined(c_plusplus)
16 extern "C" {
17 #endif
18 
19 //-----------------------------------------------------------------------------
20 // WebPConfig
21 //-----------------------------------------------------------------------------
22 
WebPConfigInitInternal(WebPConfig * const config,WebPPreset preset,float quality,int version)23 int WebPConfigInitInternal(WebPConfig* const config,
24                            WebPPreset preset, float quality, int version) {
25   if (version != WEBP_ENCODER_ABI_VERSION) {
26     return 0;   // caller/system version mismatch!
27   }
28   if (config == NULL) return 0;
29 
30   config->quality = quality;
31   config->target_size = 0;
32   config->target_PSNR = 0.;
33   config->method = 4;
34   config->sns_strength = 50;
35   config->filter_strength = 20;   // default: light filtering
36   config->filter_sharpness = 0;
37   config->filter_type = 0;        // default: simple
38   config->partitions = 0;
39   config->segments = 4;
40   config->pass = 1;
41   config->show_compressed = 0;
42   config->preprocessing = 0;
43   config->autofilter = 0;
44   config->alpha_compression = 0;
45 
46   // TODO(skal): tune.
47   switch (preset) {
48     case WEBP_PRESET_PICTURE:
49       config->sns_strength = 80;
50       config->filter_sharpness = 4;
51       config->filter_strength = 35;
52       break;
53     case WEBP_PRESET_PHOTO:
54       config->sns_strength = 80;
55       config->filter_sharpness = 3;
56       config->filter_strength = 30;
57       break;
58     case WEBP_PRESET_DRAWING:
59       config->sns_strength = 25;
60       config->filter_sharpness = 6;
61       config->filter_strength = 10;
62       break;
63     case WEBP_PRESET_ICON:
64       config->sns_strength = 0;
65       config->filter_strength = 0;   // disable filtering to retain sharpness
66       break;
67     case WEBP_PRESET_TEXT:
68       config->sns_strength = 0;
69       config->filter_strength = 0;   // disable filtering to retain sharpness
70       config->segments = 2;
71       break;
72     case WEBP_PRESET_DEFAULT:
73     default:
74       break;
75   }
76   return WebPValidateConfig(config);
77 }
78 
WebPValidateConfig(const WebPConfig * const config)79 int WebPValidateConfig(const WebPConfig* const config) {
80   if (config == NULL) return 0;
81   if (config->quality < 0 || config->quality > 100)
82     return 0;
83   if (config->target_size < 0)
84     return 0;
85   if (config->target_PSNR < 0)
86     return 0;
87   if (config->method < 0 || config->method > 6)
88     return 0;
89   if (config->segments < 1 || config->segments > 4)
90     return 0;
91   if (config->sns_strength < 0 || config->sns_strength > 100)
92     return 0;
93   if (config->filter_strength < 0 || config->filter_strength > 100)
94     return 0;
95   if (config->filter_sharpness < 0 || config->filter_sharpness > 7)
96     return 0;
97   if (config->filter_type < 0 || config->filter_type > 1)
98     return 0;
99   if (config->autofilter < 0 || config->autofilter > 1)
100     return 0;
101   if (config->pass < 1 || config->pass > 10)
102     return 0;
103   if (config->show_compressed < 0 || config->show_compressed > 1)
104     return 0;
105   if (config->preprocessing < 0 || config->preprocessing > 1)
106     return 0;
107   if (config->partitions < 0 || config->partitions > 3)
108     return 0;
109   if (config->alpha_compression < 0)
110     return 0;
111   return 1;
112 }
113 
114 //-----------------------------------------------------------------------------
115 
116 #if defined(__cplusplus) || defined(c_plusplus)
117 }    // extern "C"
118 #endif
119