CDDSImage Class Reference

List of all members.

Public Member Functions

 CDDSImage ()
 ~CDDSImage ()
bool load (std::istream &is, bool flipImage=true, bool swapCubeMap=true, bool flipCubeMap=false)
void clear ()
 operator char * ()
CTextureoperator[] (Int32 index)
Int32 get_num_images (void)
CTextureget_image (Int32 index)
Int32 get_components ()
Int32 get_format ()
bool is_compressed ()
bool is_cubemap ()
bool is_volume ()
bool is_valid ()

Private Member Functions

Int32 clamp_size (Int32 size)
Int32 get_line_width (Int32 width, Int32 bpp)
Int32 size_dxtc (Int32 width, Int32 height)
Int32 size_rgb (Int32 width, Int32 height)
void swap_endian (void *val)
void align_memory (CTexture *surface)
void flip (char *image, Int32 width, Int32 height, Int32 depth, Int32 size)
bool check_dxt1_alpha_data (char *image, Int32 size)
void swap (void *byte1, void *byte2, Int32 size)
void flip_blocks_dxtc1 (DXTColBlock *line, Int32 numBlocks)
void flip_blocks_dxtc3 (DXTColBlock *line, Int32 numBlocks)
void flip_blocks_dxtc5 (DXTColBlock *line, Int32 numBlocks)
void flip_dxt5_alpha (DXT5AlphaBlock *block)

Private Attributes

Int32 format
Int32 components
bool compressed
bool cubemap
bool volume
bool valid
std::vector< CTextureimages


Detailed Description

Definition at line 224 of file OSGDDSImageFileType.cpp.


Constructor & Destructor Documentation

CDDSImage::CDDSImage (  ) 

Definition at line 477 of file OSGDDSImageFileType.cpp.

00478   : format(0),
00479     components(0),
00480     compressed(false),
00481     cubemap(false),
00482     volume(false),
00483     valid(false)
00484 {
00485 }

CDDSImage::~CDDSImage (  ) 

Definition at line 487 of file OSGDDSImageFileType.cpp.

00488 {
00489 }


Member Function Documentation

bool CDDSImage::load ( std::istream &  is,
bool  flipImage = true,
bool  swapCubeMap = true,
bool  flipCubeMap = false 
)

Definition at line 496 of file OSGDDSImageFileType.cpp.

References align_memory(), check_dxt1_alpha_data(), clamp_size(), clear(), components, compressed, cubemap, DDS_HEADER::ddspf, CSurface::depth, DDS_HEADER::dwCaps1, DDS_HEADER::dwCaps2, DDS_HEADER::dwDepth, DDS_PIXELFORMAT::dwFlags, DDS_HEADER::dwFlags, DDS_PIXELFORMAT::dwFourCC, DDS_HEADER::dwHeight, DDS_HEADER::dwMipMapCount, DDS_HEADER::dwPitchOrLinearSize, DDS_PIXELFORMAT::dwRGBBitCount, DDS_PIXELFORMAT::dwSize, DDS_HEADER::dwSize, DDS_HEADER::dwWidth, osg::endLog(), flip(), format, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, CSurface::height, images, CTexture::mipmaps, CSurface::size, size_dxtc(), size_rgb(), swap_endian(), SWARNING, valid, volume, and CSurface::width.

Referenced by osg::DDSImageFileType::read().

