From 4fec59ec6427cac41a04b8db0157ee7b56b7e5c3 Mon Sep 17 00:00:00 2001 From: tth Date: Tue, 28 Jul 2020 08:19:38 +0200 Subject: [PATCH] this is romulian saturation control --- floatimg.h | 7 ++++++- funcs/Makefile | 5 ++++- funcs/saturation.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 funcs/saturation.c diff --git a/floatimg.h b/floatimg.h index eacfa888..3e62026b 100644 --- a/floatimg.h +++ b/floatimg.h @@ -63,7 +63,8 @@ void fimg_print_sizeof(void); void fimg_printhead(FloatImg *h); int fimg_describe(FloatImg *head, char *txt); char *fimg_str_type(int type); -int fimg_plot_rgb (FloatImg *head, int x, int y, float r, float g, float b); +int fimg_plot_rgb (FloatImg *head, int x, int y, + float r, float g, float b); int fimg_get_rgb(FloatImg *head, int x, int y, float *rgb); int fimg_put_rgb(FloatImg *head, int x, int y, float *rgb); int fimg_clear(FloatImg *fimg); @@ -119,6 +120,10 @@ int fimg_power_2(FloatImg *s, FloatImg *d, double maxval); int fimg_cos_01(FloatImg *s, FloatImg *d, double maxval); int fimg_cos_010(FloatImg *s, FloatImg *d, double maxval); + +int fimg_mix_rgb_gray(FloatImg *img, float mix); + + /* module funcs/geometry.c */ int fimg_equalize_compute(FloatImg *src, void *vptr); diff --git a/funcs/Makefile b/funcs/Makefile index 209947df..9ad28abb 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -4,7 +4,7 @@ COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0 DEPS = ../floatimg.h Makefile OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \ fimg-libpnm.o rampes.o sfx0.o geometry.o rotate.o \ - equalize.o fimg-fits.o + equalize.o fimg-fits.o saturation.o #--------------------------------------------------------------- @@ -41,6 +41,9 @@ geometry.o: geometry.c $(DEPS) rotate.o: rotate.c $(DEPS) gcc $(COPT) -c $< +saturation.o: saturation.c $(DEPS) + gcc $(COPT) -c $< + equalize.o: equalize.c $(DEPS) gcc $(COPT) -c $< diff --git a/funcs/saturation.c b/funcs/saturation.c new file mode 100644 index 00000000..68ff3882 --- /dev/null +++ b/funcs/saturation.c @@ -0,0 +1,44 @@ +/* + * FloatImg library from tTh + */ + +#include + +#include "../floatimg.h" + +/* -------------------------------------------------------------- */ +/* global vars from main + */ +extern int verbosity; + +/* -------------------------------------------------------------- */ + +int fimg_mix_rgb_gray(FloatImg *img, float mix) +{ +int x, y, p; +float gr; + +if (FIMG_TYPE_RGB != img->type) { + fprintf(stderr, "%s bad type\n", __func__); + return -6; + } + +for (y=0; yheight; y++) { + p = y * img->width; + for (x=0; xwidth; x++) { + + gr = (img->R[p] + img->G[p] + img->R[p]) / 3.0; + + img->R[p] = ((gr * mix) + (img->R[p] * (1.0-mix))) / 2.0; + img->G[p] = ((gr * mix) + (img->G[p] * (1.0-mix))) / 2.0; + img->B[p] = ((gr * mix) + (img->B[p] * (1.0-mix))) / 2.0; + + p++; /* next pixel in the row */ + } + + } + +return 0; +} + +/* -------------------------------------------------------------- */