mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2025-01-18 22:36:27 +01:00
Update color converter
This commit is contained in:
parent
ae74c0354d
commit
595f39f9bf
@ -14,11 +14,26 @@ export class ColorConverter
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
const extracted = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
|
||||
|
Loading…
Reference in New Issue
Block a user