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

Unified Diff: ui/gfx/image/image_skia.cc

Issue 10532009: Make imageSkia:::extractSubset multi-image aware. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix const refs. Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/image/image_skia.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/image_skia.cc
diff --git a/ui/gfx/image/image_skia.cc b/ui/gfx/image/image_skia.cc
index df9d99b2a8e79b767825bd43c97a39148e91b91e..95815499f95d7ebb577cb6ecef6959f001f28c7e 100644
--- a/ui/gfx/image/image_skia.cc
+++ b/ui/gfx/image/image_skia.cc
@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "ui/gfx/size.h"
+#include "ui/gfx/skia_util.h"
namespace gfx {
@@ -159,11 +160,30 @@ int ImageSkia::height() const {
bool ImageSkia::extractSubset(ImageSkia* dst, const SkIRect& subset) const {
if (isNull())
return false;
- SkBitmap dst_bitmap;
- bool return_value = storage_->bitmaps()[0].extractSubset(&dst_bitmap,
- subset);
- *dst = ImageSkia(dst_bitmap);
- return return_value;
+ gfx::ImageSkia image;
+ int dip_width = width();
+ const std::vector<SkBitmap>& bitmaps = storage_->bitmaps();
+ for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin();
+ it != bitmaps.end(); ++it) {
+ const SkBitmap& bitmap = *it;
+ int px_width = it->width();
+ float dip_scale = static_cast<float>(px_width) /
+ static_cast<float>(dip_width);
+ // Rounding boundary in case of a non-integer scale factor.
+ int x = static_cast<int>(subset.left() * dip_scale + 0.5);
+ int y = static_cast<int>(subset.top() * dip_scale + 0.5);
+ int w = static_cast<int>(subset.width() * dip_scale + 0.5);
+ int h = static_cast<int>(subset.height() * dip_scale + 0.5);
+ SkBitmap dst_bitmap;
+ SkIRect scaled_subset = SkIRect::MakeXYWH(x, y, w, h);
+ if (bitmap.extractSubset(&dst_bitmap, scaled_subset))
+ image.AddBitmapForScale(dst_bitmap, dip_scale);
+ }
+ if (image.empty())
+ return false;
+
+ *dst = image;
+ return true;
}
const std::vector<SkBitmap> ImageSkia::bitmaps() const {
« no previous file with comments | « ui/gfx/image/image_skia.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698