| OLD | NEW |
| 1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // This code is licensed under the same terms as WebM: | 3 // Use of this source code is governed by a BSD-style license |
| 4 // Software License Agreement: http://www.webmproject.org/license/software/ | 4 // that can be found in the COPYING file in the root of the source |
| 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ | 5 // tree. An additional intellectual property rights grant can be found |
| 6 // in the file PATENTS. All contributing project authors may |
| 7 // be found in the AUTHORS file in the root of the source tree. |
| 6 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 7 // | 9 // |
| 8 // Spatial prediction using various filters | 10 // Spatial prediction using various filters |
| 9 // | 11 // |
| 10 // Author: Urvang (urvang@google.com) | 12 // Author: Urvang (urvang@google.com) |
| 11 | 13 |
| 12 #include "./filters.h" | 14 #include "./filters.h" |
| 13 #include <assert.h> | 15 #include <assert.h> |
| 14 #include <stdlib.h> | 16 #include <stdlib.h> |
| 15 #include <string.h> | 17 #include <string.h> |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 DoGradientFilter(data, width, height, stride, 0, filtered_data); | 149 DoGradientFilter(data, width, height, stride, 0, filtered_data); |
| 148 } | 150 } |
| 149 | 151 |
| 150 static void GradientUnfilter(int width, int height, int stride, uint8_t* data) { | 152 static void GradientUnfilter(int width, int height, int stride, uint8_t* data) { |
| 151 DoGradientFilter(data, width, height, stride, 1, data); | 153 DoGradientFilter(data, width, height, stride, 1, data); |
| 152 } | 154 } |
| 153 | 155 |
| 154 #undef SANITY_CHECK | 156 #undef SANITY_CHECK |
| 155 | 157 |
| 156 // ----------------------------------------------------------------------------- | 158 // ----------------------------------------------------------------------------- |
| 157 // Quick estimate of a potentially interesting filter mode to try, in addition | 159 // Quick estimate of a potentially interesting filter mode to try. |
| 158 // to the default NONE. | |
| 159 | 160 |
| 160 #define SMAX 16 | 161 #define SMAX 16 |
| 161 #define SDIFF(a, b) (abs((a) - (b)) >> 4) // Scoring diff, in [0..SMAX) | 162 #define SDIFF(a, b) (abs((a) - (b)) >> 4) // Scoring diff, in [0..SMAX) |
| 162 | 163 |
| 163 WEBP_FILTER_TYPE EstimateBestFilter(const uint8_t* data, | 164 WEBP_FILTER_TYPE EstimateBestFilter(const uint8_t* data, |
| 164 int width, int height, int stride) { | 165 int width, int height, int stride) { |
| 165 int i, j; | 166 int i, j; |
| 166 int bins[WEBP_FILTER_LAST][SMAX]; | 167 int bins[WEBP_FILTER_LAST][SMAX]; |
| 167 memset(bins, 0, sizeof(bins)); | 168 memset(bins, 0, sizeof(bins)); |
| 169 |
| 168 // We only sample every other pixels. That's enough. | 170 // We only sample every other pixels. That's enough. |
| 169 for (j = 2; j < height - 1; j += 2) { | 171 for (j = 2; j < height - 1; j += 2) { |
| 170 const uint8_t* const p = data + j * stride; | 172 const uint8_t* const p = data + j * stride; |
| 171 int mean = p[0]; | 173 int mean = p[0]; |
| 172 for (i = 2; i < width - 1; i += 2) { | 174 for (i = 2; i < width - 1; i += 2) { |
| 173 const int diff0 = SDIFF(p[i], mean); | 175 const int diff0 = SDIFF(p[i], mean); |
| 174 const int diff1 = SDIFF(p[i], p[i - 1]); | 176 const int diff1 = SDIFF(p[i], p[i - 1]); |
| 175 const int diff2 = SDIFF(p[i], p[i - width]); | 177 const int diff2 = SDIFF(p[i], p[i - width]); |
| 176 const int grad_pred = | 178 const int grad_pred = |
| 177 GradientPredictor(p[i - 1], p[i - width], p[i - width - 1]); | 179 GradientPredictor(p[i - 1], p[i - width], p[i - width - 1]); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 HorizontalUnfilter, // WEBP_FILTER_HORIZONTAL | 221 HorizontalUnfilter, // WEBP_FILTER_HORIZONTAL |
| 220 VerticalUnfilter, // WEBP_FILTER_VERTICAL | 222 VerticalUnfilter, // WEBP_FILTER_VERTICAL |
| 221 GradientUnfilter // WEBP_FILTER_GRADIENT | 223 GradientUnfilter // WEBP_FILTER_GRADIENT |
| 222 }; | 224 }; |
| 223 | 225 |
| 224 //------------------------------------------------------------------------------ | 226 //------------------------------------------------------------------------------ |
| 225 | 227 |
| 226 #if defined(__cplusplus) || defined(c_plusplus) | 228 #if defined(__cplusplus) || defined(c_plusplus) |
| 227 } // extern "C" | 229 } // extern "C" |
| 228 #endif | 230 #endif |
| OLD | NEW |