00497 {
00498     DDS_HEADER ddsh;
00499     char filecode[4];
00500     Int32 width, height, depth;
00501     Int32 (CDDSImage::*sizefunc)(Int32, Int32);
00502 
00503     // clear any previously loaded images
00504     clear();
00505 
00506     // read in file marker, make sure its a DDS file
00507     is.read(filecode, 4);
00508     if (strncmp(filecode, "DDS ", 4) != 0)
00509         return false;
00510 
00511     // read in DDS header
00512     is.read(reinterpret_cast<char*>(&ddsh), sizeof(ddsh));
00513 
00514     swap_endian(&ddsh.dwSize);
00515     swap_endian(&ddsh.dwFlags);
00516     swap_endian(&ddsh.dwHeight);
00517     swap_endian(&ddsh.dwWidth);
00518     swap_endian(&ddsh.dwPitchOrLinearSize);
00519     swap_endian(&ddsh.dwDepth);
00520     swap_endian(&ddsh.dwMipMapCount);
00521     swap_endian(&ddsh.ddspf.dwSize);
00522     swap_endian(&ddsh.ddspf.dwFlags);
00523     swap_endian(&ddsh.ddspf.dwFourCC);
00524     swap_endian(&ddsh.ddspf.dwRGBBitCount);
00525     swap_endian(&ddsh.dwCaps1);
00526     swap_endian(&ddsh.dwCaps2);
00527 
00528     // check if image is a cubempa
00529     if (ddsh.dwCaps2 & DDS_CUBEMAP)
00530         cubemap = true;
00531 
00532     // check if image is a volume texture
00533     if ((ddsh.dwCaps2 & DDS_VOLUME) && (ddsh.dwDepth > 0))
00534         volume = true;
00535 
00536     // figure out what the image format is
00537     if (ddsh.ddspf.dwFlags & DDS_FOURCC)
00538     {
00539         switch(ddsh.ddspf.dwFourCC)
00540         {
00541             case FOURCC_DXT1:
00542                 format = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
00543                 components = 3;
00544                 compressed = true;
00545                 break;
00546             case FOURCC_DXT3:
00547                 format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
00548                 components = 4;
00549                 compressed = true;
00550                 break;
00551             case FOURCC_DXT5:
00552                 format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
00553                 components = 4;
00554                 compressed = true;
00555                 break;
00556             default:
00557                 SWARNING << "ERROR: unknown compressed format(" << ddsh.ddspf.dwFourCC
00558                          << ")!" << endLog;
00559                 return false;
00560         }
00561     }
00562     else if (ddsh.ddspf.dwFlags == DDS_RGBA && ddsh.ddspf.dwRGBBitCount == 32)
00563     {
00564         format = Image::OSG_BGRA_PF;
00565         compressed = false;
00566         components = 4;
00567     }
00568     else if (ddsh.ddspf.dwFlags == DDS_RGB  && ddsh.ddspf.dwRGBBitCount == 32)
00569     {
00570         format = Image::OSG_BGRA_PF;
00571         compressed = false;
00572         components = 4;
00573     }
00574     else if (ddsh.ddspf.dwFlags == DDS_RGB  && ddsh.ddspf.dwRGBBitCount == 24)
00575     {
00576         format = Image::OSG_BGR_PF;
00577         compressed = false;
00578         components = 3;
00579     }
00580     else if (/*ddsh.ddspf.dwFlags == 0x20000  &&*/ ddsh.ddspf.dwRGBBitCount == 8)
00581     {
00582         format = Image::OSG_L_PF;
00583         compressed = false;
00584         components = 1;
00585     }
00586     else
00587     {
00588         SWARNING << "ERROR: unknown image format!" << endLog;
00589         return false;
00590     }
00591 
00592     // store primary surface width/height/depth
00593     width = ddsh.dwWidth;
00594     height = ddsh.dwHeight;
00595     depth = clamp_size(ddsh.dwDepth);   // set to 1 if 0
00596 
00597     // use correct size calculation function depending on whether image is
00598     // compressed
00599     sizefunc = (compressed ? &CDDSImage::size_dxtc : &CDDSImage::size_rgb);
00600 
00601     // load all surfaces for the image (6 surfaces for cubemaps)
00602     for (Int32 n = 0; n < (cubemap ? 6 : 1); n++)
00603     {
00604         Int32 size;
00605 
00606         // calculate surface size
00607         size = (this->*sizefunc)(width, height)*depth;
00608 
00609         // load surface
00610         CTexture img(width, height, depth, size);
00611         is.read(img, img.size);
00612 
00613         // data dump
00614         /*
00615         std::cerr << "Param: " 
00616                   << width << "x" << height 
00617                   << ", depth: " << depth
00618                   << ", size: " << size
00619                   << ", img.size: " << img.size
00620                   << ", img.pixels: " << ((unsigned long)(img.pixels))
00621                   << std::endl;
00622         */
00623 
00624         align_memory(&img);
00625 
00626         if ( (format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT) &&
00627              check_dxt1_alpha_data(img, img.size))
00628           format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
00629 
00630         if ((flipImage && !cubemap) || (flipCubeMap && cubemap))
00631             flip(img, img.width, img.height, img.depth, img.size);
00632 
00633         Int32 w = clamp_size(width >> 1);
00634         Int32 h = clamp_size(height >> 1);
00635         Int32 d = clamp_size(depth >> 1);
00636 
00637         // store number of mipmaps
00638         Int32 numMipmaps = ddsh.dwMipMapCount;
00639 
00640         // number of mipmaps in file includes main surface so decrease count
00641         // by one
00642         if (numMipmaps != 0)
00643             numMipmaps--;
00644 
00645         // load all mipmaps for current surface
00646         for (Int32 i = 0; i < numMipmaps && (w || h); i++)
00647         {
00648             // calculate mipmap size
00649             size = (this->*sizefunc)(w, h)*d;
00650 
00651             CSurface mipmap(w, h, d, size);
00652             is.read(mipmap, mipmap.size);
00653 
00654             if ((flipImage && !cubemap) || (flipCubeMap && cubemap))
00655             {
00656                 flip(mipmap, mipmap.width, mipmap.height, mipmap.depth,
00657                     mipmap.size);
00658             }
00659 
00660             img.mipmaps.push_back(mipmap);
00661 
00662             // shrink to next power of 2
00663             w = clamp_size(w >> 1);
00664             h = clamp_size(h >> 1);
00665             d = clamp_size(d >> 1);
00666         }
00667         
00668         images.push_back(img);
00669 
00670     }
00671 
00672     // swap cubemaps on y axis (since image is flipped in OGL)
00673     if (cubemap && swapCubeMap)
00674     {
00675         CTexture tmp;
00676         tmp = images[3];
00677         images[3] = images[2];
00678         images[2] = tmp;
00679     }
00680 
00681     valid = true;
00682 
00683     return true;
00684 }

