int freadscan( /* read in a scanline */ COLOR *scanline, int len, FILE *fp ) { COLR *clrscan; if ((clrscan = (COLR *)tempbuffer(len*sizeof(COLR))) == NULL) return(-1); if (freadcolrs(clrscan, len, fp) < 0) return(-1); /* convert scanline */ colr_color(scanline[0], clrscan[0]); while (--len > 0) { scanline++; clrscan++; if (clrscan[0][GRN] == clrscan[-1][GRN] && (clrscan[0][RED] == clrscan[-1][RED]) & (clrscan[0][BLU] == clrscan[-1][BLU]) & (clrscan[0][EXP] == clrscan[-1][EXP])) copycolor(scanline[0], scanline[-1]); else colr_color(scanline[0], clrscan[0]); } return(0); }
/* Get ray contribution from previous file */ static int get_contrib(DCOLOR cnt, FILE *finp) { COLOR fv; COLR cv; switch (outfmt) { case 'a': return(fscanf(finp,"%lf %lf %lf",&cnt[0],&cnt[1],&cnt[2]) == 3); case 'f': if (fread(fv, sizeof(fv[0]), 3, finp) != 3) return(0); copycolor(cnt, fv); return(1); case 'd': return(fread(cnt, sizeof(cnt[0]), 3, finp) == 3); case 'c': if (fread(cv, sizeof(cv), 1, finp) != 1) return(0); colr_color(fv, cv); copycolor(cnt, fv); return(1); default: error(INTERNAL, "botched output format"); } return(0); /* pro forma return */ }
static void vips_rad2float_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width ) { COLR *inp = (COLR *) in[0]; COLOR *outbuf = (COLOR *) out; colr_color(outbuf[0], inp[0]); while (--width > 0) { outbuf++; inp++; if (inp[0][RED] == inp[-1][RED] && inp[0][GRN] == inp[-1][GRN] && inp[0][BLU] == inp[-1][BLU] && inp[0][EXP] == inp[-1][EXP]) copycolor(outbuf[0], outbuf[-1]); else colr_color(outbuf[0], inp[0]); } }
static void getpicture(void) /* load in picture colors */ { COLR *scanln; COLOR pval; int ccount[24]; double d; int y, i; register int x; scanln = (COLR *)malloc(xmax*sizeof(COLR)); if (scanln == NULL) { perror(progname); exit(1); } for (i = 0; i < 24; i++) { setcolor(inpRGB[i], 0., 0., 0.); ccount[i] = 0; } for (y = ymax-1; y >= 0; y--) { if (freadcolrs(scanln, xmax, stdin) < 0) { fprintf(stderr, "%s: error reading input picture\n", progname); exit(1); } for (x = 0; x < xmax; x++) if (chartndx(x, y, &i) == RG_CENT) { colr_color(pval, scanln[x]); addcolor(inpRGB[i], pval); ccount[i]++; } } for (i = 0; i < 24; i++) { /* compute averages */ if (ccount[i] == 0) continue; d = 1./ccount[i]; scalecolor(inpRGB[i], d); inpflags |= 1L<<i; } free((void *)scanln); }
void addpicz( /* add a picture + depth-buffer */ char *pcf, char *zbf ) { FILE *pfp; int zfd; COLR *cscn; float *zscn; struct phead phd; int eshft; double emult; RESOLU prs; RREAL vl[2]; FVECT ro, rd; double aftd; COLOR ctmp; int j; register int i; /* open files */ if ((pfp = fopen(pcf, "r")) == NULL) { sprintf(errmsg, "cannot open picture file \"%s\"", pcf); error(SYSTEM, pcf); } if ((zfd = open(zbf, O_RDONLY)) < 0) { sprintf(errmsg, "cannot open depth file \"%s\"", zbf); error(SYSTEM, pcf); } /* load picture header */ phd.vw = stdview; phd.expos = 1.0; phd.badfmt = phd.gotview = phd.altprims = 0; if (getheader(pfp, picheadline, &phd) < 0 || phd.badfmt || !fgetsresolu(&prs, pfp)) { sprintf(errmsg, "bad format for picture file \"%s\"", pcf); error(USER, errmsg); } if (!phd.gotview || setview(&phd.vw) != NULL) { sprintf(errmsg, "missing/illegal view in picture \"%s\"", pcf); error(USER, errmsg); } if (phd.altprims) { sprintf(errmsg, "ignoring primary values in picture \"%s\"", pcf); error(WARNING, errmsg); } /* figure out what to do about exposure */ if ((phd.expos < 0.99) | (phd.expos > 1.01)) { emult = -log(phd.expos)/log(2.); eshft = emult >= 0. ? emult+.5 : emult-.5; emult -= (double)eshft; if ((emult <= 0.01) & (emult >= -0.01)) emult = -1.; else { emult = 1./phd.expos; eshft = 0; } } else { emult = -1.; eshft = 0; } /* allocate buffers */ cscn = (COLR *)malloc(scanlen(&prs)*sizeof(COLR)); zscn = (float *)malloc(scanlen(&prs)*sizeof(float)); if ((cscn == NULL) | (zscn == NULL)) error(SYSTEM, "out of memory in addpicz"); /* read and process each scanline */ for (j = 0; j < numscans(&prs); j++) { i = scanlen(&prs); /* read colrs */ if (freadcolrs(cscn, i, pfp) < 0) { sprintf(errmsg, "error reading picture \"%s\"", pcf); error(USER, errmsg); } if (eshft) /* shift exposure */ shiftcolrs(cscn, i, eshft); i *= sizeof(float); /* read depth */ if (read(zfd, (char *)zscn, i) != i) { sprintf(errmsg, "error reading depth file \"%s\"", zbf); error(USER, errmsg); } for (i = scanlen(&prs); i--; ) { /* do each pixel */ pix2loc(vl, &prs, i, j); aftd = viewray(ro, rd, &phd.vw, vl[0], vl[1]); if (aftd < -FTINY) continue; /* off view */ if (aftd > FTINY && zscn[i] > aftd) continue; /* aft clipped */ if (emult > 0.) { /* whatta pain */ colr_color(ctmp, cscn[i]); scalecolor(ctmp, emult); setcolr(cscn[i], colval(ctmp,RED), colval(ctmp,GRN), colval(ctmp,BLU)); } addray(ro, rd, (double)zscn[i], cscn[i]); } } /* write output and free beams */ hdflush(NULL); /* clean up */ free((void *)cscn); free((void *)zscn); fclose(pfp); close(zfd); }