From b62b5a4805ce0cbf29e6bc815d7d214f5bc81eca Mon Sep 17 00:00:00 2001 From: tth Date: Wed, 20 Nov 2019 11:12:16 +0100 Subject: [PATCH] two new operators (mini & maxi) --- doc/notes.txt | 6 +++++ doc/the_floatimg_hack.tex | 10 +++++--- floatimg.h | 4 ++- lib/operators.c | 51 ++++++++++++++++++++++++++++++++++++++- lib/runme.sh | 10 +++++--- tools/fimgops.c | 12 +++++++-- 6 files changed, 83 insertions(+), 10 deletions(-) diff --git a/doc/notes.txt b/doc/notes.txt index abe14231..b91eb17d 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -10,4 +10,10 @@ [794365.892937] usb 4-5: SerialNumber: 00000 + Comment imprimer ce code trop gruik ? + +enscript -o - -Ec -f Courier9 -F Times-Roman14 --word-wrap \ + -i 6 --swap-even-page-margins v4l2_pr_structs.c | + ps2pdf - /media/tth/BLIRBOU/v4l2_pr_structs.pdf + diff --git a/doc/the_floatimg_hack.tex b/doc/the_floatimg_hack.tex index ed33f1df..e6037855 100644 --- a/doc/the_floatimg_hack.tex +++ b/doc/the_floatimg_hack.tex @@ -388,7 +388,9 @@ le calcul de la variance\index{variance}. \subsection{fimgops}\index{fimgops}\label{fimgops} -Operations diverses sur ou entre des images. +Operations diverses entre deeux images, qui doivent être +de la même taille, et du même type \textsl{pour le moment, +uniquement RGB}. \begin{verbatim} usage: @@ -398,14 +400,16 @@ operators: sub 2 mix 3 mul 4 + mini 5 + maxi 6 options: -g convert output to gray -k N.N set float value -v increase verbosity \end{verbatim} -Pour des operateurs paramétrable (comme \texttt{mix}), le paramêtre flottant doit -être fourni en utilisant l'option \texttt{-k}. +Pour des operateurs paramétrable (comme \texttt{mix}), le paramêtre +flottant doit être fourni en utilisant l'option \texttt{-k}. La véracité mathématique n'est pas garantie. \subsection{fimg2png, fimg2pnm, fimg2tiff} diff --git a/floatimg.h b/floatimg.h index da2903ab..52694d74 100644 --- a/floatimg.h +++ b/floatimg.h @@ -2,7 +2,7 @@ * floatimg.h */ -#define FIMG_VERSION 76 +#define FIMG_VERSION 77 /* * in memory descriptor @@ -68,6 +68,8 @@ int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef); int fimg_add(FloatImg *a, FloatImg *b, FloatImg *d); int fimg_sub(FloatImg *a, FloatImg *b, FloatImg *d); int fimg_mul(FloatImg *a, FloatImg *b, FloatImg *d); +int fimg_minimum(FloatImg *a, FloatImg *b, FloatImg *d); +int fimg_maximum(FloatImg *a, FloatImg *b, FloatImg *d); /* PNM files module */ int fimg_save_as_pnm(FloatImg *head, char *fname, int flags); diff --git a/lib/operators.c b/lib/operators.c index 32dbbee8..9decadf7 100644 --- a/lib/operators.c +++ b/lib/operators.c @@ -66,7 +66,6 @@ for (idx=0; idx D */ @@ -94,3 +93,53 @@ for (idx=0; idx>> %s ( %p %p %p )\n", __func__, a, b, d); +#endif + +if (3 != a->type || 3 != b->type || 3 != d->type) { + fprintf(stderr, "%s : got a bad type fimg\n", __func__); + return -8; + } + +nbiter = a->width * a->height * 3; + +for (idx=0; idxR[idx] > b->R[idx]) + d->R[idx] = a->R[idx]; + else + d->R[idx] = b->R[idx]; + } + +return 0; +} +/* ---------------------------------------------------------------- */ +int fimg_maximum(FloatImg *a, FloatImg *b, FloatImg *d) +{ +int idx, nbiter; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d); +#endif + +if (3 != a->type || 3 != b->type || 3 != d->type) { + fprintf(stderr, "%s : got a bad type fimg\n", __func__); + return -8; + } + +nbiter = a->width * a->height * 3; + +for (idx=0; idxR[idx] < b->R[idx]) + d->R[idx] = a->R[idx]; + else + d->R[idx] = b->R[idx]; + } + +return 0; +} +/* ---------------------------------------------------------------- */ diff --git a/lib/runme.sh b/lib/runme.sh index d38a4d3c..f67ebc5b 100755 --- a/lib/runme.sh +++ b/lib/runme.sh @@ -1,13 +1,17 @@ #!/bin/bash -../v4l2/grabvidseq -s 960x720 -n 10000 -p 0.193 \ - -vv -g -c none \ +../v4l2/grabvidseq -s 960x720 -n 100 -p 0.193 \ + -vv -c none \ -o original.fimg make t && ./t -for picz in original power2 squareroot cos_01 +../tools/fimgops original.fimg cos_01.fimg mini minimum.fimg +../tools/fimgops original.fimg cos_01.fimg maxi maximum.fimg + + +for picz in original power2 squareroot cos_01 minimum maximum do echo _______________________ ${picz} diff --git a/tools/fimgops.c b/tools/fimgops.c index 75211b71..afbf5481 100644 --- a/tools/fimgops.c +++ b/tools/fimgops.c @@ -16,6 +16,8 @@ float global_fvalue; #define OP_SUB 2 #define OP_MIX 3 #define OP_MUL 4 +#define OP_MINI 5 +#define OP_MAXI 6 typedef struct { int code; char *op; @@ -26,6 +28,8 @@ Opcode opcodes[] = { { OP_SUB, "sub" }, { OP_MIX, "mix" }, { OP_MUL, "mul" }, + { OP_MINI, "mini" }, + { OP_MAXI, "maxi" }, { 0, NULL } }; static void pr_opcodes(void) @@ -57,11 +61,11 @@ static void help(int lj) { puts("usage:\n\tfimgops [options] A.fimg B.fimg operator D.fimg"); -pr_opcodes(); puts("options:"); puts("\t-g convert output to gray"); puts("\t-k N.N set float value"); puts("\t-v increase verbosity"); +pr_opcodes(); if (verbosity) fimg_print_version(1); exit(0); } @@ -83,6 +87,10 @@ switch (action) { break; case OP_MUL: foo = fimg_add(A, B, D); break; + case OP_MINI: + foo = fimg_maximum(A, B, D); break; + case OP_MAXI: + foo = fimg_minimum(A, B, D); break; default: foo = -99; break; @@ -125,7 +133,7 @@ if (action < 0) { } /* - * load the two source files, and check comatibility + * load the two source files, and check compatibility */ if ((foo=fimg_create_from_dump(argv[optind], &srcA))) { fprintf(stderr, "read error on '%s' is %d\n", argv[optind], foo);