56 txb.
seek(dataSize + 128);
61 e.
add(
"Failed reading TXB file");
74 return width * height;
90 if ((width >= 0x8000) || (height >= 0x8000))
141 encoding, width, height, mipMapCount, dataSize);
147 if (dataSize < fullImageDataSize)
151 for (
uint32 i = 0; i < mipMapCount; i++) {
154 mipMap->width = width;
155 mipMap->height = height;
160 if (width > 1) width >>= 1;
161 if (height > 1) height >>= 1;
167 for (
uint32 y = 0; y < height; y++) {
168 for (
uint32 x = 0; x < width; x++) {
171 for (
uint8 p = 0; p < bpp; p++)
172 *dst++ = src[offset + p];
178 for (MipMaps::iterator mipMap =
_mipMaps.begin(); mipMap !=
_mipMaps.end(); ++mipMap) {
182 const bool widthPOT = ((*mipMap)->width & ((*mipMap)->width - 1)) == 0;
183 const bool swizzled = needDeSwizzle && widthPOT;
185 (*mipMap)->data.reset(
new byte[(*mipMap)->size]);
186 if (txb.
read((*mipMap)->data.get(), (*mipMap)->size) != (*mipMap)->size)
192 const uint32 oldSize = (*mipMap)->size;
193 const uint32 newSize = (*mipMap)->size * 3;
196 for (
uint32 i = 0; i < oldSize; i++)
197 tmp1[i * 3 + 0] = tmp1[i * 3 + 1] = tmp1[i * 3 + 2] = (*mipMap)->data[i];
201 deSwizzle(tmp2.
get(), tmp1.
get(), (*mipMap)->width, (*mipMap)->height, 3);
206 (*mipMap)->data.swap(tmp1);
207 (*mipMap)->size = newSize;
209 }
else if (swizzled) {
212 deSwizzle(tmp.
get(), (*mipMap)->data.get(), (*mipMap)->width, (*mipMap)->height, 4);
214 (*mipMap)->data.swap(tmp);
221 const size_t txiDataSize = txb.
size() - txb.
pos();
222 if (txiDataSize == 0)
uint16 readUint16LE()
Read an unsigned 16-bit word stored in little endian (LSB first) order from the stream and return it...
static const byte kEncodingGray
void add(const char *s,...) GCC_PRINTF(2
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.
MemoryReadStream * readStream(size_t dataSize)
Read the specified amount of data into a new[]'ed buffer which then is wrapped into a MemoryReadStrea...
static bool hasValidDimensions(PixelFormatRaw format, int32 width, int32 height)
Are these image dimensions valid for this format?
TXB(Common::SeekableReadStream &txb)
Implementing the reading stream interfaces for plain memory blocks.
void load(Common::SeekableReadStream &txb)
void swap(ScopedPtrBase< T, Deallocator > &right)
Swap the managed pointers of two ScopedPtrs of the same type.
void load(Common::SeekableReadStream &stream)
Exception that provides a stack of explanations.
A simple scoped smart pointer template.
Basic exceptions to throw.
static uint32 deSwizzleOffset(uint32 x, uint32 y, uint32 width, uint32 height)
De-"swizzle" a texture pixel offset.
void readTXI(Common::SeekableReadStream &txb)
Utility templates and functions.
TXB (another one of BioWare's own texture formats) loading.
static uint32 getTXBDataSize(byte encoding, PixelFormatRaw format, int32 width, int32 height)
virtual size_t skip(ptrdiff_t offset)
Skip the specified number of bytes, adding that offset to the current position in the stream...
PixelFormatRaw _formatRaw
virtual size_t read(void *dataPtr, size_t dataSize)=0
Read data from the stream.
static const byte kEncodingDXT5
static void deSwizzle(byte *dst, const byte *src, uint32 width, uint32 height, uint8 bpp)
Image related utility functions.
const Exception kReadError("Read error")
Exception when reading from a stream failed.
A scoped plain pointer, allowing pointer-y access and normal deletion.
void readData(Common::SeekableReadStream &txb, byte encoding)
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...
virtual size_t pos() const =0
Obtains the current value of the stream position indicator of the stream.
static const byte kEncodingBGRA
PointerType get() const
Returns the plain pointer value.
static const byte kEncodingDXT1
Interface for a seekable & readable data stream.
byte readByte()
Read an unsigned byte from the stream and return it.
void readHeader(Common::SeekableReadStream &txb, byte &encoding, uint32 &dataSize)