Commit f7d337d3 authored by hybrid's avatar hybrid

Fix 64bit problem with dds loader, not yet tested, though.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3731 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 20c0d588
...@@ -28,21 +28,21 @@ namespace irr ...@@ -28,21 +28,21 @@ namespace irr
namespace video namespace video
{ {
namespace
{
/*! /*!
DDSDecodePixelFormat() DDSDecodePixelFormat()
determines which pixel format the dds texture is in determines which pixel format the dds texture is in
*/ */
void DDSDecodePixelFormat( ddsBuffer *dds, eDDSPixelFormat *pf ) void DDSDecodePixelFormat( ddsBuffer *dds, eDDSPixelFormat *pf )
{ {
u32 fourCC;
/* dummy check */ /* dummy check */
if( dds == NULL || pf == NULL ) if( dds == NULL || pf == NULL )
return; return;
/* extract fourCC */ /* extract fourCC */
fourCC = dds->pixelFormat.fourCC; const u32 fourCC = dds->pixelFormat.fourCC;
/* test it */ /* test it */
if( fourCC == 0 ) if( fourCC == 0 )
...@@ -62,7 +62,6 @@ void DDSDecodePixelFormat( ddsBuffer *dds, eDDSPixelFormat *pf ) ...@@ -62,7 +62,6 @@ void DDSDecodePixelFormat( ddsBuffer *dds, eDDSPixelFormat *pf )
} }
/*! /*!
DDSGetInfo() DDSGetInfo()
extracts relevant info from a dds texture, returns 0 on success extracts relevant info from a dds texture, returns 0 on success
...@@ -93,7 +92,6 @@ s32 DDSGetInfo( ddsBuffer *dds, s32 *width, s32 *height, eDDSPixelFormat *pf ) ...@@ -93,7 +92,6 @@ s32 DDSGetInfo( ddsBuffer *dds, s32 *width, s32 *height, eDDSPixelFormat *pf )
} }
/*! /*!
DDSGetColorBlockColors() DDSGetColorBlockColors()
extracts colors from a dds color block extracts colors from a dds color block
...@@ -188,14 +186,13 @@ void DDSGetColorBlockColors( ddsColorBlock *block, ddsColor colors[ 4 ] ) ...@@ -188,14 +186,13 @@ void DDSGetColorBlockColors( ddsColorBlock *block, ddsColor colors[ 4 ] )
} }
/* /*
DDSDecodeColorBlock() DDSDecodeColorBlock()
decodes a dds color block decodes a dds color block
fixme: make endian-safe fixme: make endian-safe
*/ */
static void DDSDecodeColorBlock( u32 *pixel, ddsColorBlock *block, s32 width, u32 colors[ 4 ] ) void DDSDecodeColorBlock( u32 *pixel, ddsColorBlock *block, s32 width, u32 colors[ 4 ] )
{ {
s32 r, n; s32 r, n;
u32 bits; u32 bits;
...@@ -246,13 +243,11 @@ static void DDSDecodeColorBlock( u32 *pixel, ddsColorBlock *block, s32 width, u3 ...@@ -246,13 +243,11 @@ static void DDSDecodeColorBlock( u32 *pixel, ddsColorBlock *block, s32 width, u3
} }
/* /*
DDSDecodeAlphaExplicit() DDSDecodeAlphaExplicit()
decodes a dds explicit alpha block decodes a dds explicit alpha block
*/ */
void DDSDecodeAlphaExplicit( u32 *pixel, ddsAlphaBlockExplicit *alphaBlock, s32 width, u32 alphaZero )
static void DDSDecodeAlphaExplicit( u32 *pixel, ddsAlphaBlockExplicit *alphaBlock, s32 width, u32 alphaZero )
{ {
s32 row, pix; s32 row, pix;
u16 word; u16 word;
...@@ -279,7 +274,6 @@ static void DDSDecodeAlphaExplicit( u32 *pixel, ddsAlphaBlockExplicit *alphaBloc ...@@ -279,7 +274,6 @@ static void DDSDecodeAlphaExplicit( u32 *pixel, ddsAlphaBlockExplicit *alphaBloc
*pixel |= *((u32*) &color); *pixel |= *((u32*) &color);
word >>= 4; /* move next bits to lowest 4 */ word >>= 4; /* move next bits to lowest 4 */
pixel++; /* move to next pixel in the row */ pixel++; /* move to next pixel in the row */
} }
} }
} }
...@@ -290,8 +284,7 @@ static void DDSDecodeAlphaExplicit( u32 *pixel, ddsAlphaBlockExplicit *alphaBloc ...@@ -290,8 +284,7 @@ static void DDSDecodeAlphaExplicit( u32 *pixel, ddsAlphaBlockExplicit *alphaBloc
DDSDecodeAlpha3BitLinear() DDSDecodeAlpha3BitLinear()
decodes interpolated alpha block decodes interpolated alpha block
*/ */
void DDSDecodeAlpha3BitLinear( u32 *pixel, ddsAlphaBlock3BitLinear *alphaBlock, s32 width, u32 alphaZero )
static void DDSDecodeAlpha3BitLinear( u32 *pixel, ddsAlphaBlock3BitLinear *alphaBlock, s32 width, u32 alphaZero )
{ {
s32 row, pix; s32 row, pix;
...@@ -300,7 +293,6 @@ static void DDSDecodeAlpha3BitLinear( u32 *pixel, ddsAlphaBlock3BitLinear *alpha ...@@ -300,7 +293,6 @@ static void DDSDecodeAlpha3BitLinear( u32 *pixel, ddsAlphaBlock3BitLinear *alpha
u16 alphas[ 8 ]; u16 alphas[ 8 ];
ddsColor aColors[ 4 ][ 4 ]; ddsColor aColors[ 4 ][ 4 ];
/* get initial alphas */ /* get initial alphas */
alphas[ 0 ] = alphaBlock->alpha0; alphas[ 0 ] = alphaBlock->alpha0;
alphas[ 1 ] = alphaBlock->alpha1; alphas[ 1 ] = alphaBlock->alpha1;
...@@ -397,7 +389,6 @@ static void DDSDecodeAlpha3BitLinear( u32 *pixel, ddsAlphaBlock3BitLinear *alpha ...@@ -397,7 +389,6 @@ static void DDSDecodeAlpha3BitLinear( u32 *pixel, ddsAlphaBlock3BitLinear *alpha
} }
/* /*
DDSDecompressDXT1() DDSDecompressDXT1()
decompresses a dxt1 format texture decompresses a dxt1 format texture
...@@ -409,7 +400,6 @@ s32 DDSDecompressDXT1( ddsBuffer *dds, s32 width, s32 height, u8 *pixels ) ...@@ -409,7 +400,6 @@ s32 DDSDecompressDXT1( ddsBuffer *dds, s32 width, s32 height, u8 *pixels )
ddsColorBlock *block; ddsColorBlock *block;
ddsColor colors[ 4 ]; ddsColor colors[ 4 ];
/* setup */ /* setup */
xBlocks = width / 4; xBlocks = width / 4;
yBlocks = height / 4; yBlocks = height / 4;
...@@ -418,7 +408,7 @@ s32 DDSDecompressDXT1( ddsBuffer *dds, s32 width, s32 height, u8 *pixels ) ...@@ -418,7 +408,7 @@ s32 DDSDecompressDXT1( ddsBuffer *dds, s32 width, s32 height, u8 *pixels )
for( y = 0; y < yBlocks; y++ ) for( y = 0; y < yBlocks; y++ )
{ {
/* 8 bytes per block */ /* 8 bytes per block */
block = (ddsColorBlock*) ((u32) dds->data + y * xBlocks * 8); block = (ddsColorBlock*) (dds->data + y * xBlocks * 8);
/* walk x */ /* walk x */
for( x = 0; x < xBlocks; x++, block++ ) for( x = 0; x < xBlocks; x++, block++ )
...@@ -434,7 +424,6 @@ s32 DDSDecompressDXT1( ddsBuffer *dds, s32 width, s32 height, u8 *pixels ) ...@@ -434,7 +424,6 @@ s32 DDSDecompressDXT1( ddsBuffer *dds, s32 width, s32 height, u8 *pixels )
} }
/* /*
DDSDecompressDXT3() DDSDecompressDXT3()
decompresses a dxt3 format texture decompresses a dxt3 format texture
...@@ -448,7 +437,6 @@ s32 DDSDecompressDXT3( ddsBuffer *dds, s32 width, s32 height, u8 *pixels ) ...@@ -448,7 +437,6 @@ s32 DDSDecompressDXT3( ddsBuffer *dds, s32 width, s32 height, u8 *pixels )
ddsAlphaBlockExplicit *alphaBlock; ddsAlphaBlockExplicit *alphaBlock;
ddsColor colors[ 4 ]; ddsColor colors[ 4 ];
/* setup */ /* setup */
xBlocks = width / 4; xBlocks = width / 4;
yBlocks = height / 4; yBlocks = height / 4;
...@@ -464,7 +452,7 @@ s32 DDSDecompressDXT3( ddsBuffer *dds, s32 width, s32 height, u8 *pixels ) ...@@ -464,7 +452,7 @@ s32 DDSDecompressDXT3( ddsBuffer *dds, s32 width, s32 height, u8 *pixels )
for( y = 0; y < yBlocks; y++ ) for( y = 0; y < yBlocks; y++ )
{ {
/* 8 bytes per block, 1 block for alpha, 1 block for color */ /* 8 bytes per block, 1 block for alpha, 1 block for color */
block = (ddsColorBlock*) ((u32) dds->data + y * xBlocks * 16); block = (ddsColorBlock*) (dds->data + y * xBlocks * 16);
/* walk x */ /* walk x */
for( x = 0; x < xBlocks; x++, block++ ) for( x = 0; x < xBlocks; x++, block++ )
...@@ -490,7 +478,6 @@ s32 DDSDecompressDXT3( ddsBuffer *dds, s32 width, s32 height, u8 *pixels ) ...@@ -490,7 +478,6 @@ s32 DDSDecompressDXT3( ddsBuffer *dds, s32 width, s32 height, u8 *pixels )
} }
/* /*
DDSDecompressDXT5() DDSDecompressDXT5()
decompresses a dxt5 format texture decompresses a dxt5 format texture
...@@ -503,7 +490,6 @@ s32 DDSDecompressDXT5( ddsBuffer *dds, s32 width, s32 height, u8 *pixels ) ...@@ -503,7 +490,6 @@ s32 DDSDecompressDXT5( ddsBuffer *dds, s32 width, s32 height, u8 *pixels )
ddsAlphaBlock3BitLinear *alphaBlock; ddsAlphaBlock3BitLinear *alphaBlock;
ddsColor colors[ 4 ]; ddsColor colors[ 4 ];
/* setup */ /* setup */
xBlocks = width / 4; xBlocks = width / 4;
yBlocks = height / 4; yBlocks = height / 4;
...@@ -519,7 +505,7 @@ s32 DDSDecompressDXT5( ddsBuffer *dds, s32 width, s32 height, u8 *pixels ) ...@@ -519,7 +505,7 @@ s32 DDSDecompressDXT5( ddsBuffer *dds, s32 width, s32 height, u8 *pixels )
for( y = 0; y < yBlocks; y++ ) for( y = 0; y < yBlocks; y++ )
{ {
/* 8 bytes per block, 1 block for alpha, 1 block for color */ /* 8 bytes per block, 1 block for alpha, 1 block for color */
block = (ddsColorBlock*) ((u32) dds->data + y * xBlocks * 16); block = (ddsColorBlock*) (dds->data + y * xBlocks * 16);
/* walk x */ /* walk x */
for( x = 0; x < xBlocks; x++, block++ ) for( x = 0; x < xBlocks; x++, block++ )
...@@ -545,62 +531,49 @@ s32 DDSDecompressDXT5( ddsBuffer *dds, s32 width, s32 height, u8 *pixels ) ...@@ -545,62 +531,49 @@ s32 DDSDecompressDXT5( ddsBuffer *dds, s32 width, s32 height, u8 *pixels )
} }
/* /*
DDSDecompressDXT2() DDSDecompressDXT2()
decompresses a dxt2 format texture (fixme: un-premultiply alpha) decompresses a dxt2 format texture (fixme: un-premultiply alpha)
*/ */
s32 DDSDecompressDXT2( ddsBuffer *dds, s32 width, s32 height, u8 *pixels ) s32 DDSDecompressDXT2( ddsBuffer *dds, s32 width, s32 height, u8 *pixels )
{ {
s32 r;
/* decompress dxt3 first */ /* decompress dxt3 first */
r = DDSDecompressDXT3( dds, width, height, pixels ); const s32 r = DDSDecompressDXT3( dds, width, height, pixels );
/* return to sender */ /* return to sender */
return r; return r;
} }
/* /*
DDSDecompressDXT4() DDSDecompressDXT4()
decompresses a dxt4 format texture (fixme: un-premultiply alpha) decompresses a dxt4 format texture (fixme: un-premultiply alpha)
*/ */
s32 DDSDecompressDXT4( ddsBuffer *dds, s32 width, s32 height, u8 *pixels ) s32 DDSDecompressDXT4( ddsBuffer *dds, s32 width, s32 height, u8 *pixels )
{ {
s32 r;
/* decompress dxt5 first */ /* decompress dxt5 first */
r = DDSDecompressDXT5( dds, width, height, pixels ); const s32 r = DDSDecompressDXT5( dds, width, height, pixels );
/* return to sender */ /* return to sender */
return r; return r;
} }
/* /*
DDSDecompressARGB8888() DDSDecompressARGB8888()
decompresses an argb 8888 format texture decompresses an argb 8888 format texture
*/ */
s32 DDSDecompressARGB8888( ddsBuffer *dds, s32 width, s32 height, u8 *pixels ) s32 DDSDecompressARGB8888( ddsBuffer *dds, s32 width, s32 height, u8 *pixels )
{ {
s32 x, y;
u8 *in, *out;
/* setup */ /* setup */
in = dds->data; u8* in = dds->data;
out = pixels; u8* out = pixels;
/* walk y */ /* walk y */
for( y = 0; y < height; y++ ) for(s32 y = 0; y < height; y++)
{ {
/* walk x */ /* walk x */
for( x = 0; x < width; x++ ) for(s32 x = 0; x < width; x++)
{ {
*out++ = *in++; *out++ = *in++;
*out++ = *in++; *out++ = *in++;
...@@ -614,20 +587,18 @@ s32 DDSDecompressARGB8888( ddsBuffer *dds, s32 width, s32 height, u8 *pixels ) ...@@ -614,20 +587,18 @@ s32 DDSDecompressARGB8888( ddsBuffer *dds, s32 width, s32 height, u8 *pixels )
} }
/* /*
DDSDecompress() DDSDecompress()
decompresses a dds texture into an rgba image buffer, returns 0 on success decompresses a dds texture into an rgba image buffer, returns 0 on success
*/ */
s32 DDSDecompress( ddsBuffer *dds, u8 *pixels ) s32 DDSDecompress( ddsBuffer *dds, u8 *pixels )
{ {
s32 width, height, r; s32 width, height;
eDDSPixelFormat pf; eDDSPixelFormat pf;
/* get dds info */ /* get dds info */
r = DDSGetInfo( dds, &width, &height, &pf ); s32 r = DDSGetInfo( dds, &width, &height, &pf );
if( r ) if ( r )
return r; return r;
/* decompress */ /* decompress */
...@@ -669,6 +640,9 @@ s32 DDSDecompress( ddsBuffer *dds, u8 *pixels ) ...@@ -669,6 +640,9 @@ s32 DDSDecompress( ddsBuffer *dds, u8 *pixels )
return r; return r;
} }
} // end anonymous namespace
//! returns true if the file maybe is able to be loaded by this class //! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga") //! based on the file extension (e.g. ".tga")
bool CImageLoaderDDS::isALoadableFileExtension(const io::path& filename) const bool CImageLoaderDDS::isALoadableFileExtension(const io::path& filename) const
...@@ -677,8 +651,6 @@ bool CImageLoaderDDS::isALoadableFileExtension(const io::path& filename) const ...@@ -677,8 +651,6 @@ bool CImageLoaderDDS::isALoadableFileExtension(const io::path& filename) const
} }
//! returns true if the file maybe is able to be loaded by this class //! returns true if the file maybe is able to be loaded by this class
bool CImageLoaderDDS::isALoadableFileFormat(io::IReadFile* file) const bool CImageLoaderDDS::isALoadableFileFormat(io::IReadFile* file) const
{ {
...@@ -691,11 +663,10 @@ bool CImageLoaderDDS::isALoadableFileFormat(io::IReadFile* file) const ...@@ -691,11 +663,10 @@ bool CImageLoaderDDS::isALoadableFileFormat(io::IReadFile* file) const
s32 width, height; s32 width, height;
eDDSPixelFormat pixelFormat; eDDSPixelFormat pixelFormat;
return 0 == DDSGetInfo( &header, &width, &height, &pixelFormat); return (0 == DDSGetInfo( &header, &width, &height, &pixelFormat));
} }
//! creates a surface from the file //! creates a surface from the file
IImage* CImageLoaderDDS::loadImage(io::IReadFile* file) const IImage* CImageLoaderDDS::loadImage(io::IReadFile* file) const
{ {
...@@ -727,7 +698,7 @@ IImage* CImageLoaderDDS::loadImage(io::IReadFile* file) const ...@@ -727,7 +698,7 @@ IImage* CImageLoaderDDS::loadImage(io::IReadFile* file) const
} }
//! creates a loader which is able to load tgas //! creates a loader which is able to load dds images
IImageLoader* createImageLoaderDDS() IImageLoader* createImageLoaderDDS()
{ {
return new CImageLoaderDDS(); return new CImageLoaderDDS();
...@@ -738,4 +709,3 @@ IImageLoader* createImageLoaderDDS() ...@@ -738,4 +709,3 @@ IImageLoader* createImageLoaderDDS()
} // end namespace irr } // end namespace irr
#endif #endif
...@@ -9,13 +9,13 @@ ...@@ -9,13 +9,13 @@
#include "IImageLoader.h" #include "IImageLoader.h"
#define _IRR_COMPILE_WITH_DDS_LOADER_
namespace irr namespace irr
{ {
namespace video namespace video
{ {
#if defined(_IRR_COMPILE_WITH_DDS_LOADER_) || defined(_IRR_COMPILE_WITH_DDS_WRITER_) #if defined(_IRR_COMPILE_WITH_DDS_LOADER_)
// byte-align structures // byte-align structures
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
...@@ -195,13 +195,6 @@ struct ddsColor ...@@ -195,13 +195,6 @@ struct ddsColor
} PACK_STRUCT; } PACK_STRUCT;
/* public functions */
s32 DDSGetInfo( ddsBuffer *dds, s32 *width, s32 *height, eDDSPixelFormat *pf );
s32 DDSDecompress( ddsBuffer *dds, u8 *pixels );
/* endian tomfoolery */ /* endian tomfoolery */
typedef union typedef union
{ {
...@@ -295,7 +288,7 @@ floatSwapUnion; ...@@ -295,7 +288,7 @@ floatSwapUnion;
#ifdef _IRR_COMPILE_WITH_DDS_LOADER_ #ifdef _IRR_COMPILE_WITH_DDS_LOADER_
/*! /*!
Surface Loader for targa images Surface Loader for DDS images
*/ */
class CImageLoaderDDS : public IImageLoader class CImageLoaderDDS : public IImageLoader
{ {
...@@ -315,7 +308,7 @@ private: ...@@ -315,7 +308,7 @@ private:
}; };
#endif // compiled with loader #endif // compiled with DDS loader
} // end namespace video } // end namespace video
} // end namespace irr } // end namespace irr
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment