• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#Topic Color4f
2#Alias Color4f_Reference ##
3
4#Struct SkPM4f
5##
6
7#Struct SkRGBA4f
8
9#Code
10#Populate
11##
12
13Each component is stored as a 32-bit single precision floating point float value.
14All values are allowed, but only the range from zero to one is meaningful.
15
16Components are independent of the others if defined with kUnpremul_SkAlphaType;
17fA Alpha is may be greater or smaller than fG green, fB blue, or fR red.
18SkColor4f is shorthand for Unpremultiplied SkRGBA4f.
19
20Components are connected if defined with kPremul_SkAlphaType;
21fA Alpha is equal to or larger than fG green, fB blue, and fR red. The values
22stored in fG, fB, and fR combine the color component with the Alpha component.
23
24Values smaller than zero or larger than one are allowed. Values out of range
25may be used with Blend_Mode so that the final component is in range.
26
27#Member float  fR
28#Line # red component ##
29Single precision float for red ranges from no red (0.0) to full red (1.0).
30##
31
32#Member float  fG
33#Line # green component ##
34Single precision float for green ranges from no green (0.0) to full green (1.0).
35##
36
37#Member float  fB
38#Line # blue component ##
39Single precision float for blue ranges from no blue (0.0) to full blue (1.0).
40##
41
42#Member float  fA
43#Line # alpha component ##
44Single precision float for Alpha ranges from no Alpha (0.0) to full Alpha (1.0).
45##
46
47
48# ------------------------------------------------------------------------------
49
50#Method bool operator==(const SkRGBA4f& other) const
51#Line # compares SkRGBA4f for equality ##
52
53Compares SkRGBA4f with other, and returns true if all components are equivalent.
54
55#Param other  SkRGBA4f to compare ##
56
57#Return true if SkRGBA4f equals other ##
58
59#Example
60    SkColor4f colorRed = { 1, 0, 0, 1 };
61    SkColor4f colorNamedRed = SkColor4f::FromColor(SK_ColorRED);
62    SkDebugf("colorRed %c= colorNamedRed", colorRed == colorNamedRed ? '=' : '!');
63#StdOut
64colorRed == colorNamedRed
65##
66##
67
68#SeeAlso operator!=(const SkRGBA4f& other) const
69
70#Method ##
71
72# ------------------------------------------------------------------------------
73
74#Method bool operator!=(const SkRGBA4f& other) const
75#Line # compares SkRGBA4f for inequality ##
76
77Compares SkRGBA4f with other, and returns true if all components are not
78equivalent.
79
80#Param other  SkRGBA4f to compare ##
81
82#Return true if SkRGBA4f is not equal to other ##
83
84#Example
85    SkColor4f colorGray = { .5, .5, .5, 1 };
86    SkColor4f colorNamedGray = SkColor4f::FromColor(SK_ColorGRAY);
87    SkDebugf("colorGray %c= colorNamedGray ", colorGray != colorNamedGray ? '!' : '=');
88#StdOut
89colorGray != colorNamedGray
90##
91##
92
93#SeeAlso operator==(const SkRGBA4f& other) const
94
95#Method ##
96
97#Method SkRGBA4f operator*(float scale) const
98#Line # multiplies components by scale ##
99
100Multiplies each component by scale. Does not pin the result.
101
102#Param scale  component multiplier ##
103
104#Return scaled color ##
105
106#NoExample
107##
108
109#SeeAlso SkBlendMode::kMultiply
110
111#Method ##
112
113#Method SkRGBA4f operator*(const SkRGBA4f& scale) const
114
115Multiplies each component by scale component. Does not pin the result.
116
117#Param scale  SkRGBA4f component multipliers ##
118
119#Return scaled color ##
120
121#NoExample
122##
123
124#SeeAlso SkBlendMode::kMultiply
125
126#Method ##
127
128# ------------------------------------------------------------------------------
129
130#Subtopic Property_Functions
131#Line # member values ##
132#Subtopic Property_Functions ##
133
134#Method const float* vec() const
135#In Property_Functions
136#Line # returns array of components ##
137
138Returns SkRGBA4f components as a read-only array.
139
140#Return components as read-only array ##
141
142#Example
143    SkColor4f color = SkColor4f::FromColor(0x884488CC);
144    SkDebugf("red=%g green=%g blue=%g alpha=%g\n", color.fR, color.fG, color.fB, color.fA);
145    const float* array = color.vec();
146    SkDebugf("[0]=%g [1]=%g [2]=%g [3]=%g\n", array[0], array[1], array[2], array[3]);
147#StdOut
148red=0.266667 green=0.533333 blue=0.8 alpha=0.533333
149[0]=0.266667 [1]=0.533333 [2]=0.8 [3]=0.533333
150##
151##
152
153#SeeAlso SkColor4f
154
155#Method ##
156
157# ------------------------------------------------------------------------------
158
159#Method float* vec()
160#In Property_Functions
161#Line # returns array of components ##
162
163Returns SkRGBA4f components as a writable array.
164
165#Return components as writable array ##
166
167#Example
168    SkColor4f color = SkColor4f::FromColor(0x884488CC);
169    SkDebugf("red=%g green=%g blue=%g alpha=%g\n", color.fR, color.fG, color.fB, color.fA);
170    float* array = color.vec();
171    array[3] = 1;
172    SkDebugf("[0]=%g [1]=%g [2]=%g [3]=%g\n", array[0], array[1], array[2], array[3]);
173#StdOut
174red=0.266667 green=0.533333 blue=0.8 alpha=0.533333
175[0]=0.266667 [1]=0.533333 [2]=0.8 [3]=1
176##
177##
178
179#SeeAlso SkColor4f
180
181#Method ##
182
183#Method float operator[](int index) const
184#Line # returns component by index ##
185
186Returns SkRGBA4f component by index, zero through three. index out of range
187triggers an assert in debug builds.
188
189#Param index component, zero through three ##
190#Return component by index ##
191
192#NoExample
193##
194
195#SeeAlso vec
196
197#Method ##
198
199#Method float& operator[](int index)
200#Line # returns writable component reference ##
201
202Returns writable component reference by index, zero through three. index out of range
203triggers an assert in debug builds.
204
205#Param index component, zero through three ##
206#Return writable component reference by index ##
207
208#NoExample
209##
210
211#SeeAlso vec
212
213#Method ##
214
215# ------------------------------------------------------------------------------
216
217#Subtopic Utility_Functions
218#Line # less common functions ##
219#Subtopic Utility_Functions ##
220
221#Method bool isOpaque() const
222#In Utility_Functions
223#Line # returns if Alpha component is at maximum ##
224
225Returns true if Alpha component is one. Color has no transparency regardless of
226whether color is Premultiplied or Unpremultiplied. Triggers a debugging assert
227if Alpha not valid.
228
229#Return true if Alpha is one ##
230
231#NoExample
232##
233
234#SeeAlso vec SkColorGetA
235
236##
237
238# ------------------------------------------------------------------------------
239
240#Method static SkRGBA4f FromColor(SkColor color)
241#In Utility_Functions
242#Line # sets components from Color ##
243#Populate
244
245#Example
246    uint8_t red = 77, green = 101, blue = 153, alpha = 43;
247    SkColor argb = SkColorSetARGB(alpha, red, green, blue);
248    SkColor4f color4f = SkColor4f::FromColor(argb);
249    SkDebugf("red=%g green=%g blue=%g alpha=%g\n", color4f.fR, color4f.fG, color4f.fB, color4f.fA);
250    SkColor fromColor4f = color4f.toSkColor();
251    SkDebugf("red=%d green=%d blue=%d alpha=%d\n", SkColorGetR(fromColor4f),
252             SkColorGetG(fromColor4f), SkColorGetB(fromColor4f), SkColorGetA(fromColor4f));
253#StdOut
254red=0.301961 green=0.396078 blue=0.6 alpha=0.168627
255red=77 green=101 blue=153 alpha=43
256##
257##
258
259#SeeAlso toSkColor
260
261#Method ##
262
263# ------------------------------------------------------------------------------
264
265#Method SkColor toSkColor() const
266#In Utility_Functions
267#Line # returns closest Color ##
268
269Converts to closest SkColor.
270
271#Return closest Color ##
272
273#Example
274    float red = 0.07, green = 0.13, blue = 0.32, alpha = 0.17;
275    SkColor4f color4f = { red, green, blue, alpha };
276    SkColor argb = color4f.toSkColor();
277    SkDebugf("red=%d green=%d blue=%d alpha=%d\n", SkColorGetR(argb),
278             SkColorGetG(argb), SkColorGetB(argb), SkColorGetA(argb));
279    SkColor4f fromSkColor = SkColor4f::FromColor(argb);
280    SkDebugf("red=%g green=%g blue=%g alpha=%g\n", fromSkColor.fR, fromSkColor.fG,
281                                                   fromSkColor.fB, fromSkColor.fA);
282#StdOut
283red=18 green=33 blue=82 alpha=43
284red=0.0705882 green=0.129412 blue=0.321569 alpha=0.168627
285##
286##
287
288#SeeAlso FromColor
289
290#Method ##
291
292# ------------------------------------------------------------------------------
293
294#Method static SkRGBA4f FromPMColor(SkPMColor)
295#In Utility_Functions
296#Line # converts from Premultiplied Color ##
297
298Converts from Premultiplied integer components to Unpremultiplied float
299components.
300
301#Param SkPMColor  Premultiplied color ##
302
303#Return Unpremultiplied color ##
304
305#NoExample
306##
307
308#SeeAlso FromColor
309
310#Method ##
311
312# ------------------------------------------------------------------------------
313
314#Method SkRGBA4f<kPremul_SkAlphaType> premul() const
315#In Utility
316#Line # returns Premultiplied color ##
317
318Returns SkColor4f with all components premultiplied by Alpha.
319
320#Return Premultiplied color ##
321
322#NoExample
323##
324
325#SeeAlso unpremul
326
327#Method ##
328
329#Method SkRGBA4f<kUnpremul_SkAlphaType> unpremul() const
330#In Utility
331#Line # returns Unpremultiplied color ##
332
333Returns SkRGBA4f with all components independent of Alpha.
334
335#Return Unpremultiplied color ##
336
337#NoExample
338##
339
340#SeeAlso premul
341
342#Method ##
343
344#Method uint32_t toBytes_RGBA() const
345#In Utility
346#Line # returns kRGBA_8888_SkColorType color ##
347
348Produces bytes in RGBA order. Component values are not affected by color Alpha.
349
350#Return color ##
351
352#NoExample
353##
354
355#Method ##
356
357#Method static SkRGBA4f FromBytes_RGBA(uint32_t color)
358#In Utility
359#Line # sets kRGBA_8888_SkColorType color ##
360
361Returns from color kRGBA_8888_SkColorType order. Component values are
362not affected by color Alpha.
363
364#Param color  Premultiplied or Unpremultiplied ##
365#Return color ##
366
367#NoExample
368##
369
370#Method ##
371
372#Method SkRGBA4f makeOpaque() const
373#In Utility
374#Line # returns color without transparency ##
375
376Returns color with Alpha set to one.
377
378#Return color ##
379
380#NoExample
381##
382
383#Method ##
384
385#Struct ##
386
387#Typedef SkRGBA4f SkColor4f
388#Line # defines Unpremultiplied Color using floats ##
389
390#Code
391using SkColor4f = SkRGBA4f<kUnpremul_SkAlphaType>;
392##
393
394##
395
396#Topic Color4f ##
397