big cleanup, word on metadata

This commit is contained in:
tTh
2022-07-06 10:27:55 +02:00
parent aa2ced081a
commit c7a51ec7a0
49 changed files with 348 additions and 105 deletions

View File

@@ -8,13 +8,19 @@ __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

View File

@@ -15,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;
@@ -26,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;

View File

@@ -23,15 +23,14 @@ extern int verbosity;
/* 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)
@@ -45,8 +44,9 @@ fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
psrc, pdst, k);
#endif
fimg_clear(pdst);
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++)
@@ -102,8 +102,9 @@ fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
psrc, pdst, k);
#endif
fimg_clear(pdst);
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++)

View File

@@ -17,6 +17,12 @@ 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__); }
for (y=0; y<psrc->height; y++) {
for (x=0; x<psrc->width; x++)

View File

@@ -32,6 +32,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];
@@ -45,7 +47,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;
}

View File

@@ -25,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);

View File

@@ -1,11 +1,15 @@
/*
* 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"
/* -------------------------------------------------------------- */
@@ -13,27 +17,67 @@
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;
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
for (y=0; y<src->height, y++) {
for (x=0; x<src->width, x++) {
if (k) {
fprintf(stderr, "%s : %d %f\n", __func__, k, valf);
}
/***********************/
/* DO SOMETHING HERE ! */
/***********************/
/* 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 -1;
return 0;
}
/* -------------------------------------------------------------- */

View File

@@ -16,7 +16,7 @@ extern int verbosity;
int fimg_show_filter(char *title, FimgFilter3x3 *filtr)
{
float *M; /* alias of filter matrix */
int foo, idx;
int idx;
float sum, value;
if (title) fprintf(stderr, "--------- %s ---------\n", title);

View File

@@ -17,12 +17,12 @@ extern int verbosity; /* must be declared around main() */
int fimg_save_plane_as_dicom(FloatImg *src, char *outname,
char plane, int flags)
{
int foo;
float *planeptr;
fprintf(stderr, ">>> %s ( %p %s %c %d )\n", __func__, src, outname, plane, flags);
planeptr = charplane2int(plane, src);
planeptr = charplane2int(plane, src); /* please explain XXX */
fprintf(stderr, "planeptr is %p\n", planeptr);
if (verbosity) {
fimg_describe(src, outname);

View File

@@ -32,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) {

View File

@@ -14,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);
@@ -24,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);
}
/* --------------------------------------------------------------------- */

View File

@@ -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) {

View File

@@ -27,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);
@@ -65,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");
@@ -108,7 +112,6 @@ return 0;
/* --------------------------------------------------------------------- */
int fimg_extractor(FloatImg *in, FloatImg *out, FimgArea51 *rect)
{
int foo;
int xs, ys, xd, yd;
int count;
float rgb[3];
@@ -149,6 +152,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;

View File

@@ -85,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;
}
@@ -131,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) {

View File

@@ -20,9 +20,10 @@ static int check_boundaries(FloatImg *from, FloatImg *to, FimgArea51 *a51)
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, from, to, a51);
#endif
fimg_printdims("from", from);
fimg_printdims("to ", to);
#endif
/* just a small molly-guard */
if ( (a51->w < 0) || (a51->h < 0) ) {
@@ -30,13 +31,13 @@ if ( (a51->w < 0) || (a51->h < 0) ) {
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);
@@ -44,6 +45,7 @@ fprintf(stderr, ">>> %s ( %p %p %p 0x%04x )\n", __func__,
return -1;
}
*/
/* ---------------------------------------------------------------- */
int fimg_incrustator_0(FloatImg *psrc, FloatImg *pdst,
int xpos, int ypos, int flags)
@@ -58,6 +60,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");
@@ -67,6 +71,10 @@ 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) ) {

View File

@@ -20,12 +20,12 @@ int line, col;
int ir;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
src, dst, k);
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, src, dst, k);
#endif
fimg_clear(dst);
if (k) { fprintf(stderr, "in %s k was %d\n", __func__, k); }
fimg_clear(dst);
ir = 0;
for (line=0; line<src->height; line++) {

View File

@@ -26,6 +26,10 @@ if (fimg->type != FIMG_TYPE_RGB) {
return -6;
}
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++) {

View File

@@ -58,8 +58,8 @@ return 0;
/* -------------------------------------------------------------- */
/*
* un essai dans la roulotte :)
* 11 oct 2021 : premier jet, essai concluant, mais nécessite
* du travail sur les rand() pour être plus 'noisy'
* 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)
@@ -68,6 +68,8 @@ 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);
@@ -87,7 +89,7 @@ if (verbosity) {
fprintf(stderr, "%s: count=%d flag=%d\n", __func__, count, flag);
}
foo = fimg_pixelize_h_0(psrc, pdst, flag ? 8 : 32);
foo = fimg_pixelize_h_0(psrc, pdst, flag ? largeur : 32);
if (foo) {
fprintf(stderr, "PANIC in %s\n", __func__);
abort();
@@ -97,6 +99,4 @@ count--; /* nice trick bro */
return 0;
}
/* -------------------------------------------------------------- */

View File

@@ -31,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;

View File

@@ -28,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;
@@ -78,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;

View File

@@ -25,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);

View File

@@ -26,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];
@@ -50,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];

View File

@@ -25,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;
@@ -54,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

View File

@@ -28,9 +28,15 @@ 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: halfval=%f\n", __func__, halfval);
fprintf(stderr, "%s: kval=%f & halfval=%f\n", __func__,
kval, halfval);
}
for (y=0; y<src->height; y++) {

View File

@@ -25,6 +25,11 @@ float in[3], out[3];
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);
@@ -48,13 +53,18 @@ return 0;
int fimg_split_level(FloatImg *src, FloatImg *dst, int notused)
{
float means[4];
float in[3];
// 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;

View File

@@ -30,12 +30,14 @@ 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);
foo = fimg_export_picture(&dst, dstfile, 0);
return -1;
}
/* --------------------------------------------------------------------- */

View File

@@ -120,6 +120,11 @@ int parse_rectangle(char *str, FimgArea51 *r, int notused)
{
int x, y, w, h, foo;
if (notused) {
fprintf(stderr, "notused was %d, must be 0 in %s\n",
notused, __func__);
}
if (verbosity)
fprintf(stderr, "parsing %s\n", str);