Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_operations.h" | 5 #include "ui/gfx/image/image_skia_operations.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "skia/ext/image_operations.h" | 9 #include "skia/ext/image_operations.h" |
| 10 #include "skia/ext/platform_canvas.h" | 10 #include "skia/ext/platform_canvas.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 private: | 173 private: |
| 174 const ImageSkia& source_; | 174 const ImageSkia& source_; |
| 175 const int src_x_; | 175 const int src_x_; |
| 176 const int src_y_; | 176 const int src_y_; |
| 177 const int dst_w_; | 177 const int dst_w_; |
| 178 const int dst_h_; | 178 const int dst_h_; |
| 179 | 179 |
| 180 DISALLOW_COPY_AND_ASSIGN(TiledImageSource); | 180 DISALLOW_COPY_AND_ASSIGN(TiledImageSource); |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 class ButtonImageSource: public gfx::ImageSkiaSource { | |
| 184 public: | |
| 185 ButtonImageSource(SkColor color, | |
| 186 const ImageSkia& image, | |
| 187 const ImageSkia& mask) | |
| 188 : color_(color), | |
| 189 image_(image), | |
| 190 mask_(mask) { | |
| 191 } | |
|
oshima
2012/07/13 16:54:55
destructor
pkotwicz
2012/07/15 03:36:48
Done.
| |
| 192 | |
| 193 // gfx::ImageSkiaSource overrides: | |
| 194 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | |
| 195 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); | |
| 196 ImageSkiaRep mask_rep = mask_.GetRepresentation(scale_factor); | |
| 197 MatchScale(&image_rep, &mask_rep); | |
| 198 return ImageSkiaRep( | |
| 199 SkBitmapOperations::CreateButtonBackground(color_, | |
| 200 image_rep.sk_bitmap(), mask_rep.sk_bitmap()), | |
| 201 image_rep.scale_factor()); | |
| 202 } | |
| 203 | |
| 204 private: | |
| 205 const SkColor color_; | |
| 206 const ImageSkia image_; | |
| 207 const ImageSkia mask_; | |
| 208 | |
| 209 DISALLOW_COPY_AND_ASSIGN(ButtonImageSource); | |
| 210 }; | |
| 211 | |
| 212 class HSLImageSource: public gfx::ImageSkiaSource { | |
| 213 public: | |
| 214 HSLImageSource(const ImageSkia& image, | |
| 215 const color_utils::HSL& hsl_shift) | |
| 216 : image_(image), | |
| 217 hsl_shift_(hsl_shift) { | |
| 218 } | |
|
oshima
2012/07/13 16:54:55
ditto
| |
| 219 | |
| 220 // gfx::ImageSkiaSource overrides: | |
| 221 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | |
| 222 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); | |
| 223 return gfx::ImageSkiaRep( | |
| 224 SkBitmapOperations::CreateHSLShiftedBitmap(image_rep.sk_bitmap(), | |
| 225 hsl_shift_), image_rep.scale_factor()); | |
| 226 } | |
| 227 | |
| 228 private: | |
| 229 const gfx::ImageSkia image_; | |
| 230 const color_utils::HSL hsl_shift_; | |
| 231 | |
| 232 DISALLOW_COPY_AND_ASSIGN(HSLImageSource); | |
| 233 }; | |
| 234 | |
| 235 class ColorMaskImageSource: public gfx::ImageSkiaSource { | |
| 236 public: | |
| 237 ColorMaskImageSource(const gfx::ImageSkia& image, | |
| 238 SkColor color) | |
| 239 : image_(image), | |
| 240 color_(color) { | |
| 241 } | |
|
oshima
2012/07/13 16:54:55
ditto
| |
| 242 | |
| 243 // gfx::ImageSkiaSource overrides: | |
| 244 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | |
| 245 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); | |
| 246 return gfx::ImageSkiaRep( | |
| 247 SkBitmapOperations::CreateColorMask(image_rep.sk_bitmap(), color_), | |
| 248 image_rep.scale_factor()); | |
| 249 } | |
| 250 | |
| 251 private: | |
| 252 const gfx::ImageSkia image_; | |
| 253 const SkColor color_; | |
| 254 | |
| 255 DISALLOW_COPY_AND_ASSIGN(ColorMaskImageSource); | |
| 256 }; | |
| 257 | |
| 258 class ExtractSubsetImageSource: public gfx::ImageSkiaSource { | |
| 259 public: | |
| 260 ExtractSubsetImageSource(const gfx::ImageSkia& image, | |
| 261 const gfx::Rect& subset_bounds) | |
| 262 : image_(image), | |
| 263 subset_bounds_(subset_bounds) { | |
| 264 } | |
|
oshima
2012/07/13 16:54:55
ditto
| |
| 265 | |
| 266 // gfx::ImageSkiaSource overrides: | |
| 267 virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE { | |
| 268 ImageSkiaRep image_rep = image_.GetRepresentation(scale_factor); | |
| 269 SkIRect subset_bounds_in_pixel = RectToSkIRect( | |
| 270 subset_bounds_.Scale(ui::GetScaleFactorScale(scale_factor))); | |
| 271 SkBitmap dst; | |
| 272 image_rep.sk_bitmap().extractSubset(&dst, subset_bounds_in_pixel); | |
| 273 return gfx::ImageSkiaRep(dst, image_rep.scale_factor()); | |
| 274 } | |
| 275 | |
| 276 private: | |
| 277 const gfx::ImageSkia image_; | |
| 278 const gfx::Rect subset_bounds_; | |
| 279 | |
| 280 DISALLOW_COPY_AND_ASSIGN(ExtractSubsetImageSource); | |
| 281 }; | |
| 282 | |
| 183 } // namespace; | 283 } // namespace; |
| 184 | 284 |
| 185 // static | 285 // static |
| 186 ImageSkia ImageSkiaOperations::CreateBlendedImage(const ImageSkia& first, | 286 ImageSkia ImageSkiaOperations::CreateBlendedImage(const ImageSkia& first, |
| 187 const ImageSkia& second, | 287 const ImageSkia& second, |
| 188 double alpha) { | 288 double alpha) { |
| 189 return ImageSkia(new BlendingImageSource(first, second, alpha), first.size()); | 289 return ImageSkia(new BlendingImageSource(first, second, alpha), first.size()); |
| 190 } | 290 } |
| 191 | 291 |
| 192 // static | 292 // static |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 204 } | 304 } |
| 205 | 305 |
| 206 // static | 306 // static |
| 207 ImageSkia ImageSkiaOperations::CreateResizedImage( | 307 ImageSkia ImageSkiaOperations::CreateResizedImage( |
| 208 const ImageSkia& source, | 308 const ImageSkia& source, |
| 209 const gfx::Size& target_size_in_dip) { | 309 const gfx::Size& target_size_in_dip) { |
| 210 return ImageSkia(new ResizingImageSource(source, target_size_in_dip), | 310 return ImageSkia(new ResizingImageSource(source, target_size_in_dip), |
| 211 target_size_in_dip); | 311 target_size_in_dip); |
| 212 } | 312 } |
| 213 | 313 |
| 314 // static | |
| 315 ImageSkia ImageSkiaOperations::CreateButtonBackground( | |
| 316 SkColor color, | |
| 317 const ImageSkia& image, | |
| 318 const ImageSkia& mask) { | |
| 319 return ImageSkia(new ButtonImageSource(color, image, mask), image.size()); | |
| 320 } | |
| 321 | |
| 322 // static | |
| 323 ImageSkia ImageSkiaOperations::CreateHSLShiftedImage( | |
| 324 const ImageSkia& image, | |
| 325 const color_utils::HSL& hsl_shift) { | |
| 326 return ImageSkia(new HSLImageSource(image, hsl_shift), image.size()); | |
| 327 } | |
| 328 | |
| 329 // static | |
| 330 ImageSkia ImageSkiaOperations::CreateColorMask( | |
| 331 const ImageSkia& image, | |
| 332 SkColor color) { | |
|
oshima
2012/07/13 16:54:55
can these be alined to at (?
| |
| 333 return ImageSkia(new ColorMaskImageSource(image, color), image.size()); | |
| 334 } | |
| 335 | |
| 336 // static | |
| 337 ImageSkia ImageSkiaOperations::ExtractSubset( | |
| 338 const ImageSkia& image, | |
| 339 const Rect& subset_bounds) { | |
|
oshima
2012/07/13 16:54:55
can these be alined to at (?
pkotwicz
2012/07/15 03:36:48
Done.
| |
| 340 if (image.isNull()) | |
| 341 return ImageSkia(); | |
|
oshima
2012/07/13 16:54:55
i wonder "return image" is better. you may keep it
pkotwicz
2012/07/15 03:36:48
I prefer it this way. SkBitmap::extractSubset retu
| |
| 342 | |
| 343 return ImageSkia(new ExtractSubsetImageSource(image, subset_bounds), | |
| 344 subset_bounds.size()); | |
| 345 } | |
| 346 | |
| 214 } // namespace gfx | 347 } // namespace gfx |
| OLD | NEW |