示例#1
0
/*
 * Load and tone-map a SGILOG TIFF.
 * Beware of greyscale input -- you must check the PHOTOMETRIC tag to
 * determine that the returned array contains only grey values, not RGB.
 * As in tmMapPicture(), grey values are also returned if flags&TM_F_BW.
 */
int
tmMapTIFF(uby8 **psp, int *xp, int *yp, int flags, RGBPRIMP monpri,
	double gamval, double Lddyn, double Ldmax, char *fname, TIFF *tp)
{
	char	*funcName = fname==NULL ? "tmMapTIFF" : fname;
	TMstruct	*tms = NULL;
	TMbright	*lp;
	uby8	*cp;
	int	err;
					/* check arguments */
	if ((psp == NULL) | (xp == NULL) | (yp == NULL) | (monpri == NULL) |
			((fname == NULL) & (tp == NULL)))
		returnErr(TM_E_ILLEGAL);
	if (gamval < MINGAM) gamval = DEFGAM;
	if (Lddyn < MINLDDYN) Lddyn = DEFLDDYN;
	if (Ldmax < MINLDMAX) Ldmax = DEFLDMAX;
	if (flags & TM_F_BW) monpri = stdprims;
					/* initialize tone mapping */
	if ((tms = tmInit(flags, monpri, gamval)) == NULL)
		returnErr(TM_E_NOMEM);
					/* load and convert TIFF */
	cp = TM_NOCHROM;
	err = tmLoadTIFF(tms, &lp, flags&TM_F_BW ? TM_NOCHROMP : &cp,
			xp, yp, fname, tp);
	if (err != TM_E_OK) {
		tmDone(tms);
		return(err);
	}
	if (cp == TM_NOCHROM) {
		*psp = (uby8 *)malloc(*xp * *yp * sizeof(uby8));
		if (*psp == NULL) {
			free((MEM_PTR)lp);
			tmDone(tms);
			returnErr(TM_E_NOMEM);
		}
	} else
		*psp = cp;
					/* compute color mapping */
	err = tmAddHisto(tms, lp, *xp * *yp, 1);
	if (err != TM_E_OK)
		goto done;
	err = tmComputeMapping(tms, gamval, Lddyn, Ldmax);
	if (err != TM_E_OK)
		goto done;
					/* map pixels */
	err = tmMapPixels(tms, *psp, lp, cp, *xp * *yp);

done:					/* clean up */
	free((MEM_PTR)lp);
	tmDone(tms);
	if (err != TM_E_OK) {		/* free memory on error */
		free((MEM_PTR)*psp);
		*psp = NULL;
		*xp = *yp = 0;
		returnErr(err);
	}
	returnOK;
}
示例#2
0
void
dev_close(void)			/* close our display and free resources */
{
	glXMakeCurrent(ourdisplay, None, NULL);
	glXDestroyContext(ourdisplay, gctx);
	XDestroyWindow(ourdisplay, gwind);
	gwind = 0;
	XCloseDisplay(ourdisplay);
	ourdisplay = NULL;
	qtFreeLeaves();
	tmDone(tmGlobal);
	freecones();
	odev.v.type = 0;
	odev.hres = odev.vres = 0;
	odev.ifd = -1;
}