OSC 10/11 working, OSC 4 partially fixed
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
|
||||
import { IColor } from 'browser/Types';
|
||||
|
||||
// FIXME: Move Color.ts lib to common?
|
||||
|
||||
/**
|
||||
* Helper functions where the source type is "channels" (individual color channels as numbers).
|
||||
*/
|
||||
@@ -17,6 +19,8 @@ export namespace channels {
|
||||
}
|
||||
|
||||
export function toRgba(r: number, g: number, b: number, a: number = 0xFF): number {
|
||||
// Note: The aggregated number is RGBA32 (BE), thus needs to be converted to ABGR32
|
||||
// on LE systems, before it can be used for direct 32-bit buffer writes.
|
||||
// >>> 0 forces an unsigned int
|
||||
return (r << 24 | g << 16 | b << 8 | a) >>> 0;
|
||||
}
|
||||
@@ -81,6 +85,11 @@ export namespace color {
|
||||
rgba: channels.toRgba(r, g, b, a)
|
||||
};
|
||||
}
|
||||
|
||||
export function toXColorName(color: IColor): string {
|
||||
const [r, g, b] = rgba.toChannels(color.rgba);
|
||||
return `rgb:${toPaddedHex(r)}/${toPaddedHex(g)}/${toPaddedHex(b)}`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,6 +206,7 @@ export namespace rgba {
|
||||
return (fgR << 24 | fgG << 16 | fgB << 8 | 0xFF) >>> 0;
|
||||
}
|
||||
|
||||
// FIXME: Move this to channels NS?
|
||||
export function toChannels(value: number): [number, number, number, number] {
|
||||
return [(value >> 24) & 0xFF, (value >> 16) & 0xFF, (value >> 8) & 0xFF, value & 0xFF];
|
||||
}
|
||||
@@ -207,6 +217,13 @@ export namespace rgba {
|
||||
rgba: channels.toRgba(r, g, b)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* convert 0xRRGGBBAA to 0xAABBGGRR (32-bit representation on LE systems)
|
||||
*/
|
||||
export function toABGR32(rgba: number): number {
|
||||
return ((rgba & 0xFF) << 24 | (rgba >>> 8 & 0xFF) << 16 | (rgba >>> 16 & 0xFF) << 8 | rgba >>> 24 & 0xFF) >>> 0;
|
||||
}
|
||||
}
|
||||
|
||||
export function toPaddedHex(c: number): string {
|
||||
|
||||
Reference in New Issue
Block a user