Compare commits

..

6 Commits

Author SHA1 Message Date
89c49282f1 Merge branch 'master' of ssh://tetalab.org:2213/tTh/FloatImg
OK
2020-11-04 17:19:15 +01:00
3859777c47 fonderie can now handle images of any size 2020-11-04 17:18:58 +01:00
e404781d98 minor tweaks 2020-11-04 10:42:02 +01:00
905022e782 modularizing the crapulator 2020-11-04 10:41:21 +01:00
f9a09871bf bla 2020-11-03 00:00:09 +01:00
b43a62db68 remove useless code 2020-11-02 22:58:38 +01:00
3 changed files with 74 additions and 53 deletions

View File

@ -11,24 +11,66 @@
#include "crapulator.h" #include "crapulator.h"
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
/* support function for the crapulator */
static int effect_3(FloatImg *image)
{
float value;
int foo;
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;
}
return 0;
}
/* -------------------------------------------------------------- */
static int insitu_ctr2x2(FloatImg *pimg)
{
FloatImg img;
int retval;
fimg_clone(pimg, &img, 0);
// XXX fimg_clear(&img);
retval = fimg_contour_2x2(pimg, &img, 0);
if (retval) {
fprintf(stderr, "%s : err contour %d\n",
__func__, retval);
exit(1);
}
fimg_copy_data(&img, pimg);
fimg_destroy(&img);
return 0;
}
/* -------------------------------------------------------------- */
/*
* This is the main filter engine
* used both for input and output
*/
int crapulator(FloatImg *image, int idFx, float fval) int crapulator(FloatImg *image, int idFx, float fval)
{ {
int retval, foo; int retval, foo;
FloatImg imgtmp; FloatImg imgtmp;
static int count = 0; static int count = 0;
int flag_debug = 0; int flag_debug = 0;
float value;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__, fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__,
image, idFx, fval); image, idFx, fval);
#endif #endif
retval = 0;
if (666==count) { if (666==count) {
flag_debug = 1; flag_debug = 1;
fprintf(stderr, "DEBUG PT 1 in %s:%d\n", __func__, __LINE__); fprintf(stderr, "DEBUG PT 1 in %s:%d\n", __func__, __LINE__);
fimg_save_as_png(image, "source.png", 0); fimg_save_as_png(image, "crap_before.png", 0);
} }
switch (idFx) { switch (idFx) {
@ -44,16 +86,7 @@ switch (idFx) {
fimg_get_maxvalue(image)); fimg_get_maxvalue(image));
break; break;
case 3: case 3:
value = fimg_get_maxvalue(image); retval = effect_3(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; break;
case 4: case 4:
brotche_rand48_a(image, 0.20, brotche_rand48_a(image, 0.20,
@ -72,26 +105,7 @@ switch (idFx) {
break; break;
case 8: case 8:
fimg_clone(image, &imgtmp, 0); retval = insitu_ctr2x2(image);
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; break;
case 9: case 9:
@ -110,7 +124,7 @@ switch (idFx) {
if (flag_debug) { if (flag_debug) {
fprintf(stderr, "DEBUG PT 2 in %s:%d\n", __func__, __LINE__); fprintf(stderr, "DEBUG PT 2 in %s:%d\n", __func__, __LINE__);
fimg_save_as_png(image, "after.png", 0); fimg_save_as_png(image, "crap_after.png", 0);
} }
count++; flag_debug = 0; count++; flag_debug = 0;

View File

@ -2,5 +2,13 @@
* crapulator.h * crapulator.h
*/ */
/*
* some constants for effect numbers */
/*
* the main function */
int crapulator(FloatImg *image, int id_effect, float fparam); int crapulator(FloatImg *image, int id_effect, float fparam);

View File

@ -28,19 +28,16 @@ if (foo) {
fprintf(stderr, "%s: err %d on insert\n", __func__, foo); fprintf(stderr, "%s: err %d on insert\n", __func__, foo);
return foo; return foo;
} }
sprintf(ligne, "p8/%05d.png", numero); sprintf(ligne, "p8/%05d.png", numero);
/* ^^^ /* ^^^
XXX hardcoded value ? wtf ? XXX hardcoded value ? wtf ?
*/ */
foo = export_fifo(ligne, proc, step); foo = export_fifo(ligne, proc, step);
if (foo) { if (foo) {
fprintf(stderr, "%s: err %d on export\n", __func__, foo); fprintf(stderr, "%s: err %d on export\n", __func__, foo);
return foo; return foo;
} }
numero++; /* VERY IMPORTANT :) */ numero++; /* VERY IMPORTANT :) */
return 0; return 0;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
@ -49,12 +46,9 @@ int insert_blank(FloatImg *image, int nbre, int pproc)
int idx, foo; int idx, foo;
fimg_clear(image); fimg_clear(image);
for (idx=0; idx<nbre; idx++) { for (idx=0; idx<nbre; idx++) {
fimg_vdeg_a(image, 16.64);
fimg_hdeg_a(image, 16.64); // brotche_rand48_b(image, drand48()*0.10, 1e5);
brotche_rand48_b(image, drand48()*0.10, 1e5);
if ((foo=traite_une_image(image, pproc, 1))) { if ((foo=traite_une_image(image, pproc, 1))) {
fprintf(stderr, "%s : err %d from 'traite_une_image'\n", fprintf(stderr, "%s : err %d from 'traite_une_image'\n",
__func__, foo); __func__, foo);
@ -62,7 +56,6 @@ for (idx=0; idx<nbre; idx++) {
} }
printf("\t%c\r", "ABCDEF"[idx%6]); fflush(stdout); printf("\t%c\r", "ABCDEF"[idx%6]); fflush(stdout);
} }
puts(""); puts("");
return 0; return 0;
@ -73,18 +66,19 @@ return 0;
int demarre_la_machine(char *pattern, char *outdir, int szfifo, int demarre_la_machine(char *pattern, char *outdir, int szfifo,
int infx, int outfx, int step) int infx, int outfx, int step)
{ {
int foo, idx; int foo, idx, width, height;
glob_t globbuf; glob_t globbuf;
char *cptr; char *cptr;
FloatImg input; FloatImg input;
double fin; double fin;
int datas[3];
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' -> '%s' %d )\n", __func__, fprintf(stderr, ">>> %s ( '%s' -> '%s' %d )\n", __func__,
pattern, outdir, szfifo); pattern, outdir, szfifo);
#endif #endif
fprintf(stderr, "\tstep is %d\n", step); if (1 != step) fprintf(stderr, "\tstep is %d\n", step);
(void)fimg_timer_set(0); (void)fimg_timer_set(0);
@ -93,19 +87,24 @@ else fprintf(stderr, "\tno in fx\n");
if (outfx) fprintf(stderr, "\tout fx #%d\n", outfx); if (outfx) fprintf(stderr, "\tout fx #%d\n", outfx);
else fprintf(stderr, "\tno out fx\n"); else fprintf(stderr, "\tno out fx\n");
foo = create_fifo(szfifo, 640, 480, FIMG_TYPE_RGB);
fprintf(stderr, "init fifo (%d slots) --> %d\n", szfifo, foo);
fimg_create(&input, 640, 480, 3);
/* XXX inject a few stange pics in the fifo */
insert_blank(&input, BLANK, outfx);
memset(&globbuf, 0, sizeof(glob_t)); memset(&globbuf, 0, sizeof(glob_t));
foo = glob(pattern, 0, NULL, &globbuf); foo = glob(pattern, 0, NULL, &globbuf);
fprintf(stderr, "glob '%s' -> %d, %ld files found\n", pattern, foo, fprintf(stderr, "glob '%s' -> %d, %ld files found\n", pattern, foo,
globbuf.gl_pathc); globbuf.gl_pathc);
/* get the size of the inputs images */
foo = fimg_fileinfos(globbuf.gl_pathv[0], datas);
width = datas[0];
height = datas[1];
foo = create_fifo(szfifo, width, height, FIMG_TYPE_RGB);
fprintf(stderr, "init fifo (%d slots) --> %d\n", szfifo, foo);
fimg_create(&input, width, height, 3);
/* XXX inject a few stange pics in the fifo */
insert_blank(&input, BLANK, outfx);
for (idx=0; idx<globbuf.gl_pathc; idx++) { for (idx=0; idx<globbuf.gl_pathc; idx++) {
cptr = globbuf.gl_pathv[idx]; cptr = globbuf.gl_pathv[idx];
@ -178,7 +177,7 @@ fprintf(stderr, "*** %s :\n\tcompiled by tTh, %s %s\n\tpid %d\n",
argv[0], __DATE__, __TIME__, getpid()); argv[0], __DATE__, __TIME__, getpid());
fimg_print_version(2); fimg_print_version(2);
while ((opt = getopt(argc, argv, "ghI:O:s:T:vx:")) != -1) { while ((opt = getopt(argc, argv, "ghI:O:s:T:vw:x:")) != -1) {
switch(opt) { switch(opt) {
case 'g': convert_to_gray = 1; case 'g': convert_to_gray = 1;