void CDDSImage::clear ( void   ) 

Definition at line 688 of file OSGDDSImageFileType.cpp.

References components, compressed, cubemap, format, images, valid, and volume.

Referenced by load().

00689 {
00690     components = 0;
00691     format = 0;
00692     compressed = false;
00693     cubemap = false;
00694     volume = false;
00695     valid = false;
00696 
00697     images.clear();
00698 }

CDDSImage::operator char * (  ) 

Definition at line 714 of file OSGDDSImageFileType.cpp.

References images, and valid.

00715 {
00716     assert(valid);
00717 
00718     return images[0];
00719 }

CTexture & CDDSImage::operator[] ( Int32  index  ) 

Definition at line 703 of file OSGDDSImageFileType.cpp.

References images, and valid.

00704 {
00705     // make sure an image has been loaded
00706     assert(valid);
00707     assert(index < (Int32)images.size());
00708 
00709     return images[index];
00710 }

Int32 CDDSImage::get_num_images ( void   )  [inline]

Definition at line 237 of file OSGDDSImageFileType.cpp.

References images.

Referenced by osg::DDSImageFileType::read().

00237 { return (Int32)images.size(); }

CTexture& CDDSImage::get_image ( Int32  index  )  [inline]

Definition at line 238 of file OSGDDSImageFileType.cpp.

References images.

00239   {
00240     assert(index < (Int32)images.size());
00241     return images[index];
00242   }

Int32 CDDSImage::get_components (  )  [inline]

Definition at line 244 of file OSGDDSImageFileType.cpp.

References components.

Referenced by osg::DDSImageFileType::read().

00244 { return components; }

Int32 CDDSImage::get_format (  )  [inline]

Definition at line 245 of file OSGDDSImageFileType.cpp.

References format.

Referenced by osg::DDSImageFileType::read().

00245 { return format; }

bool CDDSImage::is_compressed (  )  [inline]

Definition at line 247 of file OSGDDSImageFileType.cpp.

References compressed.

Referenced by osg::DDSImageFileType::read().

00247 { return compressed; }

