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
3 // found in the LICENSE file.
5 #ifndef APP_GFX_SKBITMAP_OPERATIONS_H_
6 #define APP_GFX_SKBITMAP_OPERATIONS_H_
8 #include "gfx/color_utils.h"
9 #include "testing/gtest/include/gtest/gtest_prod.h"
13 class SkBitmapOperations
{
15 // Create a bitmap that is an inverted image of the passed in image.
16 // Each color becomes its inverse in the color wheel. So (255, 15, 0) becomes
17 // (0, 240, 255). The alpha value is not inverted.
18 static SkBitmap
CreateInvertedBitmap(const SkBitmap
& image
);
20 // Create a bitmap that is a superimposition of the second bitmap on top of
21 // the first. The provided bitmaps must use have the kARGB_8888_Config config
22 // and be of equal dimensions.
23 static SkBitmap
CreateSuperimposedBitmap(const SkBitmap
& first
,
24 const SkBitmap
& second
);
26 // Create a bitmap that is a blend of two others. The alpha argument
27 // specifies the opacity of the second bitmap. The provided bitmaps must
28 // use have the kARGB_8888_Config config and be of equal dimensions.
29 static SkBitmap
CreateBlendedBitmap(const SkBitmap
& first
,
30 const SkBitmap
& second
,
33 // Create a bitmap that is the original bitmap masked out by the mask defined
34 // in the alpha bitmap. The images must use the kARGB_8888_Config config and
35 // be of equal dimensions.
36 static SkBitmap
CreateMaskedBitmap(const SkBitmap
& first
,
37 const SkBitmap
& alpha
);
39 // We create a button background image by compositing the color and image
40 // together, then applying the mask. This is a highly specialized composite
41 // 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|.
43 // The images must use kARGB_8888_Config config.
44 static SkBitmap
CreateButtonBackground(SkColor color
,
45 const SkBitmap
& image
,
46 const SkBitmap
& mask
);
48 // Shift a bitmap's HSL values. The shift values are in the range of 0-1,
49 // with the option to specify -1 for 'no change'. The shift values are
51 // hsl_shift[0] (hue): The absolute hue value for the image - 0 and 1 map
52 // to 0 and 360 on the hue color wheel (red).
53 // hsl_shift[1] (saturation): A saturation shift for the image, with the
54 // following key values:
55 // 0 = remove all color.
56 // 0.5 = leave unchanged.
57 // 1 = fully saturate the image.
58 // hsl_shift[2] (lightness): A lightness shift for the image, with the
59 // following key values:
60 // 0 = remove all lightness (make all pixels black).
61 // 0.5 = leave unchanged.
62 // 1 = full lightness (make all pixels white).
63 static SkBitmap
CreateHSLShiftedBitmap(const SkBitmap
& bitmap
,
64 color_utils::HSL hsl_shift
);
66 // Create a bitmap that is cropped from another bitmap. This is special
67 // because it tiles the original bitmap, so your coordinates can extend
68 // outside the bounds of the original image.
69 static SkBitmap
CreateTiledBitmap(const SkBitmap
& bitmap
,
71 int dst_w
, int dst_h
);
73 // Iteratively downsamples by 2 until the bitmap is no smaller than the
74 // input size. The normal use of this is to downsample the bitmap "close" to
75 // the final size, and then use traditional resampling on the result.
76 // Because the bitmap will be closer to the final size, it will be faster,
77 // and linear interpolation will generally work well as a second step.
78 static SkBitmap
DownsampleByTwoUntilSize(const SkBitmap
& bitmap
,
79 int min_w
, int min_h
);
81 // Makes a bitmap half has large in each direction by averaging groups of
82 // 4 pixels. This is one step in generating a mipmap.
83 static SkBitmap
DownsampleByTwo(const SkBitmap
& bitmap
);
85 SkBitmapOperations(); // Class for scoping only.
87 FRIEND_TEST(SkBitmapOperationsTest
, DownsampleByTwo
);
88 FRIEND_TEST(SkBitmapOperationsTest
, DownsampleByTwoSmall
);
91 #endif // APP_GFX_SKBITMAP_OPERATIONS_H_