FloatImg4PythonBinding/Fonderie/crapulator.c

138 lines
2.6 KiB
C
Raw Normal View History

2020-11-02 01:25:00 +01:00
/*
* crapulator.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <floatimg.h>
2020-11-02 14:51:48 +01:00
#include "fonctions.h"
2020-11-02 01:25:00 +01:00
#include "crapulator.h"
2020-11-04 10:41:21 +01:00
/* -------------------------------------------------------------- */
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;
}
2020-11-02 01:25:00 +01:00
/* -------------------------------------------------------------- */
2020-11-03 00:00:09 +01:00
/*
* This is the main filter engine
* used both for input and output
*/
2020-11-02 14:51:48 +01:00
int crapulator(FloatImg *image, int idFx, float fval)
2020-11-02 01:25:00 +01:00
{
2020-11-05 21:07:38 +01:00
int retval;
// FloatImg imgtmp;
2020-11-02 14:51:48 +01:00
static int count = 0;
int flag_debug = 0;
2020-11-02 01:25:00 +01:00
#if DEBUG_LEVEL
2020-11-02 14:51:48 +01:00
fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__,
image, idFx, fval);
2020-11-02 01:25:00 +01:00
#endif
2020-11-03 00:00:09 +01:00
retval = 0;
2020-11-02 14:51:48 +01:00
if (666==count) {
flag_debug = 1;
2020-11-02 22:20:54 +01:00
fprintf(stderr, "DEBUG PT 1 in %s:%d\n", __func__, __LINE__);
2020-11-03 00:00:09 +01:00
fimg_save_as_png(image, "crap_before.png", 0);
2020-11-02 14:51:48 +01:00
}
switch (idFx) {
case 0: /* DO NOTHING */
retval = 0; 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:
2020-11-04 10:41:21 +01:00
retval = effect_3(image);
2020-11-02 14:51:48 +01:00
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:
2020-11-04 10:41:21 +01:00
retval = insitu_ctr2x2(image);
2020-11-02 14:51:48 +01:00
break;
case 9:
2020-11-02 22:20:54 +01:00
retval = fimg_classif_trial(image, image, 0.37, 0);
2020-11-02 14:51:48 +01:00
if (retval) {
fprintf(stderr, "err %d in classif\n", retval);
exit(1);
}
break;
2020-11-05 21:07:38 +01:00
case 10:
retval = binarize(image, 0);
break;
2020-11-10 00:50:25 +01:00
case 11:
retval = trinarize(image, 0);
break;
/* --- WTF -- */
2020-11-02 14:51:48 +01:00
default :
fprintf(stderr, "%s : effect #%d invalid\n",
__func__, idFx);
return -77;
}
2020-11-02 01:25:00 +01:00
2020-11-02 14:51:48 +01:00
if (flag_debug) {
2020-11-02 22:20:54 +01:00
fprintf(stderr, "DEBUG PT 2 in %s:%d\n", __func__, __LINE__);
2020-11-03 00:00:09 +01:00
fimg_save_as_png(image, "crap_after.png", 0);
2020-11-02 01:25:00 +01:00
}
2020-11-02 14:51:48 +01:00
count++; flag_debug = 0;
2020-11-02 01:25:00 +01:00
2020-11-02 14:51:48 +01:00
return retval;
2020-11-02 01:25:00 +01:00
}
/* -------------------------------------------------------------- */