--- Irrlicht.old/CImageLoaderDDS.h 2005-12-22 11:39:22.086264785 +0100 +++ Irrlicht/CImageLoaderDDS.h 2005-12-20 20:45:22.000000000 +0100 @@ -0,0 +1,91 @@ +#ifndef __C_IMAGE_LOADER_DDS_H_INCLUDED__ +#define __C_IMAGE_LOADER_DDS_H_INCLUDED__ + +#include "IImageLoader.h" + + +namespace irr +{ +namespace video +{ + + // byte-align structures +#ifdef _MSC_VER +# pragma pack( push, packing ) +# pragma pack( 1 ) +# define PACK_STRUCT +#elif defined( __GNUC__ ) +# define PACK_STRUCT __attribute__((packed)) +#else +# error compiler not supported +#endif + +struct ddsHeader{ + unsigned Magic; + unsigned HeaderSize; + unsigned DDSFlags; + unsigned Height; + unsigned Width; + unsigned Size; + unsigned Depth; + unsigned MipMapCount; + unsigned Reserved[11]; + + unsigned PFSize; + unsigned PFFlags; + unsigned FourCC; + unsigned RGBBitCount; + unsigned RBitMask; + unsigned GBitMask; + unsigned BBitMask; + unsigned AlphaBitMask; + + unsigned Caps1; + unsigned Caps2; + unsigned DDSX; + unsigned Whatever[2]; +}; + + +// Default alignment +#ifdef _MSC_VER +# pragma pack( pop, packing ) +#endif + +#undef PACK_STRUCT + + +/*! + Surface Loader for Microsoft DDS bitmaps +*/ +class CImageLoaderDDS : public IImageLoader +{ +public: + + //! constructor + CImageLoaderDDS(); + + //! destructor + virtual ~CImageLoaderDDS(); + + //! returns true if the file maybe is able to be loaded by this class + //! based on the file extension (e.g. ".tga") + virtual bool isALoadableFileExtension(const c8* fileName); + + //! returns true if the file maybe is able to be loaded by this class + virtual bool isALoadableFileFormat(irr::io::IReadFile* file); + + //! creates a surface from the file + virtual IImage* loadImage(irr::io::IReadFile* file); + +private: + c8* DDSData; +}; + + +} // end namespace video +} // end namespace irr + + +#endif + --- Irrlicht.old/CImageLoaderDDS.cpp 2005-12-22 11:39:24.442931589 +0100 +++ Irrlicht/CImageLoaderDDS.cpp 2005-12-21 08:38:52.000000000 +0100 @@ -0,0 +1,85 @@ +// Copyright (C) 2002-2005 Nikolaus Gebhardt +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in irrlicht.h + +#include "CImageLoaderDDS.h" +#include +#include "SColor.h" +#include "CColorConverter.h" +#include "CImage.h" +#include "os.h" + +namespace irr +{ +namespace video +{ + + +//! constructor +CImageLoaderDDS::CImageLoaderDDS() +: DDSData(0) +{ + #ifdef _DEBUG + setDebugName("CImageLoaderDDS"); + #endif +} + +//! destructor +CImageLoaderDDS::~CImageLoaderDDS() +{ + if (DDSData)delete [] DDSData; +} + +//! returns true if the file maybe is able to be loaded by this class +//! based on the file extension (e.g. ".tga") +bool CImageLoaderDDS::isALoadableFileExtension(const c8* fileName) +{ + return strstr(fileName, ".dds") != 0; +} + +//! returns true if the file maybe is able to be loaded by this class +bool CImageLoaderDDS::isALoadableFileFormat(irr::io::IReadFile* file) +{ + u32 headerID; + file->read(&headerID, sizeof(u32)); + return headerID == 0x20534444; +} + +//! creates a surface from the file +IImage* CImageLoaderDDS::loadImage(irr::io::IReadFile* file) +{ + ddsHeader header; + file->read(&header, sizeof(header)); + + EIMAGE_TYPE type = EIT_IMAGE_2D; + if (header.Magic != 0x20534444) return 0; + if (header.MipMapCount>1) header.Size<<=1; + if (header.Caps2) { + header.Size*=6; + type=EIT_CUBE_MAP; + } + + ECOLOR_FORMAT fmt = ECF_BGRA8; + switch(header.FourCC) { + case 0x31545844: fmt = ECF_DXT1; break; + case 0x33545844: fmt = ECF_DXT3; break; + case 0x35545844: fmt = ECF_DXT5; break; + } + + IImage* image = new CImage(fmt, core::dimension2d(header.Width, header.Height), + header.Size, header.MipMapCount, type); + file->read(image->lock(), header.Size); + image->unlock(); + return image; +} + + +//! creates a loader which is able to load windows bitmaps +IImageLoader* createImageLoaderDDS() +{ + return new CImageLoaderDDS; +} + + +} // end namespace video +} // end namespace irr --- Irrlicht.old/CNullDriver.cpp 2005-11-27 12:01:00.000000000 +0100 +++ Irrlicht/CNullDriver.cpp 2005-12-21 08:45:32.000000000 +0100 @@ -27,6 +27,8 @@ IImageLoader* createImageLoaderPCX(); //! creates a loader which is able to load png images IImageLoader* createImageLoaderPNG(); +//! creates a loader which is able to load dds images +IImageLoader* createImageLoaderDDS(); @@ -57,6 +59,7 @@ SurfaceLoader.push_back(video::createImageLoaderPSD()); SurfaceLoader.push_back(video::createImageLoaderPCX()); SurfaceLoader.push_back(video::createImageLoaderPNG()); + SurfaceLoader.push_back(video::createImageLoaderDDS()); // set ExposedData to 0 memset(&ExposedData, 0, sizeof(ExposedData));