xoreos  0.0.5
surface.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 
25 #include <cassert>
26 #include <cstring>
27 
29 
30 namespace Graphics {
31 
32 Surface::Surface(int width, int height) {
33  assert((width > 0) && (height > 0));
34 
35  _compressed = false;
36  _hasAlpha = true;
40 
41  _mipMaps.push_back(new MipMap(this));
42 
43  _mipMaps[0]->width = width;
44  _mipMaps[0]->height = height;
45  _mipMaps[0]->size = _mipMaps[0]->width * _mipMaps[0]->height * 4;
46 
47  _mipMaps[0]->data.reset(new byte[_mipMaps[0]->size]);
48 }
49 
51 }
52 
53 int Surface::getWidth() const {
54  return _mipMaps[0]->width;
55 }
56 
57 int Surface::getHeight() const {
58  return _mipMaps[0]->height;
59 }
60 
62  return _mipMaps[0]->data.get();
63 }
64 
65 const byte *Surface::getData() const {
66  return _mipMaps[0]->data.get();
67 }
68 
69 void Surface::fill(byte r, byte g, byte b, byte a) {
70  if ((r == g) && (r == b) && (r == a)) {
71  std::memset(_mipMaps[0]->data.get(), r, _mipMaps[0]->size);
72  return;
73  }
74 
75  byte *data = _mipMaps[0]->data.get();
76  uint32 size = _mipMaps[0]->size / 4;
77  while (size-- > 0) {
78  *data++ = b;
79  *data++ = g;
80  *data++ = r;
81  *data++ = a;
82  }
83 }
84 
85 const ImageDecoder::MipMap &Surface::getMipMap(size_t mipMap) const {
86  return ImageDecoder::getMipMap(mipMap);
87 }
88 
90  return *_mipMaps[0];
91 }
92 
94  return *_mipMaps[0];
95 }
96 
97 } // End of namespace Graphics
byte * getData()
Definition: surface.cpp:61
void fill(byte r, byte g, byte b, byte a)
Definition: surface.cpp:69
PixelDataType _dataType
Definition: decoder.h:124
int getWidth() const
Definition: surface.cpp:53
PixelFormat _format
Definition: decoder.h:122
const MipMap & getMipMap() const
Return a mip map.
Definition: surface.cpp:89
PixelFormatRaw _formatRaw
Definition: decoder.h:123
const MipMap & getMipMap(size_t mipMap, size_t layer=0) const
Return a mip map.
Definition: decoder.cpp:204
An image surface, in BGRA format.
uint32_t uint32
Definition: types.h:204
int getHeight() const
Definition: surface.cpp:57
Surface(int width, int height)
Definition: surface.cpp:32
uint8 byte
Definition: types.h:209