Minor fixes following up review

use CLAMP in colordistance

keep MY_MAX_RAND in rgbnoise

code cleanup from old experiments

leaner free section in water

Co-authored-by: Dan Dennedy <dan@dennedy.org>
This commit is contained in:
Jaromil
2025-12-02 17:01:49 +01:00
parent 542c4bc0a9
commit f081aa64d4
4 changed files with 23 additions and 31 deletions

View File

@@ -135,8 +135,7 @@ void f0r_update(f0r_instance_t instance, double time,
l = (int)rint( sqrtf( powf( r1 - r2, 2 ) + powf( g1 - g2, 2 ) + powf( b1 - b2, 2 ) ) * SCALE_FACTOR );
// Clamp result to valid range
if (l < 0) l = 0;
if (l > 255) l = 255;
l = CLAMP(l, 0, 255);
*dst++ = (unsigned char) (l);
*dst++ = (unsigned char) (l);

View File

@@ -29,12 +29,14 @@
#include "frei0r.h"
#include "frei0r/math.h"
#define MY_MAX_RAND 32767 // assume RAND_MAX to be at least this big.
typedef struct rgbnoise_instance
{
unsigned int width;
unsigned int height;
double noise;
double gaussian_lookup[32767];
double gaussian_lookup[MY_MAX_RAND];
int table_inited;
int next_gaussian_index;
int last_in_range;
@@ -77,7 +79,7 @@ f0r_instance_t f0r_construct(unsigned int width, unsigned int height)
inst->noise = 0.2;
inst->table_inited = 0;
inst->next_gaussian_index = 0;
inst->last_in_range = 32766;
inst->last_in_range = MY_MAX_RAND;
return (f0r_instance_t)inst;
}
@@ -137,8 +139,8 @@ static inline double gauss()
static void create_new_lookup_range(rgbnoise_instance_t* inst)
{
int first, last, tmp;
first = rand() % (32767 - 1);
last = rand() % (32767 - 1);
first = rand() % (MY_MAX_RAND - 1);
last = rand() % (MY_MAX_RAND - 1);
if (first > last)
{
tmp = last;
@@ -185,13 +187,13 @@ void rgb_noise(f0r_instance_t instance, double time,
if (inst->table_inited == 0)
{
int i;
for( i = 0; i < 32767; i++)
for( i = 0; i < MY_MAX_RAND; i++)
{
inst->gaussian_lookup[i] = gauss() * 127.0;
}
inst->table_inited = 1;
inst->next_gaussian_index = 0;
inst->last_in_range = 32766;
inst->last_in_range = MY_MAX_RAND;
}
unsigned char* dst = (unsigned char*)outframe;
@@ -218,4 +220,3 @@ void f0r_update(f0r_instance_t instance, double time,
assert(instance);
rgb_noise(instance, time, inframe, outframe);
}

View File

@@ -111,13 +111,6 @@ f0r_instance_t f0r_construct(unsigned int width, unsigned int height)
inst->width = width; inst->height = height;
inst->shiftY = 0;
inst->shiftX = 0;
// Initialize default values for shift to avoid division by zero issues
if (width > 0 && height > 0) {
inst->shiftY = (unsigned int)((height / 8) * 0.0); // 0.0 corresponds to center
inst->shiftX = (unsigned int)((width / 8) * 0.0); // 0.0 corresponds to center
}
return (f0r_instance_t)inst;
}
@@ -239,4 +232,3 @@ void f0r_update(f0r_instance_t instance, double time,
*(dst + x + (y*inst->width)) = (pxG | pxB | pxR);
}
}

View File

@@ -141,11 +141,11 @@ public:
~Water() {
delete geo;
if (Height[0]) free(Height[0]);
if (Height[1]) free(Height[1]);
if (BkGdImagePre) free(BkGdImagePre);
if (BkGdImage) free(BkGdImage);
if (BkGdImagePost) free(BkGdImagePost);
free(Height[0]);
free(Height[1]);
free(BkGdImagePre);
free(BkGdImage);
free(BkGdImagePost);
}
virtual void update(double time,