Compare commits

..

2 Commits

Author SHA1 Message Date
tth
6ffc08188d work on the real PGM export 2022-02-09 23:21:58 +01:00
tth
0da81df892 oups... 2022-02-09 22:59:58 +01:00
10 changed files with 87 additions and 13 deletions

1
.gitignore vendored
View File

@ -12,6 +12,7 @@ gmon.out
*.swp *.swp
*.pnm *.pnm
*.pgm
*.fimg *.fimg
essai essai
MANIFEST MANIFEST

View File

@ -4,7 +4,7 @@
* http://la.buvette.org/photos/cumul * http://la.buvette.org/photos/cumul
*/ */
#define FIMG_VERSION 167 #define FIMG_VERSION 169
/* /*
* in memory descriptor * in memory descriptor
@ -54,6 +54,7 @@ typedef struct {
#define FILE_TYPE_BMP 7 #define FILE_TYPE_BMP 7
#define FILE_TYPE_EXR 8 #define FILE_TYPE_EXR 8
#define FILE_TYPE_DICOM 9 #define FILE_TYPE_DICOM 9
#define FILE_TYPE_PGM 10
/* lib/contrast.c */ /* lib/contrast.c */
#define CONTRAST_NONE 0 #define CONTRAST_NONE 0
@ -151,6 +152,7 @@ int fimg_export_picture(FloatImg *pic, char *fname, int flags);
/* PNM files module */ /* PNM files module */
int fimg_save_as_pnm(FloatImg *head, char *fname, int flags); 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_load_from_pnm(char *fname, FloatImg *head, int notused);
double fimg_timer_set(int whot); double fimg_timer_set(int whot);

View File

@ -59,6 +59,10 @@ switch(filetype) {
fprintf(stderr, "%s: file type EXR experimental\n", __func__); fprintf(stderr, "%s: file type EXR experimental\n", __func__);
foo = fimg_save_as_exr(pic, fname, 0); foo = fimg_save_as_exr(pic, fname, 0);
break; break;
case FILE_TYPE_PGM:
fprintf(stderr, "XXX %s EXPERIMENT!\n", __func__);
foo = fimg_save_as_pgm(pic, fname, 0);
break;
default: default:
foo = -1789; foo = -1789;
break; break;

View File

@ -100,6 +100,7 @@ if (!strcasecmp(name, "tif" )) return FILE_TYPE_TIFF;
if (!strcasecmp(name, "fits")) return FILE_TYPE_FITS; if (!strcasecmp(name, "fits")) return FILE_TYPE_FITS;
if (!strcasecmp(name, "exr")) return FILE_TYPE_EXR; if (!strcasecmp(name, "exr")) return FILE_TYPE_EXR;
if (!strcasecmp(name, "dicom")) return FILE_TYPE_EXR; if (!strcasecmp(name, "dicom")) return FILE_TYPE_EXR;
if (!strcasecmp(name, "pgm" )) return FILE_TYPE_PGM;
return -1; return -1;
} }

View File

@ -196,3 +196,51 @@ fputs("\n", fp); fclose(fp);
return 0; 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 ( 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;
}
fprintf(fp, "P2\n%d\n%d\n65532\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;
}

18
lib/t.c
View File

