forked from tTh/FloatImg
source tree refactor and build system (to be completed)
This commit is contained in:
73
extras/Fonderie/Makefile
Normal file
73
extras/Fonderie/Makefile
Normal file
@@ -0,0 +1,73 @@
|
||||
#
|
||||
# compilation de la fonderie, du crapulator
|
||||
# et de tout le crap...
|
||||
#
|
||||
|
||||
COPT = -g -fpic -no-pie -Wall -DDEBUG_LEVEL=0 -Werror=parentheses
|
||||
LIBS = ../libfloatimg.a -ltiff -lpnglite -lm -lz -lcfitsio
|
||||
|
||||
OBJS = fifo.o sfx.o crapulator.o glitches.o metriques.o \
|
||||
filterstack.o single.o
|
||||
|
||||
DEPS = ../floatimg.h \
|
||||
fifo.h crapulator.h metriques.h glitches.h sfx.h \
|
||||
filterstack.h crapdef.h crapstr.h single.h
|
||||
|
||||
all: fonderie interpolator singlepass t
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
t: t.c Makefile ${OBJS}
|
||||
gcc ${COPT} $< ${OBJS} ${LIBS} -o $@
|
||||
|
||||
# ---------------------------------------------------------
|
||||
#
|
||||
# the three main programms
|
||||
#
|
||||
|
||||
fonderie: fonderie.c ${DEPS} ${OBJS} Makefile
|
||||
gcc ${COPT} $< ${OBJS} ${LIBS} -lz -o $@
|
||||
|
||||
# another way to brotch some pics...
|
||||
interpolator: interpolator.c ${DEPS} ${OBJS} Makefile
|
||||
gcc ${COPT} $< ${OBJS} ${LIBS} -lz -o $@
|
||||
|
||||
singlepass: singlepass.c ${DEPS} ${OBJS} Makefile
|
||||
gcc ${COPT} $< ${OBJS} ${LIBS} -lz -o $@
|
||||
|
||||
# ---------------------------------------------------------
|
||||
#
|
||||
# some files are magically generated, sorry.
|
||||
#
|
||||
crapdef.h: crapulors.liste Makefile craplist2h.awk
|
||||
./craplist2h.awk < $< | tee $@
|
||||
|
||||
crapstr.h: crapulors.liste Makefile craplist2str.awk
|
||||
./craplist2str.awk < $< | tee $@
|
||||
|
||||
# ---------------------------------------------------------
|
||||
#
|
||||
# a lot of silly functions
|
||||
#
|
||||
crapulator.o: crapulator.c ${DEPS} Makefile
|
||||
gcc ${COPT} -c $<
|
||||
|
||||
fifo.o: fifo.c fifo.h Makefile
|
||||
gcc ${COPT} -c $<
|
||||
|
||||
sfx.o: sfx.c ${DEPS} Makefile
|
||||
gcc ${COPT} -c $<
|
||||
|
||||
single.o: single.c ${DEPS} Makefile
|
||||
gcc ${COPT} -c $<
|
||||
|
||||
filterstack.o: filterstack.c ${DEPS} Makefile
|
||||
gcc ${COPT} -c $<
|
||||
|
||||
metriques.o: metriques.c metriques.h Makefile
|
||||
gcc ${COPT} -c $<
|
||||
|
||||
glitches.o: glitches.c glitches.h Makefile
|
||||
gcc ${COPT} -c $<
|
||||
|
||||
# ---------------------------------------------------------
|
||||
141
extras/Fonderie/README.md
Normal file
141
extras/Fonderie/README.md
Normal file
@@ -0,0 +1,141 @@
|
||||
# Fonderie et Interpolator
|
||||
|
||||
Avec toutes ces fonctions disponibles et `grabvidseq`, nous
|
||||
savons faire des images **floues**. L'étape suivante, les plus
|
||||
pervers d'entre vous le savent déja, est celle de la création
|
||||
de **films flous** dans le domaine spacio-temporel.
|
||||
|
||||
À l'heure actuelle, il y a plusieurs programmes distincts. Le premier
|
||||
(fonderie) fait une moyenne mobile sur N images consécutives,
|
||||
et le second (interpolator) fait un fondu-enchainé de N pas
|
||||
entre deux images consécutives.
|
||||
|
||||
Mais avant et après un de ces deux traitements, il y a des chaines
|
||||
de filtres...
|
||||
|
||||
## Chaine de filtres
|
||||
|
||||
Ce système connait un certain nombre de filtres et d'effets spéciaux
|
||||
destinés à augmenter la kitchitude du produit final. Ils peuvent être chainés
|
||||
les uns après les autres, à l'entrée et à la sortie du process
|
||||
de floutagement.
|
||||
|
||||
Ces filtres ont chacun un nom et un numéro. que l'on peut (en théorie)
|
||||
utiliser indistinctement dans une chaine de filtres.
|
||||
L'option `-L` de ces logiciels permet d'obtenir la liste des filtres.
|
||||
|
||||
Une chaine de filtres est constituée d'une liste de nom ou de numéro
|
||||
de filtre, séparés par le caractère `:`, une façon de faire très
|
||||
classique dans notre univers, en fait. Et si on veut prendre des risques,
|
||||
on doit continuer à appeler les filtres par leur numéro, jdçjdr.
|
||||
|
||||
`mirsplit:ctr2x2:3:killlines`
|
||||
|
||||
Nous allons donc voir quelques exemples un peu plus loin.
|
||||
|
||||
## Fonderie
|
||||
|
||||
Le programme principal, utilisé à partir de la ligne de commande
|
||||
avec une foule d'options aux mnémoniques abscons et à la syntaxe
|
||||
perverse.
|
||||
|
||||
Rassurez-vous, en général il est wrappable dans des scripts
|
||||
écrits en Bash. Il est même possible un jour qu'ils puissent lire des
|
||||
paramètres dans `$(env)`.
|
||||
|
||||
```
|
||||
./fonderie, compiled Dec 30 2020, 14:09:18, pid 5013
|
||||
*** FloatImg library, alpha v116 (Dec 27 2020, 22:39:28)
|
||||
FONDERIE
|
||||
options:
|
||||
-E input:filter:chain
|
||||
-F output:filter:chain
|
||||
-g convert to gray
|
||||
-I input glob pattern
|
||||
-L list available filters
|
||||
-O output directory
|
||||
-T fifo size
|
||||
-v increase verbosity
|
||||
```
|
||||
|
||||
## exemple d'utilisation
|
||||
|
||||
Voici comment appeler cette machinerie depuis la ligne de commande
|
||||
tel qu'il m'arrive de le pratiquer :
|
||||
|
||||
```
|
||||
#!/bin/bash
|
||||
|
||||
GRABDIR="/spool/tth/fonderie"
|
||||
FONDEUR="$HOME/Devel/FloatImg/Fonderie/fonderie"
|
||||
GLOB=${GRABDIR}'/?????.fimg'
|
||||
|
||||
${FONDEUR} -I "$GLOB" -E cos01:25 -T 30 -F 2:classtrial
|
||||
```
|
||||
|
||||
Votre machine va maintenant mouliner avec entrain et persévérance,
|
||||
puis
|
||||
ensuite il suffit d'encoder toutes les images générées dans
|
||||
`p8/` (répertoire de sortie par défaut)
|
||||
avec une incantation de ffmpeg :
|
||||
|
||||
```
|
||||
ffmpeg -nostdin \
|
||||
-loglevel error \
|
||||
-y -r 30 -f image2 -i p8/%05d.png \
|
||||
-c:v libx264 -pix_fmt yuv420p \
|
||||
foo.mp4
|
||||
```
|
||||
|
||||
## crapulator.c
|
||||
|
||||
C'est dans ce module qu'est codé le moteur de filtrage, utilisé
|
||||
aussi bien en entrée qu'en sortie. Il est, à l'heure actuelle,
|
||||
assez rudimentaire, avec un paramétrage simpliste, et un manque
|
||||
criant de documentation...
|
||||
|
||||
Dans la même équipe, vous pouvez aussi aller contempler `glitches.c`
|
||||
pour voir le genre de traitement que l'on fait subir à nox pixels
|
||||
flottants.
|
||||
|
||||
## Interpolator
|
||||
|
||||
Un logiciel dont l'inspiration vient du passé et les améliorations
|
||||
d'une résidence à Terre-Blanque, ça ne peut pas être complètement
|
||||
malsain.
|
||||
|
||||
```
|
||||
*** interpolator.c : compiled by tTh, Jan 12 2021 16:18:58
|
||||
*** FloatImg library, alpha v116 (Dec 27 2020, 22:39:28)
|
||||
INTERPOLATOR
|
||||
usage:
|
||||
interpolator [options] <inglob> <outdir> <nbsteep>
|
||||
options:
|
||||
-S nn mysterious sort
|
||||
-E i:bla:k input filter chain
|
||||
-F name:j output filter chain
|
||||
-L list available filters
|
||||
-v increase verbosity
|
||||
```
|
||||
## Singlepass
|
||||
|
||||
Le monde à l'envers : pas de traitement inter-frames, mais par contre,
|
||||
on peut facilement tester une chaine de filtres sur une image unique.
|
||||
|
||||
```
|
||||
*** singlepass.c : compiled Mar 17 2021 11:21:45
|
||||
*** FloatImg library, alpha 122 (Mar 16 2021, 18:44:00)
|
||||
------ Single pass serial filter ------
|
||||
usage:
|
||||
-F define:the:filter:chain
|
||||
-g input glob pattern
|
||||
-L list available filters
|
||||
-O /output/directory
|
||||
-v spit more messages
|
||||
```
|
||||
|
||||
## Conclusion
|
||||
|
||||
|
||||
**Use the source, Luke**
|
||||
|
||||
23
extras/Fonderie/craplist2h.awk
Executable file
23
extras/Fonderie/craplist2h.awk
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/awk -f
|
||||
|
||||
#
|
||||
# this utility script make a file who
|
||||
# is includet by 'crapulator.h'
|
||||
#
|
||||
|
||||
BEGIN {
|
||||
print "// -----------------------------------"
|
||||
print "// generated file, do not edit by hand !"
|
||||
print "// -----------------------------------"
|
||||
}
|
||||
|
||||
# $1 is the badly brain-designed numeric id
|
||||
# $2 is the user name of the filter
|
||||
|
||||
{
|
||||
printf "#define CR_%s (%d)\n", $2, $1
|
||||
}
|
||||
|
||||
END {
|
||||
print "// generated file, do not edit by hand !"
|
||||
}
|
||||
27
extras/Fonderie/craplist2str.awk
Executable file
27
extras/Fonderie/craplist2str.awk
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/awk -f
|
||||
|
||||
#
|
||||
# this utility script make a file who
|
||||
# is includet by 'crapulator.c'
|
||||
#
|
||||
BEGIN {
|
||||
print "// -----------------------------------"
|
||||
print "// generated file, do not edit by hand";
|
||||
print "// -----------------------------------"
|
||||
print "Crapulor CrapL[] = {";
|
||||
}
|
||||
|
||||
# $1 is the badly brain-designed numeric id
|
||||
# $2 is the user name of the filter
|
||||
# $3 and $4 are two not used parameters
|
||||
#
|
||||
{
|
||||
printf " { CR_%s, \"%s\", %d, %f }, // id=%d\n",
|
||||
$2, $2, $3, $4, $1;
|
||||
}
|
||||
|
||||
END {
|
||||
print " { -1, NULL }"
|
||||
print " };"
|
||||
print "// generated file, do not edit by hand"
|
||||
}
|
||||
401
extras/Fonderie/crapulator.c
Normal file
401
extras/Fonderie/crapulator.c
Normal file
@@ -0,0 +1,401 @@
|
||||
/*
|
||||
* crapulator.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
#include "fifo.h"
|
||||
#include "crapulator.h"
|
||||
#include "glitches.h"
|
||||
#include "sfx.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
static int trier_les_pixels(FloatImg *pimg)
|
||||
{
|
||||
FloatImg copy;
|
||||
int foo;
|
||||
|
||||
fimg_clone(pimg, ©, 1);
|
||||
|
||||
foo = fimg_qsort_rgb_a(pimg, ©, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err qsort rgb = %d\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
incrustation_vignette(pimg, ©, 0);
|
||||
|
||||
fimg_copy_data(©, pimg);
|
||||
|
||||
fimg_destroy(©);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
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);
|
||||
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;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
static int insitu_filtre3x3(FloatImg *pimg, int typef)
|
||||
{
|
||||
FloatImg img;
|
||||
int foo, retval;
|
||||
FimgFilter3x3 *pfiltre;
|
||||
|
||||
FimgFilter3x3 lowpass = {
|
||||
{
|
||||
1.0, 2.0, 1.0,
|
||||
2.0, 4.0, 2.0,
|
||||
1.0, 2.0, 1.0,
|
||||
},
|
||||
16.0, 0.0
|
||||
};
|
||||
|
||||
FimgFilter3x3 hipass = {
|
||||
{
|
||||
-1.0, -1.0, -1.0,
|
||||
-1.0, 9.0, -1.0,
|
||||
-1.0, -1.0, -1.0,
|
||||
},
|
||||
1.0, 0.0
|
||||
};
|
||||
|
||||
FimgFilter3x3 diagonal = {
|
||||
{
|
||||
2.0, 1.0, 0.0,
|
||||
1.0, 0.0, -1.0,
|
||||
0.0, -1.0, -2.0,
|
||||
},
|
||||
1.0, 0.0
|
||||
};
|
||||
|
||||
switch (typef) {
|
||||
case 0: pfiltre = &lowpass; break;
|
||||
case 1: pfiltre = &hipass; break;
|
||||
case 2: pfiltre = &diagonal; break;
|
||||
default:
|
||||
fprintf(stderr, "%s: bad filter number %d\n",
|
||||
__func__, typef);
|
||||
return -6;
|
||||
break;
|
||||
}
|
||||
|
||||
fimg_clone(pimg, &img, 0);
|
||||
|
||||
retval = fimg_filter_3x3(pimg, &img, pfiltre);
|
||||
if (retval) {
|
||||
fprintf(stderr, "%s error %d on filter\n", __func__, retval);
|
||||
exit(1);
|
||||
}
|
||||
(void)fimg_killborders(&img); /* nice try ? */
|
||||
|
||||
foo = fimg_auto_shift_to_zero(&img, &img);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d zero shift\n", __func__, foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/** may be, we can check for negative values ? */
|
||||
/** or is this useless because whe have shifted to zero ? */
|
||||
if (verbosity > 1) {
|
||||
foo = fimg_count_negativ(&img);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s -> %d / %d negative pixels\n", __func__,
|
||||
foo, img.width*img.height);
|
||||
}
|
||||
}
|
||||
|
||||
fimg_killborders(&img);
|
||||
fimg_copy_data(&img, pimg);
|
||||
fimg_destroy(&img);
|
||||
|
||||
return retval;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* This is the main filter engine used both for input and
|
||||
* output processing. It can be called by the filterstack
|
||||
* processor.
|
||||
*/
|
||||
|
||||
#define DEBUG_THIS_CRAP 0
|
||||
|
||||
int crapulator(FloatImg *image, int idFx, float fval)
|
||||
{
|
||||
int retval;
|
||||
// FloatImg imgtmp;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__,
|
||||
image, idFx, fval);
|
||||
#endif
|
||||
|
||||
#if DEBUG_THIS_CRAP
|
||||
static int count = 0;
|
||||
int flag_debug = 0;
|
||||
if (DEBUG_THIS_CRAP==count) {
|
||||
flag_debug = 1;
|
||||
fprintf(stderr, "DEBUG PT 1 in %s:%d\n", __func__, __LINE__);
|
||||
fimg_save_as_png(image, "crap_before.png", 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
retval = 0;
|
||||
|
||||
switch (idFx) {
|
||||
case CR_none: /* DO NOTHING */
|
||||
retval = 0;
|
||||
break;
|
||||
|
||||
case CR_cos01:
|
||||
fimg_cos_01(image, image,
|
||||
fimg_get_maxvalue(image));
|
||||
break;
|
||||
case CR_cos010:
|
||||
fimg_cos_010(image, image,
|
||||
fimg_get_maxvalue(image));
|
||||
break;
|
||||
case CR_fx3:
|
||||
retval = effect_3(image);
|
||||
break;
|
||||
case CR_rnd48a:
|
||||
brotche_rand48_a(image, 0.20,
|
||||
fimg_get_maxvalue(image));
|
||||
break;
|
||||
case CR_rnd48b:
|
||||
brotche_rand48_b(image, 0.10,
|
||||
fimg_get_maxvalue(image)*0.8);
|
||||
break;
|
||||
case CR_killcola:
|
||||
retval = fimg_killcolors_a(image, 0.0);
|
||||
break;
|
||||
case CR_colmixa:
|
||||
retval = fimg_colors_mixer_a(image, 2.0);
|
||||
break;
|
||||
case CR_ctr2x2:
|
||||
retval = insitu_ctr2x2(image);
|
||||
break;
|
||||
case CR_classtrial:
|
||||
retval = fimg_classif_trial(image, image, 0.37, 0);
|
||||
break;
|
||||
case CR_binarize:
|
||||
retval = fimg_binarize(image, 0);
|
||||
break;
|
||||
case CR_trinarize:
|
||||
retval = fimg_trinarize(image, 0);
|
||||
break;
|
||||
case CR_liss2x2:
|
||||
retval = fimg_lissage_2x2(image);
|
||||
// (void)fimg_killborders(image);
|
||||
break;
|
||||
case CR_liss3x3:
|
||||
/* smooth filter */
|
||||
retval = insitu_filtre3x3(image, 0);
|
||||
break;
|
||||
case CR_desaturate:
|
||||
retval = fimg_desaturate(image, image, 0);
|
||||
break;
|
||||
case CR_killlines:
|
||||
retval = kill_a_few_lines(image, fval,
|
||||
image->height/19);
|
||||
break;
|
||||
case CR_water:
|
||||
retval = bouger_les_pixels(image, 12);
|
||||
break;
|
||||
case CR_mirsplit:
|
||||
retval = mirror_split(image, 0);
|
||||
break;
|
||||
case CR_updown:
|
||||
retval = upside_down(image);
|
||||
break;
|
||||
case CR_hipass:
|
||||
/* hipass filter */
|
||||
retval = insitu_filtre3x3(image, 1);
|
||||
break;
|
||||
case CR_diagonal:
|
||||
retval = insitu_filtre3x3(image, 2);
|
||||
break;
|
||||
case CR_octotree:
|
||||
retval = octotree_classif(image, 0.500, 0);
|
||||
break;
|
||||
|
||||
case CR_trinitron:
|
||||
retval = trinitron(image, 0);
|
||||
break;
|
||||
|
||||
case CR_sqrt:
|
||||
retval = fimg_square_root(image, image, 1000.0);
|
||||
break;
|
||||
case CR_pow2:
|
||||
retval = fimg_power_2(image, image, 1000.0);
|
||||
break;
|
||||
|
||||
/* here are the glitches */
|
||||
case CR_bsombra: /* experiment ! */
|
||||
retval = des_bords_sombres_a(image, 160);
|
||||
break;
|
||||
case CR_bsombrb: /* experiment ! */
|
||||
retval = des_bords_sombres_b(image, 160);
|
||||
break;
|
||||
case CR_vsglitch:
|
||||
/* please make this function more tweakable */
|
||||
retval = vertical_singlitch(image, 290+rand()%45,
|
||||
fval, 0.19, 0);
|
||||
break;
|
||||
|
||||
case CR_rndblks:
|
||||
retval = random_blocks(image, 70);
|
||||
break;
|
||||
|
||||
case CR_shiftln0:
|
||||
retval = multilines_shift_0(image, 11, 120);
|
||||
break;
|
||||
|
||||
case CR_qsortrgb:
|
||||
retval = trier_les_pixels(image);
|
||||
break;
|
||||
|
||||
case CR_multidots:
|
||||
retval = plot_multidots(image, 42);
|
||||
break;
|
||||
|
||||
case CR_message:
|
||||
fprintf(stderr, "### msg from pid %d, fval=%f ###\n",
|
||||
getpid(), fval);
|
||||
/* here, we can display stats ! */
|
||||
fimg_describe(image, "in crapulator");
|
||||
retval = 0;
|
||||
break;
|
||||
|
||||
case CR_nothing:
|
||||
retval = do_something(image, 3);
|
||||
break;
|
||||
|
||||
case CR_hilightr:
|
||||
retval = fimg_highlight_color(image, image, 'R', 1.717);
|
||||
break;
|
||||
|
||||
default :
|
||||
fprintf(stderr, "%s : effect #%d invalid\n",
|
||||
__func__, idFx);
|
||||
return -77;
|
||||
}
|
||||
|
||||
#if DEBUG_THIS_CRAP
|
||||
if (flag_debug) {
|
||||
fprintf(stderr, "DEBUG PT 2 in %s:%d\n", __func__, __LINE__);
|
||||
fimg_save_as_png(image, "crap_after.png", 0);
|
||||
flag_debug = 0;
|
||||
}
|
||||
count++;
|
||||
#endif
|
||||
|
||||
return retval;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
typedef struct {
|
||||
int id;
|
||||
char *name;
|
||||
int ipar;
|
||||
float fpar;
|
||||
int flags;
|
||||
} Crapulor;
|
||||
|
||||
/* Warning: overengeniring inside */
|
||||
#include "crapstr.h" /* generated file ! */
|
||||
#define NBCRAP (sizeof(CrapL)/sizeof(Crapulor))
|
||||
|
||||
void list_crapulors(char *texte)
|
||||
{
|
||||
int idx;
|
||||
|
||||
#define OUT stdout
|
||||
fprintf(OUT, "______________. %s\n", texte);
|
||||
for (idx=0; CrapL[idx].id!=-1; idx++) {
|
||||
fprintf(OUT, " %-12s | %4d | %5d | %8.3f\n",
|
||||
CrapL[idx].name,
|
||||
CrapL[idx].id,
|
||||
CrapL[idx].ipar,
|
||||
CrapL[idx].fpar);
|
||||
}
|
||||
#undef OUT
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
char * crap_name_from_number(int num)
|
||||
{
|
||||
int idx;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %d )\n", __func__, num);
|
||||
#endif
|
||||
|
||||
for (idx=0; CrapL[idx].id!=-1; idx++) {
|
||||
if (num == CrapL[idx].id) {
|
||||
return CrapL[idx].name;
|
||||
}
|
||||
}
|
||||
|
||||
return "???";
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int crap_number_from_name(char *name)
|
||||
{
|
||||
int idx, retval;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, name);
|
||||
#endif
|
||||
|
||||
retval = -1; /* not found */
|
||||
for (idx=0; CrapL[idx].id!=-1; idx++) {
|
||||
if (0 == strcmp(CrapL[idx].name, name)) {
|
||||
// fprintf(stderr, "found '%s' -> %d\n", name,
|
||||
// CrapL[idx].id);
|
||||
retval = CrapL[idx].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return retval; /* not found */
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
21
extras/Fonderie/crapulator.h
Normal file
21
extras/Fonderie/crapulator.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* crapulator.h
|
||||
*/
|
||||
|
||||
/*
|
||||
* the main function */
|
||||
|
||||
int crapulator(FloatImg *image, int id_effect, float fparam);
|
||||
|
||||
/*
|
||||
* naming system */
|
||||
void list_crapulors(char *texte);
|
||||
char *crap_name_from_number(int num);
|
||||
int crap_number_from_name(char *name);
|
||||
|
||||
/*
|
||||
* this generated file contains the #define
|
||||
* for symbolic name of effect ids.
|
||||
*/
|
||||
#include "crapdef.h"
|
||||
|
||||
36
extras/Fonderie/crapulors.liste
Normal file
36
extras/Fonderie/crapulors.liste
Normal file
@@ -0,0 +1,36 @@
|
||||
0 none 1 1.0
|
||||
1 cos01 1 1.0
|
||||
2 cos010 1 1.0
|
||||
3 fx3 1 1.0
|
||||
4 rnd48a 1 1.0
|
||||
5 rnd48b 1 1.0
|
||||
6 killcola 1 1.0
|
||||
7 colmixa 1 1.0
|
||||
8 ctr2x2 1 1.0
|
||||
9 classtrial 1 1.0
|
||||
10 binarize 1 1.0
|
||||
11 trinarize 1 1.0
|
||||
12 liss2x2 1 1.0
|
||||
13 liss3x3 1 1.0
|
||||
14 desaturate 1 1.0
|
||||
15 killlines 1 1.0
|
||||
16 water 1 1.0
|
||||
17 mirsplit 1 1.0
|
||||
18 updown 1 1.0
|
||||
19 hipass 1 1.0
|
||||
20 octotree 1 1.0
|
||||
21 trinitron 3 0.0
|
||||
22 sqrt 1 0.0
|
||||
23 pow2 1 0.0
|
||||
24 bsombra 1 1.0
|
||||
25 bsombrb 1 1.0
|
||||
26 rndblks 1 1.0
|
||||
27 shiftln0 1 1.0
|
||||
28 qsortrgb 2 1.0
|
||||
30 multidots 100 1.333
|
||||
31 diagonal 1 1.0
|
||||
32 vsglitch 1 1.0
|
||||
42 nothing 42 3.1415926
|
||||
45 hilightr 1 1.717
|
||||
99 message 1 1.0
|
||||
-1 end 1 1.0
|
||||
59
extras/Fonderie/essai.sh
Executable file
59
extras/Fonderie/essai.sh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
# ------------------------------------------------------------
|
||||
essai_filtres ()
|
||||
{
|
||||
FILTRES=$(./t -L | awk 'NR>1 { print $1 }' | sort)
|
||||
|
||||
rm /tmp/fstack*.png
|
||||
|
||||
SRC=$(ls -rt1 $HOME/Essais/FondageDePlomb/capture/* | tail -1)
|
||||
# SRC=mire.fimg
|
||||
|
||||
for F in $FILTRES
|
||||
do
|
||||
I="/tmp/fstack-"$F".png"
|
||||
echo ; echo ======== $I
|
||||
./t -v -i $SRC -F $F -o foo.png
|
||||
txt=$(printf "( %-10s )" $F)
|
||||
convert foo.png -pointsize 48 -kerning 0 \
|
||||
-fill Gray80 -undercolor Gray20 \
|
||||
-font Courier-Bold \
|
||||
-annotate +10+50 "$txt" \
|
||||
$I
|
||||
done
|
||||
|
||||
echo ; echo "making gif89a..."
|
||||
convert -delay 200 /tmp/fstack*.png foo.gif
|
||||
}
|
||||
# ------------------------------------------------------------
|
||||
essai_singlepass ()
|
||||
{
|
||||
MP4="/home/tth/Essais/FondageDePlomb/foo.mp4"
|
||||
INPUT="/home/tth/Essais/FondageDePlomb/capture/02[0123]??.fimg"
|
||||
FILTRE="multidots:liss3x3:nothing:liss3x3:liss3x3"
|
||||
OUTDIR="/tmp/x8/"
|
||||
|
||||
echo '********* essai single *********'
|
||||
|
||||
rm $OUTDIR/*.png
|
||||
|
||||
time ./singlepass -v -g "$INPUT" -F $FILTRE -O $OUTDIR -s
|
||||
|
||||
echo ; echo "encoding picz to " $MP4
|
||||
|
||||
ffmpeg -nostdin \
|
||||
-loglevel error \
|
||||
-y -r 25 -f image2 -i /tmp/x8/%05d.png \
|
||||
-c:v libx264 -pix_fmt yuv420p \
|
||||
$MP4
|
||||
|
||||
}
|
||||
# ------------------------------------------------------------
|
||||
# MAIN
|
||||
|
||||
essai_filtres
|
||||
|
||||
# ------------------------------------------------------------
|
||||
197
extras/Fonderie/fifo.c
Normal file
197
extras/Fonderie/fifo.c
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* 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 "fifo.h"
|
||||
#include "crapulator.h"
|
||||
#include "filterstack.h"
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* global vars from main
|
||||
*/
|
||||
extern int verbosity;
|
||||
|
||||
/* private vars of this module - it was very dirty,
|
||||
* but simple and efficient.
|
||||
*/
|
||||
static A_Fifo g_fifo;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
static int big_adder(FloatImg *from, FloatImg *to)
|
||||
{
|
||||
int size, idx;
|
||||
|
||||
size = from->width * from->height;
|
||||
|
||||
for (idx=0; idx<size; idx++) to->R[idx] += from->R[idx];
|
||||
for (idx=0; idx<size; idx++) to->G[idx] += from->G[idx];
|
||||
for (idx=0; idx<size; idx++) to->B[idx] += from->B[idx];
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* 97% of the total run time was in that function \o_
|
||||
*/
|
||||
int faire_la_somme(A_Fifo *pfifo, FloatImg *destination, int step)
|
||||
{
|
||||
int idx, foo;
|
||||
FloatImg *pdest;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
|
||||
pfifo, destination, step);
|
||||
#endif
|
||||
|
||||
if (step<1){
|
||||
fprintf(stderr, "***** %s invalid step %d\n", __func__, step);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (NULL==destination) {
|
||||
pdest = &(pfifo->total); }
|
||||
else {
|
||||
pdest = destination; }
|
||||
|
||||
fimg_clear(pdest);
|
||||
|
||||
for (idx=0; idx<pfifo->nbslots; idx += step) {
|
||||
|
||||
foo = big_adder(&(pfifo->slots[idx]), pdest);
|
||||
if (foo)
|
||||
{
|
||||
fprintf(stderr, "%s: err %d on add_2\n", __func__, foo);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
fprintf(stderr, "*** %s:%s writing debugB file ***\n",
|
||||
__FILE__, __func__);
|
||||
fimg_dump_to_file(&g_fifo.total, "debugB.fimg", 0);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* called by 'fonderie.c'
|
||||
*/
|
||||
int export_fifo(char *fname, int notused)
|
||||
{
|
||||
int foo, type;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, step);
|
||||
#endif
|
||||
|
||||
foo = faire_la_somme(&g_fifo, NULL, 1);
|
||||
|
||||
foo = filterstack_run(1, &g_fifo.total, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: ERR post process picture -> %d\n",
|
||||
__func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
#if 0
|
||||
fimg_dump_to_file(&g_fifo.total, "outputXXX.fimg", 0);
|
||||
#endif
|
||||
|
||||
foo = fimg_export_picture(&g_fifo.total, fname, 0);
|
||||
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, foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p )\n", __func__, src);
|
||||
#endif
|
||||
|
||||
dst = &g_fifo.slots[g_fifo.next];
|
||||
|
||||
nbre = dst->width * dst->height * sizeof(float);
|
||||
memcpy(dst->R, src->R, nbre);
|
||||
memcpy(dst->G, src->G, nbre);
|
||||
memcpy(dst->B, src->B, nbre);
|
||||
|
||||
/* XXX
|
||||
fprintf(stderr, "*** %s:%s writing debugA file ***\n",
|
||||
__FILE__, __func__);
|
||||
foo = fimg_dump_to_file(dst, "debugA.fimg", 0);
|
||||
fprintf(stderr, " ok file dumped %d\n", foo);
|
||||
XXX */
|
||||
|
||||
g_fifo.next++; g_fifo.next %= g_fifo.nbslots;
|
||||
|
||||
if (verbosity > 2) fprintf(stderr, "%s : next slot %d\n",
|
||||
__func__, g_fifo.next);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* this function must have a lot of new parameters,
|
||||
* -- filetype of exported pictures...
|
||||
*/
|
||||
|
||||
int create_fifo(int nbslot, int w, int h, int imgtype)
|
||||
{
|
||||
int foo, idx;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %d %dx%d %d )\n", __func__,
|
||||
nbslot, w, h, imgtype);
|
||||
#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, imgtype);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s idx %d err%d\n", __func__, idx, foo);
|
||||
return foo;
|
||||
}
|
||||
fimg_clear(&g_fifo.slots[idx]);
|
||||
}
|
||||
foo = fimg_create(&g_fifo.total, w, h, imgtype);
|
||||
g_fifo.next = 0;
|
||||
g_fifo.magic = MAGIC_FIFO;
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* omfg ! I've write a setter !
|
||||
*/
|
||||
int set_fifo_output_format(int filetype)
|
||||
{
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %d )\n", __func__, filetype);
|
||||
#endif
|
||||
|
||||
g_fifo.export_type = filetype;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
49
extras/Fonderie/fifo.h
Normal file
49
extras/Fonderie/fifo.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Machine qui fait des fils flous par la
|
||||
* méthode de la moyenne mobile.
|
||||
*/
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
typedef struct {
|
||||
unsigned long magic;
|
||||
int nbslots; /* how many pics used ? */
|
||||
|
||||
FloatImg total; /* computing workspace */
|
||||
FloatImg wspace; /* computing workspace */
|
||||
|
||||
FloatImg *slots; /* circular buffer */
|
||||
|
||||
int next; /* incremented with modulo */
|
||||
|
||||
int export_type; /* fimg/png/pnm/... */
|
||||
} A_Fifo;
|
||||
|
||||
#define MAGIC_FIFO 0xabcd9876
|
||||
|
||||
typedef struct {
|
||||
unsigned long magic;
|
||||
|
||||
int blanks; /* ???? */
|
||||
float fk;
|
||||
int preproc, postproc;
|
||||
|
||||
int step; /* for fifo export */
|
||||
|
||||
} ControlBloc;
|
||||
|
||||
#define MAGIC_CTRLB 0xabcdfefe
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
int create_fifo(int nbslot, int w, int h, int t);
|
||||
int set_fifo_output_format(int filetype);
|
||||
|
||||
int export_fifo(char *fname, int notused);
|
||||
|
||||
int insert_picture(FloatImg *src);
|
||||
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* funcs in 'sfx.c' ---> sfx.h
|
||||
*/
|
||||
242
extras/Fonderie/filterstack.c
Normal file
242
extras/Fonderie/filterstack.c
Normal file
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
* filterstack.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <alloca.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
#include "crapulator.h"
|
||||
#include "filterstack.h"
|
||||
|
||||
// #undef DEBUG_LEVEL
|
||||
// #define DEBUG_LEVEL 1
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
static FilterStack f_stacks[NUMBER_OF_STACK];
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
int filterstack_init(int numid, int notused)
|
||||
{
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %d %d )\n", __func__, numid, notused);
|
||||
#endif
|
||||
|
||||
if (numid < 0 || numid > NUMBER_OF_STACK) {
|
||||
fprintf(stderr, "%s: slot number %d is invalid\n", __func__, numid);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
memset(&f_stacks[numid], 0, sizeof(FilterSlot));
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int filterstack_add(int numid, int code, int ival, float fval)
|
||||
{
|
||||
int idxsl;
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %d %d %f )\n", __func__, code, ival, fval);
|
||||
#endif
|
||||
|
||||
if (numid < 0 || numid > NUMBER_OF_STACK) {
|
||||
fprintf(stderr, "%s: slot number %d is invalid\n", __func__, numid);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (f_stacks[numid].count == FILTER_BY_STACK) {
|
||||
fprintf(stderr, "%s: stack is full\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
idxsl = f_stacks[numid].count; /* aliasing */
|
||||
|
||||
f_stacks[numid].slots[idxsl].numero = code;
|
||||
f_stacks[numid].slots[idxsl].ival = ival;
|
||||
f_stacks[numid].slots[idxsl].fval = fval;
|
||||
|
||||
f_stacks[numid].count++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int filterstack_list(int numid, const char *txt)
|
||||
{
|
||||
int idx;
|
||||
|
||||
if (numid < 0 || numid > NUMBER_OF_STACK) {
|
||||
fprintf(stderr, "%s: slot number %d is invalid\n", __func__, numid);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "---- %2d ---- %-20s -----------\n", numid, txt);
|
||||
// fprintf(stderr, "stack at %p, size %d, current %d\n",
|
||||
// f_slots, nbre_filters, idx_slot);
|
||||
fprintf(stderr, "idx ___ fx# _ name ________ ival _ fval ___\n");
|
||||
|
||||
for (idx=0; idx<f_stacks[numid].count; idx++) {
|
||||
|
||||
fprintf(stderr, "%3d %3d %-10s %3d %f\n", idx,
|
||||
f_stacks[numid].slots[idx].numero,
|
||||
crap_name_from_number(f_stacks[numid].slots[idx].numero),
|
||||
f_stacks[numid].slots[idx].ival,
|
||||
f_stacks[numid].slots[idx].fval);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int filterstack_run(int numid, FloatImg *target, int notused)
|
||||
{
|
||||
int idx, foo, eff;
|
||||
float fv;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, target, notused);
|
||||
#endif
|
||||
|
||||
if (numid < 0 || numid > NUMBER_OF_STACK) {
|
||||
fprintf(stderr, "%s: slot number %d is invalid\n", __func__, numid);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (0==f_stacks[numid].count) {
|
||||
fprintf(stderr, "%s: stack %d empty ?\n", __func__, numid);
|
||||
return -11;
|
||||
}
|
||||
|
||||
for (idx=0; idx<f_stacks[numid].count; idx++) {
|
||||
|
||||
eff = f_stacks[numid].slots[idx].numero;
|
||||
fv = f_stacks[numid].slots[idx].fval;
|
||||
|
||||
if (verbosity > 1)
|
||||
fprintf(stderr, "stack %d idx %d : effect %2d on %p\n",
|
||||
numid, idx, eff, target);
|
||||
|
||||
foo = crapulator(target, eff, fv);
|
||||
|
||||
if (foo) {
|
||||
fprintf(stderr,
|
||||
"crapulator give me error %d on effect %d (%s)\n",
|
||||
foo, eff,
|
||||
crap_name_from_number(eff));
|
||||
return foo;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int load_stack_from_file(int numid, char *fname, int notused)
|
||||
{
|
||||
FILE *fp;
|
||||
// int a, b;
|
||||
// float f;
|
||||
// char line[100];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused);
|
||||
#endif
|
||||
|
||||
if (numid < 0 || numid > NUMBER_OF_STACK) {
|
||||
fprintf(stderr, "%s: slot number %d is invalid\n", __func__, numid);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (NULL==(fp=fopen(fname, "r"))) {
|
||||
perror(fname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* here was dragons
|
||||
*/
|
||||
/* hadoc parser ? */
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int parse_filter_chain(int numid, char *argument)
|
||||
{
|
||||
char *cptr, *tmparg;
|
||||
int value, foo;
|
||||
|
||||
if (numid < 0 || numid > NUMBER_OF_STACK) {
|
||||
fprintf(stderr, "%s: slot number %d is invalid\n", __func__, numid);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "\n%s: arg = '%s'\n", __func__, argument);
|
||||
#endif
|
||||
|
||||
foo = filterstack_init(numid, 8);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: filterstack init --> %d\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
/* BUG ?
|
||||
If the 'argument' string is coming from a default value (as defined
|
||||
here in main), strtok make a nice segfault. so I make a copy of that
|
||||
string...
|
||||
*/
|
||||
tmparg = alloca(strlen(argument) + 1);
|
||||
if (NULL==tmparg) {
|
||||
fprintf(stderr, "memory panic in %s:%s\n", __FILE__, __func__);
|
||||
exit(1);
|
||||
}
|
||||
strcpy(tmparg, argument);
|
||||
|
||||
for (;;) {
|
||||
cptr = strtok(tmparg, ":");
|
||||
// fprintf(stderr, "cptr %p\n", cptr);
|
||||
if (NULL==cptr) break;
|
||||
tmparg = NULL; /* for the next pass of strtok */
|
||||
// fprintf(stderr, " parsing '%s'\n", cptr);
|
||||
|
||||
if (isalpha(*cptr)) {
|
||||
value = crap_number_from_name(cptr);
|
||||
// fprintf(stderr, "%s: '%s' -> %d\n", __func__,
|
||||
// cptr, value);
|
||||
if (value < 0) {
|
||||
fprintf(stderr, "%s: '%s' not found\n",
|
||||
__func__, cptr);
|
||||
return -1;
|
||||
}
|
||||
foo = filterstack_add(numid, value, 1, 1.0);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('@' == cptr[0]) {
|
||||
fprintf(stderr, "%s: got indirect '%s'\n", __func__,
|
||||
cptr+1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (1 == sscanf(cptr, "%d", &value)) {
|
||||
foo = filterstack_add(numid, value, 1, 1.0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d add\n",
|
||||
__func__, foo);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (verbosity > 1) filterstack_list(numid, __func__);
|
||||
return 0;
|
||||
}
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
|
||||
31
extras/Fonderie/filterstack.h
Normal file
31
extras/Fonderie/filterstack.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* filterstack.h
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
int numero; /* id in crapulator */
|
||||
char *name;
|
||||
int ival;
|
||||
float fval;
|
||||
} FilterSlot;
|
||||
|
||||
#define NUMBER_OF_STACK 8
|
||||
#define FILTER_BY_STACK 8
|
||||
|
||||
typedef struct {
|
||||
int count;
|
||||
FilterSlot slots[FILTER_BY_STACK];
|
||||
} FilterStack;
|
||||
|
||||
int filterstack_init(int numid, int notused);
|
||||
|
||||
int filterstack_add(int numid, int code, int ival, float fval);
|
||||
|
||||
int filterstack_list(int numid, const char *txt); /* XXX */
|
||||
|
||||
int filterstack_run(int numid, FloatImg *target, int notused);
|
||||
|
||||
int load_stack_from_file(int numid, char *fname, int notused);
|
||||
|
||||
int parse_filter_chain(int numid, char *argument);
|
||||
|
||||
264
extras/Fonderie/fonderie.c
Normal file
264
extras/Fonderie/fonderie.c
Normal file
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* FONDERIE
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <glob.h>
|
||||
#include "../floatimg.h"
|
||||
|
||||
#include "fifo.h"
|
||||
#include "glitches.h"
|
||||
#include "crapulator.h"
|
||||
#include "filterstack.h"
|
||||
|
||||
int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* this is the real worker ? or just a wrapper ?
|
||||
*/
|
||||
int traite_une_image(FloatImg *image, char *outd)
|
||||
{
|
||||
static int numero;
|
||||
int foo;
|
||||
char ligne[200];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "\n>>> %s ( %p '%s' )\n", __func__, image, outd);
|
||||
#endif
|
||||
|
||||
/* here, we put the picz in the fifo machinery */
|
||||
foo = insert_picture(image);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d on insert\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
/* and now, we pull the result on the magic computation
|
||||
*/
|
||||
sprintf(ligne, "%s/%05d.png", outd, numero);
|
||||
if (verbosity > 1) fprintf(stderr, " exporting to '%s'\n", ligne);
|
||||
|
||||
foo = export_fifo(ligne, 1);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d on export\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
numero++; /* VERY IMPORTANT :) */
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int insert_blank(FloatImg *image, int nbre, char *outd)
|
||||
{
|
||||
int idx, foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d '%s' )\n", __func__,
|
||||
image, nbre, outd);
|
||||
#endif
|
||||
|
||||
fimg_clear(image);
|
||||
for (idx=0; idx<nbre; idx++) {
|
||||
if ((foo=traite_une_image(image, outd))) {
|
||||
fprintf(stderr, "%s : err %d from 'traite_une_image'\n",
|
||||
__func__, foo);
|
||||
break;
|
||||
}
|
||||
printf("\t%c\r", "ABCDEFGH"[idx%8]); fflush(stdout);
|
||||
}
|
||||
puts("");
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
int demarre_la_machine(char *pattern, char *outdir, int szfifo,
|
||||
int outfmt, int blk)
|
||||
{
|
||||
int foo, idx, width, height;
|
||||
glob_t globbuf;
|
||||
char *cptr;
|
||||
FloatImg input;
|
||||
double fin;
|
||||
float maxvalue;
|
||||
int datas[3];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "\n>>> %s ( '%s' -> '%s' %d )\n", __func__,
|
||||
pattern, outdir, szfifo);
|
||||
#endif
|
||||
|
||||
(void)fimg_timer_set(0);
|
||||
|
||||
memset(&globbuf, 0, sizeof(glob_t));
|
||||
foo = glob(pattern, 0, NULL, &globbuf);
|
||||
if (foo) {
|
||||
fprintf(stderr, "glob (%s) failure %d\n", pattern, foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "glob '%s' -> %d, %d files found\n", pattern, foo,
|
||||
(int)globbuf.gl_pathc);
|
||||
|
||||
/* get the size of the inputs images */
|
||||
foo = fimg_fileinfos(globbuf.gl_pathv[0], datas);
|
||||
width = datas[0]; height = datas[1];
|
||||
fprintf(stderr, "first image size %dx%d\n", width, height);
|
||||
|
||||
fimg_create(&input, width, height, 3);
|
||||
|
||||
/* get the maximum value of the first pic */
|
||||
foo = fimg_load_from_dump(globbuf.gl_pathv[0], &input);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d loading %s\n",
|
||||
__func__, foo, globbuf.gl_pathv[0]);
|
||||
exit(1);
|
||||
}
|
||||
maxvalue = fimg_get_maxvalue(&input);
|
||||
fprintf(stderr, "first image maxvalue %f\n", maxvalue);
|
||||
|
||||
foo = create_fifo(szfifo, width, height, FIMG_TYPE_RGB);
|
||||
fprintf(stderr, "init fifo (%d slots) --> %d\n", szfifo, foo);
|
||||
|
||||
/* XXX inject a few strange pics in the fifo */
|
||||
insert_blank(&input, blk, outdir);
|
||||
|
||||
for (idx=0; idx<globbuf.gl_pathc; idx++) {
|
||||
|
||||
cptr = globbuf.gl_pathv[idx];
|
||||
/* first step : read the current grabed picz from disk,
|
||||
and put it in our private buffer */
|
||||
// fprintf(stderr, "\n######### loading '%s'\n", cptr);
|
||||
foo = fimg_load_from_dump(cptr, &input);
|
||||
if (foo) {
|
||||
fprintf(stderr, "load #%d from dump -> %d\n", idx, foo);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* fscking input filter here */
|
||||
foo = filterstack_run(0, &input, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: input filter -> %d\n", __func__, foo);
|
||||
exit(1);
|
||||
}
|
||||
#if 0
|
||||
if (idx==42) fimg_dump_to_file(&input, "inputXXX.fimg", 0);
|
||||
#endif
|
||||
foo = traite_une_image(&input, outdir);
|
||||
|
||||
if (foo) {
|
||||
fprintf(stderr, "traitement %s -> %d WTF?\n", cptr, foo);
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "\t%5d / %5d\r", idx, (int)globbuf.gl_pathc);
|
||||
}
|
||||
|
||||
fputs("\n", stderr);
|
||||
|
||||
insert_blank(&input, blk, outdir);
|
||||
|
||||
/*
|
||||
* PLEASE, FLUSH THE FIFO !
|
||||
*/
|
||||
|
||||
fin = fimg_timer_get(0);
|
||||
if (idx) {
|
||||
fprintf(stderr, "\nelapsed %.2f seconds, %.2f s/pic\n", fin, fin/idx);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "\nelapsed %.2f seconds\n", fin);
|
||||
}
|
||||
|
||||
return 8; /* why 9 ? */
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
void help(void)
|
||||
{
|
||||
puts("\tFONDERIE\noptions:");
|
||||
|
||||
puts("\t-E\tinput:filter:chain");
|
||||
puts("\t-F\toutput:filter:chain");
|
||||
// puts("\t-g\tconvert to gray");
|
||||
puts("\t-I\tinput glob pattern");
|
||||
puts("\t-L\tlist available filters");
|
||||
puts("\t-O\toutput directory");
|
||||
puts("\t-T\tfifo size");
|
||||
puts("\t-v\tincrease verbosity");
|
||||
|
||||
exit(0);
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int foo, opt;
|
||||
int fifosize = 10;
|
||||
char *in_pattern = "capture/?????.fimg";
|
||||
char *out_dir = "p8";
|
||||
int outfmt = FILE_TYPE_PNG;
|
||||
int blanks = 20;
|
||||
char *InFchain = "none";
|
||||
char *OutFchain = "none";
|
||||
|
||||
fprintf(stderr, "*** %s\n\tcompiled %s, %s, pid %d\n",
|
||||
argv[0], __DATE__, __TIME__, getpid());
|
||||
fimg_print_version(2);
|
||||
|
||||
while ((opt = getopt(argc, argv, "B:E:F:ghI:LO:T:vw:x:")) != -1) {
|
||||
switch(opt) {
|
||||
case 'E': InFchain = optarg; break;
|
||||
case 'F': OutFchain = optarg; break;
|
||||
case 'B': blanks = atoi(optarg);
|
||||
break;
|
||||
case 'g': // convert_to_gray = 1;
|
||||
break;
|
||||
case 'h': help();
|
||||
break;
|
||||
case 'I': in_pattern = optarg;
|
||||
break;
|
||||
case 'L':
|
||||
list_crapulors("available filters");
|
||||
exit(0);
|
||||
case 'O': out_dir = optarg;
|
||||
break;
|
||||
case 'T': fifosize = atoi(optarg);
|
||||
break;
|
||||
case 'v': verbosity++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "\tinput glob '%s'\n", in_pattern);
|
||||
fprintf(stderr, "\toutput dir '%s'\n", out_dir);
|
||||
fprintf(stderr, "\tsrc filter '%s'\n", InFchain);
|
||||
fprintf(stderr, "\tout filter '%s'\n", OutFchain);
|
||||
}
|
||||
|
||||
foo = parse_filter_chain(0, InFchain);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d parsing '%s'\n", foo, InFchain);
|
||||
exit(1);
|
||||
}
|
||||
foo = parse_filter_chain(1, OutFchain);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d parsing '%s'\n", foo, OutFchain);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (verbosity > 1) {
|
||||
filterstack_list(0, "input");
|
||||
filterstack_list(1, "ouput");
|
||||
fprintf(stderr, ".\n");
|
||||
}
|
||||
|
||||
foo = demarre_la_machine(in_pattern, out_dir, fifosize, outfmt, blanks);
|
||||
|
||||
fprintf(stderr, "retour du big-run de la machine -> %d\n", foo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
313
extras/Fonderie/glitches.c
Normal file
313
extras/Fonderie/glitches.c
Normal file
@@ -0,0 +1,313 @@
|
||||
/*
|
||||
* glitches.c
|
||||
* ----------
|
||||
*
|
||||
* initially developped for the interpolator
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
#include "glitches.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* 10 mai 2021 a Terre Blanque */
|
||||
int microglitch(FloatImg *pimg, int notused)
|
||||
{
|
||||
int surface;
|
||||
int offset, idx;
|
||||
|
||||
surface = pimg->width * pimg->height;
|
||||
|
||||
for (idx=0; idx<10000; idx++) {
|
||||
offset = rand() % surface;
|
||||
pimg->R[offset] *= 0.8;
|
||||
pimg->G[offset] *= 0.8;
|
||||
pimg->B[offset] *= 0.8;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* nouveau du 32 decembre 2020, endless september */
|
||||
int do_something(FloatImg *pimg, int notused)
|
||||
{
|
||||
int ypos, idx, pos, sline;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, notused);
|
||||
#endif
|
||||
|
||||
ypos = rand() % pimg->width;
|
||||
|
||||
for (idx=0; idx < pimg->height; idx++) {
|
||||
sline = idx * pimg->width;
|
||||
pos = sline + ypos;
|
||||
// fprintf(stderr, "%6d %6d\n", idx, sline);
|
||||
pimg->R[pos] = pimg->G[pos];
|
||||
pimg->B[pos] = pimg->G[pos];
|
||||
pimg->G[pos] *= 1.717;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int kill_a_random_line(FloatImg *pvictime, float fval, int bits)
|
||||
{
|
||||
int line, xpos, offset;
|
||||
float ftmp;
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pvictime, bits);
|
||||
#endif
|
||||
|
||||
if (verbosity > 1) {
|
||||
fprintf(stderr, "--> %s: hauteur image = %d fval = %f\n",
|
||||
__func__, pvictime->height, fval);
|
||||
}
|
||||
|
||||
line = rand() % pvictime->height;
|
||||
|
||||
if (verbosity > 2) {
|
||||
fprintf(stderr, "%s: try to kill line %d\n", __func__, line);
|
||||
}
|
||||
|
||||
offset = pvictime->width * line;
|
||||
|
||||
for (xpos=0; xpos<pvictime->width; xpos++) {
|
||||
if (bits & 1) { ftmp = pvictime->R[offset+xpos] * fval;
|
||||
pvictime->R[offset+xpos] = sqrt(ftmp); }
|
||||
else pvictime->R[offset+xpos] = 0.0;
|
||||
if (bits & 2) { ftmp = pvictime->G[offset+xpos] * fval;
|
||||
pvictime->G[offset+xpos] = sqrt(ftmp); }
|
||||
else pvictime->G[offset+xpos] = 0.0;
|
||||
if (bits & 4) { ftmp = pvictime->B[offset+xpos] * fval;
|
||||
pvictime->B[offset+xpos] = sqrt(ftmp); }
|
||||
else pvictime->B[offset+xpos] = 0.0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int kill_a_few_lines(FloatImg *who, float fval, int number)
|
||||
{
|
||||
int idx, foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %f %d )\n", __func__, who, fval, number);
|
||||
#endif
|
||||
|
||||
/* Frag the pixels */
|
||||
for (idx=0; idx<number; idx++) {
|
||||
foo = kill_a_random_line(who, fval, rand() & 0x07);
|
||||
if (foo) abort();
|
||||
}
|
||||
|
||||
return foo;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int un_petit_flou_8x8(FloatImg *picture, int xpos, int ypos)
|
||||
{
|
||||
float sr, sg, sb;
|
||||
int x, y, off;
|
||||
|
||||
/*
|
||||
* please add boundary check ?
|
||||
*/
|
||||
sr = sg = sb = 0.0;
|
||||
for (y=0; y<8; y++) {
|
||||
off = xpos + (picture->width * (y+ypos));
|
||||
for (x=0; x<8; x++) {
|
||||
sr += picture->R[off];
|
||||
sg += picture->G[off];
|
||||
sb += picture->B[off];
|
||||
off++;
|
||||
}
|
||||
}
|
||||
sr /= 64.0; sg /= 64.0; sb /= 64.0;
|
||||
for (y=0; y<8; y++) {
|
||||
off = xpos + (picture->width * (y+ypos));
|
||||
for (x=0; x<8; x++) {
|
||||
picture->R[off] = sr;
|
||||
picture->G[off] = sg;
|
||||
picture->B[off] = sb;
|
||||
off++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int plot_multidots(FloatImg *picture, int notused)
|
||||
{
|
||||
int pass, szimg, osrc, odst;
|
||||
|
||||
szimg = picture->width * picture->height;
|
||||
|
||||
for (pass=0; pass<szimg/32; pass++) {
|
||||
|
||||
osrc = rand() % szimg;
|
||||
odst = rand() % szimg;
|
||||
picture->R[odst] = (picture->R[osrc] + picture->R[odst]) / 2.0;
|
||||
picture->G[odst] = (picture->G[osrc] + picture->G[odst]) / 2.0;
|
||||
picture->B[odst] = (picture->B[osrc] + picture->B[odst]) / 2.0;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
int random_blocks(FloatImg *picture, int percent)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
if ( (picture->width%16) || (picture->height%16) )
|
||||
{
|
||||
fprintf(stderr, "%s: %d%d bad dims\n", __func__,
|
||||
picture->width, picture->height);
|
||||
}
|
||||
|
||||
for (y=0; y<picture->height; y+=16) {
|
||||
for (x=0; x<picture->width; x+=16) {
|
||||
if (percent < (rand()%100) ) {
|
||||
un_petit_flou_8x8(picture, x, y);
|
||||
un_petit_flou_8x8(picture, x+8, y);
|
||||
un_petit_flou_8x8(picture, x, y+8);
|
||||
un_petit_flou_8x8(picture, x+8, y+8);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int un_moyen_flou_8x8(FloatImg *picture, int xpos, int ypos)
|
||||
{
|
||||
int i, j, x, y;
|
||||
|
||||
/*
|
||||
* please add boundary check ?
|
||||
*/
|
||||
for (i=y=0; i<8; i++, y+=8) {
|
||||
for (j=x=0; j<8; j++, x+=8 ) {
|
||||
un_petit_flou_8x8(picture, x+xpos, y+ypos);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int poke_a_random_pixel(FloatImg *picz, float fval, int kaboo)
|
||||
{
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* used by vertical_singlitch()
|
||||
*/
|
||||
static int x_delta(float dy, float phy)
|
||||
{
|
||||
float param, fv;
|
||||
param = dy + phy;
|
||||
fv = 12.11*sin(param+0.22) + 8.5*sin(param*3.02) + 0.42*sin(param*5.1);
|
||||
return (int)fv;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* please explain arguments
|
||||
*/
|
||||
int vertical_singlitch(FloatImg *picz, int xpos, float fval,
|
||||
float omega, float phi)
|
||||
{
|
||||
int y, x, w, h;
|
||||
float dy;
|
||||
float fv;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d %f %f )\n", __func__, picz,
|
||||
xpos, omega, phi);
|
||||
#endif
|
||||
|
||||
h = picz->height; w = picz->width;
|
||||
#define BB 2
|
||||
for (y=BB; y<h-BB; y++) {
|
||||
|
||||
dy = (float)y * omega; /* normalize vertical position */
|
||||
x = xpos + x_delta(dy, phi); /* add sinus deviation */
|
||||
/* compute bounding box */
|
||||
if ( (x>BB) && (x<w-BB) ) {
|
||||
/* an make the glitch */
|
||||
fimg_plot_rgb(picz, x, y, fval, fval, fval);
|
||||
fv = fval / 3.0;
|
||||
if (rand() & 8)
|
||||
fimg_plot_rgb(picz, x-1, y, fv, fv, fv);
|
||||
if (rand() & 8)
|
||||
fimg_plot_rgb(picz, x+1, y, fv, fv, fv);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
static void shifter(float *fs, float *fd, int stp, int largeur)
|
||||
{
|
||||
int xpos;
|
||||
|
||||
/* move the pixels */
|
||||
for (xpos=0; xpos<largeur; xpos++) {
|
||||
fd[xpos] = fs[(xpos+stp)%largeur];
|
||||
}
|
||||
/* take your sixpack, film at 11 */
|
||||
}
|
||||
|
||||
static void smooth_line(float *fs, float *fd, int sz)
|
||||
{
|
||||
int xpos;
|
||||
for (xpos=1; xpos<(sz-1); xpos++) {
|
||||
fd[xpos] = (fs[xpos-1]+fs[xpos]+fs[xpos+1]) / 3.0;
|
||||
}
|
||||
fd[0] = fd[sz-1] = 0.0;
|
||||
}
|
||||
|
||||
int multilines_shift_0(FloatImg *picz, int step, int nombre)
|
||||
{
|
||||
float *buffline, *sptr;
|
||||
int idx, ypos;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, picz, step, nombre);
|
||||
#endif
|
||||
|
||||
buffline = alloca(picz->width * sizeof(float));
|
||||
if (NULL==buffline) {
|
||||
fprintf(stderr, "%s: memory panic\n", __func__);
|
||||
abort();
|
||||
}
|
||||
|
||||
for (idx=0; idx<nombre; idx++) {
|
||||
ypos = rand() % picz->height;
|
||||
|
||||
sptr = picz->R + (ypos * picz->width);
|
||||
shifter(sptr, buffline, step, picz->width);
|
||||
smooth_line(buffline, sptr, picz->width);
|
||||
// XXX memcpy (sptr, buffline, picz->width*sizeof(float));
|
||||
|
||||
sptr = picz->G + (ypos * picz->width);
|
||||
shifter(sptr, buffline, step, picz->width);
|
||||
smooth_line(buffline, sptr, picz->width);
|
||||
// XXX memcpy (sptr, buffline, picz->width*sizeof(float));
|
||||
|
||||
sptr = picz->B + (ypos * picz->width);
|
||||
shifter(sptr, buffline, step, picz->width);
|
||||
smooth_line(buffline, sptr, picz->width);
|
||||
// XXX memcpy (sptr, buffline, picz->width*sizeof(float));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
22
extras/Fonderie/glitches.h
Normal file
22
extras/Fonderie/glitches.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* glitches.h
|
||||
*/
|
||||
|
||||
int microglitch(FloatImg *pimg, int notused);
|
||||
|
||||
int do_something(FloatImg *pimg, int notused);
|
||||
int plot_multidots(FloatImg *picture, int notused);
|
||||
|
||||
int kill_a_random_line(FloatImg *pvictime, float level, int bits);
|
||||
int kill_a_few_lines(FloatImg *who, float fval, int number);
|
||||
int random_blocks(FloatImg *picture, int percent);
|
||||
|
||||
int un_petit_flou_8x8(FloatImg *picture, int x, int y);
|
||||
int un_moyen_flou_8x8(FloatImg *picture, int x, int y);
|
||||
int poke_a_random_pixel(FloatImg *picz, float fval, int kaboo);
|
||||
|
||||
int vertical_singlitch(FloatImg *picz, int xpos, float fv, float omega,
|
||||
float phi);
|
||||
int multilines_shift_0(FloatImg *picz, int step, int nombre);
|
||||
|
||||
/* this is a wtf file */
|
||||
322
extras/Fonderie/interpolator.c
Normal file
322
extras/Fonderie/interpolator.c
Normal file
@@ -0,0 +1,322 @@
|
||||
/*
|
||||
* INTERPOLATOR 2070
|
||||
*
|
||||
* +---------------------------------------+
|
||||
* ! Do not use that software in real life !
|
||||
* +---------------------------------------+
|
||||
*
|
||||
* imported in FloatImg Mon Nov 9 19:08:57 CET 2020
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <glob.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
#include "fifo.h"
|
||||
#include "glitches.h"
|
||||
#include "crapulator.h"
|
||||
#include "metriques.h"
|
||||
#include "filterstack.h"
|
||||
|
||||
int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* on va essayer de trier l'ordre d'apparition des images
|
||||
* selon une metrique approximative
|
||||
*/
|
||||
typedef struct {
|
||||
int idx; /* in globbuf.gl_pathv[n] */
|
||||
float value; /* from metric analyse */
|
||||
} IdxValue;
|
||||
|
||||
static int negative = 0;
|
||||
|
||||
static int cmp_idxvalues(const void *pa, const void *pb)
|
||||
{
|
||||
if (negative)
|
||||
return ( ((IdxValue *)pa)->value < ((IdxValue *)pb)->value);
|
||||
else
|
||||
return ( ((IdxValue *)pa)->value > ((IdxValue *)pb)->value);
|
||||
}
|
||||
|
||||
int tentative_triage(glob_t *ptr_glob, IdxValue **ptr_idxval,
|
||||
int method, double *p_average)
|
||||
{
|
||||
int idx, foo, nombre;
|
||||
float metrique;
|
||||
double average;
|
||||
char *filename;
|
||||
IdxValue *idxvalues;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, ptr_glob,
|
||||
ptr_idxval, method);
|
||||
#endif
|
||||
|
||||
nombre = ptr_glob->gl_pathc;
|
||||
|
||||
/* allocate the array for the sorting action */
|
||||
idxvalues = calloc(nombre, sizeof(IdxValue));
|
||||
if (NULL==idxvalues) {
|
||||
fprintf(stderr, "MEMORY ERROR in %s\n", __func__);
|
||||
exit(1);
|
||||
}
|
||||
fprintf(stderr, "IdxValues array at %p\n", idxvalues);
|
||||
|
||||
*ptr_idxval = idxvalues;
|
||||
average = 0.0;
|
||||
|
||||
/* compute all the needed values */
|
||||
for (idx=0; idx<nombre; idx++) {
|
||||
filename = ptr_glob->gl_pathv[idx];
|
||||
foo = get_float_metric_from_file(filename, &metrique, method);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d get metric of '%s'\n",
|
||||
__func__, foo, filename);
|
||||
return -1;
|
||||
}
|
||||
if (verbosity)
|
||||
fprintf(stderr, "%5d %s %10.3f\r",
|
||||
idx, filename, metrique);
|
||||
idxvalues[idx].idx = idx;
|
||||
idxvalues[idx].value = metrique;
|
||||
average += (double)metrique;
|
||||
}
|
||||
|
||||
if (method) {
|
||||
/* and now, we can massage all our datas */
|
||||
fprintf(stderr, "sorting method = %d ...\n", method);
|
||||
qsort(idxvalues, nombre, sizeof(IdxValue), cmp_idxvalues);
|
||||
}
|
||||
|
||||
if (verbosity > 1) {
|
||||
for (idx=0; idx<nombre; idx++) {
|
||||
printf("%5d %9.3f %5d\n", idx,
|
||||
idxvalues[idx].value, idxvalues[idx].idx);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
average /= (double)nombre;
|
||||
*p_average = average;
|
||||
|
||||
fprintf(stderr, "\naverage %f\n", average);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* This is the mega working loop
|
||||
*/
|
||||
int interpolator(char *pattern, char *outdir, int Nsteps,
|
||||
int infx, int outfx, int sort)
|
||||
{
|
||||
FloatImg A, B, Out, *pFirst, *pSecond;
|
||||
glob_t globbuf;
|
||||
int foo, idx, ipng, w, h, step;
|
||||
int curpix;
|
||||
int iarray[3];
|
||||
char *cptr, line[200];
|
||||
float coef, value;
|
||||
double meanmetric;
|
||||
IdxValue *idx_values; /* gni? */
|
||||
|
||||
fprintf(stderr, " interpolate from '%s' to '%s' with %d steps.\n",
|
||||
pattern, outdir, Nsteps);
|
||||
|
||||
if (negative) fprintf(stderr, "%s: negative ON\n", __func__);
|
||||
|
||||
memset(&globbuf, 0, sizeof(glob_t));
|
||||
foo = glob(pattern, 0, NULL, &globbuf);
|
||||
fprintf(stderr, "globbing '%s' -> %d, %d files found\n",
|
||||
pattern, foo, (int)globbuf.gl_pathc);
|
||||
if (0 == globbuf.gl_pathc) {
|
||||
fprintf(stderr, "%s : no file found, aborting\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
idx_values = NULL;
|
||||
foo = tentative_triage(&globbuf, &idx_values, sort, &meanmetric);
|
||||
if (foo) {
|
||||
fprintf(stderr, "sort of %p -> %d\n\n", idx_values, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
foo = fimg_fileinfos(globbuf.gl_pathv[0], iarray);
|
||||
if (FIMG_TYPE_RGB != iarray[2]) {
|
||||
fprintf(stderr, "can work only on RGB fimg picture, was %d\n",
|
||||
iarray[2]);
|
||||
exit(1); /* BLAM! */
|
||||
}
|
||||
|
||||
w = iarray[0], h = iarray[1];
|
||||
fprintf(stderr, "first image size : %dx%d\n", w, h);
|
||||
|
||||
fimg_create(&A, w, h, 3); pFirst = &A; fimg_clear(&A);
|
||||
fimg_create(&B, w, h, 3); pSecond = &B; fimg_clear(&B);
|
||||
fimg_create(&Out, w, h, 3);
|
||||
|
||||
ipng = 0;
|
||||
for (idx=0; idx<globbuf.gl_pathc; idx++) {
|
||||
|
||||
curpix = idx_values[idx].idx;
|
||||
cptr = globbuf.gl_pathv[curpix]; /* aliasing filename */
|
||||
|
||||
/* read the next file in B */
|
||||
fprintf(stderr, "%5d / %5d %s\r", idx,
|
||||
(int)globbuf.gl_pathc, cptr);
|
||||
foo = fimg_load_from_dump(cptr, &B);
|
||||
if (foo) {
|
||||
fprintf(stderr, "load %s from dump -> %d\n", cptr, foo);
|
||||
continue;
|
||||
}
|
||||
value = idx_values[idx].value;
|
||||
|
||||
/* here was the input filter */
|
||||
foo = filterstack_run(0, &B, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: input fx fail %d\n", __func__, foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (step=0; step<Nsteps; step++) {
|
||||
coef = (float)step / (float)Nsteps;
|
||||
fimg_interpolate(pSecond, pFirst, &Out, coef);
|
||||
|
||||
foo = filterstack_run(1, &Out, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "run filt stack--> %d\n", foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
sprintf(line, "%s/%05d.png", outdir, ipng);
|
||||
foo = fimg_save_as_png(&Out, line, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err saving %s\n", line);
|
||||
return -8;
|
||||
}
|
||||
ipng++;
|
||||
}
|
||||
|
||||
#if 1
|
||||
/* temporary hack : move datas */
|
||||
fimg_copy_data(&B, &A);
|
||||
#else
|
||||
/* swap pointers to the two picz */
|
||||
pTmp = pSecond;
|
||||
pSecond = pFirst;
|
||||
pFirst = pTmp;
|
||||
/* XXX THIS CODE DON'T WORK !!! */
|
||||
#endif
|
||||
}
|
||||
|
||||
fprintf(stderr, "\ngenerated %d png files\n", ipng);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
void help(void)
|
||||
{
|
||||
puts("\tINTERPOLATOR");
|
||||
puts("usage:\n\tinterpolator [options] <inglob> <outdir> <nbsteep>");
|
||||
|
||||
/* may be we can make options incoherent, like
|
||||
* the options of 'fonderie' software ?
|
||||
*/
|
||||
puts("options:");
|
||||
puts("\t-E i:bla:k\tinput filter chain");
|
||||
puts("\t-F name:j\toutput filter chain");
|
||||
puts("\t-n\t\tmake negative");
|
||||
puts("\t-S nn\t\tmysterious sort");
|
||||
puts("\t-L\t\tlist available filters");
|
||||
puts("\t-v\t\tincrease verbosity");
|
||||
|
||||
if (verbosity) {
|
||||
list_crapulors("available filters");
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int foo;
|
||||
int nbrsteps = 9;
|
||||
int opt;
|
||||
// int inFx = 0;
|
||||
// int outFx = 0;
|
||||
int sort = 0;
|
||||
char *InFchain = "0";
|
||||
char *OutFchain = "0";
|
||||
|
||||
fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", __FILE__,
|
||||
__DATE__, __TIME__);
|
||||
fimg_print_version(2);
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
/* this is for the debug off calling shellscript */
|
||||
for (foo=0; foo<argc; foo++)
|
||||
fprintf(stderr, "%5d %s\n", foo, argv[foo]);
|
||||
#endif
|
||||
|
||||
while ((opt = getopt(argc, argv, "E:F:hLnS:v")) != -1) {
|
||||
switch(opt) {
|
||||
case 'E': InFchain = optarg; break;
|
||||
case 'F': OutFchain = optarg; break;
|
||||
case 'h': help(); break;
|
||||
case 'L':
|
||||
list_crapulors("available filters");
|
||||
exit(0);
|
||||
case 'S': sort = atoi(optarg); break;
|
||||
case 'v': verbosity++; break;
|
||||
case 'n': negative = 1; break;
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s: argc = %d, optind = %d\n", argv[0], argc, optind);
|
||||
#endif
|
||||
|
||||
if (3 != (argc-optind)) {
|
||||
fprintf(stderr, "args: [options] <inglob> <outdir> <nbsteep>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
foo = parse_filter_chain(0, InFchain);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d parsing '%s'\n", foo, InFchain);
|
||||
exit(1);
|
||||
}
|
||||
foo = parse_filter_chain(1, OutFchain);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d parsing '%s'\n", foo, OutFchain);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "\tinput glob '%s'\n", argv[optind]);
|
||||
fprintf(stderr, "\toutput dir '%s'\n", argv[optind+1]);
|
||||
fprintf(stderr, "\tsrc filter '%s'\n", InFchain);
|
||||
fprintf(stderr, "\tout filter '%s'\n", OutFchain);
|
||||
}
|
||||
|
||||
if (verbosity > 1) {
|
||||
puts("=========================");
|
||||
filterstack_list(0, __FILE__);
|
||||
filterstack_list(1, __FILE__);
|
||||
puts("=========================");
|
||||
}
|
||||
|
||||
nbrsteps = atoi(argv[optind+2]);
|
||||
foo = interpolator(argv[optind], argv[optind+1], nbrsteps,
|
||||
0, 0, sort);
|
||||
|
||||
fprintf(stderr, "interpolator give us a %d score\n", foo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
148
extras/Fonderie/metriques.c
Normal file
148
extras/Fonderie/metriques.c
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* metriques.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../floatimg.h"
|
||||
#include "metriques.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* usage --> sfx.c:trinitron */
|
||||
int stat_zone(FloatImg *pimg, int geom[4], float v3[3])
|
||||
{
|
||||
int x, y, xe, ye;
|
||||
int off;
|
||||
double accus[3], divisor;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stdout, "geom: %5d %5d %5d %5d\n",
|
||||
geom[0], geom[1], geom[2], geom[3]);
|
||||
#endif
|
||||
|
||||
xe = geom[0] + geom[2];
|
||||
ye = geom[1] + geom[3];
|
||||
|
||||
accus[0] = accus[1] = accus[2] = 0.0;
|
||||
for (y=geom[1]; y<ye; y++) {
|
||||
for (x=geom[0]; x<xe; x++) {
|
||||
off = (y*pimg->width) + x;
|
||||
accus[0] += (double) pimg->R[off];
|
||||
accus[1] += (double) pimg->G[off];
|
||||
accus[2] += (double) pimg->B[off];
|
||||
}
|
||||
}
|
||||
|
||||
divisor = (double)(geom[2] * geom[3]); /* array of zone */
|
||||
v3[0] = (float)(accus[0] / divisor);
|
||||
v3[1] = (float)(accus[1] / divisor);
|
||||
v3[2] = (float)(accus[2] / divisor);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* premier essai : moyenne de toutes les composantes
|
||||
* de tous les pixels.
|
||||
*
|
||||
* Question: pourquoi pas le retour en double precision ?
|
||||
*/
|
||||
int get_float_metric_avg(FloatImg *pimg, float *where)
|
||||
{
|
||||
float means[4]; /* four values : R G B A */
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p )\n", __func__, pimg, where);
|
||||
#endif
|
||||
|
||||
foo = fimg_meanvalues(pimg, means);
|
||||
if (foo) {
|
||||
fprintf(stderr, "fatal error in %s\n", __func__);
|
||||
exit(1);
|
||||
}
|
||||
*where = means[0] + means[1] + means[2];
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* echantillonage des pixels rouges */
|
||||
int get_float_metric_iRed(FloatImg *pimg, float *where)
|
||||
{
|
||||
int idx, size, nbre;
|
||||
double adder;
|
||||
|
||||
adder = 0.0;
|
||||
nbre = 0;
|
||||
size = pimg->width * pimg->height;
|
||||
for (idx=20; idx < size; idx+=42) {
|
||||
adder += (double)pimg->R[idx];
|
||||
nbre++;
|
||||
}
|
||||
*where = (float)(adder/(nbre+1));
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int get_float_metric_LR(FloatImg *pimg, float *where)
|
||||
{
|
||||
int coords[4], foo;
|
||||
float valL[3], valR[3];
|
||||
|
||||
coords[0] = 0; // X
|
||||
coords[1] = 0; // Y
|
||||
coords[2] = pimg->width / 2; // W
|
||||
coords[3] = pimg->height; // H
|
||||
|
||||
foo = stat_zone(pimg, coords, valL);
|
||||
coords[1] = pimg->width / 2;
|
||||
foo = stat_zone(pimg, coords, valR);
|
||||
|
||||
*where = valL[1] - valR[1];
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* et voici le grand dispactheur
|
||||
*/
|
||||
int get_float_metric_from_file(char *fname, float *where, int mode)
|
||||
{
|
||||
FloatImg image;
|
||||
int foo;
|
||||
float fval;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %p %d )\n", __func__, fname, where, mode);
|
||||
#endif
|
||||
|
||||
foo = fimg_create_from_dump(fname, &image);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d loading %s\n", __func__, foo, fname);
|
||||
return foo;
|
||||
}
|
||||
fval = -1.0; /* sensible default value */
|
||||
switch (mode) {
|
||||
case 0: case 1:
|
||||
foo = get_float_metric_avg(&image, &fval);
|
||||
break;
|
||||
case 2:
|
||||
foo = get_float_metric_iRed(&image, &fval);
|
||||
break;
|
||||
case 3:
|
||||
foo = get_float_metric_LR(&image, &fval);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: method %d invalid\n",
|
||||
__func__, mode);
|
||||
exit(1);
|
||||
break; /* not reached */
|
||||
}
|
||||
|
||||
*where = fval;
|
||||
|
||||
fimg_destroy(&image);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
15
extras/Fonderie/metriques.h
Normal file
15
extras/Fonderie/metriques.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* metriques.h
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
int stat_zone(FloatImg *pimg, int geom[4], float v3[3]);
|
||||
|
||||
|
||||
/* first experiments */
|
||||
|
||||
int get_float_metric_a(FloatImg *pimg, float *where);
|
||||
int get_float_metric_from_file(char *imgname, float *where, int mode);
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
4
extras/Fonderie/notes.md
Normal file
4
extras/Fonderie/notes.md
Normal file
@@ -0,0 +1,4 @@
|
||||
'help system' pour l'explication des divers filtres.
|
||||
|
||||
pipeliner le graber et le fondeur par la SHM ?
|
||||
|
||||
385
extras/Fonderie/sfx.c
Normal file
385
extras/Fonderie/sfx.c
Normal file
@@ -0,0 +1,385 @@
|
||||
/*
|
||||
* SPECIAL EFFECTS
|
||||
*
|
||||
* Du code bien cracra / tTh / Tetalab
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
#include "fifo.h"
|
||||
#include "metriques.h"
|
||||
#include "sfx.h"
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* here are global vars exported by the main module
|
||||
*/
|
||||
extern int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* please, add some parameters !
|
||||
*/
|
||||
int incrustation_vignette(FloatImg *src, FloatImg *dst, int k)
|
||||
{
|
||||
int x, y, x4, y4;
|
||||
float rgb[3];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, src, dst, k);
|
||||
#endif
|
||||
|
||||
x4 = dst->width / 4, y4 = dst->height / 4;
|
||||
|
||||
for (y=0; y<y4; y++) {
|
||||
for (x=0; x<x4; x++) {
|
||||
fimg_get_rgb(src, x*4, y*4, rgb);
|
||||
fimg_put_rgb(dst, x+39, y+39, rgb);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* nouveau du premier dimanche de 2020 'nextgen' */
|
||||
static int pixel_trinitron(FloatImg *pimg, int pos[4], float *fvals)
|
||||
{
|
||||
int x, y, pline, off;
|
||||
|
||||
for (y=pos[1]; y<pos[1]+pos[3]; y++) {
|
||||
pline = y*pimg->width;
|
||||
for (x=pos[0]+2; x<pos[0]+pos[2]-2; x++) {
|
||||
off = pline + x;
|
||||
pimg->R[off] = fvals[0];
|
||||
pimg->G[off] = fvals[1];
|
||||
pimg->B[off] = fvals[2];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int trinitron(FloatImg *pimg, int notused)
|
||||
{
|
||||
int x, y, coo[4], foo;
|
||||
float vals[3];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, notused);
|
||||
#endif
|
||||
|
||||
#define STP 16 /* stepd for x & y axex */
|
||||
coo[2] = coo[3] = STP;
|
||||
|
||||
for (y=0; y<pimg->height; y+=STP) {
|
||||
coo[1] = y;
|
||||
for (x=0; x<pimg->width; x+=STP) {
|
||||
coo[0] = x;
|
||||
foo = stat_zone(pimg, coo, vals);
|
||||
if (foo) abort();
|
||||
/* next step : plot the datas */
|
||||
pixel_trinitron(pimg, coo, vals);
|
||||
}
|
||||
}
|
||||
#undef STP
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* nouveau du 27 decembre 2020, un soir de grand froid... */
|
||||
int octotree_classif(FloatImg *pimg, float kdist, int notused)
|
||||
{
|
||||
int foo;
|
||||
float mm[6], delta[3];
|
||||
float r, g, b, kr, kg, kb, dp, trig;
|
||||
int idx, sz, n8, count;
|
||||
typedef struct {
|
||||
float x, y, z;
|
||||
} ptc_t;
|
||||
ptc_t ptc[8];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %f %d )\n", __func__,
|
||||
pimg, kdist, notused);
|
||||
#endif
|
||||
|
||||
foo = fimg_get_minmax_rgb(pimg, mm);
|
||||
if (foo) {
|
||||
fprintf(stderr, "oups %d in get minmax\n", foo);
|
||||
return foo;
|
||||
}
|
||||
if (verbosity>1) fimg_print_minmax(mm, " input pic ");
|
||||
|
||||
/*
|
||||
* compute the 8 center points
|
||||
*/
|
||||
delta[0] = mm[1] - mm[0]; /* R */
|
||||
delta[1] = mm[3] - mm[2]; /* G */
|
||||
delta[2] = mm[5] - mm[4]; /* B */
|
||||
// fprintf(stderr, "delta: %11.3f %11.3f %11.3f\n",
|
||||
// delta[0], delta[1], delta[2]);
|
||||
for (idx=0; idx<8; idx++) {
|
||||
kr = 0.25 * ((idx & 0x4) ? 1 : 3);
|
||||
kg = 0.25 * ((idx & 0x2) ? 1 : 3);
|
||||
kb = 0.25 * ((idx & 0x1) ? 1 : 3);
|
||||
// fprintf(stderr, "%6d %.2f %.2f %.2f\n", idx, kr, kg, kb);
|
||||
ptc[idx].x = (delta[0] * kr) + mm[0];
|
||||
ptc[idx].y = (delta[1] * kg) + mm[2];
|
||||
ptc[idx].z = (delta[2] * kb) + mm[4];
|
||||
// fprintf(stderr, "%6d %.3f %.3f %.3f\n", idx,
|
||||
// ptc[idx].x, ptc[idx].y, ptc[idx].z);
|
||||
}
|
||||
|
||||
sz = pimg->width * pimg->height;
|
||||
trig = kdist * ((mm[1] + mm[3] + mm[5])/6.0);
|
||||
// fprintf(stderr, "trig value %f\n", trig);
|
||||
|
||||
count = 0;
|
||||
|
||||
#define X(a,b) ( ((a)-(b)) * ((a)-(b)) )
|
||||
for (idx=0; idx<sz; idx++) {
|
||||
|
||||
r = pimg->R[idx]; g = pimg->G[idx]; b = pimg->B[idx];
|
||||
for (n8=0; n8<8; n8++) {
|
||||
dp = sqrt(X(r,ptc[n8].x)+X(g,ptc[n8].y)+X(b,ptc[n8].z));
|
||||
if (dp < trig) {
|
||||
pimg->R[idx] = ptc[n8].x;
|
||||
pimg->G[idx] = ptc[n8].y;
|
||||
pimg->B[idx] = ptc[n8].z;
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
pimg->R[idx]=pimg->G[idx]=pimg->B[idx]=0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (verbosity > 1) {
|
||||
fprintf(stderr, "%s: %d/%d pixels, ratio %f\n", __func__, count, sz,
|
||||
(float)count/(float)sz);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* nouveau du 19 decembre 2020, pour le grand ecran de da Scritch */
|
||||
|
||||
int upside_down(FloatImg *pimg)
|
||||
{
|
||||
float *rowpix;
|
||||
float *Ps, *Pd;
|
||||
int Os, Od; /* offset of lines */
|
||||
int wsz;
|
||||
int ya, y2;
|
||||
|
||||
if (verbosity>1) fprintf(stderr, "%s: image width is %d\n",
|
||||
__func__, pimg->width);
|
||||
|
||||
rowpix = calloc(pimg->width, sizeof(float));
|
||||
if (NULL==rowpix) {
|
||||
fprintf(stderr, "%s : memory full\n", __func__);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
wsz = pimg->width * sizeof(float);
|
||||
if (verbosity>1) fprintf(stderr, "%s: wsx = %d\n", __func__, wsz);
|
||||
|
||||
for (ya=0; ya<pimg->height/2; ya++) {
|
||||
|
||||
y2 = pimg->height - (ya+1);
|
||||
Os = (pimg->width * ya);
|
||||
Od = (pimg->width * y2);
|
||||
|
||||
/* let's go, crash coredumping... */
|
||||
Ps = pimg->R + Os;
|
||||
Pd = pimg->R + Od;
|
||||
memcpy(rowpix, Ps, wsz);
|
||||
memcpy(Ps, Pd, wsz);
|
||||
memcpy(Pd, rowpix, wsz);
|
||||
|
||||
Ps = pimg->G + Os;
|
||||
Pd = pimg->G + Od;
|
||||
memcpy(rowpix, Ps, wsz);
|
||||
memcpy(Ps, Pd, wsz);
|
||||
memcpy(Pd, rowpix, wsz);
|
||||
|
||||
Ps = pimg->B + Os;
|
||||
Pd = pimg->B + Od;
|
||||
memcpy(rowpix, Ps, wsz);
|
||||
memcpy(Ps, Pd, wsz);
|
||||
memcpy(Pd, rowpix, wsz);
|
||||
}
|
||||
|
||||
free(rowpix);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* nouveau du 9 decembre 2020, en ecoutant le Fermion raconter du
|
||||
superbe portnawak */
|
||||
int bouger_les_pixels(FloatImg *pimg, int intensite)
|
||||
{
|
||||
int x, y, nx, ny;
|
||||
float rgb[3];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, intensite);
|
||||
#endif
|
||||
|
||||
if (intensite < 1) {
|
||||
fprintf(stderr, "%s: %d bad intensity\n", __func__, intensite);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (x=0; x<pimg->width; x++) {
|
||||
for (y=0; y<pimg->height; y++) {
|
||||
|
||||
nx = x+(rand()%intensite)-(intensite/2);
|
||||
ny = y+(rand()%intensite)-(intensite/2);
|
||||
|
||||
if ( nx<0 || ny<0 || nx>=pimg->width
|
||||
|| ny>=pimg->height )
|
||||
continue;
|
||||
|
||||
/* XXX optimize here ? */
|
||||
fimg_get_rgb(pimg, nx, ny, rgb);
|
||||
fimg_put_rgb(pimg, x, y, rgb);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* nouveau du 9 decembre 2020, en ecoutant les Cernettes */
|
||||
int mirror_split(FloatImg *pimg, int kaboo)
|
||||
{
|
||||
int line, x, xs, xd;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, kaboo);
|
||||
#endif
|
||||
|
||||
for (line=0; line<pimg->height; line++) {
|
||||
for (x=0; x<pimg->width/2; x++) {
|
||||
xs = (pimg->width * line) + x;
|
||||
xd = (pimg->width * line) + (pimg->width -x);
|
||||
pimg->R[xd] = pimg->R[xs];
|
||||
pimg->G[xd] = pimg->G[xs];
|
||||
pimg->B[xd] = pimg->B[xs];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* nouveau du 20 novembre 2020, pour encoder une vidz du vernissage
|
||||
* du festival Sauvageonnes de Mixart-Myrys */
|
||||
int des_bords_sombres_a(FloatImg *pimg, int offset)
|
||||
{
|
||||
float coef;
|
||||
int xpos, xp2, lidx, y;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, offset);
|
||||
#endif
|
||||
|
||||
if (offset<0 || offset>=pimg->width) {
|
||||
fprintf(stderr, "%s: offset %d is bad\n", __func__, offset);
|
||||
return -66;
|
||||
}
|
||||
|
||||
for (y=0; y<pimg->height; y++) {
|
||||
lidx = y * pimg->width; /* start of the
|
||||
'y' line */
|
||||
for (xpos=0; xpos<offset; xpos++) {
|
||||
coef = (float)xpos / (float)offset;
|
||||
pimg->R[xpos+lidx] *= coef;
|
||||
pimg->G[xpos+lidx] *= coef;
|
||||
pimg->B[xpos+lidx] *= coef;
|
||||
xp2 = pimg->width-xpos;
|
||||
pimg->R[xp2+lidx] *= coef;
|
||||
pimg->G[xp2+lidx] *= coef;
|
||||
pimg->B[xp2+lidx] *= coef;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* nouveau Mon 10 May 2021 08:46:02 PM CEST
|
||||
* chez Eric 1KA */
|
||||
int des_bords_sombres_b(FloatImg *pimg, int offset)
|
||||
{
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, offset);
|
||||
#endif
|
||||
|
||||
if (offset<0 || offset>=pimg->width) {
|
||||
fprintf(stderr, "%s: offset %d is bad\n", __func__, offset);
|
||||
return -66;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* int binarize(FloatImg *pimg, int notused) was now in
|
||||
* funcs/sfx2.c
|
||||
* same move for trinarize.
|
||||
*/
|
||||
/* -------------------------------------------------------------- */
|
||||
int brotche_rand48_a(FloatImg *fimg, float ratio, float mval)
|
||||
{
|
||||
int nbpix, todo, foo;
|
||||
int x, y;
|
||||
float fval;
|
||||
|
||||
nbpix = fimg->width * fimg->height;
|
||||
todo = (int)((float)nbpix * ratio);
|
||||
if (verbosity > 1) {
|
||||
fprintf(stderr, "%s: ratio %f nbpix %d todo %d\n", __func__,
|
||||
ratio, nbpix, todo);
|
||||
}
|
||||
|
||||
for (foo=0; foo<todo; foo++)
|
||||
{
|
||||
fval = (float)drand48() * mval;
|
||||
x = rand() % fimg->width;
|
||||
y = rand() % fimg->height;
|
||||
fimg_plot_rgb(fimg, x, y, fval, fval, fval);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int brotche_rand48_b(FloatImg *fimg, float ratio, float mval)
|
||||
{
|
||||
int nbpix, todo, foo;
|
||||
int x, y;
|
||||
float fval;
|
||||
|
||||
nbpix = fimg->width * fimg->height;
|
||||
todo = (int)((float)nbpix * ratio);
|
||||
if (verbosity > 1) {
|
||||
fprintf(stderr, "%s: ratio %f nbpix %d todo %d\n", __func__,
|
||||
ratio, nbpix, todo);
|
||||
}
|
||||
|
||||
for (foo=0; foo<todo; foo++)
|
||||
{
|
||||
fval = (float)drand48() * mval;
|
||||
x = 1 + (rand() % (fimg->width-2));
|
||||
y = rand() % fimg->height;
|
||||
fimg_plot_rgb(fimg, x-1, y, fval, 0.0, 0.0);
|
||||
fimg_plot_rgb(fimg, x , y, 0.0, 0.0, fval);
|
||||
fimg_plot_rgb(fimg, x+1, y, 0.0, fval, 0.0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
26
extras/Fonderie/sfx.h
Normal file
26
extras/Fonderie/sfx.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* sfx.h - special effects for fonderie & interpolator
|
||||
* ---------------------------------------------------
|
||||
*/
|
||||
|
||||
int incrustation_vignette(FloatImg *src, FloatImg *dst, int k);
|
||||
|
||||
|
||||
int trinitron(FloatImg *pimg, int notused);
|
||||
|
||||
int bouger_les_pixels(FloatImg *pimg, int kaboo);
|
||||
int octotree_classif(FloatImg *pimg, float fk, int notused);
|
||||
|
||||
int mirror_split(FloatImg *pimg, int kaboo);
|
||||
int upside_down(FloatImg *pimg);
|
||||
|
||||
int des_bords_sombres_a(FloatImg *pimg, int offset);
|
||||
int des_bords_sombres_b(FloatImg *pimg, int offset);
|
||||
|
||||
int brotche_rand48_a(FloatImg *fimg, float ratio, float mval);
|
||||
int brotche_rand48_b(FloatImg *fimg, float ratio, float mval);
|
||||
int colors_brotcher(FloatImg *fimg, float fval);
|
||||
|
||||
/*
|
||||
* see also "crapulator.h" for some #define's
|
||||
*/
|
||||
110
extras/Fonderie/single.c
Normal file
110
extras/Fonderie/single.c
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
SINGLE
|
||||
experimental and/or testing code, do not use in
|
||||
production.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
#include "sfx.h"
|
||||
#include "filterstack.h"
|
||||
#include "crapulator.h"
|
||||
#include "single.h"
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* singleton/private variables
|
||||
*/
|
||||
static int nextpng, counter;
|
||||
static char *destination;
|
||||
static int chainfilter;
|
||||
static int outtype;
|
||||
|
||||
/* and the classic global var */
|
||||
extern int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
int single_init(int next, char *dest, int fxchain, int outfmt)
|
||||
{
|
||||
int foo;
|
||||
struct stat stbuf;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %d '%s' %d %d )\n", __func__,
|
||||
next, dest, fxchain, outfmt);
|
||||
#endif
|
||||
|
||||
nextpng = next;
|
||||
chainfilter = fxchain;
|
||||
|
||||
foo = stat(dest, &stbuf);
|
||||
if (foo) {
|
||||
perror("stat dest dir");
|
||||
return -2;
|
||||
}
|
||||
if (S_IFDIR != (stbuf.st_mode & S_IFMT)) {
|
||||
fprintf(stderr, "! %s must be a directory\n", dest);
|
||||
return -3;
|
||||
}
|
||||
|
||||
destination = strdup(dest); /* have a static copy */
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int single_push_picture(FloatImg *pimg)
|
||||
{
|
||||
int foo;
|
||||
char line[1000], buff[100];
|
||||
char *extension = "png";
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p )\n", __func__, pimg);
|
||||
#endif
|
||||
|
||||
strncpy(line, destination, 100);
|
||||
if ('/' != line[strlen(line)-1]) {
|
||||
// fprintf(stderr, "adding '/'\n");
|
||||
strcat(line, "/");
|
||||
}
|
||||
|
||||
sprintf(buff, "%05d.%s", nextpng, extension);
|
||||
strcat(line, buff);
|
||||
|
||||
// fprintf(stderr, "writing %p to '%s'\n", pimg, line);
|
||||
foo = fimg_export_picture(pimg, line, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d on export\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
nextpng++; counter++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int single_print_state(char *title, int k)
|
||||
{
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, title, k);
|
||||
#endif
|
||||
|
||||
fprintf(stderr, "%s : %s\n", __FILE__, title);
|
||||
fprintf(stderr, " nextpng %d\n", nextpng);
|
||||
fprintf(stderr, " counter %d\n", counter);
|
||||
fprintf(stderr, " chainfilter %d\n", chainfilter);
|
||||
|
||||
fprintf(stderr, " destination %s\n", destination);
|
||||
|
||||
if (k) {
|
||||
/* XXX */
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
21
extras/Fonderie/single.h
Normal file
21
extras/Fonderie/single.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
SINGLE
|
||||
experimental and/or testing code, do not use in
|
||||
serious production.
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* next:
|
||||
* dest:
|
||||
* fxchain:
|
||||
* outfmt: see floatimg.h for FILE_TYPE_XXX constants
|
||||
*/
|
||||
int single_init(int next, char *dest, int fxchain, int outfmt);
|
||||
|
||||
int single_push_picture(FloatImg *pimg);
|
||||
|
||||
int single_print_state(char *title, int k);
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
221
extras/Fonderie/singlepass.c
Normal file
221
extras/Fonderie/singlepass.c
Normal file
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* +-------------------------+
|
||||
* | S I N G L E P A S S |
|
||||
* +-------------------------+
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <glob.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
#include "crapulator.h"
|
||||
#include "filterstack.h"
|
||||
#include "single.h"
|
||||
#include "glitches.h"
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
#define FILTERS 0
|
||||
|
||||
int verbosity;
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
int run_the_singlepass(char *globber, char *destdir, int duplic,
|
||||
int fchain, int outfmt)
|
||||
{
|
||||
FloatImg image = { 0 };
|
||||
int idx, foo, loop;
|
||||
glob_t globbuf;
|
||||
char *fname;
|
||||
double elapsed;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' %d %d )\n", __func__,
|
||||
globber, destdir, fchain, outfmt);
|
||||
#endif
|
||||
|
||||
// filterstack_list(fchain, "Run the single pass");
|
||||
|
||||
(void)fimg_timer_set(0);
|
||||
|
||||
foo = single_init(0, destdir, fchain, outfmt);
|
||||
if (foo) {
|
||||
fprintf(stderr, "erreur %d single_init\n", foo);
|
||||
return foo;
|
||||
}
|
||||
// single_print_state("just after init", 0);
|
||||
|
||||
memset(&globbuf, 0, sizeof(glob_t));
|
||||
foo = glob(globber, 0, NULL, &globbuf);
|
||||
// fprintf(stderr, "globbing '%s' -> %d, %d files found\n",
|
||||
// globber, foo, (int)globbuf.gl_pathc);
|
||||
switch (foo) {
|
||||
case GLOB_NOSPACE:
|
||||
fprintf(stderr, "%s: glob run out of memory\n", __func__);
|
||||
break;
|
||||
case GLOB_ABORTED:
|
||||
fprintf(stderr, "%s: glob read error\n", __func__);
|
||||
break;
|
||||
case GLOB_NOMATCH:
|
||||
fprintf(stderr, "%s: glob found no matches\n", __func__);
|
||||
break;
|
||||
}
|
||||
|
||||
if (0 == globbuf.gl_pathc) {
|
||||
fprintf(stderr, "%s: no file found, aborting\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (idx=0; idx<globbuf.gl_pathc; idx++) {
|
||||
|
||||
fname = globbuf.gl_pathv[idx]; /* alias of filename */
|
||||
|
||||
if (0==image.width && 0==image.height) {
|
||||
foo = fimg_create_from_dump(fname, &image);
|
||||
}
|
||||
else {
|
||||
foo = fimg_load_from_dump(fname, &image);
|
||||
}
|
||||
if (foo) {
|
||||
fprintf(stderr, "get image -> %d\n", foo);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 == idx) {
|
||||
fprintf(stderr, "image size %dx%d\n",
|
||||
image.width, image.height);
|
||||
}
|
||||
|
||||
fprintf(stderr, " %6ld %s\r", (long)globbuf.gl_pathc-idx, fname);
|
||||
|
||||
foo = filterstack_run(fchain, &image, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: filterstack run --> %d\n",
|
||||
__func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
/* HERE WE CAN REPEAT THE INSERT OF THE PICZ */
|
||||
for (loop=0; loop<duplic; loop++) {
|
||||
foo = single_push_picture(&image);
|
||||
if (foo) {
|
||||
fprintf(stderr, "error %d on push_picture\n", foo);
|
||||
return foo;
|
||||
}
|
||||
if (loop) {
|
||||
/* this is just a wip XXX */
|
||||
microglitch(&image, loop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
globfree(&globbuf);
|
||||
|
||||
fimg_destroy(&image);
|
||||
single_print_state("end of run", 0);
|
||||
|
||||
elapsed = fimg_timer_get(0);
|
||||
fprintf(stderr, "%s: %ld frames, elapsed %.3f s, %.3f fps\n",
|
||||
__func__,
|
||||
(long)globbuf.gl_pathc, elapsed,
|
||||
(double)globbuf.gl_pathc/elapsed);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ----------------------------------------------------------- */
|
||||
static void help(void)
|
||||
{
|
||||
puts("------ Single pass serial filter ------\nusage:");
|
||||
|
||||
puts("\t-F\tdefine:the:filter:chain");
|
||||
puts("\t-g\tinput glob pattern");
|
||||
puts("\t-L\tlist available filters");
|
||||
puts("\t-O\t/output/directory (default ./p8)");
|
||||
puts("\t-r N\trepetiiing factor");
|
||||
// puts("\t-s\tdo single test");
|
||||
puts("\t-v\tspit more messages");
|
||||
|
||||
exit(0);
|
||||
}
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo, opt;
|
||||
char *filterchain = "none";
|
||||
char *globbing = "./capture/?????.fimg";
|
||||
char *outdir = "./p8";
|
||||
// char *outtype = ".png";
|
||||
int do_xper = 0;
|
||||
int repeat = 1;
|
||||
|
||||
fprintf(stderr, "*** %s : compiled %s %s\n", __FILE__,
|
||||
__DATE__, __TIME__);
|
||||
fimg_print_version(2);
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "\t/!\\ %s is option driven\n", argv[0]);
|
||||
help();
|
||||
}
|
||||
|
||||
while ((opt = getopt(argc, argv, "hF:g:LO:r:svx")) != -1) {
|
||||
switch (opt) {
|
||||
case 'h': help(); break;
|
||||
|
||||
case 'F': filterchain = optarg; break;
|
||||
case 'g': globbing = optarg; break;
|
||||
|
||||
case 'L':
|
||||
list_crapulors("available filters");
|
||||
exit(0);
|
||||
|
||||
case 'O': outdir = optarg; break;
|
||||
|
||||
case 'r': repeat = atoi(optarg); break;
|
||||
|
||||
case 'v': verbosity++; break;
|
||||
|
||||
case 'x': do_xper = 1; break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "%s ABEND\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (repeat < 1) {
|
||||
fprintf(stderr, "%s: loop %d invalid\n", argv[0], repeat);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
foo = parse_filter_chain(FILTERS, filterchain);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d in parse_filter_chain\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "\tpid %d\n", getpid());
|
||||
fprintf(stderr, "\tinput glob %s\n", globbing);
|
||||
fprintf(stderr, "\tfilter chain %s\n", filterchain);
|
||||
fprintf(stderr, "\toutput dir %s\n", outdir);
|
||||
fprintf(stderr, "\trepeat %d\n", repeat);
|
||||
// fprintf(stderr, "\toutput type %s\n", outtype);
|
||||
fprintf(stderr, "\tdo xper %d\n", do_xper);
|
||||
}
|
||||
|
||||
foo = run_the_singlepass(globbing, outdir, repeat,
|
||||
FILTERS, FILE_TYPE_PNG);
|
||||
fprintf(stderr, "\n\tRun the single pass --> %d\n", foo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
249
extras/Fonderie/t.c
Normal file
249
extras/Fonderie/t.c
Normal file
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* test des trucs
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <glob.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
#include "glitches.h"
|
||||
#include "sfx.h"
|
||||
#include "filterstack.h"
|
||||
#include "crapulator.h"
|
||||
#include "single.h"
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
int verbosity;
|
||||
|
||||
#define PNG "out.png"
|
||||
#define W 800
|
||||
#define H 600
|
||||
#define LMAX 255.0
|
||||
#define TIMER 1
|
||||
|
||||
#define STK 6
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
int essai_filterstack(char *fIname, char *fOname)
|
||||
{
|
||||
int foo;
|
||||
FloatImg image;
|
||||
double debut, fin;
|
||||
|
||||
// filterstack_list(STK, __func__);
|
||||
|
||||
foo = fimg_create_from_dump(fIname, &image);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d create image\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
srand(getpid()); srand48(getpid());
|
||||
|
||||
debut = fimg_timer_set(TIMER);
|
||||
|
||||
foo = filterstack_run(STK, &image, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "filterstack run --> %d\n", foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
fin = fimg_timer_set(TIMER);
|
||||
|
||||
foo = fimg_export_picture(&image, fOname, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "erreur export %d\n", foo);
|
||||
}
|
||||
|
||||
fprintf(stderr, "elapsed %f\n", fin-debut);
|
||||
|
||||
fimg_destroy(&image);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ----------------------------------------------------------- */
|
||||
/*
|
||||
* test-only function !
|
||||
|
||||
foo = essayer_single("capture/???42.fimg", "/tmp/x8/", STK);
|
||||
fprintf(stderr, "essayer single -> %d\n", foo);
|
||||
|
||||
|
||||
*/
|
||||
int essayer_single(char *globpattern, char *destdir, int chain)
|
||||
{
|
||||
FloatImg image = { 0 };
|
||||
int idx, foo;
|
||||
glob_t globbuf;
|
||||
char *fname;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__,
|
||||
globpattern, destdir, chain);
|
||||
#endif
|
||||
|
||||
filterstack_list(chain, "essai du single");
|
||||
|
||||
foo = single_init(0, destdir, chain, -1);
|
||||
if (foo) {
|
||||
fprintf(stderr, "erreur %d single_init\n", foo);
|
||||
return foo;
|
||||
}
|
||||
single_print_state("just after init", 0);
|
||||
|
||||
memset(&globbuf, 0, sizeof(glob_t));
|
||||
foo = glob(globpattern, 0, NULL, &globbuf);
|
||||
fprintf(stderr, "globbing '%s' -> %d, %d files found\n",
|
||||
globpattern, foo, (int)globbuf.gl_pathc);
|
||||
if (0 == globbuf.gl_pathc) {
|
||||
fprintf(stderr, "%s : no file found, aborting\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (idx=0; idx<globbuf.gl_pathc; idx++) {
|
||||
|
||||
fname = globbuf.gl_pathv[idx]; /* alias of filename */
|
||||
fprintf(stderr, "%s %6d %s\r", __func__, idx, fname);
|
||||
|
||||
if (0==image.width && 0==image.height) {
|
||||
foo = fimg_create_from_dump(fname, &image);
|
||||
}
|
||||
else {
|
||||
foo = fimg_load_from_dump(fname, &image);
|
||||
}
|
||||
if (foo) {
|
||||
fprintf(stderr, "get image -> %d\n", foo);
|
||||
return -1;
|
||||
}
|
||||
|
||||
foo = filterstack_run(chain, &image, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: filterstack run --> %d\n",
|
||||
__func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
foo = single_push_picture(&image);
|
||||
if (foo) {
|
||||
fprintf(stderr, "erreur %d push picture\n", foo);
|
||||
return foo;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
single_print_state("end of run :)", 0);
|
||||
|
||||
fimg_destroy(&image);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
int help(void)
|
||||
{
|
||||
puts("Yolo!");
|
||||
|
||||
puts("\t-F\tdefine:the:filter:chain");
|
||||
puts("\t-g\tinput glob pattern");
|
||||
puts("\t-i\tinfile.fimg");
|
||||
puts("\t-L\tlist available filters");
|
||||
puts("\t-o\toutfile.xxx");
|
||||
puts("\t-O\t/output/directory");
|
||||
puts("\t-s\tdo single test");
|
||||
|
||||
exit(0);
|
||||
}
|
||||
/* ----------------------------------------------------------- */
|
||||
int experiment(void)
|
||||
{
|
||||
int foo;
|
||||
FloatImg image, dest;
|
||||
|
||||
fprintf(stderr, "EXPERIMENT\n");
|
||||
|
||||
foo = fimg_create_from_dump("01137.fimg", &image);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d on create\n", __func__, foo);
|
||||
return -1;
|
||||
}
|
||||
|
||||
foo = fimg_clone(&image, &dest, 1);
|
||||
foo = fimg_copy_data(&image, &dest);
|
||||
|
||||
incrustation_vignette(&image, &dest, 0);
|
||||
|
||||
fimg_export_picture(&dest, "foo.png", 0);
|
||||
|
||||
exit(0); /* back to real world */
|
||||
}
|
||||
/* ----------------------------------------------------------- */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo, opt;
|
||||
int do_xper = 0;
|
||||
int do_single = 0;
|
||||
char *filterchain = "0";
|
||||
char *infile = "mire.fimg";
|
||||
char *outfile = PNG;
|
||||
char *outdir = "/tmp/x8/";
|
||||
char *globstr = "capture/????7.fimg";
|
||||
|
||||
fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", __FILE__,
|
||||
__DATE__, __TIME__);
|
||||
fimg_print_version(2);
|
||||
|
||||
while ((opt = getopt(argc, argv, "hF:g:i:Lo:O:svx")) != -1) {
|
||||
switch(opt) {
|
||||
case 'h': help(); break;
|
||||
case 'F': filterchain = optarg; break;
|
||||
case 'g': globstr = optarg; break;
|
||||
case 'i': infile = optarg; break;
|
||||
case 'L':
|
||||
list_crapulors("available filters");
|
||||
exit(0);
|
||||
case 'o': outfile = optarg; break;
|
||||
case 'O': outdir = optarg; break;
|
||||
case 's': do_single = 1; break;
|
||||
case 'v': verbosity++; break;
|
||||
case 'x': do_xper = 1; break;
|
||||
default: exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s : argc = %d, optind = %d\n", argv[0], argc, optind);
|
||||
#endif
|
||||
|
||||
foo = parse_filter_chain(STK, filterchain);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d in parse_filter_chain\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (do_xper) {
|
||||
experiment();
|
||||
return 0;
|
||||
}
|
||||
if (do_single) {
|
||||
fprintf(stderr, "Globbing '%s'\n", globstr);
|
||||
essayer_single(globstr, outdir, STK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
foo = essai_filterstack(infile, outfile);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d in essai_filterstack\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
Reference in New Issue
Block a user