forked from tTh/FloatImg
Compare commits
203 Commits
Author | SHA1 | Date |
---|---|---|
tTh | c598c4a2c0 | |
tTh | b33a752af7 | |
tTh | 9c5849e299 | |
tTh | 9dd2064b7a | |
tTh | a438ab9362 | |
tTh | 381f329810 | |
tTh | 3bd387f0a9 | |
tTh | 085e19942a | |
tTh | 152beddcb7 | |
tTh | c1b6f9ae40 | |
tTh | 2c407e5dd9 | |
tTh | c6b75d3bba | |
tTh | 12347e9066 | |
tTh | 9e9535221f | |
tTh | 1f1398f9f2 | |
tTh | 2699476135 | |
tTh | cfe9f8cdae | |
tTh | 5d139312e2 | |
tTh | 2c14368cd5 | |
tTh | 658ef3ab08 | |
tTh | 8b8c1b466f | |
tTh | 817982c074 | |
tTh | 6a4b2f7c32 | |
tTh | 36fcc15b0a | |
tTh | 8c0f55b7cb | |
tTh | ee5e081031 | |
tTh | d23a35849a | |
tTh | 82ffe1c2cc | |
tTh | 0a482a7316 | |
tTh | 2c1687f82b | |
tTh | 0f245582d5 | |
tTh | c8faa77904 | |
tTh | 03763a4dfb | |
tTh | 54d9a9939d | |
tTh | 488893f6a3 | |
tTh | e9ca450584 | |
tTh | 3fd604b14a | |
tTh | 0169fbade7 | |
tTh | 0e00e00df5 | |
tTh | 6e9aa75694 | |
tTh | 603194451a | |
tTh | 3ef1fdf02e | |
tTh | ad93b7935c | |
tTh | cd6f045789 | |
tTh | 99bbd20b47 | |
tTh | 54b061232d | |
tTh | b0fc5107c9 | |
tTh | 9e36c8b64c | |
tTh | 0a5f58867c | |
tTh | 5c59dc7ef7 | |
tTh | 7244b4c829 | |
tTh | 17a4cc4dd2 | |
tTh | 3949d147ef | |
tTh | 72cb5aa0f6 | |
tTh | 2ff17fc54b | |
tTh | ed227d6563 | |
tTh | 90b9d4e37a | |
tTh | 253647c008 | |
tTh | 67cb70fa3b | |
tTh | 1d356a6f12 | |
tTh | cc647b43b4 | |
tTh | 58e782de84 | |
tTh | cb599a253c | |
tTh | ff916c434c | |
tTh | 11a1e95146 | |
tTh | 6e92252778 | |
tTh | a4b7f5c21c | |
tTh | 36d30b76d7 | |
tTh | e00423ed9b | |
tTh | 3e66e822f2 | |
tTh | a449c53592 | |
tTh | 154844c94d | |
tTh | bf239a9004 | |
tTh | 7d66b09635 | |
tTh | 70694cf592 | |
tTh | a72f544b4b | |
tTh | b3ca197b89 | |
tTh | c1ce8f7696 | |
tTh | 4ae4947fbe | |
tTh | af103abdcf | |
tTh | 1ef877d947 | |
tTh | 1ad4b406d7 | |
tTh | c004f22b16 | |
tTh | d58decefcb | |
tTh | 63bc4ed7af | |
tTh | b79f6851f5 | |
tTh | 70dc8a7638 | |
tTh | 63674c8eee | |
tTh | be4b6a774e | |
tTh | d750c027fa | |
tTh | 7f3912a133 | |
tTh | 1f4b424be7 | |
tTh | d49b77a79f | |
tTh | 86a903360c | |
tTh | 5d18cb6c3f | |
tTh | 0e77fdeb7a | |
tTh | 0cb40ae2a0 | |
tTh | a02b725ae0 | |
tTh | 56073c0c80 | |
tTh | eedc9197db | |
tTh | feafd2799d | |
tTh | e6379f6338 | |
tTh | 1b598227c3 | |
tTh | 3eed90c3e7 | |
tTh | c7a51ec7a0 | |
tTh | aa2ced081a | |
tTh | b12151444b | |
tTh | af41acba4a | |
tTh | f63f918530 | |
tth | e224ab83b6 | |
tth | 3c551b6c7c | |
tth | fe9a14e2b5 | |
tth | 11082c0d08 | |
tth | 615321eca8 | |
tth | 4dcc524fc4 | |
tth | 263e254980 | |
tth | 27e42a0ddd | |
tth | 12c3218a93 | |
tth | 8a663a95ee | |
tth | ddfadf9a67 | |
tth | 455428f444 | |
tth | 6810783426 | |
tth | 5064126da8 | |
tth | 2e6bff3f67 | |
tth | a5fac7effd | |
tth | 4b64330884 | |
tth | f52e24b30c | |
tth | 63e6dcd07b | |
tth | 125383adf3 | |
tth | be48fc6e84 | |
tth | 039d4cb77b | |
tth | 7ea77cc882 | |
tth | 60b4181f3c | |
tth | 3eb2f549ee | |
tth | af92ce4e2e | |
tth | 0cdb977a82 | |
tth | b98c398c3c | |
tth | c17132e969 | |
tth | 6ffc08188d | |
tth | 0da81df892 | |
tth | 4597598b02 | |
tth | db7b740b2c | |
tth | 6aa802fde2 | |
tth | 879e25463b | |
tTh | 3f7abf4ea0 | |
tTh | af7266eb30 | |
tth | 0dee6e0e46 | |
tth | fcd8b09029 | |
tth | f938bbc7bd | |
tTh | c61251ad53 | |
tTh | e7e3713972 | |
tTh | 4c38ff032a | |
tTh | a8d1e18650 | |
tTh | ccd324749e | |
tth | ab9e4b0250 | |
tth | 6e896ee463 | |
tth | 99187104ce | |
tth | be4e6b0dc9 | |
tth | 8c514ffe99 | |
tth | 2a1d74a83f | |
tth | f09162d4ce | |
tth | 8dbe6dd5c1 | |
tth | 86df4ef602 | |
tth | 5845ab7962 | |
tth | 0e79b3e8fa | |
tth | 1b5186f4b3 | |
tth | 6c92cca12c | |
tth | bc864a6acb | |
tth | 39f48a56b0 | |
tth | 094b61ba39 | |
tth | 9bde22f560 | |
tth | f3dc73782a | |
tth | b93ec2e603 | |
tth | 9124ab6434 | |
tth | 23908cb746 | |
tth | f08f860daa | |
tth | 19c8f6aad5 | |
tth | 30cb448642 | |
tth | 40bf700a32 | |
tth | f24ad0d229 | |
tth | 19094fee24 | |
tth | dbff8129b7 | |
tth | 3b2be2e5dc | |
tth | e88ea153bd | |
tth | 49d2703612 | |
tth | 5a90dce59d | |
tth | 17955bd303 | |
tth | 865cc60ccf | |
tth | f77a63b08c | |
tth | 389beea6cd | |
tth | b2d2c45be1 | |
tth | 468b5feb74 | |
tth | fed3076b92 | |
tth | 72e162e4cf | |
tth | 802ec6e9c1 | |
tth | a87ad8dea2 | |
tth | 41e77a5185 | |
tth | 77e967cf38 | |
tth | 20e2f1e71e | |
tth | 92b7eb478c | |
tth | 5b934abd0a | |
tth | 07dde749ed | |
tth | 4a52c16e40 |
|
@ -8,8 +8,12 @@ lib/*.gif
|
|||
|
||||
*.a
|
||||
gmon.out
|
||||
cscope.out
|
||||
|
||||
*.swp
|
||||
|
||||
*.pnm
|
||||
*.pgm
|
||||
*.fimg
|
||||
essai
|
||||
MANIFEST
|
||||
|
@ -50,22 +54,6 @@ v4l2/*.tiff
|
|||
v4l2/video-infos
|
||||
v4l2/nc-camcontrol
|
||||
|
||||
tools/fimg2png
|
||||
tools/fimg2pnm
|
||||
tools/fimg2tiff
|
||||
tools/fimg2fits
|
||||
tools/fimg2text
|
||||
tools/fimgstats
|
||||
tools/fimghalfsize
|
||||
tools/mkfimg
|
||||
tools/png2fimg
|
||||
tools/addtga2fimg
|
||||
tools/addpnm2fimg
|
||||
tools/cumulfimgs
|
||||
tools/fimgops
|
||||
tools/fimgfx
|
||||
tools/*.png
|
||||
tools/*.tiff
|
||||
|
||||
Fonderie/*.o
|
||||
Fonderie/*.png
|
||||
|
@ -79,9 +67,4 @@ Fonderie/singlepass
|
|||
Fonderie/crapdef.h
|
||||
Fonderie/crapstr.h
|
||||
|
||||
experiment/assemblage
|
||||
experiment/extracteur
|
||||
experiment/*.fimg
|
||||
experiment/*.pnm
|
||||
experiment/*.o
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ OBJS = fifo.o sfx.o crapulator.o glitches.o metriques.o \
|
|||
filterstack.o single.o
|
||||
|
||||
DEPS = ../floatimg.h \
|
||||
../libfloatimg.a \
|
||||
fifo.h crapulator.h metriques.h glitches.h sfx.h \
|
||||
filterstack.h crapdef.h crapstr.h single.h
|
||||
|
||||
|
@ -40,19 +41,19 @@ singlepass: singlepass.c ${DEPS} ${OBJS} Makefile
|
|||
# some files are magically generated, sorry.
|
||||
#
|
||||
crapdef.h: crapulors.liste Makefile craplist2h.awk
|
||||
./craplist2h.awk < $< | tee $@
|
||||
< $< ./craplist2h.awk > $@
|
||||
|
||||
crapstr.h: crapulors.liste Makefile craplist2str.awk
|
||||
./craplist2str.awk < $< | tee $@
|
||||
< $< ./craplist2str.awk > $@
|
||||
|
||||
# ---------------------------------------------------------
|
||||
#
|
||||
# a lot of silly functions
|
||||
#
|
||||
crapulator.o: crapulator.c ${DEPS} Makefile
|
||||
crapulator.o: crapulator.c $(DEPS) Makefile
|
||||
gcc ${COPT} -c $<
|
||||
|
||||
fifo.o: fifo.c fifo.h Makefile
|
||||
fifo.o: fifo.c fifo.h $(DEPS) Makefile
|
||||
gcc ${COPT} -c $<
|
||||
|
||||
sfx.o: sfx.c ${DEPS} Makefile
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
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.
|
||||
de **films flous** dans le domaine spatio-temporel.
|
||||
|
||||
À l'heure actuelle, il y a plusieurs programmes distincts. Le premier
|
||||
(fonderie) fait une moyenne mobile sur N images consécutives,
|
||||
|
@ -20,16 +20,15 @@ destinés à augmenter la kitchitude du produit final. Ils peuvent être chainé
|
|||
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.
|
||||
Ces filtres ont chacun un nom, utilisable dans une chaine de filtres.
|
||||
L'option `-L` de ces logiciels permet d'obtenir la liste des filtres.
|
||||
Pour ne rien filtrer, utilisez le filtre `none`, il est là pour ça.
|
||||
|
||||
Une chaine de filtres est constituée d'une liste de nom ou de numéro
|
||||
Une chaine de filtres est constituée d'une liste de nom
|
||||
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.
|
||||
classique dans notre univers, en fait.
|
||||
|
||||
`mirsplit:ctr2x2:3:killlines`
|
||||
`mirsplit:ctr2x2:killlines`
|
||||
|
||||
Nous allons donc voir quelques exemples un peu plus loin.
|
||||
|
||||
|
@ -70,12 +69,12 @@ GRABDIR="/spool/tth/fonderie"
|
|||
FONDEUR="$HOME/Devel/FloatImg/Fonderie/fonderie"
|
||||
GLOB=${GRABDIR}'/?????.fimg'
|
||||
|
||||
${FONDEUR} -I "$GLOB" -E cos01:25 -T 30 -F 2:classtrial
|
||||
${FONDEUR} -I "$GLOB" -E cos01:trinitron -F classtrial -T 30
|
||||
```
|
||||
|
||||
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
|
||||
ensuite il vous suffira d'encoder toutes les images générées dans
|
||||
`p8/` (répertoire de sortie par défaut)
|
||||
avec une incantation de ffmpeg :
|
||||
|
||||
|
@ -136,6 +135,8 @@ usage:
|
|||
|
||||
## Conclusion
|
||||
|
||||
Tout cela est bien rigolo :)
|
||||
|
||||
|
||||
**Use the source, Luke**
|
||||
|
||||
|
|
|
@ -6,18 +6,19 @@
|
|||
#
|
||||
|
||||
BEGIN {
|
||||
print "// -----------------------------------"
|
||||
print "// -------------------------------------"
|
||||
print "// generated file, do not edit by hand !"
|
||||
print "// -----------------------------------"
|
||||
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
|
||||
name = sprintf("CR_%s", $2)
|
||||
printf "#define %-15s (%d)\n", name, $1
|
||||
}
|
||||
|
||||
END {
|
||||
print "// generated file, do not edit by hand !"
|
||||
print "\n// generated file, do not edit by hand !"
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
# is includet by 'crapulator.c'
|
||||
#
|
||||
BEGIN {
|
||||
print "// -----------------------------------"
|
||||
print "// generated file, do not edit by hand";
|
||||
print "// -----------------------------------"
|
||||
print "Crapulor CrapL[] = {";
|
||||
print "// -------------------------------------"
|
||||
print "// generated file, do not edit by hand !";
|
||||
print "// -------------------------------------"
|
||||
print "Crapulor CrapL[] = {";
|
||||
}
|
||||
|
||||
# $1 is the badly brain-designed numeric id
|
||||
|
@ -16,12 +16,13 @@ BEGIN {
|
|||
# $3 and $4 are two not used parameters
|
||||
#
|
||||
{
|
||||
printf " { CR_%s, \"%s\", %d, %f }, // id=%d\n",
|
||||
$2, $2, $3, $4, $1;
|
||||
name = sprintf("CR_%s", $2)
|
||||
printf " { %-14s, \"%s\", %d, %f }, // #%d\n",
|
||||
name, $2, $3, $4, $1;
|
||||
}
|
||||
|
||||
END {
|
||||
print " { -1, NULL }"
|
||||
print " };"
|
||||
print "// generated file, do not edit by hand"
|
||||
print "// ! generated file, do not edit by hand !"
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -81,7 +82,7 @@ FloatImg img;
|
|||
int foo, retval;
|
||||
FimgFilter3x3 *pfiltre;
|
||||
|
||||
FimgFilter3x3 lowpass = {
|
||||
static FimgFilter3x3 lowpass = {
|
||||
{
|
||||
1.0, 2.0, 1.0,
|
||||
2.0, 4.0, 2.0,
|
||||
|
@ -90,7 +91,8 @@ FimgFilter3x3 lowpass = {
|
|||
16.0, 0.0
|
||||
};
|
||||
|
||||
FimgFilter3x3 hipass = {
|
||||
static FimgFilter3x3 hipass = {
|
||||
/* there was a bug with this filter */
|
||||
{
|
||||
-1.0, -1.0, -1.0,
|
||||
-1.0, 9.0, -1.0,
|
||||
|
@ -99,11 +101,12 @@ FimgFilter3x3 hipass = {
|
|||
1.0, 0.0
|
||||
};
|
||||
|
||||
FimgFilter3x3 diagonal = {
|
||||
static FimgFilter3x3 diagonal = {
|
||||
/* there was a bug with this filter */
|
||||
{
|
||||
2.0, 1.0, 0.0,
|
||||
4.0, 1.0, 0.0,
|
||||
1.0, 0.0, -1.0,
|
||||
0.0, -1.0, -2.0,
|
||||
0.0, -1.0, -4.0,
|
||||
},
|
||||
1.0, 0.0
|
||||
};
|
||||
|
@ -151,6 +154,133 @@ fimg_destroy(&img);
|
|||
return retval;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int run_killrgb_0(FloatImg *img, int k)
|
||||
{
|
||||
FloatImg tmp;
|
||||
int ret;
|
||||
|
||||
// fprintf(stderr, "----> %s\n", __func__);
|
||||
|
||||
memset(&tmp, 0, sizeof(FloatImg));
|
||||
|
||||
fimg_clone(img, &tmp, 0);
|
||||
ret = fimg_killrgb_v(img, &tmp, k);
|
||||
fimg_copy_data(&tmp, img);
|
||||
fimg_destroy(&tmp);
|
||||
|
||||
// fprintf(stderr, "%s ---->\n", __func__);
|
||||
|
||||
return ret;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
static int run_pixelize_0(FloatImg *img, int k)
|
||||
{
|
||||
FloatImg tmp;
|
||||
int ret;
|
||||
|
||||
memset(&tmp, 0, sizeof(FloatImg));
|
||||
fimg_clone(img, &tmp, 0);
|
||||
ret = fimg_pixelize_h_0(img, &tmp, k);
|
||||
fimg_copy_data(&tmp, img);
|
||||
fimg_destroy(&tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
static int run_pixelize_random(FloatImg *img, int k)
|
||||
{
|
||||
FloatImg tmp;
|
||||
int ret;
|
||||
|
||||
memset(&tmp, 0, sizeof(FloatImg));
|
||||
fimg_clone(img, &tmp, 0);
|
||||
ret = fimg_pixelize_h_rnd(img, &tmp, k);
|
||||
if (verbosity > 1) fprintf(stderr, "in %s, pixelize H rnd -> %d\n",
|
||||
__func__, ret);
|
||||
fimg_copy_data(&tmp, img);
|
||||
fimg_destroy(&tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
static int run_decomprgbz_color(FloatImg *img, int k)
|
||||
{
|
||||
FloatImg tmp;
|
||||
int ret;
|
||||
|
||||
memset(&tmp, 0, sizeof(FloatImg));
|
||||
fimg_clone(img, &tmp, 0);
|
||||
ret = fimg_decomp_rgbz_color(img, &tmp, k);
|
||||
fimg_copy_data(&tmp, img);
|
||||
fimg_destroy(&tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* nouveau 14 mai 2022 */
|
||||
static int run_gr2popcol(FloatImg *img, int k)
|
||||
{
|
||||
FloatImg tmp;
|
||||
int ret;
|
||||
memset(&tmp, 0, sizeof(FloatImg));
|
||||
fimg_clone(img, &tmp, 0);
|
||||
ret = graylevel2popcolors(img, &tmp, k);
|
||||
fimg_copy_data(&tmp, img);
|
||||
fimg_destroy(&tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* new Sun Feb 12 11:30:02 CET 2023 */
|
||||
static int run_rndfluffy(FloatImg *img, int k)
|
||||
{
|
||||
FloatImg tmp;
|
||||
int ret;
|
||||
memset(&tmp, 0, sizeof(FloatImg));
|
||||
fimg_clone(img, &tmp, 0);
|
||||
ret = fimg_make_rndfluffy_lines(img, &tmp, k);
|
||||
fimg_copy_data(&tmp, img);
|
||||
fimg_destroy(&tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
static int run_decomprgbz_gray(FloatImg *img, int k)
|
||||
{
|
||||
FloatImg tmp;
|
||||
int ret;
|
||||
|
||||
/* ugly code here */
|
||||
memset(&tmp, 0, sizeof(FloatImg));
|
||||
fimg_clone(img, &tmp, 0);
|
||||
ret = fimg_decomp_rgbz_gray(img, &tmp, k);
|
||||
fimg_copy_data(&tmp, img);
|
||||
fimg_destroy(&tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* new Sun Jul 16 11:27:43 UTC 2023 */
|
||||
int run_suprbg(FloatImg *img, int notused)
|
||||
{
|
||||
FloatImg tmp;
|
||||
int ret;
|
||||
|
||||
if (notused) {
|
||||
fprintf(stderr, "FATAL: invalid notused in %s\n", __func__);
|
||||
abort();
|
||||
}
|
||||
|
||||
/* ugly code here */
|
||||
memset(&tmp, 0, sizeof(FloatImg));
|
||||
fimg_clone(img, &tmp, 0);
|
||||
ret = poke_sup_rb_g(img, &tmp);
|
||||
fimg_copy_data(&tmp, img);
|
||||
fimg_destroy(&tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* This is the main filter engine used both for input and
|
||||
* output processing. It can be called by the filterstack
|
||||
|
@ -269,19 +399,28 @@ switch (idFx) {
|
|||
retval = fimg_power_2(image, image, 1000.0);
|
||||
break;
|
||||
|
||||
case CR_triplemul:
|
||||
retval = fimg_sfx_triplemul(image, image, 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);
|
||||
retval = des_bords_sombres_b(image, 120);
|
||||
break;
|
||||
|
||||
case CR_vsglitch:
|
||||
/* please make this function more tweakable */
|
||||
retval = vertical_singlitch(image, 290+rand()%45,
|
||||
fval, 0.19, 0);
|
||||
break;
|
||||
|
||||
case CR_crumphard: /* new june 1st 2021, in the bibcave */
|
||||
retval = fimg_crump_hard(image, image, fval, 0);
|
||||
break;
|
||||
|
||||
case CR_rndblks:
|
||||
retval = random_blocks(image, 70);
|
||||
break;
|
||||
|
@ -298,22 +437,52 @@ switch (idFx) {
|
|||
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_killrgb0:
|
||||
retval = run_killrgb_0(image, 0);
|
||||
break;
|
||||
|
||||
case CR_pixelizh:
|
||||
retval = run_pixelize_0(image, 8);
|
||||
break;
|
||||
case CR_pixelizv:
|
||||
retval = run_pixelize_0(image, 32);
|
||||
break;
|
||||
|
||||
case CR_pixelrand:
|
||||
retval = run_pixelize_random(image, 16);
|
||||
break;
|
||||
|
||||
case CR_splitlevel:
|
||||
retval = fimg_split_level(image, image, 0);
|
||||
break;
|
||||
|
||||
case CR_decrgbzc:
|
||||
retval = run_decomprgbz_color(image, 0);
|
||||
break;
|
||||
case CR_decrgbzg:
|
||||
retval = run_decomprgbz_gray(image, 0);
|
||||
break;
|
||||
|
||||
case CR_hilightr:
|
||||
retval = fimg_highlight_color(image, image, 'R', 1.717);
|
||||
break;
|
||||
|
||||
case CR_gr2popcol:
|
||||
retval = run_gr2popcol(image, -1);
|
||||
break;
|
||||
|
||||
case CR_fluffy:
|
||||
retval = run_rndfluffy(image, 75);
|
||||
break;
|
||||
|
||||
case CR_suprbg:
|
||||
retval = run_suprbg(image, 0);
|
||||
break;
|
||||
|
||||
default :
|
||||
fprintf(stderr, "%s : effect #%d invalid\n",
|
||||
__func__, idFx);
|
||||
|
@ -349,13 +518,25 @@ void list_crapulors(char *texte)
|
|||
int idx;
|
||||
|
||||
#define OUT stdout
|
||||
fprintf(OUT, "______________. %s\n", texte);
|
||||
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "We have around %ld filters now !\n", NBCRAP);
|
||||
}
|
||||
|
||||
if (NULL!=texte && verbosity)
|
||||
fprintf(OUT, " _________ %s _________\n", texte);
|
||||
|
||||
for (idx=0; CrapL[idx].id!=-1; idx++) {
|
||||
fprintf(OUT, " %-12s | %4d | %5d | %8.3f\n",
|
||||
if (verbosity) {
|
||||
fprintf(OUT, " %-12s | %4d | %5d | %8.3f\n",
|
||||
CrapL[idx].name,
|
||||
CrapL[idx].id,
|
||||
CrapL[idx].ipar,
|
||||
CrapL[idx].fpar);
|
||||
}
|
||||
else {
|
||||
fprintf(OUT, "%s\n", CrapL[idx].name);
|
||||
}
|
||||
}
|
||||
#undef OUT
|
||||
}
|
||||
|
|
|
@ -27,10 +27,21 @@
|
|||
26 rndblks 1 1.0
|
||||
27 shiftln0 1 1.0
|
||||
28 qsortrgb 2 1.0
|
||||
29 triplemul 3 1.0
|
||||
30 multidots 100 1.333
|
||||
31 diagonal 1 1.0
|
||||
32 vsglitch 1 1.0
|
||||
33 crumphard 1 1.0
|
||||
42 nothing 42 3.1415926
|
||||
43 killrgb0 1 9
|
||||
45 hilightr 1 1.717
|
||||
99 message 1 1.0
|
||||
46 pixelizh 1 1.111
|
||||
47 pixelizv 1 1.111
|
||||
48 pixelrand 1 1
|
||||
49 splitlevel 1 1
|
||||
50 decrgbzc 1 99
|
||||
51 decrgbzg 1 99
|
||||
60 gr2popcol 1 99
|
||||
61 fluffy 1 0.12
|
||||
62 suprbg 1 0
|
||||
-1 end 1 1.0
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
|
||||
|
@ -25,7 +26,7 @@ extern int verbosity;
|
|||
static A_Fifo g_fifo;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
static int big_adder(FloatImg *from, FloatImg *to)
|
||||
static inline int big_adder(FloatImg *from, FloatImg *to)
|
||||
{
|
||||
int size, idx;
|
||||
|
||||
|
@ -89,7 +90,7 @@ int export_fifo(char *fname, int notused)
|
|||
int foo, type;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, step);
|
||||
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused);
|
||||
#endif
|
||||
|
||||
foo = faire_la_somme(&g_fifo, NULL, 1);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <alloca.h>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <glob.h>
|
||||
|
@ -199,7 +200,7 @@ int fifosize = 10;
|
|||
char *in_pattern = "capture/?????.fimg";
|
||||
char *out_dir = "p8";
|
||||
int outfmt = FILE_TYPE_PNG;
|
||||
int blanks = 20;
|
||||
int blanks = 10;
|
||||
char *InFchain = "none";
|
||||
char *OutFchain = "none";
|
||||
|
||||
|
@ -228,6 +229,7 @@ while ((opt = getopt(argc, argv, "B:E:F:ghI:LO:T:vw:x:")) != -1) {
|
|||
break;
|
||||
case 'v': verbosity++;
|
||||
break;
|
||||
default: exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
|
@ -150,36 +151,38 @@ 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;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* FIXME XXX
|
||||
*/
|
||||
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__,
|
||||
fprintf(stderr, "WARNING %s: %dx%d bad dims\n", __func__,
|
||||
picture->width, picture->height);
|
||||
// return -1;
|
||||
}
|
||||
|
||||
for (y=0; y<picture->height; y+=16) {
|
||||
for (x=0; x<picture->width; x+=16) {
|
||||
for (y=16; y<picture->height-16; y+=16) {
|
||||
for (x=16; x<picture->width-16; 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <glob.h>
|
||||
|
@ -57,6 +58,10 @@ fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, ptr_glob,
|
|||
ptr_idxval, method);
|
||||
#endif
|
||||
|
||||
if (0 == method) {
|
||||
fprintf(stderr, "\tWTF? in %s, method was ZERO?\n", __func__);
|
||||
}
|
||||
|
||||
nombre = ptr_glob->gl_pathc;
|
||||
|
||||
/* allocate the array for the sorting action */
|
||||
|
@ -65,7 +70,7 @@ if (NULL==idxvalues) {
|
|||
fprintf(stderr, "MEMORY ERROR in %s\n", __func__);
|
||||
exit(1);
|
||||
}
|
||||
fprintf(stderr, "IdxValues array at %p\n", idxvalues);
|
||||
// fprintf(stderr, "IdxValues array at %p\n", idxvalues);
|
||||
|
||||
*ptr_idxval = idxvalues;
|
||||
average = 0.0;
|
||||
|
@ -103,7 +108,7 @@ if (verbosity > 1) {
|
|||
average /= (double)nombre;
|
||||
*p_average = average;
|
||||
|
||||
fprintf(stderr, "\naverage %f\n", average);
|
||||
fprintf(stderr, "\naverage of ??? is %f\n", average);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -121,18 +126,18 @@ int foo, idx, ipng, w, h, step;
|
|||
int curpix;
|
||||
int iarray[3];
|
||||
char *cptr, line[200];
|
||||
float coef, value;
|
||||
float coef;
|
||||
double meanmetric;
|
||||
IdxValue *idx_values; /* gni? */
|
||||
|
||||
fprintf(stderr, " interpolate from '%s' to '%s' with %d steps.\n",
|
||||
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",
|
||||
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__);
|
||||
|
@ -174,7 +179,6 @@ for (idx=0; idx<globbuf.gl_pathc; idx++) {
|
|||
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);
|
||||
|
@ -253,7 +257,7 @@ int sort = 0;
|
|||
char *InFchain = "0";
|
||||
char *OutFchain = "0";
|
||||
|
||||
fprintf(stderr, "*** %s : compiled by tTh, %s %s\n", __FILE__,
|
||||
fprintf(stderr, "*** %s\n\tcompiled on %s %s\n", argv[0],
|
||||
__DATE__, __TIME__);
|
||||
fimg_print_version(2);
|
||||
|
||||
|
@ -274,6 +278,7 @@ while ((opt = getopt(argc, argv, "E:F:hLnS:v")) != -1) {
|
|||
case 'S': sort = atoi(optarg); break;
|
||||
case 'v': verbosity++; break;
|
||||
case 'n': negative = 1; break;
|
||||
default: exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -302,13 +307,14 @@ if (verbosity) {
|
|||
fprintf(stderr, "\toutput dir '%s'\n", argv[optind+1]);
|
||||
fprintf(stderr, "\tsrc filter '%s'\n", InFchain);
|
||||
fprintf(stderr, "\tout filter '%s'\n", OutFchain);
|
||||
fprintf(stderr, "\tsort %d\n", sort);
|
||||
}
|
||||
|
||||
if (verbosity > 1) {
|
||||
puts("=========================");
|
||||
fputs("=========================\n", stderr);
|
||||
filterstack_list(0, __FILE__);
|
||||
filterstack_list(1, __FILE__);
|
||||
puts("=========================");
|
||||
fputs("=========================\n", stderr);
|
||||
}
|
||||
|
||||
nbrsteps = atoi(argv[optind+2]);
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
#include "metriques.h"
|
||||
|
||||
|
@ -84,6 +86,9 @@ for (idx=20; idx < size; idx+=42) {
|
|||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* LR mean left/right
|
||||
*/
|
||||
int get_float_metric_LR(FloatImg *pimg, float *where)
|
||||
{
|
||||
int coords[4], foo;
|
||||
|
@ -95,8 +100,16 @@ coords[2] = pimg->width / 2; // W
|
|||
coords[3] = pimg->height; // H
|
||||
|
||||
foo = stat_zone(pimg, coords, valL);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d stat zone in %s\n", foo, __func__);
|
||||
return foo;
|
||||
}
|
||||
coords[1] = pimg->width / 2;
|
||||
foo = stat_zone(pimg, coords, valR);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d stat zone in %s\n", foo, __func__);
|
||||
return foo;
|
||||
}
|
||||
|
||||
*where = valL[1] - valR[1];
|
||||
|
||||
|
|
160
Fonderie/sfx.c
160
Fonderie/sfx.c
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <math.h>
|
||||
|
@ -20,6 +21,78 @@
|
|||
*/
|
||||
extern int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* nouveau Sun Jul 16 07:37:22 UTC 2023
|
||||
*
|
||||
* may-be this can be an on-place function ?
|
||||
*
|
||||
*/
|
||||
int poke_sup_rb_g(FloatImg *src, FloatImg *dst)
|
||||
{
|
||||
int idx, nbpix, foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p )\n", __func__, src, dst);
|
||||
#endif
|
||||
|
||||
if ( (foo=fimg_images_not_compatible(src, dst)) )
|
||||
{
|
||||
fprintf(stderr, "%s: no compat %d\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
nbpix = src->width * src->height;
|
||||
if (verbosity > 1)
|
||||
fprintf(stderr, "%s work on %d pixels\n", __func__, nbpix);
|
||||
|
||||
for (idx=0; idx<nbpix; idx++) {
|
||||
dst->R[idx] = src->R[idx];
|
||||
dst->B[idx] = src->B[idx];
|
||||
if (src->R[idx] < src->B[idx])
|
||||
dst->G[idx] = src->R[idx];
|
||||
else
|
||||
dst->G[idx] = src->B[idx];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* nouveau 14 mai 2022 rue Ernest Renan */
|
||||
|
||||
int graylevel2popcolors(FloatImg *src, FloatImg *dst, int k)
|
||||
{
|
||||
int x, y;
|
||||
float rgb[3];
|
||||
float theoric_maxval, real_maxv;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, src, dst, k);
|
||||
#endif
|
||||
|
||||
theoric_maxval = src->fval * src->count;
|
||||
real_maxv = fimg_get_maxvalue(src);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "maxval: theoric= %.3f real= %.3f\n", \
|
||||
theoric_maxval, real_maxv);
|
||||
#endif
|
||||
|
||||
fimg_clear(dst);
|
||||
|
||||
for (y=0; y<src->height; y++) {
|
||||
|
||||
for (x=0; x<src->width; x++)
|
||||
{
|
||||
fimg_get_rgb(src, x, y, rgb);
|
||||
rgb[0] = real_maxv * fabs(cos(21.0 * rgb[0] / real_maxv));
|
||||
rgb[1] = real_maxv * fabs(cos(31.0 * rgb[1] / real_maxv));
|
||||
rgb[2] = real_maxv * fabs(cos(11.0 * rgb[2] / real_maxv));
|
||||
fimg_put_rgb(dst, x, y, rgb);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* please, add some parameters !
|
||||
|
@ -46,21 +119,43 @@ return -1;
|
|||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* nouveau du premier dimanche de 2020 'nextgen' */
|
||||
|
||||
/* CE TRUC NE MARCHE PAS COMME PRÉVU */
|
||||
|
||||
static int pixel_trinitron(FloatImg *pimg, int pos[4], float *fvals)
|
||||
{
|
||||
int x, y, pline, off;
|
||||
int ym;
|
||||
|
||||
for (y=pos[1]; y<pos[1]+pos[3]; y++) {
|
||||
fimg_clear_rectangle(pimg, pos);
|
||||
|
||||
ym = pos[1]+pos[3]-1;
|
||||
|
||||
#define FDIM 0.60
|
||||
|
||||
for (y=pos[1]; y<ym; 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];
|
||||
for (x=0; x<5; x++) {
|
||||
off = pline + (x+pos[0]);
|
||||
/* wtf i'm doing here ? */
|
||||
if ( (pos[1]==y) || (ym-1==y) ) {
|
||||
pimg->R[off] = fvals[0] * FDIM;
|
||||
pimg->G[off+5] = fvals[1] * FDIM;
|
||||
pimg->B[off+10] = fvals[2] * FDIM;
|
||||
}
|
||||
else {
|
||||
pimg->R[off] = fvals[0];
|
||||
pimg->G[off+5] = fvals[1];
|
||||
pimg->B[off+10] = fvals[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* need more explanation, need more work
|
||||
*/
|
||||
int trinitron(FloatImg *pimg, int notused)
|
||||
{
|
||||
int x, y, coo[4], foo;
|
||||
|
@ -70,16 +165,31 @@ float vals[3];
|
|||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, notused);
|
||||
#endif
|
||||
|
||||
#define STP 16 /* stepd for x & y axex */
|
||||
/* XXX CRITICAL BUG XXX
|
||||
*
|
||||
* what to do if STP is not a modulo of
|
||||
* the width (or size) of the picture ?
|
||||
* why if img height is 600 and stp was 16 ?
|
||||
|
||||
tth@redlady:~/Devel/FloatImg/Fonderie$ bc -l
|
||||
600/16
|
||||
37.50000000000000000000
|
||||
|
||||
*
|
||||
* And this mistake is all around the code /o\
|
||||
*
|
||||
*/
|
||||
#define STP 8 /* stepd for x & y axex */
|
||||
coo[2] = coo[3] = STP;
|
||||
|
||||
for (y=0; y<pimg->height; y+=STP) {
|
||||
for (y=0; y < pimg->height; y+=STP) {
|
||||
coo[1] = y;
|
||||
for (x=0; x<pimg->width; x+=STP) {
|
||||
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 */
|
||||
// XXX fprintf(stderr, "%s %6d %6d\n", __func__, x, y);
|
||||
pixel_trinitron(pimg, coo, vals);
|
||||
}
|
||||
}
|
||||
|
@ -311,19 +421,39 @@ return 0;
|
|||
/* -------------------------------------------------------------- */
|
||||
/* nouveau Mon 10 May 2021 08:46:02 PM CEST
|
||||
* chez Eric 1KA */
|
||||
int des_bords_sombres_b(FloatImg *pimg, int offset)
|
||||
int des_bords_sombres_b(FloatImg *pimg, int nbre)
|
||||
{
|
||||
|
||||
int idx, x, foo;
|
||||
float coef, *fptr;
|
||||
#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 (idx=0; idx<nbre; idx++) {
|
||||
|
||||
coef = (float)idx / (float)nbre;
|
||||
|
||||
fptr = pimg->R + (idx*pimg->width);
|
||||
for (x=0; x<pimg->width; x++) *fptr++ *= coef;
|
||||
fptr = pimg->G + (idx*pimg->width);
|
||||
for (x=0; x<pimg->width; x++) *fptr++ *= coef;
|
||||
fptr = pimg->B + (idx*pimg->width);
|
||||
for (x=0; x<pimg->width; x++) *fptr++ *= coef;
|
||||
|
||||
foo = (pimg->height-idx) - 1;
|
||||
fptr = pimg->R + (foo*pimg->width);
|
||||
// fprintf(stderr, "%5d %9.3f %p\n", foo, coef, fptr);
|
||||
for (x=0; x<pimg->width; x++) *fptr++ *= coef;
|
||||
fptr = pimg->G + (foo*pimg->width);
|
||||
for (x=0; x<pimg->width; x++) *fptr++ *= coef;
|
||||
fptr = pimg->B + (foo*pimg->width);
|
||||
for (x=0; x<pimg->width; x++) *fptr++ *= coef;
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
// fprintf(stderr, "WARNING: %s badly implemented\n", __func__);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
|
|
|
@ -3,8 +3,11 @@
|
|||
* ---------------------------------------------------
|
||||
*/
|
||||
|
||||
int graylevel2popcolors(FloatImg *src, FloatImg *dst, int k);
|
||||
|
||||
int incrustation_vignette(FloatImg *src, FloatImg *dst, int k);
|
||||
|
||||
int poke_sup_rb_g(FloatImg *src, FloatImg *dst);
|
||||
|
||||
int trinitron(FloatImg *pimg, int notused);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
SINGLE
|
||||
SINGLE PICZ PROCESSOR
|
||||
|
||||
experimental and/or testing code, do not use in
|
||||
production.
|
||||
|
||||
|
@ -8,6 +9,8 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
|
@ -23,7 +26,7 @@
|
|||
static int nextpng, counter;
|
||||
static char *destination;
|
||||
static int chainfilter;
|
||||
static int outtype;
|
||||
// static int outtype;
|
||||
|
||||
/* and the classic global var */
|
||||
extern int verbosity;
|
||||
|
@ -98,7 +101,6 @@ 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) {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <glob.h>
|
||||
|
@ -24,6 +25,9 @@
|
|||
int verbosity;
|
||||
|
||||
/* ----------------------------------------------------------- */
|
||||
/*
|
||||
* parameter 'duplic' is the repetition factor
|
||||
*/
|
||||
int run_the_singlepass(char *globber, char *destdir, int duplic,
|
||||
int fchain, int outfmt)
|
||||
{
|
||||
|
@ -34,11 +38,11 @@ char *fname;
|
|||
double elapsed;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' %d %d )\n", __func__,
|
||||
globber, destdir, fchain, outfmt);
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' %d %d %d )\n", __func__,
|
||||
globber, destdir, duplic, fchain, outfmt);
|
||||
#endif
|
||||
|
||||
// filterstack_list(fchain, "Run the single pass");
|
||||
if (verbosity) filterstack_list(fchain, "Run the single pass");
|
||||
|
||||
(void)fimg_timer_set(0);
|
||||
|
||||
|
@ -106,19 +110,15 @@ for (idx=0; idx<globbuf.gl_pathc; idx++) {
|
|||
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");
|
||||
fprintf(stderr, "\n\n");
|
||||
|
||||
globfree(&globbuf);
|
||||
|
||||
fimg_destroy(&image);
|
||||
single_print_state("end of run", 0);
|
||||
// single_print_state("end of run", 0);
|
||||
|
||||
elapsed = fimg_timer_get(0);
|
||||
fprintf(stderr, "%s: %ld frames, elapsed %.3f s, %.3f fps\n",
|
||||
|
@ -155,7 +155,7 @@ char *outdir = "./p8";
|
|||
int do_xper = 0;
|
||||
int repeat = 1;
|
||||
|
||||
fprintf(stderr, "*** %s : compiled %s %s\n", __FILE__,
|
||||
fprintf(stderr, "*** %s\n\tcompiled %s %s\n", argv[0],
|
||||
__DATE__, __TIME__);
|
||||
fimg_print_version(2);
|
||||
|
||||
|
@ -211,6 +211,9 @@ if (verbosity) {
|
|||
fprintf(stderr, "\tdo xper %d\n", do_xper);
|
||||
}
|
||||
|
||||
/*
|
||||
* REAL action here
|
||||
*/
|
||||
foo = run_the_singlepass(globbing, outdir, repeat,
|
||||
FILTERS, FILE_TYPE_PNG);
|
||||
fprintf(stderr, "\n\tRun the single pass --> %d\n", foo);
|
||||
|
|
22
Fonderie/t.c
22
Fonderie/t.c
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <glob.h>
|
||||
|
@ -39,7 +40,7 @@ double debut, fin;
|
|||
|
||||
foo = fimg_create_from_dump(fIname, &image);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d create image\n", foo);
|
||||
fprintf(stderr, "%s: err %d create from dump\n", __func__, foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -72,8 +73,6 @@ return 0;
|
|||
|
||||
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)
|
||||
{
|
||||
|
@ -160,23 +159,24 @@ puts("\t-s\tdo single test");
|
|||
exit(0);
|
||||
}
|
||||
/* ----------------------------------------------------------- */
|
||||
int experiment(void)
|
||||
int experiment(char *fname)
|
||||
{
|
||||
int foo;
|
||||
FloatImg image, dest;
|
||||
|
||||
fprintf(stderr, "EXPERIMENT\n");
|
||||
fprintf(stderr, "----- EXPERIMENT on '%s' -----\n", fname);
|
||||
|
||||
foo = fimg_create_from_dump("01137.fimg", &image);
|
||||
foo = fimg_create_from_dump(fname, &image);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d on create\n", __func__, foo);
|
||||
fprintf(stderr, "%s: err %d on create_from_dump\n",
|
||||
__func__, foo);
|
||||
return -1;
|
||||
}
|
||||
|
||||
foo = fimg_clone(&image, &dest, 1);
|
||||
foo = fimg_copy_data(&image, &dest);
|
||||
foo = fimg_clone(&image, &dest, 0);
|
||||
|
||||
incrustation_vignette(&image, &dest, 0);
|
||||
foo = poke_sup_rb_g(&image, &dest);
|
||||
fprintf(stderr, "poke sup rb g --> %d\n", foo);
|
||||
|
||||
fimg_export_picture(&dest, "foo.png", 0);
|
||||
|
||||
|
@ -228,7 +228,7 @@ if (foo) {
|
|||
}
|
||||
|
||||
if (do_xper) {
|
||||
experiment();
|
||||
experiment(infile);
|
||||
return 0;
|
||||
}
|
||||
if (do_single) {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
|
7
Makefile
7
Makefile
|
@ -3,8 +3,8 @@
|
|||
# a look to the 'build.sh' script ! #
|
||||
####################################################
|
||||
|
||||
COPT = -Wall -fpic -g -pg -no-pie -DDEBUG_LEVEL=0
|
||||
LDOPT = libfloatimg.a -pg -lm
|
||||
COPT = -Wall -Wextra -fpic -g -no-pie -DDEBUG_LEVEL=0
|
||||
LDOPT = libfloatimg.a -g -lm
|
||||
|
||||
all: essai
|
||||
|
||||
|
@ -13,6 +13,9 @@ all: essai
|
|||
essai: essai.c libfloatimg.a floatimg.h Makefile
|
||||
gcc $(COPT) $< $(LDOPT) -lpnglite -lz -o $@
|
||||
|
||||
install:
|
||||
@echo "=== Use the 'install.sh' script ==="
|
||||
|
||||
#---------------------------------------------------------------
|
||||
|
||||
TOTAR = *.[ch] Makefile *.sh *.md \
|
||||
|
|
24
README.md
24
README.md
|
@ -15,7 +15,7 @@ pour les codeurs.
|
|||
Le service après-vente est (plus ou moins bien) assuré sur
|
||||
la [mailing list](https://lists.tetalab.org/mailman/listinfo/tetalab) et/ou
|
||||
le canal IRC #tetalab sur le réseau de
|
||||
[Freenode](https://webchat.freenode.net/)...
|
||||
[Libera.Chat](https://libera.chat/)...
|
||||
|
||||
Par ailleurs, d'autres expérimentations sont
|
||||
[en cours](http://la.buvette.org/photos/cumul/fonderie/vidz.html#interpolator)
|
||||
|
@ -39,6 +39,28 @@ apt install libcfitsio-dev
|
|||
apt install libnetpbm-dev
|
||||
```
|
||||
|
||||
Bon, OK, je suis en train de changer de machine, et ça serait vraiment
|
||||
cool d'avoir juste une ligne à c'n'p, donc voila :
|
||||
|
||||
```
|
||||
apt install libtiff-dev libpnglite-dev liblo-dev libv4l2-dev \
|
||||
libcfitsio-dev libnetpbm-dev
|
||||
```
|
||||
|
||||
Il est probable que j'en oublie.
|
||||
Et ya Debian qui change des trucs, alors, ça marche plus, du
|
||||
genre que c'est la deuxième fois que ça m'arrive.
|
||||
|
||||
```
|
||||
E: Unable to locate package libv4l2-dev
|
||||
E: Unable to locate package libnetpbm-dev
|
||||
```
|
||||
|
||||
Ensuite, j'ai dans l'idée de construire
|
||||
um meta-packet à la sauce Debian pour installer facilement tout ce
|
||||
qui sert à faire fonctionner ce kluge. Ensuite, j'irais voir du
|
||||
coté de pkg-config.
|
||||
|
||||
Certains outils externes sont aussi utiles :
|
||||
|
||||
- gnuplot
|
||||
|
|
6
build.sh
6
build.sh
|
@ -4,7 +4,7 @@
|
|||
|
||||
function build
|
||||
{
|
||||
echo ============= $1 ==============
|
||||
echo "============= $1 =============="
|
||||
curdir=${PWD}
|
||||
cd $1
|
||||
make
|
||||
|
@ -13,7 +13,7 @@ cd ${curdir}
|
|||
|
||||
if [ ${error} -ne 0 ]
|
||||
then
|
||||
echo === error on $1 = ${error}
|
||||
echo "=== error on $1 = ${error}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ build Fonderie
|
|||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
|
||||
echo "========== Project root ==============="
|
||||
make
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
fimg2povhf
|
||||
demo_fmorph
|
||||
|
||||
toto
|
||||
core
|
||||
|
||||
*.tga
|
||||
*.png
|
||||
*.pnm
|
||||
*.gif
|
||||
*.fimg
|
||||
*.mp4
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
DBGL = -DDEBUG_LEVEL=1 -g
|
||||
|
||||
fimg2povhf: fimg2povhf.c Makefile
|
||||
gcc -Wall $(DBGL) $< -limage -lfloatimg -lm -o $@
|
||||
|
||||
# --------------------------------------------------------
|
||||
|
||||
demo_fmorph: demo_fmorph.c Makefile
|
||||
gcc -Wall $(DBGL) $< -lfloatimg -lpnglite -lm -o $@
|
||||
|
||||
in.fimg: Makefile
|
||||
mkfimg -t tpat0 -v $@ 640 480
|
||||
|
||||
out.png: in.fimg demo_fmorph
|
||||
./demo_fmorph $< $@
|
||||
|
||||
# --------------------------------------------------------
|
|
@ -0,0 +1,14 @@
|
|||
# Contributions
|
||||
|
||||
## fimg2povhf
|
||||
|
||||
Need some external garbage, sorry.
|
||||
|
||||
## do_eff_spass.sh
|
||||
|
||||
Script shell permettant (en théorie) de faire un montage
|
||||
d'une petite séquence de chacun des effets disponibles
|
||||
dans la Fonderie. `singlepass` inside.
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* DEMONSTRATOR FOR FMORPHO
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <floatimg.h>
|
||||
|
||||
int verbosity = 1;
|
||||
|
||||
#define DF_W 512
|
||||
#define DF_H 128
|
||||
|
||||
/* ~~~ -------------------------------------------------------------- +++ */
|
||||
int demo_fmorph(char *srcf, char *dsti, int mode)
|
||||
{
|
||||
FloatImg simg, // image source
|
||||
timg, uimg, // intermediaires
|
||||
dimg; // destination
|
||||
FimgArea51 rect;
|
||||
char line[200];
|
||||
|
||||
int foo, pass, hpos;
|
||||
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__, srcf, dsti, mode);
|
||||
|
||||
/*
|
||||
* chargement image source
|
||||
*/
|
||||
foo = fimg_create_from_dump(srcf, &simg);
|
||||
fprintf(stderr, " load of %s --> %d\n", srcf, foo);
|
||||
if (foo) {
|
||||
return foo;
|
||||
}
|
||||
|
||||
/*
|
||||
* images temporaires
|
||||
*/
|
||||
foo = fimg_create(&timg, DF_W, DF_H, FIMG_TYPE_RGB);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d create T img\n", foo);
|
||||
return foo;
|
||||
}
|
||||
foo = fimg_create(&uimg, DF_W, DF_H, FIMG_TYPE_RGB);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d create U img\n", foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
/*
|
||||
* image de destination
|
||||
*/
|
||||
foo = fimg_create(&dimg, DF_W, DF_H*9, FIMG_TYPE_RGB);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d create D img\n", foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
/*
|
||||
* this is an iterator
|
||||
*/
|
||||
rect.x = 20; rect.y = 20;
|
||||
rect.w = DF_W; rect.h = DF_H;
|
||||
|
||||
for (pass=0; pass<9; pass++) {
|
||||
hpos = pass * DF_H;
|
||||
fprintf(stderr, "pass %d, hpos %d\n", pass, hpos);
|
||||
foo = fimg_extractor(&simg, &timg, &rect);
|
||||
|
||||
// sprintf(line, "S_%02d.png", pass);
|
||||
// foo = fimg_save_as_png(&timg, line, 0);
|
||||
|
||||
foo = fimg_filtre_morpho_0(&timg, &uimg, pass);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d filtre morpho, pass %d\n",
|
||||
foo, pass);
|
||||
exit(1);
|
||||
}
|
||||
sprintf(line, "D_%02d.png", pass);
|
||||
foo = fimg_save_as_png(&uimg, line, 0);
|
||||
|
||||
foo = fimg_incrustator_0(&uimg, &dimg, 0, hpos, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d incrustator\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
foo = fimg_save_as_png(&dimg, dsti, 0);
|
||||
/*
|
||||
* do some cleanup
|
||||
*/
|
||||
fimg_destroy(&simg); fimg_destroy(&timg); fimg_destroy(&dimg);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ~~~ -------------------------------------------------------------- +++ */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo;
|
||||
|
||||
fimg_print_version(1);
|
||||
|
||||
if (3 != argc) {
|
||||
fprintf(stderr, "usage:\n\t%s src.fimg dst.png\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
foo = demo_fmorph(argv[1], argv[2], 0);
|
||||
fprintf(stderr, " got --> %d\n", foo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ~~~ -------------------------------------------------------------- +++ */
|
|
@ -0,0 +1,163 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
SPASS="../Fonderie/singlepass"
|
||||
|
||||
SRCDIR=$HOME"/Essais/PS-eye/frames/"
|
||||
DSTPOL=$HOME"/TMP/"
|
||||
echo "source = " $SRCDIR
|
||||
echo "spool = " $DSTPOL
|
||||
|
||||
LINKFARM=$DSTPOL"LinkFarm"
|
||||
echo "linkfarm = " $LINKFARM
|
||||
|
||||
# VIDZ="$HOME/BU/vrac/all_effects.mp4"
|
||||
VIDZ="foo.mp4"
|
||||
echo "lolvidz = " $VIDZ
|
||||
|
||||
LINKNUM=0
|
||||
|
||||
# --------------------------------------------
|
||||
|
||||
do_an_effect_pass()
|
||||
{
|
||||
local effect=$1
|
||||
local ddir=$2
|
||||
|
||||
figlet "$effect" ; echo
|
||||
echo " files to ===> " $ddir
|
||||
|
||||
rm -f $ddir/?????.png
|
||||
|
||||
$SPASS -F $effect \
|
||||
-g $SRCDIR/'?????.fimg' \
|
||||
-O $ddir \
|
||||
-r 1
|
||||
|
||||
}
|
||||
|
||||
# --------------------------------------------
|
||||
insert_blank()
|
||||
{
|
||||
local count=$1
|
||||
|
||||
local imgname="$DSTPOL/blank.fimg"
|
||||
|
||||
if [ ! -r $imgname ] ; then
|
||||
mkfimg -v -t black $imgname 640 480
|
||||
fimg2png -v $imgname $DSTPOL/blank.png
|
||||
echo "blankimage done" | boxes
|
||||
# display $DSTPOL/blank.png &
|
||||
# exit
|
||||
fi
|
||||
|
||||
for foo in $(seq 0 $count)
|
||||
do
|
||||
linkname=$(printf "%s/L%05d.png" $LINKFARM $LINKNUM)
|
||||
ln --force --symbolic $DSTPOL/blank.png $linkname
|
||||
# file $linkname
|
||||
LINKNUM=$(( LINKNUM + 1 ))
|
||||
done
|
||||
}
|
||||
# --------------------------------------------
|
||||
|
||||
make_the_linkfarm_from()
|
||||
{
|
||||
local effname=$1
|
||||
local sdir=$2
|
||||
|
||||
echo "====== Linkfarming from " $sdir \
|
||||
"====== avec" $(ls $sdir | wc -l) "images"
|
||||
|
||||
mogrify \
|
||||
-font Utopia-Bold \
|
||||
-pointsize 64 \
|
||||
-kerning 9 \
|
||||
-fill Gray90 \
|
||||
-stroke Gray10 \
|
||||
-strokewidth 2 \
|
||||
-gravity South-East \
|
||||
-annotate +30+20 $effname \
|
||||
$sdir/*.png
|
||||
|
||||
for img in $(ls -1 $sdir/?????.png)
|
||||
do
|
||||
|
||||
linkname=$(printf "%s/L%05d.png" $LINKFARM $LINKNUM)
|
||||
# echo "image = " $img
|
||||
# echo "link = " $linkname
|
||||
|
||||
ln --force --symbolic $img $linkname
|
||||
|
||||
LINKNUM=$(( LINKNUM + 1 ))
|
||||
done
|
||||
echo " linkfarming done"
|
||||
}
|
||||
# --------------------------------------------
|
||||
# traite tous les effets
|
||||
|
||||
do_all_the_effects()
|
||||
{
|
||||
EFFECTS=$( $SPASS -L | sort )
|
||||
|
||||
banner 'FULL RUN'
|
||||
|
||||
for effect in $EFFECTS
|
||||
do
|
||||
DDIR=$DSTPOL"/$effect"
|
||||
|
||||
if [ -d $DDIR ] ; then
|
||||
rm -f $DDIR"/?????.png"
|
||||
fi
|
||||
if [ ! -r $DDIR ] ; then
|
||||
mkdir -v $DDIR
|
||||
fi
|
||||
|
||||
do_an_effect_pass $effect $DDIR
|
||||
make_the_linkfarm_from $effect $DDIR
|
||||
|
||||
insert_blank 30
|
||||
done
|
||||
}
|
||||
|
||||
# --------------------------------------------
|
||||
|
||||
debug_run()
|
||||
{
|
||||
local eff=$1
|
||||
local DDIR=$DSTPOL"/$eff"
|
||||
|
||||
banner 'DEBUG RUN'
|
||||
echo "DDIR = " $DDIR
|
||||
|
||||
do_an_effect_pass $eff $DDIR
|
||||
make_the_linkfarm_from $eff $DDIR
|
||||
}
|
||||
|
||||
# --------------------------------------------
|
||||
# MAIN
|
||||
|
||||
echo
|
||||
|
||||
rm -v -f $LINKFARM/L*.png ; echo
|
||||
|
||||
insert_blank 30
|
||||
|
||||
# debug_run 'rndblks'
|
||||
do_all_the_effects
|
||||
|
||||
banner 'encoding'
|
||||
|
||||
ffmpeg -nostdin \
|
||||
-loglevel warning \
|
||||
-y -r 30 -f image2 -i ${LINKFARM}/L%05d.png \
|
||||
-metadata artist='---[ tTh ]---' \
|
||||
-metadata title='---[ All the 'Fonderie' effects ]---' \
|
||||
-preset veryslow \
|
||||
-c:v libx264 -pix_fmt yuv420p \
|
||||
$VIDZ
|
||||
|
||||
echo " encoding of " $VIDZ " . . . . . [done]"
|
||||
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* convertir une image flottante en champ d'altitude
|
||||
*
|
||||
* nouveau 64 ernest renan - 20220108
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "tthimage.h"
|
||||
#include "floatimg.h"
|
||||
|
||||
int verbosity;
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
int This_is_the_real_conversion(FloatImg *fimg, Image_Desc *hf, int k)
|
||||
{
|
||||
int foo;
|
||||
float minmax[6];
|
||||
int x, y, h;
|
||||
float rgb[6], cumul;
|
||||
float maxi;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, fimg, hf, k);
|
||||
#endif
|
||||
|
||||
foo = fimg_get_minmax_rgb(fimg, minmax);
|
||||
// fimg_print_minmax(minmax, "source");
|
||||
|
||||
maxi = 0.0;
|
||||
|
||||
for (y=0; y<fimg->height; y++) {
|
||||
for (x=0; x<fimg->width; x++) {
|
||||
foo = fimg_get_rgb(fimg, x, y, rgb);
|
||||
/* non-magic nuabmer spotted */
|
||||
cumul = 1.732 * (rgb[1] + rgb[3] + rgb[5]);
|
||||
if (cumul > maxi) maxi = cumul;
|
||||
h = (int)cumul;
|
||||
foo = Image_hf15_plot(hf, x, y, h);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "--- the critical maximum is %f\n", maxi);
|
||||
|
||||
return FULL_NUCKED;
|
||||
}
|
||||
/* ------------------------------------------------------------------ */
|
||||
int Convertir_Fimg_to_Povhf(char *fimgname, char *hfname, int k)
|
||||
{
|
||||
FloatImg fimg;
|
||||
Image_Desc *hf;
|
||||
int wid, hei;
|
||||
int foo;
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %s %s %d )\n", __func__, fimgname, hfname, k);
|
||||
#endif
|
||||
|
||||
foo = fimg_create_from_dump(fimgname, &fimg);
|
||||
fprintf(stderr, "load of %s --> %d\n", fimgname, foo);
|
||||
if (foo) {
|
||||
return foo;
|
||||
}
|
||||
|
||||
wid = fimg.width; hei = fimg.height; // nice alias
|
||||
fprintf(stderr, " source picture size %dx%d\n", wid, hei);
|
||||
|
||||
hf = Image_alloc(wid, hei, IMAGE_RGB);
|
||||
fprintf(stderr, "hf alloc -> %p\n", hf);
|
||||
if (NULL == hf) {
|
||||
return NULL_POINTER;
|
||||
}
|
||||
|
||||
foo = This_is_the_real_conversion(&fimg, hf, k);
|
||||
fprintf(stderr, "real conversion -> %d\n", foo);
|
||||
|
||||
foo = Image_TGA_save(hfname, hf, 0);
|
||||
fprintf(stderr, "export as tga -> %d\n", foo);
|
||||
|
||||
return FULL_NUCKED;
|
||||
}
|
||||
/* ------------------------------------------------------------------ */
|
||||
void help(int nu)
|
||||
{
|
||||
printf("usage :\n");
|
||||
printf("\t$ fimg2povhf src.fimg dst.tga\n");
|
||||
}
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo;
|
||||
|
||||
verbosity = 1;
|
||||
|
||||
// printf("%s: argc = %d\n", argv[0], argc);
|
||||
|
||||
if (3 != argc) {
|
||||
help(0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (verbosity > 1) {
|
||||
Image_print_version(3);
|
||||
fimg_print_version(3);
|
||||
}
|
||||
|
||||
foo = Convertir_Fimg_to_Povhf(argv[1], argv[2], 0);
|
||||
fprintf(stderr, "retour conversion was %d\n", foo);
|
||||
|
||||
fprintf(stderr, "end\n\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
src="/dev/shm/foo.fimg"
|
||||
dst="hf.tga"
|
||||
TMPDIR=${HOME}/TMP
|
||||
|
||||
POVOPT="-w512 -h342 +q9 -a "
|
||||
|
||||
rm $TMPDIR/hf???.png
|
||||
|
||||
for idx in $(seq 0 60)
|
||||
do
|
||||
|
||||
echo "========================== " $idx
|
||||
|
||||
grabvidseq -v \
|
||||
-d /dev/video0 -s 640x480 \
|
||||
-n 60 -p 1.0 \
|
||||
-o ${src}
|
||||
|
||||
./fimg2povhf $src $dst
|
||||
|
||||
out=$(printf "%s/hf%03d.png" $TMPDIR $idx)
|
||||
echo "raytracing " ${POVOPT} $out
|
||||
povray -iscene.pov ${POVOPT} -o${out} 2> pov.stderr
|
||||
# tail -15 pov.stderr
|
||||
|
||||
done
|
||||
|
||||
convert -delay 10 -colors 240 $TMPDIR/hf???.png foo.gif
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
|
||||
/* scene demo conversion floatimg -> height field */
|
||||
|
||||
#version 3.7;
|
||||
|
||||
global_settings {
|
||||
ambient_light rgb <0.07, 0.07, 0.07>
|
||||
assumed_gamma 1.0
|
||||
}
|
||||
|
||||
#include "colors.inc"
|
||||
|
||||
height_field {
|
||||
tga "hf.tga"
|
||||
smooth
|
||||
pigment { color Orange*0.7 }
|
||||
translate <-0.5, 0, -0.5>
|
||||
// scale 2
|
||||
translate y*0.002
|
||||
}
|
||||
|
||||
camera {
|
||||
location <-0.86, 4, -6.20>
|
||||
look_at <0, 0, 0>
|
||||
angle 14
|
||||
}
|
||||
|
||||
plane {
|
||||
<0, 1, 0>, 0
|
||||
pigment {
|
||||
hexagon
|
||||
pigment { color Gray20 },
|
||||
pigment { color Gray10 },
|
||||
pigment { color Gray30 }
|
||||
}
|
||||
scale 0.27
|
||||
}
|
||||
|
||||
|
||||
light_source { <-9, 2, 3> color White }
|
||||
|
|
@ -1,7 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
#
|
||||
# this script generate some picz for the PDF documentation
|
||||
# and was called by mkdoc.sh
|
||||
#
|
||||
|
||||
PI=" 3.141592654 "
|
||||
|
||||
# ---------------------------------------------------
|
||||
|
||||
OUT="cos01.tex"
|
||||
|
||||
gnuplot << __EOF__
|
||||
|
@ -24,6 +31,8 @@ __EOF__
|
|||
|
||||
wc $OUT
|
||||
|
||||
# ---------------------------------------------------
|
||||
|
||||
OUT="cos010.tex"
|
||||
|
||||
gnuplot << __EOF__
|
||||
|
@ -45,3 +54,5 @@ plot \
|
|||
__EOF__
|
||||
|
||||
wc $OUT
|
||||
|
||||
# ---------------------------------------------------
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
% \lstset{frame=single} % dessin d'un cadre autour du listing
|
||||
\lstset{basicstyle=\ttfamily\small}
|
||||
\lstset{aboveskip=0.1em,belowskip=0.1em}
|
||||
\lstset{aboveskip=0.01em,belowskip=0.1em}
|
||||
|
||||
\usepackage{babel} % ?
|
||||
|
||||
|
@ -25,8 +25,10 @@
|
|||
% \usepackage{url}
|
||||
\usepackage{xspace}
|
||||
\usepackage[verbose]{layout}
|
||||
\usepackage{ulem}
|
||||
|
||||
\setlength \parskip {0.35em}
|
||||
\setlength \parskip {0.15em}
|
||||
\setcounter{tocdepth}{1} % XXX à regarder un de ces jours ?
|
||||
|
||||
\makeatletter
|
||||
% explication de ce truc ?
|
||||
|
@ -41,7 +43,7 @@
|
|||
\makeindex
|
||||
|
||||
% ------ a few new commands
|
||||
\newcommand{\interparagraphe { \vspace{60pt} } }
|
||||
\newcommand{\interparagraphe { \vspace{50pt} } }
|
||||
|
||||
% -------------------------------------------------------------------
|
||||
\title{Floating images processing (for fun and profit ?)}
|
||||
|
@ -52,6 +54,8 @@
|
|||
|
||||
\section*{Une image flottante ?}
|
||||
|
||||
\textsl{Back in a far past part of history.}
|
||||
|
||||
\textsl{Mais de quoi parle-t-on exactement ?}
|
||||
|
||||
% XXX XXX XXX\vspace{1em}
|
||||
|
@ -69,15 +73,21 @@ chaque pixel en virgule flottante sur 32bits, le type
|
|||
% XXX XXX XXX\vspace{1em}
|
||||
|
||||
\textbf{Attention !} tout le code que nous allons voir ensemble est en
|
||||
perpétuelle évolution\footnote{voir page \pageref{TODO}},
|
||||
perpétuelle évolution\footnote{voir page \pageref{TODO} pour les détails},
|
||||
et sa fiablité (surtout sur certains aspects mathématiques)
|
||||
reste à démontrer\index{valgrind}.
|
||||
Mais le service après-vente est assez réactif. Du moins
|
||||
pour ceux qui suivent le canal \texttt{\#tetalab} sur le réseau
|
||||
IRC de Freenode.
|
||||
IRC de \textsl{libera.chat}.
|
||||
|
||||
\textbf{Attention !} ce document commence par une bonne rafale
|
||||
de technique parfois \textsl{hardue}.
|
||||
de technique parfois \textsl{hardue}\footnote{hard + ardue = private
|
||||
joke Usenet}, avec des pointeurs dedans, mais vous êtes déja
|
||||
au courant.
|
||||
Le pointeur, c'est bien, c'est comme le doigt sur les écrans
|
||||
de zombiephones, ça sert juste à dire «~C'est là !~», c'est
|
||||
donc gravement utile, mais parfois, le doigt glisse.
|
||||
Et là, tout peut arriver.
|
||||
Vous avez parfaitement le droit de sauter directement à
|
||||
la page \pageref{outils} pour quelque chose de plus concret.
|
||||
|
||||
|
@ -92,7 +102,7 @@ certains points. Je vais tenter de répondre à ces FAQ~:%
|
|||
« Fréquentes et Absurdes Questions » avec des réponses
|
||||
absurdes et précises.
|
||||
|
||||
\subsubsection*{c'est quoi un image d'un point de vue physique ?}
|
||||
\subsubsection*{c'est quoi une image d'un point de vue physique ?}
|
||||
|
||||
Une représentation approximative d'un monde physique invisible.
|
||||
L'infinie bio-complexité de notre système oculaire et ses interactions
|
||||
|
@ -103,7 +113,7 @@ physique.
|
|||
|
||||
Les détails techniques sur cette représentation sont en page
|
||||
\pageref{FloatImg desc}, avec des pointeurs dedans.
|
||||
Ah, les pointeurs, la pire chose du monde\dots
|
||||
Ah, les pointeurs, la pire chose du monde, mais pourquoi s'en passer\dots
|
||||
|
||||
\subsubsection*{quelques rappels de comment on acquiert et numérise une image}
|
||||
|
||||
|
@ -122,13 +132,13 @@ dans les machin-trocs, et un grain d'image vraiment présent.
|
|||
|
||||
Ah vous en voulez de la technique ? Oké, on y va.
|
||||
En fait, on va tripoter pleins de nombres, plus ou moins rangés dans
|
||||
des pixels, pour concrétiser l'existence perceptuelles de ces
|
||||
des champs de pixels, pour concrétiser l'existence perceptuelle de ces
|
||||
grains de lumière chromatisés.
|
||||
|
||||
\subsubsection*{quelques belles images / schémas polychromes en intro pour
|
||||
illustrer tout ça}
|
||||
|
||||
Tour cela est dans le grand Ternet\footnote{\textsl{Thanks, mister J Postel}}
|
||||
Tour cela est dans le grand Ternet
|
||||
mondial, je pourrais même vous donner l'url si vous me promettez de ne pas
|
||||
la glisser dans le capitalisme de surveillance.
|
||||
|
||||
|
@ -136,20 +146,22 @@ la glisser dans le capitalisme de surveillance.
|
|||
|
||||
\setlength \parskip {0em}
|
||||
|
||||
\pagebreak
|
||||
\tableofcontents
|
||||
\pagebreak
|
||||
\setlength \parskip {0.40em}
|
||||
|
||||
\layout \pagebreak
|
||||
% XXX \layout \pagebreak
|
||||
|
||||
% ===================================================================
|
||||
\section{Théorie}\index{théorie}
|
||||
|
||||
\section{Théorie}\index{théorie}
|
||||
|
||||
Pour le moment, seule la quête de l'empirisme absolu a été
|
||||
visée. Les justifications mathématiques attendront le retour
|
||||
du schmod777. Ceci dit, rien ne nous empêche d'aller consulter
|
||||
Wikipedia~:
|
||||
Wikipedia, afin de mieux connaitre ces nombres flottants
|
||||
que nous allons utiliser~:
|
||||
|
||||
\begin{quotation}
|
||||
An IEEE 754 32-bit base-2 floating-point variable has
|
||||
|
@ -164,22 +176,35 @@ officially referred to as binary32; it was called single in
|
|||
IEEE 754-1985.
|
||||
\end{quotation}
|
||||
|
||||
Ce qui nous conduit à estimer qu'il est possible de cumuler environ
|
||||
quelques milliers d'images standard à 256 niveaux, sans trop avoir
|
||||
à se soucier des éventuelles pertes de précision. Mais ça demande
|
||||
à être confirmé par des esprits supérieurs.
|
||||
% XXX
|
||||
% Ce qui nous conduit à estimer qu'il est possible de cumuler environ
|
||||
% quelques milliers d'images standard à 256 niveaux, sans trop avoir
|
||||
% à se soucier des éventuelles pertes de précision. Mais ça demande
|
||||
% à être confirmé par des esprits supérieurs.
|
||||
|
||||
https://dl.acm.org/doi/pdf/10.1145/103162.103163
|
||||
|
||||
\subsection{Dynamique}\index{dynamique}
|
||||
|
||||
Dynamique, précision et \textsl{macheps} ? Peu de gens connaissent
|
||||
la fourbitude des calculs en virgule flottante avec les ordinateurs.
|
||||
Moi-même compris.
|
||||
Moi-même compris. Il est évident qu'une étude théorique doit être
|
||||
effectuée afin d'éviter les potentiels inconvénients.
|
||||
|
||||
Ceci dit, le standard \textsl{ieee754}\index{ieee754} nous indique qu'il
|
||||
y a 23 bits pour la mantisse, ce qui nous propose déja
|
||||
plus de huit millions de valeurs. Considérons un cas typique~:
|
||||
le cumul de $N$ images ayant un niveau maximum $Vm$.
|
||||
|
||||
\subsection{Pixel négatif ?}
|
||||
|
||||
Il est très difficle d'imaginer une lumière négative. Sauf peut-être
|
||||
si nous songeons à des coefficients d'absorption, ou un canal
|
||||
\textsl{alpha} qui inverserait les valeurs ?
|
||||
\textsl{alpha} qui inverserait les valeurs ? Un domaine dont
|
||||
l'exploration peut confiner au mysticisme de part la multitude
|
||||
des traitement possibles : valeur absolue, \textsl{clamping},
|
||||
report sur les autres composantes. Votre imagination est
|
||||
la limite.
|
||||
|
||||
% ===================================================================
|
||||
|
||||
|
@ -191,7 +216,8 @@ et sur disque. Ça a été imaginé de façon presque empirique,
|
|||
mais nous sommes tous là pour améliorer les choses, dans
|
||||
la mesure de nos moyens.
|
||||
Nous allons donc directement rentrer au cœur du problème,
|
||||
en écrivant quelques lignes de code.
|
||||
en écrivant quelques lignes de code montrant le fonctionnement
|
||||
général de la chose.
|
||||
|
||||
\subsection{L'idée}
|
||||
|
||||
|
@ -199,24 +225,28 @@ Pour commencer par quelque chose de simple,
|
|||
nous allons créer une image RGB\index{RGB} complètement noire,
|
||||
puis l'enregistrer dans un fichier \texttt{.fimg}\index{.fimg},
|
||||
un format complètement inconnu, puisque je viens de l'inventer
|
||||
à l'instant même.
|
||||
Enfin, non, il y a déja longtemps, avant la grande pandémie.
|
||||
à l'instant même\footnote{Enfin, non, il y a déja longtemps,
|
||||
avant la grande pandémie.}.
|
||||
|
||||
Tout d'abord, nous devons déclarer et garnir quelques variables
|
||||
pour gérer la machinerie interne.
|
||||
|
||||
\begin{lstlisting}
|
||||
int width = 640, height = 480;
|
||||
char *fname = "exemple.fimg";
|
||||
char *fname = "quux.fimg";
|
||||
FloatImg fimg;
|
||||
\end{lstlisting}
|
||||
|
||||
Ensuite, nous enchainerons trois étapes : la création de l'image
|
||||
en mémoire centrale, l'initialisation des valeurs de chaque pixel à 0.0,
|
||||
et pour conclure, l'enregistrement dans un fichier\footnote{Au format
|
||||
en mémoire centrale, l'initialisation des valeurs de chaque pixel à 0.0
|
||||
(une valeur que certains associent au noir complet, et d'autres à une
|
||||
impossibilité quantique),
|
||||
et pour conclure, l'enregistrement de cette image dans un
|
||||
fichier\footnote{Au format
|
||||
ésotérique, mais très véloce.} binaire.
|
||||
|
||||
\begin{lstlisting}
|
||||
memset(fimg, 0, sizeof(FloatImg));
|
||||
foo = fimg_create(&fimg, width, height, FIMG_TYPE_RGB);
|
||||
if (foo) {
|
||||
fprintf(stderr, "create floatimg -> %d\n", foo);
|
||||
|
@ -231,9 +261,9 @@ if (foo) {
|
|||
\end{lstlisting}
|
||||
|
||||
|
||||
Une fois ce code enrobé dans un \texttt{main()}, compilé et exécuté,
|
||||
Une fois ce code enrobé dans un \texttt{main()}, compilé puis exécuté,
|
||||
nous pouvons entrevoir, grâce au logiciel
|
||||
\texttt{fimgstats} (voir page \pageref{fimgstats}),
|
||||
\texttt{fimgstats} (décrit en page \pageref{fimgstats}),
|
||||
le résultat sous forme de chiffres divers, et/ou inutiles~:
|
||||
|
||||
\begin{verbatim}
|
||||
|
@ -257,9 +287,9 @@ Avec un bon script bash, il y a déja de quoi faire.
|
|||
La suite vers la page \pageref{codaz}.
|
||||
|
||||
Vous trouverez dans le répertoire \texttt{tools/}\index{tools/}
|
||||
d'autres exemples de mise en œuvre des fonctions disponibles
|
||||
d'autres exemples de mise en œuvre de quelques fonctions disponibles
|
||||
sous formes d'outils en ligne de commande,
|
||||
lesquels sont approximativement décrits en page \pageref{outils}.
|
||||
lesquels outils sont approximativement décrits en page \pageref{outils}.
|
||||
|
||||
% ===================================================================
|
||||
\section{Installation}
|
||||
|
@ -275,15 +305,15 @@ soucis de boutisme.
|
|||
\subsection{Prérequis}
|
||||
|
||||
Vous devez, en dehors des outils classiques (gcc, Awk, make\dots),
|
||||
avoir quelques bibliothèques installées\footnote{Les \texttt{-dev}
|
||||
en plus pour Debian et dérivées}~:
|
||||
avoir quelques bibliothèques installées~:
|
||||
\textsf{
|
||||
libv4l2, libpnglite, libtiff,
|
||||
libnetpbm\footnote{package libnetpbm10-dev},
|
||||
libz\footnote{package zlib1g-dev}, libcurses,
|
||||
libcfitsio-dev
|
||||
libcfitsio...
|
||||
} % end of textsf
|
||||
éventuellement avec le \textsf{-dev} correspondant,
|
||||
éventuellement avec le \textsf{-dev} correspondant, qui contient, entre
|
||||
autres, les fichiers \texttt{.h} associés
|
||||
et probablement d'autres choses.
|
||||
|
||||
Il est même quasiment certain que Bash soit indispensable, tout
|
||||
|
@ -291,7 +321,11 @@ comme \textsc{gnu}/make\index{make}.
|
|||
Une connaissance de base de l'utilisation du shell\index{shell}
|
||||
et de l'écriture de Makefile's sera un plus.
|
||||
|
||||
Il faut aussi savoir où trouver le code.
|
||||
Il faut aussi savoir où trouver le code. Il est dans le Git du
|
||||
Tetalab\footnote{\texttt{https://git.tetalab.org/tTh/FloatImg}}.
|
||||
Mais comme je ne comprend rien à Git, c'est pas la peine
|
||||
de m'envoyer des trucs genre \textsl{pull-request} auquels je ne
|
||||
comprend rien.
|
||||
|
||||
\subsection{Compilation}
|
||||
|
||||
|
@ -331,7 +365,7 @@ Faites-en ce que vous voulez.
|
|||
Classiquement, il y a un fichier \texttt{.h} à inclure dans chacun
|
||||
de vos codes source,
|
||||
\texttt{floatimg.h}, généralement logé dans \texttt{/usr/local/include}
|
||||
contenant un certain nombre de définition de structures, de macros,
|
||||
et contenant un certain nombre de définition de structures, de macros,
|
||||
de constantes\footnote{À l'ancienne, via le pré-processeur}
|
||||
et les prototypes des fonctions utilisables par vos logiciels.
|
||||
|
||||
|
@ -340,7 +374,7 @@ classées en deux catégories : \texttt{lib/} et \texttt{funcs/}.
|
|||
La première contient les choses qui sont relativement figées,
|
||||
et la seconde celles qui risquent de bouger. Cette classification
|
||||
est en fait indécement arbitraire.
|
||||
D'autant plus qu'il y a aussi un répertoire nommé « experiemental ».
|
||||
D'autant plus qu'il y a aussi un répertoire nommé « experimental ».
|
||||
|
||||
\subsection{Structures, macros\dots}
|
||||
|
||||
|
@ -399,7 +433,7 @@ quelques images...
|
|||
|
||||
Le champ \textsl{count} sera mis à 0 et
|
||||
le champ \textsl{fval} sera initialisé à 15.0
|
||||
(qui est la valeur maximale que peut renvoyer ce capteur).
|
||||
(ce qui est la valeur maximale que peut renvoyer ce capteur).
|
||||
Ensuite, dans la boucle capture/cumul, \textsl{count} sera
|
||||
incrémenté à chaque passe, et nous aurons donc, en finale,
|
||||
toutes les informations nécessaires pour exploiter au mieux la dynamique
|
||||
|
@ -438,15 +472,16 @@ avant le moindre usage\footnote{\texttt{man 3 memset}}.
|
|||
Certains membres de cette structure sont
|
||||
documentés dans ce document, et les autres sont dangereux à
|
||||
toucher. Les types d'images actuellement gérés sont les trois grands
|
||||
classiques : gray, rgb et rgba. et expliquées quelques lignes plus haut.
|
||||
classiques : niveau de gris, rouge-vert-bleu et rgb avec un canal alpha,
|
||||
et expliquées quelques lignes plus haut.
|
||||
|
||||
Comme vous allez le voir plus loin, il y a plein de fonctions qui
|
||||
prennent en argument deux images: une source et une destination.
|
||||
Et dans la plupart des cas, ces deux images doivent être compatibles,
|
||||
prennent en argument deux images: la source et la destination.
|
||||
Dans la plupart des cas, ces deux images doivent être compatibles,
|
||||
c'est à dire même type et mêmes dimensions.
|
||||
|
||||
\begin{lstlisting}
|
||||
/* return 0 if compatible */
|
||||
/* return 0 if pictures are compatible */
|
||||
int fimg_images_not_compatible(FloatImg *a, FloatImg *b);
|
||||
\end{lstlisting}
|
||||
|
||||
|
@ -455,7 +490,7 @@ C'est bien beau d'être enfin une image résidente en mémoire centrale, mais
|
|||
pouvoir aussi exister à long terme en étant stocké dans la matrice
|
||||
est tout aussi pertinent.
|
||||
Il y a deux opérations qui supportent le reste des transits ram/ps.
|
||||
Le format des fichiers est décrit page \pageref{formatfimg}.
|
||||
Le format de ces fichiers est décrit page \pageref{formatfimg}.
|
||||
|
||||
\begin{lstlisting}
|
||||
int fimg_dump_to_file(FloatImg *fimg, char *fname, int notused);
|
||||
|
@ -465,7 +500,7 @@ int fimg_load_from_dump(char *fname, FloatImg *where);
|
|||
Recharger une image depuis un fichier nécessite que celle-ci et
|
||||
l'image de destination en mémoire
|
||||
ait précisément les mêmes caractéristiques
|
||||
(taille, type...), donc l'image en ram doit être
|
||||
(taille, type...), donc l'image en mémoire centrale doit être
|
||||
pré-allouée. On peut connaitre ces valeurs en appelant
|
||||
\texttt{int fimg\_fileinfos(char *fname, int datas[3])}.
|
||||
|
||||
|
@ -489,7 +524,9 @@ foo = fimg_create_from_dump("lena.fimg", &head);
|
|||
|
||||
Si la valeur retournée est différente de 0, c'est que quelque
|
||||
chose s'est probablement mal passé.
|
||||
Certains messages sont parfois explicites.
|
||||
Certains messages sont parfois explicites. Mais parfois non.
|
||||
Quand aux valeurs retournées en cas d'erreur, c'est le désordre
|
||||
intégral\footnote{Un vrai désastre, même...}.
|
||||
|
||||
% _________
|
||||
|
||||
|
@ -519,7 +556,8 @@ $x$ et $y$ de la demande.
|
|||
Quand au canal \textsl{alpha}\index{alpha}, il est pour le moment
|
||||
superbement ignoré. Ceci dit, on vient de me faire remarquer qu'il
|
||||
peut être utilisable aussi pour faire du
|
||||
\textsl{z-buffer}\index{z-buffer}\index{rgbz}\dots
|
||||
\textsl{z-buffer}\index{z-buffer}\index{rgbz}, une technique
|
||||
classique dans la génération d'images en trois dimensions.\dots
|
||||
|
||||
% ----------------------------------
|
||||
|
||||
|
@ -637,32 +675,73 @@ aux bonnes dimensions (échange W et H).
|
|||
\subsection{Format du fichier \textsc{fimg}}\index{format}\label{formatfimg}
|
||||
|
||||
D'un design très empirique, c'est certainement à revoir pour l'avenir.
|
||||
Tout d'abord pour normaliser l'endianess et le packing\dots
|
||||
La force du \textsl{legacy} va-t-elle dominer le monde ?
|
||||
Il faudrait normaliser l'endianess et le packing dans les structs%
|
||||
\footnote{Directives du compilateur ?}, et surtout l'ajout
|
||||
de données sur la prise de vue, du genre type de capteur, date et heure,
|
||||
réglages divers\dots
|
||||
|
||||
\begin{lstlisting}
|
||||
typedef struct {
|
||||
char magic[8];
|
||||
int w, h, t;
|
||||
int32_t w, h, t;
|
||||
} FimgFileHead;
|
||||
\end{lstlisting}
|
||||
|
||||
\dots Mais aussi pour faciliter l'ajout de métadonnées, telles que
|
||||
la valeur maximale, la date de création, une longueur d'onde,
|
||||
et bien plus encore.
|
||||
|
||||
Le champ \texttt{magic[8]} doit contenir une valeur magique~:
|
||||
les quatre premier octets doivent contenir les quatre caractères
|
||||
\texttt{'FIMG'}, et les quatre dernier doivent être à 0.
|
||||
les quatre premiers octets doivent contenir les quatre caractères
|
||||
\texttt{'FIMG'}, et les quatre derniers doivent être à 0, sauf que,
|
||||
voir plus bas, le cinquième vas vous étonner.
|
||||
Le champ \texttt{t} (le type de l'image) doit avoir les trois octets
|
||||
de poids fort à 0. Vous trouverez les constantes de type dans le
|
||||
de poids fort à 0\footnote{Pourquoi ? Je n'en sais rien.}.
|
||||
|
||||
Ensuite, nous aurons (dans le cas courant) : 1, 2 ou 4 blocs
|
||||
de WxH pixels sous forme de Float32. La première ligne lue
|
||||
est la ligne du haut de l'image. Les valeurs négatives sont
|
||||
tolérées.
|
||||
|
||||
Vous trouverez les constantes de type pertinentes dans le
|
||||
fichier \texttt{floatimg.h}, et quelques informations
|
||||
(non-)essentielles.
|
||||
(non-)essentielles qui ne vous serviront probablement à rien.
|
||||
|
||||
|
||||
% ----------------------------------
|
||||
% new février 2022
|
||||
|
||||
\subsection{Métadonnées}
|
||||
\index{metadata} \index{timestamp}
|
||||
|
||||
Attention, ce n'est pas encore une version définitive, beaucoup de
|
||||
choses restent à préciser sur le contenu de cette structure, mais
|
||||
l'essentiel est déja là. On reconnait un fichier avec metadata
|
||||
quand l'octet \texttt{magic[4]} du premier header est égal à
|
||||
la lettre \texttt{'a'}.
|
||||
|
||||
\begin{lstlisting}
|
||||
typedef struct {
|
||||
char magic[8];
|
||||
struct timeval timestamp;
|
||||
int32_t count;
|
||||
float fval;
|
||||
char idcam[32];
|
||||
int32_t origin; // enum ?
|
||||
} FimgMetaData;
|
||||
\end{lstlisting}
|
||||
|
||||
Voyons maintenant chacun des champs de cette structure, en prenant bien
|
||||
en compte qu'à ce moment\footnote{4 avril 2022}, tout n'est pas figé.
|
||||
Ceci dit, nous allons aussi retrouver de vieilles connaissances.
|
||||
|
||||
\textbf{to be continued}
|
||||
|
||||
% ----------------------------------
|
||||
|
||||
\subsection{Exportation \& Importation}\index{export}\label{export}
|
||||
|
||||
Notre format de fichier étant totalement inconnu, il nous
|
||||
Notre format de fichier étant totalement inconnu%
|
||||
\footnote{Du monde extérieur, vous l'aurez compris.},
|
||||
il nous
|
||||
faut bien exporter nos images en quelque chose de plus
|
||||
connu. Bien entendu, c'est toujours affaire de compromis
|
||||
entre précision de valeurs et taille des fichiers.
|
||||
|
@ -671,7 +750,7 @@ Et dans le sens inverse, il serait bien de savoir importer
|
|||
le monde extérieur dans nos sombres caves à pixel.
|
||||
Il faut quand même reconnaitre que c'est un peu la jungle dans les
|
||||
formats de fichiers d'image, ce qui explique le retard
|
||||
dans ce domaine\dots
|
||||
du développement dans ce domaine\dots
|
||||
|
||||
\subsubsection{Vers PNM}\index{PNM}
|
||||
|
||||
|
@ -701,12 +780,14 @@ Les autres bits ne sont pas utilisés et doivent être à zéro.
|
|||
|
||||
\subsubsection{Vers PNG}\index{PNG}
|
||||
|
||||
Actuellement, on peut enregistrer uniquement en mode RGB,
|
||||
8 bits par composante,
|
||||
Actuellement, on ne peut enregistrer qu'en mode RGB uniquement,
|
||||
avec 8 bits par composante,
|
||||
mais on a quand même une bonne compression, ça compense.
|
||||
|
||||
J'utilise \textsl{libpnglite} avec qui j'ai un peu de mal à suivre.
|
||||
Mais je me soigne. Le mode 16 bits va bientôt arriver.
|
||||
On peut aussi songer à l'export de metadatas.
|
||||
On peut aussi songer à l'export des metadonnées, pour celles qui
|
||||
sont compatibles avec le standard PNG.
|
||||
|
||||
\begin{lstlisting}
|
||||
int fimg_save_as_png(FloatImg *src, char *outname, int flags);
|
||||
|
@ -714,8 +795,9 @@ int fimg_save_as_png(FloatImg *src, char *outname, int flags);
|
|||
|
||||
Tous les flags doivent être à zéro. Sinon, ça foire parfois.
|
||||
Et en fait (mars 2021) je ne suis pas très content de
|
||||
\texttt{pnglite}, donc un de ces jours\footnote{Rendez-nous notre
|
||||
Mixou !}, je prendrais cinq jours pour régler le souci.
|
||||
\texttt{pnglite}, donc un de ces jours, je prendrais
|
||||
\sout{cinq} quelques jours pour
|
||||
régler ce souci en passant à la bibliothèque canonique.
|
||||
|
||||
\subsubsection{Vers TIFF}\index{TIFF}
|
||||
|
||||
|
@ -728,7 +810,7 @@ int fimg_write_as_tiff(FloatImg *src, char *outname, int flags);
|
|||
\end{lstlisting}
|
||||
|
||||
Tous les flags doivent être à zéro. Pour le moment.
|
||||
|
||||
Un premier jet pas forcément parfait.
|
||||
|
||||
\subsubsection{Vers FITS}\index{FITS}
|
||||
|
||||
|
@ -748,6 +830,7 @@ sais pas encore comment régler ce petit détail.
|
|||
|
||||
Tous les flags doivent être à zéro.
|
||||
|
||||
% =============================================================
|
||||
|
||||
\subsection{Utilitaires}
|
||||
|
||||
|
@ -760,17 +843,19 @@ fichier de configuration.
|
|||
int parse_WxH(char *str, int *pw, int *ph)
|
||||
int parse_double(char *str, double *dptr)
|
||||
\end{lstlisting}
|
||||
|
||||
% XXX rjouter quelques explication, please !
|
||||
|
||||
La fonction \texttt{int format\_from\_extension(char *fname)} examine un
|
||||
nom de fichier tel que \texttt{lena.xxx}, et retourne, si la partie
|
||||
\texttt{xxx} est connue, un éventuel nombre positif, dont les valeurs sont
|
||||
déclarées dans floatimg.h
|
||||
le valeureux.
|
||||
Les extensions actuellement connues sont : fimg, png, pnm, fits et tiff.
|
||||
Les extensions actuellement connues sont :
|
||||
fimg, png, pnm, pgm, fits et tiff. Le bmp est plus ou moins prévu\dots
|
||||
|
||||
To be continued\index{XXX}\dots
|
||||
|
||||
% =============================================================
|
||||
|
||||
\subsection{Effets}\index{sfx}
|
||||
|
||||
|
@ -794,10 +879,9 @@ J'ai commencé à étudier ces objets étranges quand j'ai commencé
|
|||
à travailler sur l'interpolator\index{interpolator} à l'automne 2020.
|
||||
Hélas, j'ai vite réalisé que c'était assez délicat.
|
||||
Pour ce genre de \textsl{usecase}, le numérique est pitoyable si on
|
||||
le compare au \textsc{Betamax}\index{Betamax}.
|
||||
|
||||
% ----------------------------------
|
||||
le compare au (hélas défunt) \textsc{Betamax}\index{Betamax}.
|
||||
|
||||
% =============================================================
|
||||
|
||||
\subsection{Filtrages}\index{filtrage}
|
||||
|
||||
|
@ -838,7 +922,8 @@ int fimg_filter_3x3(FloatImg *src, FloatImg *dst, FimgFilter3x3 *filtr)
|
|||
\end{lstlisting}
|
||||
|
||||
Comme dans la plupart des cas, la gestion des valeurs négatives
|
||||
de pixel est laissé au hasard. Quoique, il doit bien exister
|
||||
de pixel est laissé au hasard, qui fait souvent du portnawak.
|
||||
Quoique, il doit bien exister
|
||||
quelques solutions de contournement : clamping ou shift ?
|
||||
|
||||
\textsl{To be continued\index{XXX}\dots}
|
||||
|
@ -890,7 +975,7 @@ En particulier tout le reste du code qui suppose qu'un pixel
|
|||
ne peut \textbf{pas} être négatif va peut-être exploser de rire.
|
||||
Vous pouvez aussi remarquer qu'il n'y a pas de controle
|
||||
de cohérence sur les dimensions des deux images, malgré l'existence
|
||||
de fonctions prévues à cet effet\dots
|
||||
de fonctions prévues à cet effet, mais il fallait rester simple\dots
|
||||
|
||||
|
||||
% ===================================================================
|
||||
|
@ -900,7 +985,8 @@ de fonctions prévues à cet effet\dots
|
|||
in-fine sur des objets que l'on peut considérer comme « physiques »,
|
||||
il est important de passer à une utilisation
|
||||
normale\footnote{Il y a une vie en dehors de git.} et construire
|
||||
des trucs qui mettent en action le code primitif.
|
||||
des trucs qui mettent en action le code primitif pour partir
|
||||
sur des bases saines.
|
||||
|
||||
Ces machins ont en commun quelques options bien pratiques~:
|
||||
\texttt{-h} pour avoir un résumé des options disponibles,
|
||||
|
@ -931,7 +1017,7 @@ deux nombres séparés ou la notation \texttt{WIDTHxHEIGHT}.
|
|||
|
||||
La plupart des types d'image générée prennent un paramètre flottant qui
|
||||
devra être donné avec l'option \texttt{-k F.F} avec une valeur par défaut
|
||||
à $1.0$, ce qui n'est pas toujours une bonne valeur.
|
||||
à $1.0$, ce qui n'est pas toujours une bonne valeur, ymmv\index{ymmv}.
|
||||
|
||||
\begin{description} \index{XXX}
|
||||
\item [black/gray/grey:] efface avec 0.0 (black) ou avec la valeur
|
||||
|
@ -952,7 +1038,11 @@ error in 'fimg_create_from_png' : read png -> -1 File error
|
|||
png2fimg : err -1, abort.
|
||||
\end{verbatim}
|
||||
|
||||
Il faut peut-être envisager le passage à \texttt{libpng}\index{libpng}.
|
||||
Il faut peut-être envisager le passage à \texttt{libpng}\index{libpng},
|
||||
la bibliothèque actuellement utilisée (\texttt{pnglite}) ayant tendance
|
||||
à borker en lecture sur certains fichiers pourtant corrects.
|
||||
|
||||
% ---------------------
|
||||
|
||||
\subsection{fimgstats}\index{fimgstats}\label{fimgstats}
|
||||
|
||||
|
@ -1002,7 +1092,9 @@ sera lisible avec le sélecteur \texttt{-L}.
|
|||
|
||||
Et pour les aventureux, la commande \texttt{xper} (abréviation
|
||||
de \textsl{expérimental}) permet de tester la plus récente tentative
|
||||
de friture du moment.
|
||||
de friture du moment. D'autre part un set bien plus complet d'effets
|
||||
àlc est disponible dans les logiciels de flou temporel, décrits
|
||||
plus loin dans ce document.
|
||||
|
||||
% ---------------------
|
||||
|
||||
|
@ -1036,6 +1128,9 @@ La véracité mathématique n'est pas garantie. Et n'oubliez pas que
|
|||
les valeurs négatives peuvent être la cause de \textsl{glitches}
|
||||
de qualitay.
|
||||
|
||||
La liste des opérations est susceptible d'être agrémenté de quelques
|
||||
possibilités bien féroces\footnote{Stay tuned, flim at 11.}.
|
||||
|
||||
% -------------------------
|
||||
|
||||
\subsection{fimg2png, fimg2pnm, fimg2tiff, fimg2fits}
|
||||
|
@ -1103,12 +1198,13 @@ tth@fubar:~/Devel/FloatImg/doc$ fimg2text -s 1 quux.fimg
|
|||
tth@fubar:~/Devel/FloatImg/doc$
|
||||
\end{verbatim}
|
||||
|
||||
Et maintenant, vous voulez un gros exemple ?
|
||||
Et maintenant, vous voulez un gros exemple ? Bah, ça doit demander
|
||||
l'utilisation de Povray\index{Povray}.
|
||||
|
||||
|
||||
% -------------------------
|
||||
|
||||
|
||||
% beaucoup trop de maths approximative dans ce passage.
|
||||
|
||||
\subsection{fimg2gray}\index{fimg2gray}\label{fimg2gray}
|
||||
|
||||
|
@ -1146,7 +1242,8 @@ cumulator options :
|
|||
\end{verbatim}
|
||||
|
||||
Le nom par défaut du fichier résultant est \texttt{out.fimg}.
|
||||
L'exportation « multiformat » est pour bientôt.
|
||||
L'exportation « multiformat » est enfin fonctionnelle, dans la
|
||||
mesure des formats connus.
|
||||
|
||||
% ===================================================================
|
||||
\section{Debug}\index{Debug}
|
||||
|
@ -1202,7 +1299,7 @@ if (foo) {
|
|||
\end{verbatim}
|
||||
|
||||
À condition d'avoir bien réglé votre ulimit pour la génération d'un coredump,
|
||||
vous aurez sous la main un fichier \textsc{core} qui vous permettra
|
||||
vous aurez sous la main un fichier \texttt{core} qui vous permettra
|
||||
de, par exemple, remonter la pile d'appel avec la commande \texttt{back} de
|
||||
gdb. Mais pour le moment, juste une infime partie du code est instrumentée
|
||||
avec ce dispositif.
|
||||
|
@ -1224,7 +1321,7 @@ Il reste plein de choses à faire pour que ce soit vraiment utilisable,
|
|||
surtout dans un contexte artistique à grande porosité.
|
||||
C'est par ces frottements de techniques ayant du sens que les
|
||||
choses seront acquises, pour le pire, le meilleur et la
|
||||
futilité du monde futur..
|
||||
techno-futilité du monde futur..
|
||||
|
||||
\begin{itemize}
|
||||
\item Import/export au format \textsc{tiff}\index{TIFF} à continuer.
|
||||
|
@ -1234,7 +1331,7 @@ futilité du monde futur..
|
|||
\item Formaliser les codes d'erreur. \textbf{Urgent}.
|
||||
\item Faire une passe complète de Valgrind\index{valgrind}.
|
||||
\item Intégrer la fonderie, l'interpolator et le singlepass.
|
||||
\item Vérifier le gestion des images mono-canal.
|
||||
\item Vérifier le gestion des images mono-canal et de la transparence.
|
||||
\end{itemize}
|
||||
|
||||
% ===================================================================
|
||||
|
@ -1248,7 +1345,7 @@ jamais négliger le traitement des éventuelles erreurs.
|
|||
Nous savons générer une image contenant des pixels aux valeurs
|
||||
probablement aléatoires, avec la commande \texttt{mkfimg},
|
||||
qui utilise le \texttt{drand48}\index{drand48} de \textsc{posix}\index{POSIX}.
|
||||
Maintenant, posons-nous une question de statisticien : ue se passe-t-il si
|
||||
Maintenant, posons-nous une question de statisticien : que se passe-t-il si
|
||||
nous faisons la somme de plusieurs centaines de ces images ?
|
||||
|
||||
\begin{lstlisting}
|
||||
|
@ -1315,7 +1412,7 @@ le premier pouvant salement brotcher une image, et le second capable de
|
|||
mélanger harmonieusement deux images, la balance est équilibrée.
|
||||
|
||||
Il s'agit donc d'un petit programme écrit en Bash\index{bash}, un langage
|
||||
dont la connaissance est, pour moi, indispendable à qui veut faire des
|
||||
dont la connaissance est, pour moi, indispensable à qui veut faire des
|
||||
images kitchies\index{kitchy}. Mais ne vous inquiétez pas, c'est en
|
||||
fait assez simple à comprendre. Et comprendre, c'est apprendre.
|
||||
|
||||
|
@ -1336,10 +1433,12 @@ OFFS=$(( NBRE / 4 ))
|
|||
\end{verbatim}
|
||||
|
||||
|
||||
Dans ce préliminaire logiciel, nous avons nommés le répertoire
|
||||
Dans ce préliminaire logiciel, nous avons nommé le répertoire
|
||||
\textsc{srcdir} contenant les captures d'image au format fimg, le répertoire
|
||||
\textsc{dstdir} dans lequel seront rangées les images calculées,
|
||||
et l'emplacement de deux fichiers de travail.
|
||||
et l'emplacement de deux fichiers de travail, placés dans ce qui
|
||||
peut être vu comme un \textsl{ramdisk}\index{ramdisk}\index{/dev/shm/}
|
||||
et qui accélère un peu les opérations.
|
||||
|
||||
Les quelques lignes suivantes, qui semble bien magiques, ne sont en fait
|
||||
que de la magie Unix\index{Unix}. Elles nous permettent d'avoir
|
||||
|
@ -1385,12 +1484,12 @@ $sin(idx/16)$ afin d'avoir une oscillation du coefficient entre
|
|||
\begin{verbatim}
|
||||
# do the hard floating computation
|
||||
#
|
||||
fimgfx -v cos010 ${imgB} ${FTMP}
|
||||
fimgops -k ${K} ${FTMP} ${imgA} mix ${FDST}
|
||||
fimgfx -v cos010 ${imgB} ${FTMP}
|
||||
fimgops -k ${K} ${FTMP} ${imgA} mix ${FDST}
|
||||
\end{verbatim}
|
||||
|
||||
Étape suivante, étape cruciale : le brassage d'une multitude de
|
||||
pixels flottants.
|
||||
pixels flottants.
|
||||
|
||||
Tout d'abord, nous faisons subir à l'image-echo
|
||||
(\texttt{imgB}, définie au début du script) un distorsion
|
||||
|
@ -1408,8 +1507,8 @@ done
|
|||
\end{verbatim}
|
||||
|
||||
Et en fin de boucle, nous convertissons le résultat de nos
|
||||
savants calculs au format PNG, et écrivons le fichier dans le répertoire
|
||||
de destination fixé au début.
|
||||
savants calculs au format PNG, et nous écrivons le fichier dans le
|
||||
répertoire de destination fixé au début.
|
||||
C'est le moment de passer la main à ffmpeg\index{ffmpeg}.
|
||||
|
||||
C'est juste une POC\index{POC}, et une implémentation bien plus
|
||||
|
@ -1417,6 +1516,9 @@ complète écrite en \textbf{C}\index{C} est déja en chantier,
|
|||
avec une complexité prévue à un niveau assez réjouissant.
|
||||
|
||||
% ===================================================================
|
||||
%
|
||||
% V4L2 is a trap.
|
||||
%
|
||||
\section{Video for Linux}\index{v4l2}
|
||||
|
||||
Donc, maintenant, nous savons un peu tripoter ces images flottantes.
|
||||
|
@ -1432,11 +1534,11 @@ v4l2.
|
|||
|
||||
\subsection{grabvidseq}\index{grabvidseq}\label{grabvidseq}
|
||||
|
||||
Un logiciel en évolution (trop ?) lente, qui permet déja la capture
|
||||
d'images en
|
||||
Un logiciel en évolution (vraiment trop) lente, qui permet déja
|
||||
la capture d'images en
|
||||
\textsl{longue pose} selon la méthode du cumul\index{cumul}, et
|
||||
devrait bientôt retrouver sa capacité à enregistrer des
|
||||
séquences d'images.
|
||||
séquences d'images. (\textsl{workaround}~: écrire une boucle en shell)
|
||||
|
||||
\begin{verbatim}
|
||||
tth@debian:~/Devel/FloatImg/v4l2$ ./grabvidseq -h
|
||||
|
@ -1472,8 +1574,8 @@ vaguement expliqué page \pageref{contraste}.
|
|||
|
||||
L'option \texttt{-X} me permet d'intégrer des \textit{fritures}
|
||||
expérimentales dans le binaire, et ne doit donc pas être
|
||||
utilisée dans des scripts si on a des visions à long (ou même)
|
||||
terme.
|
||||
utilisée dans des scripts si on a des visions à long
|
||||
(ou même moyen) terme.
|
||||
|
||||
\subsubsection{Upscaling}\index{upscaling}\label{upscaling}
|
||||
|
||||
|
@ -1507,19 +1609,27 @@ Options :
|
|||
Je me sens obligé d'avouer qu'il reste quelques points mystérieux dans
|
||||
l'\textsc{api} de \textsc{v4l2}, et donc, que ce que raconte
|
||||
ce logiciel doit être pris avec des pincettes. En particulier
|
||||
la liste des résolutions disponibles.
|
||||
des choses essentielles comme la liste des résolutions disponibles.
|
||||
|
||||
\subsection{nc-camcontrol}
|
||||
|
||||
Ajustement \textsl{Brightness Contrast Saturation Hue\dots}
|
||||
|
||||
Probablement pilotable au joystick\index{joystick}.
|
||||
|
||||
% ===================================================================
|
||||
\section{À l'extérieur}
|
||||
|
||||
Il existe une foultitude de logiciels (composants ou end-yuser) et
|
||||
il est souvent nécessaire de pouvoir communiquer facilement
|
||||
avec eux. Nous avons déja quelques possibilité d'exportation,
|
||||
mais passer par cette étape intermédiaire est parfois délicat
|
||||
à gérer dans un \textsl{pipedeprod} autrement bien huilé.
|
||||
|
||||
\subsection{ImageMagick}\index{ImageMagick}
|
||||
|
||||
Pour afficher notre format .fimg exotique avec \texttt{display}, vous
|
||||
Pour afficher notre format .fimg exotique avec \texttt{display}, un
|
||||
des éléments du package ImageMagick, vous
|
||||
devez mettre ce bout de XML\index{XML} dans le fichier
|
||||
\texttt{\$HOME/.magick/delegates.xml}~:
|
||||
|
||||
|
@ -1531,17 +1641,20 @@ devez mettre ce bout de XML\index{XML} dans le fichier
|
|||
\end{lstlisting}
|
||||
|
||||
C'est juste un hack rapide, qui ne fonctionne pas très bien avec
|
||||
d'autres commande de IM, comme identify, qui a tendance à
|
||||
d'autres commande de IM, comme \texttt{identify}\index{identify},
|
||||
qui a tendance à
|
||||
raconter un peu n'importe quoi, puisqu'elle se base sur le
|
||||
résultat de la conversion\dots
|
||||
Je compte donc sur le bouquin de \textsl{Brunus} pour avancer\dots
|
||||
résultat de la conversion.
|
||||
Je compte donc sur le bouquin de \textsl{Brunus}\index{Brunus}
|
||||
pour avancer\dots
|
||||
|
||||
\subsection{Gimp}\index{Gimp}
|
||||
|
||||
Mmmmm... Ça semble un peu plus compliqué.
|
||||
La documentation à ce sujet me semble ésotérique.
|
||||
D'un autre coté, il
|
||||
faut faire ça en \textbf{C}, ce qui ne peut pas être négatif.
|
||||
faut faire ça en \textbf{C}, ce qui ne peut pas être totalement négatif.
|
||||
Sauf pour les riiRistes.
|
||||
|
||||
\subsection{ffmpeg}\index{ffmpeg}
|
||||
|
||||
|
@ -1554,24 +1667,33 @@ ffmpeg -nostdin \
|
|||
-c:v libx264 \
|
||||
-pix_fmt yuv420p \
|
||||
-tune film \
|
||||
-metadata artist='---[ tTh ]---' \
|
||||
-metadata title='awesome video' \
|
||||
stereo.mp4
|
||||
\end{lstlisting}
|
||||
|
||||
Il existe environ un gazillion d'options pour encoder avec ffmpeg.
|
||||
Bon courage pour toutes les explorer, voire même juste les comprendre.
|
||||
|
||||
\subsection{Et encore ?}\index{krita}\index{geeqie}
|
||||
|
||||
Il y a d'autres logiciels pour lesquels écrire une fonction d'importation
|
||||
serait bien~: \textsl{Geeqie}, un visualiseur d'image fort pratique, ou
|
||||
\textsl{Krita} qui semble avoir les faveurs de
|
||||
dessinateurs de talent\footnote{Oui, David, c'est à toi que je pense.}.
|
||||
dessinateurs de talent.
|
||||
Ce qui nous conduit à une question importante~: quels sont les logiciels
|
||||
qui gèrent le chargement d'image par un système de
|
||||
\textsl{plugin}\index{plugin},
|
||||
parce que recompiler tout Gimp juste pour ça, c'est un peu overkill.
|
||||
|
||||
% -------------------------------------------------------------------
|
||||
% ===================================================================
|
||||
\section{Le flou temporel}
|
||||
|
||||
Et si nous jouions sur l'axe du temps ?
|
||||
\textit{\hspace{7em}Et si nous jouions sur l'axe du temps ?}
|
||||
|
||||
Nous avons plus ou moins la magie du cumul sur la prise de vue
|
||||
d'\textbf{image} en enchainant plusieurs capture d'image.
|
||||
Nous avons déja plus ou moins la magie du cumul sur la prise de vue
|
||||
d'\textbf{image} en enchainant plusieurs captures d'image accumulées
|
||||
en une seule.
|
||||
Maintenant, voyons ce que l'on peut faire à partir de plusieurs images.
|
||||
On peut d'abord penser faire une moyenne (ou la somme, en fait) de toutes
|
||||
ces images. Mais ce n'est qu'une façon déguisée de faire du cumul.
|
||||
|
@ -1579,29 +1701,133 @@ C'est à ce moment que nous changeons l'axe de vue du défi.
|
|||
|
||||
Par ailleurs, il m'a semblé pertinent d'inclure dans le projet une
|
||||
foultitude d'effets spéciaux.
|
||||
Qui manquent cruellement de possibilités de paramétrage.
|
||||
Mais peuvent être enchainés dans ce que j'appelle des
|
||||
\textsl{filter-chains}~: ces effets seront appliqués dans
|
||||
l'ordre aux image traitées soit en entrée soit en sortie.
|
||||
Je pense qu'un schéma\footnote{omg, apprendre un nouveau truc en
|
||||
\LaTeX, quel challenge étourdissant !} s'impose.
|
||||
|
||||
\subsection{\textsl{moving average}}
|
||||
|
||||
\texttt{./fonderie} : Basé sur la moyenne mobile, avec une structure de
|
||||
\subsection{\texttt{./fonderie} : \textsl{moving average}}
|
||||
|
||||
Basé sur la moyenne mobile, avec une structure de
|
||||
fifo\index{fifo} particulièrement mal conçue.
|
||||
Qui, en fait, n'est pas vraiment un fifo, mais plutôt un buffer
|
||||
circulaire. Pour chaque image source, elle est lue, passe dans la chaine de
|
||||
filtre d'entrée et est insérée dans ce buffer.
|
||||
Ensuite on calcule la moyenne des images contenues dans ce buffer.
|
||||
Et pour conclure, cette image moyennée passe au travers de la
|
||||
chaine de filtre de sortie, avant d'être enregistrée en PNG\index{PNG}
|
||||
dans le répertoire de destination.
|
||||
|
||||
\begin{verbatim}
|
||||
*** fonderie compiled Jan 23 2023, 10:43:56, pid 23366
|
||||
options:
|
||||
-E input:filter:chain
|
||||
-F output:filter:chain
|
||||
-I input glob pattern
|
||||
-L list available filters
|
||||
-O output directory
|
||||
-T fifo size
|
||||
-v increase verbosity
|
||||
\end{verbatim}
|
||||
|
||||
Euh, c'est quoi un '\textsl{input glob pattern}' ?
|
||||
|
||||
C'est ce qui vous permet
|
||||
de sélectionner un peu les images que vous voulez traiter, exactement
|
||||
comme vous pourriez le faire avec un shell classique.
|
||||
Par exemple pour choisir une image sur dix, le glob-pattern sera
|
||||
'\texttt{frames/????0.fimg}', et vous trouverez les explications détaillées
|
||||
dans le manuel~: \texttt{glob(7)}, et \texttt{glob(3)} pour la
|
||||
fonction utilisée.
|
||||
|
||||
% -------------------------------------------------------------------
|
||||
|
||||
\subsection{Interpolator}\index{interpolator}
|
||||
|
||||
Juste des calculs pas si simple que ça.
|
||||
Pour le moment, juste des calculs pas si simple que ça.
|
||||
Je pense qu'il faudra
|
||||
se lancer dans des calculs splinesques pour améliorer les choses dans
|
||||
la création des images intermédiaires.
|
||||
Voyons d'abord le principe actuel.
|
||||
|
||||
Nous avons une série de centaines, voire de milliers, de photos.
|
||||
En parcourant cette liste, nous allons en prélever une sur $N$,
|
||||
et entre celle-ci et la
|
||||
précédente prélevée, nous allons calculer par interpolation
|
||||
\textbf{linéaire} $N - 1$ images intermédiaires, et les
|
||||
intercaler entre nos deux sélections pour générer le
|
||||
flux de sortie,
|
||||
ce qui devrait nous donner un ralenti de bon aloi.
|
||||
|
||||
\begin{verbatim}
|
||||
usage:
|
||||
interpolator [options] <inglob> <outdir> <nbsteep>
|
||||
options:
|
||||
-E i:bla:k input filter chain
|
||||
-F name:j output filter chain
|
||||
-n make negative
|
||||
-S nn mysterious sort
|
||||
-L list available filters
|
||||
-v increase verbosity
|
||||
\end{verbatim}
|
||||
|
||||
L'option « mysterious sort » mérite bien son nom. Cette friture a
|
||||
été écrite il y a bien longtemps pour un projet précis, et les
|
||||
résultats ont été décevants. Je pense qu'il est toxique de
|
||||
l'utiliser pour le moment\footnote{Ou le repenser différent ?}.
|
||||
|
||||
% -------------------------------------------------------------------
|
||||
|
||||
|
||||
\subsection{Singlepass}
|
||||
|
||||
Ce programme \texttt{singlepass} prétend vous permettre de tester
|
||||
tous les filtres disponibles, dont on peut avoir la liste
|
||||
tous les filtres disponibles, et dont on peut avoir la liste
|
||||
avec l'option \texttt{-L}\footnote{liste hélas peu machinable.}
|
||||
|
||||
\subsection{Déviance}
|
||||
\begin{verbatim}
|
||||
usage:
|
||||
-F define:the:filter:chain
|
||||
-g input glob pattern
|
||||
-L list available filters
|
||||
-O /output/directory (default ./p8)
|
||||
-r N repetiiing factor
|
||||
-v spit more messages
|
||||
\end{verbatim}
|
||||
|
||||
Il n'y a pas de moyenne mobile, pas d'interpolation, mais un facteur de
|
||||
répétition qui permet de dupliquer $N$ fois une image dans le flux de
|
||||
sortie. Si vous globez \texttt{frames/????[02468]}, vous prenez
|
||||
une image sur deux, alors un facteur de répétition à $2$ conservera
|
||||
la 'vitesse' de la séquence, mais avec une petite saccade régulière
|
||||
de bon aloi \textit{:)}
|
||||
|
||||
% -------------------------------------------------------------------
|
||||
|
||||
\subsection{Déviance dans le flou ?}
|
||||
|
||||
Là, nous tombons dans de la \textsl{troiD}\index{3d} de haut niveau,
|
||||
avec plein de maths compliquées
|
||||
à l'intérieur.
|
||||
avec plein de maths compliquées à l'intérieur.
|
||||
Et surtout quelque chose qui n'est encore qu'une idée abstraite,
|
||||
mais il y aura du zbuffer dedans.
|
||||
mais il y aura du zbuffer\index{zbuffer} dedans.
|
||||
|
||||
% ===================================================================
|
||||
|
||||
\section{Expérimentations} \index{experimental}
|
||||
|
||||
Il m'arrive parfois d'avoir de vagues idées d'image, et donc de logiciel,
|
||||
qui tournent dans un coin de la tête.
|
||||
Parfois je songe à une fonction qui me
|
||||
serait bien utile, mais j'ai des doutes sur son
|
||||
\textsc{api}\footnote{Application Programming Interface}\index{api}
|
||||
qui soit à la fois simple et complète. Je fais donc des essais.
|
||||
Parfois j'imagine confusément un algorithme\index{algorithme} tordu
|
||||
et sans but précis. Je le \textit{runne} et je le \textit{re-runne}
|
||||
un gazillion de fois dans mon cerveau processique.
|
||||
Quel va être son facteur $O$ ? Je fais donc des essais.
|
||||
|
||||
% ===================================================================
|
||||
|
||||
|
@ -1618,6 +1844,7 @@ L'idée est donc de construire un appareil autonome, basé sur un Raspi et
|
|||
une webcam \textsc{usb}\index{USB}, pilotable par \textsc{lirc}\index{LIRC},
|
||||
alimenté par une (grosse) batterie et permettant d'aller
|
||||
faire des images au bord d'un lac ou dans la campagne de l'Ariège.
|
||||
Et, comme le dit la sagesse populaire : « fimg at 11 ».
|
||||
|
||||
% -------------------------------------------------------------------
|
||||
|
||||
|
|
20
essai.c
20
essai.c
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
@ -17,14 +18,17 @@ int verbosity;
|
|||
void fait_un_dessin(FloatImg *dessin)
|
||||
{
|
||||
|
||||
// fprintf(stderr, "je dessine dans %p\n", dessin);
|
||||
|
||||
fimg_draw_something(dessin);
|
||||
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
void help(int k)
|
||||
void help(void)
|
||||
{
|
||||
puts("Options :");
|
||||
puts("\t-d WxH\timage size");
|
||||
puts("\t-v\tincrease verbosity");
|
||||
exit(0);
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
@ -33,14 +37,14 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
FloatImg fimgA, fimgB;
|
||||
int foo, opt;
|
||||
int W = 800, H = 600;
|
||||
int W = 640, H = 480;
|
||||
double tb;
|
||||
|
||||
while ((opt = getopt(argc, argv, "d:hv")) != -1) {
|
||||
switch(opt) {
|
||||
case 'd': parse_WxH(optarg, &W, &H);
|
||||
break;
|
||||
case 'h': help(0); break;
|
||||
case 'h': help(); break;
|
||||
case 'v': verbosity++; break;
|
||||
}
|
||||
}
|
||||
|
@ -56,19 +60,19 @@ fimg_drand48(&fimgB, 100.0);
|
|||
foo = fimg_dump_to_file(&fimgB, "B.fimg", 0);
|
||||
|
||||
fimg_timer_set(0);
|
||||
#define NBP 500
|
||||
#define NBP 5
|
||||
for (foo=0; foo<NBP; foo++) {
|
||||
if (verbosity) {
|
||||
printf("%5d / %5d\n", foo, NBP);
|
||||
printf("%5d / %5d\n", foo, NBP);
|
||||
}
|
||||
fait_un_dessin(&fimgB);
|
||||
fimg_add_3(&fimgA, &fimgB, &fimgA);
|
||||
// fimg_mul(&fimgA, &fimgB, &fimgA);
|
||||
}
|
||||
tb = fimg_timer_get(0);
|
||||
fprintf(stderr, "%s = %f seconds\n", __func__, tb);
|
||||
foo = fimg_save_as_pnm(&fimgA, "drand48.pnm", 0);
|
||||
foo = fimg_dump_to_file(&fimgA, "drand48.fimg", 0);
|
||||
fprintf(stderr, "%s = %.2f seconds, %.2f s/p\n", __func__, tb, tb/(double)NBP);
|
||||
foo = fimg_save_as_pnm(&fimgA, "out.pnm", 0);
|
||||
foo = fimg_dump_to_file(&fimgA, "out.fimg", 0);
|
||||
|
||||
fimg_destroy(&fimgA);
|
||||
fimg_destroy(&fimgB);
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
|
||||
*.fimg
|
||||
*.o
|
||||
*.pnm
|
||||
*.data
|
||||
|
||||
assemblage
|
||||
extracteur
|
||||
fimg2obj
|
||||
mnt
|
||||
movepixels
|
||||
muxplanes
|
||||
tcache
|
|
@ -1,15 +1,40 @@
|
|||
|
||||
# experiments
|
||||
#
|
||||
# some ugly experiments, do not use in production
|
||||
#
|
||||
|
||||
|
||||
COPT = -Wall -fpic -g -DDEBUG_LEVEL=1 -lm
|
||||
COPT = -Wall -Wextra -fpic -g -DDEBUG_LEVEL=0 -lm
|
||||
DEPS = ../floatimg.h ../libfloatimg.a Makefile
|
||||
LIBS = -ltiff -lpnglite -lcfitsio
|
||||
LIBS = ../libfloatimg.a -ltiff -lpnglite -lcfitsio -lm
|
||||
|
||||
all: assemblage extracteur
|
||||
all: assemblage muxplanes movepixels mnt
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
assemblage: assemblage.c ${DEPS}
|
||||
gcc $(COPT) $< ../libfloatimg.a $(LIBS) -o $@
|
||||
gcc $(COPT) $< ../libfloatimg.a ${LIBS} -o $@
|
||||
|
||||
muxplanes: muxplanes.c ${DEPS}
|
||||
gcc $(COPT) $< ${LIBS} -o $@
|
||||
|
||||
movepixels: movepixels.c ${DEPS}
|
||||
gcc $(COPT) $< ../libfloatimg.a ${LIBS} -o $@
|
||||
|
||||
mnt: mnt.c ${DEPS}
|
||||
gcc $(COPT) $< ../libfloatimg.a ${LIBS} -o $@
|
||||
|
||||
fimg2obj: fimg2obj.c $(DEPS)
|
||||
gcc $(COPT) $< ../libfloatimg.a ${LIBS} -o $@
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# CACHE ENGINE
|
||||
|
||||
cachengn.o: cachengn.c cachengn.h Makefile
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
tcache.o: tcache.c cachengn.h Makefile
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
tcache: tcache.o cachengn.o Makefile
|
||||
gcc $(COPT) tcache.o cachengn.o $(LIBS) -o $@
|
||||
|
||||
extracteur: extracteur.c ${DEPS}
|
||||
gcc $(COPT) $< ../libfloatimg.a $(LIBS) -o $@
|
||||
|
|
|
@ -1,6 +1,29 @@
|
|||
# EXPÉRIMENTATION ÀLC
|
||||
# EXPÉRIMENTATIONS ÀLC
|
||||
|
||||
## ASSEMBLAGE
|
||||
Attention, tout ce qui se trouve dans ce répertoire ne sont que des
|
||||
essais. Certains aboutissent, et sont migrés vers `funcs/` ou
|
||||
`tools/`, d'autre échouent et restent trainer dans le coin en attente
|
||||
du retour de l'inspiration.
|
||||
|
||||
## EXTRACTEUR
|
||||
Le contenu de ce répertoire doit donc être considéré comme
|
||||
**volatile**. Si vous y trouvez votre bonheur, il serait sage
|
||||
d'en faire une copie personnelle...
|
||||
|
||||
## MNT
|
||||
|
||||
Modèles numériques de terrain. Rien ne marche. Plein de maths.
|
||||
Un [code](mnt.c) complexe.
|
||||
|
||||
## fimg2obj
|
||||
|
||||
Création d'un fichier .OBJ (de Wavefront) à partir d'une image
|
||||
flottante afin d'avoir des vues en 3d pertinentes, bien qu'assez
|
||||
futiles.
|
||||
|
||||
## système de cache
|
||||
|
||||
`new: Mon Jul 17 12:49:20 UTC 2023`
|
||||
|
||||
En cours : définition d'à peu-près tout ce qu'il reste à faire
|
||||
pour avoir quelque chose qui fonctionne.
|
||||
Plus d'information dans le [.h](cachengn.h).
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* the chache engine - code
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
#include "cachengn.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
static int nombre_slots = -1;
|
||||
static int index_slot = -1;
|
||||
static FimgCacheEntry *le_cache = NULL;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
||||
void cachengn_print_version(int k)
|
||||
{
|
||||
|
||||
printf("\t!!! this is the version ZERO !!!\n");
|
||||
|
||||
fprintf(stderr, "sizeof cache entry: %ld\n", sizeof(FimgCacheEntry));
|
||||
|
||||
if (k) fimg_print_version(0);
|
||||
}
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int init_empty_cache(int iw, int ih, int szc, int wtfparam)
|
||||
{
|
||||
int idx;
|
||||
|
||||
fprintf(stderr, ">>> %s ( %d %d %d %d )\n", __func__,
|
||||
iw, ih, szc, wtfparam);
|
||||
|
||||
/* MOLLYGUARD : don't init TWICE, please */
|
||||
if (NULL != le_cache) {
|
||||
fprintf(stderr, "%s: there is a cache at %p\n", __func__,
|
||||
le_cache);
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* allocate an prepare memory */
|
||||
if ( NULL==(le_cache=calloc(szc, sizeof(FimgCacheEntry))) ) {
|
||||
fprintf(stderr, "%s: no memory, sorry...\n", __func__);
|
||||
return -3;
|
||||
}
|
||||
fprintf(stderr, " slot array at %p\n", le_cache);
|
||||
for (idx=0; idx<szc; idx++) {
|
||||
le_cache[idx].flags = 0xF0;
|
||||
le_cache[idx].index = idx;
|
||||
}
|
||||
|
||||
/* update private cache metadata */
|
||||
nombre_slots = szc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
*
|
||||
*/
|
||||
FloatImg *give_me_thiz_picz(char *fname, int notused)
|
||||
{
|
||||
int idx, foo, freeslot;
|
||||
FloatImg img;
|
||||
char *nptr;
|
||||
|
||||
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused);
|
||||
|
||||
/* please add molly guard ! */
|
||||
|
||||
if (notused)
|
||||
fprintf(stderr, "in %s, notused was %d\n", __func__, notused);
|
||||
|
||||
/* is the floatimg already in the cahce ? */
|
||||
for (idx=0; idx<nombre_slots; idx++) {
|
||||
nptr = le_cache[idx].filename;
|
||||
if (NULL!=nptr && (! strcmp(fname, nptr))) {
|
||||
fprintf(stderr, "found '%s' at %d\n", nptr, idx);
|
||||
return le_cache[idx].image;
|
||||
}
|
||||
}
|
||||
|
||||
/* we not have this picture in ou cache, so we need a free
|
||||
slot for it */
|
||||
freeslot = -1;
|
||||
for (idx=0; idx<nombre_slots; idx++) {
|
||||
if (NULL==le_cache[idx].image) {
|
||||
freeslot = idx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "freeslot = %d\n", freeslot);
|
||||
|
||||
/* check if we can read this file */
|
||||
foo = access(fname, R_OK); /* XXX */
|
||||
if (foo) {
|
||||
perror(__FILE__ ": give_me_thiz_picz");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* try to load the requested file */
|
||||
foo = fimg_create_from_dump(fname, &img);
|
||||
if (foo) {
|
||||
fprintf(stderr, "oups on %s\n", fname);
|
||||
return NULL;
|
||||
}
|
||||
/* OK we have all the pixels in core memorey */
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/* ------------------------------------------------------------ */
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int liste_le_cache(unsigned int flags)
|
||||
{
|
||||
int idx;
|
||||
|
||||
fprintf(stderr, ">>> %s ( Ox%X )\n", __func__, flags);
|
||||
|
||||
/* please add molly guard here */
|
||||
|
||||
fprintf(stderr, "cache at %p : %d slots, idx = %d\n",
|
||||
le_cache, nombre_slots, index_slot);
|
||||
|
||||
for (idx=0; idx<nombre_slots; idx++) {
|
||||
fprintf(stderr, "%5d ", idx);
|
||||
fprintf(stderr, "0x%02x ", le_cache[idx].flags);
|
||||
fprintf(stderr, "%p ", le_cache[idx].image);
|
||||
fprintf(stderr, "%s\n", le_cache[idx].filename);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ------------------------------------------------------------ */
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* the chache engine - header
|
||||
*/
|
||||
|
||||
void cachengn_print_version(int k);
|
||||
|
||||
typedef struct {
|
||||
int flags;
|
||||
char *filename;
|
||||
FloatImg *image;
|
||||
int index;
|
||||
} FimgCacheEntry;
|
||||
|
||||
|
||||
/*
|
||||
* parameters:
|
||||
* - iw, ik : image size
|
||||
* - szc : number of slots
|
||||
* - nbre : WTF isthat?
|
||||
*/
|
||||
int init_empty_cache(int iw, int ih, int szc, int nbre);
|
||||
|
||||
|
||||
/* /!\ the floatimg returned must be view as readonly */
|
||||
FloatImg *give_me_thiz_picz(char *fname, int notused);
|
||||
|
||||
|
||||
/* utilities functions */
|
||||
int liste_le_cache(unsigned int flags);
|
|
@ -1,131 +0,0 @@
|
|||
/*
|
||||
* another ugly experiment
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
// #include "incrustator.h"
|
||||
|
||||
int verbosity;
|
||||
|
||||
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
|
||||
|
||||
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
|
||||
int essai_extraction(FloatImg *in, FloatImg *out, FimgArea51 *rect)
|
||||
{
|
||||
int foo;
|
||||
int xs, ys, xd, yd;
|
||||
int count;
|
||||
float rgb[3];
|
||||
|
||||
if (verbosity) {
|
||||
fimg_describe(in, "source");
|
||||
fimg_describe(out, "destination");
|
||||
print_rectangle(__func__, rect);
|
||||
}
|
||||
|
||||
count = 0;
|
||||
for (yd=0; yd<rect->h; yd++) {
|
||||
ys = yd + rect->y;
|
||||
if ((ys<0) || (ys>=in->height)) continue;
|
||||
for (xd=0; xd<rect->w; xd++) {
|
||||
xs = xd + rect->x;
|
||||
if ((xs<0) || (xs>=in->width)) continue;
|
||||
fimg_get_rgb(in, xs, ys, rgb);
|
||||
fimg_put_rgb(out, xd, yd, rgb);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
// fprintf(stderr, "%s: %d pix moved\n", __func__, count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
|
||||
void help(int k)
|
||||
{
|
||||
puts("Usage:\n\textracteur in.fimg w,h,x,y out.???");
|
||||
}
|
||||
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo, opt;
|
||||
FloatImg src, dst;
|
||||
FimgArea51 zone;
|
||||
char *infile = "foo.fimg";
|
||||
char *outfile = "out.fimg";
|
||||
|
||||
verbosity = 0;
|
||||
|
||||
#if 0
|
||||
for (foo=0; foo<argc; foo++) {
|
||||
fprintf(stderr, "%9d %s\n", foo, argv[foo]);
|
||||
}
|
||||
#endif
|
||||
|
||||
while ((opt = getopt(argc, argv, "hv")) != -1) {
|
||||
switch(opt) {
|
||||
case 'h': help(0), exit(0); break;
|
||||
case 'v': verbosity++; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
if (3 != argc-optind) {
|
||||
fprintf(stderr, "---- %s errcli c=%d %d ----\n", argv[0],
|
||||
argc, argc-optind);
|
||||
help(1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "*** %s %s %s\n", argv[0], __DATE__, __TIME__);
|
||||
fimg_print_version(1);
|
||||
}
|
||||
|
||||
infile = argv[optind]; outfile = argv[optind+2];
|
||||
fprintf(stderr, "%s %s -> %s\n", argv[0], infile, outfile);
|
||||
|
||||
foo = fimg_create_from_dump(infile, &src);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d loading image '%s'\n", __func__,
|
||||
foo, infile);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (4 != parse_rectangle( argv[optind+1], &zone, 0) ) {
|
||||
fprintf(stderr, "%s: error in parsing of '%s'\n",
|
||||
argv[0], argv[optind+1]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// zone.w = src.width / 2; zone.h = src.height / 2;
|
||||
// zone.x = src.width / 4 ; zone.y = src.height / 4;
|
||||
|
||||
if (verbosity) print_rectangle(argv[0], &zone);
|
||||
|
||||
foo = fimg_create(&dst, zone.w, zone.h, FIMG_TYPE_RGB);
|
||||
if (foo) {
|
||||
fprintf(stderr, "NO PICZ EPIC FAIL %d\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
foo = fimg_extractor(&src, &dst, &zone);
|
||||
if (foo) {
|
||||
fprintf(stderr, "EXTRACTOR EPIC FAIL %d\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
foo = fimg_export_picture(&dst, outfile, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "export '%s' -> err %d\n", outfile, foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
|
|
@ -0,0 +1,67 @@
|
|||
|
||||
/*
|
||||
* another ugly experiment
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
int verbosity;
|
||||
|
||||
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
|
||||
|
||||
int convert_fimg_to_obj(char *fimgfname, char *objfname, int mode)
|
||||
{
|
||||
FloatImg src;
|
||||
int foo, x, y;
|
||||
FILE *fp;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__,
|
||||
fimgfname, objfname, mode);
|
||||
#endif
|
||||
|
||||
if (mode) {
|
||||
fprintf(stderr, "in %s(), mode must be 0, was %d\n", __func__, mode);
|
||||
}
|
||||
|
||||
foo = fimg_create_from_dump(fimgfname, &src);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d loading %f\n", foo, fimgfname);
|
||||
return foo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo, opt;
|
||||
char *infile = "foo.fimg";
|
||||
|
||||
fprintf(stderr, "*** fimg2obj (%s %s)\n", __DATE__, __TIME__);
|
||||
|
||||
verbosity = 0;
|
||||
|
||||
#if 0
|
||||
for (foo=0; foo<argc; foo++) {
|
||||
fprintf(stderr, "%9d %s\n", foo, argv[foo]);
|
||||
}
|
||||
#endif
|
||||
|
||||
foo = convert_fimg_to_obj(infile, "foo.obj", 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "convertor give us %d\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
* Modeles Numeriques de Terrain -- UGLY CODE INSIDE !!
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
int verbosity;
|
||||
|
||||
/* ------------------------------------------------------------------- */
|
||||
/* for debug purpose */
|
||||
int printf_histo_gray(char *fname, int histo[], int nbre)
|
||||
{
|
||||
FILE *fp;
|
||||
int idx;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' %p %d )\n", __func__,
|
||||
fname, histo, nbre);
|
||||
#endif
|
||||
|
||||
if (NULL == (fp = fopen(fname, "w"))) {
|
||||
perror(fname);
|
||||
exit(1);
|
||||
}
|
||||
for (idx=0; idx<nbre; idx++) {
|
||||
fprintf(fp, "%6d %8d\n", idx, histo[idx]);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* ------------------------------------------------------------------- */
|
||||
/* for debug purpose */
|
||||
int calcul_histo_gray(FloatImg *img, char *fname, int nbslots, float *pmax)
|
||||
{
|
||||
int offset, nbpix, ival;
|
||||
float pixel, minp, maxp;
|
||||
int *counts;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p '%s' %d )\n", __func__,
|
||||
img, fname, nbslots);
|
||||
#endif
|
||||
|
||||
if (FIMG_TYPE_GRAY != img->type) {
|
||||
fprintf(stderr, "%s: image is not in greylevel\n", __func__);
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* allocate memory for histogram computation */
|
||||
counts = calloc(nbslots, sizeof(int));
|
||||
if (NULL == counts) {
|
||||
fprintf(stderr, "malloc fail in %s\n", __func__);
|
||||
abort();
|
||||
}
|
||||
|
||||
nbpix = img->width * img->height;
|
||||
minp = 1e10, maxp = -1e10;
|
||||
|
||||
for (offset=0; offset<nbpix; offset++) {
|
||||
pixel = img->R[offset];
|
||||
if (pixel < minp) minp = pixel;
|
||||
if (pixel > maxp) maxp = pixel;
|
||||
}
|
||||
fprintf(stderr, " values = %g < %g\n", minp, maxp);
|
||||
|
||||
*pmax = maxp; /* copy value for the caller */
|
||||
|
||||
/* calcul de l'histogramme avec scaling */
|
||||
for (offset=0; offset<nbpix; offset++) {
|
||||
pixel = img->R[offset];
|
||||
ival = (int)((pixel * (float)nbslots) / maxp);
|
||||
counts[ival]++;
|
||||
// fprintf(stderr, "%6d %10.6f %i\n", offset, pixel, ival);
|
||||
}
|
||||
|
||||
if (NULL != fname)
|
||||
{
|
||||
printf_histo_gray(fname, counts, nbslots);
|
||||
}
|
||||
|
||||
/* garbage collect stuff */
|
||||
free(counts);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ------------------------------------------------------------------- */
|
||||
/*
|
||||
* Second try - ahem?
|
||||
*/
|
||||
int brotche_mnt_style(FloatImg *src, FloatImg *dst)
|
||||
{
|
||||
FloatImg tmp;
|
||||
int x, y, foo;
|
||||
int offset;
|
||||
float z1, z2, z3, z4;
|
||||
float a, b, c;
|
||||
float pente, minp, maxp, seuil;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p )\n", __func__, src, dst);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* trying some preprocessor filters
|
||||
*/
|
||||
//foo = fimg_lissage_2x2(src);
|
||||
foo = fimg_lissage_3x3(src);
|
||||
if (foo) fprintf(stderr, " lissage -> %d\n", foo);
|
||||
foo = fimg_killborders(src);
|
||||
if (foo) fprintf(stderr, " killborder -> %d\n", foo);
|
||||
|
||||
#define W (src->width)
|
||||
#define DX 1.0
|
||||
#define DY 1.0
|
||||
|
||||
/* allocate a graylevel image for storing la 'pente' */
|
||||
memset(&tmp, 0, sizeof(FloatImg));
|
||||
foo = fimg_create(&tmp, src->width, src->height, FIMG_TYPE_GRAY);
|
||||
if (foo) {
|
||||
fprintf(stderr, "create tmp pic --> %d\n", foo);
|
||||
return foo;
|
||||
}
|
||||
/* calcul de la pente : a vérifier ! */
|
||||
for (y=0; y<(src->height-1); y++) {
|
||||
for (x=0; x<(src->width-1); x++) {
|
||||
offset = (y * W) + x;
|
||||
z1 = src->R[offset];
|
||||
z2 = src->R[offset+1];
|
||||
z3 = src->R[offset+W];
|
||||
z4 = src->R[offset+W+1];
|
||||
a = ( z1 + z2 + z3 + z4) / 4.0;
|
||||
b = (-z1 + z2 - z3 + z4) / 2.0 / DX;
|
||||
c = (-z1 - z2 + z3 + z4) / 2.0 / DY;
|
||||
pente = atanf(sqrt(b*b + c*c));
|
||||
tmp.R[offset] = pente;
|
||||
}
|
||||
}
|
||||
|
||||
foo = calcul_histo_gray(&tmp, "histogramme.data", 499, &maxp);
|
||||
if (foo) fprintf(stderr, "<<< calcul histo -> %d\n", foo);
|
||||
|
||||
|
||||
minp = 1e10;
|
||||
seuil = 0.700 * maxp;
|
||||
fprintf(stderr, " seuil = %f\n", seuil);
|
||||
|
||||
for (offset=0; offset<(src->width*src->height); offset++) {
|
||||
pente = tmp.R[offset];
|
||||
if (pente > seuil) {
|
||||
if (pente < minp) minp = pente;
|
||||
}
|
||||
if (pente > maxp) maxp = pente;
|
||||
}
|
||||
// fprintf(stderr, " minp = %f maxp = %f\n", minp, maxp);
|
||||
|
||||
/* recopie dans l'image destination avec translation hauteur */
|
||||
for (offset=0; offset<(src->width*src->height); offset++) {
|
||||
pente = tmp.R[offset] - minp;
|
||||
if (pente < 0.0) pente = 0.0;
|
||||
dst->R[offset] = pente;
|
||||
dst->G[offset] = pente;
|
||||
dst->B[offset] = pente;
|
||||
}
|
||||
|
||||
foo = fimg_killborders(dst);
|
||||
if (foo) fprintf(stderr, " killborder -> %d\n", foo);
|
||||
|
||||
/* clean the memory */
|
||||
fimg_destroy(&tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ------------------------------------------------------------------- */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FloatImg src, dst;
|
||||
char *infile, *outfile;
|
||||
int foo;
|
||||
|
||||
verbosity = 1; /* FIXME */
|
||||
|
||||
if (3 != argc) {
|
||||
fprintf(stderr, "'%s' need 2 args : infile & outfile\n", argv[0]);
|
||||
fimg_print_version(0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
infile = argv[1]; outfile = argv[2];
|
||||
|
||||
if (verbosity) fprintf(stderr,"*** MNT %s -> %s\n", infile, outfile);
|
||||
|
||||
foo = fimg_create_from_dump(infile, &src);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d loading image '%s'\n", foo, infile);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
foo = fimg_clone(&src, &dst, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d cloning image\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
fimg_clear(&dst);
|
||||
|
||||
foo = brotche_mnt_style(&src, &dst);
|
||||
if (foo) {
|
||||
fprintf(stderr, "something weird happen %d\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
foo = fimg_export_picture(&dst, outfile, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d exporting to %s\n", foo, outfile);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* clean the memory */
|
||||
fimg_destroy(&src);
|
||||
fimg_destroy(&dst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ------------------------------------------------------------------- */
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* MOVEPIXELS
|
||||
*
|
||||
* This is experimental, do not use in production !
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <floatimg.h>
|
||||
|
||||
int verbosity;
|
||||
|
||||
/* ------------------------------------------------------------------- */
|
||||
int displace(FloatImg *psrc, FloatImg *pshift, FloatImg *pdst, float k)
|
||||
{
|
||||
int xd, yd, xs, ys;
|
||||
float rgb[3], disp[3], maxv;
|
||||
float minmax[6];
|
||||
int foo, inside, outside;
|
||||
float dltr, dltg, dltb; /* delta des minmax */
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %p %g )\n", __func__,
|
||||
psrc, pshift, pdst, k);
|
||||
#endif
|
||||
|
||||
if (FIMG_TYPE_RGB != psrc->type) {
|
||||
fprintf(stderr, "%s: bad src type %d\n", __func__, psrc->type);
|
||||
return -7;
|
||||
}
|
||||
if (fimg_images_not_compatible(psrc, pshift)) {
|
||||
fprintf(stderr, "%s: bad shift image %d\n", __func__, pshift->type);
|
||||
return -8;
|
||||
}
|
||||
if (fimg_images_not_compatible(psrc, pdst)) {
|
||||
fprintf(stderr, "%s: bad dst image %d\n", __func__, pdst->type);
|
||||
return -8;
|
||||
}
|
||||
|
||||
foo = fimg_get_minmax_rgb(pshift, minmax);
|
||||
if (verbosity) {
|
||||
fimg_print_minmax(minmax, (char *)__func__);
|
||||
}
|
||||
dltr = minmax[1] - minmax[0];
|
||||
dltg = minmax[3] - minmax[2];
|
||||
dltb = minmax[5] - minmax[4];
|
||||
if (verbosity) fprintf(stderr, "delta shift %f %f %f\n", dltr, dltg, dltb);
|
||||
|
||||
maxv = fimg_get_maxvalue(psrc);
|
||||
inside = outside = 0;
|
||||
|
||||
/* hardcoded parameters. this is very dirty :) */
|
||||
|
||||
#define MULT (140.0)
|
||||
#define OFFS (70.0)
|
||||
|
||||
/* loop over all the pixels of the DESTINATION picture */
|
||||
for (yd=0; yd<pdst->height; yd++) {
|
||||
|
||||
for (xd=0; xd<pdst->width; xd++) {
|
||||
|
||||
fimg_get_rgb(pshift, xd, yd, disp);
|
||||
|
||||
xs = xd + ((disp[0]/dltr*MULT) - OFFS);
|
||||
ys = yd + ((disp[2]/dltb*MULT) - OFFS);
|
||||
|
||||
if ( xs<0 || xs>psrc->width ||
|
||||
ys<0 || ys>psrc->height ) {
|
||||
rgb[0] = maxv; /* fucking bug XXX */
|
||||
rgb[1] = rgb[2] = 0.0;
|
||||
outside++;
|
||||
}
|
||||
else {
|
||||
fimg_get_rgb(psrc, xs, ys, rgb);
|
||||
inside++;
|
||||
}
|
||||
|
||||
fimg_put_rgb(pdst, xd, yd, rgb);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// fprintf(stderr, "%s: inside %d outside %d\n", __func__, inside, outside);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ------------------------------------------------------------------- */
|
||||
|
||||
int move_the_pixels(char *infile, char *statfile, char *outfile, int k)
|
||||
{
|
||||
int foo;
|
||||
FloatImg src, shift, dst;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %s %s 0x%04x )\n", __func__,
|
||||
infile, outfile, k);
|
||||
#endif
|
||||
|
||||
/* 'infile' contains the shifting values */
|
||||
foo = fimg_create_from_dump(infile, &shift);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: error loading '%s'\n", __func__, infile);
|
||||
return foo;
|
||||
}
|
||||
|
||||
fimg_clone(&shift, &dst, 0);
|
||||
|
||||
foo = fimg_create_from_dump(statfile, &src);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: error loading 'cumul.fimg'\n", __func__);
|
||||
return foo;
|
||||
}
|
||||
|
||||
foo = displace(&src, &shift, &dst, 42.42);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d in disp map 0\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
foo = fimg_export_picture(&dst, outfile, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d saving result\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ------------------------------------------------------------------- */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo;
|
||||
char *srcfile, *dstfile;
|
||||
|
||||
if (3 != argc) {
|
||||
fprintf(stderr, "usage:\n\t%s src.fimg dst.fimg\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
srcfile = argv[1];
|
||||
dstfile = argv[2];
|
||||
verbosity = 0;
|
||||
|
||||
foo = move_the_pixels(srcfile, "cumul.fimg", dstfile, 3);
|
||||
|
||||
// fprintf(stderr, "move pixels %s -> %s = %d\n", srcfile, dstfile, foo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ------------------------------------------------------------------- */
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* another ugly experiment
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------- */
|
||||
|
||||
int triplane_muxer(FloatImg *sr, FloatImg *sg, FloatImg *sb,
|
||||
FloatImg *dst, int flages)
|
||||
{
|
||||
int foo;
|
||||
int sz;
|
||||
|
||||
if (FIMG_TYPE_RGB != dst->type) {
|
||||
fprintf(stderr, "%s: dst picz must be RGB, was %d\n",
|
||||
__func__, dst->type);
|
||||
return -99;
|
||||
}
|
||||
|
||||
if ( fimg_images_not_compatible(sr, sg) ||
|
||||
fimg_images_not_compatible(sr, sb) ||
|
||||
fimg_images_not_compatible(sr, dst) ) {
|
||||
fprintf(stderr, "%s: compatibility error\n", __func__);
|
||||
return -2;
|
||||
}
|
||||
|
||||
sz = sr->width * sr->height * sizeof(float);
|
||||
|
||||
memcpy(dst->R, sr->R, sz);
|
||||
memcpy(dst->G, sg->G, sz);
|
||||
memcpy(dst->B, sb->B, sz);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------- */
|
||||
int try_this_muxplane(char *fr, char *fg, char *fb, char *dst, int flags)
|
||||
{
|
||||
int foo;
|
||||
FloatImg imr, img, imb, dest;
|
||||
|
||||
fprintf(stderr, "muxing: %s %s %s -> %s\n", fr, fg, fb, dst);
|
||||
|
||||
foo = fimg_create_from_dump(fr, &imr);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d loading %s\n", __func__, foo, fr);
|
||||
return -1;
|
||||
}
|
||||
foo = fimg_create_from_dump(fg, &img);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d loading %s\n", __func__, foo, fr);
|
||||
return -1;
|
||||
}
|
||||
foo = fimg_create_from_dump(fb, &imb);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d loading %s\n", __func__, foo, fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fimg_clone(&imr, &dest, 0);
|
||||
|
||||
foo = triplane_muxer(&imr, &img, &imb, &dest, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
foo = fimg_export_picture(&dest, dst, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d exporting to %s\n", __func__, foo, dst);
|
||||
return foo;
|
||||
}
|
||||
|
||||
fimg_destroy(&imr); fimg_destroy(&img);
|
||||
fimg_destroy(&imb); fimg_destroy(&dest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------- */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo;
|
||||
|
||||
if (5 != argc) {
|
||||
fprintf(stderr, "ERROR: %s need four fimg files arguments\n",
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* and now, we have to decipher options on the
|
||||
* command line.
|
||||
*/
|
||||
|
||||
foo = try_this_muxplane(argv[1], argv[2], argv[3], argv[4], 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "oups %d\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------- */
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* tests du systeme de cache
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
#include "cachengn.h"
|
||||
|
||||
int verbosity;
|
||||
|
||||
#define IMGW 320
|
||||
#define IMGH 240
|
||||
|
||||
#define SIZE 5 // number of slots
|
||||
#define NBRI 1000
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo;
|
||||
FloatImg *picz;
|
||||
char *fname = "quux.fimg";
|
||||
|
||||
fprintf(stderr, "\nTest of the cache engin - %s %s\n",
|
||||
__DATE__, __TIME__);
|
||||
cachengn_print_version(1);
|
||||
|
||||
foo = init_empty_cache(IMGW, IMGH, SIZE, NBRI);
|
||||
fprintf(stderr, " init_empty_cache --> %d\n", foo);
|
||||
|
||||
foo = liste_le_cache((unsigned int)'U');
|
||||
fprintf(stderr, " liste le cache --> %d\n", foo);
|
||||
|
||||
picz = give_me_thiz_picz(fname, 0);
|
||||
if (NULL == picz) {
|
||||
fprintf(stderr, " error 'givemeapicz' on '%s'\n", fname);
|
||||
}
|
||||
|
||||
picz = give_me_thiz_picz(fname, 0);
|
||||
if (NULL == picz) {
|
||||
fprintf(stderr, " error 'givemeapicz' on '%s'\n", fname);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#!/bin/bash
|
||||
|
||||
GRABOPT=" -vv -d /dev/video0 -n 400 -p 0.5 -u "
|
||||
SPOOL=${HOME}/TMP
|
||||
|
||||
echo ; echo ; echo
|
||||
|
||||
for capture in red green blue
|
||||
do
|
||||
image=${SPOOL}/${capture}.fimg
|
||||
echo grabbing $image
|
||||
grabvidseq ${GRABOPT} -o $image
|
||||
echo
|
||||
done
|
||||
|
||||
./muxplanes "${SPOOL}/red.fimg" \
|
||||
"${SPOOL}/green.fimg" \
|
||||
"${SPOOL}/blue.fimg" \
|
||||
yo.fimg
|
||||
|
||||
echo $0 "got a" $?
|
||||
|
||||
fimgstats -v yo.fimg
|
||||
|
134
floatimg.h
134
floatimg.h
|
@ -1,37 +1,89 @@
|
|||
/*
|
||||
* floatimg.h
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
|
||||
* ugly code from tTh
|
||||
* http://la.buvette.org/photos/cumul
|
||||
* http://la.buvette.org/photos/cumul/
|
||||
* https://git.tetalab.org/tTh/FloatImg
|
||||
*/
|
||||
|
||||
#define FIMG_VERSION 145
|
||||
#define FIMG_VERSION (231)
|
||||
#define RELEASE_NAME ("noname")
|
||||
#define PATCH_LEVEL ("aaaa")
|
||||
|
||||
|
||||
/* XXX add a test for stdint.h / uint32_t XXX */
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
/*
|
||||
* in memory descriptor
|
||||
* new 11 mars 2022, and a lot of iterations
|
||||
* around the concept of metadata for my work.
|
||||
*/
|
||||
/*
|
||||
* we MUST look at packing and endianess problems NOW
|
||||
* and we can think about a fixed size of this datablock
|
||||
*/
|
||||
#define MAGIC_MDATA 0xfe007007
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
uint32_t padding;
|
||||
|
||||
struct timeval timestamp; // #include <stdlib.h>
|
||||
uint64_t cpid; // process id of the creator
|
||||
int32_t count;
|
||||
float fval;
|
||||
char idcam[32];
|
||||
int32_t origin; // enum ?
|
||||
uint32_t reserved[8];
|
||||
} FimgMetaData;
|
||||
|
||||
|
||||
/*
|
||||
* in memory descriptor of a floating image
|
||||
* ----------------------------------------
|
||||
*/
|
||||
#define MAGIC_FIMG 0x00F11F00
|
||||
typedef struct {
|
||||
unsigned long magic;
|
||||
uint32_t magic;
|
||||
int width;
|
||||
int height;
|
||||
int type;
|
||||
float fval;
|
||||
int count;
|
||||
float *R, *G, *B, *A;
|
||||
FimgMetaData mdatas; // added 20230912
|
||||
int reserved;
|
||||
} FloatImg;
|
||||
|
||||
/*
|
||||
* fimg file header
|
||||
* fimg file header (short version)
|
||||
*/
|
||||
typedef struct {
|
||||
char magic[8];
|
||||
int w, h, t;
|
||||
char magic[8]; // this is not an asciiz !
|
||||
int32_t w, h, t;
|
||||
/*
|
||||
* what about the packing ?
|
||||
*/
|
||||
} FimgFileHead;
|
||||
|
||||
|
||||
#define MAGIC_AREA51 0xA5EA0051
|
||||
typedef struct {
|
||||
unsigned long magic;
|
||||
uint32_t magic;
|
||||
int w, h;
|
||||
int x, y;
|
||||
int flags;
|
||||
|
@ -50,6 +102,8 @@ typedef struct {
|
|||
#define FILE_TYPE_FITS 6
|
||||
#define FILE_TYPE_BMP 7
|
||||
#define FILE_TYPE_EXR 8
|
||||
#define FILE_TYPE_DICOM 9
|
||||
#define FILE_TYPE_PGM 10
|
||||
|
||||
/* lib/contrast.c */
|
||||
#define CONTRAST_NONE 0
|
||||
|
@ -57,7 +111,7 @@ typedef struct {
|
|||
#define CONTRAST_POW2 2
|
||||
#define CONTRAST_COS01 3
|
||||
#define CONTRAST_COS010 4
|
||||
|
||||
#define CONTRAST_XPER 5 /* use with caution */
|
||||
/*
|
||||
* core module
|
||||
*/
|
||||
|
@ -96,21 +150,26 @@ int fimg_minimum(FloatImg *a, FloatImg *b, FloatImg *d);
|
|||
int fimg_maximum(FloatImg *a, FloatImg *b, FloatImg *d);
|
||||
|
||||
|
||||
/* ---------------------------------------------------- */
|
||||
/* funcs/filtrage.c */
|
||||
|
||||
typedef struct {
|
||||
float matrix[9];
|
||||
float mult;
|
||||
float offset;
|
||||
} FimgFilter3x3;
|
||||
|
||||
/*
|
||||
* this module contains bugs...
|
||||
*/
|
||||
int fimg_killborders(FloatImg *img);
|
||||
int fimg_lissage_2x2(FloatImg *img);
|
||||
int fimg_lissage_3x3(FloatImg *img);
|
||||
int fimg_show_filter(char *title, FimgFilter3x3 *filtr);
|
||||
int fimg_filter_3x3(FloatImg *s, FloatImg *d, FimgFilter3x3 *filtr);
|
||||
|
||||
|
||||
int fimg_contour_2x2(FloatImg *psrc, FloatImg *pdst, int reverse);
|
||||
|
||||
/* ---------------------------------------------------- */
|
||||
|
||||
/* module sfx0.c */
|
||||
int fimg_killcolors_a(FloatImg *fimg, float fval);
|
||||
int fimg_killcolors_b(FloatImg *fimg, float fval);
|
||||
|
@ -124,17 +183,33 @@ int fimg_highlight_color(FloatImg *src, FloatImg *dst,
|
|||
int fimg_binarize(FloatImg *pimg, int notused);
|
||||
int fimg_trinarize(FloatImg *pimg, int notused);
|
||||
|
||||
/* module sfx3.c */
|
||||
int fimg_make_rndfluffy_lines(FloatImg *src, FloatImg *dst, int rndt);
|
||||
int fimg_crump_hard(FloatImg *src, FloatImg *dst, float kval, int notused);
|
||||
|
||||
/* module sfx4.c */
|
||||
int fimg_sfx_triplemul(FloatImg *s, FloatImg *d, int notused);
|
||||
int fimg_split_level(FloatImg *src, FloatImg *dst, int notused);
|
||||
|
||||
/* funcs/rotate.c module */
|
||||
/* #coronamaison */
|
||||
int fimg_rotate_90(FloatImg *src, FloatImg *dst, int notused);
|
||||
|
||||
int fimg_killrgb_v(FloatImg *src, FloatImg *dst, int k);
|
||||
int fimg_decomp_rgbz_color(FloatImg *psrc, FloatImg *pdst, int k);
|
||||
int fimg_decomp_rgbz_gray(FloatImg *psrc, FloatImg *pdst, int k);
|
||||
|
||||
int fimg_save_plane_as_dicom(FloatImg *src, char *outname,
|
||||
char plane, int flags);
|
||||
|
||||
/* universal exporter XXX */
|
||||
int fimg_export_picture(FloatImg *pic, char *fname, int flags);
|
||||
|
||||
/* PNM files module */
|
||||
int fimg_save_as_pnm(FloatImg *head, char *fname, int flags);
|
||||
int fimg_save_as_pgm(FloatImg *head, char *fname, int flags);
|
||||
int fimg_load_from_pnm(char *fname, FloatImg *head, int notused);
|
||||
int fimg_save_plane_as_pgm(FloatImg *psrc, char *fname, char plane);
|
||||
|
||||
double fimg_timer_set(int whot);
|
||||
double fimg_timer_get(int whot);
|
||||
|
@ -151,16 +226,29 @@ int fimg_mix_rgb_gray(FloatImg *img, float mix);
|
|||
int fimg_shift_to_zero(FloatImg *s, FloatImg *d, float coefs[6]);
|
||||
int fimg_auto_shift_to_zero(FloatImg *s, FloatImg *d);
|
||||
|
||||
/* funcs/falsecolors.c */
|
||||
int fimg_falsecolors_0(FloatImg *src, FloatImg *dst, int k, float valf);
|
||||
|
||||
/* funcs/fmorpho.c */
|
||||
int fimg_filtre_morpho_0(FloatImg *sfimg, FloatImg *dfimg, int index);
|
||||
|
||||
|
||||
/* --> funcs/plasmas.c */
|
||||
int fimg_prototype_plasma(FloatImg *img, double time, int type);
|
||||
|
||||
/* --> funcs/pixelize.c
|
||||
voir fimg_pixelize_h_rnd() */
|
||||
int fimg_pixelize_h_0(FloatImg *psrc, FloatImg *pdst, int k);
|
||||
int fimg_pixelize_h_rnd(FloatImg *psrc, FloatImg *pdst, int largeur);
|
||||
|
||||
/* * * * experimental ! */
|
||||
int fimg_classif_trial(FloatImg *src, FloatImg*dst, float fval, int notused);
|
||||
int fimg_qsort_rgb_a(FloatImg *psrc, FloatImg *pdst, int notused);
|
||||
int fimg_qsort_rgb_b(FloatImg *psrc, FloatImg *pdst, int notused);
|
||||
|
||||
/* module funcs/??????.c */
|
||||
/* module funcs/equalize.c */
|
||||
int fimg_equalize_compute(FloatImg *src, void *vptr, float vmax);
|
||||
int fimg_equalize(FloatImg *src, double vmax);
|
||||
|
||||
int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k);
|
||||
int fimg_desaturate(FloatImg *src, FloatImg *dst, int notused);
|
||||
|
@ -181,13 +269,21 @@ int fimg_displacement_0(FloatImg *psrc, FloatImg *pdst, int flags);
|
|||
/* module funcs/rampes.c */
|
||||
int fimg_hdeg_a(FloatImg *img, double dcoef);
|
||||
int fimg_vdeg_a(FloatImg *img, double dcoef);
|
||||
int fimg_do_stripes(FloatImg *img, float fmax, int mode);
|
||||
|
||||
/* FIMG files module */
|
||||
/* FIMG native file module */
|
||||
int fimg_fileinfos(char *fname, int *datas);
|
||||
int fimg_dump_to_file(FloatImg *head, char *fname, int notused);
|
||||
int fimg_dumpmd_to_file(FloatImg *fi, char *nm, FimgMetaData *pmd, int nu);
|
||||
|
||||
int fimg_load_from_dump(char *fname, FloatImg *where);
|
||||
int fimg_create_from_dump(char *fname, FloatImg *head);
|
||||
|
||||
/* FIMG metadata module */
|
||||
int fimg_show_metadata(FimgMetaData *pmd, char *title, int notused);
|
||||
int fimg_default_metadata(FimgMetaData *pmd, int bla);
|
||||
int fimg_get_metadata_from_file(char *fname, FimgMetaData *pmd);
|
||||
|
||||
int fimg_save_R_as_fits(FloatImg *src, char *outname, int flags);
|
||||
int fimg_save_G_as_fits(FloatImg *src, char *outname, int flags);
|
||||
int fimg_save_B_as_fits(FloatImg *src, char *outname, int flags);
|
||||
|
@ -198,17 +294,22 @@ int fimg_save_as_exr(FloatImg *src, char *outname, int flags);
|
|||
|
||||
|
||||
/* mathematics operations */
|
||||
float fimg_get_plane_maxvalue(FloatImg *psrc, char plane);
|
||||
float fimg_get_maxvalue(FloatImg *head);
|
||||
int fimg_get_minmax_rgb(FloatImg *head, float mmvals[6]);
|
||||
int fimg_meanvalues(FloatImg *head, float means[4]);
|
||||
int fimg_to_gray(FloatImg *head);
|
||||
int fimg_add_cste(FloatImg *fi, float value);
|
||||
int fimg_mul_cste(FloatImg *fi, float value);
|
||||
int fimg_div_cste(FloatImg *fi, float value);
|
||||
int fimg_ajust_from_grab(FloatImg *fi, double maxima, int notused);
|
||||
int fimg_absolute(FloatImg *fimg);
|
||||
void fimg_drand48(FloatImg *fi, float kmul);
|
||||
long fimg_count_negativ(FloatImg *fi);
|
||||
long fimg_clamp_negativ(FloatImg *fi);
|
||||
|
||||
int fimg_max_of_max(FloatImg *img, float maxes[3]);
|
||||
|
||||
/* various funcs modules */
|
||||
int fimg_load_from_png(char *filename, FloatImg *fimg);
|
||||
int fimg_create_from_png(char *filename, FloatImg *fimg);
|
||||
|
@ -218,17 +319,22 @@ int fimg_save_as_bmp(FloatImg *src, char *outname, int flags);
|
|||
|
||||
int fimg_test_pattern(FloatImg *fimg, int type, double dval);
|
||||
int fimg_draw_something(FloatImg *fimg);
|
||||
int fimg_mircol_1(FloatImg *dst, float mval);
|
||||
int fimg_multirandom(FloatImg *fimg, long nbpass);
|
||||
|
||||
/* file is 'funcs/utils.c' */
|
||||
void fimg_print_minmax(float minmax[6], char *titre);
|
||||
float *charplane2int(char plane, FloatImg *img);
|
||||
|
||||
int parse_WxH(char *str, int *pw, int *ph);
|
||||
int parse_double(char *str, double *dptr);
|
||||
int irand2(int offset, int modulo);
|
||||
int print_rectangle(char *str, FimgArea51 *rect);
|
||||
int parse_rectangle(char *str, FimgArea51 *r, int notused);
|
||||
int format_from_extension(char *fname);
|
||||
char * extension_from_format(int fmt);
|
||||
|
||||
int fimg_clear_rectangle(FloatImg *pimg, int rect[4]);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,16 +3,19 @@
|
|||
# Please, use the 'Gloabl.makefile' system !
|
||||
|
||||
|
||||
COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0
|
||||
COPT = -Wall -Wextra -fpic -g -no-pie -DDEBUG_LEVEL=0
|
||||
DEPS = ../floatimg.h Makefile
|
||||
|
||||
OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \
|
||||
fimg-libpnm.o rampes.o sfx0.o sfx1.o sfx2.o \
|
||||
fimg-libpnm.o rampes.o rectangle.o \
|
||||
sfx0.o sfx1.o sfx2.o sfx3.o sfx4.o \
|
||||
falsecolors.o fmorpho.o \
|
||||
geometry.o rotate.o fimg-openexr.o \
|
||||
equalize.o fimg-fits.o saturation.o histogram.o \
|
||||
fimg-dicom.o \
|
||||
hsv.o classif.o contour2x2.o qsortrgb.o exporter.o \
|
||||
displacement.o dithering.o plasmas.o incrustator.o \
|
||||
recurse.o
|
||||
killrgb.o recurse.o pixelize.o decomprgb.o
|
||||
|
||||
#---------------------------------------------------------------
|
||||
|
||||
|
@ -36,6 +39,18 @@ tests.o: tests.c tests.h $(DEPS)
|
|||
|
||||
# ###
|
||||
|
||||
rectangle.o: rectangle.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
decomprgb.o: decomprgb.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
pixelize.o: pixelize.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
killrgb.o: killrgb.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
recurse.o: recurse.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
|
@ -45,6 +60,9 @@ incrustator.o: incrustator.c $(DEPS)
|
|||
displacement.o: displacement.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
fmorpho.o: fmorpho.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
fimg-png.o: fimg-png.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
|
@ -57,6 +75,9 @@ fimg-tiff.o: fimg-tiff.c $(DEPS)
|
|||
fimg-openexr.o: fimg-openexr.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
fimg-dicom.o: fimg-dicom.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
fimg-fits.o: fimg-fits.c $(DEPS)
|
||||
gcc $(COPT) -I/usr/include/cfitsio/ -c $<
|
||||
|
||||
|
@ -99,6 +120,12 @@ sfx1.o: sfx1.c $(DEPS)
|
|||
sfx2.o: sfx2.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
sfx3.o: sfx3.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
sfx4.o: sfx4.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
contour2x2.o: contour2x2.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
|
@ -114,6 +141,9 @@ qsortrgb.o: qsortrgb.c $(DEPS)
|
|||
exporter.o: exporter.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
falsecolors.o: falsecolors.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
|
||||
hsv.o: hsv.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
|
|
@ -4,13 +4,23 @@ Plein de fonctions qu'il serait bon de documenter :)
|
|||
|
||||
## PNG
|
||||
|
||||
__Attention__ : la bibliothèque `pnglite`actuellement utiilsée pour lire les
|
||||
fichiers PNG n'accepte que **certains** types de fichiers.
|
||||
__Attention__ : la bibliothèque `pnglite`actuellement utilisée pour lire
|
||||
les fichiers PNG n'accepte que **certains** types de fichiers.
|
||||
Et en particulier, elle brotche sur ceux produits par ImageMagick !
|
||||
|
||||
## FITS
|
||||
|
||||
Un Format de fichier utilisé en astronomie.
|
||||
|
||||
https://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/node1.html
|
||||
|
||||
## DICOM
|
||||
|
||||
https://en.wikipedia.org/wiki/DICOM et ça semble bien compliqué :(
|
||||
|
||||
## Contours
|
||||
|
||||
Détecter des contours est une activité respectable.
|
||||
Détecter des contours est une activité respectable. Mais difficile.
|
||||
|
||||
## Exporter
|
||||
|
||||
|
@ -21,6 +31,10 @@ une image en fonction de l'extension du nom de fichier.
|
|||
|
||||
Effets spéciaux divers.
|
||||
|
||||
La fonction `fimg_pixelize_h_rnd` est issue d'une idée qui m'est venue
|
||||
dans la roulotte de TerreBlanque. Elle a besoin de recherches sur la
|
||||
dynamique temporelle, et d'une FSM à trois états.
|
||||
|
||||
## Dithering
|
||||
|
||||
Work in progress...
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
@ -14,7 +15,7 @@ extern int verbosity;
|
|||
/* --------------------------------------------------------------------- */
|
||||
/* nouveau 2 octobre 2020, juste avant sonoptic de la pluie craignos */
|
||||
|
||||
int fimg_classif_trial(FloatImg *psrc, FloatImg *pdst, float fval, int notused)
|
||||
int fimg_classif_trial(FloatImg *psrc, FloatImg *pdst, float fval, int flags)
|
||||
{
|
||||
float minmax[6], delta[3], baryc[3];
|
||||
float range, dist, rgb[3], dr, dg, db;
|
||||
|
@ -25,6 +26,8 @@ fprintf(stderr, ">>> %s ( %p %p %f %d )\n", __func__,
|
|||
psrc, pdst, fval, notused);
|
||||
#endif
|
||||
|
||||
if (flags) { fprintf(stderr, "flags: 0x%04x in %s\n", flags, __func__); }
|
||||
|
||||
if (FIMG_TYPE_RGB != psrc->type) {
|
||||
fprintf(stderr, "%s: bad src type %d\n", __func__, psrc->type);
|
||||
return -7;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
|
|
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
* DECOMPOSITION RGB
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* == ---------------------------------------------------- == */
|
||||
|
||||
/* some dirty macros */
|
||||
|
||||
#define pixidx(fi,x,y) (((y)*fi->width)+(x))
|
||||
|
||||
#define getRpix(fi,x,y) (fi->R[ pixidx(fi,(x),(y)) ])
|
||||
#define getGpix(fi,x,y) (fi->G[ pixidx(fi,(x),(y)) ])
|
||||
#define getBpix(fi,x,y) (fi->B[ pixidx(fi,(x),(y)) ])
|
||||
|
||||
/* A lot of strange and usefull parenthesis */
|
||||
|
||||
/* == ---------------------------------------------------- == */
|
||||
#if DEBUG_LEVEL
|
||||
static float compute_z_value(float r, float g, float b)
|
||||
{
|
||||
double dval;
|
||||
|
||||
return 42.0;
|
||||
}
|
||||
#endif
|
||||
/* == ---------------------------------------------------- == */
|
||||
|
||||
int fimg_decomp_rgbz_color(FloatImg *psrc, FloatImg *pdst, int k)
|
||||
{
|
||||
int x, y, x2, y2;
|
||||
int w2, h2;
|
||||
float cumul, vgray;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
|
||||
psrc, pdst, k);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* XXX useless message ?
|
||||
*/
|
||||
if (k) { fprintf(stderr, "k=%d in %s\n", k, __func__); }
|
||||
|
||||
fimg_clear(pdst);
|
||||
w2 = psrc->width/2; h2 = psrc->height/2;
|
||||
|
||||
for (y=0; y<h2; y++)
|
||||
{
|
||||
y2 = y * 2;
|
||||
for (x=0; x<w2; x++) {
|
||||
x2 = x * 2;
|
||||
|
||||
cumul = getRpix(psrc, x2, y2) +
|
||||
getRpix(psrc, x2, y2+1) +
|
||||
getRpix(psrc, x2+1, y2) +
|
||||
getRpix(psrc, x2+1, y2+1);
|
||||
cumul /= 4, vgray = cumul;
|
||||
pdst->R[pixidx(pdst,x,y)] = cumul;
|
||||
pdst->R[pixidx(pdst,x+w2,y+h2)] = cumul;
|
||||
|
||||
cumul = getGpix(psrc, x2, y2) +
|
||||
getGpix(psrc, x2, y2+1) +
|
||||
getGpix(psrc, x2+1, y2) +
|
||||
getGpix(psrc, x2+1, y2+1);
|
||||
cumul /= 4, vgray += cumul;
|
||||
pdst->G[pixidx(pdst,x+w2,y)] = cumul;
|
||||
pdst->G[pixidx(pdst,x+w2,y+h2)] = cumul;
|
||||
|
||||
cumul = getBpix(psrc, x2, y2) +
|
||||
getBpix(psrc, x2, y2+1) +
|
||||
getBpix(psrc, x2+1, y2) +
|
||||
getBpix(psrc, x2+1, y2+1);
|
||||
cumul /= 4, vgray += cumul;
|
||||
pdst->B[pixidx(pdst,x,y+h2)] = cumul;
|
||||
pdst->B[pixidx(pdst,x+w2,y+h2)] = cumul;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* == ---------------------------------------------------- == */
|
||||
|
||||
/* PUTAIN LE COPIER/COLLÉ DE BATARD !!! */
|
||||
|
||||
int fimg_decomp_rgbz_gray(FloatImg *psrc, FloatImg *pdst, int k)
|
||||
{
|
||||
int x, y, x2, y2;
|
||||
int w2, h2, idx;
|
||||
float cumul, vgray;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
|
||||
psrc, pdst, k);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* XXX useless message ?
|
||||
*/
|
||||
if (k) { fprintf(stderr, "k=%d in %s\n", k, __func__); }
|
||||
|
||||
fimg_clear(pdst);
|
||||
w2 = psrc->width/2; h2 = psrc->height/2;
|
||||
|
||||
for (y=0; y<h2; y++)
|
||||
{
|
||||
y2 = y * 2;
|
||||
for (x=0; x<w2; x++) {
|
||||
x2 = x * 2;
|
||||
|
||||
cumul = getRpix(psrc, x2, y2) +
|
||||
getRpix(psrc, x2, y2+1) +
|
||||
getRpix(psrc, x2+1, y2) +
|
||||
getRpix(psrc, x2+1, y2+1);
|
||||
cumul /= 4, vgray = cumul;
|
||||
idx = pixidx(pdst,x,y);
|
||||
pdst->R[idx] = pdst->G[idx] = pdst->B[idx] = cumul;
|
||||
|
||||
cumul = getGpix(psrc, x2, y2) +
|
||||
getGpix(psrc, x2, y2+1) +
|
||||
getGpix(psrc, x2+1, y2) +
|
||||
getGpix(psrc, x2+1, y2+1);
|
||||
cumul /= 4, vgray += cumul;
|
||||
idx = pixidx(pdst,x+w2,y);
|
||||
pdst->R[idx] = pdst->G[idx] = pdst->B[idx] = cumul;
|
||||
|
||||
cumul = getBpix(psrc, x2, y2) +
|
||||
getBpix(psrc, x2, y2+1) +
|
||||
getBpix(psrc, x2+1, y2) +
|
||||
getBpix(psrc, x2+1, y2+1);
|
||||
cumul /= 4, vgray += cumul;
|
||||
idx = pixidx(pdst,x,y+h2);
|
||||
pdst->R[idx] = pdst->G[idx] = pdst->B[idx] = cumul;
|
||||
|
||||
idx = pixidx(pdst,x+w2,y+h2);
|
||||
pdst->R[idx] = pdst->G[idx] = \
|
||||
pdst->B[idx] = vgray / 3.0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* == ---------------------------------------------------- == */
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
|
@ -21,7 +22,6 @@ float minmax[6];
|
|||
float rgb[3];
|
||||
float dltr, dltg, dltb; /* delta des minmax */
|
||||
float dispx, dispy;
|
||||
|
||||
int dstx, dsty;
|
||||
int in, out;
|
||||
|
||||
|
@ -39,6 +39,10 @@ if (fimg_images_not_compatible(psrc, pdst)) {
|
|||
}
|
||||
|
||||
foo = fimg_get_minmax_rgb(psrc, minmax);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s : err %d on get minmax\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
if (verbosity) {
|
||||
fimg_print_minmax(minmax, (char *)__func__);
|
||||
}
|
||||
|
@ -59,7 +63,7 @@ for (y=0; y<psrc->height; y++) {
|
|||
fimg_get_rgb(psrc, x, y, rgb);
|
||||
|
||||
dispx = (float)x + (rgb[1]/dltg * 20.0);
|
||||
dispy = (float)y + (rgb[2]/dltb * 10.0);
|
||||
dispy = (float)y + (rgb[2]/dltb * 20.0);
|
||||
dstx = (int)roundf(dispx - 10.0);
|
||||
dsty = (int)roundf(dispy - 10.0);
|
||||
|
||||
|
@ -78,9 +82,7 @@ for (y=0; y<psrc->height; y++) {
|
|||
fimg_put_rgb(pdst, dstx, dsty, rgb);
|
||||
in++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (verbosity) fprintf(stderr, "%s -> in %d out %d\n", __func__, in, out);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
|
@ -16,11 +17,23 @@ int fimg_dither_0(FloatImg *psrc, FloatImg *pdst, int flags)
|
|||
{
|
||||
int x, y;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p 0x%04x )\n", __func__, psrc, pdst, flags);
|
||||
#endif
|
||||
|
||||
if (flags) { fprintf(stderr, "flags: 0x%04x in %s\n", flags, __func__); }
|
||||
|
||||
if (fimg_images_not_compatible(psrc, pdst)) {
|
||||
fprintf(stderr, "%s: shit happen\n", __func__);
|
||||
return -2;
|
||||
}
|
||||
|
||||
for (y=0; y<psrc->height; y++) {
|
||||
|
||||
for (x=0; x<psrc->width; x++)
|
||||
{
|
||||
|
||||
/* PLEASE DO SOMETHING HERE */
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,55 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* new func: Wed 14 Sep 2022 11:28:04 AM CEST
|
||||
*/
|
||||
int fimg_equalize(FloatImg *src, double vmax)
|
||||
{
|
||||
float mm[6];
|
||||
double maxi, coef;
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %f )\n", __func__, src, vmax);
|
||||
#endif
|
||||
|
||||
memset(mm, 0, 6*sizeof(float));
|
||||
foo = fimg_get_minmax_rgb(src, mm);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d get_minmax\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
maxi = mm[1] > mm[3] ? (double)mm[1] : (double)mm[3];
|
||||
maxi = maxi > mm[5] ? maxi : (double)mm[5];
|
||||
coef = vmax / maxi;
|
||||
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "maximums %.3f %.3f %.3f %.3f\n",
|
||||
mm[1], mm[3], mm[5], maxi);
|
||||
fprintf(stderr, "vmax %f maxi %f multcoef = %g\n", vmax, maxi, coef);
|
||||
}
|
||||
|
||||
foo = fimg_mul_cste(src, (float)coef);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d mul_cste\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
*
|
||||
* - wtf is this "void *vptr" thing ?
|
||||
*/
|
||||
int fimg_equalize_compute(FloatImg *src, void *vptr, float vmax)
|
||||
{
|
||||
float minmax[6];
|
||||
|
@ -30,6 +73,8 @@ if (foo) {
|
|||
return foo;
|
||||
}
|
||||
|
||||
fprintf(stderr, "vptr is %p vmax is %f\n", vptr, vmax);
|
||||
|
||||
dr = minmax[1] - minmax[0];
|
||||
dg = minmax[3] - minmax[2];
|
||||
db = minmax[5] - minmax[4];
|
||||
|
@ -43,7 +88,7 @@ if ( (minmax[0]<0.0) || (minmax[2]<0.0) || (minmax[4]<0.0) ) {
|
|||
return -4;
|
||||
}
|
||||
|
||||
// printf("deltas %12.4g %12.4g %12.4g\n", dr, dg, db);
|
||||
fprintf(stderr, "deltas %12.4g %12.4g %12.4g\n", dr, dg, db);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
@ -24,6 +25,8 @@ fprintf(stderr, ">>> %s ( %p '%s' 0x%X )\n", __func__,
|
|||
pic, fname, flags);
|
||||
#endif
|
||||
|
||||
if (flags) { fprintf(stderr, "flags: 0x%04x in %s\n", flags, __func__); }
|
||||
|
||||
filetype = format_from_extension(fname);
|
||||
if (verbosity > 1) {
|
||||
fprintf(stderr, "file %s have type %d\n", fname, filetype);
|
||||
|
@ -53,9 +56,15 @@ switch(filetype) {
|
|||
case FILE_TYPE_BMP:
|
||||
fprintf(stderr, "%s: file type BMP not implemented\n", __func__);
|
||||
foo = -666;
|
||||
break;
|
||||
case FILE_TYPE_EXR:
|
||||
fprintf(stderr, "%s: file type EXR experimental\n", __func__);
|
||||
foo = fimg_save_as_exr(pic, fname, 0);
|
||||
break;
|
||||
case FILE_TYPE_PGM:
|
||||
fprintf(stderr, "XXX %s EXPERIMENT!\n", __func__);
|
||||
foo = fimg_save_as_pgm(pic, fname, 0);
|
||||
break;
|
||||
default:
|
||||
foo = -1789;
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* FloatImg library from tTh - really ugly code inside
|
||||
*
|
||||
* F A L S E C O L O R S
|
||||
* or fake colors ?
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
#include <math.h>
|
||||
#include "../floatimg.h"
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* this is a global vars exported from main */
|
||||
extern int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* TRUCS A VOIR
|
||||
|
||||
f(x,y) = (((y & x) * (y - x)) % ((21 & x) * (y | 8))) ^ (~((x & 7) | (x % x)))
|
||||
|
||||
|
||||
*/
|
||||
/* -------------------------------------------------------------- */
|
||||
/* nouveau 18 mai 2022 */
|
||||
/* please explain the meaning of 'valf' parameter */
|
||||
int fimg_falsecolors_0(FloatImg *src, FloatImg *dst, int k, float valf)
|
||||
{
|
||||
int x, y, offset;
|
||||
float r, g, b, gray, maxv;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d %f )\n", __func__,
|
||||
src, dst, k, valf);
|
||||
#endif
|
||||
|
||||
if (k) {
|
||||
fprintf(stderr, "%s : %d %f\n", __func__, k, valf);
|
||||
}
|
||||
|
||||
/* check validity of parameters */
|
||||
if (FIMG_TYPE_RGB != dst->type) {
|
||||
fprintf(stderr, "in %s, picz at %p is not valid\n",
|
||||
__func__, dst);
|
||||
abort();
|
||||
/* BLAM! */
|
||||
}
|
||||
|
||||
|
||||
maxv = fimg_get_plane_maxvalue(src, 'r');
|
||||
fprintf(stderr, "%s: maxv of red plane = %f\n", __func__, maxv);
|
||||
|
||||
/* enter big loop */
|
||||
offset = 0;
|
||||
for (y=0; y<src->height; y++) {
|
||||
for (x=0; x<src->width; x++) {
|
||||
|
||||
gray = src->R[offset];
|
||||
|
||||
if (gray < maxv/2.0) {
|
||||
r = gray * 2.0;
|
||||
g = 0.0;
|
||||
}
|
||||
else {
|
||||
r = 0.0;
|
||||
g = gray * 2.0;
|
||||
}
|
||||
b = fmodf(gray*8.0, maxv);
|
||||
|
||||
dst->R[offset] = r;
|
||||
dst->G[offset] = g;
|
||||
dst->B[offset] = b;
|
||||
|
||||
/* and GOTO next pixel */
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
100
funcs/filtrage.c
100
funcs/filtrage.c
|
@ -1,11 +1,43 @@
|
|||
/*
|
||||
* Floating filters are all WIP !
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
int fimg_show_filter(char *title, FimgFilter3x3 *filtr)
|
||||
{
|
||||
float *M; /* alias of filter matrix */
|
||||
int idx;
|
||||
float sum, value;
|
||||
|
||||
if (title) fprintf(stderr, "--------- %s ---------\n", title);
|
||||
|
||||
M = filtr->matrix; /* aliasing here */
|
||||
|
||||
fprintf(stderr, "%8.3f %8.3f %8.3f\n", M[0], M[1], M[2]);
|
||||
fprintf(stderr, "%8.3f %8.3f %8.3f\n", M[3], M[4], M[5]);
|
||||
fprintf(stderr, "%8.3f %8.3f %8.3f\n", M[6], M[7], M[8]);
|
||||
|
||||
sum = 0.0;
|
||||
for (idx=0; idx<9; idx++) sum += M[idx];
|
||||
fprintf(stderr, " sum: %8.3f\n", sum);
|
||||
fprintf(stderr, " mult: %8.3f\n", filtr->mult);
|
||||
fprintf(stderr, " offset: %8.3f\n", filtr->offset);
|
||||
|
||||
value = (sum * filtr->mult) + filtr->offset;
|
||||
fprintf(stderr, " value: %8.3f\n", value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------------- */
|
||||
int fimg_filter_3x3(FloatImg *src, FloatImg *dst, FimgFilter3x3 *filtr)
|
||||
{
|
||||
|
@ -15,7 +47,7 @@ float *M; /* alias of filter matrix */
|
|||
double dval;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, src, dst, filtr);
|
||||
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, src, dst, filtr);
|
||||
#endif
|
||||
|
||||
if (src->type != FIMG_TYPE_RGB) {
|
||||
|
@ -27,19 +59,21 @@ if (dst->type != FIMG_TYPE_RGB) {
|
|||
return -99;
|
||||
}
|
||||
if (fimg_images_not_compatible(src, dst)) {
|
||||
fprintf(stderr, "%s: src & dst not comatibles\n", __func__);
|
||||
fprintf(stderr, "%s: src & dst not compatibles\n", __func__);
|
||||
return -98;
|
||||
}
|
||||
|
||||
if (verbosity > 1) {
|
||||
fimg_show_filter((char *)__func__, filtr);
|
||||
}
|
||||
|
||||
/* aliasing some vars for cleaner code */
|
||||
pr = src->R; pg = src->G; pb = src->B;
|
||||
w = src->width; h = src->height;
|
||||
M = filtr->matrix;
|
||||
|
||||
for (y=1; y < h-1; y++) {
|
||||
|
||||
for (x=1; x < w-1; x++) {
|
||||
|
||||
of = x + (y * w);
|
||||
|
||||
dval = M[0] * pr[of-(w+1)] +
|
||||
|
@ -106,9 +140,7 @@ if (img->type != FIMG_TYPE_RGB) {
|
|||
pr = img->R; pg = img->G; pb = img->B;
|
||||
|
||||
for (y=1; y < img->height-1; y++) {
|
||||
|
||||
for (x=1; x < img->width-1; x++) {
|
||||
|
||||
offset = x + (y * img->width);
|
||||
|
||||
cr = pr[offset] + pr[offset+1] +
|
||||
|
@ -123,7 +155,6 @@ for (y=1; y < img->height-1; y++) {
|
|||
pr[offset] = cr / 4.0;
|
||||
pg[offset] = cg / 4.0;
|
||||
pb[offset] = cb / 4.0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,7 +195,6 @@ for (idx=0; idx<h; idx++) {
|
|||
}
|
||||
|
||||
o = w * (h - 1);
|
||||
|
||||
for (idx=0; idx<w; idx++) {
|
||||
#if FAST
|
||||
img->R[idx] = 0.0;
|
||||
|
@ -186,6 +216,10 @@ int fimg_lissage_2x2(FloatImg *img)
|
|||
{
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p )\n", __func__, img);
|
||||
#endif
|
||||
|
||||
foo = fimg_lissage_2x2_a(img);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: fail %d\n", __func__, foo);
|
||||
|
@ -197,4 +231,54 @@ fimg_killborders(img);
|
|||
return foo;
|
||||
}
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------- */
|
||||
/*
|
||||
* XXX inplace filtering is a BAD IDEA
|
||||
*/
|
||||
int fimg_lissage_3x3(FloatImg *img)
|
||||
{
|
||||
int foo;
|
||||
FloatImg tmp;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p )\n", __func__, img);
|
||||
#endif
|
||||
|
||||
static FimgFilter3x3 lowpass = {
|
||||
{
|
||||
1.0, 2.0, 1.0,
|
||||
2.0, 4.0, 2.0,
|
||||
1.0, 2.0, 1.0,
|
||||
},
|
||||
16.0, 0.0
|
||||
};
|
||||
|
||||
foo = fimg_clone(img, &tmp, 1);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: clone -> %d\n", __func__, foo);
|
||||
abort();
|
||||
}
|
||||
foo = fimg_filter_3x3(&tmp, img, &lowpass);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: lowpass -> %d\n", __func__, foo);
|
||||
abort();
|
||||
}
|
||||
|
||||
foo = fimg_copy_data(&tmp, img);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: copy data -> %d\n", __func__, foo);
|
||||
abort();
|
||||
}
|
||||
|
||||
foo = fimg_destroy(&tmp);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: destroy -> %d\n", __func__, foo);
|
||||
abort();
|
||||
}
|
||||
|
||||
fimg_killborders(img);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
Digital Imaging and Communications in Medicine
|
||||
|
||||
nouveau Fri 26 Nov 2021 11:12:44 PM CET - allée de Dinan
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
extern int verbosity; /* must be declared around main() */
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int fimg_save_plane_as_dicom(FloatImg *src, char *outname,
|
||||
char plane, int flags)
|
||||
{
|
||||
float *planeptr;
|
||||
|
||||
fprintf(stderr, ">>> %s ( %p %s %c %d )\n", __func__, src, outname, plane, flags);
|
||||
|
||||
planeptr = charplane2int(plane, src); /* please explain XXX */
|
||||
fprintf(stderr, "planeptr is %p\n", planeptr);
|
||||
|
||||
if (verbosity) {
|
||||
fimg_describe(src, outname);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <fitsio.h>
|
||||
|
||||
|
@ -30,6 +32,8 @@ long naxes[2];
|
|||
fprintf(stderr, ">>> %s ( %p '%s' %d )\n", __func__, src, outname, flags);
|
||||
#endif
|
||||
|
||||
if (flags) { fprintf(stderr, "flags: 0x%04x in %s\n", flags, __func__); }
|
||||
|
||||
status = 0;
|
||||
|
||||
switch (plane) {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <pam.h>
|
||||
|
@ -13,9 +14,9 @@
|
|||
extern int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
static void print_struct_pam(struct pam *ppam, char *txt)
|
||||
static void print_struct_pam(struct pam *ppam, char *text)
|
||||
{
|
||||
|
||||
printf(" text %s\n", text);
|
||||
printf(" size %d\n", ppam->size);
|
||||
|
||||
printf(" format %d\n", ppam->format);
|
||||
|
@ -23,7 +24,6 @@ printf(" plainformat %d\n", ppam->plainformat);
|
|||
printf(" width & height %d %d\n", ppam->width, ppam->height);
|
||||
printf(" depth %d\n", ppam->depth);
|
||||
printf(" maxval %lu\n", ppam->maxval);
|
||||
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <pnglite.h>
|
||||
|
@ -86,7 +87,7 @@ if (PNG_NO_ERROR != foo) {
|
|||
}
|
||||
|
||||
ptr = datas;
|
||||
for (idx=0; idx<png.width * png.height; idx++) {
|
||||
for (idx=0; idx<(int)(png.width*png.height); idx++) {
|
||||
fimg->R[idx] = (float)*ptr++;
|
||||
fimg->G[idx] = (float)*ptr++;
|
||||
fimg->B[idx] = (float)*ptr++;
|
||||
|
@ -131,12 +132,12 @@ if ( 3 != png.bpp ) { /* TO BE PATCHED */
|
|||
}
|
||||
|
||||
/* check if floatimg and PNG have the same size */
|
||||
if ((fimg->width != png.width) || (fimg->height != png.height)) {
|
||||
if ((fimg->width != (int)png.width) || (fimg->height != (int)png.height)) {
|
||||
fprintf(stderr, "%s : fatal error on images sizes\n", __func__);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
datasize = png.width * png.height * png.bpp;
|
||||
datasize = png.width * png.height * png.bpp;
|
||||
datas = malloc(datasize);
|
||||
if (NULL==datas) {
|
||||
fprintf(stderr, "%s : fatal memory failure\n", __func__);
|
||||
|
@ -150,7 +151,7 @@ if (PNG_NO_ERROR != foo) {
|
|||
}
|
||||
|
||||
ptr = datas;
|
||||
for (idx=0; idx<png.width * png.height; idx++) {
|
||||
for (idx=0; idx<(int)(png.width*png.height); idx++) {
|
||||
fimg->R[idx] = (float)*ptr++;
|
||||
fimg->G[idx] = (float)*ptr++;
|
||||
fimg->B[idx] = (float)*ptr++;
|
||||
|
@ -170,9 +171,13 @@ unsigned char *bytes, *bptr;
|
|||
double maximum, fk;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %-25s ( %p '%s' 0x%x )\n", __func__, src, outname, flags);
|
||||
fprintf(stderr, ">>> %s ( %p '%s' 0x%x )\n", __func__, src, outname, flags);
|
||||
#endif
|
||||
|
||||
if (flags) {
|
||||
fprintf(stderr, "*** in %s, flags are %08x\n", __func__, flags);
|
||||
}
|
||||
|
||||
/* convert ou floating datas to a byte/rgb array */
|
||||
/* first, alloc a buffer */
|
||||
sz = src->width * src->height;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <tiffio.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
@ -23,6 +23,9 @@ int x, y, idx, foo;
|
|||
char ligne[100];
|
||||
double maximum, fk;
|
||||
|
||||
if (flags) fprintf(stderr, "in %s, flags are 0x%04x, must be 0\n",
|
||||
__func__, flags);
|
||||
|
||||
/* bon, tout cela semble bien tortueux ! */
|
||||
|
||||
if (FIMG_TYPE_RGB != src->type) {
|
||||
|
@ -44,6 +47,7 @@ if (verbosity) {
|
|||
|
||||
tiff = TIFFOpen(fname, "w");
|
||||
if (NULL==tiff) {
|
||||
fprintf(stderr, "erreur TIFFOpen\n");
|
||||
return -6;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* FLOATIMG
|
||||
* --------
|
||||
|
||||
* F M O R P H O
|
||||
*
|
||||
* nouveau 30 septembre 2022 / integration 28 octobre 2022
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
/* --------------------------------------------------------------------- !*/
|
||||
static struct
|
||||
{
|
||||
int x, y;
|
||||
} deltas[] =
|
||||
{ { -1, -1, },
|
||||
{ 0, -1, },
|
||||
{ 1, -1, },
|
||||
{ -1, 0, },
|
||||
{ 0, 0, },
|
||||
{ 1, 0, },
|
||||
{ -1, 1, },
|
||||
{ 0, 1, },
|
||||
{ 1, 1 }
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x, y; // not used
|
||||
float r, g, b;
|
||||
float fgris;
|
||||
int rang;
|
||||
} fpixel;
|
||||
|
||||
static fpixel pixels[9];
|
||||
|
||||
/* --------------------------------------------------------------------- !*/
|
||||
static int comparaison_fgris(const void *A, const void *B)
|
||||
{
|
||||
return ((fpixel *)A)->fgris > ((fpixel *)B)->fgris;
|
||||
}
|
||||
/* --------------------------------------------------------------------- !*/
|
||||
/*
|
||||
* this is a klugy approch, sorry.
|
||||
*/
|
||||
int fimg_filtre_morpho_0(FloatImg *sfimg, FloatImg *dfimg, int index)
|
||||
{
|
||||
int xs, ys, loop9;
|
||||
int xp, yp;
|
||||
float rgb[3];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, sfimg, dfimg, index);
|
||||
#endif
|
||||
|
||||
if ( (index<0) || (index>8)) {
|
||||
fprintf(stderr, " %s: bad index %d\n", __func__, index);
|
||||
#if MUST_ABORT
|
||||
fflush(stderr); abort();
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
fimg_clear(dfimg);
|
||||
|
||||
for (ys=1; ys<sfimg->height-1; ys++) {
|
||||
for (xs=1; xs<sfimg->width-1; xs++) {
|
||||
for (loop9=0; loop9<9; loop9++) {
|
||||
xp = xs + deltas[loop9].x;
|
||||
yp = ys + deltas[loop9].y;
|
||||
fimg_get_rgb(sfimg, xp, yp, rgb);
|
||||
pixels[loop9].fgris = rgb[0] + rgb[1] + rgb[2];
|
||||
pixels[loop9].rang = loop9;
|
||||
}
|
||||
qsort(&pixels, 9, sizeof(fpixel), comparaison_fgris);
|
||||
rgb[0] = rgb[1] = rgb[2] = pixels[index].fgris;
|
||||
fimg_put_rgb(dfimg, xs, ys, rgb);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- !*/
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
@ -26,6 +27,8 @@ fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
|
|||
src, dst, notused);
|
||||
#endif
|
||||
|
||||
if (notused) fprintf(stderr, "notused %d in %s\n", notused, __func__);
|
||||
|
||||
/* no magic check here ? */
|
||||
if (dst->width || dst->height) {
|
||||
fprintf(stderr, "*** %s: image at %p not empty\n", __func__, dst);
|
||||
|
@ -64,6 +67,8 @@ int wd, hd;
|
|||
int foo, x, y, x2, y2;
|
||||
float ac;
|
||||
|
||||
if (notused) fprintf(stderr, "notused %d in %s\n", notused, __func__);
|
||||
|
||||
if (dst->width || dst->height) {
|
||||
fprintf(stderr, "*** %s: image at %p not empty\n", __func__, dst);
|
||||
fimg_describe(dst, "destination halfsize 1");
|
||||
|
@ -105,19 +110,28 @@ for (y=0; y<hd; y++) {
|
|||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
* this function can be optimized with direct pixel copy
|
||||
*/
|
||||
int fimg_extractor(FloatImg *in, FloatImg *out, FimgArea51 *rect)
|
||||
{
|
||||
int foo;
|
||||
int xs, ys, xd, yd;
|
||||
int count;
|
||||
float rgb[3];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, in, out, rect);
|
||||
#endif
|
||||
|
||||
if (verbosity > 1) {
|
||||
fimg_describe(in, "extractor: source");
|
||||
fimg_describe(out, "extractor: destination");
|
||||
// print_rectangle(rect);
|
||||
}
|
||||
|
||||
/*
|
||||
* some sanity controls, please ! XXX
|
||||
*/
|
||||
|
||||
count = 0;
|
||||
for (yd=0; yd<rect->h; yd++) {
|
||||
ys = yd + rect->y;
|
||||
|
@ -131,7 +145,7 @@ for (yd=0; yd<rect->h; yd++) {
|
|||
}
|
||||
}
|
||||
|
||||
// fprintf(stderr, "%s: %d pix moved\n", __func__, count);
|
||||
if (verbosity > 1) fprintf(stderr, "%s: %d pix moved\n", __func__, count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -148,6 +162,8 @@ fprintf(stderr, ">>> %s ( %p %p 0x%04x )\n", __func__,
|
|||
src, dst, notused);
|
||||
#endif
|
||||
|
||||
if (notused) fprintf(stderr, "notused %d in %s\n", notused, __func__);
|
||||
|
||||
if (fimg_images_not_compatible(src, dst)) {
|
||||
fprintf(stderr, "bad karma in %s\n", __func__);
|
||||
return -9;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
|
|
14
funcs/hsv.c
14
funcs/hsv.c
|
@ -10,12 +10,19 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "../floatimg.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/*
|
||||
https://baillehachepascal.dev/2021/rgb_hsv.php
|
||||
|
||||
|
||||
|
||||
*/
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* helper functions */
|
||||
static float maxi3f(float a, float b, float c)
|
||||
|
@ -28,7 +35,7 @@ return ((a < b)? (a < c ? a : c) : (b < c ? b : c));
|
|||
}
|
||||
static int pseudoeq(float a, float b)
|
||||
{
|
||||
return (fabsf(a-b)<0.00000000000001); // UGLY HACK ???
|
||||
return (fabsf(a-b)<0.00000001); // UGLY HACK ???
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
|
@ -78,7 +85,7 @@ float hh, ff, p, q, t;
|
|||
long i;
|
||||
|
||||
if(hsv[1] <= 0.0) { // < is bogus, just shuts up warnings
|
||||
rgb[0] = rgb[1] = rgb[2] = hsv[2];
|
||||
rgb[0] = rgb[1] = rgb[2] = (hsv[2] * scale);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -124,7 +131,10 @@ int fimg_essai_hsv(char *fname)
|
|||
float colors[3], values[3], newcols[3];
|
||||
int foo, r, g, b;
|
||||
|
||||
fprintf(stderr, "%s NOT writing to %s\n", __func__, fname);
|
||||
|
||||
#define INC 16
|
||||
|
||||
for (r=0; r<255; r+=INC) {
|
||||
for (g=0; g<255; g+=INC) {
|
||||
for (b=0; b<255; b+=INC) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
@ -19,23 +20,26 @@ static int check_boundaries(FloatImg *from, FloatImg *to, FimgArea51 *a51)
|
|||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, from, to, a51);
|
||||
fimg_printdims("from", from);
|
||||
fimg_printdims("to ", to);
|
||||
#endif
|
||||
|
||||
if (verbosity > 1) {
|
||||
fimg_printdims("from", from);
|
||||
fimg_printdims("to ", to);
|
||||
}
|
||||
|
||||
/* just a small molly-guard */
|
||||
if ( (a51->w < 0) || (a51->h < 0) ) {
|
||||
fprintf(stderr, "%s: fubar on %p\n", __func__, a51);
|
||||
abort(); /* FY Bro ! */
|
||||
}
|
||||
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* XXX
|
||||
static int move_pixels(FloatImg *from, FloatImg *to,
|
||||
FimgArea51 *a51, int flags)
|
||||
{
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %p 0x%04x )\n", __func__,
|
||||
from, to, a51, flags);
|
||||
|
@ -43,7 +47,11 @@ fprintf(stderr, ">>> %s ( %p %p %p 0x%04x )\n", __func__,
|
|||
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
* See also: fimg_extractor() in geometry.c
|
||||
*/
|
||||
int fimg_incrustator_0(FloatImg *psrc, FloatImg *pdst,
|
||||
int xpos, int ypos, int flags)
|
||||
{
|
||||
|
@ -57,6 +65,8 @@ fprintf(stderr, ">>> %s ( %p %p %d %d 0x%04X\n", __func__, psrc, pdst,
|
|||
xpos, ypos, flags);
|
||||
#endif
|
||||
|
||||
if (flags) { fprintf(stderr, "flags: 0x%04x in %s\n", flags, __func__); }
|
||||
|
||||
if (verbosity > 1) {
|
||||
fimg_describe(psrc, "source");
|
||||
fimg_describe(pdst, "destination");
|
||||
|
@ -66,10 +76,15 @@ if (verbosity > 1) {
|
|||
area.x = xpos; area.y = ypos;
|
||||
area.w = psrc->width; area.h = psrc->height;
|
||||
foo = check_boundaries(psrc, pdst, &area);
|
||||
if (foo) {
|
||||
fprintf(stderr, "Boudary error %d in %s:%d\n", foo, __func__, __LINE__);
|
||||
return foo;
|
||||
}
|
||||
|
||||
if ( (xpos < 0) || (xpos > pdst->width - psrc->width) ||
|
||||
(ypos < 0) || (ypos > pdst->height - psrc->height) ) {
|
||||
fprintf(stderr, "%s: boudary error\n", __func__);
|
||||
fprintf(stderr, "%s: boudary error, x=%d y=%d\n", __func__,
|
||||
xpos, ypos);
|
||||
return -2;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* KILL RGB !
|
||||
*
|
||||
* nouveau TerreBlanque 4 octobre 2021
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
#include "tests.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
int fimg_killrgb_v(FloatImg *src, FloatImg *dst, int k)
|
||||
{
|
||||
int line, col;
|
||||
int ir;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, src, dst, k);
|
||||
#endif
|
||||
|
||||
if (k) { fprintf(stderr, "in %s k was %d\n", __func__, k); }
|
||||
|
||||
fimg_clear(dst);
|
||||
ir = 0;
|
||||
|
||||
for (line=0; line<src->height; line++) {
|
||||
// fprintf(stderr, "%s line %d\n", __func__, line);
|
||||
for (col=0; col<(src->width-3); col+=3) {
|
||||
|
||||
dst->R[ir ] = src->R[ir]; ir++;
|
||||
dst->G[ir+1] = src->G[ir]; ir++;
|
||||
dst->B[ir+2] = src->B[ir]; ir++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
|
@ -4,11 +4,17 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
*********************************************
|
||||
* SEGFAULT SI IMAGE TROP PETITE *
|
||||
*********************************************
|
||||
*/
|
||||
|
||||
int fimg_test_pattern(FloatImg *fimg, int type, double dval)
|
||||
{
|
||||
|
@ -25,6 +31,12 @@ if (fimg->type != FIMG_TYPE_RGB) {
|
|||
return -6;
|
||||
}
|
||||
|
||||
fprintf(stderr, "ENTERING %s\n", __func__);
|
||||
|
||||
if (type) {
|
||||
fprintf(stderr, "%s : %d %f\n", __func__, type, dval);
|
||||
}
|
||||
|
||||
/* rampe de primaires dans le quart du haut */
|
||||
val = (float)dval;
|
||||
for (x=0; x<fimg->width; x++) {
|
||||
|
@ -45,7 +57,7 @@ for (x=0; x<fimg->width; x++) {
|
|||
fimg_plot_rgb(fimg, x, y, fr, fg, fb);
|
||||
}
|
||||
|
||||
k = fimg->height / 4;
|
||||
k = (fimg->height / 4) + 20;
|
||||
for (x=0; x<fimg->width; x++) {
|
||||
val = ((double)x / (double)fimg->width) * dval;
|
||||
for (y=0; y<20; y++) {
|
||||
|
@ -55,6 +67,27 @@ for (x=0; x<fimg->width; x++) {
|
|||
// fprintf(stderr, " %6d %f\n", x, val);
|
||||
}
|
||||
|
||||
|
||||
k = (fimg->height / 4) + 90;
|
||||
for (x=0; x<fimg->width; x++) {
|
||||
val = ((x%8)<4) ? dval : 0.0;
|
||||
for (y=0; y<20; y++) {
|
||||
fimg_plot_rgb(fimg, x, k+y, val, val, val);
|
||||
fimg_plot_rgb(fimg, x, k+y+20, dval-val, dval-val, dval-val);
|
||||
}
|
||||
}
|
||||
|
||||
k = (fimg->height / 4) + 140;
|
||||
for (x=0; x<fimg->width; x++) {
|
||||
for (y=0; y<20; y++) {
|
||||
val = drand48() * dval;
|
||||
fimg_plot_rgb(fimg, x, k+y, val, val, val);
|
||||
fimg_plot_rgb(fimg, x, k+y+20, dval-val, dval-val, dval-val);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "ALIVE %s\n", __func__);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
@ -86,6 +119,24 @@ for (y=1; y<fimg->height; y++) {
|
|||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int fimg_mircol_1(FloatImg *dst, float mval)
|
||||
{
|
||||
int x, y;
|
||||
float fx, fy, rgb[3];
|
||||
|
||||
for (y=0; y<dst->height; y++) {
|
||||
fy = (float)y / (float)dst->height;
|
||||
for (x=0; x<dst->width; x++) {
|
||||
fx = (float)x / (float)dst->width;
|
||||
rgb[0] = mval * fx;
|
||||
rgb[1] = mval * ((fx+fy)/2.0);
|
||||
rgb[2] = mval * fy;
|
||||
fimg_put_rgb(dst, x, y, rgb);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int fimg_multirandom(FloatImg *fimg, long nbpass)
|
||||
{
|
||||
int foo, x, y;
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* P I X E L I Z E
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* nouveau 10 octobre 2021 dans la roulotte de Terreblanque */
|
||||
|
||||
#define LARGEUR 16
|
||||
|
||||
int fimg_pixelize_h_0(FloatImg *psrc, FloatImg *pdst, int largeur)
|
||||
{
|
||||
int line, col, loop, idx;
|
||||
float cr, cg, cb; /* cumuls */
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, largeur);
|
||||
#endif
|
||||
|
||||
if (fimg_images_not_compatible(psrc, pdst)) {
|
||||
fprintf(stderr, "%s: err compatibility\n", __func__);
|
||||
return -8;
|
||||
}
|
||||
|
||||
switch(largeur) {
|
||||
case 8: case 16: case 32:
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: bad width %d\n", __func__, largeur);
|
||||
return -77;
|
||||
}
|
||||
|
||||
for (line=0; line<psrc->height; line++) {
|
||||
for (col=0; col<psrc->width; col+=largeur) {
|
||||
cr = cg = cb = 0.0;
|
||||
idx = line * psrc->width + col;
|
||||
for (loop=0; loop<largeur; loop++) {
|
||||
cr += psrc->R[idx+loop];
|
||||
cg += psrc->G[idx+loop];
|
||||
cb += psrc->B[idx+loop];
|
||||
}
|
||||
for (loop=0; loop<largeur; loop++) {
|
||||
pdst->R[idx+loop] = cr / (float)largeur;
|
||||
pdst->G[idx+loop] = cg / (float)largeur;
|
||||
pdst->B[idx+loop] = cb / (float)largeur;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* un essai dans la roulotte :)
|
||||
* 11 oct 2021 : premier jet, essai concluant, mais necessite
|
||||
* du travail sur les rand() pour etre plus 'noisy'
|
||||
*
|
||||
*/
|
||||
int fimg_pixelize_h_rnd(FloatImg *psrc, FloatImg *pdst, int largeur)
|
||||
{
|
||||
static int count = 0;
|
||||
static int flag = 0;
|
||||
int foo;
|
||||
|
||||
/* may be a mollyguard on 'largeur' parameter ? */
|
||||
|
||||
if (0==count) {
|
||||
if (flag) {
|
||||
count = irand2(5, 10);
|
||||
flag = ! flag;
|
||||
}
|
||||
else {
|
||||
count = irand2(20, 40);
|
||||
flag = ! flag;
|
||||
}
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "%s c=%d f=%c\n", __func__,
|
||||
count, flag?'T':'F');
|
||||
}
|
||||
}
|
||||
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "%s: count=%d flag=%d\n", __func__, count, flag);
|
||||
}
|
||||
|
||||
foo = fimg_pixelize_h_0(psrc, pdst, flag ? largeur : 32);
|
||||
if (foo) {
|
||||
fprintf(stderr, "pixelize_h_0 give err %d in %s\n", foo, __func__);
|
||||
}
|
||||
|
||||
count--; /* nice trick bro */
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
|
@ -29,13 +31,11 @@ for (y=0; y<img->height; y++) {
|
|||
for (x=0; x<img->width; x++) {
|
||||
dx = ((double)x/(double)img->width) - 0.5000;
|
||||
|
||||
rgb[0] = sin(dx*10 + time) + 1.0;
|
||||
rgb[1] = sin(dx*12 + time) + 1.0;
|
||||
rgb[2] = sin(dx*14 + time) + 1.0;
|
||||
rgb[0] = sin(dx*10 + time + dy) + 1.0;
|
||||
rgb[1] = sin(dx*12 + time + dy) + 1.0;
|
||||
rgb[2] = sin(dx*14 + time + dy) + 1.0;
|
||||
fimg_put_rgb(img, x, y, rgb);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
|
@ -27,6 +28,8 @@ int foo, szimg;
|
|||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, notused);
|
||||
#endif
|
||||
|
||||
if (notused) { fprintf(stderr, "%s notused != 0, WTF ?\n", __func__); }
|
||||
|
||||
if (FIMG_TYPE_RGB != psrc->type) {
|
||||
fprintf(stderr, "%s: bad src type %d\n", __func__, psrc->type);
|
||||
return -7;
|
||||
|
@ -77,6 +80,8 @@ float rgb[3];
|
|||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, psrc, pdst, notused);
|
||||
#endif
|
||||
|
||||
if (notused) { fprintf(stderr, "%s notused != 0, WTF ?\n", __func__); }
|
||||
|
||||
if (FIMG_TYPE_RGB != psrc->type) {
|
||||
fprintf(stderr, "%s: bad src type %d\n", __func__, psrc->type);
|
||||
return -7;
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
|
@ -21,8 +24,7 @@ if (FIMG_TYPE_RGB != img->type) {
|
|||
fprintf(stderr, "%s bad type\n", __func__);
|
||||
return -6;
|
||||
}
|
||||
for (x=0; x<img->width; x++)
|
||||
{
|
||||
for (x=0; x<img->width; x++) {
|
||||
value = (float)x / (float)img->width;
|
||||
value *= dcoef;
|
||||
for (y=0; y<img->height; y++) {
|
||||
|
@ -49,11 +51,10 @@ if (FIMG_TYPE_RGB != img->type) {
|
|||
fprintf(stderr, "%s bad type\n", __func__);
|
||||
return -6;
|
||||
}
|
||||
for (y=0; y<img->height; y++)
|
||||
{
|
||||
value = (float)y / (float)img->height;
|
||||
for (x=0; x<img->width; x++) {
|
||||
value = (float)x / (float)img->width;
|
||||
value *= dcoef;
|
||||
for (x=0; x<img->width; x++) {
|
||||
for (y=0; y<img->height; y++) {
|
||||
fimg_plot_rgb(img, x, y, value, value, value);
|
||||
}
|
||||
}
|
||||
|
@ -61,3 +62,52 @@ for (y=0; y<img->height; y++)
|
|||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* nouveau 19 septembre 2022
|
||||
*
|
||||
* 6 octobre 2023 : rajout du parametre 'fmax'
|
||||
*/
|
||||
|
||||
int fimg_do_stripes(FloatImg *img, float fmax, int mode)
|
||||
{
|
||||
int x, y, quad;
|
||||
float *ligne;
|
||||
float fr, fg, fb;
|
||||
|
||||
fprintf(stderr, ">>> %s ( %p %f %d )\n", __func__, img, fmax, mode);
|
||||
|
||||
/*
|
||||
* allocate and fill a lookup table
|
||||
*/
|
||||
if (NULL==(ligne=malloc(img->width*sizeof(float)))) {
|
||||
fprintf(stderr, "%s: malloc fail\n", __func__);
|
||||
exit(1);
|
||||
}
|
||||
for (x=0; x<img->width; x++) {
|
||||
ligne[x] = (float)x / (float)img->width;
|
||||
ligne[x] *= fmax;
|
||||
}
|
||||
|
||||
/*
|
||||
* build the pixels
|
||||
*/
|
||||
for (y=0; y<img->height; y++)
|
||||
{
|
||||
quad = (y*4) / img->height ;
|
||||
for (x=0; x<img->width; x++) {
|
||||
fr = fg = fb = ligne[x];
|
||||
switch(quad) {
|
||||
case 0: fg = fb = 0; break;
|
||||
case 1: fr = fb = 0; break;
|
||||
case 2: fr = fg = 0; break;
|
||||
case 3: break;
|
||||
default: abort(); break;
|
||||
}
|
||||
fimg_plot_rgb(img, x, y, fr, fg, fb);
|
||||
}
|
||||
}
|
||||
|
||||
free(ligne);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* R E C T A N G L E
|
||||
* This is an eternal WIP, sorry...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int fimg_clear_rectangle(FloatImg *pi, int coo[4])
|
||||
{
|
||||
int line, off;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p )\n", __func__, pi, coo);
|
||||
#endif
|
||||
|
||||
/* please add boudary checks */
|
||||
|
||||
for (line=0; line<coo[3]; line++) {
|
||||
off = (line+coo[1])*pi->width + coo[0];
|
||||
// fprintf(stderr, "line %3d off %8d\n", line, off);
|
||||
/* Kaboum ! */
|
||||
memset(pi->R + off, 0, coo[2]*sizeof(float));
|
||||
memset(pi->G + off, 0, coo[2]*sizeof(float));
|
||||
memset(pi->B + off, 0, coo[2]*sizeof(float));
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
|
@ -20,6 +22,19 @@ int fimg_recursion_proto(FloatImg *src, FloatImg *dst, int notused)
|
|||
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, src, dst, notused);
|
||||
#endif
|
||||
|
||||
if (notused) {
|
||||
fprintf(stderr, "%s parameter notused is %d, must be 0\n",
|
||||
__func__, notused);
|
||||
return -2;
|
||||
}
|
||||
|
||||
fprintf(stderr, "!!!!!! %s is a wip !!!!!\n", __func__);
|
||||
|
||||
/*
|
||||
* bon, maintenant, il faut plonger dans du code du
|
||||
* siecle dernier et l'adapter a ce nouveau contexte
|
||||
*/
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
|
@ -23,6 +25,8 @@ fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
|
|||
src, dst, notused);
|
||||
#endif
|
||||
|
||||
if (notused) fprintf(stderr, "notused %d in %s\n", notused, __func__);
|
||||
|
||||
if (src->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s: src type %d not valid\n", __func__,
|
||||
src->type);
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
|
@ -99,7 +101,7 @@ coefs[0] = coefs[2] = coefs[4] = minima;
|
|||
|
||||
foo = fimg_shift_to_zero(src, dst, coefs);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s WTF?\n", __func__);
|
||||
fprintf(stderr, "%s WTF? %d\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
|
@ -24,7 +26,7 @@ if (FIMG_TYPE_RGB != fimg->type) {
|
|||
|
||||
nbpix = fimg->width * fimg->height;
|
||||
for (foo=0; foo<nbpix; foo++) {
|
||||
if (fimg->R[foo] > fimg->G[foo])
|
||||
if ((fimg->R[foo]+fval) > fimg->G[foo])
|
||||
fimg->B[foo] = fimg->R[foo];
|
||||
else
|
||||
fimg->B[foo] = fimg->G[foo];
|
||||
|
@ -48,7 +50,7 @@ if (FIMG_TYPE_RGB != fimg->type) {
|
|||
|
||||
nbpix = fimg->width * fimg->height;
|
||||
for (foo=0; foo<nbpix; foo++) {
|
||||
if (fimg->R[foo] > fimg->B[foo])
|
||||
if ((fimg->R[foo]+fval) > fimg->B[foo])
|
||||
fimg->G[foo] = fimg->R[foo];
|
||||
else
|
||||
fimg->G[foo] = fimg->B[foo];
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
|
|
12
funcs/sfx2.c
12
funcs/sfx2.c
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
|
@ -23,6 +25,11 @@ int foo, size;
|
|||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, notused);
|
||||
#endif
|
||||
|
||||
if (notused) {
|
||||
fprintf(stderr, "notused was %d, must be 0 in %s\n",
|
||||
notused, __func__);
|
||||
}
|
||||
|
||||
foo = fimg_get_minmax_rgb(pimg, mm);
|
||||
mR = (mm[1] - mm[0]) / 2.0;
|
||||
mG = (mm[3] - mm[2]) / 2.0;
|
||||
|
@ -52,6 +59,11 @@ float mm[6], mRa, mGa, mBa, mRb, mGb, mBb;
|
|||
float *fptr;
|
||||
int foo, size;
|
||||
|
||||
if (notused) {
|
||||
fprintf(stderr, "notused was %d, must be 0 in %s\n",
|
||||
notused, __func__);
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, notused);
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* FLOATIMG - a kluge from tTh
|
||||
* ---------------------------
|
||||
*
|
||||
* some strange effects on floating pictures, made in
|
||||
* the batcave of "Le Bib", in Montpellier.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
/* new Sun 29 Jan 2023 10:01:39 PM CET
|
||||
|
||||
*/
|
||||
int fimg_make_rndfluffy_lines(FloatImg *src, FloatImg *dst, int rndt)
|
||||
{
|
||||
int x, y, ol;
|
||||
float accu;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%p' '%p' %d )\n", __func__,
|
||||
src, dst, rndt);
|
||||
#endif
|
||||
|
||||
if (fimg_images_not_compatible(src, dst)) {
|
||||
/* be hard for the lamers */
|
||||
fprintf(stderr, "compatibility OUPS in %s\n", __func__);
|
||||
abort();
|
||||
}
|
||||
|
||||
for (y=0; y<src->height; y++) {
|
||||
ol = y * src->width;
|
||||
if (rndt < (rand() % 100)) {
|
||||
accu = 0.0;
|
||||
for (x=0; x<src->width; x++) accu += src->R[ol + x];
|
||||
accu /= (float)src->width;
|
||||
for (x=0; x<src->width; x++) dst->R[ol + x] = accu;
|
||||
}
|
||||
else {
|
||||
for (x=0; x<src->width; x++) {
|
||||
dst->R[ol+x] = src->R[ol+x];
|
||||
dst->G[ol+x] = src->G[ol+x];
|
||||
dst->B[ol+x] = src->B[ol+x];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
int fimg_crump_hard(FloatImg *src, FloatImg *dst, float kval, int notused)
|
||||
{
|
||||
float halfval;
|
||||
float rgb[3];
|
||||
int x, y, foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %f 0x%04x )\n", __func__,
|
||||
src, dst, kval, notused);
|
||||
#endif
|
||||
|
||||
if (notused) {
|
||||
fprintf(stderr, "notused was %d, must be 0 in %s\n",
|
||||
notused, __func__);
|
||||
}
|
||||
|
||||
halfval = fimg_get_maxvalue(src) / 2.0;
|
||||
if (verbosity > 1) {
|
||||
fprintf(stderr, "%s: kval=%f & halfval=%f\n", __func__,
|
||||
kval, halfval);
|
||||
}
|
||||
|
||||
for (y=0; y<src->height; y++) {
|
||||
for (x=0; x<src->width; x++) {
|
||||
foo = fimg_get_rgb(src, x, y, rgb);
|
||||
if (foo) return foo;
|
||||
|
||||
if (rgb[0] > halfval) rgb[0] /= 2.0;
|
||||
if (rgb[1] > halfval) rgb[1] /= 2.0;
|
||||
if (rgb[2] > halfval) rgb[2] /= 2.0;
|
||||
|
||||
foo = fimg_put_rgb(dst, x, y, rgb);
|
||||
if (foo) return foo;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* FLOATIMG - a kluge from tTh
|
||||
* ---------------------------
|
||||
*
|
||||
* some strange effects on floating pictures.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
int fimg_sfx_triplemul(FloatImg *src, FloatImg *dst, int notused)
|
||||
{
|
||||
int x, y, foo;
|
||||
float in[3], out[3];
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p 0x%04x )\n", __func__, src, dst, notused);
|
||||
#endif
|
||||
|
||||
if (notused) {
|
||||
fprintf(stderr, "notused was %d, must be 0 in %s\n",
|
||||
notused, __func__);
|
||||
}
|
||||
|
||||
for (y=0; y<src->height; y++) {
|
||||
for (x=0; x<src->width; x++) {
|
||||
foo = fimg_get_rgb(src, x, y, in);
|
||||
if (foo) return foo;
|
||||
out[0] = in[1] * in[2];
|
||||
out[1] = in[0] * in[2];
|
||||
out[2] = in[0] * in[1];
|
||||
// fprintf(stderr, "%9f %9f %9f\n", out[0], out[1], out[2]);
|
||||
foo = fimg_put_rgb(dst, x, y, out);
|
||||
if (foo) return foo;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/*
|
||||
* see also:
|
||||
sfx3.c:fimg_crump_hard()
|
||||
*/
|
||||
int fimg_split_level(FloatImg *src, FloatImg *dst, int notused)
|
||||
{
|
||||
float means[4];
|
||||
// float in[3];
|
||||
int foo, idx, surface;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p 0x%04x )\n", __func__, src, dst, notused);
|
||||
#endif
|
||||
|
||||
if (notused) {
|
||||
fprintf(stderr, "notused was %d, must be 0 in %s\n",
|
||||
notused, __func__);
|
||||
}
|
||||
|
||||
foo = fimg_meanvalues(src, means);
|
||||
if (foo) {
|
||||
return -66;
|
||||
}
|
||||
|
||||
surface = src->width*src->height;
|
||||
for(idx=0; idx<surface; idx++) {
|
||||
if (src->R[idx]<means[0]) dst->R[idx]=src->R[idx]*2.0;
|
||||
else dst->R[idx]=(src->R[idx]-means[0])*2.0;
|
||||
if (src->G[idx]<means[1]) dst->G[idx]=src->G[idx]*2.0;
|
||||
else dst->G[idx]=(src->G[idx]-means[1])*2.0;
|
||||
if (src->B[idx]<means[2]) dst->B[idx]=src->B[idx]*2.0;
|
||||
else dst->B[idx]=(src->B[idx]-means[2])*2.0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------- */
|
65
funcs/t.c
65
funcs/t.c
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <pam.h>
|
||||
|
||||
|
@ -22,7 +23,10 @@ float global_fvalue;
|
|||
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
|
||||
Histo, Hsv, Classif, Ctr2x2, Qsortrgb,
|
||||
Displace, ReadPNG, Plasmas, Hilight, OpenEXR,
|
||||
Geometrie, FileType, Mirror };
|
||||
Geometrie, FileType, Mirror, KillRGB,
|
||||
Pixelize,SplitLevel, DecompRgbz, DecompRgbg,
|
||||
Rectangle, Dicom, Fakolor0, Fakolor3,
|
||||
Fmorpho0, Fluffy };
|
||||
typedef struct {
|
||||
char *name;
|
||||
int Cmd;
|
||||
|
@ -50,6 +54,17 @@ Command commands[] = {
|
|||
{ "geometrie", Geometrie, },
|
||||
{ "filetype", FileType },
|
||||
{ "mirror", Mirror },
|
||||
{ "killrgb", KillRGB },
|
||||
{ "pixelize", Pixelize },
|
||||
{ "spltlvl", SplitLevel },
|
||||
{ "decomprgbz", DecompRgbz },
|
||||
{ "decomprgbg", DecompRgbg },
|
||||
{ "rectangle", Rectangle },
|
||||
{ "dicom", Dicom },
|
||||
{ "fakolor0", Fakolor0 },
|
||||
{ "fakolor3", Fakolor3 },
|
||||
{ "fmorpho0", Fmorpho0 },
|
||||
{ "fluffy", Fluffy },
|
||||
{ NULL, 0 }
|
||||
} ;
|
||||
|
||||
|
@ -87,15 +102,21 @@ fprintf(stderr, "options:\n");
|
|||
fprintf(stderr, "\t-k 1.414\tset float value\n");
|
||||
fprintf(stderr, "\t-l\t\tlist tests\n");
|
||||
fprintf(stderr, "\t-o \t\toutfile\n");
|
||||
fprintf(stderr, "\t-v \t\tincrease verbosity\n");
|
||||
|
||||
fprintf(stderr, "commands:\n");
|
||||
pcmd = commands;
|
||||
while (pcmd->name) {
|
||||
fprintf(stderr, "\t%-15s %d\n", pcmd->name, pcmd->Cmd);
|
||||
pcmd++;
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "commands:\n");
|
||||
pcmd = commands;
|
||||
while (pcmd->name) {
|
||||
fprintf(stderr, "\t%-15s %d\n", pcmd->name, pcmd->Cmd);
|
||||
pcmd++;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "\ncompiled on "__DATE__" at "__TIME__"\n");
|
||||
|
||||
if (k) fimg_print_version(k);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
@ -215,6 +236,36 @@ switch(opt) {
|
|||
case Mirror:
|
||||
foo = essai_miroir(filename, outfile, 0);
|
||||
break;
|
||||
case KillRGB:
|
||||
foo = essai_killrgb(filename, outfile);
|
||||
break;
|
||||
case Pixelize:
|
||||
foo = essai_pixelize(filename, outfile);
|
||||
break;
|
||||
case SplitLevel:
|
||||
foo = essai_split_level(filename, outfile, 0);
|
||||
break;
|
||||
case DecompRgbz:
|
||||
foo = essai_decomprgb_color(filename, outfile);
|
||||
break;
|
||||
case DecompRgbg:
|
||||
foo = essai_decomprgb_gray(filename, outfile);
|
||||
break;
|
||||
case Rectangle:
|
||||
essai_rectangle(outfile, 0);
|
||||
break;
|
||||
case Dicom:
|
||||
foo = essai_dicom(filename, outfile, 0);
|
||||
break;
|
||||
case Fakolor0:
|
||||
foo = essai_0_fausses_couleurs(outfile, 0);
|
||||
break;
|
||||
case Fmorpho0:
|
||||
foo = essai_fmorpho_0(filename, "/tmp/fmorpho", 0);
|
||||
break;
|
||||
case Fluffy:
|
||||
foo = essai_rndfluffy(filename, outfile, 0);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "'%s' is a bad command\n", command);
|
||||
exit(1);
|
||||
|
@ -222,7 +273,7 @@ switch(opt) {
|
|||
}
|
||||
|
||||
if (foo) {
|
||||
fprintf(stderr, "******* Essai --> %d\n", foo);
|
||||
fprintf(stderr, "******* essai --> %d\n\n", foo);
|
||||
}
|
||||
|
||||
fprintf(stderr, "++++++++++++ end of '%s' pid %d\n", command, getpid());
|
||||
|
|
351
funcs/tests.c
351
funcs/tests.c
|
@ -1,10 +1,14 @@
|
|||
/*
|
||||
* FLOATIMG
|
||||
* --------
|
||||
|
||||
* tests des fonctions diverses - subroutines
|
||||
see also: t.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <pam.h>
|
||||
|
||||
|
@ -16,6 +20,234 @@
|
|||
|
||||
extern int verbosity;
|
||||
|
||||
#define W 1024
|
||||
#define H 768
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
* nouveau 30 octobre 2022 --> fmorpho.c
|
||||
*/
|
||||
int essai_fmorpho_0(char *infile, char *basefname, int k)
|
||||
{
|
||||
FloatImg src, dst;
|
||||
int idx, foo;
|
||||
char fname[100];
|
||||
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__, infile, basefname, k);
|
||||
|
||||
if (k) {
|
||||
fprintf(stderr, "%s k=%d must be 0\n", __func__, k);
|
||||
return -6;
|
||||
}
|
||||
|
||||
if (NULL == infile ) {
|
||||
foo = fimg_create(&src, W, H, FIMG_TYPE_RGB);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: create -> %d\n",__func__, foo);
|
||||
return foo;
|
||||
}
|
||||
foo = fimg_test_pattern(&src, 0, 254.99);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: test_pattern -> %d\n",__func__, foo);
|
||||
return foo;
|
||||
}
|
||||
}
|
||||
else {
|
||||
foo = fimg_create_from_dump(infile, &src);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: error %d loading '%s'\n", __func__, foo, infile);
|
||||
return foo;
|
||||
}
|
||||
}
|
||||
|
||||
fimg_save_as_pnm(&src, "foo.pnm", 0);
|
||||
|
||||
foo = fimg_clone(&src, &dst, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: clone -> %d\n",__func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
for (idx=0; idx<9; idx++) {
|
||||
sprintf(fname, "%s%04d.pnm", basefname, idx);
|
||||
fprintf(stderr, " ---> %s\n", fname);
|
||||
foo = fimg_filtre_morpho_0(&src, &dst, idx);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: got a %d at round %d\n", __func__, foo, idx);
|
||||
return foo;
|
||||
}
|
||||
fimg_save_as_pnm(&dst, fname, 0);
|
||||
}
|
||||
|
||||
fimg_destroy(&src); fimg_destroy(&dst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* nouveau 18 mai 2022 */
|
||||
int essai_0_fausses_couleurs(char *dstfile, int type)
|
||||
{
|
||||
FloatImg src, dst;
|
||||
int foo;
|
||||
|
||||
fprintf(stderr, "\nEssais fausses couleurs (type %d) -> '%s'\n", type, dstfile);
|
||||
|
||||
foo = fimg_create(&src, W, H, FIMG_TYPE_RGB);
|
||||
foo = fimg_hdeg_a(&src, 12e3);
|
||||
// fimg_export_picture(&src, "debug.pnm", 0);
|
||||
foo = fimg_clone(&src, &dst, 0);
|
||||
foo = fimg_clear(&dst);
|
||||
|
||||
foo = fimg_falsecolors_0(&src, &dst, type, 3.141592654);
|
||||
fprintf(stderr, "false colors 0 --> %d\n", foo);
|
||||
|
||||
foo = fimg_export_picture(&dst, dstfile, 0);
|
||||
fimg_destroy(&src); fimg_destroy(&dst);
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int essai_dicom(char *inf, char *outf, int k)
|
||||
{
|
||||
int foo;
|
||||
FloatImg img;
|
||||
|
||||
fprintf(stderr, ">>> %s ( %s %s %d )\n", __func__, inf, outf, k);
|
||||
|
||||
foo = fimg_create(&img, 320, 240, FIMG_TYPE_RGB);
|
||||
fimg_drand48(&img, 1.0);
|
||||
|
||||
foo = fimg_save_plane_as_dicom(&img, outf, 'R', 0);
|
||||
fprintf(stderr, "dicom: save a plane --> %d\n", foo);
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int essai_rectangle(char *outf, int k)
|
||||
{
|
||||
FloatImg img;
|
||||
int foo;
|
||||
int rect[4];
|
||||
|
||||
if (0 != k) {
|
||||
fprintf(stderr, "in %s, k muste be 0, was %d\n", __func__, k);
|
||||
}
|
||||
|
||||
foo = fimg_create(&img, 320, 240, FIMG_TYPE_RGB);
|
||||
|
||||
fimg_drand48(&img, 1.0);
|
||||
|
||||
rect[0] = 100; rect[1] = 100;
|
||||
rect[2] = 32; rect[3] = 16;
|
||||
|
||||
foo = fimg_clear_rectangle(&img, rect);
|
||||
|
||||
foo = fimg_export_picture(&img, outf, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
fimg_destroy(&img);
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int essai_killrgb(char *inf, char *outf)
|
||||
{
|
||||
int foo;
|
||||
FloatImg src, dst;
|
||||
|
||||
fprintf(stderr, ">>> %s ( %s %s )\n", __func__, inf, outf);
|
||||
|
||||
foo = fimg_create_from_dump(inf, &src);
|
||||
if (0 != foo) {
|
||||
fprintf(stderr, "%s: err %d loading image '%s'\n", __func__,
|
||||
foo, inf);
|
||||
return foo;
|
||||
}
|
||||
fimg_clone(&src, &dst, 1);
|
||||
|
||||
foo = fimg_killrgb_v(&src, &dst, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s:%s(): fail %d line %d\n",
|
||||
__FILE__, __func__, foo, __LINE__);
|
||||
return foo;
|
||||
}
|
||||
|
||||
foo = fimg_export_picture(&dst, outf, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int essai_decomprgb_gray(char *inf, char *outf)
|
||||
{
|
||||
int foo;
|
||||
FloatImg src, dst;
|
||||
|
||||
fprintf(stderr, ">>> %s ( %s %s )\n", __func__, inf, outf);
|
||||
|
||||
foo = fimg_create_from_dump(inf, &src);
|
||||
if (0 != foo) {
|
||||
fprintf(stderr, "%s: err %d loading image '%s'\n", __func__,
|
||||
foo, inf);
|
||||
return foo;
|
||||
}
|
||||
fimg_clone(&src, &dst, 1);
|
||||
|
||||
foo = fimg_decomp_rgbz_gray(&src, &dst, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s:%s(): fail %d line %d\n",
|
||||
__FILE__, __func__, foo, __LINE__);
|
||||
return foo;
|
||||
}
|
||||
|
||||
foo = fimg_export_picture(&dst, outf, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
fimg_destroy(&src); fimg_destroy(&dst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int essai_decomprgb_color(char *inf, char *outf)
|
||||
{
|
||||
int foo;
|
||||
FloatImg src, dst;
|
||||
|
||||
fprintf(stderr, ">>> %s ( %s %s )\n", __func__, inf, outf);
|
||||
|
||||
foo = fimg_create_from_dump(inf, &src);
|
||||
if (0 != foo) {
|
||||
fprintf(stderr, "%s: err %d loading image '%s'\n", __func__,
|
||||
foo, inf);
|
||||
return foo;
|
||||
}
|
||||
fimg_clone(&src, &dst, 1);
|
||||
|
||||
foo = fimg_decomp_rgbz_color(&src, &dst, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s:%s(): fail %d line %d\n",
|
||||
__FILE__, __func__, foo, __LINE__);
|
||||
return foo;
|
||||
}
|
||||
|
||||
foo = fimg_export_picture(&dst, outf, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
fimg_destroy(&src); fimg_destroy(&dst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
int fimg_recursion_proto(FloatImg *src, FloatImg *dst, int notused);
|
||||
|
@ -72,7 +304,7 @@ fimg_clone(&src, &dst, 0);
|
|||
/* run the crappy code */
|
||||
foo = fimg_mirror(&src, &dst, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d in fimg_mirrot\n", foo);
|
||||
fprintf(stderr, "err %d in fimg_mirror\n", foo);
|
||||
return -6;
|
||||
}
|
||||
|
||||
|
@ -82,6 +314,72 @@ if (foo) {
|
|||
return foo;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* new Sun Feb 12 10:34:06 CET 2023
|
||||
*/
|
||||
int essai_rndfluffy(char *infile, char *outfile, int k)
|
||||
{
|
||||
int foo;
|
||||
FloatImg src, dst;
|
||||
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__,
|
||||
infile, outfile, k);
|
||||
|
||||
foo = fimg_create_from_dump(infile, &src);
|
||||
if (0 != foo) {
|
||||
fprintf(stderr, "%s: err %d loading image '%s'\n", __func__,
|
||||
foo, infile);
|
||||
return foo;
|
||||
}
|
||||
fprintf(stderr, " %s loaded.\n", infile);
|
||||
|
||||
fimg_clone(&src, &dst, 0);
|
||||
fprintf(stderr, " %p cloned.\n", &src);
|
||||
|
||||
foo = fimg_make_rndfluffy_lines(&src, &dst, 80);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d while making fluffy\n", foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
foo = fimg_export_picture(&dst, outfile, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err %d exporting %s\n", __func__, foo, outfile);
|
||||
return foo;
|
||||
}
|
||||
fimg_destroy(&src); fimg_destroy(&dst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int essai_split_level(char *inf, char *outf, int flags)
|
||||
{
|
||||
int foo;
|
||||
FloatImg src, dst;
|
||||
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' 0x%X )\n", __func__,
|
||||
inf, outf, flags);
|
||||
|
||||
foo = fimg_create_from_dump(inf, &src);
|
||||
if (0 != foo) {
|
||||
fprintf(stderr, "%s: err %d loading image '%s'\n", __func__,
|
||||
foo, inf);
|
||||
return foo;
|
||||
}
|
||||
fimg_clone(&src, &dst, 0);
|
||||
foo = fimg_split_level(&src, &dst, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err %d in split_level\n", foo);
|
||||
return -6;
|
||||
}
|
||||
foo = fimg_export_picture(&dst, outf, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
@ -571,6 +869,10 @@ int essai_geometrie(char *infile, int notused)
|
|||
FloatImg fimg, result;
|
||||
int foo;
|
||||
|
||||
if (0 != notused) {
|
||||
fprintf(stderr, "in %s, k must be 0, was %d\n", __func__, notused);
|
||||
}
|
||||
|
||||
if (NULL != infile) {
|
||||
fprintf(stderr, "loading %s\n", infile);
|
||||
foo = fimg_create_from_dump(infile, &fimg);
|
||||
|
@ -709,13 +1011,17 @@ int essai_mire(char *outname, int notused)
|
|||
FloatImg fimg;
|
||||
int re, foo;
|
||||
|
||||
if (0 != notused) {
|
||||
fprintf(stderr, "in %s, k must be 0, was %d\n", __func__, notused);
|
||||
}
|
||||
|
||||
fimg_create(&fimg, 1280, 960, FIMG_TYPE_RGB);
|
||||
|
||||
re = fimg_test_pattern(&fimg, 9, 1.0);
|
||||
if (re) {
|
||||
fprintf(stderr, "fimg_test_pattern -> %d\n", re);
|
||||
}
|
||||
foo = fimg_export_picture(&fimg, "mire.pnm", 0);
|
||||
foo = fimg_export_picture(&fimg, outname, 0);
|
||||
fprintf(stderr, "in %s, export give a %d value\n", __func__, foo);
|
||||
|
||||
return 0;
|
||||
|
@ -798,7 +1104,7 @@ return 0;
|
|||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
int fimg_essai_hsv(char *fname); /* hsv.c */
|
||||
int fimg_essai_hsv(char *fname); /* hsv.c */
|
||||
|
||||
|
||||
int essai_histogramme(char *fname, int k)
|
||||
|
@ -827,4 +1133,43 @@ fprintf(stderr, "\\o/ end of %s\n", __func__);
|
|||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/*
|
||||
* dans la roulotte de terreblanque
|
||||
*/
|
||||
int essai_pixelize(char *infile, char *outfile)
|
||||
{
|
||||
FloatImg src, dst;
|
||||
int foo;
|
||||
|
||||
fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, infile, outfile);
|
||||
|
||||
memset(&src, 0, sizeof(FloatImg));
|
||||
foo = fimg_create_from_dump(infile, &src);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: err load '%s'\n", __func__, infile);
|
||||
return foo;
|
||||
}
|
||||
|
||||
memset(&dst, 0, sizeof(FloatImg));
|
||||
foo = fimg_clone(&src, &dst, 0);
|
||||
if (foo) return -888;
|
||||
|
||||
foo = fimg_pixelize_h_0(&src, &dst, 8);
|
||||
if (foo) {
|
||||
fprintf(stderr, "in %s, pixelize give us a %d\n", __func__, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
foo = fimg_export_picture(&dst, outfile, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s : err %d saving result to %s\n", __func__,
|
||||
foo, outfile);
|
||||
return foo;
|
||||
}
|
||||
|
||||
fimg_destroy(&src);
|
||||
fimg_destroy(&dst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
|
|
@ -5,6 +5,11 @@
|
|||
|
||||
int essai_plasma(char *infile, char *outfile, int ikoef, float fkoef);
|
||||
int essai_miroir(char *inf, char *outf, int flags);
|
||||
int essai_killrgb(char *inf, char *outf);
|
||||
int essai_decomprgb_color(char *inf, char *outf);
|
||||
int essai_decomprgb_gray(char *inf, char *outf);
|
||||
int essai_rndfluffy(char *infile, char *outfile, int k); /* sfx3.c */
|
||||
int essai_split_level(char *inf, char *outf, int flags);
|
||||
|
||||
int essai_displacement(char *infile, char *outfile);
|
||||
int essai_qsort_rgb(char *infile, char *outfile);
|
||||
|
@ -24,9 +29,16 @@ int essai_geometrie(char *infile, int notused);
|
|||
int essai_detect_type(void);
|
||||
int fimg_essai_histo(FloatImg *src, char *outpic, int k); /* histogram.c */
|
||||
int essai_histogramme(char *fname, int k);
|
||||
int essai_0_fausses_couleurs(char *dstfile, int type);
|
||||
|
||||
int essai_lecture_png(char *fname, char *outfile, int notused);
|
||||
|
||||
int essai_highlights(char *inf, char *outf, int ikoef, float fkoef);
|
||||
int essai_openexr(char *inf, char *outf, int flags);
|
||||
int essai_fmorpho_0(char *infile, char *basefname, int k);
|
||||
|
||||
int essai_pixelize(char *infile, char *outfile);
|
||||
|
||||
int essai_rectangle(char *outf, int k);
|
||||
|
||||
int essai_dicom(char *inf, char *outf, int k);
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
|
@ -19,6 +21,30 @@ fprintf(stderr, "green\t\t%10f %10f\n", minmax[2], minmax[3]);
|
|||
fprintf(stderr, "blue\t\t%10f %10f\n", minmax[4], minmax[5]);
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* used in fimg-fits & fimg-dicom */
|
||||
float *charplane2int(char plane, FloatImg *img)
|
||||
{
|
||||
float *pplane = NULL;
|
||||
|
||||
fprintf(stderr, "get plane for '%c' in %p ", plane, img);
|
||||
|
||||
switch (plane) {
|
||||
case 'r': case 'R':
|
||||
pplane = img->R; break;
|
||||
case 'g': case 'G':
|
||||
pplane = img->G; break;
|
||||
case 'b': case 'B':
|
||||
pplane = img->B; break;
|
||||
|
||||
default:
|
||||
pplane = NULL;
|
||||
}
|
||||
|
||||
fprintf(stderr, "give me %p\n", pplane);
|
||||
|
||||
return pplane;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int parse_WxH(char *str, int *pw, int *ph)
|
||||
{
|
||||
// char *ptr;
|
||||
|
@ -52,6 +78,12 @@ if (1 == foo) {
|
|||
return -1;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* new Mon 11 Oct 2021 08:28:27 PM CEST */
|
||||
int irand2(int offset, int modulo)
|
||||
{
|
||||
return offset + (rand() % modulo);
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int file_type_from_name(char *name)
|
||||
{
|
||||
|
||||
|
@ -59,14 +91,16 @@ int file_type_from_name(char *name)
|
|||
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, name);
|
||||
#endif
|
||||
|
||||
if (!strcasecmp(name, "pnm" )) return FILE_TYPE_PNM;
|
||||
if (!strcasecmp(name, "fimg")) return FILE_TYPE_FIMG;
|
||||
if (!strcasecmp(name, "tga" )) return FILE_TYPE_TGA;
|
||||
if (!strcasecmp(name, "png" )) return FILE_TYPE_PNG;
|
||||
if (!strcasecmp(name, "tiff")) return FILE_TYPE_TIFF;
|
||||
if (!strcasecmp(name, "tif" )) return FILE_TYPE_TIFF;
|
||||
if (!strcasecmp(name, "fits")) return FILE_TYPE_FITS;
|
||||
if (!strcasecmp(name, "exr")) return FILE_TYPE_EXR;
|
||||
if (!strcasecmp(name, "pnm" )) return FILE_TYPE_PNM;
|
||||
if (!strcasecmp(name, "fimg")) return FILE_TYPE_FIMG;
|
||||
if (!strcasecmp(name, "tga" )) return FILE_TYPE_TGA;
|
||||
if (!strcasecmp(name, "png" )) return FILE_TYPE_PNG;
|
||||
if (!strcasecmp(name, "tiff")) return FILE_TYPE_TIFF;
|
||||
if (!strcasecmp(name, "tif" )) return FILE_TYPE_TIFF;
|
||||
if (!strcasecmp(name, "fits")) return FILE_TYPE_FITS;
|
||||
if (!strcasecmp(name, "exr")) return FILE_TYPE_EXR;
|
||||
if (!strcasecmp(name, "dicom")) return FILE_TYPE_EXR;
|
||||
if (!strcasecmp(name, "pgm" )) return FILE_TYPE_PGM;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -74,7 +108,13 @@ return -1;
|
|||
/* --------------------------------------------------------------------- */
|
||||
int print_rectangle(char *str, FimgArea51 *rect)
|
||||
{
|
||||
printf("rect @ %p '%s':\n\t %dx%d at %d,%d\n", rect, str,
|
||||
if (MAGIC_AREA51 != rect->magic) {
|
||||
fprintf(stderr, "%s: bad magic number 0x%08X\n", __func__,
|
||||
rect->magic);
|
||||
return -666;
|
||||
}
|
||||
|
||||
printf("rect @ %p '%s' :\n\t %dx%d at %d,%d\n", rect, str,
|
||||
rect->w, rect->h, rect->x, rect->y);
|
||||
return 0;
|
||||
}
|
||||
|
@ -86,17 +126,28 @@ int parse_rectangle(char *str, FimgArea51 *r, int notused)
|
|||
{
|
||||
int x, y, w, h, foo;
|
||||
|
||||
if (verbosity)
|
||||
fprintf(stderr, "parsing %s\n", str);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %s %p %d )\n", __func__, str, r, notused);
|
||||
#endif
|
||||
|
||||
if (notused) {
|
||||
fprintf(stderr, "notused was %d, must be 0 in %s\n",
|
||||
notused, __func__);
|
||||
}
|
||||
|
||||
if (verbosity > 1) fprintf(stderr, "%s: parsing '%s'\n", __func__, str);
|
||||
|
||||
foo = sscanf(str, "%d,%d,%d,%d", &w, &h, &x, &y);
|
||||
if (4 == foo) {
|
||||
r->x = x, r->y = y, r->w = w, r->h = h;
|
||||
r->magic = MAGIC_AREA51;
|
||||
return 4;
|
||||
}
|
||||
|
||||
r->magic = 0xBAD;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int format_from_extension(char *fname)
|
||||
{
|
||||
|
|
|
@ -8,6 +8,8 @@ cp tools/mkfimg tools/fimg2pnm tools/fimgops \
|
|||
tools/png2fimg tools/fimgstats tools/fimgfx \
|
||||
tools/cumulfimgs tools/fimg2text \
|
||||
tools/fimghalfsize \
|
||||
tools/fimgmetadata tools/fimgfilters \
|
||||
tools/fimgextract \
|
||||
/usr/local/bin
|
||||
|
||||
cp v4l2/grabvidseq v4l2/video-infos \
|
||||
|
|
11
lib/Makefile
11
lib/Makefile
|
@ -2,11 +2,12 @@
|
|||
# building the base library
|
||||
#
|
||||
|
||||
COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0
|
||||
COPT = -Wall -Wextra -fpic -g -no-pie -DDEBUG_LEVEL=0
|
||||
|
||||
OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \
|
||||
fimg-timers.o operators.o fimg-2gray.o \
|
||||
interpolate.o fimg-compare.o contrast.o
|
||||
interpolate.o fimg-compare.o contrast.o \
|
||||
metadata.o alphachan.o
|
||||
|
||||
DEPS = Makefile ../floatimg.h
|
||||
|
||||
|
@ -23,6 +24,9 @@ t: t.c ../libfloatimg.a $(DEPS)
|
|||
../libfloatimg.a: $(OBJS)
|
||||
$(AR) r $@ $?
|
||||
|
||||
alphachan.o: alphachan.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
fimg-core.o: fimg-core.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
|
@ -35,6 +39,9 @@ fimg-2gray.o: fimg-2gray.c $(DEPS)
|
|||
operators.o: operators.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
metadata.o: metadata.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
contrast.o: contrast.c $(DEPS)
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
# Fimg tools
|
||||
|
||||
Need more explanations...
|
||||
|
||||
|
||||
|
||||
## Converting to/from rgb or gray
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* alphachan.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
extern int verbosity; /* must be declared around main() */
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
int fimg_add_alpha_chan(FloatImg *img)
|
||||
{
|
||||
|
||||
fprintf(stderr, ">>> %s ( %p )\n", __func__, img);
|
||||
|
||||
return -4;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
int fimg_kill_alpha_chan(FloatImg *img)
|
||||
{
|
||||
|
||||
fprintf(stderr, ">>> %s ( %p )\n", __func__, img);
|
||||
|
||||
return -4;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
|
@ -1,9 +1,14 @@
|
|||
/*
|
||||
* contrast.c - part of libfloatimg
|
||||
* --------------------------------
|
||||
*
|
||||
* you can see some use in 'tools/fimgfx.c', so you can thing
|
||||
* about the 'maxval' parameter. It was touchy :)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
@ -21,6 +26,11 @@ if (!strcmp(str, "sqrt")) return CONTRAST_SQRT;
|
|||
if (!strcmp(str, "pow2")) return CONTRAST_POW2;
|
||||
if (!strcmp(str, "cos01")) return CONTRAST_COS01;
|
||||
if (!strcmp(str, "cos010")) return CONTRAST_COS010;
|
||||
if (!strcmp(str, "xper")) return CONTRAST_XPER;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s: unknow contrast name '%s'\n", __func__, str);
|
||||
#endif
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -34,7 +44,7 @@ int nbre, idx;
|
|||
double dval;
|
||||
|
||||
if (s->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s : type %d invalide\n",
|
||||
fprintf(stderr, "%s: type %d invalide\n",
|
||||
__func__, s->type);
|
||||
return -4;
|
||||
}
|
||||
|
@ -42,13 +52,12 @@ if (s->type != FIMG_TYPE_RGB) {
|
|||
if (NULL==d) { d = s; }
|
||||
else {
|
||||
if (d->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s : dst type %d invalide\n",
|
||||
fprintf(stderr, "%s: dst type %d invalide\n",
|
||||
__func__, d->type);
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nbre = s->width * s->height;
|
||||
|
||||
for (idx=0; idx<nbre; idx++) {
|
||||
|
@ -83,7 +92,6 @@ else {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
nbre = s->width * s->height;
|
||||
|
||||
for (idx=0; idx<nbre; idx++) {
|
||||
|
@ -97,7 +105,6 @@ for (idx=0; idx<nbre; idx++) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
#macro Cos_01( X )
|
||||
|
@ -109,16 +116,20 @@ int fimg_cos_01(FloatImg *s, FloatImg *d, double maxval)
|
|||
int nbre, idx;
|
||||
double dval;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %g )\n", __func__, s, d, maxval);
|
||||
#endif
|
||||
|
||||
if (s->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s : type %d invalide\n",
|
||||
fprintf(stderr, "%s: type %d invalide\n",
|
||||
__func__, s->type);
|
||||
return -4;
|
||||
}
|
||||
|
||||
if (NULL==d) { d = s; }
|
||||
if (NULL==d) { d = s; } /* In place */
|
||||
else {
|
||||
if (d->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s : dst type %d invalide\n",
|
||||
fprintf(stderr, "%s: dst type %d invalide\n",
|
||||
__func__, d->type);
|
||||
return -4;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
/*
|
||||
* fimg-2gray.c
|
||||
*
|
||||
* This is a tricky job...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include "string.h"
|
||||
|
||||
|
@ -20,7 +23,14 @@ int fimg_mk_gray_from(FloatImg *src, FloatImg *dst, int k)
|
|||
float kr, kg, kb, kdiv;
|
||||
int nbb, foo;
|
||||
|
||||
kr = kg = kb = 1.0; /* canonic random values */
|
||||
if (k) {
|
||||
/* some random funky values ... */
|
||||
kr = 0.789; kg = 0.523; kb = 0.349;
|
||||
}
|
||||
else {
|
||||
/* ... and canonic random values */
|
||||
kr = kg = kb = 1.0;
|
||||
}
|
||||
kdiv = kr + kg + kb;
|
||||
|
||||
/* we must check the validity of our parameters */
|
||||
|
@ -58,6 +68,10 @@ int fimg_desaturate(FloatImg *src, FloatImg *dst, int notused)
|
|||
int foo, nbb;
|
||||
|
||||
/* we must check the validity of our parameters */
|
||||
if (notused) {
|
||||
fprintf(stderr, "notused was %d, must be 0 in %s\n",
|
||||
notused, __func__);
|
||||
}
|
||||
if (FIMG_TYPE_RGB != src->type || FIMG_TYPE_RGB != dst->type) {
|
||||
fprintf(stderr, "%s : bad image type\n", __func__);
|
||||
return -18;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include "string.h"
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include "string.h"
|
||||
|
||||
|
@ -38,8 +39,8 @@ return "???";
|
|||
/* --------------------------------------------------------------------- */
|
||||
int fimg_print_version(int k)
|
||||
{
|
||||
fprintf(stderr, "*** FloatImg library, alpha %d (%s, %s)\n",
|
||||
FIMG_VERSION, __DATE__, __TIME__);
|
||||
fprintf(stderr, "*** FloatImg library, v%d '%s' (%s, %s)\n",
|
||||
FIMG_VERSION, RELEASE_NAME, __DATE__, __TIME__);
|
||||
|
||||
if (51 == k) {
|
||||
puts("+------------------------+");
|
||||
|
@ -54,6 +55,7 @@ void fimg_print_sizeof(void)
|
|||
{
|
||||
fprintf(stderr, " sz FloatImg = %lu\n", sizeof(FloatImg));
|
||||
fprintf(stderr, " sz filehead = %lu\n", sizeof(FimgFileHead));
|
||||
fprintf(stderr, " sz metadata = %lu\n", sizeof(FimgMetaData));
|
||||
fprintf(stderr, " sz filter = %lu\n", sizeof(FimgFilter3x3));
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
|
154
lib/fimg-file.c
154
lib/fimg-file.c
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
@ -45,6 +46,11 @@ if (memcmp(filehead.magic, "FIMG", 4)) {
|
|||
return -3;
|
||||
}
|
||||
|
||||
/* XXX preparer la gestion des metadata */
|
||||
if ('a' == filehead.magic[4] && verbosity > 1) {
|
||||
fprintf(stderr,"*** %s have metadata\n", fname);
|
||||
}
|
||||
|
||||
datas[0] = filehead.w;
|
||||
datas[1] = filehead.h;
|
||||
datas[2] = filehead.t;
|
||||
|
@ -53,7 +59,103 @@ return 0;
|
|||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
* /!\ thi func work ONLY on RGB image
|
||||
* new avril 2022 : trying to save metadatas...
|
||||
*/
|
||||
int fimg_dumpmd_to_file(FloatImg *fimg, char *fname, \
|
||||
FimgMetaData *pmd, int notused)
|
||||
{
|
||||
FILE *fp;
|
||||
int foo, nbre;
|
||||
FimgFileHead filehead;
|
||||
FimgMetaData fakemd;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p '%s' %p %d )\n", __func__, fimg,
|
||||
fname, pmd, notused);
|
||||
#endif
|
||||
|
||||
if (notused) {
|
||||
fprintf(stderr, "%s: notused must be 0, was %d\n", \
|
||||
__func__, notused);
|
||||
}
|
||||
|
||||
if (FIMG_TYPE_RGB != fimg->type) {
|
||||
fprintf(stderr, "%s : bad type %d\n", __func__, fimg->type);
|
||||
return -8;
|
||||
}
|
||||
|
||||
/* OK, we have to make a fake metadata chunk, if the caller
|
||||
* don't have one. Ugly, and nice */
|
||||
if (NULL == pmd) {
|
||||
fprintf(stderr, ">>> %s making faked metadata\n", __func__);
|
||||
foo = fimg_default_metadata(&fakemd, 3);
|
||||
fprintf(stderr, "fakemd is at %p\n", &fakemd);
|
||||
pmd = &fakemd;
|
||||
}
|
||||
else {
|
||||
/* OK, get some funky metadatas */
|
||||
// fprintf(stderr, "%s get metadatas\n", __func__);
|
||||
fprintf(stderr, "acqu fval=%f count=%d\n", pmd->fval, pmd->count);
|
||||
}
|
||||
|
||||
fp = fopen(fname, "w");
|
||||
if (NULL==fp) {
|
||||
perror(fname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&filehead, 0, sizeof(filehead));
|
||||
memcpy(filehead.magic, "FIMG", 4);
|
||||
filehead.w = fimg->width; filehead.h = fimg->height;
|
||||
filehead.t = fimg->type;
|
||||
|
||||
/* XXX metadata */
|
||||
if (NULL != pmd) {
|
||||
// fprintf(stderr, "ok, %s give an 'a' flag\n", __func__);
|
||||
filehead.magic[4] = 'a';
|
||||
}
|
||||
|
||||
foo = fwrite(&filehead, sizeof(FimgFileHead), 1, fp);
|
||||
if (1 != foo) {
|
||||
perror(fname);
|
||||
fclose(fp);
|
||||
/* may be here, we can remove the broken file ? */
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* we have metadata, put them on tape */
|
||||
if (NULL != pmd) {
|
||||
// fprintf(stderr, ">>> %s write metadata %p\n", __func__, pmd);
|
||||
foo = fwrite(pmd, sizeof(FimgMetaData), 1, fp);
|
||||
if (1 != foo) {
|
||||
perror(fname);
|
||||
fclose(fp);
|
||||
/* may be here, we can remove the broken file ? */
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
nbre = fimg->width * fimg->height; /* pixels per frame */
|
||||
foo = fwrite(fimg->R, sizeof(float), nbre, fp);
|
||||
if (nbre != foo) {
|
||||
perror(fname); fclose(fp); return -3;
|
||||
}
|
||||
foo = fwrite(fimg->G, sizeof(float), nbre, fp);
|
||||
if (nbre != foo) {
|
||||
perror(fname); fclose(fp); return -3;
|
||||
}
|
||||
foo = fwrite(fimg->B, sizeof(float), nbre, fp);
|
||||
if (nbre != foo) {
|
||||
perror(fname); fclose(fp); return -3;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
* /!\ this func work ONLY on RGB image
|
||||
*/
|
||||
int fimg_dump_to_file(FloatImg *fimg, char *fname, int notused)
|
||||
{
|
||||
|
@ -66,16 +168,27 @@ fprintf(stderr, ">>> %-25s ( %p '%s' %d )\n", __func__, fimg,
|
|||
fname, notused);
|
||||
#endif
|
||||
|
||||
if (3 != fimg->type) {
|
||||
if (notused) {
|
||||
fprintf(stderr, "%s: notused must be 0, was %d\n", \
|
||||
__func__, notused);
|
||||
}
|
||||
|
||||
if (FIMG_TYPE_RGB != fimg->type) {
|
||||
fprintf(stderr, "%s : bad type %d\n", __func__, fimg->type);
|
||||
return -8;
|
||||
}
|
||||
|
||||
// fprintf(stderr, "'%s' try to open '%s'\n", __func__, fname);
|
||||
fp = fopen(fname, "w");
|
||||
if (NULL==fp) {
|
||||
// fprintf(stderr, " fp at %p\n", fp);
|
||||
|
||||
if (NULL == fp) {
|
||||
perror(fname);
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
// fprintf(stderr, "file '%s' opened\n", fname);
|
||||
}
|
||||
|
||||
memset(&filehead, 0, sizeof(filehead));
|
||||
memcpy(filehead.magic, "FIMG", 4);
|
||||
|
@ -88,6 +201,9 @@ if (1 != foo) {
|
|||
fclose(fp);
|
||||
return -2;
|
||||
}
|
||||
// fprintf(stderr, "'%s' write header --> %d\n", __func__, foo);
|
||||
|
||||
|
||||
nbre = fimg->width * fimg->height; /* pixels per frame */
|
||||
|
||||
foo = fwrite(fimg->R, sizeof(float), nbre, fp);
|
||||
|
@ -142,6 +258,18 @@ if ( (filehead.w != where->width) ||
|
|||
return -17;
|
||||
}
|
||||
|
||||
/* XXX preparer la gestion des metadata */
|
||||
if ('a' == filehead.magic[4]) {
|
||||
if (verbosity > 1) fprintf(stderr,"%s say %s have metadata\n",
|
||||
__func__, fname);
|
||||
foo = fseek(fp, (long)sizeof(FimgMetaData), SEEK_CUR);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: seek error\n", __func__);
|
||||
perror(fname);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
nbre = filehead.w * filehead.h; /* number of pixels per frame */
|
||||
foo = fread(where->R, sizeof(float), nbre, fp);
|
||||
if (nbre != foo) {
|
||||
|
@ -178,7 +306,8 @@ fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, fname, head);
|
|||
|
||||
/*
|
||||
* may be we can crash coredump here if the head
|
||||
* descriptor is not blank ?
|
||||
* descriptor from caller is not blank ? Or just
|
||||
* display a warning ?
|
||||
*/
|
||||
|
||||
fp = fopen(fname, "r");
|
||||
|
@ -205,6 +334,23 @@ if (foo) {
|
|||
return foo;
|
||||
}
|
||||
|
||||
/* bugfix Sat 14 May 2022 07:02:53 PM CEST */
|
||||
/*
|
||||
* Oh boy, we have to skeep the metadata chunck
|
||||
*/
|
||||
if ('a' == filehead.magic[4]) {
|
||||
if (verbosity > 1)
|
||||
{ fprintf(stderr, "in %s, %s has metadata\n", __func__, fname); }
|
||||
/* old school processing...
|
||||
foo = fseek(fp, (long)sizeof(FimgMetaData), SEEK_CUR);
|
||||
*/
|
||||
foo = fread(&head->mdatas, sizeof(FimgMetaData), 1, fp);
|
||||
if (1 != foo) {
|
||||
fprintf(stderr, "%s: shit hit the fan %d\n", __func__, foo);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
size = filehead.w * filehead.h;
|
||||
nbread = 0;
|
||||
nbread += fread(head->R, sizeof(float), size, fp);
|
||||
|
|
126
lib/fimg-math.c
126
lib/fimg-math.c
|
@ -1,11 +1,12 @@
|
|||
/*
|
||||
* fimg-core.c
|
||||
* fimg-math.c
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <float.h> /* for FLT_MAX */
|
||||
|
@ -15,6 +16,41 @@
|
|||
|
||||
extern int verbosity; /* must be declared around main() */
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* nouveau 27 fevrier 2022 */
|
||||
float fimg_get_plane_maxvalue(FloatImg *psrc, char plane)
|
||||
{
|
||||
float *ptrplane;
|
||||
float maxval;
|
||||
int area, foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p '%c' )\n", __func__, psrc, plane);
|
||||
#endif
|
||||
|
||||
switch (plane) {
|
||||
case 'r': case 'R':
|
||||
ptrplane = psrc->R; break;
|
||||
case 'g': case 'G':
|
||||
ptrplane = psrc->G; break;
|
||||
case 'b': case 'B':
|
||||
ptrplane = psrc->B; break;
|
||||
case 'a': case 'A':
|
||||
ptrplane = psrc->A; break;
|
||||
default:
|
||||
fprintf(stderr, "%s: plane error\n", __func__);
|
||||
abort(); break;
|
||||
}
|
||||
|
||||
area = psrc->width * psrc->height;
|
||||
maxval = 0.0;
|
||||
|
||||
for (foo=0; foo<area; foo++) {
|
||||
if (ptrplane[foo] > maxval) maxval = ptrplane[foo];
|
||||
}
|
||||
|
||||
return maxval;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
float fimg_get_maxvalue(FloatImg *head)
|
||||
{
|
||||
|
@ -38,10 +74,12 @@ switch (head->type) {
|
|||
if (head->G[foo] > maxval) maxval = head->G[foo];
|
||||
if (head->B[foo] > maxval) maxval = head->B[foo];
|
||||
}
|
||||
break;
|
||||
case FIMG_TYPE_GRAY:
|
||||
for (foo=0; foo<surface; foo++) {
|
||||
if (head->R[foo] > maxval) maxval = head->R[foo];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return maxval;
|
||||
|
@ -78,7 +116,37 @@ for (idx=0; idx<surface; idx++) {
|
|||
else if (fval > mmvals[5]) mmvals[5] = fval;
|
||||
}
|
||||
|
||||
return -0;
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* new: Fri Oct 6 19:51:28 UTC 2023
|
||||
*
|
||||
* can compute the maxima of a lot of pictures...
|
||||
*/
|
||||
|
||||
int fimg_max_of_max(FloatImg *img, float maxes[3])
|
||||
{
|
||||
float localmax[3];
|
||||
int idx, surface;
|
||||
float fval;
|
||||
|
||||
localmax[0] = localmax[1] = localmax[2] = -1e9;
|
||||
|
||||
surface = img->width * img->height;
|
||||
for (idx=0; idx<surface; idx++) {
|
||||
fval = img->R[idx];
|
||||
if (fval > localmax[0]) localmax[0] = fval;
|
||||
fval = img->G[idx];
|
||||
if (fval > localmax[1]) localmax[1] = fval;
|
||||
fval = img->B[idx];
|
||||
if (fval > localmax[2]) localmax[2] = fval;
|
||||
}
|
||||
|
||||
if (localmax[0] > maxes[0]) maxes[0] = localmax[0];
|
||||
if (localmax[1] > maxes[1]) maxes[1] = localmax[1];
|
||||
if (localmax[2] > maxes[2]) maxes[2] = localmax[2];
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
int fimg_meanvalues(FloatImg *head, float means[4])
|
||||
|
@ -106,7 +174,7 @@ for (idx=0; idx<4; idx++) {
|
|||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* d'après Wikipedia Fr :
|
||||
/* d'apres Wikipedia Fr :
|
||||
| c = 0
|
||||
| s = x1
|
||||
| pour j de 2 à n
|
||||
|
@ -258,6 +326,33 @@ if (fi->type == FIMG_TYPE_GRAY) {
|
|||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* nouveau 17 septembre 2022 */
|
||||
int fimg_div_cste(FloatImg *fi, float value)
|
||||
{
|
||||
int nbre, idx;
|
||||
|
||||
if ( (fi->type != FIMG_TYPE_RGB) && (fi->type != FIMG_TYPE_GRAY) ) {
|
||||
fprintf(stderr, "%s : type %d invalide\n",
|
||||
__func__, fi->type);
|
||||
return -44;
|
||||
}
|
||||
|
||||
nbre = fi->width * fi->height;
|
||||
if (fi->type == FIMG_TYPE_RGB) {
|
||||
for (idx=0; idx<nbre; idx++) {
|
||||
fi->R[idx] /= value;
|
||||
fi->G[idx] /= value;
|
||||
fi->B[idx] /= value;
|
||||
}
|
||||
}
|
||||
if (fi->type == FIMG_TYPE_GRAY) {
|
||||
for (idx=0; idx<nbre; idx++) {
|
||||
fi->R[idx] /= value;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
* oh, please explain the usecase of this function !
|
||||
*/
|
||||
|
@ -265,6 +360,11 @@ int fimg_ajust_from_grab(FloatImg *fi, double maxima, int notused)
|
|||
{
|
||||
double coef;
|
||||
|
||||
if (notused) {
|
||||
fprintf(stderr, "notused was %d, must be 0 in %s\n",
|
||||
notused, __func__);
|
||||
}
|
||||
|
||||
if (fi->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s : type %d invalide\n",
|
||||
__func__, fi->type);
|
||||
|
@ -286,6 +386,7 @@ if (verbosity) {
|
|||
fprintf(stderr, "image @ %p\n", fi);
|
||||
fprintf(stderr, "fval %f\n", fi->fval);
|
||||
fprintf(stderr, "count %d\n", fi->count);
|
||||
fprintf(stderr, "maxima %f\n", maxima);
|
||||
fprintf(stderr, "coef %f\n", coef);
|
||||
}
|
||||
|
||||
|
@ -294,6 +395,22 @@ fimg_mul_cste(fi, coef);
|
|||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
int fimg_absolute(FloatImg *fi)
|
||||
{
|
||||
int surface, idx;
|
||||
|
||||
surface = fi->width * fi->height;
|
||||
|
||||
for (idx=0; idx<surface; idx++) {
|
||||
fi->R[idx] = fabsf(fi->R[idx]);
|
||||
fi->G[idx] = fabsf(fi->G[idx]);
|
||||
fi->B[idx] = fabsf(fi->B[idx]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
/* Warning: this function is _very_ slow */
|
||||
void fimg_drand48(FloatImg *fi, float kmul)
|
||||
{
|
||||
|
@ -309,6 +426,9 @@ if (fi->type != FIMG_TYPE_RGB) {
|
|||
return;
|
||||
}
|
||||
nbre = fi->width * fi->height;
|
||||
|
||||
fprintf(stderr, "in %s, drand48() is %f\n", __func__, drand48());
|
||||
|
||||
for (idx=0; idx<nbre; idx++) {
|
||||
fi->R[idx] = drand48() * kmul;
|
||||
fi->G[idx] = drand48() * kmul;
|
||||
|
|
138
lib/fimg-pnm.c
138
lib/fimg-pnm.c
|
@ -1,14 +1,15 @@
|
|||
/*
|
||||
* fimg-pnm.c
|
||||
*
|
||||
*
|
||||
* crude version who make HUGE ascii files !
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "string.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
|
@ -22,9 +23,14 @@ int fimg_load_from_pnm(char *fname, FloatImg *head, int notused)
|
|||
FILE *fp;
|
||||
int width, height, maxval;
|
||||
int foo, line, column;
|
||||
unsigned char *buffline, *idxrd, dummychar;
|
||||
unsigned char *buffline, *idxrd;
|
||||
float *Rptr, *Gptr, *Bptr;
|
||||
|
||||
if (notused) {
|
||||
fprintf(stderr, "notused was %d, must be 0 in %s\n",
|
||||
notused, __func__);
|
||||
}
|
||||
|
||||
if (NULL==head) {
|
||||
fprintf(stderr, "%s : head ptr is %p\n", __func__, head);
|
||||
return -8;
|
||||
|
@ -57,6 +63,7 @@ if (foo) {
|
|||
}
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
unsigned char dummychar;
|
||||
fread(&dummychar, 1, 1, fp);
|
||||
fprintf(stderr, "%s : dummychar %xx\n", __func__, dummychar);
|
||||
#else
|
||||
|
@ -82,6 +89,10 @@ return 0;
|
|||
}
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
* this func write the content of the R channel, the
|
||||
* only one used by graylevel images
|
||||
*/
|
||||
static void dump_gray_values(FILE *fp, FloatImg *picz, float fk)
|
||||
{
|
||||
int cnt, sz, value;
|
||||
|
@ -111,7 +122,7 @@ int Rv, Gv, Bv;
|
|||
cnt = 0;
|
||||
sz = picz->width * picz->height;
|
||||
for (idx=0; idx<sz; idx++) {
|
||||
if (fk > 0) {
|
||||
if (fk > 0) { /* why ? */
|
||||
Rv = (int)(picz->R[idx] / fk);
|
||||
Gv = (int)(picz->G[idx] / fk);
|
||||
Bv = (int)(picz->B[idx] / fk);
|
||||
|
@ -195,3 +206,122 @@ fputs("\n", fp); fclose(fp);
|
|||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* nouveau 27 fevrier 2022 */
|
||||
/* WARNING ! UGLY CODE INSIDE */
|
||||
int fimg_save_plane_as_pgm(FloatImg *psrc, char *fname, char plane)
|
||||
{
|
||||
FILE *fp;
|
||||
float maxval, fk, *ptrplane;
|
||||
int area, idx, printed;
|
||||
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %s '%c' )\n", __func__, psrc, fname, plane);
|
||||
#endif
|
||||
|
||||
switch (plane) {
|
||||
case 'r': case 'R':
|
||||
ptrplane = psrc->R; break;
|
||||
case 'g': case 'G':
|
||||
ptrplane = psrc->G; break;
|
||||
case 'b': case 'B':
|
||||
ptrplane = psrc->B; break;
|
||||
case 'a': case 'A':
|
||||
ptrplane = psrc->A; break;
|
||||
default:
|
||||
fprintf(stderr, "%s: bad plane '%c'\n", __func__, plane);
|
||||
abort(); break;
|
||||
}
|
||||
|
||||
if (NULL == ptrplane) { /* mmmm... */
|
||||
fprintf(stderr, "%s: mmmm...\n", __func__);
|
||||
return -3;
|
||||
}
|
||||
|
||||
if (NULL==(fp=fopen(fname, "w"))) {
|
||||
perror(fname);
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* WARNING !
|
||||
* some software (yes, povray, I look at you) doesn't like
|
||||
* width and height on two separate lines.
|
||||
*/
|
||||
fprintf(fp, "P2\n%d %d\n65535\n\n", psrc->width, psrc->height);
|
||||
|
||||
area = psrc->width * psrc->height;
|
||||
maxval = fimg_get_plane_maxvalue(psrc, plane);
|
||||
fk = maxval / 65535.0;
|
||||
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "%s: maxval of plane '%c' = %f\n", __func__,
|
||||
plane, maxval);
|
||||
}
|
||||
|
||||
printed = 0;
|
||||
for (idx=0; idx<area; idx++) {
|
||||
printed += fprintf(fp, "%d ", (int)(ptrplane[idx]/fk));
|
||||
if (printed > 72) {
|
||||
fputs("\n", fp);
|
||||
printed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* nouveau 10 fevrier 2022 */
|
||||
int fimg_save_as_pgm(FloatImg *src, char *fname, int flags)
|
||||
{
|
||||
FILE *fp;
|
||||
float maximum, fk;
|
||||
int area, idx, printed;
|
||||
float accu;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %s %d )\n", __func__, src, fname, flags);
|
||||
#endif
|
||||
|
||||
if (flags) {
|
||||
fprintf(stderr, "%s: flags must be 0\n", __func__);
|
||||
}
|
||||
|
||||
if ( src->type != FIMG_TYPE_RGB ) {
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%s : type %d is bad.\n", __func__, src->type);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (NULL==(fp=fopen(fname, "w"))) {
|
||||
perror(fname);
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* WARNING !
|
||||
* some software (yes, povray, I look at you) doesn't like
|
||||
* width and height on two separate lines.
|
||||
*/
|
||||
fprintf(fp, "P2\n%d %d\n65535\n\n", src->width, src->height);
|
||||
|
||||
area = src->width * src->height;
|
||||
maximum = fimg_get_maxvalue(src);
|
||||
fk = maximum / 65535.0;
|
||||
|
||||
printed = 0;
|
||||
for (idx=0; idx<area; idx++) {
|
||||
accu = (src->R[idx] + src->G[idx] + src->B[idx]) / 3.0;
|
||||
printed += fprintf(fp, "%d ", (int)(accu/fk));
|
||||
if (printed > 72) {
|
||||
fputs("\n", fp);
|
||||
printed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ double fimg_timer_set(int whot)
|
|||
{
|
||||
double current;
|
||||
|
||||
if (whot) fprintf(stderr, "in %s whot is %d\n", __func__, whot);
|
||||
|
||||
current = dtime();
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
|
@ -36,6 +38,9 @@ return memory_time;
|
|||
double fimg_timer_get(int whot)
|
||||
{
|
||||
double current;
|
||||
|
||||
if (whot) fprintf(stderr, "in %s whot is %d\n", __func__, whot);
|
||||
|
||||
current = dtime();
|
||||
return current - memory_time;
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue