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

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: 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..ec43a6f0be9bba88726e82ed77d5ef55e9890316 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,10 +160,25 @@ 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);
+ bool return_value = true;
+ gfx::ImageSkia image;
+ int dip_width = width();
+ std::vector<SkBitmap> bitmaps = storage_->bitmaps();
+ for (std::vector<SkBitmap> ::const_iterator it = bitmaps.begin();
+ it != bitmaps.end(); ++it) {
Robert Sesek 2012/06/05 17:52:09 nit: align under s
kevers 2012/06/05 20:29:34 Done.
+ SkBitmap bitmap = *it;
+ int px_width = it->width();
+ float dip_scale = (float) px_width / (float) dip_width;
Robert Sesek 2012/06/05 17:52:09 C-style casts aren't allowed by the style guide.
kevers 2012/06/05 20:29:34 Changed to static_cast.
+ int x = (int) (subset.left() * dip_scale + 0.5);
+ int y = (int) (subset.top() * dip_scale + 0.5);
+ int w = (int) (subset.width() * dip_scale + 0.5);
+ int h = (int) (subset.height() * dip_scale + 0.5);
+ SkBitmap dst_bitmap;
+ SkIRect scaled_subset = SkIRect::MakeXYWH(x, y, w, h);
+ return_value &= bitmap.extractSubset(&dst_bitmap, scaled_subset);
+ image.AddBitmapForScale(dst_bitmap, dip_scale);
+ }
+ *dst = image;
Robert Sesek 2012/06/05 17:52:09 Should you overwrite dst ven if return_value==fals
kevers 2012/06/05 20:29:34 Changed to store only successfully extracted subse
return return_value;
}
« 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