filters now have a name

This commit is contained in:
Tonton Th 2020-12-30 14:42:44 +01:00
parent 1693ad9051
commit a31e51a234
12 changed files with 178 additions and 96 deletions

View File

@ -17,7 +17,7 @@ all: fonderie interpolator t
# ---------------------------------------------------------
t: t.c Makefile ${OBJS}
gcc ${COPT} $< ${OBJS} ${LIBS} -o $@
gcc ${COPT} $< ${OBJS} ${LIBS} -ltiff -lcfitsio -o $@
# ---------------------------------------------------------
#

View File

@ -20,6 +20,17 @@ destinés à 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. En principe,
l'option `-L` 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.
`mirsplit:ctr2x2:3:killlines`
Nous allons donc voir quelques exemples un peu plus loin.
## Fonderie
@ -32,26 +43,24 @@ Rassurez-vous, en général il est wrappable dans des scripts
paramètres dans `$(env)`.
```
tth@delirium:~/Devel/FloatImg/Fonderie$ ./fonderie -h
*** ./fonderie :
compiled by tTh, Nov 3 2020 03:42:29
pid 3424
*** FloatImg library, alpha v112 (Nov 2 2020, 00:31:33)
./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
-E input effect chain
-F output effect chain
```
## exemple d'utilisation
Voici comment appeler ce truc depuis la ligne de commande
tel qu'il m'arrive de pratiquer :
Voici comment appeler cette machinerie depuis la ligne de commande
tel qu'il m'arrive de le pratiquer :
```
#!/bin/bash
@ -60,10 +69,11 @@ GRABDIR="/spool/tth/fonderie"
FONDEUR="$HOME/Devel/FloatImg/Fonderie/fonderie"
GLOB=${GRABDIR}'/?????.fimg'
${FONDEUR} -T 40 -I "$GLOB" -E 10 -T 30 -F 2:7
${FONDEUR} -I "$GLOB" -E cos01:25 -T 30 -F 2:classtrial
```
Votre machine va maintenant mouliner avec entrain, et
Votre machine va maintenant mouliner avec entrain et persévérence,
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 :

View File

