| 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 #include "../webp/encode.h" | 14 #include "../webp/encode.h" |
| 15 | 15 |
| 16 #if defined(__cplusplus) || defined(c_plusplus) | |
| 17 extern "C" { | |
| 18 #endif | |
| 19 | |
| 20 //------------------------------------------------------------------------------ | 16 //------------------------------------------------------------------------------ |
| 21 // WebPConfig | 17 // WebPConfig |
| 22 //------------------------------------------------------------------------------ | 18 //------------------------------------------------------------------------------ |
| 23 | 19 |
| 24 int WebPConfigInitInternal(WebPConfig* config, | 20 int WebPConfigInitInternal(WebPConfig* config, |
| 25 WebPPreset preset, float quality, int version) { | 21 WebPPreset preset, float quality, int version) { |
| 26 if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_ENCODER_ABI_VERSION)) { | 22 if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_ENCODER_ABI_VERSION)) { |
| 27 return 0; // caller/system version mismatch! | 23 return 0; // caller/system version mismatch! |
| 28 } | 24 } |
| 29 if (config == NULL) return 0; | 25 if (config == NULL) return 0; |
| 30 | 26 |
| 31 config->quality = quality; | 27 config->quality = quality; |
| 32 config->target_size = 0; | 28 config->target_size = 0; |
| 33 config->target_PSNR = 0.; | 29 config->target_PSNR = 0.; |
| 34 config->method = 4; | 30 config->method = 4; |
| 35 config->sns_strength = 50; | 31 config->sns_strength = 50; |
| 36 config->filter_strength = 60; // rather high filtering, helps w/ gradients. | 32 config->filter_strength = 60; // mid-filtering |
| 37 config->filter_sharpness = 0; | 33 config->filter_sharpness = 0; |
| 38 config->filter_type = 1; // default: strong (so U/V is filtered too) | 34 config->filter_type = 1; // default: strong (so U/V is filtered too) |
| 39 config->partitions = 0; | 35 config->partitions = 0; |
| 40 config->segments = 4; | 36 config->segments = 4; |
| 41 config->pass = 1; | 37 config->pass = 1; |
| 42 config->show_compressed = 0; | 38 config->show_compressed = 0; |
| 43 config->preprocessing = 0; | 39 config->preprocessing = 0; |
| 44 config->autofilter = 0; | 40 config->autofilter = 0; |
| 45 config->partition_limit = 0; | 41 config->partition_limit = 0; |
| 46 config->alpha_compression = 1; | 42 config->alpha_compression = 1; |
| 47 config->alpha_filtering = 1; | 43 config->alpha_filtering = 1; |
| 48 config->alpha_quality = 100; | 44 config->alpha_quality = 100; |
| 49 config->lossless = 0; | 45 config->lossless = 0; |
| 50 config->image_hint = WEBP_HINT_DEFAULT; | 46 config->image_hint = WEBP_HINT_DEFAULT; |
| 51 config->emulate_jpeg_size = 0; | 47 config->emulate_jpeg_size = 0; |
| 52 config->thread_level = 0; | 48 config->thread_level = 0; |
| 53 config->low_memory = 0; | 49 config->low_memory = 0; |
| 54 | 50 |
| 55 // TODO(skal): tune. | 51 // TODO(skal): tune. |
| 56 switch (preset) { | 52 switch (preset) { |
| 57 case WEBP_PRESET_PICTURE: | 53 case WEBP_PRESET_PICTURE: |
| 58 config->sns_strength = 80; | 54 config->sns_strength = 80; |
| 59 config->filter_sharpness = 4; | 55 config->filter_sharpness = 4; |
| 60 config->filter_strength = 35; | 56 config->filter_strength = 35; |
| 57 config->preprocessing &= ~2; // no dithering |
| 61 break; | 58 break; |
| 62 case WEBP_PRESET_PHOTO: | 59 case WEBP_PRESET_PHOTO: |
| 63 config->sns_strength = 80; | 60 config->sns_strength = 80; |
| 64 config->filter_sharpness = 3; | 61 config->filter_sharpness = 3; |
| 65 config->filter_strength = 30; | 62 config->filter_strength = 30; |
| 63 config->preprocessing |= 2; |
| 66 break; | 64 break; |
| 67 case WEBP_PRESET_DRAWING: | 65 case WEBP_PRESET_DRAWING: |
| 68 config->sns_strength = 25; | 66 config->sns_strength = 25; |
| 69 config->filter_sharpness = 6; | 67 config->filter_sharpness = 6; |
| 70 config->filter_strength = 10; | 68 config->filter_strength = 10; |
| 71 break; | 69 break; |
| 72 case WEBP_PRESET_ICON: | 70 case WEBP_PRESET_ICON: |
| 73 config->sns_strength = 0; | 71 config->sns_strength = 0; |
| 74 config->filter_strength = 0; // disable filtering to retain sharpness | 72 config->filter_strength = 0; // disable filtering to retain sharpness |
| 73 config->preprocessing &= ~2; // no dithering |
| 75 break; | 74 break; |
| 76 case WEBP_PRESET_TEXT: | 75 case WEBP_PRESET_TEXT: |
| 77 config->sns_strength = 0; | 76 config->sns_strength = 0; |
| 78 config->filter_strength = 0; // disable filtering to retain sharpness | 77 config->filter_strength = 0; // disable filtering to retain sharpness |
| 78 config->preprocessing &= ~2; // no dithering |
| 79 config->segments = 2; | 79 config->segments = 2; |
| 80 break; | 80 break; |
| 81 case WEBP_PRESET_DEFAULT: | 81 case WEBP_PRESET_DEFAULT: |
| 82 default: | 82 default: |
| 83 break; | 83 break; |
| 84 } | 84 } |
| 85 return WebPValidateConfig(config); | 85 return WebPValidateConfig(config); |
| 86 } | 86 } |
| 87 | 87 |
| 88 int WebPValidateConfig(const WebPConfig* config) { | 88 int WebPValidateConfig(const WebPConfig* config) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 104 if (config->filter_sharpness < 0 || config->filter_sharpness > 7) | 104 if (config->filter_sharpness < 0 || config->filter_sharpness > 7) |
| 105 return 0; | 105 return 0; |
| 106 if (config->filter_type < 0 || config->filter_type > 1) | 106 if (config->filter_type < 0 || config->filter_type > 1) |
| 107 return 0; | 107 return 0; |
| 108 if (config->autofilter < 0 || config->autofilter > 1) | 108 if (config->autofilter < 0 || config->autofilter > 1) |
| 109 return 0; | 109 return 0; |
| 110 if (config->pass < 1 || config->pass > 10) | 110 if (config->pass < 1 || config->pass > 10) |
| 111 return 0; | 111 return 0; |
| 112 if (config->show_compressed < 0 || config->show_compressed > 1) | 112 if (config->show_compressed < 0 || config->show_compressed > 1) |
| 113 return 0; | 113 return 0; |
| 114 if (config->preprocessing < 0 || config->preprocessing > 1) | 114 if (config->preprocessing < 0 || config->preprocessing > 3) |
| 115 return 0; | 115 return 0; |
| 116 if (config->partitions < 0 || config->partitions > 3) | 116 if (config->partitions < 0 || config->partitions > 3) |
| 117 return 0; | 117 return 0; |
| 118 if (config->partition_limit < 0 || config->partition_limit > 100) | 118 if (config->partition_limit < 0 || config->partition_limit > 100) |
| 119 return 0; | 119 return 0; |
| 120 if (config->alpha_compression < 0) | 120 if (config->alpha_compression < 0) |
| 121 return 0; | 121 return 0; |
| 122 if (config->alpha_filtering < 0) | 122 if (config->alpha_filtering < 0) |
| 123 return 0; | 123 return 0; |
| 124 if (config->alpha_quality < 0 || config->alpha_quality > 100) | 124 if (config->alpha_quality < 0 || config->alpha_quality > 100) |
| 125 return 0; | 125 return 0; |
| 126 if (config->lossless < 0 || config->lossless > 1) | 126 if (config->lossless < 0 || config->lossless > 1) |
| 127 return 0; | 127 return 0; |
| 128 if (config->image_hint >= WEBP_HINT_LAST) | 128 if (config->image_hint >= WEBP_HINT_LAST) |
| 129 return 0; | 129 return 0; |
| 130 if (config->emulate_jpeg_size < 0 || config->emulate_jpeg_size > 1) | 130 if (config->emulate_jpeg_size < 0 || config->emulate_jpeg_size > 1) |
| 131 return 0; | 131 return 0; |
| 132 if (config->thread_level < 0 || config->thread_level > 1) | 132 if (config->thread_level < 0 || config->thread_level > 1) |
| 133 return 0; | 133 return 0; |
| 134 if (config->low_memory < 0 || config->low_memory > 1) | 134 if (config->low_memory < 0 || config->low_memory > 1) |
| 135 return 0; | 135 return 0; |
| 136 return 1; | 136 return 1; |
| 137 } | 137 } |
| 138 | 138 |
| 139 //------------------------------------------------------------------------------ | 139 //------------------------------------------------------------------------------ |
| 140 | 140 |
| 141 #if defined(__cplusplus) || defined(c_plusplus) | |
| 142 } // extern "C" | |
| 143 #endif | |
| OLD | NEW |