2020-11-02 11:25:00 +11:00
|
|
|
/*
|
|
|
|
* Fonctions de la Fonderie du Cumul
|
|
|
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
* Du code bien cracra / tTh / Tetalab
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
|
|
|
|
#include <floatimg.h>
|
|
|
|
|
|
|
|
#include "fonctions.h"
|
2020-11-03 00:51:48 +11:00
|
|
|
#include "crapulator.h"
|
2020-11-02 11:25:00 +11:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
/* global vars from main
|
|
|
|
*/
|
|
|
|
extern int verbosity;
|
|
|
|
|
|
|
|
/* private vars of this module - it was very dirty
|
|
|
|
*/
|
|
|
|
static A_Fifo g_fifo;
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int faire_la_somme(A_Fifo *pfifo, FloatImg *destination, int step)
|
|
|
|
{
|
|
|
|
int idx, foo;
|
|
|
|
FloatImg *pdest;
|
|
|
|
|
|
|
|
if (NULL==destination) {
|
|
|
|
pdest = &(pfifo->total); }
|
|
|
|
else {
|
|
|
|
pdest = destination; }
|
|
|
|
|
|
|
|
fimg_clear(pdest);
|
|
|
|
for (idx=0; idx<pfifo->nbslots; idx += step) {
|
|
|
|
foo = fimg_add_2(&(pfifo->slots[idx]), pdest);
|
|
|
|
if (foo)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: err %d on add_2\n", __func__, foo);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
/*
|
|
|
|
* this func save the fifo content as
|
|
|
|
* - float FIMG
|
|
|
|
* - 16 bits PNM
|
|
|
|
* - 8 bits PNG
|
|
|
|
*/
|
|
|
|
int export_fifo(char *fname, int postproc, int step)
|
|
|
|
{
|
|
|
|
int foo, type;
|
|
|
|
|
|
|
|
foo = faire_la_somme(&g_fifo, NULL, step);
|
|
|
|
|
|
|
|
/* BEGIN GRUIK CODE */
|
|
|
|
extern int convert_to_gray;
|
|
|
|
/* END OF THE KLUGE */
|
|
|
|
if (convert_to_gray) {
|
|
|
|
fimg_to_gray(&g_fifo.total);
|
|
|
|
// fprintf(stderr, "%p gray-washed\n", &fifo.total);
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:51:48 +11:00
|
|
|
foo = crapulator(&g_fifo.total, postproc, 0.0);
|
2020-11-02 11:25:00 +11:00
|
|
|
if (foo) {
|
2020-11-03 00:51:48 +11:00
|
|
|
fprintf(stderr, "%s: ERR post process picture -> %d\n",
|
|
|
|
__func__, foo);
|
2020-11-02 11:25:00 +11:00
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
type = format_from_extension(fname);
|
|
|
|
switch (type) {
|
|
|
|
case FILE_TYPE_PNG:
|
|
|
|
foo = fimg_save_as_png(&g_fifo.total, fname, 0);
|
|
|
|
break;
|
|
|
|
case FILE_TYPE_PNM:
|
|
|
|
foo = fimg_save_as_pnm(&g_fifo.total, fname, 0);
|
|
|
|
break;
|
|
|
|
case FILE_TYPE_FIMG:
|
|
|
|
foo = fimg_dump_to_file(&g_fifo.total, fname, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s : type of '%s' unknow\n",
|
|
|
|
__func__, fname);
|
|
|
|
foo = 888;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "ERR EXPORT '%s' is %d\n", fname, foo);
|
|
|
|
exit(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
int insert_picture(FloatImg *src)
|
|
|
|
{
|
|
|
|
FloatImg *dst;
|
|
|
|
int nbre;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this is the where we can insert the 'input filter'
|
|
|
|
*/
|
|
|
|
|
|
|
|
dst = &g_fifo.slots[g_fifo.next];
|
|
|
|
|
|
|
|
nbre = dst->width * dst->height * dst->type;
|
|
|
|
memcpy(dst->R, src->R, nbre*sizeof(float));
|
|
|
|
|
|
|
|
g_fifo.next++, g_fifo.next %= g_fifo.nbslots;
|
|
|
|
// maybe we can write :
|
|
|
|
// (++fifo.next) %= fifo.nbslots;
|
|
|
|
|
|
|
|
if (verbosity > 2) fprintf(stderr, "%s : next slot %d\n",
|
|
|
|
__func__, g_fifo.next);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
int create_fifo(int nbslot, int w, int h, int t)
|
|
|
|
{
|
|
|
|
int foo, idx;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %d %dx%d %d )\n", __func__,
|
|
|
|
nbslot, w, h, t);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
memset(&g_fifo, 0, sizeof(A_Fifo));
|
|
|
|
|
|
|
|
g_fifo.nbslots = nbslot;
|
|
|
|
|
|
|
|
g_fifo.slots = calloc(nbslot, sizeof(FloatImg));
|
|
|
|
if (NULL==g_fifo.slots) abort();
|
|
|
|
for (idx=0; idx<nbslot; idx++) {
|
|
|
|
foo = fimg_create(&g_fifo.slots[idx], w, h, t);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s idx %d err%d\n", __func__, idx, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foo = fimg_create(&g_fifo.total, w, h, t);
|
|
|
|
g_fifo.next = 0;
|
|
|
|
g_fifo.magic = MAGIC_FIFO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|