refactoring fonderie, step 1

This commit is contained in:
Tonton Th 2020-11-02 14:51:48 +01:00
parent d50f2145ba
commit 8cc7695d70
7 changed files with 143 additions and 166 deletions

9
Fonderie/README.md Normal file
View File

@ -0,0 +1,9 @@
# Fonderie
Avec toutes ces fonctions disponibles et `grabvidseq`, nous
savons faire des images **floues***. L'étape suivante, les plus
pervers d'entre vous le savent déja, est celle de la création
de **films flous**.
## fonderie

View File

@ -7,35 +7,115 @@
#include <floatimg.h>
#include "fonctions.h"
#include "crapulator.h"
/* -------------------------------------------------------------- */
int crapulator(FloatImg *image, int notused)
int crapulator(FloatImg *image, int idFx, float fval)
{
int retval;
FloatImg imgtmp;
int retval, foo;
FloatImg imgtmp;
static int count = 0;
int flag_debug = 0;
float value;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, image, notused);
fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__,
image, idFx, fval);
#endif
/* contour 2x2 don't work inplace */
fimg_clone(image, &imgtmp, 0);
/* so we work on a copy */
retval = fimg_contour_2x2(image, &imgtmp, 0);
if (retval) {
fprintf(stderr, "%s : err contour %d\n",
__func__, retval);
exit(1);
if (666==count) {
flag_debug = 1;
fprintf(stderr, "DEBUG POINT 1 in %s\n", __func__);
fimg_save_as_png(image, "source.png", 0);
}
/* and put back porcessed pixels */
fimg_copy_data(&imgtmp, image);
fimg_destroy(&imgtmp);
switch (idFx) {
case 0: /* DO NOTHING */
retval = 0; break;
return 0;
case 1:
fimg_cos_01(image, image,
fimg_get_maxvalue(image));
break;
case 2:
fimg_cos_010(image, image,
fimg_get_maxvalue(image));
break;
case 3:
value = fimg_get_maxvalue(image);
fimg_mul_cste(image, -1.0);
fimg_add_cste(image, value);
foo = fimg_count_negativ(image);
if (foo) {
fimg_dump_to_file(image, "err.fimg", 0);
fprintf(stderr, "%s negativ %d\n",
__func__, foo);
return -78;
}
break;
case 4:
brotche_rand48_a(image, 0.20,
fimg_get_maxvalue(image));
break;
case 5:
brotche_rand48_b(image, 0.10,
fimg_get_maxvalue(image)*0.8);
break;
case 6:
fimg_killcolors_a(image, 0.0);
break;
case 7:
retval = fimg_colors_mixer_a(image, 2.0);
break;
case 8:
fimg_clone(image, &imgtmp, 0);
fimg_clear(&imgtmp);
if (flag_debug) {
fprintf(stderr, "DEBUG A contour 2x2\n");
fimg_save_as_png(image, "before.png", 0);
fimg_dump_to_file(image, "before.fimg", 0);
}
retval = fimg_contour_2x2(image, &imgtmp, 0);
if (retval) {
fprintf(stderr, "%s : err contour %d\n",
__func__, retval);
exit(1);
}
if (flag_debug) {
fprintf(stderr, "DEBUG B contour 2x2\n");
// fimg_save_as_png(&imgtmp, "contour.png", 0);
fimg_dump_to_file(&imgtmp, "contour.fimg", 0);
}
fimg_copy_data(&imgtmp, image);
fimg_destroy(&imgtmp);
break;
case 9:
retval = fimg_classif_trial(image, image, 0.42, 0);
if (retval) {
fprintf(stderr, "err %d in classif\n", retval);
exit(1);
}
break;
default :
fprintf(stderr, "%s : effect #%d invalid\n",
__func__, idFx);
return -77;
}
if (flag_debug) {
fprintf(stderr, "DEBUG POINT 2 in %s\n", __func__);
fimg_save_as_png(image, "after.png", 0);
}
count++; flag_debug = 0;
return retval;
}
/* -------------------------------------------------------------- */

View File

@ -2,5 +2,5 @@
* crapulator.h
*/
int crapulator(FloatImg *image, int notused);
int crapulator(FloatImg *image, int id_effect, float fparam);

View File

