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

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: Don't overwrite dst if image is empty. 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..1ef9276f7c29e8a6c3bc08e1b1c4a75e8998be59 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,28 @@ 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();
+ std::vector<SkBitmap> bitmaps = storage_->bitmaps();
+ for (std::vector<SkBitmap> ::const_iterator it = bitmaps.begin();
Robert Sesek 2012/06/06 19:44:39 nit: no space before :
kevers 2012/06/07 12:58:03 Done.
+ it != bitmaps.end(); ++it) {
+ SkBitmap bitmap = *it;
+ int px_width = it->width();
+ float dip_scale = (float) px_width / (float) dip_width;
Robert Sesek 2012/06/06 19:44:39 C-style cast
kevers 2012/06/07 12:58:03 Fixed.
+ 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