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

@@ -3,7 +3,7 @@
* It contains code from plug-ins/common/noise-rgb.c, see that for copyrights.
*
* rgbnoise.c
* Copyright 2012 Janne Liljeblad
* Copyright 2012 Janne Liljeblad
*
* This file is a Frei0r plugin.
*
@@ -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;
@@ -52,9 +54,9 @@ void f0r_get_plugin_info(f0r_plugin_info_t* rgbnoiseInfo)
rgbnoiseInfo->plugin_type = F0R_PLUGIN_TYPE_FILTER;
rgbnoiseInfo->color_model = F0R_COLOR_MODEL_RGBA8888;
rgbnoiseInfo->frei0r_version = FREI0R_MAJOR_VERSION;
rgbnoiseInfo->major_version = 0;
rgbnoiseInfo->minor_version = 9;
rgbnoiseInfo->num_params = 1;
rgbnoiseInfo->major_version = 0;
rgbnoiseInfo->minor_version = 9;
rgbnoiseInfo->num_params = 1;
rgbnoiseInfo->explanation = "Adds RGB noise to image.";
}
@@ -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;
}
@@ -86,7 +88,7 @@ void f0r_destruct(f0r_instance_t instance)
free(instance);
}
void f0r_set_param_value(f0r_instance_t instance,
void f0r_set_param_value(f0r_instance_t instance,
f0r_param_t param, int param_index)
{
rgbnoise_instance_t* inst = (rgbnoise_instance_t*)instance;
@@ -100,9 +102,9 @@ void f0r_set_param_value(f0r_instance_t instance,
void f0r_get_param_value(f0r_instance_t instance,
f0r_param_t param, int param_index)
{
{
rgbnoise_instance_t* inst = (rgbnoise_instance_t*)instance;
switch (param_index)
switch (param_index)
{
case 0:
*((double*)param) = inst->noise;
@@ -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

@@ -1,7 +1,7 @@
/* rgbsplit0r.c
* Copyright (C) 2016 IDENT Software ~ http://identsoft.org
* Inspired by the witch house and web culture
*
*
* This file is a Frei0r plugin.
*
* This program is free software; you can redistribute it and/or modify
@@ -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;
}
@@ -126,7 +119,7 @@ void f0r_destruct(f0r_instance_t instance)
free(instance);
}
void f0r_set_param_value(f0r_instance_t instance,
void f0r_set_param_value(f0r_instance_t instance,
f0r_param_t param, int param_index)
{
assert(instance);
@@ -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,