1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program 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 2
10 * of the License, or (at your option) any later version.
11
12 * This program 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 this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22 #include "common/stream.h"
23 #include "common/memstream.h"
24
25 #include "startrek/bitmap.h"
26 #include "startrek/startrek.h"
27
28 namespace StarTrek {
29
Bitmap(FileStream stream)30 Bitmap::Bitmap(FileStream stream) {
31 xoffset = stream->readUint16();
32 yoffset = stream->readUint16();
33 width = stream->readUint16();
34 height = stream->readUint16();
35
36 pixelsArraySize = width * height;
37 pixels = new byte[pixelsArraySize];
38 stream->read(pixels, width * height);
39 }
40
Bitmap(Common::MemoryReadStreamEndian * stream)41 Bitmap::Bitmap(Common::MemoryReadStreamEndian *stream) {
42 xoffset = stream->readUint16();
43 yoffset = stream->readUint16();
44 width = stream->readUint16();
45 height = stream->readUint16();
46
47 pixelsArraySize = width * height;
48 pixels = new byte[pixelsArraySize];
49 stream->read(pixels, width * height);
50 }
51
Bitmap(const Bitmap & bitmap)52 Bitmap::Bitmap(const Bitmap &bitmap) {
53 xoffset = bitmap.xoffset;
54 yoffset = bitmap.yoffset;
55 width = bitmap.width;
56 height = bitmap.height;
57 pixelsArraySize = bitmap.pixelsArraySize;
58 pixels = new byte[pixelsArraySize];
59 memcpy(pixels, bitmap.pixels, pixelsArraySize);
60 }
61
Bitmap(int w,int h)62 Bitmap::Bitmap(int w, int h) : width(w), height(h), xoffset(0), yoffset(0) {
63 pixels = new byte[width * height];
64 pixelsArraySize = width * height;
65 }
66
~Bitmap()67 Bitmap::~Bitmap() {
68 if (pixels != nullptr)
69 delete[] pixels;
70 }
71
72
TextBitmap(int w,int h)73 TextBitmap::TextBitmap(int w, int h) {
74 width = w;
75 height = h;
76 // Width and Height are the total dimensions. Since each character takes 8 pixels in
77 // each dimension, the "pixels" array (which actually stores character indices) must
78 // be smaller.
79 pixelsArraySize = width / 8 * height / 8;
80 pixels = new byte[pixelsArraySize];
81 }
82
StubBitmap(int w,int h)83 StubBitmap::StubBitmap(int w, int h) {
84 width = w;
85 height = h;
86 pixelsArraySize = 0;
87 }
88
89 } // End of namespace StarTrek
90