Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: third_party/libwebp/dsp/filters.c

Issue 1546003002: libwebp: update to 0.5.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libwebp/dsp/enc_sse41.c ('k') | third_party/libwebp/dsp/filters_mips_dsp_r2.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Spatial prediction using various filters 10 // Spatial prediction using various filters
11 // 11 //
12 // Author: Urvang (urvang@google.com) 12 // Author: Urvang (urvang@google.com)
13 13
14 #include "./filters.h" 14 #include "./dsp.h"
15 #include <assert.h> 15 #include <assert.h>
16 #include <stdlib.h> 16 #include <stdlib.h>
17 #include <string.h> 17 #include <string.h>
18 18
19 //------------------------------------------------------------------------------ 19 //------------------------------------------------------------------------------
20 // Helpful macro. 20 // Helpful macro.
21 21
22 # define SANITY_CHECK(in, out) \ 22 # define SANITY_CHECK(in, out) \
23 assert(in != NULL); \ 23 assert(in != NULL); \
24 assert(out != NULL); \ 24 assert(out != NULL); \
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // Leftmost pixel is predicted from above. 68 // Leftmost pixel is predicted from above.
69 PredictLine(in, preds - stride, out, 1, inverse); 69 PredictLine(in, preds - stride, out, 1, inverse);
70 PredictLine(in + 1, preds, out + 1, width - 1, inverse); 70 PredictLine(in + 1, preds, out + 1, width - 1, inverse);
71 ++row; 71 ++row;
72 preds += stride; 72 preds += stride;
73 in += stride; 73 in += stride;
74 out += stride; 74 out += stride;
75 } 75 }
76 } 76 }
77 77
78 static void HorizontalFilter(const uint8_t* data, int width, int height,
79 int stride, uint8_t* filtered_data) {
80 DoHorizontalFilter(data, width, height, stride, 0, height, 0, filtered_data);
81 }
82
83 static void HorizontalUnfilter(int width, int height, int stride, int row,
84 int num_rows, uint8_t* data) {
85 DoHorizontalFilter(data, width, height, stride, row, num_rows, 1, data);
86 }
87
88 //------------------------------------------------------------------------------ 78 //------------------------------------------------------------------------------
89 // Vertical filter. 79 // Vertical filter.
90 80
91 static WEBP_INLINE void DoVerticalFilter(const uint8_t* in, 81 static WEBP_INLINE void DoVerticalFilter(const uint8_t* in,
92 int width, int height, int stride, 82 int width, int height, int stride,
93 int row, int num_rows, 83 int row, int num_rows,
94 int inverse, uint8_t* out) { 84 int inverse, uint8_t* out) {
95 const uint8_t* preds; 85 const uint8_t* preds;
96 const size_t start_offset = row * stride; 86 const size_t start_offset = row * stride;
97 const int last_row = row + num_rows; 87 const int last_row = row + num_rows;
(...skipping 18 matching lines...) Expand all
116 // Filter line-by-line. 106 // Filter line-by-line.
117 while (row < last_row) { 107 while (row < last_row) {
118 PredictLine(in, preds, out, width, inverse); 108 PredictLine(in, preds, out, width, inverse);
119 ++row; 109 ++row;
120 preds += stride; 110 preds += stride;
121 in += stride; 111 in += stride;
122 out += stride; 112 out += stride;
123 } 113 }
124 } 114 }
125 115
126 static void VerticalFilter(const uint8_t* data, int width, int height,
127 int stride, uint8_t* filtered_data) {
128 DoVerticalFilter(data, width, height, stride, 0, height, 0, filtered_data);
129 }
130
131 static void VerticalUnfilter(int width, int height, int stride, int row,
132 int num_rows, uint8_t* data) {
133 DoVerticalFilter(data, width, height, stride, row, num_rows, 1, data);
134 }
135
136 //------------------------------------------------------------------------------ 116 //------------------------------------------------------------------------------
137 // Gradient filter. 117 // Gradient filter.
138 118
139 static WEBP_INLINE int GradientPredictor(uint8_t a, uint8_t b, uint8_t c) { 119 static WEBP_INLINE int GradientPredictor(uint8_t a, uint8_t b, uint8_t c) {
140 const int g = a + b - c; 120 const int g = a + b - c;
141 return ((g & ~0xff) == 0) ? g : (g < 0) ? 0 : 255; // clip to 8bit 121 return ((g & ~0xff) == 0) ? g : (g < 0) ? 0 : 255; // clip to 8bit
142 } 122 }
143 123
144 static WEBP_INLINE void DoGradientFilter(const uint8_t* in, 124 static WEBP_INLINE void DoGradientFilter(const uint8_t* in,
145 int width, int height, int stride, 125 int width, int height, int stride,
(...skipping 28 matching lines...) Expand all
174 preds[w - stride - 1]); 154 preds[w - stride - 1]);
175 out[w] = in[w] + (inverse ? pred : -pred); 155 out[w] = in[w] + (inverse ? pred : -pred);
176 } 156 }
177 ++row; 157 ++row;
178 preds += stride; 158 preds += stride;
179 in += stride; 159 in += stride;
180 out += stride; 160 out += stride;
181 } 161 }
182 } 162 }
183 163
164 #undef SANITY_CHECK
165
166 //------------------------------------------------------------------------------
167
168 static void HorizontalFilter(const uint8_t* data, int width, int height,
169 int stride, uint8_t* filtered_data) {
170 DoHorizontalFilter(data, width, height, stride, 0, height, 0, filtered_data);
171 }
172
173 static void VerticalFilter(const uint8_t* data, int width, int height,
174 int stride, uint8_t* filtered_data) {
175 DoVerticalFilter(data, width, height, stride, 0, height, 0, filtered_data);
176 }
177
178
184 static void GradientFilter(const uint8_t* data, int width, int height, 179 static void GradientFilter(const uint8_t* data, int width, int height,
185 int stride, uint8_t* filtered_data) { 180 int stride, uint8_t* filtered_data) {
186 DoGradientFilter(data, width, height, stride, 0, height, 0, filtered_data); 181 DoGradientFilter(data, width, height, stride, 0, height, 0, filtered_data);
187 } 182 }
188 183
184
185 //------------------------------------------------------------------------------
186
187 static void VerticalUnfilter(int width, int height, int stride, int row,
188 int num_rows, uint8_t* data) {
189 DoVerticalFilter(data, width, height, stride, row, num_rows, 1, data);
190 }
191
192 static void HorizontalUnfilter(int width, int height, int stride, int row,
193 int num_rows, uint8_t* data) {
194 DoHorizontalFilter(data, width, height, stride, row, num_rows, 1, data);
195 }
196
189 static void GradientUnfilter(int width, int height, int stride, int row, 197 static void GradientUnfilter(int width, int height, int stride, int row,
190 int num_rows, uint8_t* data) { 198 int num_rows, uint8_t* data) {
191 DoGradientFilter(data, width, height, stride, row, num_rows, 1, data); 199 DoGradientFilter(data, width, height, stride, row, num_rows, 1, data);
192 } 200 }
193 201
194 #undef SANITY_CHECK 202 //------------------------------------------------------------------------------
203 // Init function
195 204
196 // ----------------------------------------------------------------------------- 205 WebPFilterFunc WebPFilters[WEBP_FILTER_LAST];
197 // Quick estimate of a potentially interesting filter mode to try. 206 WebPUnfilterFunc WebPUnfilters[WEBP_FILTER_LAST];
198 207
199 #define SMAX 16 208 extern void VP8FiltersInitMIPSdspR2(void);
200 #define SDIFF(a, b) (abs((a) - (b)) >> 4) // Scoring diff, in [0..SMAX) 209 extern void VP8FiltersInitSSE2(void);
201 210
202 WEBP_FILTER_TYPE EstimateBestFilter(const uint8_t* data, 211 static volatile VP8CPUInfo filters_last_cpuinfo_used =
203 int width, int height, int stride) { 212 (VP8CPUInfo)&filters_last_cpuinfo_used;
204 int i, j;
205 int bins[WEBP_FILTER_LAST][SMAX];
206 memset(bins, 0, sizeof(bins));
207 213
208 // We only sample every other pixels. That's enough. 214 WEBP_TSAN_IGNORE_FUNCTION void VP8FiltersInit(void) {
209 for (j = 2; j < height - 1; j += 2) { 215 if (filters_last_cpuinfo_used == VP8GetCPUInfo) return;
210 const uint8_t* const p = data + j * stride; 216
211 int mean = p[0]; 217 WebPUnfilters[WEBP_FILTER_NONE] = NULL;
212 for (i = 2; i < width - 1; i += 2) { 218 WebPUnfilters[WEBP_FILTER_HORIZONTAL] = HorizontalUnfilter;
213 const int diff0 = SDIFF(p[i], mean); 219 WebPUnfilters[WEBP_FILTER_VERTICAL] = VerticalUnfilter;
214 const int diff1 = SDIFF(p[i], p[i - 1]); 220 WebPUnfilters[WEBP_FILTER_GRADIENT] = GradientUnfilter;
215 const int diff2 = SDIFF(p[i], p[i - width]); 221
216 const int grad_pred = 222 WebPFilters[WEBP_FILTER_NONE] = NULL;
217 GradientPredictor(p[i - 1], p[i - width], p[i - width - 1]); 223 WebPFilters[WEBP_FILTER_HORIZONTAL] = HorizontalFilter;
218 const int diff3 = SDIFF(p[i], grad_pred); 224 WebPFilters[WEBP_FILTER_VERTICAL] = VerticalFilter;
219 bins[WEBP_FILTER_NONE][diff0] = 1; 225 WebPFilters[WEBP_FILTER_GRADIENT] = GradientFilter;
220 bins[WEBP_FILTER_HORIZONTAL][diff1] = 1; 226
221 bins[WEBP_FILTER_VERTICAL][diff2] = 1; 227 if (VP8GetCPUInfo != NULL) {
222 bins[WEBP_FILTER_GRADIENT][diff3] = 1; 228 #if defined(WEBP_USE_SSE2)
223 mean = (3 * mean + p[i] + 2) >> 2; 229 if (VP8GetCPUInfo(kSSE2)) {
230 VP8FiltersInitSSE2();
224 } 231 }
232 #endif
233 #if defined(WEBP_USE_MIPS_DSP_R2)
234 if (VP8GetCPUInfo(kMIPSdspR2)) {
235 VP8FiltersInitMIPSdspR2();
236 }
237 #endif
225 } 238 }
226 { 239 filters_last_cpuinfo_used = VP8GetCPUInfo;
227 int filter;
228 WEBP_FILTER_TYPE best_filter = WEBP_FILTER_NONE;
229 int best_score = 0x7fffffff;
230 for (filter = WEBP_FILTER_NONE; filter < WEBP_FILTER_LAST; ++filter) {
231 int score = 0;
232 for (i = 0; i < SMAX; ++i) {
233 if (bins[filter][i] > 0) {
234 score += i;
235 }
236 }
237 if (score < best_score) {
238 best_score = score;
239 best_filter = (WEBP_FILTER_TYPE)filter;
240 }
241 }
242 return best_filter;
243 }
244 } 240 }
245
246 #undef SMAX
247 #undef SDIFF
248
249 //------------------------------------------------------------------------------
250
251 const WebPFilterFunc WebPFilters[WEBP_FILTER_LAST] = {
252 NULL, // WEBP_FILTER_NONE
253 HorizontalFilter, // WEBP_FILTER_HORIZONTAL
254 VerticalFilter, // WEBP_FILTER_VERTICAL
255 GradientFilter // WEBP_FILTER_GRADIENT
256 };
257
258 const WebPUnfilterFunc WebPUnfilters[WEBP_FILTER_LAST] = {
259 NULL, // WEBP_FILTER_NONE
260 HorizontalUnfilter, // WEBP_FILTER_HORIZONTAL
261 VerticalUnfilter, // WEBP_FILTER_VERTICAL
262 GradientUnfilter // WEBP_FILTER_GRADIENT
263 };
264
265 //------------------------------------------------------------------------------
266
OLDNEW
« no previous file with comments | « third_party/libwebp/dsp/enc_sse41.c ('k') | third_party/libwebp/dsp/filters_mips_dsp_r2.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698