16 #define TACHYON_INTERNAL 1    28   for (i=0; i<MAXIMGS; i++) {
    48 rawimage * 
AllocateImageRGB24(
const char * filename, 
int xs, 
int ys, 
int zs, 
unsigned char * rgb) {
    49   rawimage * newimage = NULL;
    63     newimage=malloc(
sizeof(rawimage));
    73     strcpy(newimage->name, filename);
    83   rawimage * newimage = NULL;
    97     newimage=malloc(
sizeof(rawimage));
   104     len=strlen(filename);
   107     strcpy(newimage->name, filename);
   117   rawimage * newimage = NULL;
   118   newimage=malloc(
sizeof(rawimage));
   119   if (newimage == NULL)
   127   newimage->data=malloc(((
long)x)*((
long)y)*((
long)z)*3L);
   128   if (newimage->data == NULL) {
   148   for (i=1; i<mip->levels; i++) {
   177   long x, y, addr, addr2;
   179   x = (long) image->xres >> 1;
   183   y = (long) image->yres >> 1;
   189   if (image->xres > 1 && image->yres > 1) {
   190     for (y=0; y<newimage->yres; y++) {
   191       for (x=0; x<newimage->xres; x++) {
   192         addr = (newimage->xres*y + x)*3L;
   193         addr2 = (image->xres*y + x)*3L*2L;
   194         newimage->data[addr] = (int)
   195           (image->data[addr2] + 
   196            image->data[addr2 + 3] +
   197            image->data[addr2 + image->xres*3] + 
   198            image->data[addr2 + (image->xres + 1)*3]) >> 2; 
   201         newimage->data[addr] = (int)
   202           (image->data[addr2] + 
   203            image->data[addr2 + 3] +
   204            image->data[addr2 + image->xres*3] + 
   205            image->data[addr2 + (image->xres + 1)*3]) >> 2; 
   208         newimage->data[addr] = (int)
   209           (image->data[addr2] + 
   210            image->data[addr2 + 3] +
   211            image->data[addr2 + image->xres*3] + 
   212            image->data[addr2 + (image->xres + 1)*3]) >> 2; 
   215   } 
else if (image->xres == 1) {
   216     for (y=0; y<newimage->yres; y++) {
   219       newimage->data[addr] = (int)
   220         (image->data[addr2] + 
   221          image->data[addr2 + 3]) >> 1;
   224       newimage->data[addr] = (int)
   225         (image->data[addr2] + 
   226          image->data[addr2 + 3]) >> 1;
   229       newimage->data[addr] = (int)
   230         (image->data[addr2] + 
   231          image->data[addr2 + 3]) >> 1;
   233   } 
else if (image->yres == 1) {
   234     for (x=0; x<newimage->xres; x++) {
   237       newimage->data[addr] = (int)
   238         (image->data[addr2] + 
   239          image->data[addr2 + 3]) >> 1;
   242       newimage->data[addr] = (int)
   243         (image->data[addr2] + 
   244          image->data[addr2 + 3]) >> 1;
   247       newimage->data[addr] = (int)
   248         (image->data[addr2] + 
   249          image->data[addr2 + 3]) >> 1;
   258   int xlevels, ylevels, zlevels, i; 
   263   mip = (mipmap *) malloc(
sizeof(mipmap));
   268   i = abs(image->xres);
   275   i = abs(image->yres);
   282   i = abs(image->zres);
   288   mip->levels = (xlevels > ylevels) ? xlevels : ylevels; 
   289   if (zlevels > mip->levels)
   295   if (image->zres > 1) {
   300     if (maxlevels < mip->levels)
   301       mip->levels = maxlevels;
   306     sprintf(msgtxt, 
"Creating MIP Map: xlevels: %d  ylevels: %d  zlevels: %d  levels: %d", xlevels, ylevels, zlevels, mip->levels);
   310   mip->images = (rawimage **) malloc(mip->levels * 
sizeof(rawimage *)); 
   311   if (mip->images == NULL) {
   316   for (i=0; i<mip->levels; i++) {
   317     mip->images[i] = NULL;
   320   mip->images[0] = image;
   321   for (i=1; i<mip->levels; i++) {
   331   color col, col1, col2;
   333   if ((u <= 1.0) && (u >= 0.0) && (v <= 1.0) && (v >= 0.0)) {
   335     t = (d > 1.0) ? 1.0 : d;
   336     d = (t < 0.0) ? 0.0 : t;
   338     mapflt = d * (mip->levels - 0.9999); 
   339     mapindex = (int) mapflt;             
   340     mapflt = mapflt - mapindex;          
   343     if (mapindex < (mip->levels - 2)) {
   344       col1 = 
ImageMap(mip->images[mapindex    ], u, v);
   345       col2 = 
ImageMap(mip->images[mapindex + 1], u, v);
   346       col.r = col1.r + mapflt*(col2.r - col1.r);
   347       col.g = col1.g + mapflt*(col2.g - col1.g);
   348       col.b = col1.b + mapflt*(col2.b - col1.b);
   353       col  = 
ImageMap(mip->images[mip->levels - 1], u, v);
   367   color col, colx, colx2;
   371   const flt texel_inv = 1.0 / 255.0;
   376   nx = (image->xres > 1) ? 3 : 0;
   377   x = (image->xres - 1.0) * u; 
   381   ny = (image->yres > 1) ? image->xres * 3 : 0;
   382   y = (image->yres - 1.0) * v; 
   387   ptr  = image->data + ((image->xres * iy) + ix) * 3; 
   390   colx.r = (
flt) ((
flt)ptr[0] + px*((
flt)ptr[nx  ] - (
flt) ptr[0])); 
   391   colx.g = (
flt) ((
flt)ptr[1] + px*((
flt)ptr[nx+1] - (
flt) ptr[1])); 
   392   colx.b = (
flt) ((
flt)ptr[2] + px*((
flt)ptr[nx+2] - (
flt) ptr[2])); 
   398   colx2.r = ((
flt)ptr[0] + px*((
flt)ptr[nx  ] - (
flt)ptr[0])); 
   399   colx2.g = ((
flt)ptr[1] + px*((
flt)ptr[nx+1] - (
flt)ptr[1])); 
   400   colx2.b = ((
flt)ptr[2] + px*((
flt)ptr[nx+2] - (
flt)ptr[2])); 
   403   col.r = (colx.r + py*(colx2.r - colx.r)) * texel_inv;
   404   col.g = (colx.g + py*(colx2.g - colx.g)) * texel_inv;
   405   col.b = (colx.b + py*(colx2.b - colx.b)) * texel_inv;
   417   x = (img->xres - 1.0) * u;  
   419   y = (img->yres - 1.0) * v;  
   421   z = (img->zres - 1.0) * w;  
   424   addr = ((iz * img->xres * img->yres) + (iy * img->xres) + ix) * 3; 
   425   col.r = img->data[addr    ];
   426   col.g = img->data[addr + 1];
   427   col.b = img->data[addr + 2];
   434   color col, colL, colU, colll, colul, colLL, colUL;
   435   flt x, y, z, px, py, pz;
   436   long ix, iy, iz, nx, ny, nz;
   437   unsigned char *llptr, *ulptr, *LLptr, *ULptr;
   439   const flt texel_inv = 1.0 / 255.0;
   444   nx = (img->xres > 1) ? 3L : 0L;
   445   x = (img->xres - 1.0) * u;  
   449   ny = (img->yres > 1) ? (img->xres * 3L) : 0L;
   450   y = (img->yres - 1.0) * v;  
   454   nz = (img->zres > 1) ? (img->xres * img->yres * 3L) : 0L;
   455   z = (img->zres - 1.0) * w;  
   459   addr = ((img->xres*img->yres * iz) + (img->xres * iy) + ix) * 3L; 
   462   llptr = img->data + addr;
   473   colll.r = (
flt) ((
flt)llptr[0] + px*((
flt)llptr[nx  ] - (
flt) llptr[0])); 
   474   colll.g = (
flt) ((
flt)llptr[1] + px*((
flt)llptr[nx+1] - (
flt) llptr[1])); 
   475   colll.b = (
flt) ((
flt)llptr[2] + px*((
flt)llptr[nx+2] - (
flt) llptr[2])); 
   478   colul.r = ((
flt)ulptr[0] + px*((
flt)ulptr[nx  ] - (
flt)ulptr[0])); 
   479   colul.g = ((
flt)ulptr[1] + px*((
flt)ulptr[nx+1] - (
flt)ulptr[1])); 
   480   colul.b = ((
flt)ulptr[2] + px*((
flt)ulptr[nx+2] - (
flt)ulptr[2])); 
   483   colLL.r = (
flt) ((
flt)LLptr[0] + px*((
flt)LLptr[nx  ] - (
flt) LLptr[0])); 
   484   colLL.g = (
flt) ((
flt)LLptr[1] + px*((
flt)LLptr[nx+1] - (
flt) LLptr[1])); 
   485   colLL.b = (
flt) ((
flt)LLptr[2] + px*((
flt)LLptr[nx+2] - (
flt) LLptr[2])); 
   488   colUL.r = ((
flt)ULptr[0] + px*((
flt)ULptr[nx  ] - (
flt)ULptr[0])); 
   489   colUL.g = ((
flt)ULptr[1] + px*((
flt)ULptr[nx+1] - (
flt)ULptr[1])); 
   490   colUL.b = ((
flt)ULptr[2] + px*((
flt)ULptr[nx+2] - (
flt)ULptr[2])); 
   493   colL.r = (colll.r + py*(colul.r - colll.r));
   494   colL.g = (colll.g + py*(colul.g - colll.g));
   495   colL.b = (colll.b + py*(colul.b - colll.b));
   498   colU.r = (colLL.r + py*(colUL.r - colLL.r));
   499   colU.g = (colLL.g + py*(colUL.g - colLL.g));
   500   colU.b = (colLL.b + py*(colUL.b - colLL.b));
   503   col.r = (colL.r + pz*(colU.r - colL.r)) * texel_inv;
   504   col.g = (colL.g + pz*(colU.g - colL.g)) * texel_inv;
   505   col.b = (colL.b + pz*(colU.b - colL.b)) * texel_inv;
   514   color col, col1, col2;
   516   if ((u <= 1.0) && (u >= 0.0) && 
   517       (v <= 1.0) && (v >= 0.0) &&
   518       (w <= 1.0) && (w >= 0.0)) {
   520     t = (d > 1.0) ? 1.0 : d;
   521     d = (t < 0.0) ? 0.0 : t;
   523     mapflt = d * (mip->levels - 0.9999); 
   524     mapindex = (int) mapflt;             
   525     mapflt = mapflt - mapindex;          
   528     if (mapindex < (mip->levels - 2)) {
   531       col.r = col1.r + mapflt*(col2.r - col1.r);
   532       col.g = col1.g + mapflt*(col2.g - col1.g);
   533       col.b = col1.b + mapflt*(col2.b - col1.b);
 color VolMIPMap(const mipmap *mip, flt u, flt v, flt w, flt d)
 
void FreeMIPMap(mipmap *mip)
 
color VolImageMapTrilinear(const rawimage *img, flt u, flt v, flt w)
 
int readimage(rawimage *img)
 
rawimage * global_imagelist[MAXIMGS]
texture map cache 
 
void rt_ui_message(int level, char *msg)
 
color VolImageMapNearest(const rawimage *img, flt u, flt v, flt w)
 
mipmap * LoadMIPMap(const char *filename, int maxlevels)
 
rawimage * NewImage(int x, int y, int z)
 
double flt
generic floating point number, using double 
 
int rt_mynode(void)
distributed memory parallel node rank 
 
color MIPMap(const mipmap *mip, flt u, flt v, flt d)
 
rawimage * DecimateImage(const rawimage *image)
 
Tachyon cross-platform timers, special math function wrappers, and RNGs. 
 
mipmap * CreateMIPMap(rawimage *image, int maxlevels)
 
void DeallocateImage(rawimage *image)
 
color ImageMap(const rawimage *image, flt u, flt v)
 
rawimage * AllocateImageFile(const char *filename)
 
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
 
void LoadRawImage(rawimage *image)
 
rawimage * AllocateImageRGB24(const char *filename, int xs, int ys, int zs, unsigned char *rgb)