a new sfx func is born

This commit is contained in:
tth 2021-03-20 19:47:42 +01:00
parent 0aba64181c
commit 64c1383283
6 changed files with 158 additions and 4 deletions

View File

@ -4,7 +4,7 @@
* http://la.buvette.org/photos/cumul * http://la.buvette.org/photos/cumul
*/ */
#define FIMG_VERSION 124 #define FIMG_VERSION 125
/* /*
* in memory descriptor * in memory descriptor
@ -102,11 +102,16 @@ int fimg_filter_3x3(FloatImg *s, FloatImg *d, FimgFilter3x3 *filtr);
int fimg_contour_2x2(FloatImg *psrc, FloatImg *pdst, int reverse); int fimg_contour_2x2(FloatImg *psrc, FloatImg *pdst, int reverse);
/* 'sfx0' module */ /* module sfx0.c */
int fimg_killcolors_a(FloatImg *fimg, float fval); int fimg_killcolors_a(FloatImg *fimg, float fval);
int fimg_killcolors_b(FloatImg *fimg, float fval); int fimg_killcolors_b(FloatImg *fimg, float fval);
int fimg_colors_mixer_a(FloatImg *fimg, float fval); int fimg_colors_mixer_a(FloatImg *fimg, float fval);
/* module sfx1.c */
int fimg_highlight_color(FloatImg *src, FloatImg *dst,
char color, float fval);
/* funcs/rotate.c module */ /* funcs/rotate.c module */
/* #coronamaison */ /* #coronamaison */
int fimg_rotate_90(FloatImg *src, FloatImg *dst, int notused); int fimg_rotate_90(FloatImg *src, FloatImg *dst, int notused);

View File

@ -4,7 +4,8 @@ COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0
DEPS = ../floatimg.h Makefile DEPS = ../floatimg.h Makefile
OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \ 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 \ fimg-libpnm.o rampes.o sfx0.o sfx1.o \
geometry.o rotate.o \
equalize.o fimg-fits.o saturation.o histogram.o \ equalize.o fimg-fits.o saturation.o histogram.o \
hsv.o classif.o contour2x2.o qsortrgb.o exporter.o \ hsv.o classif.o contour2x2.o qsortrgb.o exporter.o \
displacement.o dithering.o plasmas.o displacement.o dithering.o plasmas.o
@ -77,6 +78,9 @@ plasmas.o: plasmas.c $(DEPS)
sfx0.o: sfx0.c $(DEPS) sfx0.o: sfx0.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<
sfx1.o: sfx1.c $(DEPS)
gcc $(COPT) -c $<
contour2x2.o: contour2x2.c $(DEPS) contour2x2.o: contour2x2.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<

107
funcs/sfx1.c Normal file
View File

