aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/SkColor4f_Reference.bmh
blob: 19d4b5dc61633c6dea8431cbcb24d9f1db6106c9 (plain)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#Topic Color4f
#Alias Color4f_Reference ##

#Struct SkColor4f

Each component is stored as a 32-bit single precision floating point float value.
All values are allowed, but only the range from zero to one is meaningful.

Each component is independent of the others; fA Alpha is not Premultiplied
with fG green, fB blue, or fR red.

Values smaller than zero or larger than one are allowed. Values out of range
may be used with Blend_Mode so that the final component is in range.

#Subtopic Overview
#Populate
##

#Subtopic Operator
#Populate
##

#Subtopic Member_Function
#Populate
##

#Member float  fR
#Line # red component ##
Single precision float for red ranges from no red (0.0) to full red (1.0).
##

#Member float  fG
#Line # green component ##
Single precision float for green ranges from no green (0.0) to full green (1.0).
##

#Member float  fB
#Line # blue component ##
Single precision float for blue ranges from no blue (0.0) to full blue (1.0).
##

#Member float  fA
#Line # alpha component ##
Single precision float for Alpha ranges from no Alpha (0.0) to full Alpha (1.0).
##

# ------------------------------------------------------------------------------

#Method bool operator==(const SkColor4f& other)_const
#In Operator
#Line # compares Color4f for equality ##

Compares Color4f with other, and returns true if all components are equivalent.

#Param other  Color4f to compare ##

#Return true if Color4f equals other ##

#Example
    SkColor4f colorRed = { 1, 0, 0, 1 };
    SkColor4f colorNamedRed = SkColor4f::FromColor(SK_ColorRED);
    SkDebugf("colorRed %c= colorNamedRed", colorRed == colorNamedRed ? '=' : '!');
#StdOut
colorRed == colorNamedRed
##
##

#SeeAlso operator!=(const SkColor4f& other)_const

#Method ##

# ------------------------------------------------------------------------------

#Method bool operator!=(const SkColor4f& other)_const
#In Operator
#Line # compares colors for inequality ##

Compares Color4f with other, and returns true if all components are not
equivalent.

#Param other  Color4f to compare ##

#Return true if Color4f is not equal to other ##

#Example
    SkColor4f colorGray = { .5, .5, .5, 1 };
    SkColor4f colorNamedGray = SkColor4f::FromColor(SK_ColorGRAY);
    SkDebugf("colorGray %c= colorNamedGray ", colorGray != colorNamedGray ? '!' : '=');
#StdOut
colorGray != colorNamedGray
##
##

#SeeAlso operator==(const SkColor4f& other)_const

#Method ##

# ------------------------------------------------------------------------------

#Method const float* vec() const
#In Property
#Line # returns array of components ##

Returns Color4f components as a read-only array.

#Return components as read-only array ##

#Example
    SkColor4f color = SkColor4f::FromColor(0x884488CC);
    SkDebugf("red=%g green=%g blue=%g alpha=%g\n", color.fR, color.fG, color.fB, color.fA);
    const float* array = color.vec();
    SkDebugf("[0]=%g [1]=%g [2]=%g [3]=%g\n", array[0], array[1], array[2], array[3]);
#StdOut
red=0.0578054 green=0.246201 blue=0.603827 alpha=0.533333
[0]=0.0578054 [1]=0.246201 [2]=0.603827 [3]=0.533333
##
##

#SeeAlso SkColor4f

#Method ##

# ------------------------------------------------------------------------------

#Method float* vec()
#In Property
#Line # returns array of components ##

Returns Color4f components as a writable array.

#Return components as writable array ##

#Example
    SkColor4f color = SkColor4f::FromColor(0x884488CC);
    SkDebugf("red=%g green=%g blue=%g alpha=%g\n", color.fR, color.fG, color.fB, color.fA);
    float* array = color.vec();
    array[3] = 1;
    SkDebugf("[0]=%g [1]=%g [2]=%g [3]=%g\n", array[0], array[1], array[2], array[3]);
#StdOut
red=0.0578054 green=0.246201 blue=0.603827 alpha=0.533333
[0]=0.0578054 [1]=0.246201 [2]=0.603827 [3]=1
##
##

#SeeAlso SkColor4f

#Method ##

# ------------------------------------------------------------------------------

#Method static SkColor4f Pin(float r, float g, float b, float a)
#In Utility
#Line # sets components to valid range ##

Constructs and returns Color4f with each component pinned from zero to one.

#Param r  red component ##
#Param g  green component ##
#Param b  blue component ##
#Param a  Alpha component ##

#Return Color4f with valid components ##

