2022-04-06 01:18:07 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
2024-11-18 19:20:23 +00:00
|
|
|
import { encode } from 'blurhash';
|
2022-04-06 01:18:07 +00:00
|
|
|
|
2024-11-18 19:20:23 +00:00
|
|
|
/**
|
|
|
|
* This generates a blurhash for a single pixel of a given color.
|
|
|
|
*
|
|
|
|
* The color is specified as an ARGB value, where the alpha channel is ignored.
|
|
|
|
*/
|
|
|
|
export function generateBlurHash(argb: number = 0xff_fbfbfb): string {
|
|
|
|
return encode(
|
|
|
|
new Uint8ClampedArray([
|
|
|
|
/* eslint-disable no-bitwise */
|
|
|
|
// Flipping from argb to rgba
|
|
|
|
0xff & (argb >> 16), // R
|
|
|
|
0xff & (argb >> 8), // G
|
|
|
|
0xff & (argb >> 0), // B
|
|
|
|
0xff, // A (ignored)
|
|
|
|
/* eslint-enable no-bitwise */
|
|
|
|
]),
|
|
|
|
1, // width (data is just one pixel)
|
|
|
|
1, // height (data is just one pixel)
|
|
|
|
1, // x components (just the average color)
|
|
|
|
1 // y components (just the average color)
|
|
|
|
);
|
2022-04-06 01:18:07 +00:00
|
|
|
}
|