home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * fromfish -
- * Convert from a fisheye projection to an environment map.
- *
- * Paul Haeberli - 1987
- */
- #include "texture.h"
- #define HORIZON
- #define TWOSIDES
-
- #define XSIZE (3*size)
- #define YSIZE (2*size)
- #define RAD (0.98) /* fish eye image is inset 2% */
- #define HACK (0.001)
-
- TEXTURE *tm;
- int doreflect;
- int size, samples;
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- float vr, vg, vb;
- float tr, tg, tb;
- int x, y;
- IMAGE *image;
- int i;
- vect c, pos, dir, fish;
- float temp;
- short *rbuf, *gbuf, *bbuf;
-
- if(argc<5) {
- fprintf(stderr,"usage: fromfish size samples file.rgb file.env\n");
- exit(1);
- }
- size = atoi(argv[1]);
- samples = atoi(argv[2]);
- tm = tmopen(argv[3]);
- if(!tm) {
- fprintf(stderr,"can't open input image.\n");
- exit(1);
- }
- rbuf = (short *)malloc(XSIZE*sizeof(short));
- gbuf = (short *)malloc(XSIZE*sizeof(short));
- bbuf = (short *)malloc(XSIZE*sizeof(short));
- image = iopen(argv[4],"w",RLE(1),3,XSIZE,YSIZE,3);
- for(y=0; y<YSIZE; y++) {
- for(x=0; x<XSIZE; x++) {
- tr = tg = tb = 0.0;
- for(i=0; i<samples; i++) {
- if(samples>1) {
- pos.x = (x+frand())/(XSIZE+HACK);
- pos.y = (y+frand())/(YSIZE+HACK);
- pos.z = 0;
- } else {
- pos.x = (x+0.5)/XSIZE;
- pos.y = (y+0.5)/YSIZE;
- pos.z = 0.0;
- }
- envtovect(&pos,&dir);
- #ifdef HORIZON
- temp = dir.x;
- dir.x = dir.y;
- dir.y = dir.z;
- dir.z = temp;
- #endif
- #ifdef TWOSIDES
- if(dir.z<0.0)
- dir.z = -dir.z;
- #endif
- if(dirtofish(&dir,&fish))
- tmsample(tm,&fish,&c);
- else
- vzero(&c);
- tr += c.x;
- tg += c.y;
- tb += c.z;
- }
- rbuf[x] = 255*tr/samples;
- gbuf[x] = 255*tg/samples;
- bbuf[x] = 255*tb/samples;
- }
- putrow(image,rbuf,y,0);
- putrow(image,gbuf,y,1);
- putrow(image,bbuf,y,2);
- tpercentdone(100.0*y/(YSIZE-1));
- }
- iclose(image);
- }
-
- dirtofish(dir,fish)
- vect *dir, *fish;
- {
- float magout, magup, angout, m;
-
- magout = sqrt(dir->x*dir->x+dir->y*dir->y);
- if(dir->z<0.0)
- return 0;
- magup = dir->z;
- angout = atan2(magout,magup)/3.1415926535;
- if(angout<0.0)
- angout = 0.0;
- if(angout>1.0)
- angout = 1.0;
- if(magout>0.0001) {
- m = RAD*angout/magout;
- fish->x = 0.5 + m*dir->x;
- fish->y = 0.5 + m*dir->y;
- fish->z = 0.0;
- } else {
- fish->x = 0.5;
- fish->y = 0.5;
- fish->z = 0.0;
- }
- return 1;
- }
-