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 #ifndef UI_GFX_IMAGE_SKIA_OPERATIONS_H_ | 5 #ifndef UI_GFX_IMAGE_SKIA_OPERATIONS_H_ |
6 #define UI_GFX_IMAGE_SKIA_OPERATIONS_H_ | 6 #define UI_GFX_IMAGE_SKIA_OPERATIONS_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "ui/base/ui_export.h" | 9 #include "ui/base/ui_export.h" |
| 10 #include "ui/gfx/color_utils.h" |
10 #include "ui/gfx/shadow_value.h" | 11 #include "ui/gfx/shadow_value.h" |
11 | 12 |
12 namespace gfx { | 13 namespace gfx { |
13 class ImageSkia; | 14 class ImageSkia; |
14 class Rect; | 15 class Rect; |
15 class Size; | 16 class Size; |
16 | 17 |
17 class UI_EXPORT ImageSkiaOperations { | 18 class UI_EXPORT ImageSkiaOperations { |
18 public: | 19 public: |
19 // Create an image that is a blend of two others. The alpha argument | 20 // Create an image that is a blend of two others. The alpha argument |
20 // specifies the opacity of the second imag. The provided image must | 21 // specifies the opacity of the second imag. The provided image must |
21 // use the kARGB_8888_Config config and be of equal dimensions. | 22 // use the kARGB_8888_Config config and be of equal dimensions. |
22 static ImageSkia CreateBlendedImage(const ImageSkia& first, | 23 static ImageSkia CreateBlendedImage(const ImageSkia& first, |
23 const ImageSkia& second, | 24 const ImageSkia& second, |
24 double alpha); | 25 double alpha); |
25 | 26 |
26 // Create an image that is the original image masked out by the mask defined | 27 // Create an image that is the original image masked out by the mask defined |
27 // in the alpha image. The images must use the kARGB_8888_Config config and | 28 // in the alpha image. The images must use the kARGB_8888_Config config and |
28 // be of equal dimensions. | 29 // be of equal dimensions. |
29 static ImageSkia CreateMaskedImage(const ImageSkia& first, | 30 static ImageSkia CreateMaskedImage(const ImageSkia& first, |
30 const ImageSkia& alpha); | 31 const ImageSkia& alpha); |
31 | 32 |
32 // Create an image that is cropped from another image. This is special | 33 // Create an image that is cropped from another image. This is special |
33 // because it tiles the original image, so your coordinates can extend | 34 // because it tiles the original image, so your coordinates can extend |
34 // outside the bounds of the original image. | 35 // outside the bounds of the original image. |
35 static ImageSkia CreateTiledImage(const ImageSkia& image, | 36 static ImageSkia CreateTiledImage(const ImageSkia& image, |
36 int src_x, int src_y, | 37 int src_x, int src_y, |
37 int dst_w, int dst_h); | 38 int dst_w, int dst_h); |
38 | 39 |
| 40 // Shift an image's HSL values. The shift values are in the range of 0-1, |
| 41 // with the option to specify -1 for 'no change'. The shift values are |
| 42 // defined as: |
| 43 // hsl_shift[0] (hue): The absolute hue value for the image - 0 and 1 map |
| 44 // to 0 and 360 on the hue color wheel (red). |
| 45 // hsl_shift[1] (saturation): A saturation shift for the image, with the |
| 46 // following key values: |
| 47 // 0 = remove all color. |
| 48 // 0.5 = leave unchanged. |
| 49 // 1 = fully saturate the image. |
| 50 // hsl_shift[2] (lightness): A lightness shift for the image, with the |
| 51 // following key values: |
| 52 // 0 = remove all lightness (make all pixels black). |
| 53 // 0.5 = leave unchanged. |
| 54 // 1 = full lightness (make all pixels white). |
| 55 static ImageSkia CreateHSLShiftedImage(const gfx::ImageSkia& image, |
| 56 const color_utils::HSL& hsl_shift); |
| 57 |
39 // Creates a button background image by compositing the color and image | 58 // Creates a button background image by compositing the color and image |
40 // together, then applying the mask. This is a highly specialized composite | 59 // together, then applying the mask. This is a highly specialized composite |
41 // operation that is the equivalent of drawing a background in |color|, | 60 // operation that is the equivalent of drawing a background in |color|, |
42 // tiling |image| over the top, and then masking the result out with |mask|. | 61 // tiling |image| over the top, and then masking the result out with |mask|. |
43 // The images must use kARGB_8888_Config config. | 62 // The images must use kARGB_8888_Config config. |
44 static ImageSkia CreateButtonBackground(SkColor color, | 63 static ImageSkia CreateButtonBackground(SkColor color, |
45 const gfx::ImageSkia& image, | 64 const gfx::ImageSkia& image, |
46 const gfx::ImageSkia& mask); | 65 const gfx::ImageSkia& mask); |
47 | 66 |
48 // Returns an image which is a subset of |image| with bounds |subset_bounds|. | 67 // Returns an image which is a subset of |image| with bounds |subset_bounds|. |
49 // The |image| cannot use kA1_Config config. | 68 // The |image| cannot use kA1_Config config. |
50 static ImageSkia ExtractSubset(const gfx::ImageSkia& image, | 69 static ImageSkia ExtractSubset(const gfx::ImageSkia& image, |
51 const gfx::Rect& subset_bounds); | 70 const gfx::Rect& subset_bounds); |
52 | 71 |
53 // Creates an image by resizing |source| to given |target_dip_size|. | 72 // Creates an image by resizing |source| to given |target_dip_size|. |
54 static ImageSkia CreateResizedImage(const ImageSkia& source, | 73 static ImageSkia CreateResizedImage(const ImageSkia& source, |
55 const Size& target_dip_size); | 74 const Size& target_dip_size); |
56 | 75 |
57 // Creates an image with drop shadow defined in |shadows| for |source|. | 76 // Creates an image with drop shadow defined in |shadows| for |source|. |
58 static ImageSkia CreateImageWithDropShadow(const ImageSkia& source, | 77 static ImageSkia CreateImageWithDropShadow(const ImageSkia& source, |
59 const ShadowValues& shadows); | 78 const ShadowValues& shadows); |
60 | 79 |
61 private: | 80 private: |
62 ImageSkiaOperations(); // Class for scoping only. | 81 ImageSkiaOperations(); // Class for scoping only. |
63 }; | 82 }; |
64 | 83 |
65 } // namespace gfx | 84 } // namespace gfx |
66 | 85 |
67 #endif // UI_GFX_IMAGE_IMAGE_SKIA_OPERATIONS_H_ | 86 #endif // UI_GFX_IMAGE_IMAGE_SKIA_OPERATIONS_H_ |
OLD | NEW |