42 cbgt(&c), pal(&p), twoda(&t) {
54 e.
add(
"Failed reading CBGT file");
79 ctx.
palettes.reserve((size + 1) / 512);
82 const uint32 paletteSize = MIN<size_t>(512, size);
87 const uint32 colorCount = (paletteSize / 2) * 3;
88 for (
uint32 i = 0; i < colorCount; i += 3) {
91 palette[i + 0] = ((color >> 10) & 0x1F) << 3;
92 palette[i + 1] = ((color >> 5) & 0x1F) << 3;
93 palette[i + 2] = ( color & 0x1F) << 3;
103 e.
add(
"Failed reading PAL file");
148 int n = std::sscanf(palette.
c_str(),
"palette%d.pal", &index);
149 if ((n != 1) || (index < 0))
159 e.
add(
"Failed reading 2DA file");
169 ctx.
cells.reserve(4096);
173 for (
size_t i = 0; i < 4096; i++) {
180 ctx.
cells.push_back(0);
189 if (ctx.
cells.back()->size() != 4096)
195 if (ctx.
cells.empty())
199 e.
add(
"Failed reading CBGT file");
222 _mipMaps.back()->size = width * height * 4;
248 const uint32 cellWidth = 64;
249 const uint32 cellHeight = 64;
252 const uint32 tileWidth = 8;
253 const uint32 tileHeight = 8;
254 const uint32 tilesX = cellWidth / tileWidth;
255 const uint32 tilesY = cellHeight / tileHeight;
258 for (
size_t i = 0; i < ctx.
cells.size(); i++) {
263 const uint32 xC = i % cellsX;
264 const uint32 yC = i / cellsX;
267 const bool is0Transp = (palette[0] == 0xF8) && (palette[1] == 0x00) && (palette[2] == 0xF8);
270 const uint32 imagePos = yC * cellHeight * ctx.
width + xC * cellWidth;
273 for (
uint32 yT = 0; yT < tilesY; yT++) {
274 for (
uint32 xT = 0; xT < tilesX; xT++) {
277 const uint32 tilePos = xT * tileWidth + yT * tileHeight * ctx.
width;
280 for (
uint32 y = 0; y < tileHeight; y++) {
281 for (
uint32 x = 0; x < tileWidth; x++) {
284 const uint32 pos = imagePos + tilePos + x + y * ctx.
width;
290 data[pos * 4 + 0] = palette[pixel * 3 + 0];
291 data[pos * 4 + 1] = palette[pixel * 3 + 1];
292 data[pos * 4 + 2] = palette[pixel * 3 + 2];
293 data[pos * 4 + 3] = ((pixel == 0) && is0Transp) ? 0x00 : 0xFF;
Class to hold the two-dimensional array of a 2DA file.
uint16 readUint16LE()
Read an unsigned 16-bit word stored in little endian (LSB first) order from the stream and return it...
void checkConsistency(ReadContext &ctx)
void add(const char *s,...) GCC_PRINTF(2
const Common::UString & getString(size_t column) const
Return the contents of a cell as a string.
A class holding an UTF-8 string.
Common::SeekableReadStream * twoda
static void decompress(Common::ReadStream &small, Common::WriteStream &out)
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
void drawImage(ReadContext &ctx)
void readPalettes(ReadContext &ctx)
ReadContext(Common::SeekableReadStream &c, Common::SeekableReadStream &p, Common::SeekableReadStream &t)
void load(ReadContext &ctx)
size_t getRowCount() const
Return the number of rows in the array.
Exception that provides a stack of explanations.
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
size_t getColumnCount() const
Return the number of columns in the array.
Utility templates and functions.
Handling BioWare's 2DAs (two-dimensional array).
PixelFormatRaw _formatRaw
virtual size_t size() const =0
Obtains the total size of the stream, measured in bytes.
Basic reading stream interfaces.
virtual size_t pos() const =0
Obtains the current value of the stream position indicator of the stream.
CBGT(Common::SeekableReadStream &cbgt, Common::SeekableReadStream &pal, Common::SeekableReadStream &twoda)
PaletteIndices paletteIndices
const TwoDARow & getRow(size_t row) const
Get a row.
Decompressing "small" files, Nintendo DS LZSS (types 0x00 and 0x10), found in Sonic.
SeekableSubReadStream provides access to a SeekableReadStream restricted to the range [begin...
Compressed BackGround Tiles, a BioWare image format found in Sonic.
Common::SeekableReadStream * pal
Interface for a seekable & readable data stream.
byte readByte()
Read an unsigned byte from the stream and return it.
void readCells(ReadContext &ctx)
Common::SeekableReadStream * cbgt
void createImage(uint32 width, uint32 height)
void readPaletteIndices(ReadContext &ctx)