| 24 |
|
extern const char BIGEND[]; |
| 25 |
|
extern const char FMTSTR[]; |
| 26 |
|
|
| 27 |
– |
int contrib = 0; // computing contributions? |
| 28 |
– |
|
| 29 |
– |
int xres = 0; // horizontal (scan) size |
| 30 |
– |
int yres = 0; // vertical resolution |
| 31 |
– |
|
| 27 |
|
// new/exclusive, overwrite if exists, or recover data |
| 28 |
|
int RSDOflags[] = {RDSwrite|RDSexcl|RDSextend, RDSwrite|RDSextend, |
| 29 |
|
RDSread|RDSwrite}; |
| 52 |
|
uint32 ac; // accumulation count |
| 53 |
|
}; |
| 54 |
|
|
| 55 |
+ |
// Get format identifier |
| 56 |
+ |
const char * |
| 57 |
+ |
formstr(int f) |
| 58 |
+ |
{ |
| 59 |
+ |
switch (f) { |
| 60 |
+ |
case 'a': return("ascii"); |
| 61 |
+ |
case 'f': return("float"); |
| 62 |
+ |
case 'd': return("double"); |
| 63 |
+ |
case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT); |
| 64 |
+ |
} |
| 65 |
+ |
return("unknown"); |
| 66 |
+ |
} |
| 67 |
+ |
|
| 68 |
|
// Our default data share function |
| 69 |
|
RdataShare * |
| 70 |
|
defDataShare(const char *name, RCOutputOp op, size_t siz) |
| 76 |
|
RcontribMod * |
| 77 |
|
NewRcMod(const char *prms, const char *binexpr, int ncbins) |
| 78 |
|
{ |
| 71 |
– |
if (ncbins <= 0) return NULL; |
| 79 |
|
if (!prms) prms = ""; |
| 80 |
|
if (!binexpr & (ncbins > 1)) { |
| 81 |
< |
error(INTERNAL, "missing bin expression"); |
| 81 |
> |
error(USER, "missing bin expression"); |
| 82 |
|
return NULL; |
| 83 |
|
} |
| 84 |
< |
if (ncbins == 1) { // shouldn't have bin expression? |
| 84 |
> |
if (ncbins <= 1) { // shouldn't have bin expression? |
| 85 |
|
if (binexpr && strcmp(binexpr, "0")) |
| 86 |
|
error(WARNING, "ignoring non-zero expression for single bin"); |
| 87 |
|
prms = ""; |
| 88 |
|
binexpr = NULL; |
| 89 |
+ |
ncbins = 1; |
| 90 |
|
} |
| 91 |
|
RcontribMod * mp = (RcontribMod *)ecalloc(1, sizeof(RcontribMod) + |
| 92 |
|
sizeof(DCOLORV)*(NCSAMP*ncbins-1) + |
| 171 |
|
} |
| 172 |
|
SCOLOR contr; |
| 173 |
|
raycontrib(contr, r, PRIMARY); // compute coefficient |
| 174 |
< |
if (contrib) |
| 174 |
> |
if (rcp->HasFlag(RCcontrib)) |
| 175 |
|
smultscolor(contr, r->rcol); // -> value contribution |
| 176 |
|
for (int i = 0; i < NCSAMP; i++) |
| 177 |
|
*dvp++ += contr[i]; // accumulate color/spectrum |
| 201 |
|
RcontribSimulManager::AddModifier(const char *modn, const char *outspec, |
| 202 |
|
const char *prms, const char *binval, int bincnt) |
| 203 |
|
{ |
| 204 |
< |
if (!modn | !outspec | (bincnt <= 0) || !*modn | !*outspec) { |
| 204 |
> |
if (!modn | !outspec || !*modn | !*outspec) { |
| 205 |
|
error(WARNING, "ignoring bad call to AddModifier()"); |
| 206 |
|
return false; |
| 207 |
|
} |
| 208 |
|
if (!nChan) { // initial call? |
| 209 |
+ |
if ((xres < 0) | (yres <= 0)) { |
| 210 |
+ |
error(USER, "xres, yres must be set before first modifier"); |
| 211 |
+ |
return false; |
| 212 |
+ |
} |
| 213 |
|
if (!SetDataFormat(dtyp)) |
| 214 |
|
return false; |
| 215 |
|
nChan = NCSAMP; |
| 216 |
|
} else if (nChan != NCSAMP) { |
| 217 |
< |
error(INTERNAL, "number of spectral channels must be fixed"); |
| 217 |
> |
error(USER, "number of spectral channels must be fixed"); |
| 218 |
|
return false; |
| 219 |
|
} |
| 220 |
|
if (Ready()) { |
| 237 |
|
const int binndx = hasFormat(outspec, "diouxX"); |
| 238 |
|
int bin0 = 0; |
| 239 |
|
char fnbuf[512]; |
| 240 |
< |
if (!modndx | (modndx > binndx)) |
| 240 |
> |
if (!modndx || (binndx > 0) & (modndx > binndx)) |
| 241 |
|
sprintf(fnbuf, outspec, bin0, modn); |
| 242 |
|
else |
| 243 |
|
sprintf(fnbuf, outspec, modn, bin0); |
| 266 |
|
mp->opl = op; // first (maybe only) output channel |
| 267 |
|
if (modndx) // remember modifier if part of name |
| 268 |
|
op->omod = lp->key; |
| 269 |
< |
if (binndx > 0) { // append output image/bin list |
| 269 |
> |
if (binndx) { // append output image/bin list |
| 270 |
|
op->rowBytes += dsiz; |
| 271 |
|
op->obin = bin0; |
| 272 |
|
for (bincnt = 1; bincnt < mp->nbins; bincnt++) { |
| 273 |
< |
if (!modndx | (modndx > binndx)) |
| 273 |
> |
if (!modndx || (binndx > 0) & (modndx > binndx)) |
| 274 |
|
sprintf(fnbuf, outspec, bin0+bincnt, modn); |
| 275 |
|
else |
| 276 |
|
sprintf(fnbuf, outspec, modn, bin0+bincnt); |
| 289 |
|
op->rowBytes += dsiz; |
| 290 |
|
} |
| 291 |
|
} else // else send all results to this channel |
| 292 |
< |
op->rowBytes += bincnt*dsiz; |
| 292 |
> |
op->rowBytes += mp->nbins*dsiz; |
| 293 |
|
return true; |
| 294 |
|
} |
| 295 |
|
|
| 404 |
|
strcpy(hdr+begData, ROWZEROSTR); |
| 405 |
|
rowCountPos = begData+LNROWSTR; |
| 406 |
|
begData += sizeof(ROWZEROSTR)-1; |
| 407 |
< |
if (!xres | (rowBytes > esiz)) { |
| 407 |
> |
if (!rcp->xres | (rowBytes > esiz)) { |
| 408 |
|
sprintf(hdr+begData, "NCOLS=%d\n", int(rowBytes/esiz)); |
| 409 |
|
begData += strlen(hdr+begData); |
| 410 |
|
} |
| 442 |
|
hdr[begData++] = ' '; |
| 443 |
|
hdr[begData++] = '\n'; // EOL for data format |
| 444 |
|
hdr[begData++] = '\n'; // end of nominal header |
| 445 |
< |
if ((xres > 0) & (rowBytes == esiz)) { // tack on resolution string? |
| 446 |
< |
sprintf(hdr+begData, PIXSTDFMT, yres, xres); |
| 445 |
> |
if ((rcp->xres > 0) & (rowBytes == esiz)) { // tack on resolution string? |
| 446 |
> |
sprintf(hdr+begData, PIXSTDFMT, rcp->yres, rcp->xres); |
| 447 |
|
begData += strlen(hdr+begData); |
| 448 |
|
} |
| 449 |
|
return rData->ReleaseMemory(hdr, RDSwrite); |
| 497 |
|
} |
| 498 |
|
// check #columns |
| 499 |
|
if (((cp = findArgs(hdr, "NCOLS=", begData)) && atoi(cp)*esiz != rowBytes) || |
| 500 |
< |
!xres | (rowBytes > esiz)) { |
| 500 |
> |
!rcp->xres | (rowBytes > esiz)) { |
| 501 |
|
sprintf(errmsg, "expected NCOLS=%d in '%s'", |
| 502 |
|
int(rowBytes/esiz), GetName()); |
| 503 |
|
error(USER, errmsg); |
| 512 |
|
rowCountPos = cp - hdr; |
| 513 |
|
int rlast = atoi(cp); |
| 514 |
|
begData++; // advance past closing EOL |
| 515 |
< |
if ((xres > 0) & (rowBytes == esiz)) { // check/skip resolution string? |
| 515 |
> |
if ((rcp->xres > 0) & (rowBytes == esiz)) { // check/skip resolution string? |
| 516 |
|
char rbuf[64]; |
| 517 |
< |
sprintf(rbuf, PIXSTDFMT, yres, xres); |
| 517 |
> |
sprintf(rbuf, PIXSTDFMT, rcp->yres, rcp->xres); |
| 518 |
|
int rlen = strlen(rbuf); |
| 519 |
|
if (strncmp(rbuf, hdr+begData, rlen)) { |
| 520 |
|
sprintf(errmsg, "bad resolution string in '%s'", GetName()); |