Skip to content

Commit

Permalink
fix: reduce dust effect on Windows
Browse files Browse the repository at this point in the history
on Windows RAND_MAX is only 32,767.
  • Loading branch information
esmane authored and jaromil committed Jun 3, 2024
1 parent d25ef65 commit 7f0c0a5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/filter/filmgrain/filmgrain.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ static inline uint32_t reduce_color_range(uint32_t color, uint8_t threshold, int
return CLAMP0255(CLAMP(color, threshold >> 1, 255 - threshold) + flicker);
}

#define DUST_RAND_LIMIT 1000000000
static inline int big_rand()
{
#if RAND_MAX > DUST_RAND_LIMIT
return rand() % DUST_RAND_LIMIT;
#else
return (rand() * (RAND_MAX + 1) + rand()) % DUST_RAND_LIMIT;
#endif
}


// these functions are for frei0r
// mostly copy/paste/slightly modified from the other frei0r effects
Expand Down Expand Up @@ -219,7 +229,7 @@ void f0r_update(f0r_instance_t instance, double time, const uint32_t* inframe, u
for(unsigned int i = 0; i < inst->height * inst->width; i++)
{
// dust
if(rand() < inst->dust_amt * 2048)
if(big_rand() < inst->dust_amt * 1000)
{
if(rand() % 2 == 0)
{
Expand Down

0 comments on commit 7f0c0a5

Please sign in to comment.