63 e.
add(
"Failed reading DDS file");
89 if ((width >= 0x8000) || (height >= 0x8000))
123 for (
uint32 i = 0; i < mipMapCount; i++) {
126 mipMap->
width = MAX<uint32>(width , 1);
127 mipMap->
height = MAX<uint32>(height, 1);
139 #define IsPower2(x) ((x) && (((x) & ((x) - 1)) == 0)) 149 if ((width >= 0x8000) || (height >= 0x8000))
166 }
else if (bpp == 4) {
176 if (((bpp == 3) && (dataSize != ((width * height) / 2))) ||
177 ((bpp == 4) && (dataSize != ((width * height) ))))
178 throw Common::Exception(
"Invalid data size (%dx%dx%d %d)", width, height, bpp, dataSize);
186 size_t fullDataSize = dds.
size() - dds.
pos();
192 mipMap->width = MAX<uint32>(width, 1);
193 mipMap->height = MAX<uint32>(height, 1);
198 if (fullDataSize < mipMap->size)
201 fullDataSize -= mipMap->size;
208 }
while ((width >= 1) && (height >= 1));
218 for (MipMaps::iterator mipMap =
_mipMaps.begin(); mipMap !=
_mipMaps.end(); ++mipMap) {
219 (*mipMap)->data.reset(
new byte[(*mipMap)->size]);
223 byte *data = (*mipMap)->data.get();
224 for (
uint32 i = 0; i < (
uint32)((*mipMap)->width * (*mipMap)->height); i++, data += 4) {
227 data[0] = ( pixel & 0x0000000F ) << 4;
228 data[1] = ((pixel & 0x000000F0) >> 4) << 4;
229 data[2] = ((pixel & 0x00000F00) >> 8) << 4;
230 data[3] = ((pixel & 0x0000F000) >> 12) << 4;
234 if (dds.
read((*mipMap)->data.get(), (*mipMap)->size) != (*mipMap)->size)
292 warning(
"Found untested DDS RGB5A1 data");
304 warning(
"Found untested DDS RGB5 data");
#define MKTAG(a0, a1, a2, a3)
A wrapper macro used around four character constants, like 'DATA', to ensure portability.
uint16 readUint16LE()
Read an unsigned 16-bit word stored in little endian (LSB first) order from the stream and return it...
void add(const char *s,...) GCC_PRINTF(2
DDS texture (DirectDraw Surface or BioWare's own format) loading).
uint32 readUint32LE()
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it...
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
PointerType release()
Returns the plain pointer value and releases ScopedPtr.
static bool hasValidDimensions(PixelFormatRaw format, int32 width, int32 height)
Are these image dimensions valid for this format?
static const uint32 kPixelFlagsIsIndexed
void readStandardHeader(Common::SeekableReadStream &dds, DataType &dataType)
static const uint32 kDXT3ID
static const uint32 kPixelFlagsIsRGB
static const uint32 kPixelFlagsHasFourCC
void readData(Common::SeekableReadStream &dds, DataType dataType)
int height
The mip map's height.
Exception that provides a stack of explanations.
A simple scoped smart pointer template.
Basic exceptions to throw.
Utility templates and functions.
virtual size_t skip(ptrdiff_t offset)
Skip the specified number of bytes, adding that offset to the current position in the stream...
static const uint32 kDXT1ID
PixelFormatRaw _formatRaw
virtual size_t read(void *dataPtr, size_t dataSize)=0
Read data from the stream.
static const uint32 kPixelFlagsHasAlpha
Image related utility functions.
const Exception kReadError("Read error")
Exception when reading from a stream failed.
static const uint32 kDDSID
A scoped plain pointer, allowing pointer-y access and normal deletion.
void readHeader(Common::SeekableReadStream &dds, DataType &dataType)
void warning(const char *s,...)
virtual size_t size() const =0
Obtains the total size of the stream, measured in bytes.
static uint32 getDataSize(PixelFormatRaw format, int32 width, int32 height)
Return the number of bytes necessary to hold an image of these dimensions and in this format...
Basic reading stream interfaces.
virtual size_t pos() const =0
Obtains the current value of the stream position indicator of the stream.
uint32 readUint32BE()
Read an unsigned 32-bit word stored in big endian (MSB first) order from the stream and return it...
void setSize(MipMap &mipMap)
int width
The mip map's width.
void readBioWareHeader(Common::SeekableReadStream &dds, DataType &dataType)
static const uint32 kDXT5ID
DDS(Common::SeekableReadStream &dds)
static const uint32 kHeaderFlagsHasMipMaps
uint32 size
The mip map's size in bytes.
Interface for a seekable & readable data stream.
void detectFormat(const DDSPixelFormat &format, DataType &dataType)
void load(Common::SeekableReadStream &dds)