bool CDDSImage::is_cubemap (  )  [inline]

Definition at line 248 of file OSGDDSImageFileType.cpp.

References cubemap.

Referenced by osg::DDSImageFileType::read().

00248 { return cubemap; }

bool CDDSImage::is_volume (  )  [inline]

Definition at line 249 of file OSGDDSImageFileType.cpp.

References volume.

Referenced by osg::DDSImageFileType::read().

00249 { return volume; }

bool CDDSImage::is_valid (  )  [inline]

Definition at line 250 of file OSGDDSImageFileType.cpp.

References valid.

Referenced by osg::DDSImageFileType::read().

00250 { return valid; }

Int32 CDDSImage::clamp_size ( Int32  size  )  [inline, private]

Definition at line 724 of file OSGDDSImageFileType.cpp.

Referenced by load().

00725 {
00726     if (size <= 0)
00727         size = 1;
00728 
00729     return size;
00730 }

Int32 CDDSImage::get_line_width ( Int32  width,
Int32  bpp 
) [inline, private]

Definition at line 738 of file OSGDDSImageFileType.cpp.

Referenced by align_memory().

00739 {
00740     return ((width * bpp + 31) & -32) >> 3;
00741 }

Int32 CDDSImage::size_dxtc ( Int32  width,
Int32  height 
) [private]

Definition at line 745 of file OSGDDSImageFileType.cpp.

References format, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, and GL_COMPRESSED_RGBA_S3TC_DXT1_EXT.

Referenced by load().

00746 {
00747   Int32 comp( ( (format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) ||
00748                 (format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT) ) ? 8 : 16 );
00749 
00750   return ((width+3)/4)*((height+3)/4)*comp;
00751 
00752   //      (format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ? 8 : 16);
00753 }

Int32 CDDSImage::size_rgb ( Int32  width,
Int32  height 
) [private]

Definition at line 757 of file OSGDDSImageFileType.cpp.

References components.

Referenced by load().

00758 {
00759     return width*height*components;
00760 
00761 }

void CDDSImage::swap_endian ( void *  val  )  [inline, private]

Definition at line 765 of file OSGDDSImageFileType.cpp.

Referenced by load().

00766 {
00767 #if BYTE_ORDER == BIG_ENDIAN
00768     UInt32 *ival = (UInt32 *)val;
00769 
00770     *ival = ((*ival >> 24) & 0x000000ff) |
00771             ((*ival >>  8) & 0x0000ff00) |
00772             ((*ival <<  8) & 0x00ff0000) |
00773             ((*ival << 24) & 0xff000000);
00774 #endif
00775 }

void CDDSImage::align_memory ( CTexture surface  )  [private]

Definition at line 779 of file OSGDDSImageFileType.cpp.

References components, compressed, cubemap, CSurface::depth, get_line_width(), CSurface::height, CSurface::size, volume, and CSurface::width.

Referenced by load().

00780 {
00781     // don't bother with compressed images, volume textures, or cubemaps
00782     if (compressed || volume || cubemap)
00783         return;
00784 
00785     // calculate new image size
00786     Int32 linesize = get_line_width(surface->width, components*8);
00787     Int32 imagesize = linesize*surface->height;
00788 
00789     // exit if already aligned
00790     if (surface->size == imagesize)
00791         return;
00792 
00793     // create new image of new size
00794     CTexture newSurface(surface->width, surface->height, surface->depth,
00795         imagesize);
00796 
00797     // add pad bytes to end of each line
00798     char *srcimage = (char*)*surface;
00799     char *dstimage = (char*)newSurface;
00800     for (Int32 n = 0; n < surface->depth; n++)
00801     {
00802         char *curline = srcimage;
00803         char *newline = dstimage;
00804 
00805         Int32 imsize = surface->size / surface->depth;
00806         Int32 lnsize = imsize / surface->height;
00807 
00808         for (Int32 i = 0; i < surface->height; i++)
00809         {
00810             memcpy(newline, curline, lnsize);
00811             newline += linesize;
00812             curline += lnsize;
00813         }
00814     }
00815 
00816     // save padded image
00817     *surface = newSurface;
00818 }

