File: image_skia_operations.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (148 lines) | stat: -rw-r--r-- 7,007 bytes parent folder | download | duplicates (5)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GFX_IMAGE_IMAGE_SKIA_OPERATIONS_H_
#define UI_GFX_IMAGE_IMAGE_SKIA_OPERATIONS_H_

#include "base/component_export.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkRRect.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/shadow_value.h"
#include "ui/gfx/skbitmap_operations.h"

namespace gfx {
class ImageSkia;
class Rect;
class Size;
class SizeF;

class COMPONENT_EXPORT(GFX) ImageSkiaOperations {
 public:
  // Create an image that is a blend of two others. The alpha argument
  // specifies the opacity of the second imag. The provided image must
  // use the kARGB_8888_Config config and be of equal dimensions.
  static ImageSkia CreateBlendedImage(const ImageSkia& first,
                                      const ImageSkia& second,
                                      double alpha);

  // Creates an image that is the original image with opacity set to |alpha|.
  static ImageSkia CreateTransparentImage(const ImageSkia& image, double alpha);

  // Creates new image by painting first and second image respectively.
  // The second image is centered in respect to the first image.
  static ImageSkia CreateSuperimposedImage(const ImageSkia& first,
                                           const ImageSkia& second);

  // Create an image that is the original image masked out by the mask defined
  // in the alpha image. The images must use the kARGB_8888_Config config and
  // be of equal dimensions.
  static ImageSkia CreateMaskedImage(const ImageSkia& first,
                                     const ImageSkia& alpha);

  // Create an image that is cropped from another image. This is special
  // because it tiles the original image, so your coordinates can extend
  // outside the bounds of the original image.
  static ImageSkia CreateTiledImage(const ImageSkia& image,
                                    int src_x,
                                    int src_y,
                                    int dst_w,
                                    int dst_h);

  // Shift an image'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 ImageSkia CreateHSLShiftedImage(const gfx::ImageSkia& image,
                                         const color_utils::HSL& hsl_shift);

  // Creates a button background image by compositing the color and image
  // together, then applying the mask. This is a highly specialized composite
  // operation that is the equivalent of drawing a background in |color|,
  // tiling |image| over the top, and then masking the result out with |mask|.
  // The images must use kARGB_8888_Config config.
  static ImageSkia CreateButtonBackground(SkColor color,
                                          const gfx::ImageSkia& image,
                                          const gfx::ImageSkia& mask);

  // Returns an image which is a subset of |image| with bounds |subset_bounds|.
  // The |image| cannot use kA1_Config config.
  static ImageSkia ExtractSubset(const gfx::ImageSkia& image,
                                 const gfx::Rect& subset_bounds);

  // Creates an image by resizing |source| to given |target_dip_size|.
  static ImageSkia CreateResizedImage(const ImageSkia& source,
                                      skia::ImageOperations::ResizeMethod methd,
                                      const Size& target_dip_size);

  // Creates an image with drop shadow defined in |shadows| for |source|.
  static ImageSkia CreateImageWithDropShadow(const ImageSkia& source,
                                             const ShadowValues& shadows);

  // Creates an image that is 1dp wide, suitable for tiling horizontally to
  // create a drop shadow effect. The purpose of tiling a static image is to
  // avoid repeatedly asking Skia to draw a shadow.
  static ImageSkia CreateHorizontalShadow(
      const std::vector<ShadowValue>& shadows,
      bool fades_down);

  // Creates an image which is a rotation of the |source|. |rotation| is the
  // amount of clockwise rotation in degrees.
  static ImageSkia CreateRotatedImage(
      const ImageSkia& source,
      SkBitmapOperations::RotationAmount rotation);

  // Creates an icon by painting the second icon as a badge to the first one.
  // The second icon is in the right corner of the first icon. If the icon
  // is valid and the badge is not, the icon will be returned.
  static ImageSkia CreateIconWithBadge(const ImageSkia& icon,
                                       const ImageSkia& badge);

  // Creates an image by combining |image| and color |color|.
  // The image must use the kARGB_8888_Config config.
  static ImageSkia CreateColorMask(const gfx::ImageSkia& image, SkColor color);

  // Creates an image with a circle background. |color| and |radius| is the
  // color and radius of the circle background.
  static ImageSkia CreateImageWithCircleBackground(int radius,
                                                   SkColor color,
                                                   const ImageSkia& image);

  // Creates an image with a rounded rect background of the specified `size`,
  // `color`, and `radius`.
  static ImageSkia CreateImageWithRoundRectBackground(const SizeF& size,
                                                      int radius,
                                                      SkColor color,
                                                      const ImageSkia& image);

  // Creates an image with a roundrect clip path with `radius`.
  static ImageSkia CreateImageWithRoundRectClip(int radius,
                                                const ImageSkia& image);

  // Returns an image of `size` that contains as much of `image` as possible
  // without distorting the `image`. That result is clipped to a roundrect with
  // radius `border_radius`.
  static ImageSkia CreateCroppedCenteredRoundRectImage(const Size& size,
                                                       int border_radius,
                                                       const ImageSkia& image);

 private:
  ImageSkiaOperations();  // Class for scoping only.
};

}  // namespace gfx

#endif  // UI_GFX_IMAGE_IMAGE_SKIA_OPERATIONS_H_