Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c423af9

Browse files
committed
switched back to float storage
1 parent ec7315e commit c423af9

File tree

1 file changed

+31
-57
lines changed

1 file changed

+31
-57
lines changed

lib/ui/painting.dart

Lines changed: 31 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ class Color {
100100
/// Color(0xFFFF9000)` (`FF` for the alpha, `FF` for the red, `90` for the
101101
/// green, and `00` for the blue).
102102
const Color(int value)
103-
: _value = value & 0xFFFFFFFF,
104-
colorSpace = ColorSpace.sRGB,
105-
_a = null,
106-
_r = null,
107-
_g = null,
108-
_b = null;
103+
: colorSpace = ColorSpace.sRGB,
104+
a = (value >> 24 & 0xff) * 255.0,
105+
r = (value >> 16 & 0xff) * 255.0,
106+
g = (value >> 8 & 0xff) * 255.0,
107+
b = (value >> 0 & 0xff) * 255.0;
109108

110109
/// Construct a color with normalized color components.
111110
///
@@ -118,11 +117,10 @@ class Color {
118117
required double green,
119118
required double blue,
120119
this.colorSpace = ColorSpace.sRGB})
121-
: _value = 0,
122-
_a = alpha,
123-
_r = red,
124-
_g = green,
125-
_b = blue;
120+
: a = alpha,
121+
r = red,
122+
g = green,
123+
b = blue;
126124

127125
/// Construct an sRGB color from the lower 8 bits of four integers.
128126
///
@@ -137,28 +135,18 @@ class Color {
137135
/// See also [fromRGBO], which takes the alpha value as a floating point
138136
/// value.
139137
const Color.fromARGB(int a, int r, int g, int b)
140-
: _value = (((a & 0xff) << 24) |
141-
((r & 0xff) << 16) |
142-
((g & 0xff) << 8) |
143-
((b & 0xff) << 0)) &
144-
0xFFFFFFFF,
145-
colorSpace = ColorSpace.sRGB,
146-
_a = null,
147-
_r = null,
148-
_g = null,
149-
_b = null;
138+
: colorSpace = ColorSpace.sRGB,
139+
a = (a & 0xff) * 255.0,
140+
r = (r & 0xff) * 255.0,
141+
g = (g & 0xff) * 255.0,
142+
b = (b & 0xff) * 255.0;
150143

151144
const Color._fromARGBC(
152145
int alpha, int red, int green, int blue, this.colorSpace)
153-
: _value = (((alpha & 0xff) << 24) |
154-
((red & 0xff) << 16) |
155-
((green & 0xff) << 8) |
156-
((blue & 0xff) << 0)) &
157-
0xFFFFFFFF,
158-
_a = null,
159-
_r = null,
160-
_g = null,
161-
_b = null;
146+
: a = (alpha & 0xff) * 255.0,
147+
r = (red & 0xff) * 255.0,
148+
g = (green & 0xff) * 255.0,
149+
b = (blue & 0xff) * 255.0;
162150

163151
/// Create an sRGB color from red, green, blue, and opacity, similar to
164152
/// `rgba()` in CSS.
@@ -173,35 +161,26 @@ class Color {
173161
///
174162
/// See also [fromARGB], which takes the opacity as an integer value.
175163
const Color.fromRGBO(int r, int g, int b, double opacity)
176-
: _value = ((((opacity * 0xff ~/ 1) & 0xff) << 24) |
177-
((r & 0xff) << 16) |
178-
((g & 0xff) << 8) |
179-
((b & 0xff) << 0)) &
180-
0xFFFFFFFF,
181-
colorSpace = ColorSpace.sRGB,
182-
_a = null,
183-
_r = null,
184-
_g = null,
185-
_b = null;
164+
: colorSpace = ColorSpace.sRGB,
165+
a = ((opacity * 0xff ~/ 1) & 0xff) * 255.0,
166+
r = (r & 0xff) * 255.0,
167+
g = (g & 0xff) * 255.0,
168+
b = (b & 0xff) * 255.0;
186169

187170
/// The alpha channel of this color.
188171
///
189172
/// A value of 0.0 means this color is fully transparent. A value of 1.0 means
190173
/// this color is fully opaque.
191-
double get a => _a ?? (alpha / 255);
192-
final double? _a;
174+
final double a;
193175

194176
/// The red channel of this color.
195-
double get r => _r ?? (red / 255);
196-
final double? _r;
177+
final double r;
197178

198179
/// The green channel of this color.
199-
double get g => _g ?? (green / 255);
200-
final double? _g;
180+
final double g;
201181

202182
/// The blue channel of this color.
203-
double get b => _b ?? (blue / 255);
204-
final double? _b;
183+
final double b;
205184

206185
/// The color space of this color.
207186
final ColorSpace colorSpace;
@@ -220,16 +199,11 @@ class Color {
220199
/// * Bits 0-7 are the blue value.
221200
@Deprecated('Use component accessors like .r or .g.')
222201
int get value {
223-
if (_a != null && _r != null && _g != null && _b != null) {
224-
return _floatToInt8(_a) << 24 |
225-
_floatToInt8(_r) << 16 |
226-
_floatToInt8(_g) << 8 |
227-
_floatToInt8(_b) << 0;
228-
} else {
229-
return _value;
230-
}
202+
return _floatToInt8(a) << 24 |
203+
_floatToInt8(r) << 16 |
204+
_floatToInt8(g) << 8 |
205+
_floatToInt8(b) << 0;
231206
}
232-
final int _value;
233207

234208
/// The alpha channel of this color in an 8 bit value.
235209
///

0 commit comments

Comments
 (0)