1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKIA_EXT_IMAGE_OPERATIONS_H_
#define SKIA_EXT_IMAGE_OPERATIONS_H_
#include "base/basictypes.h"
#include "base/gfx/rect.h"
#include "SkColor.h"
class SkBitmap;
namespace skia {
class ImageOperations {
public:
enum ResizeMethod {
// Box filter. This is a weighted average of all of the pixels touching
// the destination pixel. For enlargement, this is nearest neighbor.
//
// You probably don't want this, it is here for testing since it is easy to
// compute. Use RESIZE_LANCZOS3 instead.
RESIZE_BOX,
// 3-cycle Lanczos filter. This is tall in the middle, goes negative on
// each side, then oscillates 2 more times. It gives nice sharp edges.
RESIZE_LANCZOS3,
};
// Resizes the given source bitmap using the specified resize method, so that
// the entire image is (dest_size) big. The dest_subset is the rectangle in
// this destination image that should actually be returned.
//
// The output image will be (dest_subset.width(), dest_subset.height()). This
// will save work if you do not need the entire bitmap.
//
// The destination subset must be smaller than the destination image.
static SkBitmap Resize(const SkBitmap& source,
ResizeMethod method,
int dest_width, int dest_height,
const gfx::Rect& dest_subset);
// Alternate version for resizing and returning the entire bitmap rather than
// a subset.
static SkBitmap Resize(const SkBitmap& source,
ResizeMethod method,
int dest_width, int dest_height);
// Create a bitmap that is a blend of two others. The alpha argument
// specifies the opacity of the second bitmap. The provided bitmaps must
// use have the kARGB_8888_Config config and be of equal dimensions.
static SkBitmap CreateBlendedBitmap(const SkBitmap& first,
const SkBitmap& second,
double alpha);
// Create a bitmap that is the original bitmap masked out by the mask defined
// in the alpha bitmap. The images must use the kARGB_8888_Config config and
// be of equal dimensions.
static SkBitmap CreateMaskedBitmap(const SkBitmap& first,
const SkBitmap& alpha);
// Blur a bitmap using an average-blur algorithm over the rectangle defined
// by |blur_amount|. The blur will wrap around image edges.
static SkBitmap CreateBlurredBitmap(const SkBitmap& bitmap, int blur_amount);
// Shift a bitmap's HSL values. The shift values are in the range of 0-1,
// with the option to specify -1 for 'no change'. The shift values are
// defined as:
// hsl_shift[0] (hue): The absolute hue value for the image - 0 and 1 map
// to 0 and 360 on the hue color wheel (red).
// hsl_shift[1] (saturation): A saturation shift for the image, with the
// following key values:
// 0 = remove all color.
// 0.5 = leave unchanged.
// 1 = fully saturate the image.
// hsl_shift[2] (lightness): A lightness shift for the image, with the
// following key values:
// 0 = remove all lightness (make all pixels black).
// 0.5 = leave unchanged.
// 1 = full lightness (make all pixels white).
static SkBitmap CreateHSLShiftedBitmap(const SkBitmap& bitmap,
float hsl_shift[3]);
// Create a bitmap that is cropped from another bitmap. This is special
// because it tiles the original bitmap, so your coordinates can extend
// outside the bounds of the original image.
static SkBitmap CreateTiledBitmap(const SkBitmap& bitmap,
int src_x, int src_y,
int dst_w, int dst_h);
private:
ImageOperations(); // Class for scoping only.
};
} // namespace skia
#endif // SKIA_EXT_IMAGE_OPERATIONS_H_
|