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

Side by Side Diff: src/core/SkConvolver.cpp

Issue 184323003: Manually set fFilterValues in SkConvolutionFilter1D. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "SkConvolver.h" 5 #include "SkConvolver.h"
6 #include "SkSize.h" 6 #include "SkSize.h"
7 #include "SkTypes.h" 7 #include "SkTypes.h"
8 8
9 namespace { 9 namespace {
10 10
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // It is common for leading/trailing filter values to be zeros. In such 276 // It is common for leading/trailing filter values to be zeros. In such
277 // cases it is beneficial to only store the central factors. 277 // cases it is beneficial to only store the central factors.
278 // For a scaling to 1/4th in each dimension using a Lanczos-2 filter on 278 // For a scaling to 1/4th in each dimension using a Lanczos-2 filter on
279 // a 1080p image this optimization gives a ~10% speed improvement. 279 // a 1080p image this optimization gives a ~10% speed improvement.
280 int filterSize = filterLength; 280 int filterSize = filterLength;
281 int firstNonZero = 0; 281 int firstNonZero = 0;
282 while (firstNonZero < filterLength && filterValues[firstNonZero] == 0) { 282 while (firstNonZero < filterLength && filterValues[firstNonZero] == 0) {
283 firstNonZero++; 283 firstNonZero++;
284 } 284 }
285 285
286 int initialOffset = fFilterValues.count();
286 if (firstNonZero < filterLength) { 287 if (firstNonZero < filterLength) {
287 // Here we have at least one non-zero factor. 288 // Here we have at least one non-zero factor.
288 int lastNonZero = filterLength - 1; 289 int lastNonZero = filterLength - 1;
289 while (lastNonZero >= 0 && filterValues[lastNonZero] == 0) { 290 while (lastNonZero >= 0 && filterValues[lastNonZero] == 0) {
290 lastNonZero--; 291 lastNonZero--;
291 } 292 }
292 293
293 filterOffset += firstNonZero; 294 filterOffset += firstNonZero;
294 filterLength = lastNonZero + 1 - firstNonZero; 295 filterLength = lastNonZero + 1 - firstNonZero;
295 SkASSERT(filterLength > 0); 296 SkASSERT(filterLength > 0);
296 297
298 // Calling fFilterValues.reset(), or push_back() in a loop, are expensiv e.
299 // Over-allocate so we can do it once instead of iteratively.
300 if (!initialOffset) fFilterValues.resize_back(filterLength * filterLengt h);
297 for (int i = firstNonZero; i <= lastNonZero; i++) { 301 for (int i = firstNonZero; i <= lastNonZero; i++) {
298 fFilterValues.push_back(filterValues[i]); 302 fFilterValues[initialOffset + i - firstNonZero] = filterValues[i];
299 } 303 }
304
300 } else { 305 } else {
301 // Here all the factors were zeroes. 306 // Here all the factors were zeroes.
302 filterLength = 0; 307 filterLength = 0;
303 } 308 }
304 309
305 FilterInstance instance; 310 FilterInstance instance;
306 311
307 // We pushed filterLength elements onto fFilterValues 312 // We pushed filterLength elements onto fFilterValues
308 instance.fDataLocation = (static_cast<int>(fFilterValues.count()) - 313 instance.fDataLocation = (static_cast<int>(fFilterValues.count()) -
309 filterLength); 314 filterLength);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 filterX.numValues(), curOutputRow , 457 filterX.numValues(), curOutputRow ,
453 sourceHasAlpha); 458 sourceHasAlpha);
454 } else { 459 } else {
455 ConvolveVertically(filterValues, filterLength, 460 ConvolveVertically(filterValues, filterLength,
456 firstRowForFilter, 461 firstRowForFilter,
457 filterX.numValues(), curOutputRow, 462 filterX.numValues(), curOutputRow,
458 sourceHasAlpha); 463 sourceHasAlpha);
459 } 464 }
460 } 465 }
461 } 466 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698