62 e.
add(
"Failed reading TPC file");
77 if ((width >= 0x8000) || (height >= 0x8000))
103 dataSize = width * height;
113 dataSize = width * height * 3;
123 dataSize = width * height * 4;
133 dataSize = width * height * 4;
135 throw Common::Exception(
"Unknown TPC raw encoding: %d (%d), %dx%d, %d", encoding, dataSize, width, height, mipMapCount);
171 size_t fullDataSize = tpc.
size() - 128;
172 if (fullDataSize < (
_layerCount * fullImageDataSize))
178 for (layerCount = 0; layerCount <
_layerCount; layerCount++) {
179 uint32 layerWidth = width;
180 uint32 layerHeight = height;
181 uint32 layerSize = dataSize;
183 for (
size_t i = 0; i < mipMapCount; i++) {
186 mipMap->width = MAX<uint32>(layerWidth, 1);
187 mipMap->height = MAX<uint32>(layerHeight, 1);
189 mipMap->size = MAX<uint32>(layerSize, minDataSize);
194 if ((fullDataSize < mipMap->size) || (mipMap->size < mipMapDataSize))
197 fullDataSize -= mipMap->size;
205 if ((layerWidth < 1) && (layerHeight < 1))
211 throw Common::Exception(
"Failed to correctly read all texture layers (%u, %u, %u, %u)",
241 if ((height == 0) || (width == 0) || ((height / width) != 6))
253 for (
uint32 y = 0; y < height; y++) {
254 for (
uint32 x = 0; x < width; x++) {
257 *dst++ = src[offset + 0];
258 *dst++ = src[offset + 1];
259 *dst++ = src[offset + 2];
260 *dst++ = src[offset + 3];
266 for (MipMaps::iterator mipMap =
_mipMaps.begin(); mipMap !=
_mipMaps.end(); ++mipMap) {
269 const bool widthPOT = ((*mipMap)->width & ((*mipMap)->width - 1)) == 0;
272 (*mipMap)->data.reset(
new byte[(*mipMap)->size]);
275 std::vector<byte> tmp((*mipMap)->size);
277 if (tpc.
read(&tmp[0], (*mipMap)->size) != (*mipMap)->size)
280 deSwizzle((*mipMap)->data.get(), &tmp[0], (*mipMap)->width, (*mipMap)->height);
283 if (tpc.
read((*mipMap)->data.get(), (*mipMap)->size) != (*mipMap)->size)
290 (*mipMap)->size = (*mipMap)->width * (*mipMap)->height * 3;
291 (*mipMap)->data.
reset(
new byte[(*mipMap)->size]);
293 for (
int i = 0; i < ((*mipMap)->width * (*mipMap)->height); i++)
294 std::memset((*mipMap)->data.get() + i * 3, dataGray[i], 3);
302 const size_t txiDataSize = tpc.
size() - tpc.
pos();
303 if (txiDataSize == 0)
336 if ((width !=
_mipMaps[index]->width ) ||
337 (height !=
_mipMaps[index]->height) ||
370 static const int rotation[6] = { 1, 3, 0, 2, 2, 0 };
372 rotate90(mipMap.data.get(), mipMap.width, mipMap.height, bpp, rotation[i]);
bool checkCubeMap(uint32 &width, uint32 &height)
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
uint32 readUint32LE()
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it...
void reset(PointerType o=0)
Resets the pointer with the new value.
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 void deSwizzle(byte *dst, const byte *src, uint32 width, uint32 height)
static bool hasValidDimensions(PixelFormatRaw format, int32 width, int32 height)
Are these image dimensions valid for this format?
Common::ScopedArray< byte > data
The mip map's data.
bool _isCubeMap
Is this image a cube map? A cube map always needs to have 6 layers!
Implementing the reading stream interfaces for plain memory blocks.
void swap(ScopedPtrBase< T, Deallocator > &right)
Swap the managed pointers of two ScopedPtrs of the same type.
static const byte kEncodingRGBA
void load(Common::SeekableReadStream &stream)
bool isCubeMap() const
Is this image a cube map?
size_t getLayerCount() const
Return the number of layers contained in the image.
Exception that provides a stack of explanations.
A simple scoped smart pointer template.
void decompress()
Manually decompress the texture image data.
void readData(Common::SeekableReadStream &tpc, byte encoding)
Basic exceptions to throw.
static uint32 deSwizzleOffset(uint32 x, uint32 y, uint32 width, uint32 height)
De-"swizzle" a texture pixel offset.
static void rotate90(byte *data, int width, int height, int bpp, int steps)
Rotate a square image in 90° steps, clock-wise.
TPC(Common::SeekableReadStream &tpc)
Utility templates and functions.
size_t _layerCount
Number of layers in this image.
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.
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.
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.
void readTXI(Common::SeekableReadStream &tpc)
void load(Common::SeekableReadStream &tpc)
TPC (BioWare's own texture format) loading.
static const byte kEncodingGray
static const byte kEncodingRGB
size_t getMipMapCount() const
Return the number of mip maps contained in the image.
void readHeader(Common::SeekableReadStream &tpc, byte &encoding)
static const byte kEncodingSwizzledBGRA
Interface for a seekable & readable data stream.
byte readByte()
Read an unsigned byte from the stream and return it.