#Example
#Height 40
    uint32_t storage[8];
    SkImageInfo info = SkImageInfo::MakeN32Premul(8, 1);
    SkPixmap pixmap(info, storage, info.minRowBytes());
    pixmap.erase(SK_ColorWHITE);
    SkIRect bounds = {0, 0, 1, 1};
    SkColor4f colors[] = { SkColor4f::Pin(1.5, 0.45f,  0.0,  1), 
                           SkColor4f::Pin(1,   0.45f, -0.25, 1),
                           {1.5, 0.45f,  0.0,  1},
                           {1,   0.45f, -0.25, 1},
                         };
    for (auto color4f : colors) {
        pixmap.erase(color4f, &bounds);
        bounds.offset(2, 0);
    }
    SkBitmap bitmap;
    canvas->scale(20, 20);
    bitmap.installPixels(pixmap);
    canvas->drawBitmap(bitmap, 0, 0);
##

#SeeAlso pin() FromColor

#Method ##

# ------------------------------------------------------------------------------

#Method static SkColor4f FromColor(SkColor)
#In Utility
#Line # sets components from Color ##

Converts to closest Color4f.

#Param SkColor  Color with Alpha, red, blue, and green components ##

#Return Color4f equivalent ##

#Example
    uint8_t red = 77, green = 101, blue = 153, alpha = 43;
    SkColor argb = SkColorSetARGB(alpha, red, green, blue);
    SkColor4f color4f = SkColor4f::FromColor(argb);
    SkDebugf("red=%g green=%g blue=%g alpha=%g\n", color4f.fR, color4f.fG, color4f.fB, color4f.fA);
    SkColor fromColor4f = color4f.toSkColor();
    SkDebugf("red=%d green=%d blue=%d alpha=%d\n", SkColorGetR(fromColor4f),
             SkColorGetG(fromColor4f), SkColorGetB(fromColor4f), SkColorGetA(fromColor4f));
#StdOut
red=0.0742136 green=0.130136 blue=0.318547 alpha=0.168627
red=77 green=101 blue=153 alpha=43
##
##

#SeeAlso toSkColor

#Method ##

# ------------------------------------------------------------------------------

#Method SkColor toSkColor() const
#In Utility
#Line # returns closest Color ##

Converts to closest SkColor.

#Return closest Color ##

#Example
    float red = 0.07, green = 0.13, blue = 0.32, alpha = 0.17;
    SkColor4f color4f = { red, green, blue, alpha };
    SkColor argb = color4f.toSkColor();
    SkDebugf("red=%d green=%d blue=%d alpha=%d\n", SkColorGetR(argb),
             SkColorGetG(argb), SkColorGetB(argb), SkColorGetA(argb));
    SkColor4f fromSkColor = SkColor4f::FromColor(argb);
    SkDebugf("red=%g green=%g blue=%g alpha=%g\n", fromSkColor.fR, fromSkColor.fG,
                                                   fromSkColor.fB, fromSkColor.fA);
#StdOut
red=75 green=101 blue=153 alpha=43
red=0.0703601 green=0.130136 blue=0.318547 alpha=0.168627
##
##

#SeeAlso FromColor

#Method ##

# ------------------------------------------------------------------------------

#Method SkColor4f pin() const
#In Utility
#Line # sets components to valid range ##

Returns Color4f with all components in the range from zero to one.

#Return Color4f with valid components ##

#Example
#Height 40
    uint32_t storage[8];
    SkImageInfo info = SkImageInfo::MakeN32Premul(8, 1);
    SkPixmap pixmap(info, storage, info.minRowBytes());
    pixmap.erase(SK_ColorWHITE);
    SkIRect bounds = {0, 0, 1, 1};
    SkColor4f colors[] = { {1.5, 0.45f,  0.0,  1},
                           {1,   0.45f, -0.25, 1},
                         };
    for (auto color4f : colors) {
        pixmap.erase(color4f, &bounds);
        bounds.offset(2, 0);
        pixmap.erase(color4f.pin(), &bounds);
        bounds.offset(2, 0);
    }
    SkBitmap bitmap;
    canvas->scale(20, 20);
    bitmap.installPixels(pixmap);
    canvas->drawBitmap(bitmap, 0, 0);
##

#SeeAlso Pin

#Method ##

# ------------------------------------------------------------------------------

#Method SkPM4f premul() const
#In Utility
#Line # returns Premultiplied color; internal use only ##
#Private
Internal use only.
##
#Return Premultiplied color ##
#Method ##

#Struct SkColor4f ##

#Struct SkPM4f
#Private
Internal use only.
##
##

#Topic Color4f ##