77 load(ncgrs, width, height, nclr);
79 e.
add(
"Failed reading NCGR files");
85 std::vector<Common::SeekableReadStream *> ncgrs;
86 ncgrs.push_back(&ncgr);
89 load(ncgrs, 1, 1, nclr);
91 e.
add(
"Failed reading NCGR file");
99 if ((width * height) != ncgrs.size())
109 ctx.
ncgrs.resize(ncgrs.size());
111 for (
size_t i = 0; i < ncgrs.size(); i++) {
142 if ((versionMajor != 1) || (versionMinor != 1))
143 throw Common::Exception(
"Unsupported version %u.%u", versionMajor, versionMinor);
150 if (headerSize != 16)
154 if ((sectionCount != 1) && (sectionCount != 2))
189 if ((ctx.
width >= 0x8000) || (ctx.
height >= 0x8000))
210 if ((tiled != 0) || (part != 0))
218 if ((dataOffset >= ctx.
ncgr->
size()) || ((ctx.
ncgr->
size() - dataOffset) < dataSize))
226 imageWidth = imageHeight = 0;
239 rowWidth += ncgr.
width;
242 imageHeight += rowHeight;
243 imageWidth =
MAX(imageWidth, rowWidth);
248 uint32 imageWidth, imageHeight;
251 if ((imageWidth >= 0x8000) || (imageHeight >= 0x8000))
260 _mipMaps.back()->width = imageWidth;
261 _mipMaps.back()->height = imageHeight;
262 _mipMaps.back()->size = imageWidth * imageHeight * 4;
267 const bool is0Transp = (ctx.
pal[0] == 0xF8) && (ctx.
pal[1] == 0x00) && (ctx.
pal[2] == 0xF8);
270 for (
uint32 i = 0; i < (imageWidth * imageHeight); i++) {
271 data[i * 4 + 0] = ctx.
pal[0];
272 data[i * 4 + 1] = ctx.
pal[1];
273 data[i * 4 + 2] = ctx.
pal[2];
274 data[i * 4 + 3] = is0Transp ? 0x00 : 0xFF;
281 const uint32 tileWidth = 8;
282 const uint32 tileHeight = 8;
284 for (std::vector<NCGRFile>::iterator n = ctx.
ncgrs.begin(); n != ctx.
ncgrs.end(); ++n) {
291 const uint32 imagePos = n->offsetX + n->offsetY * imageWidth;
294 const uint32 tilesX = n->width / tileWidth;
295 const uint32 tilesY = n->height / tileHeight;
298 for (
uint32 yT = 0; yT < tilesY; yT++) {
299 for (
uint32 xT = 0; xT < tilesX; xT++) {
302 const uint32 tilePos = xT * tileWidth + yT * tileHeight * imageWidth;
305 for (
uint32 y = 0; y < tileHeight; y++) {
306 for (
uint32 x = 0; x < tileWidth; x++) {
309 const uint32 pos = imagePos + tilePos + x + y * imageWidth;
310 const uint8 pixel = n->image->readByte();
312 if (pos > (imageWidth * imageHeight))
315 data[pos * 4 + 0] = ctx.
pal[pixel * 3 + 0];
316 data[pos * 4 + 1] = ctx.
pal[pixel * 3 + 1];
317 data[pos * 4 + 2] = ctx.
pal[pixel * 3 + 2];
318 data[pos * 4 + 3] = ((pixel == 0) && is0Transp) ? 0x00 : 0xFF;
Loading Nitro CoLoR palette files.
#define MKTAG(a0, a1, a2, a3)
A wrapper macro used around four character constants, like 'DATA', to ensure portability.
uint32 offsetX
X offset in pixels into the final image.
void add(const char *s,...) GCC_PRINTF(2
uint32 width
Width of the NCGR grid, in NCGR.
Common::ScopedArray< const byte > pal
void reset(PointerType o=0)
Resets the pointer with the new value.
void calculateGrid(ReadContext &ctx, uint32 &imageWidth, uint32 &imageHeight)
static const uint32 kCHARID
static const byte * load(Common::SeekableReadStream &nclr)
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.
void load(const std::vector< Common::SeekableReadStream *> &ncgrs, uint32 width, uint32 height, Common::SeekableReadStream &nclr)
static const uint32 kNCGRID
Basic exceptions to throw.
Common::SeekableSubReadStreamEndian * ncgr
size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)
Sets the stream position indicator for the stream.
uint32 width
Width in pixels of this NCGR.
Utility templates and functions.
Common::SeekableReadStream * image
uint32 offsetY
Y offset in pixels into the final 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
void readHeader(NCGRFile &ctx)
Basic reading stream interfaces.
NCGR(Common::SeekableReadStream &ncgr, Common::SeekableReadStream &nclr)
uint8 depth
Color depth in bits.
uint32 offsetCHAR
Offset to the CHAR section within the NCGR file.
void readChar(NCGRFile &ctx)
uint32 height
Height of the NCGR grid, in NCGR.
UString debugTag(uint32 tag, bool trim)
Create an elaborate string from an integer tag, for debugging purposes.
Nitro Character Graphic Resource, a Nintendo DS image format.
SeekableSubReadStream provides access to a SeekableReadStream restricted to the range [begin...
uint32 height
Height in pixels of this NCGR.
static Common::SeekableSubReadStreamEndian * open(Common::SeekableReadStream &stream)
Treat this stream as a Nitro file and return an endian'd stream according to its BOM.
Interface for a seekable & readable data stream.
byte readByte()
Read an unsigned byte from the stream and return it.
std::vector< NCGRFile > ncgrs
void draw(ReadContext &ctx)