void CDDSImage::flip ( char *  image,
Int32  width,
Int32  height,
Int32  depth,
Int32  size 
) [private]

Definition at line 862 of file OSGDDSImageFileType.cpp.

References compressed, flip_blocks_dxtc1(), flip_blocks_dxtc3(), flip_blocks_dxtc5(), format, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, and swap().

Referenced by load().

00863 {
00864     Int32 linesize;
00865     Int32 offset;
00866 
00867     if (!compressed)
00868     {
00869         assert(depth > 0);
00870 
00871         Int32 imagesize = size/depth;
00872         linesize = imagesize / height;
00873 
00874         for (Int32 n = 0; n < depth; n++)
00875         {
00876             offset = imagesize*n;
00877             char *top = image + offset;
00878             char *bottom = top + (imagesize-linesize);
00879 
00880             for (Int32 i = 0; i < (height >> 1); i++)
00881             {
00882                 swap(bottom, top, linesize);
00883 
00884                 top += linesize;
00885                 bottom -= linesize;
00886             }
00887         }
00888     }
00889     else
00890     {
00891         void (CDDSImage::*flipblocks)(DXTColBlock*, Int32);
00892         Int32 xblocks = width / 4;
00893         Int32 yblocks = height / 4;
00894         Int32 blocksize;
00895 
00896         switch (format)
00897         {
00898             case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
00899                 blocksize = 8;
00900                 flipblocks = &CDDSImage::flip_blocks_dxtc1;
00901                 break;
00902             case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
00903                 blocksize = 8;
00904                 flipblocks = &CDDSImage::flip_blocks_dxtc1;
00905                 break;
00906             case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
00907                 blocksize = 16;
00908                 flipblocks = &CDDSImage::flip_blocks_dxtc3;
00909                 break;
00910             case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
00911                 blocksize = 16;
00912                 flipblocks = &CDDSImage::flip_blocks_dxtc5;
00913                 break;
00914             default:
00915                 return;
00916         }
00917 
00918         linesize = xblocks * blocksize;
00919 
00920         DXTColBlock *top;
00921         DXTColBlock *bottom;
00922 
00923         for (Int32 j = 0; j < (yblocks >> 1); j++)
00924         {
00925             top = (DXTColBlock*)(image + j * linesize);
00926             bottom = (DXTColBlock*)(image + (((yblocks-j)-1) * linesize));
00927 
00928             (this->*flipblocks)(top, xblocks);
00929             (this->*flipblocks)(bottom, xblocks);
00930 
00931             swap(bottom, top, linesize);
00932         }
00933     }
00934 }

bool CDDSImage::check_dxt1_alpha_data ( char *  image,
Int32  size 
) [private]

Definition at line 822 of file OSGDDSImageFileType.cpp.

References FNOTICE, p, and DXTColBlock::row.

Referenced by load().

00823 {
00824   bool        hasAlpha(false);
00825   DXTColBlock *colBlock((DXTColBlock*)(image));
00826 
00827   for (unsigned i = 0, n = (size / 8); i < n; i++)
00828     if (colBlock[i].col0 <= colBlock[i].col1) 
00829     {
00830         for (unsigned j = 0; j < 4; j++) {
00831           UInt8 byte = colBlock[i].row[j];
00832           for (unsigned p = 0; p < 4; p++, byte >> 2) {
00833             if ((byte & 3) == 3) {
00834               hasAlpha = true;
00835               break;
00836             }
00837           }
00838         }
00839 
00840         if (hasAlpha) 
00841         {
00842           FNOTICE (( "Found alpha in DXT1 %d/%d, col0:%d, col1:%d\n",
00843                      i, n, colBlock[i].col0, colBlock[i].col1 ));
00844 
00845           for (unsigned j = 0; j < 4; j++) 
00846             FNOTICE (( "  DXT Col Index: %d %d %d %d\n",
00847                        ((colBlock[i].row[j] >> 0) & 3),
00848                        ((colBlock[i].row[j] >> 2) & 3),
00849                        ((colBlock[i].row[j] >> 4) & 3),
00850                        ((colBlock[i].row[j] >> 6) & 3) ));
00851         }
00852 
00853         if (hasAlpha)
00854           break;
00855     }
00856 
00857   return hasAlpha;
00858 }