@ -11,6 +11,7 @@
#include <floatimg.h>
#include "fonctions.h"
#include "crapulator.h"
/* -------------------------------------------------------------- */
/* global vars from main
@ -46,104 +47,6 @@ for (idx=0; idx<pfifo->nbslots; idx += step) {
return 0;
}
/* -------------------------------------------------------------- */
int post_process_picture(FloatImg *image, int numFx, float fval)
{
int retval = 0;
int foo;
float value;
FloatImg imgtmp;
static int count, flag_debug;
if (666==count) {
flag_debug = 1;
fprintf(stderr, "DEBUG POINT 1 in %s\n", __func__);
fimg_save_as_png(image, "source.png", 0);
}
switch (numFx) {
case 0: /* DO NOTHING */ break;
case 1:
fimg_cos_01(image, image,
fimg_get_maxvalue(image));
break;
case 2:
fimg_cos_010(image, image,
fimg_get_maxvalue(image));
break;
case 3:
value = fimg_get_maxvalue(image);
fimg_mul_cste(image, -1.0);
fimg_add_cste(image, value);
foo = fimg_count_negativ(image);
if (foo) {
fimg_dump_to_file(image, "err.fimg", 0);
fprintf(stderr, "%s negativ %d\n", __func__, foo);
return -78;
}
break;
case 4:
brotche_rand48(image, 0.20,
fimg_get_maxvalue(image));
break;
case 5:
brotche_rand48_b(image, 0.10,
fimg_get_maxvalue(image)*0.8);
break;
case 6:
kill_colors_a(image, 0.0);
break;
case 7:
retval = fimg_colors_mixer_a(image, 2.0);
break;
case 8:
fimg_clone(image, &imgtmp, 0);
fimg_clear(&imgtmp);
if (flag_debug) {
fprintf(stderr, "DEBUG A contour 2x2\n");
fimg_save_as_png(image, "before.png", 0);
fimg_dump_to_file(image, "before.fimg", 0);
}
retval = fimg_contour_2x2(image, &imgtmp, 0);
if (retval) {
fprintf(stderr, "%s : err contour %d\n",
__func__, retval);
exit(1);
}
if (flag_debug) {
fprintf(stderr, "DEBUG B contour 2x2\n");
// fimg_save_as_png(&imgtmp, "contour.png", 0);
fimg_dump_to_file(&imgtmp, "contour.fimg", 0);
}
fimg_copy_data(&imgtmp, image);
fimg_destroy(&imgtmp);
break;
case 9:
retval = fimg_classif_trial(image, image, 0.42, 0);
if (retval) {
fprintf(stderr, "err %d in classif\n", retval);
exit(1);
}
break;
default :
fprintf(stderr, "%s : postproc #%d invalid\n",
__func__, numFx);
return -77;
}
if (flag_debug) {
fprintf(stderr, "DEBUG POINT 2 in %s\n", __func__);
fimg_save_as_png(image, "after.png", 0);
}
count++; flag_debug = 0;
return retval;
}
/* -------------------------------------------------------------- */
/*
* this func save the fifo content as
@ -165,9 +68,10 @@ if (convert_to_gray) {
// fprintf(stderr, "%p gray-washed\n", &fifo.total);
}
foo = post_process_picture(&g_fifo.total, postproc, 0.0);
foo = crapulator(&g_fifo.total, postproc, 0.0);
if (foo) {
fprintf(stderr, "ERR post process picture -> %d\n", foo);
fprintf(stderr, "%s: ERR post process picture -> %d\n",
__func__, foo);
return foo;
}

View File

@ -40,9 +40,8 @@ int create_fifo(int nbslot, int w, int h, int t);
* funcs in 'sfx.c'
*/
int brotche_rand48(FloatImg *fimg, float ratio, float mval);
int brotche_rand48_a(FloatImg *fimg, float ratio, float mval);
int brotche_rand48_b(FloatImg *fimg, float ratio, float mval);
int kill_colors_a(FloatImg *fimg, float fval);
int colors_brotcher(FloatImg *fimg, float fval);
/* -------------------------------------------------------------- */

View File