@ -1,11 +1,13 @@
#!/usr/bin/awk -f
BEGIN {
print "// -----------------------------------"
print "// generated file, do not edit by hand !"
print "// -----------------------------------"
}
{
printf "#define CR_%s %d\n", $2, $1
printf "#define CR_%s (%d)\n", $2, $1
}
END {

View File

@ -1,13 +1,19 @@
#!/usr/bin/awk -f
BEGIN {
print "// generated file, do not edit by hand"
print "// -----------------------------------"
print "// generated file, do not edit by hand";
print "// -----------------------------------"
print "Crapulor CrapL[] = {";
}
{
printf "char str_%s[] = \"%s\" ;\t\t// %d\n", $2, $2, $1
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"
}

View File

@ -4,6 +4,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <floatimg.h>
@ -129,92 +131,99 @@ if (666==count) {
#endif
switch (idFx) {
case 0: /* DO NOTHING */
case CR_none: /* DO NOTHING */
retval = 0; break;
case 1:
case CR_cos01:
fimg_cos_01(image, image,
fimg_get_maxvalue(image));
break;
case 2:
case CR_cos010:
fimg_cos_010(image, image,
fimg_get_maxvalue(image));
break;
case 3:
case CR_fx3:
retval = effect_3(image);
break;
case 4:
case CR_rnd48a:
brotche_rand48_a(image, 0.20,
fimg_get_maxvalue(image));
break;
case 5:
case CR_rnd48b:
brotche_rand48_b(image, 0.10,
fimg_get_maxvalue(image)*0.8);
break;
case 6:
case CR_killcola:
retval = fimg_killcolors_a(image, 0.0);
break;
case 7:
case CR_colmixa:
retval = fimg_colors_mixer_a(image, 2.0);
break;
case 8:
case CR_ctr2x2:
retval = insitu_ctr2x2(image);
break;
case 9:
case CR_classtrial:
retval = fimg_classif_trial(image, image, 0.37, 0);
break;
case 10:
case CR_binarize:
retval = binarize(image, 0);
break;
case 11:
case CR_trinarize:
retval = trinarize(image, 0);
break;
case 12:
case CR_liss2x2:
retval = fimg_lissage_2x2(image);
(void)fimg_killborders(image);
break;
case 13:
case CR_liss3x3:
/* smooth filter */
retval = insitu_filtre3x3(image, 0);
break;
case 14:
case CR_desaturate:
retval = fimg_desaturate(image, image, 0);
break;
case 15:
case CR_killlines:
retval = kill_a_few_lines(image, fval,
image->height/20);
break;
case 16:
case CR_water:
retval = bouger_les_pixels(image, 8);
break;
case 17:
case CR_mirsplit:
retval = mirror_split(image, 0);
break;
case 18:
case CR_updown:
retval = upside_down(image);
break;
case 19:
case CR_hipass:
/* hipass filter */
retval = insitu_filtre3x3(image, 1);
break;
case 20:
case CR_octotree:
retval = octotree_classif(image, 0.500, 0);
break;
/* here are the glitches */
case 24: /* experiment ! */
case CR_bsombra: /* experiment ! */
retval = des_bords_sombres_a(image, 160);
break;
case 25:
case CR_vsglitch:
/* please make this function more tweakable */
retval = vertical_singlitch(image, 290+rand()%45,
fval, 0.19, 0);
fval, 0.19, 0);
break;
case 26:
case CR_rndblks:
retval = random_blocks(image, 70);
break;
case CR_message:
fprintf(stderr, "### message from pid %d, fv=%f ###\n",
getpid(), fval);
retval = 0;
break;
default :
fprintf(stderr, "%s : effect #%d invalid\n",
__func__, idFx);
@ -241,54 +250,38 @@ typedef struct {
int flags;
} Crapulor;
#include "crapstr.h"
Crapulor CrapL[] = {
{ CR_none, str_none },
{ CR_cos01, str_cos01 },
{ CR_cos010, str_cos010 },
{ CR_fx3, str_fx3 },
{ CR_end, str_end }
};
/* Warning: overengeniring inside */
#include "crapstr.h" /* generated file ! */
#define NBCRAP (sizeof(CrapL)/sizeof(Crapulor))
void list_crapulors(char *texte)
{
int idx;
for (idx=0; idx<NBCRAP; idx++) {
fprintf(stderr, "%3d : %3d %-12s %5d %f\n", idx,
CrapL[idx].id,
#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)
{
switch (num) {
case 0: return "none";
case 1: return "cos01";
case 2: return "cos010";
case 6: return "killcola";
case 7: return "colmixa";
case 8: return "ctr2x2";
case 9: return "classif0";
case 10: return "binariz";
case 11: return "trinariz";
case 12: return "smoo2x2";
case 13: return "fltr3x3";
case 14: return "desatur";
case 15: return "killines";
int idx;
case 18: return "updown";
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %d )\n", __func__, num);
#endif
case 20: return "octoclass";
case 25: return "vsglitch";
for (idx=0; CrapL[idx].id!=-1; idx++) {
if (num == CrapL[idx].id) {
return CrapL[idx].name;
}
}
return "???";
@ -296,8 +289,26 @@ return "???";
/* -------------------------------------------------------------- */
int crap_number_from_name(char *name)
{
int idx, foo, retval;
return -1;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, name);
#endif
retval = -1; /* not found */
for (idx=0; CrapL[idx].id!=-1; idx++) {
foo = strcmp(CrapL[idx].name, name);
if (0 == foo) {
// fprintf(stderr, "found '%s' -> %d\n", name,
// CrapL[idx].id);
retval = CrapL[idx].id;
break;
}
}
return retval; /* not found */
}
/* -------------------------------------------------------------- */

View File

@ -1,5 +1,26 @@
0 none
1 cos01
2 cos010
3 fx3
-1 end
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
24 bsombra 1 1.0
25 vsglitch 1 1.0
26 rndblks 1 1.0
99 message 1 1.0
-1 end 1 1.0

View File

@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <alloca.h>
#include "../floatimg.h"
@ -174,7 +175,9 @@ if (numid < 0 || numid > NUMBER_OF_STACK) {
exit(1);
}
#if DEBUG_LEVEL
fprintf(stderr, "\n%s: arg = '%s'\n", __func__, argument);
#endif
foo = filterstack_init(numid, 8);
if (foo) {
@ -201,6 +204,14 @@ for (;;) {
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);
foo = filterstack_add(numid, value, 1, 1.0);
continue;
}
if ('@' == cptr[0]) {
fprintf(stderr, "%s: got indirect '%s'\n", __func__,
cptr+1);

View File

@ -171,15 +171,14 @@ void help(void)
{
puts("\tFONDERIE\noptions:");
puts("\t-E input:filter:chain");
puts("\t-F output:filter:chain");
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");
puts("\t-w\tinput effect");
puts("\t-x\toutput effect");
exit(0);
}
@ -197,11 +196,11 @@ int blanks = 20;
char *InFchain = "0";
char *OutFchain = "0";
fprintf(stderr, "*** %s :\n\tcompiled by tTh, %s %s\n\tpid %d\n",
fprintf(stderr, "%s, compiled %s, %s, pid %d\n",
argv[0], __DATE__, __TIME__, getpid());
fimg_print_version(2);
while ((opt = getopt(argc, argv, "B:E:F:ghI:O:s:T:vw:x:")) != -1) {
while ((opt = getopt(argc, argv, "B:E:F:ghI:LO:s:T:vw:x:")) != -1) {
switch(opt) {
case 'E': InFchain = optarg; break;
case 'F': OutFchain = optarg; break;
@ -213,6 +212,9 @@ while ((opt = getopt(argc, argv, "B:E:F:ghI:O:s:T:vw:x:")) != -1) {
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);

View File

@ -250,6 +250,7 @@ puts("usage:\n\tinterpolator [options] <inglob> <outdir> <nbsteep>");
puts("options:");
puts("\t-S nn\tmysterious sort");
puts("\t-F i:j\tfilter chain");
puts("\t-L\tlist available filters");
puts("\t-w nn\tinput effect");
puts("\t-x nn\toutput effect");
puts("\t-v\tincrease verbosity");
@ -278,11 +279,14 @@ for (foo=0; foo<argc; foo++)
fprintf(stderr, "%5d %s\n", foo, argv[foo]);
//#endif
while ((opt = getopt(argc, argv, "E:F:hS:vw:x:")) != -1) {
while ((opt = getopt(argc, argv, "E:F:hLS:vw:x:")) != -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 'w': inFx = atoi(optarg); break;

View File

@ -1,4 +1,4 @@
'help system' pour l'explication des divers filtres.
pipeliner le graber et le fondeur par la SHM ?

View File

@ -53,7 +53,7 @@ if (foo) {
fprintf(stderr, "oups %d in get minmax\n", foo);
return foo;
}
if (verbosity>1) fimg_print_minmax(mm, "input pic");
if (verbosity>1) fimg_print_minmax(mm, " input pic ");
/*
* compute the 8 center points
@ -86,7 +86,7 @@ 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) );
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;
@ -100,8 +100,10 @@ for (idx=0; idx<sz; idx++) {
}
}
fprintf(stderr, "%s: %d/%d pixels, ratio %f\n", __func__, count, sz,
if (verbosity > 1) {
fprintf(stderr, "%s: %d/%d pixels, ratio %f\n", __func__, count, sz,
(float)count/(float)sz);
}
return 0;
}

View File

@ -28,15 +28,15 @@ int convert_to_gray; /* WTF ? */
/* ----------------------------------------------------------- */
int essai_filterstack(char *fname)
int essai_filterstack(char *fIname, char *fOname)
{
int foo;
FloatImg image;
double debut, fin;
filterstack_list(STK, __func__);
// filterstack_list(STK, __func__);
foo = fimg_create_from_dump(fname, &image);
foo = fimg_create_from_dump(fIname, &image);
if (foo) {
fprintf(stderr, "err %d create image\n", foo);
exit(1);
@ -54,7 +54,7 @@ if (foo) {
fin = fimg_timer_set(TIMER);
foo = fimg_save_as_png(&image, "foo.png", 0);
foo = fimg_export_picture(&image, fOname, 0);
if (foo) {
fprintf(stderr, "erreur export %d\n", foo);
}
@ -74,10 +74,20 @@ exit(0);
/* ----------------------------------------------------------- */
void experiment(void)
{
int foo;
fprintf(stderr, "EXPERIMENT\n");
list_crapulors("experiment");
#if 0
foo = crap_number_from_name("cos01");
fprintf(stderr, "name cos01 -> %d\n", foo);
foo = crap_number_from_name("xxxxx");
fprintf(stderr, "name xxxxx -> %d\n", foo);
#endif
exit(0); /* back to real world */
}
/* ----------------------------------------------------------- */
@ -85,17 +95,20 @@ int main(int argc, char *argv[])
{
int foo;
int opt;
char *filterchain = "18";
char *filterchain = "0";
char *infile = "mire.fimg";
char *outfile = "out.png";
fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", __FILE__,
__DATE__, __TIME__);
fimg_print_version(2);
while ((opt = getopt(argc, argv, "hF:vx")) != -1) {
while ((opt = getopt(argc, argv, "hF:i:o:vx")) != -1) {
switch(opt) {
case 'h': help(); break;
case 'F': filterchain = optarg; break;
case 'i': infile = optarg; break;
case 'o': outfile = optarg; break;
case 'v': verbosity++; break;
case 'x': experiment(); break;
default: exit(1);
@ -112,7 +125,7 @@ if (foo) {
exit(1);
}
foo = essai_filterstack(infile);
foo = essai_filterstack(infile, outfile);
if (foo) {
fprintf(stderr, "err %d in essai_filterstack\n", foo);
exit(1);