je crois que je suis en train de foutre la grouille...

This commit is contained in:
tonton th 2021-02-23 11:31:03 +01:00
commit dc4f2f8089
11 changed files with 116 additions and 36 deletions

1
.gitignore vendored
View File

@ -67,6 +67,7 @@ Fonderie/*.o
Fonderie/*.png Fonderie/*.png
Fonderie/*.pnm Fonderie/*.pnm
Fonderie/*.gif Fonderie/*.gif
Fonderie/*.fimg
Fonderie/fonderie Fonderie/fonderie
Fonderie/interpolator Fonderie/interpolator
Fonderie/t Fonderie/t

View File

@ -14,6 +14,8 @@
#include "glitches.h" #include "glitches.h"
#include "sfx.h" #include "sfx.h"
extern int verbosity;
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
static int trier_les_pixels(FloatImg *pimg) static int trier_les_pixels(FloatImg *pimg)
{ {
@ -76,7 +78,7 @@ return 0;
static int insitu_filtre3x3(FloatImg *pimg, int typef) static int insitu_filtre3x3(FloatImg *pimg, int typef)
{ {
FloatImg img; FloatImg img;
int retval; int foo, retval;
FimgFilter3x3 *pfiltre; FimgFilter3x3 *pfiltre;
FimgFilter3x3 lowpass = { FimgFilter3x3 lowpass = {
@ -97,9 +99,19 @@ FimgFilter3x3 hipass = {
1.0, 0.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, 4.0
};
switch (typef) { switch (typef) {
case 0: pfiltre = &lowpass; break; case 0: pfiltre = &lowpass; break;
case 1: pfiltre = &hipass; break; case 1: pfiltre = &hipass; break;
case 2: pfiltre = &diagonal; break;
default: default:
fprintf(stderr, "%s: bad filter number %d\n", fprintf(stderr, "%s: bad filter number %d\n",
__func__, typef); __func__, typef);
@ -114,7 +126,14 @@ if (retval) {
fprintf(stderr, "%s error %d on filter\n", __func__, retval); fprintf(stderr, "%s error %d on filter\n", __func__, retval);
exit(1); exit(1);
} }
fimg_killborders(&img); /* XXX WTF OMG */ /** may be, we can check for negative values ? */
if (verbosity > 1) {
foo = fimg_count_negativ(&img);
fprintf(stderr, "%s -> %d / %d negative pixels\n", __func__,
foo, img.width*img.height);
}
fimg_killborders(&img);
fimg_copy_data(&img, pimg); fimg_copy_data(&img, pimg);
fimg_destroy(&img); fimg_destroy(&img);
@ -194,7 +213,7 @@ switch (idFx) {
break; break;
case CR_liss2x2: case CR_liss2x2:
retval = fimg_lissage_2x2(image); retval = fimg_lissage_2x2(image);
(void)fimg_killborders(image); // (void)fimg_killborders(image);
break; break;
case CR_liss3x3: case CR_liss3x3:
/* smooth filter */ /* smooth filter */
@ -220,6 +239,9 @@ switch (idFx) {
/* hipass filter */ /* hipass filter */
retval = insitu_filtre3x3(image, 1); retval = insitu_filtre3x3(image, 1);
break; break;
case CR_diagonal:
retval = insitu_filtre3x3(image, 2);
break;
case CR_octotree: case CR_octotree:
retval = octotree_classif(image, 0.500, 0); retval = octotree_classif(image, 0.500, 0);
break; break;

View File

@ -26,6 +26,7 @@
27 shiftln0 1 1.0 27 shiftln0 1 1.0
28 qsortrgb 2 1.0 28 qsortrgb 2 1.0
30 multidots 100 1.333 30 multidots 100 1.333
31 diagonal 1 1.0
42 nothing 42 3.1415926 42 nothing 42 3.1415926
99 message 1 1.0 99 message 1 1.0
-1 end 1 1.0 -1 end 1 1.0

View File

@ -9,7 +9,8 @@ FILTRES=$(./t -L | awk 'NR>1 { print $1 }' | sort)
rm /tmp/fstack*.png rm /tmp/fstack*.png
SRC=$(ls -rt1 $HOME/Essais/FondageDePlomb/capture/* | tail -1) # SRC=$(ls -rt1 $HOME/Essais/FondageDePlomb/capture/* | tail -1)
SRC=mire.fimg
for F in $FILTRES for F in $FILTRES
do do
@ -53,6 +54,6 @@ ffmpeg -nostdin \
# ------------------------------------------------------------ # ------------------------------------------------------------
# MAIN # MAIN
essai_singlepass essai_filtres
# ------------------------------------------------------------ # ------------------------------------------------------------

View File

@ -120,10 +120,6 @@ int insert_picture(FloatImg *src)
FloatImg *dst; FloatImg *dst;
int nbre; int nbre;
/*
* this is the where we can insert the 'input filter'
*/
dst = &g_fifo.slots[g_fifo.next]; dst = &g_fifo.slots[g_fifo.next];
nbre = dst->width * dst->height * sizeof(float); nbre = dst->width * dst->height * sizeof(float);

View File

@ -43,20 +43,49 @@ int insert_blank(FloatImg *image, int nbre, int pproc,
float fval, char *outd) float fval, char *outd)
{ {
int idx, foo; int idx, foo;
int preloaded = 0;
FloatImg blank;
char *fname;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d %d %f '%s' )\n", __func__,
image, nbre, pproc, fval, outd);
#endif
if (NULL != (fname=getenv("BLANK_FIMG"))) {
fprintf(stderr,"%s: try to load %s\n", __func__, fname);
fimg_clone(image, &blank, 1);
foo = fimg_load_from_dump(fname, &blank);
if (foo) {
fprintf(stderr, "epic fail %d on %s\n", foo, fname);
exit(1);
}
if (verbosity) fimg_describe(&blank, "Blank pic");
preloaded = 1;
}
fimg_clear(image); fimg_clear(image);
for (idx=0; idx<nbre; idx++) { for (idx=0; idx<nbre; idx++) {
fimg_vdeg_a(image, fval); if (preloaded) {
// brotche_rand48_b(image, drand48()*0.10, 1e5); fimg_copy_data(&blank, image);
}
else {
fimg_hdeg_a(image, fval);
}
if ((foo=traite_une_image(image, pproc, 1, outd))) { if ((foo=traite_une_image(image, pproc, 1, outd))) {
fprintf(stderr, "%s : err %d from 'traite_une_image'\n", fprintf(stderr, "%s : err %d from 'traite_une_image'\n",
__func__, foo); __func__, foo);
break; break;
} }
printf("\t%c\r", "ABCDEF"[idx%6]); fflush(stdout); printf("\t%c\r", "ABCDEFGH"[idx%8]); fflush(stdout);
} }
puts(""); puts("");
if (preloaded) {
fimg_destroy(&blank);
}
return 0; return 0;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */

View File

@ -3,7 +3,7 @@
* ugly code from tTh * ugly code from tTh
*/ */
#define FIMG_VERSION 118 #define FIMG_VERSION 119
/* /*
* in memory descriptor * in memory descriptor

View File

@ -48,7 +48,7 @@ for (y=1; y < h-1; y++) {
M[7] * pr[of+w] + M[7] * pr[of+w] +
M[8] * pr[of+(w-1)] ; M[8] * pr[of+(w-1)] ;
dst->R[of] = dval; dst->R[of] = dval + filtr->offset;
dval = M[0] * pg[of-(w+1)] + dval = M[0] * pg[of-(w+1)] +
M[1] * pg[of-w] + M[1] * pg[of-w] +
@ -60,7 +60,7 @@ for (y=1; y < h-1; y++) {
M[7] * pg[of+w] + M[7] * pg[of+w] +
M[8] * pg[of+(w-1)] ; M[8] * pg[of+(w-1)] ;
dst->G[of] = dval; dst->G[of] = dval + filtr->offset;
dval = M[0] * pb[of-(w+1)] + dval = M[0] * pb[of-(w+1)] +
M[1] * pb[of-w] + M[1] * pb[of-w] +
@ -72,7 +72,7 @@ for (y=1; y < h-1; y++) {
M[7] * pb[of+w] + M[7] * pb[of+w] +
M[8] * pb[of+(w-1)] ; M[8] * pb[of+(w-1)] ;
dst->B[of] = dval; dst->B[of] = dval + filtr->offset;
} }
} }
@ -189,7 +189,6 @@ if (foo) {
return foo; return foo;
} }
/* XXX */
fimg_killborders(img); fimg_killborders(img);
return foo; return foo;

View File

@ -323,7 +323,7 @@ FimgFilter3x3 filter_a = {
{ 1.0, 1.0, 1.0, { 1.0, 1.0, 1.0,
1.0, -3.0, 1.0, 1.0, -3.0, 1.0,
1.0, 1.0, 1.0 }, 1.0, 1.0, 1.0 },
8.0, 0.0 9.0, 0.0
}; };
@ -336,6 +336,15 @@ FimgFilter3x3 filter_b = {
}; };
FimgFilter3x3 filter_c = {
{
2.0, 1.0, 0.0,
1.0, 0.0, -1.0,
0.0, -1.0, -2.0,
},
1.0, 8.0
};
if (NULL != infile) { if (NULL != infile) {
fprintf(stderr, "%s: loading %s\n", __func__, infile); fprintf(stderr, "%s: loading %s\n", __func__, infile);
foo = fimg_create_from_dump(infile, &src); foo = fimg_create_from_dump(infile, &src);
@ -351,6 +360,8 @@ else {
} }
// fimg_save_as_png(&src, "test.png", 0); // fimg_save_as_png(&src, "test.png", 0);
foo = fimg_count_negativ(&src);
fprintf(stderr, "%s: source have %d negs\n", __func__, foo);
foo = fimg_clone(&src, &dst, 0); foo = fimg_clone(&src, &dst, 0);
if (foo) { if (foo) {
@ -359,21 +370,27 @@ if (foo) {
} }
fimg_filter_3x3(&src, &dst, &filter_a); fimg_filter_3x3(&src, &dst, &filter_a);
foo = fimg_clamp_negativ(&dst); foo = fimg_clamp_negativ(&dst);
if (foo) { if (foo) {
fprintf(stderr, "clamped %d negative pixels\n", foo); fprintf(stderr, "A clamped %d negative pixels\n", foo);
} }
// foo = fimg_save_as_png(&dst, "f3x3a.png", 0); foo = fimg_save_as_png(&dst, "f3x3a.png", 0);
// foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0); // foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0);
fimg_filter_3x3(&src, &dst, &filter_b); fimg_filter_3x3(&src, &dst, &filter_b);
foo = fimg_clamp_negativ(&dst); foo = fimg_clamp_negativ(&dst);
if (foo) { if (foo) {
fprintf(stderr, "clamped %d negative pixels\n", foo); fprintf(stderr, "B clamped %d negative pixels\n", foo);
} }
// foo = fimg_save_as_png(&dst, "f3x3b.png", 0); foo = fimg_save_as_png(&dst, "f3x3b.png", 0);
// foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0);
fimg_filter_3x3(&src, &dst, &filter_c);
foo = fimg_clamp_negativ(&dst);
if (foo) {
fprintf(stderr, "C clamped %d negative pixels\n", foo);
}
foo = fimg_save_as_png(&dst, "f3x3b.png", 0);
// foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0); // foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0);
fimg_destroy(&src); fimg_destroy(&dst); fimg_destroy(&src); fimg_destroy(&dst);

View File

@ -16,33 +16,42 @@
int verbosity = 0; int verbosity = 0;
/* --------------------------------------------------------------------- */
void help(int k)
{
if (verbosity) fimg_print_version(k);
exit(0);
}
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
FloatImg fimg; FloatImg fimg;
int foo; int foo, opt;
/* while ((opt = getopt(argc, argv, "hv")) != -1) {
* pas de traitement des options ? switch(opt) {
*/ case 'v': verbosity++; break;
case 'h': help(1); exit(1);
}
}
if (3 != argc) { if (2 != argc-optind) {
fimg_print_version(1); fprintf(stderr, "error: %s need two filenames\n", argv[0]);
fprintf(stderr, "usage:\n\t%s foo.png bar.fimg\n", argv[0]);
exit(1); exit(1);
} }
memset(&fimg, 0, sizeof(FloatImg)); memset(&fimg, 0, sizeof(FloatImg));
foo = fimg_create_from_png(argv[1], &fimg); foo = fimg_create_from_png(argv[optind], &fimg);
if (foo) { if (foo) {
fprintf(stderr, "%s : err %d, abort.\n", argv[0], foo); fprintf(stderr, "%s : err %d, abort.\n", argv[0], foo);
exit(1); exit(1);
} }
if (verbosity) fimg_describe(&fimg, argv[2]); if (verbosity) fimg_describe(&fimg, argv[optind+1]);
foo = fimg_dump_to_file(&fimg, argv[2], 0); foo = fimg_dump_to_file(&fimg, argv[optind+1], 0);
if (foo) { if (foo) {
fprintf(stderr, "save as '%s' -> err %d\n", argv[2], foo); fprintf(stderr, "save as '%s' -> err %d\n", argv[2], foo);
exit(1); exit(1);

View File

@ -168,6 +168,11 @@ if (verbosity > 1) {
if (upscaling) fprintf(stderr, "upscaling is on\n"); if (upscaling) fprintf(stderr, "upscaling is on\n");
} }
if (upscaling && (nbre_capt%4)) {
fprintf(stderr, "WARN upscaling: %d bad nbre_capt\n",
nbre_capt);
}
fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0); fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0);
if (fd < 0) { if (fd < 0) {
perror(dev_name); perror(dev_name);