From b0fe0091d496a162e9053af8a11fc125e04c3a5c Mon Sep 17 00:00:00 2001 From: tth Date: Tue, 17 Sep 2019 11:22:00 +0200 Subject: [PATCH] another scaling computation... --- floatimg.h | 2 +- lib/fimg-pnm.c | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/floatimg.h b/floatimg.h index 13a9fdb..afb0829 100644 --- a/floatimg.h +++ b/floatimg.h @@ -58,7 +58,7 @@ int fimg_sub(FloatImg *a, FloatImg *b, FloatImg *d); int fimg_mul(FloatImg *a, FloatImg *b, FloatImg *d); /* PNM files module */ -int fimg_save_as_pnm(FloatImg *head, char *fname, int notused); +int fimg_save_as_pnm(FloatImg *head, char *fname, int flags); int fimg_load_from_pnm(char *fname, FloatImg *head, int notused); double fimg_timer_set(int whot); diff --git a/lib/fimg-pnm.c b/lib/fimg-pnm.c index 80db3e6..5af3f63 100644 --- a/lib/fimg-pnm.c +++ b/lib/fimg-pnm.c @@ -131,17 +131,17 @@ fputs("\n", fp); } /* ---------------------------------------------------------------- */ /* - * + * bit 0 of flags : use fvalue/count */ -int fimg_save_as_pnm(FloatImg *head, char *fname, int notused) +int fimg_save_as_pnm(FloatImg *head, char *fname, int flags) { FILE *fp; float maximum, fk; char *code; #if DEBUG_LEVEL -fprintf(stderr, ">>> %-25s ( %p '%s' %d )\n", __func__, head, - fname, notused); +fprintf(stderr, ">>> %-25s ( %p '%s' 0x%04x )\n", __func__, head, + fname, flags); #endif if ( head->type != FIMG_TYPE_RGB && head->type != FIMG_TYPE_GRAY) { @@ -163,10 +163,18 @@ switch(head->type) { fprintf(fp, "%s\n%d %d\n", code, head->width, head->height); -maximum = fimg_get_maxvalue(head); -fprintf(fp, "# maxval %15f\n", maximum); -fk = maximum / 65535.0; -fprintf(fp, "# divisor %15f\n", fk); +if ( flags & 1 ) { + fprintf(stderr, "%s using fval/count %f %d -> %f\n", __func__, + head->fval, head->count, + head->fval * head->count); + fk = (head->fval * head->count) / 65535.0; + } +else { + maximum = fimg_get_maxvalue(head); + fk = maximum / 65535.0; + fprintf(fp, "# maxval %15f\n# divisor %15f\n", maximum, fk); + } + fprintf(fp, "65535\n"); fflush(fp);