@ -12,9 +12,7 @@
#include "fonctions.h"
#include "crapulator.h"
int verbosity;
int convert_to_gray;
/* -------------------------------------------------------------- */
@ -27,17 +25,16 @@ char ligne[200];
/* here, we put the picz in the fifo machinery */
foo = insert_picture(image);
if (foo) {
fprintf(stderr, "%s : err %d on insert\n", __func__, foo);
fprintf(stderr, "%s: err %d on insert\n", __func__, foo);
return foo;
}
sprintf(ligne, "p8/%05d.png", numero);
foo = export_fifo(ligne, proc, step);
if (foo) {
fprintf(stderr, "%s : err %d on export\n", __func__, foo);
fprintf(stderr, "%s: err %d on export\n", __func__, foo);
return foo;
}
numero++; /* VERY IMPORTANT :) */
return 0;
@ -67,7 +64,7 @@ puts("");
return 0;
}
/* -------------------------------------------------------------- */
#define BLANK 30
#define BLANK 40
int demarre_la_machine(char *pattern, char *outdir, int szfifo,
int outfx, int step)
@ -110,7 +107,6 @@ for (idx=0; idx<globbuf.gl_pathc; idx++) {
/* first step : read the current grabed picz from disk,
and put it in our private buffer */
foo = fimg_load_from_dump(cptr, &input);
if (foo) {
fprintf(stderr, "load #%d from dump -> %d\n", idx, foo);
continue;
@ -118,8 +114,7 @@ for (idx=0; idx<globbuf.gl_pathc; idx++) {
/* ========================= */
/* FSCKING INPUT FILTER HERE */
foo = crapulator(&input, idx);
foo = crapulator(&input, 0, 0.42);
if (foo) {
fprintf(stderr, "%s crapulator -> %d\n", __func__, foo);
exit(1);
@ -148,26 +143,41 @@ else {
return 8;
}
/* -------------------------------------------------------------- */
void help(void)
{
puts("\tFONDERIE\noptions:");
puts("\t-g\tconvert to gray");
puts("\t-I\tinput glob pattern");
puts("\t-O\toutput directory");
puts("\t-T\tfifo size");
puts("\t-v\tincrease verbosity");
puts("\t-x\toutput effect");
exit(0);
}
/* -------------------------------------------------------------- */
int main (int argc, char *argv[])
{
int foo, opt;
int fifosize = 10;
char *in_pattern = "capture/?????.fimg";
char *out_dir = "p8";
int in_effect = 0;
int out_effect = 0;
int steps = 1;
// float maxlevel = 2500.0;
fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", argv[0],
__DATE__, __TIME__);
fimg_print_version(2);
while ((opt = getopt(argc, argv, "gI:O:s:T:vx:")) != -1) {
while ((opt = getopt(argc, argv, "ghI:O:s:T:vx:")) != -1) {
switch(opt) {
case 'g': convert_to_gray = 1;
break;
case 'h': help();
break;
case 'I': in_pattern = optarg;
break;
case 'O': out_dir = optarg;

View File

@ -15,11 +15,12 @@
/* -------------------------------------------------------------- */
/* global vars from main
*/
extern int verbosity;
extern int verbosity;
/* -------------------------------------------------------------- */
int brotche_rand48(FloatImg *fimg, float ratio, float mval)
/* -------------------------------------------------------------- */
int brotche_rand48_a(FloatImg *fimg, float ratio, float mval)
{
int nbpix, todo, foo;
int x, y;
@ -27,9 +28,10 @@ float fval;
nbpix = fimg->width * fimg->height;
todo = (int)((float)nbpix * ratio);
if (verbosity > 1)
fprintf(stderr, "ratio %f nbpix %d todo %d\n", ratio, nbpix, todo);
if (verbosity > 1) {
fprintf(stderr, "%s: ratio %f nbpix %d todo %d\n", __func__,
ratio, nbpix, todo);
}
for (foo=0; foo<todo; foo++)
{
@ -50,9 +52,8 @@ float fval;
nbpix = fimg->width * fimg->height;
todo = (int)((float)nbpix * ratio);
if (verbosity > 1) {
fprintf(stderr, "ratio %f nbpix %d todo %d\n",
fprintf(stderr, "%s: ratio %f nbpix %d todo %d\n", __func__,
ratio, nbpix, todo);
}
@ -69,33 +70,7 @@ for (foo=0; foo<todo; foo++)
return 0;
}
/* -------------------------------------------------------------- */
/*
* OMG ! a Color Graphic Adaptor emulator :)
*/
int kill_colors_a(FloatImg *fimg, float fval)
{
int nbpix, foo;
if (FIMG_TYPE_RGB != fimg->type) {
fprintf(stderr, "%s: bad src type %d on %p\n", __func__,
fimg->type, fimg);
return -8;
}
nbpix = fimg->width * fimg->height;
for (foo=0; foo<nbpix; foo++) {
if (fimg->R[foo] > fimg->G[foo])
fimg->B[foo] = fimg->R[foo];
else
fimg->B[foo] = fimg->G[foo];
}
return 0;
}
/* -------------------------------------------------------------- */
/* -------------------------------------------------------------- */