void VideoDecoder::initVideo(uint32 width, uint32 height) { _width = width; _height = height; // The real texture dimensions. Have to be a power of 2 int realWidth = NEXTPOWER2(width); int realHeight = NEXTPOWER2(height); // Dimensions of the actual video part of texture _textureWidth = ((float) _width ) / ((float) realWidth ); _textureHeight = ((float) _height) / ((float) realHeight); delete _surface; _surface = new Graphics::Surface(realWidth, realHeight); _surface->fill(0, 0, 0, 0); rebuild(); }
void SBM::readData(Common::SeekableReadStream &sbm, bool deswizzle) { if ((sbm.size() % 1024) != 0) throw Common::Exception("Invalid SBM (%u)", (uint)sbm.size()); const size_t rowCount = (sbm.size() / 1024); _mipMaps.push_back(new MipMap); _mipMaps[0]->width = 4 * 32; _mipMaps[0]->height = NEXTPOWER2((uint32) rowCount * 32); _mipMaps[0]->size = _mipMaps[0]->width * _mipMaps[0]->height * 4; _mipMaps[0]->data.reset(new byte[_mipMaps[0]->size]); // SBM data consists of character sized 32 * 32 pixels, with 2 bits per pixel. // 4 characters each are on top of each other, occupying the same x/y // coordinates but different planes. // We'll unpack them and draw them next to each other instead. static const int masks [4] = { 0x03, 0x0C, 0x30, 0xC0 }; static const int shifts[4] = { 0, 2, 4, 6 }; byte *data = _mipMaps[0]->data.get(); byte buffer[1024]; for (size_t c = 0; c < rowCount; c++) { if (sbm.read(buffer, 1024) != 1024) throw Common::Exception(Common::kReadError); for (int y = 0; y < 32; y++) { for (int plane = 0; plane < 4; plane++) { for (int x = 0; x < 32; x++) { const uint32 offset = deswizzle ? deSwizzleOffset(x, y, 32, rowCount) : (y * 32 + x); const byte a = ((buffer[offset] & masks[plane]) >> shifts[plane]) * 0x55; *data++ = 0xFF; // B *data++ = 0xFF; // G *data++ = 0xFF; // R *data++ = a; // A } } } } byte *dataEnd = _mipMaps[0]->data.get() + _mipMaps[0]->size; std::memset(data, 0, dataEnd - data); }