Skip to content

Commit

Permalink
feat(binary): add interleave4_12_24/4_16_32()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 25, 2021
1 parent d54d943 commit 89044d2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/binary/src/splat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,23 @@ export const same4 = (x: number) => ((x >> 4) & 0xf) === (x & 0xf);
* @param x -
*/
export const same8 = (x: number) => ((x >> 8) & 0xff) === (x & 0xff);

/**
* Expands 3x4bit value like `0xabc` to 24bits: `0xaabbcc`
*
* @param x
*/
export const interleave4_12_24 = (x: number) =>
((x & 0xf00) * 0x1100) | ((x & 0xf0) * 0x110) | ((x & 0xf) * 0x11);

/**
* Expands 4x4bit value like `0xabcd` to 32bits: `0xaabbccdd`
*
* @param x
*/
export const interleave4_16_32 = (x: number) =>
(((x & 0xf000) * 0x11000) |
((x & 0xf00) * 0x1100) |
((x & 0xf0) * 0x110) |
((x & 0xf) * 0x11)) >>>
0;

0 comments on commit 89044d2

Please sign in to comment.