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

Side by Side Diff: skia/ext/image_operations.cc

Issue 6334070: SIMD implementation of Convolver for Lanczos filter etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: typo Created 9 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 | « skia/ext/convolver_unittest.cc ('k') | 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 #define _USE_MATH_DEFINES 5 #define _USE_MATH_DEFINES
6 #include <algorithm> 6 #include <algorithm>
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "skia/ext/image_operations.h" 10 #include "skia/ext/image_operations.h"
11 11
12 // TODO(pkasting): skia/ext should not depend on base/! 12 // TODO(pkasting): skia/ext should not depend on base/!
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/stack_container.h" 15 #include "base/stack_container.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "skia/ext/convolver.h" 18 #include "skia/ext/convolver.h"
19 #include "third_party/skia/include/core/SkColorPriv.h"
19 #include "third_party/skia/include/core/SkBitmap.h" 20 #include "third_party/skia/include/core/SkBitmap.h"
20 #include "third_party/skia/include/core/SkRect.h" 21 #include "third_party/skia/include/core/SkRect.h"
21 #include "third_party/skia/include/core/SkFontHost.h" 22 #include "third_party/skia/include/core/SkFontHost.h"
22 #include "third_party/skia/include/core/SkColorPriv.h"
23 23
24 namespace skia { 24 namespace skia {
25 25
26 namespace { 26 namespace {
27 27
28 // Returns the ceiling/floor as an integer. 28 // Returns the ceiling/floor as an integer.
29 inline int CeilInt(float val) { 29 inline int CeilInt(float val) {
30 return static_cast<int>(ceil(val)); 30 return static_cast<int>(ceil(val));
31 } 31 }
32 inline int FloorInt(float val) { 32 inline int FloorInt(float val) {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // arbitrarily add this to the center of the filter array (this won't always 309 // arbitrarily add this to the center of the filter array (this won't always
310 // be the center of the filter function since it could get clipped on the 310 // be the center of the filter function since it could get clipped on the
311 // edges, but it doesn't matter enough to worry about that case). 311 // edges, but it doesn't matter enough to worry about that case).
312 int16 leftovers = output->FloatToFixed(1.0f) - fixed_sum; 312 int16 leftovers = output->FloatToFixed(1.0f) - fixed_sum;
313 fixed_filter_values[fixed_filter_values->size() / 2] += leftovers; 313 fixed_filter_values[fixed_filter_values->size() / 2] += leftovers;
314 314
315 // Now it's ready to go. 315 // Now it's ready to go.
316 output->AddFilter(src_begin, &fixed_filter_values[0], 316 output->AddFilter(src_begin, &fixed_filter_values[0],
317 static_cast<int>(fixed_filter_values->size())); 317 static_cast<int>(fixed_filter_values->size()));
318 } 318 }
319
320 output->PaddingForSIMD(8);
319 } 321 }
320 322
321 ImageOperations::ResizeMethod ResizeMethodToAlgorithmMethod( 323 ImageOperations::ResizeMethod ResizeMethodToAlgorithmMethod(
322 ImageOperations::ResizeMethod method) { 324 ImageOperations::ResizeMethod method) {
323 // Convert any "Quality Method" into an "Algorithm Method" 325 // Convert any "Quality Method" into an "Algorithm Method"
324 if (method >= ImageOperations::RESIZE_FIRST_ALGORITHM_METHOD && 326 if (method >= ImageOperations::RESIZE_FIRST_ALGORITHM_METHOD &&
325 method <= ImageOperations::RESIZE_LAST_ALGORITHM_METHOD) { 327 method <= ImageOperations::RESIZE_LAST_ALGORITHM_METHOD) {
326 return method; 328 return method;
327 } 329 }
328 // The call to ImageOperationsGtv::Resize() above took care of 330 // The call to ImageOperationsGtv::Resize() above took care of
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 ResizeFilter filter(method, source.width(), source.height(), 497 ResizeFilter filter(method, source.width(), source.height(),
496 dest_width, dest_height, dest_subset); 498 dest_width, dest_height, dest_subset);
497 499
498 // Get a source bitmap encompassing this touched area. We construct the 500 // Get a source bitmap encompassing this touched area. We construct the
499 // offsets and row strides such that it looks like a new bitmap, while 501 // offsets and row strides such that it looks like a new bitmap, while
500 // referring to the old data. 502 // referring to the old data.
501 const uint8* source_subset = 503 const uint8* source_subset =
502 reinterpret_cast<const uint8*>(source.getPixels()); 504 reinterpret_cast<const uint8*>(source.getPixels());
503 505
504 // Convolve into the result. 506 // Convolve into the result.
507 base::CPU cpu;
505 SkBitmap result; 508 SkBitmap result;
506 result.setConfig(SkBitmap::kARGB_8888_Config, 509 result.setConfig(SkBitmap::kARGB_8888_Config,
507 dest_subset.width(), dest_subset.height()); 510 dest_subset.width(), dest_subset.height());
508 result.allocPixels(); 511 result.allocPixels();
509 BGRAConvolve2D(source_subset, static_cast<int>(source.rowBytes()), 512 BGRAConvolve2D(source_subset, static_cast<int>(source.rowBytes()),
510 !source.isOpaque(), filter.x_filter(), filter.y_filter(), 513 !source.isOpaque(), filter.x_filter(), filter.y_filter(),
511 static_cast<int>(result.rowBytes()), 514 static_cast<int>(result.rowBytes()),
512 static_cast<unsigned char*>(result.getPixels())); 515 static_cast<unsigned char*>(result.getPixels()),
516 cpu.has_sse2());
513 517
514 // Preserve the "opaque" flag for use as an optimization later. 518 // Preserve the "opaque" flag for use as an optimization later.
515 result.setIsOpaque(source.isOpaque()); 519 result.setIsOpaque(source.isOpaque());
516 520
517 base::TimeDelta delta = base::TimeTicks::Now() - resize_start; 521 base::TimeDelta delta = base::TimeTicks::Now() - resize_start;
518 UMA_HISTOGRAM_TIMES("Image.ResampleMS", delta); 522 UMA_HISTOGRAM_TIMES("Image.ResampleMS", delta);
519 523
520 return result; 524 return result;
521 } 525 }
522 526
523 // static 527 // static
524 SkBitmap ImageOperations::Resize(const SkBitmap& source, 528 SkBitmap ImageOperations::Resize(const SkBitmap& source,
525 ResizeMethod method, 529 ResizeMethod method,
526 int dest_width, int dest_height) { 530 int dest_width, int dest_height) {
527 SkIRect dest_subset = { 0, 0, dest_width, dest_height }; 531 SkIRect dest_subset = { 0, 0, dest_width, dest_height };
528 return Resize(source, method, dest_width, dest_height, dest_subset); 532 return Resize(source, method, dest_width, dest_height, dest_subset);
529 } 533 }
530 534
531 } // namespace skia 535 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/convolver_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698