--- ray/src/common/depthcodec.c 2021/01/26 18:47:25 2.11 +++ ray/src/common/depthcodec.c 2025/06/07 05:09:45 2.14 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: depthcodec.c,v 2.11 2021/01/26 18:47:25 greg Exp $"; +static const char RCSid[] = "$Id: depthcodec.c,v 2.14 2025/06/07 05:09:45 greg Exp $"; #endif /* * Routines to encode/decoded 16-bit depths @@ -7,9 +7,9 @@ static const char RCSid[] = "$Id: depthcodec.c,v 2.11 #include "copyright.h" -#include #include #include +#include "paths.h" #include "rtio.h" #include "fvect.h" #include "depthcodec.h" @@ -80,7 +80,25 @@ headline(char *s, void *p) dcp->swapped = (nativebigendian() != rv); return 0; } - /* check for reference depth */ + if (!strncmp(s, "NCOMP=", 6)) { + if (atoi(s+6) != 1) { + if (dcp->hdrflags & HF_STDERR) { + fputs(dcp->inpname, stderr); + fputs(": NCOMP must equal 1\n", stderr); + } + return -1; + } + return 0; + } + if (!strncmp(s, "NROWS=", 6)) { + dcp->res.yr = atoi(s+6); + return 0; + } + if (!strncmp(s, "NCOLS=", 6)) { + dcp->res.xr = atoi(s+6); + return 0; + } + /* check for reference depth */ if (!strncmp(s, DEPTHSTR, LDEPTHSTR)) { char *cp; strlcpy(dcp->depth_unit, s+LDEPTHSTR, sizeof(dcp->depth_unit)); @@ -122,6 +140,16 @@ process_dc_header(DEPTHCODEC *dcp, int ac, char *av[]) return 0; } dcp->gotview *= (dcp->gotview > 0); + /* get resolution string? */ + if (dcp->hdrflags & HF_RESIN && + (dcp->res.xr <= 0) | (dcp->res.yr <= 0) && + !fgetsresolu(&dcp->res, dcp->finp)) { + if (dcp->hdrflags & HF_STDERR) { + fputs(dcp->inpname, stderr); + fputs(": bad resolution string\n", stderr); + } + return 0; + } if (dcp->hdrflags & HF_HEADOUT) { /* finish header */ if (!(dcp->hdrflags & HF_HEADIN)) newheader("RADIANCE", stdout); @@ -132,7 +160,12 @@ process_dc_header(DEPTHCODEC *dcp, int ac, char *av[]) fputs(dcp->depth_unit, stdout); fputc('\n', stdout); fputformat(DEPTH16FMT, stdout); - } else + } else { + fputs("NCOMP=1\n", stdout); + if ((dcp->hdrflags & (HF_RESIN|HF_RESOUT)) == HF_RESIN) + printf("NCOLS=%d\nNROWS=%d\n", + scanlen(&dcp->res), + numscans(&dcp->res)); switch (dcp->format) { case 'a': fputformat("ascii", stdout); @@ -146,17 +179,10 @@ process_dc_header(DEPTHCODEC *dcp, int ac, char *av[]) fputformat("double", stdout); break; } + } fputc('\n', stdout); } - /* get/put resolution string */ - if (dcp->hdrflags & HF_RESIN && !fgetsresolu(&dcp->res, dcp->finp)) { - if (dcp->hdrflags & HF_STDERR) { - fputs(dcp->inpname, stderr); - fputs(": bad resolution string\n", stderr); - } - return 0; - } - if (dcp->hdrflags & HF_RESOUT) + if (dcp->hdrflags & HF_RESOUT) /* put resolution string? */ fputsresolu(&dcp->res, stdout); dcp->dstart = dcp->curpos = ftell(dcp->finp);