Exemple #1
0
void
getpictcolrs(				/* get scanline from picture */
	int  yoff,
	COLR  *scan,
	PNODE  *p,
	int  xsiz,
	int  ysiz
)
{
	int  mx;
	int  my;

	if (p->kid == NULL) {			/* do this node */
		setcolr(scan[0], colval(p->v,RED),
				colval(p->v,GRN),
				colval(p->v,BLU));
		for (mx = 1; mx < xsiz; mx++)
			copycolr(scan[mx], scan[0]);
		return;
	}
						/* do kids */
	mx = xsiz >> 1;
	my = ysiz >> 1;
	if (yoff < my) {
		getpictcolrs(yoff, scan, p->kid+DL, mx, my);
		getpictcolrs(yoff, scan+mx, p->kid+DR, xsiz-mx, my);
	} else {
		getpictcolrs(yoff-my, scan, p->kid+UL, mx, ysiz-my);
		getpictcolrs(yoff-my, scan+mx, p->kid+UR, xsiz-mx, ysiz-my);
	}
}
Exemple #2
0
int oldreadcolrs(COLR *scanline, int len, FILE *fp) {              /* read in an old colr scanline */
    int  rshift;
    int  i;

    rshift = 0;

    while (len > 0) {
        scanline[0][RED] = getc(fp);
        scanline[0][GRN] = getc(fp);
        scanline[0][BLU] = getc(fp);
        scanline[0][EXP] = getc(fp);
        if (feof(fp) || ferror(fp)) {
            return(-1);
        }
        if (scanline[0][RED] == 1 &&
            scanline[0][GRN] == 1 &&
            scanline[0][BLU] == 1) {
            for (i = scanline[0][EXP] << rshift; i > 0; i--) {
                copycolr(scanline[0], scanline[-1]);
                scanline++;
                len--;
            }
            rshift += 8;
        } else {
            scanline++;
            len--;
            rshift = 0;
        }
    }
    return(0);
}
Exemple #3
0
void
addray(		/* add a ray to our output holodeck */
	FVECT	ro,
	FVECT	rd,
	double	d,
	COLR	cv
)
{
	int	sn, bi, n;
	register HOLO	*hp;
	GCOORD	gc[2];
	uby8	rr[2][2];
	BEAM	*bp;
	double	d0, d1;
	unsigned	dc;
	register RAYVAL	*rv;
				/* check each output section */
	for (sn = noutsects; sn--; ) {
		hp = hdlist[sn];
		d0 = hdinter(gc, rr, &d1, hp, ro, rd);
		if (d <= d0 || d1 < -0.001)
			continue;	/* missed section */
		if (checkdepth) {		/* check depth */
			if (hp->priv == &obstr && d0 < -0.001)
				continue;	/* ray starts too late */
			if (hp->priv == &unobstr && d < 0.999*d1)
				continue;	/* ray ends too soon */
		}
		dc = hdcode(hp, d-d0);
		bi = hdbindex(hp, gc);		/* check for duplicates */
		if (checkrepeats && (bp = hdgetbeam(hp, bi)) != NULL) {
			for (n = bp->nrm, rv = hdbray(bp); n--; rv++)
				if ((hp->priv != NULL || rv->d == dc) &&
						rv->r[0][0] == rr[0][0] &&
						rv->r[0][1] == rr[0][1] &&
						rv->r[1][0] == rr[1][0] &&
						rv->r[1][1] == rr[1][1])
					break;
			if (n >= 0)
				continue;	/* found a matching ray */
		}
		rv = hdnewrays(hp, bi, 1);
		rv->d = dc;
		rv->r[0][0] = rr[0][0]; rv->r[0][1] = rr[0][1];
		rv->r[1][0] = rr[1][0]; rv->r[1][1] = rr[1][1];
		copycolr(rv->v, cv);
	}
}
Exemple #4
0
static int
oldreadcolrs(			/* read in an old-style colr scanline */
	COLR  *scanline,
	int  len,
	FILE  *fp
)
{
	int  rshift = 0;
	int  i;
	
	while (len > 0) {
		scanline[0][RED] = getc(fp);
		scanline[0][GRN] = getc(fp);
		scanline[0][BLU] = getc(fp);
		scanline[0][EXP] = i = getc(fp);
		if (i == EOF)
			return(-1);
		if (scanline[0][GRN] == 1 &&
				(scanline[0][RED] == 1) &
				(scanline[0][BLU] == 1)) {
			i = scanline[0][EXP] << rshift;
			while (i--) {
				copycolr(scanline[0], scanline[-1]);
				if (--len <= 0)
					return(0);
				scanline++;
			}
			rshift += 8;
		} else {
			scanline++;
			len--;
			rshift = 0;
		}
	}
	return(0);
}
static void
rotateccw(			/* rotate picture counter-clockwise */
	FILE	*fp
)
{
	register COLR	*inln;
	register int	xoff, inx, iny;
	long	start, ftell();

	if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
		fprintf(stderr, "%s: out of memory\n", progname);
		exit(1);
	}
	start = ftell(fp);
	for (xoff = xres-1; xoff >= 0; xoff -= nrows) {
		if (fseek(fp, start, 0) < 0) {
			fprintf(stderr, "%s: seek error\n", progname);
			exit(1);
		}
		for (iny = 0; iny < yres; iny++) {
			if (freadcolrs(inln, xres, fp) < 0) {
				fprintf(stderr, "%s: read error\n", progname);
				exit(1);
			}
			for (inx = 0; inx < nrows && xoff-inx >= 0; inx++)
				copycolr(scanbar[inx*yres+iny],
						inln[xoff-inx]);
		}
		for (inx = 0; inx < nrows && xoff-inx >= 0; inx++)
			if (fwritecolrs(scanbar+inx*yres, yres, stdout) < 0) {
				fprintf(stderr, "%s: write error\n", progname);
				exit(1);
			}
	}
	free((void *)inln);
}
Exemple #6
0
static void
compos(void)				/* composite pictures */
{
	COLR  *scanin, *scanout;
	int  y;
	register int  x, i;

	scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR));
	if (scanin == NULL)
		goto memerr;
	scanin -= xmin;
	if (checkthresh) {
		scanout = (COLR *)malloc(xsiz*sizeof(COLR));
		if (scanout == NULL)
			goto memerr;
	} else
		scanout = scanin;
	for (y = ymax-1; y >= 0; y--) {
		for (x = 0; x < xsiz; x++)
			copycolr(scanout[x], bgcolr);
		for (i = 0; i < nfile; i++) {
			if (input[i].yloc > y ||
					input[i].yloc+input[i].yres <= y)
				continue;
			if (freadcolrs(scanin+input[i].xloc,
					input[i].xres, input[i].fp) < 0) {
				fprintf(stderr, "%s: read error (y==%d)\n",
						input[i].name,
						y-input[i].yloc);
				quit(1);
			}
			if (y >= ysiz)
				continue;
			if (checkthresh) {
				x = input[i].xloc+input[i].xres;
				if (x > xsiz)
					x = xsiz;
				for (x--; x >= 0 && x >= input[i].xloc; x--) {
					if (input[i].flags & HASMIN &&
					cmpcolr(scanin[x], input[i].thmin) <= 0)
						continue;
					if (input[i].flags & HASMAX &&
					cmpcolr(scanin[x], input[i].thmax) >= 0)
						continue;
					copycolr(scanout[x], scanin[x]);
				}
			}
		}
		if (y >= ysiz)
			continue;
		if (fwritecolrs(scanout, xsiz, stdout) < 0) {
			perror(progname);
			quit(1);
		}
	}
					/* read remainders from streams */
	for (i = 0; i < nfile; i++)
		if (input[i].name[0] == '<')
			while (getc(input[i].fp) != EOF)
				;
	return;