@ -83,12 +83,13 @@ return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
int essai_2gray(FloatImg *picz, char *outname) int essai_2gray(FloatImg *picz, char *basename)
{ {
int foo; int foo;
FloatImg gray; FloatImg gray;
char outname[200];
fprintf(stderr, ">>> %s ( %p '%s' )\n", __func__, picz, outname); fprintf(stderr, ">>> %s ( %p '%s' )\n", __func__, picz, basename);
foo = fimg_create(&gray, picz->width, picz->height, FIMG_TYPE_GRAY); foo = fimg_create(&gray, picz->width, picz->height, FIMG_TYPE_GRAY);
if (foo) { if (foo) {
@ -101,9 +102,16 @@ if (foo) {
exit(1); exit(1);
} }
strcpy(outname,basename); strcat(outname, ".pnm");
foo = fimg_save_as_pnm(&gray, outname, 0); foo = fimg_save_as_pnm(&gray, outname, 0);
if (foo) { if (foo) {
fprintf(stderr, "%s : err %d on save_as_pnm\n", __func__, foo); fprintf(stderr, "%s : err %d on save_as_PNM\n", __func__, foo);
exit(1);
}
strcpy(outname,basename); strcat(outname, ".pgm");
foo = fimg_save_as_pgm(&gray, outname, 0);
if (foo) {
fprintf(stderr, "%s : err %d on save_as_PGM\n", __func__, foo);
exit(1); exit(1);
} }
@ -261,8 +269,8 @@ if (verbosity) {
fimg_print_sizeof(); fimg_print_sizeof();
} }
foo = essai_contraste("quux.fimg"); foo = essai_2gray(NULL, "quux");
fprintf(stderr, "retour essai contraste -> %d\n", foo); fprintf(stderr, "retour essai -> %d\n", foo);
// foo = essai_clone_et_copy(0); // foo = essai_clone_et_copy(0);
// fprintf(stderr, "retour essai clone'n'copy -> %d\n", foo); // fprintf(stderr, "retour essai clone'n'copy -> %d\n", foo);

View File

@ -43,7 +43,7 @@ puts("\t-v\tincrease verbosity");
puts("\t-o\tname of output file"); puts("\t-o\tname of output file");
puts("\t-g\tconvert to gray level"); puts("\t-g\tconvert to gray level");
puts(""); puts("");
if (verbosity) { puts(""); fimg_print_version(1); } if (verbosity) { puts("Xperiment"); fimg_print_version(1); }
exit(0); exit(0);
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
@ -54,6 +54,7 @@ int opt;
int compte = 0; int compte = 0;
int to_gray = 0; int to_gray = 0;
int experiment = 0;
char *output_file = "out.fimg"; char *output_file = "out.fimg";
FloatImg accu, temp; FloatImg accu, temp;
int src_loaded = 0; int src_loaded = 0;
@ -61,12 +62,13 @@ float vals[6];
g_width = g_height = 0; g_width = g_height = 0;
while ((opt = getopt(argc, argv, "gho:v")) != -1) { while ((opt = getopt(argc, argv, "gho:vx")) != -1) {
switch(opt) { switch(opt) {
case 'g': to_gray = 1; break; case 'g': to_gray = 1; break;
case 'h': help(0); break; case 'h': help(0); break;
case 'o': output_file = optarg; break; case 'o': output_file = optarg; break;
case 'v': verbosity++; break; case 'v': verbosity++; break;
case 'x': experiment++; break;
} }
} }
@ -101,6 +103,13 @@ for (idx=optind; idx<argc; idx++) {
compte++; compte++;
} }
/* XXX */
if (experiment) {
}
/* XXX */
if (to_gray) { if (to_gray) {
foo = fimg_desaturate(&accu, &accu, 0); foo = fimg_desaturate(&accu, &accu, 0);
if (foo) { if (foo) {
@ -108,7 +117,8 @@ if (to_gray) {
} }
} }
// XXX foo = fimg_dump_to_file(&accu, output_file, 0); /* PLEASE CHECK IF EXPORT TO GRAY MAKE A REAL .pgm FILE */
foo = fimg_export_picture(&accu, output_file, 0); foo = fimg_export_picture(&accu, output_file, 0);
if (foo) { if (foo) {
fprintf(stderr, "error %d while saving '%s'\n", foo, output_file); fprintf(stderr, "error %d while saving '%s'\n", foo, output_file);

View File

@ -19,7 +19,7 @@ FloatImg fimg;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %25s ( '%s' '%s' %d )\n", __func__, fprintf(stderr, ">>> %25s ( '%s' '%s' %d )\n", __func__,
srcname, dstname, notused); srcname, dstname, grisaille);
#endif #endif
foo = fimg_fileinfos(srcname, infos); foo = fimg_fileinfos(srcname, infos);

View File

@ -87,8 +87,8 @@ int foo, infos[3];
FloatImg fimg; FloatImg fimg;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %25s ( '%s' '%s' %d )\n", __func__, fprintf(stderr, ">>> %25s ( '%s' '%s' %d %f )\n", __func__,
srcname, dstname, notused); srcname, dstname, steps, norm);
#endif #endif
if (steps < 1) { if (steps < 1) {

View File

@ -19,7 +19,7 @@ FloatImg fimg;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %25s ( '%s' '%s' %d )\n", __func__, fprintf(stderr, ">>> %25s ( '%s' '%s' %d )\n", __func__,
srcname, dstname, notused); srcname, dstname, grisaille);
#endif #endif
foo = fimg_fileinfos(srcname, infos); foo = fimg_fileinfos(srcname, infos);