xoreos  0.0.5
xoreositex.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
26 #include "src/common/util.h"
27 #include "src/common/strutil.h"
28 #include "src/common/readstream.h"
29 #include "src/common/error.h"
30 
32 
33 static const uint32 kXEOSID = MKTAG('X', 'E', 'O', 'S');
34 static const uint32 kITEXID = MKTAG('I', 'T', 'E', 'X');
35 
36 namespace Graphics {
37 
39  load(xeositex);
40 }
41 
43 }
44 
46  try {
47 
48  readHeader(xeositex);
49  readMipMaps(xeositex);
50 
51  } catch (Common::Exception &e) {
52  e.add("Failed reading XEOSITEX file");
53  throw;
54  }
55 }
56 
58  const uint32 magic1 = xeositex.readUint32BE();
59  const uint32 magic2 = xeositex.readUint32BE();
60  if ((magic1 != kXEOSID) || (magic2 != kITEXID))
61  throw Common::Exception("Not a valid XEOSITEX (%s, %s)",
62  Common::debugTag(magic1).c_str(), Common::debugTag(magic2).c_str());
63 
64  const uint32 version = xeositex.readUint32LE();
65  if (version != 0)
66  throw Common::Exception("Invalid XEOSITEX version %u", version);
67 
68  const uint32 pixelFormat = xeositex.readUint32LE();
69  if ((pixelFormat != 3) && (pixelFormat != 4))
70  throw Common::Exception("Invalid XEOSITEX pixel format %u", pixelFormat);
71 
72  if (pixelFormat == 3) {
76  _hasAlpha = false;
77  } else if (pixelFormat == 4) {
81  _hasAlpha = true;
82  }
83 
84  _wrapX = xeositex.readByte() != 0;
85  _wrapY = xeositex.readByte() != 0;
86  _flipX = xeositex.readByte() != 0;
87  _flipY = xeositex.readByte() != 0;
88 
89  _coordTransform = xeositex.readByte();
90 
91  _txi.getFeatures().filter = xeositex.readByte() != 0;
92 
93  const uint32 mipMaps = xeositex.readUint32LE();
94  _mipMaps.resize(mipMaps, 0);
95 }
96 
98  for (size_t i = 0; i < _mipMaps.size(); i++) {
99  _mipMaps[i] = new MipMap(this);
100 
101  _mipMaps[i]->width = xeositex.readUint32LE();
102  _mipMaps[i]->height = xeositex.readUint32LE();
103  _mipMaps[i]->size = xeositex.readUint32LE();
104 
105  _mipMaps[i]->data.reset(new byte[_mipMaps[i]->size]);
106 
107  if (xeositex.read(_mipMaps[i]->data.get(), _mipMaps[i]->size) != _mipMaps[i]->size)
109  }
110 }
111 
112 } // End of namespace Graphics
#define MKTAG(a0, a1, a2, a3)
A wrapper macro used around four character constants, like &#39;DATA&#39;, to ensure portability.
Definition: endianness.h:140
void add(const char *s,...) GCC_PRINTF(2
Definition: error.cpp:58
static const uint32 kITEXID
Definition: xoreositex.cpp:34
uint32 readUint32LE()
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it...
Definition: readstream.h:133
XEOSITEX(Common::SeekableReadStream &xeositex)
Definition: xoreositex.cpp:38
static const uint32 kXEOSID
Definition: xoreositex.cpp:33
void resize(typename std::vector< T *>::size_type n, typename std::vector< T *>::value_type val=typename std::vector< T *>::value_type())
Definition: ptrvector.h:76
PixelDataType _dataType
Definition: decoder.h:124
void load(Common::SeekableReadStream &xeositex)
Definition: xoreositex.cpp:45
Utility templates and functions for working with strings and streams.
Exception that provides a stack of explanations.
Definition: error.h:36
Basic exceptions to throw.
PixelFormat _format
Definition: decoder.h:122
Utility templates and functions.
void readMipMaps(Common::SeekableReadStream &xeositex)
Definition: xoreositex.cpp:97
PixelFormatRaw _formatRaw
Definition: decoder.h:123
virtual size_t read(void *dataPtr, size_t dataSize)=0
Read data from the stream.
StackException Exception
Definition: error.h:59
const Exception kReadError("Read error")
Exception when reading from a stream failed.
Definition: error.h:62
Our very own intermediate texture format.
Basic reading stream interfaces.
uint32 readUint32BE()
Read an unsigned 32-bit word stored in big endian (MSB first) order from the stream and return it...
Definition: readstream.h:166
uint32_t uint32
Definition: types.h:204
UString debugTag(uint32 tag, bool trim)
Create an elaborate string from an integer tag, for debugging purposes.
Definition: strutil.cpp:117
void readHeader(Common::SeekableReadStream &xeositex)
Definition: xoreositex.cpp:57
const Features & getFeatures() const
Definition: txi.cpp:283
Interface for a seekable & readable data stream.
Definition: readstream.h:265
byte readByte()
Read an unsigned byte from the stream and return it.
Definition: readstream.h:92
uint8 byte
Definition: types.h:209