memerr:
	perror(progname);
	quit(1);
}
static void
clrdebug(void)			/* put out debug picture from color input */
{
	static COLR	blkclr = BLKCOLR;
	COLR	mbclr[24], cvclr[24], orclr[24];
	COLR	*scan;
	COLOR	ctmp, ct2;
	int	y, i;
	register int	x, rg;
						/* convert colors */
	for (i = 0; i < 24; i++) {
		copycolor(ctmp, mbRGB[i]);
		clipgamut(ctmp, bright(ctmp), CGAMUT, cblack, cwhite);
		setcolr(mbclr[i], colval(ctmp,RED),
				colval(ctmp,GRN), colval(ctmp,BLU));
		if (inpflags & 1L<<i) {
			copycolor(ctmp, inpRGB[i]);
			clipgamut(ctmp, bright(ctmp), CGAMUT, cblack, cwhite);
			setcolr(orclr[i], colval(ctmp,RED),
					colval(ctmp,GRN), colval(ctmp,BLU));
			if (rawmap)
				copycolr(cvclr[i], mbclr[i]);
			else {
				bresp(ctmp, inpRGB[i]);
				colortrans(ct2, solmat, ctmp);
				clipgamut(ct2, bright(ct2), CGAMUT,
						cblack, cwhite);
				setcolr(cvclr[i], colval(ct2,RED),
						colval(ct2,GRN),
						colval(ct2,BLU));
			}
		}
	}
						/* allocate scanline */
	scan = (COLR *)malloc(xmax*sizeof(COLR));
	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--) {
		for (x = 0; x < xmax; x++) {
			rg = chartndx(x, y, &i);
			if (rg == RG_CENT) {
				if (!(1L<<i & gmtflags) || (x+y)&07)
					copycolr(scan[x], mbclr[i]);
				else
					copycolr(scan[x], blkclr);
			} else if (rg == RG_BORD || !(1L<<i & inpflags))
				copycolr(scan[x], blkclr);
			else if (rg == RG_ORIG)
				copycolr(scan[x], orclr[i]);
			else /* rg == RG_CORR */
				copycolr(scan[x], cvclr[i]);
		}
		if (fwritecolrs(scan, xmax, debugfp) < 0) {
			fprintf(stderr, "%s: error writing debugging picture\n",
					progname);
			exit(1);
		}
	}
						/* clean up */
	fclose(debugfp);
	free((void *)scan);
}