void CDDSImage::swap ( void *  byte1,
void *  byte2,
Int32  size 
) [private]

Definition at line 938 of file OSGDDSImageFileType.cpp.

Referenced by flip(), flip_blocks_dxtc1(), flip_blocks_dxtc3(), and flip_blocks_dxtc5().

00939 {
00940     UInt8 *tmp = new UInt8[size];
00941 
00942     memcpy(tmp, byte1, size);
00943     memcpy(byte1, byte2, size);
00944     memcpy(byte2, tmp, size);
00945 
00946     delete [] tmp;
00947 }

void CDDSImage::flip_blocks_dxtc1 ( DXTColBlock line,
Int32  numBlocks 
) [private]

Definition at line 951 of file OSGDDSImageFileType.cpp.

References DXTColBlock::row, and swap().

Referenced by flip().

00952 {
00953     DXTColBlock *curblock = line;
00954 
00955     for (Int32 i = 0; i < numBlocks; i++)
00956     {
00957         swap(&curblock->row[0], &curblock->row[3], sizeof(UInt8));
00958         swap(&curblock->row[1], &curblock->row[2], sizeof(UInt8));
00959 
00960         curblock++;
00961     }
00962 }

void CDDSImage::flip_blocks_dxtc3 ( DXTColBlock line,
Int32  numBlocks 
) [private]

Definition at line 966 of file OSGDDSImageFileType.cpp.

References DXTColBlock::row, DXT3AlphaBlock::row, and swap().

Referenced by flip().

00967 {
00968     DXTColBlock *curblock = line;
00969     DXT3AlphaBlock *alphablock;
00970 
00971     for (Int32 i = 0; i < numBlocks; i++)
00972     {
00973         alphablock = (DXT3AlphaBlock*)curblock;
00974 
00975         swap(&alphablock->row[0], &alphablock->row[3], sizeof(UInt16));
00976         swap(&alphablock->row[1], &alphablock->row[2], sizeof(UInt16));
00977 
00978         curblock++;
00979 
00980         swap(&curblock->row[0], &curblock->row[3], sizeof(UInt8));
00981         swap(&curblock->row[1], &curblock->row[2], sizeof(UInt8));
00982 
00983         curblock++;
00984     }
00985 }

void CDDSImage::flip_blocks_dxtc5 ( DXTColBlock line,
Int32  numBlocks 
) [private]

Definition at line 1065 of file OSGDDSImageFileType.cpp.

References flip_dxt5_alpha(), DXTColBlock::row, and swap().

Referenced by flip().

01066 {
01067     DXTColBlock *curblock = line;
01068     DXT5AlphaBlock *alphablock;
01069 
01070     for (Int32 i = 0; i < numBlocks; i++)
01071     {
01072         alphablock = (DXT5AlphaBlock*)curblock;
01073 
01074         flip_dxt5_alpha(alphablock);
01075 
01076         curblock++;
01077 
01078         swap(&curblock->row[0], &curblock->row[3], sizeof(UInt8));
01079         swap(&curblock->row[1], &curblock->row[2], sizeof(UInt8));
01080 
01081         curblock++;
01082     }
01083 }

void CDDSImage::flip_dxt5_alpha ( DXT5AlphaBlock block  )  [private]

Definition at line 989 of file OSGDDSImageFileType.cpp.

References DXT5AlphaBlock::row.

Referenced by flip_blocks_dxtc5().

