Compare commits

..

No commits in common. "89c49282f18d27a86c17f61e1c3b3b76bb80820f" and "b4e68865b8afbbcb756200fb803c80c61c35bbf3" have entirely different histories.

3 changed files with 53 additions and 74 deletions

View File

@ -11,66 +11,24 @@
#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 retval, foo;
FloatImg imgtmp;
static int count = 0;
int flag_debug = 0;
float value;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__,
image, idFx, fval);
#endif
retval = 0;
if (666==count) {
flag_debug = 1;
fprintf(stderr, "DEBUG PT 1 in %s:%d\n", __func__, __LINE__);
fimg_save_as_png(image, "crap_before.png", 0);
fimg_save_as_png(image, "source.png", 0);
}
switch (idFx) {
@ -86,7 +44,16 @@ switch (idFx) {
fimg_get_maxvalue(image));
break;
case 3:
retval = effect_3(image);
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,
@ -105,7 +72,26 @@ switch (idFx) {
break;
case 8:
retval = insitu_ctr2x2(image);
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:
@ -124,7 +110,7 @@ switch (idFx) {
if (flag_debug) {
fprintf(stderr, "DEBUG PT 2 in %s:%d\n", __func__, __LINE__);
fimg_save_as_png(image, "crap_after.png", 0);
fimg_save_as_png(image, "after.png", 0);
}
count++; flag_debug = 0;

View File

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

View File

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