FloatImg/Fonderie/crapulator.c

123 lines
2.5 KiB
C
Raw Normal View History

2020-11-02 11:25:00 +11:00
/*
* crapulator.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <floatimg.h>
2020-11-03 00:51:48 +11:00
#include "fonctions.h"
2020-11-02 11:25:00 +11:00
#include "crapulator.h"
/* -------------------------------------------------------------- */
2020-11-03 00:51:48 +11:00
int crapulator(FloatImg *image, int idFx, float fval)
2020-11-02 11:25:00 +11:00
{
2020-11-03 00:51:48 +11:00
int retval, foo;
FloatImg imgtmp;
static int count = 0;
int flag_debug = 0;
float value;
2020-11-02 11:25:00 +11:00
#if DEBUG_LEVEL
2020-11-03 00:51:48 +11:00
fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__,
image, idFx, fval);
2020-11-02 11:25:00 +11:00
#endif
2020-11-03 00:51:48 +11:00
if (666==count) {
flag_debug = 1;
2020-11-03 08:20:54 +11:00
fprintf(stderr, "DEBUG PT 1 in %s:%d\n", __func__, __LINE__);
2020-11-03 00:51:48 +11:00
fimg_save_as_png(image, "source.png", 0);
}
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:
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:
2020-11-03 08:20:54 +11:00
retval = fimg_classif_trial(image, image, 0.37, 0);
2020-11-03 00:51:48 +11:00
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;
}
2020-11-02 11:25:00 +11:00
2020-11-03 00:51:48 +11:00
if (flag_debug) {
2020-11-03 08:20:54 +11:00
fprintf(stderr, "DEBUG PT 2 in %s:%d\n", __func__, __LINE__);
2020-11-03 00:51:48 +11:00
fimg_save_as_png(image, "after.png", 0);
2020-11-02 11:25:00 +11:00
}
2020-11-03 00:51:48 +11:00
count++; flag_debug = 0;
2020-11-02 11:25:00 +11:00
2020-11-03 00:51:48 +11:00
return retval;
2020-11-02 11:25:00 +11:00
}
/* -------------------------------------------------------------- */