mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
fix(color): output from rgbToHsv and rgbToHsl is now correct (#9933)
This commit is contained in:

committed by
GitHub

parent
aee1d05651
commit
ef70956623
@ -466,8 +466,12 @@ function argbFromHsvOrHsva(value: string): number {
|
|||||||
// *Assumes:* r, g, and b are contained in [0, 255]
|
// *Assumes:* r, g, and b are contained in [0, 255]
|
||||||
// *Returns:* { h, s, l } in [0,360] and [0,100]
|
// *Returns:* { h, s, l } in [0,360] and [0,100]
|
||||||
function rgbToHsl(r, g, b) {
|
function rgbToHsl(r, g, b) {
|
||||||
const max = Math.max(r, g, b) / 255,
|
r /= 255;
|
||||||
min = Math.min(r, g, b) / 255;
|
g /= 255;
|
||||||
|
b /= 255;
|
||||||
|
|
||||||
|
const max = Math.max(r, g, b),
|
||||||
|
min = Math.min(r, g, b);
|
||||||
let h, s;
|
let h, s;
|
||||||
const l = (max + min) / 2;
|
const l = (max + min) / 2;
|
||||||
|
|
||||||
@ -478,13 +482,13 @@ function rgbToHsl(r, g, b) {
|
|||||||
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
||||||
switch (max) {
|
switch (max) {
|
||||||
case r:
|
case r:
|
||||||
h = (g - b) / 255 / d + (g < b ? 6 : 0);
|
h = (g - b) / d + (g < b ? 6 : 0);
|
||||||
break;
|
break;
|
||||||
case g:
|
case g:
|
||||||
h = (b - r) / 255 / d + 2;
|
h = (b - r) / d + 2;
|
||||||
break;
|
break;
|
||||||
case b:
|
case b:
|
||||||
h = (r - g) / 255 / d + 4;
|
h = (r - g) / d + 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,8 +534,12 @@ function hslToRgb(h1, s1, l1) {
|
|||||||
// *Assumes:* r, g, and b are contained in the set [0, 255]
|
// *Assumes:* r, g, and b are contained in the set [0, 255]
|
||||||
// *Returns:* { h, s, v } in [0,360] and [0,100]
|
// *Returns:* { h, s, v } in [0,360] and [0,100]
|
||||||
function rgbToHsv(r, g, b) {
|
function rgbToHsv(r, g, b) {
|
||||||
const max = Math.max(r, g, b) / 255,
|
r /= 255;
|
||||||
min = Math.min(r, g, b) / 255;
|
g /= 255;
|
||||||
|
b /= 255;
|
||||||
|
|
||||||
|
const max = Math.max(r, g, b),
|
||||||
|
min = Math.min(r, g, b);
|
||||||
let h;
|
let h;
|
||||||
const v = max;
|
const v = max;
|
||||||
|
|
||||||
@ -543,13 +551,13 @@ function rgbToHsv(r, g, b) {
|
|||||||
} else {
|
} else {
|
||||||
switch (max) {
|
switch (max) {
|
||||||
case r:
|
case r:
|
||||||
h = (g - b) / 255 / d + (g < b ? 6 : 0);
|
h = (g - b) / d + (g < b ? 6 : 0);
|
||||||
break;
|
break;
|
||||||
case g:
|
case g:
|
||||||
h = (b - r) / 255 / d + 2;
|
h = (b - r) / d + 2;
|
||||||
break;
|
break;
|
||||||
case b:
|
case b:
|
||||||
h = (r - g) / 255 / d + 4;
|
h = (r - g) / d + 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
h /= 6;
|
h /= 6;
|
||||||
|
Reference in New Issue
Block a user