OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 GFX_SKBITMAP_OPERATIONS_H_ | 5 #ifndef GFX_SKBITMAP_OPERATIONS_H_ |
6 #define GFX_SKBITMAP_OPERATIONS_H_ | 6 #define GFX_SKBITMAP_OPERATIONS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/gtest_prod_util.h" | 9 #include "ui/gfx/skbitmap_operations.h" |
10 #include "gfx/color_utils.h" | 10 // TODO(sail): remove this file once all includes have been updated. |
11 | |
12 class SkBitmap; | |
13 | |
14 class SkBitmapOperations { | |
15 public: | |
16 // Create a bitmap that is an inverted image of the passed in image. | |
17 // Each color becomes its inverse in the color wheel. So (255, 15, 0) becomes | |
18 // (0, 240, 255). The alpha value is not inverted. | |
19 static SkBitmap CreateInvertedBitmap(const SkBitmap& image); | |
20 | |
21 // Create a bitmap that is a superimposition of the second bitmap on top of | |
22 // the first. The provided bitmaps must use have the kARGB_8888_Config config | |
23 // and be of equal dimensions. | |
24 static SkBitmap CreateSuperimposedBitmap(const SkBitmap& first, | |
25 const SkBitmap& second); | |
26 | |
27 // Create a bitmap that is a blend of two others. The alpha argument | |
28 // specifies the opacity of the second bitmap. The provided bitmaps must | |
29 // use have the kARGB_8888_Config config and be of equal dimensions. | |
30 static SkBitmap CreateBlendedBitmap(const SkBitmap& first, | |
31 const SkBitmap& second, | |
32 double alpha); | |
33 | |
34 // Create a bitmap that is the original bitmap masked out by the mask defined | |
35 // in the alpha bitmap. The images must use the kARGB_8888_Config config and | |
36 // be of equal dimensions. | |
37 static SkBitmap CreateMaskedBitmap(const SkBitmap& first, | |
38 const SkBitmap& alpha); | |
39 | |
40 // We create a button background image by compositing the color and image | |
41 // together, then applying the mask. This is a highly specialized composite | |
42 // operation that is the equivalent of drawing a background in |color|, | |
43 // tiling |image| over the top, and then masking the result out with |mask|. | |
44 // The images must use kARGB_8888_Config config. | |
45 static SkBitmap CreateButtonBackground(SkColor color, | |
46 const SkBitmap& image, | |
47 const SkBitmap& mask); | |
48 | |
49 // Shift a bitmap's HSL values. The shift values are in the range of 0-1, | |
50 // with the option to specify -1 for 'no change'. The shift values are | |
51 // defined as: | |
52 // hsl_shift[0] (hue): The absolute hue value for the image - 0 and 1 map | |
53 // to 0 and 360 on the hue color wheel (red). | |
54 // hsl_shift[1] (saturation): A saturation shift for the image, with the | |
55 // following key values: | |
56 // 0 = remove all color. | |
57 // 0.5 = leave unchanged. | |
58 // 1 = fully saturate the image. | |
59 // hsl_shift[2] (lightness): A lightness shift for the image, with the | |
60 // following key values: | |
61 // 0 = remove all lightness (make all pixels black). | |
62 // 0.5 = leave unchanged. | |
63 // 1 = full lightness (make all pixels white). | |
64 static SkBitmap CreateHSLShiftedBitmap(const SkBitmap& bitmap, | |
65 color_utils::HSL hsl_shift); | |
66 | |
67 // Create a bitmap that is cropped from another bitmap. This is special | |
68 // because it tiles the original bitmap, so your coordinates can extend | |
69 // outside the bounds of the original image. | |
70 static SkBitmap CreateTiledBitmap(const SkBitmap& bitmap, | |
71 int src_x, int src_y, | |
72 int dst_w, int dst_h); | |
73 | |
74 // Iteratively downsamples by 2 until the bitmap is no smaller than the | |
75 // input size. The normal use of this is to downsample the bitmap "close" to | |
76 // the final size, and then use traditional resampling on the result. | |
77 // Because the bitmap will be closer to the final size, it will be faster, | |
78 // and linear interpolation will generally work well as a second step. | |
79 static SkBitmap DownsampleByTwoUntilSize(const SkBitmap& bitmap, | |
80 int min_w, int min_h); | |
81 | |
82 // Makes a bitmap half has large in each direction by averaging groups of | |
83 // 4 pixels. This is one step in generating a mipmap. | |
84 static SkBitmap DownsampleByTwo(const SkBitmap& bitmap); | |
85 | |
86 // Unpremultiplies all pixels in |bitmap|. You almost never want to call | |
87 // this, as |SkBitmap|s are always premultiplied by conversion. Call this | |
88 // only if you will pass the bitmap's data into a system function that | |
89 // doesn't expect premultiplied colors. | |
90 static SkBitmap UnPreMultiply(const SkBitmap& bitmap); | |
91 | |
92 // Transpose the pixels in |bitmap| by swapping x and y. | |
93 static SkBitmap CreateTransposedBtmap(const SkBitmap& bitmap); | |
94 | |
95 private: | |
96 SkBitmapOperations(); // Class for scoping only. | |
97 | |
98 FRIEND_TEST_ALL_PREFIXES(SkBitmapOperationsTest, DownsampleByTwo); | |
99 FRIEND_TEST_ALL_PREFIXES(SkBitmapOperationsTest, DownsampleByTwoSmall); | |
100 }; | |
101 | 11 |
102 #endif // GFX_SKBITMAP_OPERATIONS_H_ | 12 #endif // GFX_SKBITMAP_OPERATIONS_H_ |
OLD | NEW |