blob: fa5748be718a96cd8f9f4fd5a90a37223ef05e98 [file] [log] [blame]
Cary Clark2d4bf5f2018-04-16 08:37:38 -04001#Topic Color4f
Cary Clark137b8742018-05-30 09:21:49 -04002#Alias Color4f_Reference ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -04003
Cary Clark61313f32018-10-08 14:57:48 -04004#Struct SkPM4f
5##
6
7#Struct SkRGBA4f
8
9#Code
10#Populate
11##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040012
Cary Clarkffb3d682018-05-17 12:17:28 -040013Each 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
Cary Clark61313f32018-10-08 14:57:48 -040016Components 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
Cary Clark77b3f3a2018-11-07 14:59:03 -050020Components are connected if defined with kPremul_SkAlphaType;
Cary Clark61313f32018-10-08 14:57:48 -040021fA 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.
Cary Clarkffb3d682018-05-17 12:17:28 -040023
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.
Cary Clark2d4bf5f2018-04-16 08:37:38 -040026
Cary Clark2d4bf5f2018-04-16 08:37:38 -040027#Member float fR
Cary Clarkffb3d682018-05-17 12:17:28 -040028#Line # red component ##
29Single precision float for red ranges from no red (0.0) to full red (1.0).
Cary Clark2d4bf5f2018-04-16 08:37:38 -040030##
31
32#Member float fG
Cary Clarkffb3d682018-05-17 12:17:28 -040033#Line # green component ##
34Single precision float for green ranges from no green (0.0) to full green (1.0).
Cary Clark2d4bf5f2018-04-16 08:37:38 -040035##
36
37#Member float fB
Cary Clarkffb3d682018-05-17 12:17:28 -040038#Line # blue component ##
39Single precision float for blue ranges from no blue (0.0) to full blue (1.0).
Cary Clark2d4bf5f2018-04-16 08:37:38 -040040##
41
42#Member float fA
Cary Clarkffb3d682018-05-17 12:17:28 -040043#Line # alpha component ##
44Single precision float for Alpha ranges from no Alpha (0.0) to full Alpha (1.0).
Cary Clark2d4bf5f2018-04-16 08:37:38 -040045##
46
Cary Clark61313f32018-10-08 14:57:48 -040047
Cary Clark2d4bf5f2018-04-16 08:37:38 -040048# ------------------------------------------------------------------------------
49
Cary Clarkcb6bef02018-11-29 12:05:25 -050050#Method bool operator==(const SkRGBA4f& other) const
Cary Clark61313f32018-10-08 14:57:48 -040051#Line # compares SkRGBA4f for equality ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040052
Cary Clark61313f32018-10-08 14:57:48 -040053Compares SkRGBA4f with other, and returns true if all components are equivalent.
Cary Clark2d4bf5f2018-04-16 08:37:38 -040054
Cary Clark61313f32018-10-08 14:57:48 -040055#Param other SkRGBA4f to compare ##
Cary Clarkffb3d682018-05-17 12:17:28 -040056
Cary Clark61313f32018-10-08 14:57:48 -040057#Return true if SkRGBA4f equals other ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040058
59#Example
Cary Clarkffb3d682018-05-17 12:17:28 -040060 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##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040066##
67
Cary Clarkcb6bef02018-11-29 12:05:25 -050068#SeeAlso operator!=(const SkRGBA4f& other) const
Cary Clark2d4bf5f2018-04-16 08:37:38 -040069
70#Method ##
71
72# ------------------------------------------------------------------------------
73
Cary Clarkcb6bef02018-11-29 12:05:25 -050074#Method bool operator!=(const SkRGBA4f& other) const
Cary Clark61313f32018-10-08 14:57:48 -040075#Line # compares SkRGBA4f for inequality ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040076
Cary Clark61313f32018-10-08 14:57:48 -040077Compares SkRGBA4f with other, and returns true if all components are not
Cary Clarkffb3d682018-05-17 12:17:28 -040078equivalent.
Cary Clark2d4bf5f2018-04-16 08:37:38 -040079
Cary Clark61313f32018-10-08 14:57:48 -040080#Param other SkRGBA4f to compare ##
Cary Clarkffb3d682018-05-17 12:17:28 -040081
Cary Clark61313f32018-10-08 14:57:48 -040082#Return true if SkRGBA4f is not equal to other ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040083
84#Example
Cary Clarkffb3d682018-05-17 12:17:28 -040085 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##
Cary Clark2d4bf5f2018-04-16 08:37:38 -040091##
92
Cary Clarkcb6bef02018-11-29 12:05:25 -050093#SeeAlso operator==(const SkRGBA4f& other) const
Cary Clark61313f32018-10-08 14:57:48 -040094
95#Method ##
96
Cary Clarkcb6bef02018-11-29 12:05:25 -050097#Method SkRGBA4f operator*(float scale) const
Cary Clark61313f32018-10-08 14:57:48 -040098#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
Cary Clarkcb6bef02018-11-29 12:05:25 -0500113#Method SkRGBA4f operator*(const SkRGBA4f& scale) const
Cary Clark61313f32018-10-08 14:57:48 -0400114
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
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400125
126#Method ##
127
128# ------------------------------------------------------------------------------
129
Cary Clark61313f32018-10-08 14:57:48 -0400130#Subtopic Property_Functions
131#Line # member values ##
132#Subtopic Property_Functions ##
133
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400134#Method const float* vec() const
Cary Clark61313f32018-10-08 14:57:48 -0400135#In Property_Functions
Cary Clarkffb3d682018-05-17 12:17:28 -0400136#Line # returns array of components ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400137
Cary Clark61313f32018-10-08 14:57:48 -0400138Returns SkRGBA4f components as a read-only array.
Cary Clarkffb3d682018-05-17 12:17:28 -0400139
140#Return components as read-only array ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400141
142#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400143 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
Cary Clark5b1f9532018-08-28 14:53:37 -0400148red=0.266667 green=0.533333 blue=0.8 alpha=0.533333
149[0]=0.266667 [1]=0.533333 [2]=0.8 [3]=0.533333
Cary Clarkffb3d682018-05-17 12:17:28 -0400150##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400151##
152
Cary Clarkffb3d682018-05-17 12:17:28 -0400153#SeeAlso SkColor4f
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400154
155#Method ##
156
157# ------------------------------------------------------------------------------
158
159#Method float* vec()
Cary Clark61313f32018-10-08 14:57:48 -0400160#In Property_Functions
Cary Clarkffb3d682018-05-17 12:17:28 -0400161#Line # returns array of components ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400162
Cary Clark61313f32018-10-08 14:57:48 -0400163Returns SkRGBA4f components as a writable array.
Cary Clarkffb3d682018-05-17 12:17:28 -0400164
165#Return components as writable array ##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400166
167#Example
Cary Clarkffb3d682018-05-17 12:17:28 -0400168 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
Cary Clark5b1f9532018-08-28 14:53:37 -0400174red=0.266667 green=0.533333 blue=0.8 alpha=0.533333
175[0]=0.266667 [1]=0.533333 [2]=0.8 [3]=1
Cary Clarkffb3d682018-05-17 12:17:28 -0400176##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400177##
178
Cary Clarkffb3d682018-05-17 12:17:28 -0400179#SeeAlso SkColor4f
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400180
181#Method ##
182
Cary Clarkcb6bef02018-11-29 12:05:25 -0500183#Method float operator[](int index) const
Cary Clark61313f32018-10-08 14:57:48 -0400184#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
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400215# ------------------------------------------------------------------------------
216
Cary Clark61313f32018-10-08 14:57:48 -0400217#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
Cary Clarkcb6bef02018-11-29 12:05:25 -0500240#Method static SkRGBA4f FromColor(SkColor color)
Cary Clark61313f32018-10-08 14:57:48 -0400241#In Utility_Functions
242#Line # sets components from Color ##
Cary Clarkcb6bef02018-11-29 12:05:25 -0500243#Populate
Cary Clark61313f32018-10-08 14:57:48 -0400244
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
Cary Clarkb94f6da2018-06-08 11:54:32 -0400315#In Utility
Cary Clarkc9b49fe2018-09-21 14:26:30 -0400316#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
Cary Clark61313f32018-10-08 14:57:48 -0400329#Method SkRGBA4f<kUnpremul_SkAlphaType> unpremul() const
Cary Clarkc9b49fe2018-09-21 14:26:30 -0400330#In Utility
331#Line # returns Unpremultiplied color ##
332
Cary Clark61313f32018-10-08 14:57:48 -0400333Returns SkRGBA4f with all components independent of Alpha.
Cary Clarkc9b49fe2018-09-21 14:26:30 -0400334
335#Return Unpremultiplied color ##
336
337#NoExample
338##
339
340#SeeAlso premul
341
342#Method ##
343
Cary Clark7bae65d2018-10-17 09:39:54 -0400344#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
Cary Clark61313f32018-10-08 14:57:48 -0400385#Struct ##
Cary Clarkc9b49fe2018-09-21 14:26:30 -0400386
Cary Clark61313f32018-10-08 14:57:48 -0400387#Typedef SkRGBA4f SkColor4f
388#Line # defines Unpremultiplied Color using floats ##
389
390#Code
391using SkColor4f = SkRGBA4f<kUnpremul_SkAlphaType>;
Cary Clarkb94f6da2018-06-08 11:54:32 -0400392##
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400393
Cary Clark682c58d2018-05-16 07:07:07 -0400394##
395
Cary Clark2d4bf5f2018-04-16 08:37:38 -0400396#Topic Color4f ##