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

Commit 3fe7306

Browse files
committed
Removes legacy color component storage from Color
1 parent a156e71 commit 3fe7306

File tree

1 file changed

+27
-56
lines changed

1 file changed

+27
-56
lines changed

lib/ui/painting.dart

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,8 @@ 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+
: this._fromARGBC(
104+
value >> 24, value >> 16, value >> 8, value, ColorSpace.sRGB);
109105

110106
/// Construct a color with normalized color components.
111107
///
@@ -118,8 +114,7 @@ class Color {
118114
required double green,
119115
required double blue,
120116
this.colorSpace = ColorSpace.sRGB})
121-
: _value = 0,
122-
_a = alpha,
117+
: _a = alpha,
123118
_r = red,
124119
_g = green,
125120
_b = blue;
@@ -137,28 +132,12 @@ class Color {
137132
/// See also [fromRGBO], which takes the alpha value as a floating point
138133
/// value.
139134
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;
135+
: this._fromARGBC(a, r, g, b, ColorSpace.sRGB);
150136

151137
const Color._fromARGBC(
152-
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;
138+
int alpha, int red, int green, int blue, ColorSpace colorSpace)
139+
: this._fromRGBOC(
140+
red, green, blue, (alpha & 0xff) / 255, colorSpace);
162141

163142
/// Create an sRGB color from red, green, blue, and opacity, similar to
164143
/// `rgba()` in CSS.
@@ -173,41 +152,38 @@ class Color {
173152
///
174153
/// See also [fromARGB], which takes the opacity as an integer value.
175154
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;
155+
: this._fromRGBOC(r, g, b, opacity, ColorSpace.sRGB);
156+
157+
const Color._fromRGBOC(int r, int g, int b, double opacity, this.colorSpace)
158+
: _a = opacity,
159+
_r = (r & 0xff) / 255,
160+
_g = (g & 0xff) / 255,
161+
_b = (b & 0xff) / 255;
186162

187163
/// The alpha channel of this color.
188164
///
189165
/// A value of 0.0 means this color is fully transparent. A value of 1.0 means
190166
/// this color is fully opaque.
191-
double get a => _a ?? (alpha / 255);
192-
final double? _a;
167+
double get a => _a;
168+
final double _a;
193169

194170
/// The red channel of this color.
195-
double get r => _r ?? (red / 255);
196-
final double? _r;
171+
double get r => _r;
172+
final double _r;
197173

198174
/// The green channel of this color.
199-
double get g => _g ?? (green / 255);
200-
final double? _g;
175+
double get g => _g;
176+
final double _g;
201177

202178
/// The blue channel of this color.
203-
double get b => _b ?? (blue / 255);
204-
final double? _b;
179+
double get b => _b;
180+
final double _b;
205181

206182
/// The color space of this color.
207183
final ColorSpace colorSpace;
208184

209185
static int _floatToInt8(double x) {
210-
return ((x * 255.0).round()) & 0xff;
186+
return (x * 255.0).round() & 0xff;
211187
}
212188

213189
/// A 32 bit value representing this color.
@@ -220,16 +196,11 @@ class Color {
220196
/// * Bits 0-7 are the blue value.
221197
@Deprecated('Use component accessors like .r or .g.')
222198
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-
}
199+
return _floatToInt8(_a) << 24 |
200+
_floatToInt8(_r) << 16 |
201+
_floatToInt8(_g) << 8 |
202+
_floatToInt8(_b) << 0;
231203
}
232-
final int _value;
233204

234205
/// The alpha channel of this color in an 8 bit value.
235206
///

0 commit comments

Comments
 (0)