mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2024-10-23 11:33:06 +02:00
Update color converter
This commit is contained in:
parent
ae74c0354d
commit
595f39f9bf
@ -14,11 +14,26 @@ export class ColorConverter
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static hex2rgba(hex: number, out: Array<number> | Float32Array = []): Array<number> | Float32Array
|
||||||
|
{
|
||||||
|
out[0] = ((hex >> 16) & 0xFF) / 255;
|
||||||
|
out[1] = ((hex >> 8) & 0xFF) / 255;
|
||||||
|
out[2] = (hex & 0xFF) / 255;
|
||||||
|
out[3] = (hex & 0xFF);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
public static rgb2hex(rgb: number[] | Float32Array): number
|
public static rgb2hex(rgb: number[] | Float32Array): number
|
||||||
{
|
{
|
||||||
return (((rgb[0] * 255) << 16) + ((rgb[1] * 255) << 8) + (rgb[2] * 255 | 0));
|
return (((rgb[0] * 255) << 16) + ((rgb[1] * 255) << 8) + (rgb[2] * 255 | 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static rgba2hex(rgb: number[] | Float32Array): number
|
||||||
|
{
|
||||||
|
return (((rgb[0] * 255) << 16) + ((rgb[1] * 255) << 8) + (rgb[2] * 255 | 0) + (rgb[3] | 0));
|
||||||
|
}
|
||||||
|
|
||||||
public static rgbStringToHex(rgb: string): string
|
public static rgbStringToHex(rgb: string): string
|
||||||
{
|
{
|
||||||
const extracted = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
|
const extracted = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
|
||||||
|
Loading…
Reference in New Issue
Block a user