Fries
f7bbb92d85
the api now requires you to call an async function initWasm to make the functions work instead of using top level await. i also optimized the wasm module to have O3 and fast-math (which the original blurhash makefile had and the results do seem to be the same with the javascript blurhash). I also gave the wasm instance functions inside typescript types and i fixed a bug where i didnt free the pointers in order so if you called decode too many times, you will run out of memory.
33 lines
621 B
C
33 lines
621 B
C
#ifndef __BLURHASH_COMMON_H__
|
|
#define __BLURHASH_COMMON_H__
|
|
|
|
#include <math.h>
|
|
|
|
#ifndef M_PI
|
|
#define M_PI 3.14159265358979323846
|
|
#endif
|
|
|
|
static inline int linearTosRGB(float value)
|
|
{
|
|
float v = fmaxf(0, fminf(1, value));
|
|
if (v <= 0.0031308)
|
|
return v * 12.92 * 255 + 0.5;
|
|
else
|
|
return (1.055 * powf(v, 1 / 2.4) - 0.055) * 255 + 0.5;
|
|
}
|
|
|
|
static inline float sRGBToLinear(int value)
|
|
{
|
|
float v = (float)value / 255;
|
|
if (v <= 0.04045)
|
|
return v / 12.92;
|
|
else
|
|
return powf((v + 0.055) / 1.055, 2.4);
|
|
}
|
|
|
|
static inline float signPow(float value, float exp)
|
|
{
|
|
return copysignf(powf(fabsf(value), exp), value);
|
|
}
|
|
|
|
#endif
|