From 6e896ee4631168d291d86c8982c3e96b90843c2a Mon Sep 17 00:00:00 2001 From: tth Date: Sat, 27 Nov 2021 00:01:37 +0100 Subject: [PATCH] dicom boilerplate: [done] --- floatimg.h | 8 +++++++- funcs/Makefile | 4 ++++ funcs/fimg-dicom.c | 32 ++++++++++++++++++++++++++++++++ funcs/t.c | 6 +++++- funcs/tests.c | 17 +++++++++++++++++ funcs/tests.h | 2 ++ funcs/utils.c | 41 +++++++++++++++++++++++++++++++++-------- 7 files changed, 100 insertions(+), 10 deletions(-) diff --git a/floatimg.h b/floatimg.h index e3bf0d5..8847238 100644 --- a/floatimg.h +++ b/floatimg.h @@ -4,7 +4,7 @@ * http://la.buvette.org/photos/cumul */ -#define FIMG_VERSION 161 +#define FIMG_VERSION 163 /* * in memory descriptor @@ -53,6 +53,7 @@ typedef struct { #define FILE_TYPE_FITS 6 #define FILE_TYPE_BMP 7 #define FILE_TYPE_EXR 8 +#define FILE_TYPE_DICOM 9 /* lib/contrast.c */ #define CONTRAST_NONE 0 @@ -142,6 +143,9 @@ 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); @@ -242,6 +246,8 @@ 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); diff --git a/funcs/Makefile b/funcs/Makefile index b2ec18f..400aa90 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -11,6 +11,7 @@ OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \ sfx0.o sfx1.o sfx2.o sfx3.o sfx4.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 \ killrgb.o recurse.o pixelize.o decomprgb.o @@ -70,6 +71,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 $< diff --git a/funcs/fimg-dicom.c b/funcs/fimg-dicom.c index e69de29..6afa07f 100644 --- a/funcs/fimg-dicom.c +++ b/funcs/fimg-dicom.c @@ -0,0 +1,32 @@ +/* + Digital Imaging and Communications in Medicine + + nouveau Fri 26 Nov 2021 11:12:44 PM CET - allée de Dinan + + */ + +#include +#include + +#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) +{ +int foo; +float *planeptr; + +fprintf(stderr, ">>> %s ( %p %s %c %d )\n", __func__, src, outname, plane, flags); + +planeptr = charplane2int(plane, src); + +if (verbosity) { + fimg_describe(src, outname); + } + +return -1; +} +/* --------------------------------------------------------------------- */ diff --git a/funcs/t.c b/funcs/t.c index eec87a3..2e84efd 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -25,7 +25,7 @@ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, Displace, ReadPNG, Plasmas, Hilight, OpenEXR, Geometrie, FileType, Mirror, KillRGB, Pixelize,SplitLevel, DecompRgbz, DecompRgbg, - Rectangle }; + Rectangle, Dicom }; typedef struct { char *name; int Cmd; @@ -59,6 +59,7 @@ Command commands[] = { { "decomprgbz", DecompRgbz }, { "decomprgbg", DecompRgbg }, { "rectangle", Rectangle }, + { "dicom", Dicom }, { NULL, 0 } } ; @@ -242,6 +243,9 @@ switch(opt) { case Rectangle: essai_rectangle(outfile, 0); break; + case Dicom: + foo = essai_dicom(filename, outfile, 0); + break; default: fprintf(stderr, "'%s' is a bad command\n", command); diff --git a/funcs/tests.c b/funcs/tests.c index 3ddf1da..df773f3 100644 --- a/funcs/tests.c +++ b/funcs/tests.c @@ -17,6 +17,23 @@ extern int verbosity; +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +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) { diff --git a/funcs/tests.h b/funcs/tests.h index ad4d10a..1033a1c 100644 --- a/funcs/tests.h +++ b/funcs/tests.h @@ -37,3 +37,5 @@ int essai_openexr(char *inf, char *outf, int flags); int essai_pixelize(char *infile, char *outfile); int essai_rectangle(char *outf, int k); + +int essai_dicom(char *inf, char *outf, int k); diff --git a/funcs/utils.c b/funcs/utils.c index 3fe60e4..62d639a 100644 --- a/funcs/utils.c +++ b/funcs/utils.c @@ -21,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; @@ -67,14 +91,15 @@ 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; return -1; }