77 texture(&t), nsbtx(&n), stream(&s) {
143 for (
uint32 n = 0; n < 4; n++, x++, pixels >>= 2) {
144 const uint8 pixel = pixels & 3;
164 for (
uint32 n = 0; n < 2; n++, x++, pixels >>= 4) {
165 const uint8 pixel = pixels & 0xF;
201 const byte r = ( pixel & 0x1F) << 3;
202 const byte g = ((pixel >> 5) & 0x1F) << 3;
203 const byte b = ((pixel >> 10) & 0x1F) << 3;
205 const byte a = ((pixel >> 15) == 0) ? 0x00 : 0xFF;
217 const uint8 index = pixel & 0x1F;
223 const byte a = (((pixel >> 5) << 2) + (pixel >> 6)) << 3;
235 const uint8 index = pixel & 0x07;
241 const byte a = (pixel >> 3) << 3;
249 std::vector<Common::UString> palNames;
251 palNames.push_back(texture.
name);
252 palNames.push_back(texture.
name +
"_pl");
253 palNames.push_back(texture.
name +
"_p");
254 palNames.push_back(texture.
name +
"_");
256 for (std::vector<Common::UString>::iterator n = palNames.begin(); n != palNames.end(); ++n)
265 static const uint16 kPaletteSize[] = { 0, 32, 4, 16, 256, 256, 8, 0 };
276 memset(palData.get(), 0, size);
282 for (
uint16 i = 0; i < palDataSize; i += 3) {
285 palData[i + 0] = ( pixel & 0x1F) << 3;
286 palData[i + 1] = ((pixel >> 5) & 0x1F) << 3;
287 palData[i + 2] = ((pixel >> 10) & 0x1F) << 3;
353 e.
add(
"Failed reading NSBTX file");
374 if ((versionMajor != 1) || (versionMinor != 0))
375 throw Common::Exception(
"Unsupported version %u.%u", versionMajor, versionMinor);
382 if (headerSize != 16)
386 if (sectionCount != 1)
399 nsbtx.
skip(4 + 4 + 2);
427 nsbtx.
skip(2 + 2 + 4 + textureCount * (2 + 2));
443 t->width = 8 << ((flags >> 4) & 7);
444 t->height = 8 << ((flags >> 7) & 7);
446 t->format = (
Format) ((flags >> 10) & 7);
448 t->wrapX = ( flags & 1) != 0;
449 t->wrapY = ((flags >> 1) & 1) != 0;
450 t->flipX = ((flags >> 2) & 1) != 0;
451 t->flipY = ((flags >> 3) & 1) != 0;
452 t->alpha = ((flags >> 13) & 1) != 0;
454 t->coordTransform = (
Transform) (flags >> 14);
456 if (t->width == 0x00) {
457 switch (unknown & 0x3) {
467 if (t->height == 0x00) {
468 switch ((unknown >> 4) & 0x3) {
491 nsbtx.
skip(2 + 2 + 4 + paletteCount * (2 + 2));
500 const uint8 paletteStep = ((flags & 1) != 0) ? 16 : 8;
512 ResourceList::iterator res =
_resources.begin();
513 Textures::iterator tex =
_textures.begin();
517 res->name = tex->name;
Common::WriteStream * stream
static void writeITEXHeader(const ReadContext &ctx)
#define MKTAG(a0, a1, a2, a3)
A wrapper macro used around four character constants, like 'DATA', to ensure portability.
const ResourceList & getResources() const
Return the list of resources.
Common::ScopedPtr< Common::SeekableSubReadStreamEndian > _nsbtx
The name of the NSBTX file.
void add(const char *s,...) GCC_PRINTF(2
NSBTXFile(Common::SeekableReadStream *nsbtx)
Take over this stream and read an NSBTX file out of it.
This is a wrapper around SeekableSubReadStream, but it adds non-endian read methods whose endianness ...
3bit alpha + 5bit color index.
A stream that dynamically grows as it's written to.
uint32 _textureInfoOffset
void reset(PointerType o=0)
Resets the pointer with the new value.
bool flipY
true: flip on every 2nd texture wrap.
void readPalettes(Common::SeekableSubReadStreamEndian &nsbtx)
Common::SeekableReadStream * getResource(uint32 index, bool tryNoCopy=false) const
Return a stream of the resource's contents.
void load(Common::SeekableSubReadStreamEndian &nsbtx)
const Palette * findPalette(const Texture &texture) const
void readTextures(Common::SeekableSubReadStreamEndian &nsbtx)
bool alpha
true: color index 0 is transparent.
Implementing the reading stream interfaces for plain memory blocks.
uint32 _paletteInfoOffset
Treat Nintendo NSBTX files, which contain multiple textures as an archive of intermediate textures...
void readHeader(Common::SeekableSubReadStreamEndian &nsbtx)
size_t pos() const
Obtains the current value of the stream position indicator of the stream.
static void getTexture16bpp(const ReadContext &ctx)
static const uint32 kXEOSID
static void getTextureA3I5(const ReadContext &ctx)
Utility templates and functions for working with strings and streams.
Exception that provides a stack of explanations.
size_t size() const
Obtains the total size of the stream, measured in bytes.
static void getTexture4bpp(const ReadContext &ctx)
void readFileHeader(Common::SeekableSubReadStreamEndian &nsbtx)
size_t size() const
Return the number of bytes written to this stream in total.
Basic exceptions to throw.
static const uint32 kBTX0ID
void createResourceList()
const char * c_str() const
Return the (utf8 encoded) string data.
size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)
Sets the stream position indicator for the stream.
Utility templates and functions.
Implementing the writing stream interfaces for memory blocks.
bool wrapY
true: wrap, false: clamp.
uint32 _paletteDataOffset
static const uint32 kITEXID
std::list< Resource > ResourceList
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 kTEX0ID
uint32 _textureDataOffset
Simple memory based 'stream', which implements the ReadStream interface for a plain memory block...
Utility functions for working with differing string encodings.
ResourceList _resources
External list of resource names and types.
void getPalette(ReadContext &ctx) const
void setDisposable(bool disposeMemory)
void writeByte(byte value)
void readInfoHeader(Common::SeekableSubReadStreamEndian &nsbtx)
bool flipX
true: flip on every 2nd texture wrap.
Generic interface for a writable data stream.
uint32 readUint32BE()
Read an unsigned 32-bit word stored in big endian (MSB first) order from the stream and return it...
static void getTexture2bpp(const ReadContext &ctx)
static const uint32 kXEOSITEXHeaderSize
static const uint32 kXEOSITEXMipMapHeaderSize
uint32 getResourceSize(uint32 index) const
Return the size of a resource.
Common::SeekableSubReadStreamEndian * nsbtx
ReadContext(Common::SeekableSubReadStreamEndian &n, const Texture &t, Common::WriteStream &s)
Plain, unextended ASCII (7bit clean).
UString toLower() const
Return a lowercased copy of the string.
Common::ScopedArray< const byte > palette
UString debugTag(uint32 tag, bool trim)
Create an elaborate string from an integer tag, for debugging purposes.
static void getTexture(const ReadContext &ctx)
UString readStringFixed(SeekableReadStream &stream, Encoding encoding, size_t length)
Read length bytes as a string with the given encoding out of a stream.
void writeUint32BE(uint32 value)
static uint32 getITEXSize(const Texture &texture)
static Common::SeekableSubReadStreamEndian * open(Common::SeekableReadStream &stream)
Treat this stream as a Nitro file and return an endian'd stream according to its BOM.
bool wrapX
true: wrap, false: clamp.
Interface for a seekable & readable data stream.
void writeUint32LE(uint32 value)
static void writePixel(const ReadContext &ctx, byte r, byte g, byte b, byte a)
byte readByte()
Read an unsigned byte from the stream and return it.
static void getTexture8bpp(const ReadContext &ctx)
5bit alpha + 3bit color index.
static void getTextureA5I3(const ReadContext &ctx)