Пример #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);
}
Пример #2
0
static void
getfovimg(void)			/* load foveal sampled image */
{
	char	combuf[PATH_MAX];
	FILE	*fp;
	int	x, y;
						/* compute image size */
	fvxr = sqrt(ourview.hn2)/FOVDIA + 0.5;
	if (fvxr < 2) fvxr = 2;
	fvyr = sqrt(ourview.vn2)/FOVDIA + 0.5;
	if (fvyr < 2) fvyr = 2;
	if (!(inpres.rt & YMAJOR)) {		/* picture is rotated? */
		y = fvyr;
		fvyr = fvxr;
		fvxr = y;
	}
	if ((fovimg = (COLOR *)malloc(fvxr*fvyr*sizeof(COLOR))) == NULL)
		syserror("malloc");
	sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d \"%s\"", fvxr, fvyr, infn);
	if ((fp = popen(combuf, "r")) == NULL)
		syserror("popen");
	getheader(fp, NULL, NULL);	/* skip header */
	if (fgetresolu(&x, &y, fp) < 0 || (x != fvxr) | (y != fvyr))
		goto readerr;
	for (y = 0; y < fvyr; y++)
		if (freadscan(fovscan(y), fvxr, fp) < 0)
			goto readerr;
	pclose(fp);
	return;
readerr:
	fprintf(stderr, "%s: error reading from pfilt process in fovimage\n",
			progname);
	exit(1);
}
Пример #3
0
static void
picdebug(void)			/* put out debugging picture */
{
	static COLOR	blkcol = BLKCOLOR;
	COLOR	*scan;
	int	y, i;
	register int	x, rg;

	if (fseek(stdin, 0L, 0) == EOF) {
		fprintf(stderr, "%s: cannot seek on input picture\n", progname);
		exit(1);
	}
	getheader(stdin, NULL, NULL);		/* skip input header */
	fgetresolu(&xmax, &ymax, stdin);
						/* allocate scanline */
	scan = (COLOR *)malloc(xmax*sizeof(COLOR));
	if (scan == NULL) {
		perror(progname);
		exit(1);
	}
						/* finish debug header */
	fputformat(COLRFMT, debugfp);
	putc('\n', debugfp);
	fprtresolu(xmax, ymax, debugfp);
						/* write debug picture */
	for (y = ymax-1; y >= 0; y--) {
		if (freadscan(scan, xmax, stdin) < 0) {
			fprintf(stderr, "%s: error rereading input picture\n",
					progname);
			exit(1);
		}
		for (x = 0; x < xmax; x++) {
			rg = chartndx(x, y, &i);
			if (rg == RG_CENT) {
				if (!(1L<<i & gmtflags) || (x+y)&07) {
					copycolor(scan[x], mbRGB[i]);
					clipgamut(scan[x], bright(scan[x]),
						CGAMUT, colmin, colmax);
				} else
					copycolor(scan[x], blkcol);
			} else if (rg == RG_CORR)
				cvtcolor(scan[x], scan[x]);
			else if (rg != RG_ORIG)
				copycolor(scan[x], blkcol);
		}
		if (fwritescan(scan, xmax, debugfp) < 0) {
			fprintf(stderr, "%s: error writing debugging picture\n",
					progname);
			exit(1);
		}
	}
						/* clean up */
	fclose(debugfp);
	free((void *)scan);
}
Пример #4
0
static int
rmx_load_rgbe(RMATRIX *rm, FILE *fp)
{
	COLOR	*scan = (COLOR *)malloc(sizeof(COLOR)*rm->ncols);
	int	i, j;

	if (scan == NULL)
		return(0);
	for (i = 0; i < rm->nrows; i++) {
	    if (freadscan(scan, rm->ncols, fp) < 0) {
		free(scan);
		return(0);
	    }
	    for (j = rm->ncols; j--; ) {
	        rmx_lval(rm,i,j,0) = colval(scan[j],RED);
	        rmx_lval(rm,i,j,1) = colval(scan[j],GRN);
	        rmx_lval(rm,i,j,2) = colval(scan[j],BLU);
	    }
	}
	free(scan);
	return(1);
}
Пример #5
0
static void
advance(void)			/* read in data for next scanline */
{
	int	ytarget;
	register COLOR	*st;
	register int	i, j;

	for (ytarget = (ypos+.5)*ymax/yres; yscan > ytarget; yscan--)
		for (i = 0; i < nfiles; i++) {
			st = input[i].scan[WINSIZ-1];
			for (j = WINSIZ-1; j > 0; j--)	/* rotate window */
				input[i].scan[j] = input[i].scan[j-1];
			input[i].scan[0] = st;
			if (yscan <= MIDSCN)		/* hit bottom? */
				continue;
			if (freadscan(st, xmax, input[i].fp) < 0) {  /* read */
				eputs(input[i].name);
				eputs(": read error\n");
				quit(1);
			}
			for (j = 0; j < xmax; j++)	/* adjust color */
				multcolor(st[j], input[i].coef);
		}
}
Пример #6
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);
}
Пример #7
0
static void
ra2ppm2(	/* convert Radiance picture to Pixmap (2-byte) */
	int  binary,
	int  grey
)
{
	COLOR	*scanin;
	double	mult, d;
	register int	x;
	int	y;
						/* allocate scanline */
	scanin = (COLOR *)malloc(xmax*sizeof(COLOR));
	if (scanin == NULL)
		quiterr("out of memory in ra2ppm2");
	if (bradj)
		mult = pow(2., (double)bradj);
						/* convert image */
	for (y = ymax-1; y >= 0; y--) {
		if (freadscan(scanin, xmax, stdin) < 0)
			quiterr("error reading Radiance picture");
		for (x = bradj?xmax:0; x--; )
			scalecolor(scanin[x], mult);
		for (x = grey?xmax:0; x--; )
			colval(scanin[x],GRN) = bright(scanin[x]);
		d = 1./gamcor;
		for (x = (d>1.01)|(d<0.99)?xmax:0; x--; ) {
			colval(scanin[x],GRN) = pow(colval(scanin[x],GRN), d);
			if (!grey) {
				colval(scanin[x],RED) =
						pow(colval(scanin[x],RED), d);
				colval(scanin[x],BLU) =
						pow(colval(scanin[x],BLU), d);
			}
		}
		if (grey)
			if (binary)
				for (x = 0; x < xmax; x++)
					putby2(intv(colval(scanin[x],GRN)),
							stdout);
			else
				for (x = 0; x < xmax; x++)
					printf("%u\n",
						intv(colval(scanin[x],GRN)));
		else
			if (binary)
				for (x = 0; x < xmax; x++) {
					putby2(intv(colval(scanin[x],RED)),
							stdout);
					putby2(intv(colval(scanin[x],GRN)),
							stdout);
					putby2(intv(colval(scanin[x],BLU)),
							stdout);
				}
			else
				for (x = 0; x < xmax; x++)
					printf("%u %u %u\n",
						intv(colval(scanin[x],RED)),
						intv(colval(scanin[x],GRN)),
						intv(colval(scanin[x],BLU)));
		if (ferror(stdout))
			quiterr("error writing Pixmap");
	}
						/* free scanline */
	free((void *)scanin);
}