00990 {
00991     UInt8 gBits[4][4];
00992 
00993     const UInt32 mask = 0x00000007;          // bits = 00 00 01 11
00994     UInt32 bits = 0;
00995     memcpy(&bits, &block->row[0], sizeof(UInt8) * 3);
00996 
00997     gBits[0][0] = (UInt8)(bits & mask);
00998     bits >>= 3;
00999     gBits[0][1] = (UInt8)(bits & mask);
01000     bits >>= 3;
01001     gBits[0][2] = (UInt8)(bits & mask);
01002     bits >>= 3;
01003     gBits[0][3] = (UInt8)(bits & mask);
01004     bits >>= 3;
01005     gBits[1][0] = (UInt8)(bits & mask);
01006     bits >>= 3;
01007     gBits[1][1] = (UInt8)(bits & mask);
01008     bits >>= 3;
01009     gBits[1][2] = (UInt8)(bits & mask);
01010     bits >>= 3;
01011     gBits[1][3] = (UInt8)(bits & mask);
01012 
01013     bits = 0;
01014     memcpy(&bits, &block->row[3], sizeof(UInt8) * 3);
01015 
01016     gBits[2][0] = (UInt8)(bits & mask);
01017     bits >>= 3;
01018     gBits[2][1] = (UInt8)(bits & mask);
01019     bits >>= 3;
01020     gBits[2][2] = (UInt8)(bits & mask);
01021     bits >>= 3;
01022     gBits[2][3] = (UInt8)(bits & mask);
01023     bits >>= 3;
01024     gBits[3][0] = (UInt8)(bits & mask);
01025     bits >>= 3;
01026     gBits[3][1] = (UInt8)(bits & mask);
01027     bits >>= 3;
01028     gBits[3][2] = (UInt8)(bits & mask);
01029     bits >>= 3;
01030     gBits[3][3] = (UInt8)(bits & mask);
01031 
01032     UInt32 *pBits = ((UInt32*) &(block->row[0]));
01033 
01034     *pBits = *pBits | (gBits[3][0] << 0);
01035     *pBits = *pBits | (gBits[3][1] << 3);
01036     *pBits = *pBits | (gBits[3][2] << 6);
01037     *pBits = *pBits | (gBits[3][3] << 9);
01038 
01039     *pBits = *pBits | (gBits[2][0] << 12);
01040     *pBits = *pBits | (gBits[2][1] << 15);
01041     *pBits = *pBits | (gBits[2][2] << 18);
01042     *pBits = *pBits | (gBits[2][3] << 21);
01043 
01044     pBits = ((UInt32*) &(block->row[3]));
01045 
01046 #if BYTE_ORDER == BIG_ENDIAN
01047     *pBits &= 0x000000ff;
01048 #else
01049     *pBits &= 0xff000000;
01050 #endif
01051 
01052     *pBits = *pBits | (gBits[1][0] << 0);
01053     *pBits = *pBits | (gBits[1][1] << 3);
01054     *pBits = *pBits | (gBits[1][2] << 6);
01055     *pBits = *pBits | (gBits[1][3] << 9);
01056 
01057     *pBits = *pBits | (gBits[0][0] << 12);
01058     *pBits = *pBits | (gBits[0][1] << 15);
01059     *pBits = *pBits | (gBits[0][2] << 18);
01060     *pBits = *pBits | (gBits[0][3] << 21);
01061 }


Member Data Documentation

Int32 CDDSImage::format [private]

Definition at line 270 of file OSGDDSImageFileType.cpp.

Referenced by clear(), flip(), get_format(), load(), and size_dxtc().

Int32 CDDSImage::components [private]

Definition at line 271 of file OSGDDSImageFileType.cpp.

Referenced by align_memory(), clear(), get_components(), load(), and size_rgb().

bool CDDSImage::compressed [private]

Definition at line 272 of file OSGDDSImageFileType.cpp.

Referenced by align_memory(), clear(), flip(), is_compressed(), and load().

bool CDDSImage::cubemap [private]

Definition at line 273 of file OSGDDSImageFileType.cpp.

Referenced by align_memory(), clear(), is_cubemap(), and load().

bool CDDSImage::volume [private]

Definition at line 274 of file OSGDDSImageFileType.cpp.

Referenced by align_memory(), clear(), is_volume(), and load().

bool CDDSImage::valid [private]

Definition at line 275 of file OSGDDSImageFileType.cpp.

Referenced by clear(), is_valid(), load(), operator char *(), and operator[]().

std::vector<CTexture> CDDSImage::images [private]


The documentation for this class was generated from the following file:

Generated on Mon Mar 17 12:02:58 2008 for OpenSG by  doxygen 1.5.5