| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <cmath> | 6 #include <cmath> |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "skia/ext/image_operations.h" | 10 #include "skia/ext/image_operations.h" |
| 11 | 11 |
| 12 #include "base/gfx/rect.h" | 12 #include "base/gfx/rect.h" |
| 13 #include "base/gfx/size.h" | 13 #include "base/gfx/size.h" |
| 14 #include "base/histogram.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/stack_container.h" | 16 #include "base/stack_container.h" |
| 17 #include "base/time.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "third_party/skia/include/core/SkColorPriv.h" | 19 #include "third_party/skia/include/core/SkColorPriv.h" |
| 18 #include "skia/ext/convolver.h" | 20 #include "skia/ext/convolver.h" |
| 19 | 21 |
| 20 namespace skia { | 22 namespace skia { |
| 21 | 23 |
| 22 // TODO(brettw) remove this and put this file in the skia namespace. | 24 // TODO(brettw) remove this and put this file in the skia namespace. |
| 23 using namespace gfx; | 25 using namespace gfx; |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 255 |
| 254 } // namespace | 256 } // namespace |
| 255 | 257 |
| 256 // Resize ---------------------------------------------------------------------- | 258 // Resize ---------------------------------------------------------------------- |
| 257 | 259 |
| 258 // static | 260 // static |
| 259 SkBitmap ImageOperations::Resize(const SkBitmap& source, | 261 SkBitmap ImageOperations::Resize(const SkBitmap& source, |
| 260 ResizeMethod method, | 262 ResizeMethod method, |
| 261 int dest_width, int dest_height, | 263 int dest_width, int dest_height, |
| 262 const gfx::Rect& dest_subset) { | 264 const gfx::Rect& dest_subset) { |
| 265 // Time how long this takes to see if it's a problem for users. |
| 266 base::TimeTicks resize_start = base::TimeTicks::Now(); |
| 267 |
| 263 DCHECK(gfx::Rect(dest_width, dest_height).Contains(dest_subset)) << | 268 DCHECK(gfx::Rect(dest_width, dest_height).Contains(dest_subset)) << |
| 264 "The supplied subset does not fall within the destination image."; | 269 "The supplied subset does not fall within the destination image."; |
| 265 | 270 |
| 266 // If the size of source or destination is 0, i.e. 0x0, 0xN or Nx0, just | 271 // If the size of source or destination is 0, i.e. 0x0, 0xN or Nx0, just |
| 267 // return empty. | 272 // return empty. |
| 268 if (source.width() < 1 || source.height() < 1 || | 273 if (source.width() < 1 || source.height() < 1 || |
| 269 dest_width < 1 || dest_height < 1) | 274 dest_width < 1 || dest_height < 1) |
| 270 return SkBitmap(); | 275 return SkBitmap(); |
| 271 | 276 |
| 272 SkAutoLockPixels locker(source); | 277 SkAutoLockPixels locker(source); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 285 result.setConfig(SkBitmap::kARGB_8888_Config, | 290 result.setConfig(SkBitmap::kARGB_8888_Config, |
| 286 dest_subset.width(), dest_subset.height()); | 291 dest_subset.width(), dest_subset.height()); |
| 287 result.allocPixels(); | 292 result.allocPixels(); |
| 288 BGRAConvolve2D(source_subset, static_cast<int>(source.rowBytes()), | 293 BGRAConvolve2D(source_subset, static_cast<int>(source.rowBytes()), |
| 289 !source.isOpaque(), filter.x_filter(), filter.y_filter(), | 294 !source.isOpaque(), filter.x_filter(), filter.y_filter(), |
| 290 static_cast<unsigned char*>(result.getPixels())); | 295 static_cast<unsigned char*>(result.getPixels())); |
| 291 | 296 |
| 292 // Preserve the "opaque" flag for use as an optimization later. | 297 // Preserve the "opaque" flag for use as an optimization later. |
| 293 result.setIsOpaque(source.isOpaque()); | 298 result.setIsOpaque(source.isOpaque()); |
| 294 | 299 |
| 300 base::TimeDelta delta = base::TimeTicks::Now() - resize_start; |
| 301 UMA_HISTOGRAM_TIMES("Image.ResampleMS", delta); |
| 302 |
| 295 return result; | 303 return result; |
| 296 } | 304 } |
| 297 | 305 |
| 298 // static | 306 // static |
| 299 SkBitmap ImageOperations::Resize(const SkBitmap& source, | 307 SkBitmap ImageOperations::Resize(const SkBitmap& source, |
| 300 ResizeMethod method, | 308 ResizeMethod method, |
| 301 int dest_width, int dest_height) { | 309 int dest_width, int dest_height) { |
| 302 gfx::Rect dest_subset(0, 0, dest_width, dest_height); | 310 gfx::Rect dest_subset(0, 0, dest_width, dest_height); |
| 303 return Resize(source, method, dest_width, dest_height, dest_subset); | 311 return Resize(source, method, dest_width, dest_height, dest_subset); |
| 304 } | 312 } |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 | 566 |
| 559 dst_row[x] = source_row[x_pix]; | 567 dst_row[x] = source_row[x_pix]; |
| 560 } | 568 } |
| 561 } | 569 } |
| 562 | 570 |
| 563 return cropped; | 571 return cropped; |
| 564 } | 572 } |
| 565 | 573 |
| 566 } // namespace skia | 574 } // namespace skia |
| 567 | 575 |
| OLD | NEW |