ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

tm.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/formats/tm.h"
00024 
00025 #include "engines/stark/gfx/driver.h"
00026 #include "engines/stark/gfx/texture.h"
00027 
00028 #include "engines/stark/formats/biff.h"
00029 
00030 #include "engines/stark/services/archiveloader.h"
00031 #include "engines/stark/services/services.h"
00032 
00033 namespace Stark {
00034 namespace Formats {
00035 
00036 class TextureGroup : public BiffObject {
00037 public:
00038     static const uint32 TYPE = kTextureSetGroup;
00039 
00040     TextureGroup() :
00041             BiffObject(),
00042             _palette(nullptr) {
00043         _type = TYPE;
00044     }
00045 
00046     ~TextureGroup() override {
00047         delete[] _palette;
00048     }
00049 
00050     const byte *getPalette() {
00051         return _palette;
00052     }
00053 
00054     // BiffObject API
00055     void readData(ArchiveReadStream *stream, uint32 dataLength) override {
00056         int entries = stream->readUint32LE();
00057         _palette = new byte[entries * 3];
00058 
00059         byte *ptr = _palette;
00060         for (int i = 0; i < entries; ++i) {
00061             *ptr++ = (byte) stream->readUint16LE();
00062             *ptr++ = (byte) stream->readUint16LE();
00063             *ptr++ = (byte) stream->readUint16LE();
00064         }
00065     }
00066 
00067 private:
00068     byte *_palette;
00069 };
00070 
00071 Texture::Texture() :
00072     BiffObject(),
00073     _texture(nullptr),
00074     _u(0) {
00075     _type = TYPE;
00076 }
00077 
00078 Texture::~Texture() {
00079     _surface.free();
00080     delete _texture;
00081 }
00082 
00083 void Texture::readData(ArchiveReadStream *stream, uint32 dataLength) {
00084     TextureGroup *textureGroup = static_cast<TextureGroup *>(_parent);
00085 
00086     _name = stream->readString16();
00087     _u = stream->readByte();
00088 
00089     uint32 w = stream->readUint32LE();
00090     uint32 h = stream->readUint32LE();
00091     uint32 levels = stream->readUint32LE();
00092 
00093     _texture = StarkGfx->createTexture();
00094     _texture->setLevelCount(levels);
00095 
00096     for (uint32 i = 0; i < levels; ++i) {
00097         // Read the pixel data to a surface
00098         Graphics::Surface level;
00099         Graphics::Surface *surface = i == 0 ? &_surface : &level;
00100 
00101         surface->create(w, h, Graphics::PixelFormat::createFormatCLUT8());
00102         stream->read(surface->getPixels(), surface->w * surface->h);
00103 
00104         // Add the mipmap level to the texture
00105         _texture->addLevel(i, surface, textureGroup->getPalette());
00106 
00107         level.free();
00108 
00109         w /= 2;
00110         h /= 2;
00111     }
00112 }
00113 
00114 Gfx::Texture *Texture::acquireTexturePointer() {
00115     Gfx::Texture *texture = _texture;
00116     _texture = nullptr;
00117 
00118     return texture;
00119 }
00120 
00121 Graphics::Surface *Texture::getSurface() const {
00122     TextureGroup *textureGroup = static_cast<TextureGroup *>(_parent);
00123 
00124     return _surface.convertTo(Gfx::Driver::getRGBAPixelFormat(), textureGroup->getPalette());
00125 }
00126 
00127 Gfx::TextureSet *TextureSetReader::read(ArchiveReadStream *stream) {
00128     BiffArchive archive = BiffArchive(stream, &biffObjectBuilder);
00129 
00130     Common::Array<Texture *> textures = archive.listObjectsRecursive<Texture>();
00131 
00132     Gfx::TextureSet *textureSet = new Gfx::TextureSet();
00133     for (uint i = 0; i < textures.size(); i++) {
00134         textureSet->addTexture(textures[i]->getName(), textures[i]->acquireTexturePointer());
00135     }
00136 
00137     return textureSet;
00138 }
00139 
00140 BiffArchive *TextureSetReader::readArchive(ArchiveReadStream *stream) {
00141     return new BiffArchive(stream, &biffObjectBuilder);
00142 }
00143 
00144 BiffObject *TextureSetReader::biffObjectBuilder(uint32 type) {
00145     switch (type) {
00146         case kTextureSetGroup:
00147             return new TextureGroup();
00148         case kTextureSetTexture:
00149             return new Texture();
00150         default:
00151             return nullptr;
00152     }
00153 }
00154 
00155 } // End of namespace Formats
00156 } // End of namespace Stark


Generated on Sat Jul 13 2019 05:01:11 for ResidualVM by doxygen 1.7.1
curved edge   curved edge