diff --git a/floatimg.h b/floatimg.h index eacfa88..3e62026 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 209947d..9ad28ab 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 0000000..68ff388 --- /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; +} + +/* -------------------------------------------------------------- */