Proper Station color averaging

This commit is contained in:
2018-04-14 18:09:25 -04:00
parent 902645d46a
commit 7c488cf2ca
5 changed files with 32 additions and 21 deletions

View File

@@ -42,13 +42,3 @@ export const rangeMap = (num: number, inMin: number, inMax: number,
outMin: number, outMax: number): number => (
(num - inMin) * (outMax - outMin) / (inMax - inMin) + outMin
);
// tslint:disable no-bitwise
export const nthByte = (num: number, n: number): number => ((num >> (8 * n)) & 0xff);
// FIXME: pretty sure this is wrong, just use a color library instead and then convert to hex
export const avgHexColor = (colorA: number, colorB: number): number => (
(Math.round((nthByte(colorA, 2) + nthByte(colorB, 2)) / 2) & 0xFF) |
((Math.round((nthByte(colorA, 1) + nthByte(colorB, 1)) / 2) & 0xFF) << 8) |
((Math.round((nthByte(colorA, 0) + nthByte(colorB, 0)) / 2) & 0x0F) << 16)
);