1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "common/stream.h"
#include "common/rect.h"
#include "common/textconsole.h"
#include "adl/display.h"
#include "adl/graphics.h"
namespace Adl {
void Graphics_v1::drawPic(Common::SeekableReadStream &pic, const Common::Point &pos) {
byte x, y;
bool bNewLine = false;
byte oldX = 0, oldY = 0;
while (1) {
x = pic.readByte();
y = pic.readByte();
if (pic.err() || pic.eos())
error("Error reading picture");
if (x == 0xff && y == 0xff)
return;
if (x == 0 && y == 0) {
bNewLine = true;
continue;
}
x += pos.x;
y += pos.y;
if (y > 160)
y = 160;
if (bNewLine) {
_display.putPixel(Common::Point(x, y), 0x7f);
bNewLine = false;
} else {
drawLine(Common::Point(oldX, oldY), Common::Point(x, y), 0x7f);
}
oldX = x;
oldY = y;
}
}
void Graphics_v1::drawCornerPixel(Common::Point &p, byte color, byte bits, byte quadrant) const {
if (bits & 4)
_display.putPixel(p, color);
bits += quadrant;
if (bits & 1)
p.x += (bits & 2 ? -1 : 1);
else
p.y += (bits & 2 ? 1 : -1);
}
void Graphics_v1::drawCorners(Common::ReadStream &corners, const Common::Point &pos, byte rotation, byte scaling, byte color) const {
const byte stepping[] = {
0xff, 0xfe, 0xfa, 0xf4, 0xec, 0xe1, 0xd4, 0xc5,
0xb4, 0xa1, 0x8d, 0x78, 0x61, 0x49, 0x31, 0x18,
0xff
};
byte quadrant = rotation >> 4;
rotation &= 0xf;
byte xStep = stepping[rotation];
byte yStep = stepping[(rotation ^ 0xf) + 1] + 1;
Common::Point p(pos);
while (true) {
byte b = corners.readByte();
if (corners.eos() || corners.err())
error("Error reading corners");
if (b == 0)
return;
do {
byte xFrac = 0x80;
byte yFrac = 0x80;
for (uint j = 0; j < scaling; ++j) {
if (xFrac + xStep + 1 > 255)
drawCornerPixel(p, color, b, quadrant);
xFrac += xStep + 1;
if (yFrac + yStep > 255)
drawCornerPixel(p, color, b, quadrant + 1);
yFrac += yStep;
}
b >>= 3;
} while (b != 0);
}
}
} // End of namespace Adl
|