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

Side by Side 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 Nits. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/image/image_skia.h ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "ui/gfx/image/image_skia.h" 5 #include "ui/gfx/image/image_skia.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "ui/gfx/size.h" 11 #include "ui/gfx/size.h"
12 #include "ui/gfx/skia_util.h"
12 13
13 namespace gfx { 14 namespace gfx {
14 15
15 namespace internal { 16 namespace internal {
16 17
17 // A helper class such that ImageSkia can be cheaply copied. ImageSkia holds a 18 // A helper class such that ImageSkia can be cheaply copied. ImageSkia holds a
18 // refptr instance of ImageSkiaStorage, which in turn holds all of ImageSkia's 19 // refptr instance of ImageSkiaStorage, which in turn holds all of ImageSkia's
19 // information. 20 // information.
20 class ImageSkiaStorage : public base::RefCounted<ImageSkiaStorage> { 21 class ImageSkiaStorage : public base::RefCounted<ImageSkiaStorage> {
21 public: 22 public:
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return isNull() ? 0 : storage_->size().width(); 153 return isNull() ? 0 : storage_->size().width();
153 } 154 }
154 155
155 int ImageSkia::height() const { 156 int ImageSkia::height() const {
156 return isNull() ? 0 : storage_->size().height(); 157 return isNull() ? 0 : storage_->size().height();
157 } 158 }
158 159
159 bool ImageSkia::extractSubset(ImageSkia* dst, const SkIRect& subset) const { 160 bool ImageSkia::extractSubset(ImageSkia* dst, const SkIRect& subset) const {
160 if (isNull()) 161 if (isNull())
161 return false; 162 return false;
162 SkBitmap dst_bitmap; 163 gfx::ImageSkia image;
163 bool return_value = storage_->bitmaps()[0].extractSubset(&dst_bitmap, 164 int dip_width = width();
164 subset); 165 std::vector<SkBitmap> bitmaps = storage_->bitmaps();
sky 2012/06/07 17:42:19 const std::vector<SkBitmap>&
kevers 2012/06/07 18:12:00 Done.
165 *dst = ImageSkia(dst_bitmap); 166 for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin();
166 return return_value; 167 it != bitmaps.end(); ++it) {
168 SkBitmap bitmap = *it;
sky 2012/06/07 17:42:19 const SkBitmap&
kevers 2012/06/07 18:12:00 Done.
169 int px_width = it->width();
170 float dip_scale = static_cast<float>(px_width) /
171 static_cast<float>(dip_width);
172 int x = static_cast<int>(subset.left() * dip_scale + 0.5);
sky 2012/06/07 17:42:19 Add a comment as to why the + .5
kevers 2012/06/07 18:12:00 Done.
173 int y = static_cast<int>(subset.top() * dip_scale + 0.5);
174 int w = static_cast<int>(subset.width() * dip_scale + 0.5);
175 int h = static_cast<int>(subset.height() * dip_scale + 0.5);
176 SkBitmap dst_bitmap;
177 SkIRect scaled_subset = SkIRect::MakeXYWH(x, y, w, h);
178 if (bitmap.extractSubset(&dst_bitmap, scaled_subset))
179 image.AddBitmapForScale(dst_bitmap, dip_scale);
180 }
181 if (image.empty())
182 return false;
183
184 *dst = image;
185 return true;
167 } 186 }
168 187
169 const std::vector<SkBitmap> ImageSkia::bitmaps() const { 188 const std::vector<SkBitmap> ImageSkia::bitmaps() const {
170 return storage_->bitmaps(); 189 return storage_->bitmaps();
171 } 190 }
172 191
173 const SkBitmap* ImageSkia::bitmap() const { 192 const SkBitmap* ImageSkia::bitmap() const {
174 if (isNull()) { 193 if (isNull()) {
175 // Callers expect an SkBitmap even if it is |isNull()|. 194 // Callers expect an SkBitmap even if it is |isNull()|.
176 // TODO(pkotwicz): Fix this. 195 // TODO(pkotwicz): Fix this.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 242
224 if (closest_index >= 0) { 243 if (closest_index >= 0) {
225 *bitmap_scale_factor = static_cast<float>(bitmaps[closest_index].width()) / 244 *bitmap_scale_factor = static_cast<float>(bitmaps[closest_index].width()) /
226 width(); 245 width();
227 } 246 }
228 247
229 return closest_index; 248 return closest_index;
230 } 249 }
231 250
232 } // namespace gfx 251 } // namespace gfx
OLDNEW
« 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