Skip to content

Commit

Permalink
fix(ColorPicker): Do not divide colors by 255 since it is already don…
Browse files Browse the repository at this point in the history
…e under the hood
  • Loading branch information
bdlukaa committed Dec 13, 2024
1 parent 6db8d2f commit 7f0f710
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions lib/src/controls/form/color_picker/color_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ class ColorState extends ChangeNotifier {

/// Creates a [ColorState] from a [Color].
static ColorState fromColor(Color color) {
final r = color.r.toDouble() / 255;
final g = color.g.toDouble() / 255;
final b = color.b.toDouble() / 255;
final a = color.a.toDouble() / 255;
final r = color.r.toDouble();
final g = color.g.toDouble();
final b = color.b.toDouble();
final a = color.a.toDouble();

final hsv = rgbToHsv(RgbComponents(r, g, b));
return ColorState(r, g, b, a, hsv.h, hsv.s, hsv.v);
Expand Down Expand Up @@ -151,10 +151,10 @@ class ColorState extends ChangeNotifier {
final colorText = text.length == 6 ? 'FF$text' : text;
final color = Color(int.parse(colorText, radix: 16));

_red = color.r / 255;
_green = color.g / 255;
_blue = color.b / 255;
_alpha = color.a / 255;
_red = color.r;
_green = color.g;
_blue = color.b;
_alpha = color.a;

final hsv = rgbToHsv(RgbComponents(_red, _green, _blue));
_hue = hsv.h;
Expand Down Expand Up @@ -342,18 +342,18 @@ class ColorState extends ChangeNotifier {

/// Converts Color to HSV.
static HsvComponents colorToHsv(Color color) {
final red = color.r / 255;
final green = color.g / 255;
final blue = color.b / 255;
final red = color.r;
final green = color.g;
final blue = color.b;

return rgbToHsv(RgbComponents(red, green, blue));
}

/// Converts Color to HSL.
static HslComponents colorToHsl(Color color) {
final red = color.r / 255;
final green = color.g / 255;
final blue = color.b / 255;
final red = color.r;
final green = color.g;
final blue = color.b;

return rgbToHsl(RgbComponents(red, green, blue));
}
Expand Down Expand Up @@ -500,8 +500,8 @@ class ColorState extends ChangeNotifier {
/// Get distance between two colors considering both RGB and HSL spaces
static double colorDistance(Color from, Color to) {
// Normalize RGB values to range 0-1
final fromRgb = RgbComponents(from.r / 255, from.g / 255, from.b / 255);
final toRgb = RgbComponents(to.r / 255, to.g / 255, to.b / 255);
final fromRgb = RgbComponents(from.r, from.g, from.b);
final toRgb = RgbComponents(to.r, to.g, to.b);

// Convert RGB to HSL
final fromHsl = rgbToHsl(fromRgb);
Expand Down Expand Up @@ -555,9 +555,9 @@ class ColorState extends ChangeNotifier {
///
/// Returns a value between 0 (darkest) and 1 (brightest).
static double relativeLuminance(Color color) {
final r = _standardToLinear(color.r / 255);
final g = _standardToLinear(color.g / 255);
final b = _standardToLinear(color.b / 255);
final r = _standardToLinear(color.r);
final g = _standardToLinear(color.g);
final b = _standardToLinear(color.b);
return (r * 0.2126 + g * 0.7152 + b * 0.0722);
}

Expand Down

0 comments on commit 7f0f710

Please sign in to comment.