Esempio n. 1
0
extern COLOR *
nextscan(void)				/* read and condition next scanline */
{
	if (nread >= numscans(&inpres)) {
		if (cwarpfile != NULL)
			free3dw(cwarp);
		free((void *)scanbuf);
		return(scanbuf = NULL);
	}
	if (what2do&DO_ACUITY)
		acuscan(scanbuf, nread);
	else if (freadscan(scanbuf, scanlen(&inpres), infp) < 0) {
		fprintf(stderr, "%s: %s: scanline read error\n",
				progname, infn);
		exit(1);
	}
	if (what2do&DO_VEIL)			/* add veiling */
		addveil(scanbuf, nread);
	if (what2do&DO_COLOR)			/* scotopic color loss */
		scotscan(scanbuf, scanlen(&inpres));
	if (what2do&DO_LINEAR)			/* map luminances */
		sfscan(scanbuf, scanlen(&inpres), scalef);
	else
		mapscan(scanbuf, scanlen(&inpres));
	if (mbcalfile != NULL)			/* device color correction */
		mbscan(scanbuf, scanlen(&inpres), &mbcond);
	else if (cwarpfile != NULL)		/* device color space warp */
		cwscan(scanbuf, scanlen(&inpres), cwarp);
	else if ((lumf == cielum) | (inprims != outprims))
		matscan(scanbuf, scanlen(&inpres), mbcond.cmat);
	nread++;
	return(scanbuf);
}
Esempio n. 2
0
static void
valtopix(void)			/* convert values to a pixel file */
{
	int  dogamma;
	register COLOR	*scanln;
	int  y;
	register int  x;

	scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
	if (scanln == NULL) {
		fprintf(stderr, "%s: out of memory\n", progname);
		quit(1);
	}
	dogamma = gamcor < .95 || gamcor > 1.05;
	set_io();
	for (y = 0; y < numscans(&picres); y++) {
		for (x = 0; x < scanlen(&picres); x++) {
			if (!dataonly) {
				fscanf(fin, "%*d %*d");
				if (fin2 != NULL) {
					fscanf(fin2, "%*d %*d");
					fscanf(fin3, "%*d %*d");
				}
			}
			if ((*getval)(scanln[x]) < 0) {
				fprintf(stderr, "%s: read error\n", progname);
				quit(1);
			}
			if (dogamma)
				setcolor(scanln[x],
					pow(colval(scanln[x],RED), gamcor),
					pow(colval(scanln[x],GRN), gamcor),
					pow(colval(scanln[x],BLU), gamcor));
			if (doexposure)
				multcolor(scanln[x], exposure);
		}
		if (fwritescan(scanln, scanlen(&picres), stdout) < 0) {
			fprintf(stderr, "%s: write error\n", progname);
			quit(1);
		}
	}
	free((void *)scanln);
}
Esempio n. 3
0
static void
checkfile(void)			/* ready a file */
{
	register int	i;
					/* process header */
	gotview = 0;
	if (echoheader) {
		fputs(input[nfiles].name, stdout);
		fputs(":\n", stdout);
	}
	getheader(input[nfiles].fp, headline, NULL);
	if (wrongformat < 0) {
		eputs(input[nfiles].name);
		eputs(": not a Radiance picture\n");
		quit(1);
	}
	if (wrongformat > 0) {
		wputs(input[nfiles].name);
		wputs(": warning -- incompatible picture format\n");
	}
	if (!gotview || setview(&input[nfiles].vw) != NULL)
		input[nfiles].vw.type = 0;
	if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) {
		eputs(input[nfiles].name);
		eputs(": bad picture size\n");
		quit(1);
	}
	if (xmax == 0 && ymax == 0) {
		xmax = scanlen(&input[nfiles].rs);
		ymax = numscans(&input[nfiles].rs);
	} else if (scanlen(&input[nfiles].rs) != xmax ||
			numscans(&input[nfiles].rs) != ymax) {
		eputs(input[nfiles].name);
		eputs(": resolution mismatch\n");
		quit(1);
	}
					/* allocate scanlines */
	for (i = 0; i < WINSIZ; i++)
		input[nfiles].scan[i] = (COLOR *)emalloc(xmax*sizeof(COLOR));
}
Esempio n. 4
0
extern COLOR *
firstscan(void)				/* return first processed scanline */
{
	if (mbcalfile != NULL)		/* load macbethcal file */
		getmbcalfile(mbcalfile, &mbcond);
	else if (cwarpfile != NULL) {
		if ((cwarp = load3dw(cwarpfile, NULL)) == NULL)
			syserror(cwarpfile);
	} else
		if (lumf == rgblum)
			comprgb2rgbWBmat(mbcond.cmat, inprims, outprims);
		else
			compxyz2rgbWBmat(mbcond.cmat, outprims);
	if (what2do&DO_ACUITY)
		initacuity();
	scanbuf = (COLOR *)malloc(scanlen(&inpres)*sizeof(COLOR));
	if (scanbuf == NULL)
		syserror("malloc");
	nread = 0;
	return(nextscan());
}
Esempio n. 5
0
static void
mapimage(void)				/* map picture and send to stdout */
{
	COLOR	*scan;

	comphist();			/* generate adaptation histogram */
	check2do();			/* modify what2do flags */
	if (what2do&DO_VEIL)
		compveil();		/* compute veil image */
	if (!(what2do&DO_LINEAR))
		if (mkbrmap() < 0)	/* make tone map */
			what2do |= DO_LINEAR;	/* failed! -- use linear */
#if ADJ_VEIL
		else if (what2do&DO_VEIL)
			adjveil();	/* else adjust veil image */
#endif
	if (what2do&DO_LINEAR) {
		if (scalef <= FTINY) {
			if (what2do&DO_HSENS)
				scalef = htcontrs(Lb(0.5*(Bldmax+Bldmin))) /
						htcontrs(Lb(bwavg));
			else
				scalef = Lb(0.5*(Bldmax+Bldmin)) / Lb(bwavg);
			scalef *= WHTEFFICACY/(inpexp*ldmax);
		}
		fputexpos(inpexp*scalef, stdout);	/* record exposure */
		if (lumf == cielum) scalef /= WHTEFFICACY;
	}
	fputformat(COLRFMT, stdout);	/* complete header */
	putchar('\n');
	fputsresolu(&inpres, stdout);	/* resolution doesn't change */
					/* condition our image */
	for (scan = firstscan(); scan != NULL; scan = nextscan())
		if (fwritescan(scan, scanlen(&inpres), stdout) < 0) {
			fprintf(stderr, "%s: scanline write error\n",
					progname);
			exit(1);
		}
}
Esempio n. 6
0
static void
init(		/* get view and find window */
    char	*pname,
    char	*wname
)
{
    extern Window	xfindwind();
    XWindowAttributes	wa;
    XColor	xc;
    XGCValues	gcv;
    register int	i;
    /* get the viewing parameters */
    if (viewfile(pname, &ourview, &pres) <= 0 ||
            setview(&ourview) != NULL) {
        fprintf(stderr, "%s: cannot get view from \"%s\"\n",
                progname, pname);
        exit(1);
    }
    /* open the display */
    if ((theDisplay = XOpenDisplay(NULL)) == NULL) {
        fprintf(stderr,
                "%s: cannot open display; DISPLAY variable set?\n",
                progname);
        exit(1);
    }
    /* find our window */
    if (wname == NULL) {
        /* remove directory prefix from name */
        for (i = strlen(pname); i-- > 0; )
            if (pname[i] == '/')
                break;
        wname = pname+i+1;
        i = 0;
    } else
        i = 1;
    gwind = xfindwind(theDisplay, rwind, wname, 4);
    if (gwind == None) {
        if (i) {
            fprintf(stderr, "%s: cannot find \"%s\" window\n",
                    progname, wname);
            exit(2);
        }
        /* start ximage */
        if (fork() == 0) {
            execlp(XIM, XIM, "-c", "256", pname, 0);
            perror(XIM);
            fprintf(stderr, "%s: cannot start %s\n",
                    progname, XIM);
            kill(getppid(), SIGPIPE);
            _exit(1);
        }
        do
            sleep(8);
        while ((gwind=xfindwind(theDisplay,rwind,wname,4)) == None);
    } else
        XMapRaised(theDisplay, gwind);
    do {
        XGetWindowAttributes(theDisplay, gwind, &wa);
        sleep(6);
    } while (wa.map_state != IsViewable);
    if (wa.width != scanlen(&pres) || wa.height != numscans(&pres)) {
        fprintf(stderr,
                "%s: warning -- window seems to be the wrong size!\n",
                progname);
        if (pres.rt & YMAJOR) {
            pres.xr = wa.width;
            pres.yr = wa.height;
        } else {
            pres.xr = wa.height;
            pres.yr = wa.width;
        }
    }
    /* set graphics context */
    gcv.font = XLoadFont(theDisplay, FONTNAME);
    if (gcv.font == 0) {
        fprintf(stderr, "%s: cannot load font \"%s\"\n",
                progname, FONTNAME);
        exit(1);
    }
    xc.red = col[0] >= 1.0 ? 65535 : (unsigned)(65536*col[0]);
    xc.green = col[1] >= 1.0 ? 65535 : (unsigned)(65536*col[1]);
    xc.blue = col[2] >= 1.0 ? 65535 : (unsigned)(65536*col[2]);
    xc.flags = DoRed|DoGreen|DoBlue;
    gcv.background = xc.green >= 32768 ?
                     BlackPixel(theDisplay,DefaultScreen(theDisplay)) :
                     WhitePixel(theDisplay,DefaultScreen(theDisplay)) ;
    if (XAllocColor(theDisplay, wa.colormap, &xc)) {
        gcv.foreground = xc.pixel;
        vecGC = XCreateGC(theDisplay,gwind,
                          GCForeground|GCBackground|GCFont,&gcv);
        strGC = vecGC;
    } else {
        gcv.function = GXinvert;
        vecGC = XCreateGC(theDisplay,gwind,GCFunction,&gcv);
        gcv.foreground = xc.green < 32768 ?
                         BlackPixel(theDisplay,DefaultScreen(theDisplay)) :
                         WhitePixel(theDisplay,DefaultScreen(theDisplay)) ;
        strGC = XCreateGC(theDisplay,gwind,
                          GCForeground|GCBackground|GCFont,&gcv);
    }
}
Esempio n. 7
0
static void
pixtoval(void)				/* convert picture to values */
{
	register COLOR	*scanln;
	int  dogamma;
	COLOR  lastc;
	RREAL  hv[2];
	int  startprim, endprim;
	long  startpos;
	int  y;
	register int  x;

	scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR));
	if (scanln == NULL) {
		fprintf(stderr, "%s: out of memory\n", progname);
		quit(1);
	}
	dogamma = gamcor < .95 || gamcor > 1.05;
	if (putprim == ALL && !interleave) {
		startprim = RED; endprim = BLU;
		startpos = ftell(fin);
	} else {
		startprim = putprim; endprim = putprim;
	}
	for (putprim = startprim; putprim <= endprim; putprim++) {
		if (putprim != startprim && fseek(fin, startpos, 0)) {
			fprintf(stderr, "%s: seek error on input file\n",
					progname);
			quit(1);
		}
		set_io();
		setcolor(lastc, 0.0, 0.0, 0.0);
		for (y = 0; y < numscans(&picres); y++) {
			if (freadscan(scanln, scanlen(&picres), fin) < 0) {
				fprintf(stderr, "%s: read error\n", progname);
				quit(1);
			}
			for (x = 0; x < scanlen(&picres); x++) {
				if (uniq) {
					if (	colval(scanln[x],RED) ==
							colval(lastc,RED) &&
						colval(scanln[x],GRN) ==
							colval(lastc,GRN) &&
						colval(scanln[x],BLU) ==
							colval(lastc,BLU)	)
						continue;
					else
						copycolor(lastc, scanln[x]);
				}
				if (doexposure)
					multcolor(scanln[x], exposure);
				if (dogamma)
					setcolor(scanln[x],
					pow(colval(scanln[x],RED), 1.0/gamcor),
					pow(colval(scanln[x],GRN), 1.0/gamcor),
					pow(colval(scanln[x],BLU), 1.0/gamcor));
				if (!dataonly) {
					pix2loc(hv, &picres, x, y);
					printf("%7d %7d ",
							(int)(hv[0]*picres.xr),
							(int)(hv[1]*picres.yr));
				}
				if ((*putval)(scanln[x]) < 0) {
					fprintf(stderr, "%s: write error\n",
							progname);
					quit(1);
				}
			}
		}
	}
	free((void *)scanln);
}
Esempio n. 8
0
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);
}