@ -0,0 +1,107 @@
/*
* FLOATIMG - a kluge from tTh
* effets spéciaux bizarres sur les couleurs.
* nouveau pour un truc chelou avec Maëva
*/
#include <stdio.h>
#include <string.h>
#include "../floatimg.h"
/* WARNING
some crapy code cuted & pasted here */
/* --------------------------------------------------------------------- */
static void highlight_red(FloatImg *src, FloatImg *dst, float fval)
{
int sz, idx;
sz = src->width * src->height;
for (idx=0; idx<sz; idx++) {
dst->G[idx] = src->G[idx];
dst->B[idx] = src->B[idx];
if ( (src->G[idx] < src->R[idx]) &&
(src->B[idx] < src->R[idx]) ) {
dst->R[idx] = src->R[idx] * fval;
}
else {
dst->R[idx] = src->R[idx];
}
}
}
/* --------------------------------------------------------------------- */
static void highlight_green(FloatImg *src, FloatImg *dst, float fval)
{
int sz, idx;
sz = src->width * src->height;
for (idx=0; idx<sz; idx++) {
dst->R[idx] = src->R[idx];
dst->B[idx] = src->B[idx];
if ( (src->R[idx] < src->R[idx]) &&
(src->B[idx] < src->R[idx]) ) {
dst->G[idx] = src->G[idx] * fval;
}
else {
dst->G[idx] = src->G[idx];
}
}
}
/* --------------------------------------------------------------------- */
static void highlight_blue(FloatImg *src, FloatImg *dst, float fval)
{
int sz, idx;
sz = src->width * src->height;
for (idx=0; idx<sz; idx++) {
dst->G[idx] = src->G[idx];
dst->R[idx] = src->R[idx];
if ( (src->G[idx] < src->B[idx]) &&
(src->R[idx] < src->B[idx]) ) {
dst->B[idx] = src->B[idx] * fval;
}
else {
dst->B[idx] = src->B[idx];
}
}
}
/* --------------------------------------------------------------------- */
int fimg_highlight_color(FloatImg *src, FloatImg *dst, char color, float fval)
{
int sz;
#ifdef DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p [%c] %f )\n", __func__,
src, dst, color, fval);
#endif
if (FIMG_TYPE_RGB != src->type) {
fprintf(stderr, "%s: bad src type %d on %p\n", __func__,
src->type, src);
return -8;
}
if (fimg_images_not_compatible(src, dst)) {
fprintf(stderr, "oh fuck in %s\n", __func__);
return -9;
}
switch (color) {
case 'r': case 'R':
highlight_red(src, dst, fval); break;
case 'g': case 'G':
highlight_green(src, dst, fval); break;
case 'b': case 'B':
highlight_blue(src, dst, fval); break;
default:
fprintf(stderr, "%s: '%c' is invalid\n", __func__, color);
return -11;
break; /* nottreached */
}
return 0;
}
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */

View File

@ -21,7 +21,7 @@ float global_fvalue;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
Histo, Hsv, Classif, Ctr2x2, Qsortrgb, Histo, Hsv, Classif, Ctr2x2, Qsortrgb,
Displace, ReadPNG, Plasmas }; Displace, ReadPNG, Plasmas, Hilight };
typedef struct { typedef struct {
char *name; char *name;
int Cmd; int Cmd;
@ -44,6 +44,7 @@ Command commands[] = {
{ "displace", Displace }, { "displace", Displace },
{ "readpng", ReadPNG }, { "readpng", ReadPNG },
{ "plasma", Plasmas }, { "plasma", Plasmas },
{ "hilight", Hilight },
{ NULL, 0 } { NULL, 0 }
} ; } ;
@ -194,6 +195,9 @@ switch(opt) {
fprintf(stderr, "rotate not implemented (%d)\n", rand()); fprintf(stderr, "rotate not implemented (%d)\n", rand());
foo = 0; foo = 0;
break; break;
case Hilight:
foo = essai_highlights(filename, outfile, 0, global_fvalue);
break;
default: default:
fprintf(stderr, "'%s' is a bad command\n", command); fprintf(stderr, "'%s' is a bad command\n", command);
exit(1); exit(1);

View File

@ -16,6 +16,39 @@
extern int verbosity; extern int verbosity;
/* --------------------------------------------------------------------- */
/* nouveau 20 mars 2021 - rue d'Aragon */
int essai_highlights(char *inf, char *outf, int ikoef, float fkoef)
{
FloatImg src, dst;
int foo;
fprintf(stderr, ">>> %s ( '%s' '%s' %d %g )\n", __func__,
inf, outf, ikoef, fkoef);
foo = fimg_create_from_dump(inf, &src);
if (0 != foo) {
fprintf(stderr, "%s: err %d loading image '%s'\n", __func__,
foo, inf);
return foo;
}
fimg_clone(&src, &dst, 0);
foo = fimg_highlight_color(&src, &dst, 'R', fkoef);
if (foo) {
fprintf(stderr, "%s: err %d ?\n", __func__, foo);
return foo;
}
foo = fimg_export_picture(&dst, outf, 0);
if (foo) {
fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
return foo;
}
return 0;
}
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int essai_plasma(char *infile, char *outfile, int ikoef, float fkoef) int essai_plasma(char *infile, char *outfile, int ikoef, float fkoef)

View File

@ -25,4 +25,5 @@ int essai_histogramme(char *fname, int k);
int essai_lecture_png(char *fname, char *outfile, int notused); int essai_lecture_png(char *fname, char *outfile, int notused);
int essai_highlights(char *inf, char *outf, int ikoef, float fkoef);