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
23
24 #ifdef ENABLE_EOB
25
26 #include "kyra/resource/resource.h"
27 #include "graphics/sjis.h"
28
29 namespace Kyra {
30
decodeSHP(const uint8 * data,int dstPage)31 void Screen_EoB::decodeSHP(const uint8 *data, int dstPage) {
32 int32 bytesLeft = READ_LE_UINT32(data);
33 const uint8 *src = data + 4;
34 uint8 *dst = getPagePtr(dstPage);
35
36 if (bytesLeft < 0) {
37 memcpy(dst, data, 64000);
38 return;
39 }
40
41 while (bytesLeft > 0) {
42 uint8 code = *src++;
43 bytesLeft--;
44
45 for (int i = 8; i; i--) {
46 if (code & 0x80) {
47 uint16 copyOffs = (src[0] << 4) | (src[1] >> 4);
48 uint8 count = (src[1] & 0x0F) + 3;
49 src += 2;
50 bytesLeft -= 2;
51 const uint8 *copySrc = dst - 1 - copyOffs;
52 while (count--)
53 *dst++ = *copySrc++;
54 } else if (bytesLeft) {
55 *dst++ = *src++;
56 bytesLeft--;
57 } else {
58 break;
59 }
60 code <<= 1;
61 }
62 }
63 }
64
convertToHiColor(int page)65 void Screen_EoB::convertToHiColor(int page) {
66 if (!_16bitPalette)
67 return;
68 uint16 *dst = (uint16 *)getPagePtr(page);
69 memcpy(_convertHiColorBuffer, dst, SCREEN_H * SCREEN_W);
70 uint8 *src = _convertHiColorBuffer;
71 for (int s = SCREEN_H * SCREEN_W; s; --s)
72 *dst++ = _16bitPalette[*src++];
73 }
74
shadeRect(int x1,int y1,int x2,int y2,int shadingLevel)75 void Screen_EoB::shadeRect(int x1, int y1, int x2, int y2, int shadingLevel) {
76 if (!_16bitPalette)
77 return;
78
79 int l = _16bitShadingLevel;
80 _16bitShadingLevel = shadingLevel;
81
82 if (_curPage == 0 || _curPage == 1)
83 addDirtyRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
84
85 uint16 *dst = (uint16*)(getPagePtr(_curPage) + y1 * SCREEN_W * _bytesPerPixel + x1 * _bytesPerPixel);
86
87 for (; y1 < y2; ++y1) {
88 uint16 *ptr = dst;
89 for (int i = 0; i < x2 - x1; i++) {
90 *ptr = shade16bitColor(*ptr);
91 ptr++;
92 }
93 dst += SCREEN_W;
94 }
95
96 _16bitShadingLevel = l;
97 }
98
SJISFontLarge(Common::SharedPtr<Graphics::FontSJIS> & font)99 SJISFontLarge::SJISFontLarge(Common::SharedPtr<Graphics::FontSJIS> &font) : SJISFont(font, 0, false, false, 0) {
100 }
101
getHeight() const102 int SJISFontLarge::getHeight() const {
103 return _font->getFontHeight();
104 }
105
getWidth() const106 int SJISFontLarge::getWidth() const {
107 return _font->getMaxFontWidth();
108 }
109
getCharWidth(uint16 c) const110 int SJISFontLarge::getCharWidth(uint16 c) const {
111 if (c <= 0x7F || (c >= 0xA1 && c <= 0xDF))
112 return _font->getCharWidth('a');
113 else
114 return getWidth();
115 }
116
drawChar(uint16 c,byte * dst,int pitch,int) const117 void SJISFontLarge::drawChar(uint16 c, byte *dst, int pitch, int) const {
118 _font->setDrawingMode(Graphics::FontSJIS::kDefaultMode);
119 _font->toggleFatPrint(false);
120 _font->drawChar(dst, c, 320, 1, _colorMap[1], _colorMap[0], 320, 200);
121 }
122
SJISFont12x12(const uint16 * searchTable)123 SJISFont12x12::SJISFont12x12(const uint16 *searchTable) : _height(6), _width(6), _data(0) {
124 assert(searchTable);
125 for (int i = 0; i < 148; i++)
126 _searchTable[searchTable[i]] = i + 1;
127 }
128
load(Common::SeekableReadStream & file)129 bool SJISFont12x12::load(Common::SeekableReadStream &file) {
130 delete[] _data;
131 int size = 148 * 24;
132 if (file.size() < size)
133 return false;
134
135 _data = new uint8[size];
136 file.read(_data, size);
137
138 return true;
139 }
140
unload()141 void SJISFont12x12::unload() {
142 delete[] _data;
143 _data = 0;
144 _searchTable.clear();
145 }
146
drawChar(uint16 c,byte * dst,int pitch,int) const147 void SJISFont12x12::drawChar(uint16 c, byte *dst, int pitch, int) const {
148 if (!_searchTable.contains(c))
149 return;
150
151 const uint8 *src = _data + (_searchTable[c] - 1) * 24;
152 uint8 color1 = _colorMap[1];
153
154 int bt = 0;
155 uint16 chr = 0;
156
157 for (int i = 0; i < 192; ++i) {
158 if (!bt) {
159 chr = *src++;
160 bt = 8;
161 }
162 if (chr & 0x80)
163 *dst = color1;
164 dst++;
165 if (--bt)
166 chr <<= 1;
167 else if (i & 8)
168 dst += (pitch - 16);
169 }
170 }
171
172 } // End of namespace Kyra
173
174 #endif // ENABLE_EOB
175