| OLD | NEW |
| 1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Use of this source code is governed by a BSD-style license | 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 | 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 | 5 // tree. An additional intellectual property rights grant can be found |
| 6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
| 7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
| 8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 9 // | 9 // |
| 10 // Coding tools configuration | 10 // Coding tools configuration |
| 11 // | 11 // |
| 12 // Author: Skal (pascal.massimino@gmail.com) | 12 // Author: Skal (pascal.massimino@gmail.com) |
| 13 | 13 |
| 14 #ifdef HAVE_CONFIG_H |
| 15 #include "../webp/config.h" |
| 16 #endif |
| 17 |
| 14 #include "../webp/encode.h" | 18 #include "../webp/encode.h" |
| 15 | 19 |
| 16 //------------------------------------------------------------------------------ | 20 //------------------------------------------------------------------------------ |
| 17 // WebPConfig | 21 // WebPConfig |
| 18 //------------------------------------------------------------------------------ | 22 //------------------------------------------------------------------------------ |
| 19 | 23 |
| 20 int WebPConfigInitInternal(WebPConfig* config, | 24 int WebPConfigInitInternal(WebPConfig* config, |
| 21 WebPPreset preset, float quality, int version) { | 25 WebPPreset preset, float quality, int version) { |
| 22 if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_ENCODER_ABI_VERSION)) { | 26 if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_ENCODER_ABI_VERSION)) { |
| 23 return 0; // caller/system version mismatch! | 27 return 0; // caller/system version mismatch! |
| (...skipping 18 matching lines...) Expand all Loading... |
| 42 config->alpha_compression = 1; | 46 config->alpha_compression = 1; |
| 43 config->alpha_filtering = 1; | 47 config->alpha_filtering = 1; |
| 44 config->alpha_quality = 100; | 48 config->alpha_quality = 100; |
| 45 config->lossless = 0; | 49 config->lossless = 0; |
| 46 config->exact = 0; | 50 config->exact = 0; |
| 47 config->image_hint = WEBP_HINT_DEFAULT; | 51 config->image_hint = WEBP_HINT_DEFAULT; |
| 48 config->emulate_jpeg_size = 0; | 52 config->emulate_jpeg_size = 0; |
| 49 config->thread_level = 0; | 53 config->thread_level = 0; |
| 50 config->low_memory = 0; | 54 config->low_memory = 0; |
| 51 config->near_lossless = 100; | 55 config->near_lossless = 100; |
| 52 #ifdef WEBP_EXPERIMENTAL_FEATURES | 56 config->use_delta_palette = 0; |
| 53 config->delta_palettization = 0; | 57 config->use_sharp_yuv = 0; |
| 54 #endif // WEBP_EXPERIMENTAL_FEATURES | |
| 55 | 58 |
| 56 // TODO(skal): tune. | 59 // TODO(skal): tune. |
| 57 switch (preset) { | 60 switch (preset) { |
| 58 case WEBP_PRESET_PICTURE: | 61 case WEBP_PRESET_PICTURE: |
| 59 config->sns_strength = 80; | 62 config->sns_strength = 80; |
| 60 config->filter_sharpness = 4; | 63 config->filter_sharpness = 4; |
| 61 config->filter_strength = 35; | 64 config->filter_strength = 35; |
| 62 config->preprocessing &= ~2; // no dithering | 65 config->preprocessing &= ~2; // no dithering |
| 63 break; | 66 break; |
| 64 case WEBP_PRESET_PHOTO: | 67 case WEBP_PRESET_PHOTO: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 85 break; | 88 break; |
| 86 case WEBP_PRESET_DEFAULT: | 89 case WEBP_PRESET_DEFAULT: |
| 87 default: | 90 default: |
| 88 break; | 91 break; |
| 89 } | 92 } |
| 90 return WebPValidateConfig(config); | 93 return WebPValidateConfig(config); |
| 91 } | 94 } |
| 92 | 95 |
| 93 int WebPValidateConfig(const WebPConfig* config) { | 96 int WebPValidateConfig(const WebPConfig* config) { |
| 94 if (config == NULL) return 0; | 97 if (config == NULL) return 0; |
| 95 if (config->quality < 0 || config->quality > 100) | 98 if (config->quality < 0 || config->quality > 100) return 0; |
| 99 if (config->target_size < 0) return 0; |
| 100 if (config->target_PSNR < 0) return 0; |
| 101 if (config->method < 0 || config->method > 6) return 0; |
| 102 if (config->segments < 1 || config->segments > 4) return 0; |
| 103 if (config->sns_strength < 0 || config->sns_strength > 100) return 0; |
| 104 if (config->filter_strength < 0 || config->filter_strength > 100) return 0; |
| 105 if (config->filter_sharpness < 0 || config->filter_sharpness > 7) return 0; |
| 106 if (config->filter_type < 0 || config->filter_type > 1) return 0; |
| 107 if (config->autofilter < 0 || config->autofilter > 1) return 0; |
| 108 if (config->pass < 1 || config->pass > 10) return 0; |
| 109 if (config->show_compressed < 0 || config->show_compressed > 1) return 0; |
| 110 if (config->preprocessing < 0 || config->preprocessing > 7) return 0; |
| 111 if (config->partitions < 0 || config->partitions > 3) return 0; |
| 112 if (config->partition_limit < 0 || config->partition_limit > 100) return 0; |
| 113 if (config->alpha_compression < 0) return 0; |
| 114 if (config->alpha_filtering < 0) return 0; |
| 115 if (config->alpha_quality < 0 || config->alpha_quality > 100) return 0; |
| 116 if (config->lossless < 0 || config->lossless > 1) return 0; |
| 117 if (config->near_lossless < 0 || config->near_lossless > 100) return 0; |
| 118 if (config->image_hint >= WEBP_HINT_LAST) return 0; |
| 119 if (config->emulate_jpeg_size < 0 || config->emulate_jpeg_size > 1) return 0; |
| 120 if (config->thread_level < 0 || config->thread_level > 1) return 0; |
| 121 if (config->low_memory < 0 || config->low_memory > 1) return 0; |
| 122 if (config->exact < 0 || config->exact > 1) return 0; |
| 123 if (config->use_delta_palette < 0 || config->use_delta_palette > 1) { |
| 96 return 0; | 124 return 0; |
| 97 if (config->target_size < 0) | 125 } |
| 98 return 0; | 126 if (config->use_sharp_yuv < 0 || config->use_sharp_yuv > 1) return 0; |
| 99 if (config->target_PSNR < 0) | 127 |
| 100 return 0; | |
| 101 if (config->method < 0 || config->method > 6) | |
| 102 return 0; | |
| 103 if (config->segments < 1 || config->segments > 4) | |
| 104 return 0; | |
| 105 if (config->sns_strength < 0 || config->sns_strength > 100) | |
| 106 return 0; | |
| 107 if (config->filter_strength < 0 || config->filter_strength > 100) | |
| 108 return 0; | |
| 109 if (config->filter_sharpness < 0 || config->filter_sharpness > 7) | |
| 110 return 0; | |
| 111 if (config->filter_type < 0 || config->filter_type > 1) | |
| 112 return 0; | |
| 113 if (config->autofilter < 0 || config->autofilter > 1) | |
| 114 return 0; | |
| 115 if (config->pass < 1 || config->pass > 10) | |
| 116 return 0; | |
| 117 if (config->show_compressed < 0 || config->show_compressed > 1) | |
| 118 return 0; | |
| 119 if (config->preprocessing < 0 || config->preprocessing > 7) | |
| 120 return 0; | |
| 121 if (config->partitions < 0 || config->partitions > 3) | |
| 122 return 0; | |
| 123 if (config->partition_limit < 0 || config->partition_limit > 100) | |
| 124 return 0; | |
| 125 if (config->alpha_compression < 0) | |
| 126 return 0; | |
| 127 if (config->alpha_filtering < 0) | |
| 128 return 0; | |
| 129 if (config->alpha_quality < 0 || config->alpha_quality > 100) | |
| 130 return 0; | |
| 131 if (config->lossless < 0 || config->lossless > 1) | |
| 132 return 0; | |
| 133 if (config->near_lossless < 0 || config->near_lossless > 100) | |
| 134 return 0; | |
| 135 if (config->image_hint >= WEBP_HINT_LAST) | |
| 136 return 0; | |
| 137 if (config->emulate_jpeg_size < 0 || config->emulate_jpeg_size > 1) | |
| 138 return 0; | |
| 139 if (config->thread_level < 0 || config->thread_level > 1) | |
| 140 return 0; | |
| 141 if (config->low_memory < 0 || config->low_memory > 1) | |
| 142 return 0; | |
| 143 if (config->exact < 0 || config->exact > 1) | |
| 144 return 0; | |
| 145 #ifdef WEBP_EXPERIMENTAL_FEATURES | |
| 146 if (config->delta_palettization < 0 || config->delta_palettization > 1) | |
| 147 return 0; | |
| 148 #endif // WEBP_EXPERIMENTAL_FEATURES | |
| 149 return 1; | 128 return 1; |
| 150 } | 129 } |
| 151 | 130 |
| 152 //------------------------------------------------------------------------------ | 131 //------------------------------------------------------------------------------ |
| 153 | 132 |
| 154 #define MAX_LEVEL 9 | 133 #define MAX_LEVEL 9 |
| 155 | 134 |
| 156 // Mapping between -z level and -m / -q parameter settings. | 135 // Mapping between -z level and -m / -q parameter settings. |
| 157 static const struct { | 136 static const struct { |
| 158 uint8_t method_; | 137 uint8_t method_; |
| 159 uint8_t quality_; | 138 uint8_t quality_; |
| 160 } kLosslessPresets[MAX_LEVEL + 1] = { | 139 } kLosslessPresets[MAX_LEVEL + 1] = { |
| 161 { 0, 0 }, { 1, 20 }, { 2, 25 }, { 3, 30 }, { 3, 50 }, | 140 { 0, 0 }, { 1, 20 }, { 2, 25 }, { 3, 30 }, { 3, 50 }, |
| 162 { 4, 50 }, { 4, 75 }, { 4, 90 }, { 5, 90 }, { 6, 100 } | 141 { 4, 50 }, { 4, 75 }, { 4, 90 }, { 5, 90 }, { 6, 100 } |
| 163 }; | 142 }; |
| 164 | 143 |
| 165 int WebPConfigLosslessPreset(WebPConfig* config, int level) { | 144 int WebPConfigLosslessPreset(WebPConfig* config, int level) { |
| 166 if (config == NULL || level < 0 || level > MAX_LEVEL) return 0; | 145 if (config == NULL || level < 0 || level > MAX_LEVEL) return 0; |
| 167 config->lossless = 1; | 146 config->lossless = 1; |
| 168 config->method = kLosslessPresets[level].method_; | 147 config->method = kLosslessPresets[level].method_; |
| 169 config->quality = kLosslessPresets[level].quality_; | 148 config->quality = kLosslessPresets[level].quality_; |
| 170 return 1; | 149 return 1; |
| 171 } | 150 } |
| 172 | 151 |
| 173 //------------------------------------------------------------------------------ | 152 //------------------------------------------------------------------------------ |
| OLD | NEW |