2008-11-10 20:38:54 +00:00
|
|
|
/* 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 "tucker/graphics.h"
|
|
|
|
|
|
|
|
namespace Tucker {
|
|
|
|
|
|
|
|
int Graphics::encodeRLE(const uint8 *src, uint8 *dst, int w, int h) {
|
2009-01-18 02:46:25 +00:00
|
|
|
int sz = 0;
|
2008-11-10 20:38:54 +00:00
|
|
|
int count = 0;
|
|
|
|
int code = 0;
|
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
for (int x = 0; x < w; ++x) {
|
|
|
|
code = src[x];
|
|
|
|
if (code == 0) {
|
|
|
|
++count;
|
|
|
|
if (count > 200) {
|
2009-01-18 02:46:25 +00:00
|
|
|
dst[sz++] = 0;
|
|
|
|
dst[sz++] = count;
|
2008-11-10 20:38:54 +00:00
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (count > 0) {
|
2009-01-18 02:46:25 +00:00
|
|
|
dst[sz++] = 0;
|
|
|
|
dst[sz++] = count;
|
2008-11-10 20:38:54 +00:00
|
|
|
count = 0;
|
|
|
|
}
|
2009-01-18 02:46:25 +00:00
|
|
|
dst[sz++] = code;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
src += 320;
|
|
|
|
}
|
|
|
|
if (count > 0) {
|
2009-01-18 02:46:25 +00:00
|
|
|
dst[sz++] = 0;
|
|
|
|
dst[sz++] = count;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
2009-01-18 02:46:25 +00:00
|
|
|
return sz;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Graphics::encodeRAW(const uint8 *src, uint8 *dst, int w, int h) {
|
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
memcpy(dst, src, w);
|
|
|
|
dst += w;
|
|
|
|
src += 320;
|
|
|
|
}
|
|
|
|
return w * h;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Graphics::decodeRLE(uint8 *dst, const uint8 *src, int w, int h) {
|
|
|
|
int code = 0;
|
|
|
|
int color = 0;
|
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
for (int x = 0; x < w; ++x) {
|
|
|
|
if (code == 0) {
|
2009-01-18 02:46:25 +00:00
|
|
|
color = *src++;
|
2008-11-10 20:38:54 +00:00
|
|
|
if (color == 0) {
|
2009-01-18 02:46:25 +00:00
|
|
|
code = *src++;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (color != 0) {
|
|
|
|
dst[x] = color;
|
2009-01-18 02:46:25 +00:00
|
|
|
} else {
|
|
|
|
--code;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dst += 640;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Graphics::decodeRLE_224(uint8 *dst, const uint8 *src, int w, int h) {
|
|
|
|
int code = 0;
|
|
|
|
int color = 0;
|
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
for (int x = 0; x < w; ++x) {
|
|
|
|
if (code == 0) {
|
2009-01-18 02:46:25 +00:00
|
|
|
color = *src++;
|
|
|
|
if (color == 0) {
|
|
|
|
code = *src++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (color != 0) {
|
|
|
|
if (dst[x] < 0xE0) {
|
|
|
|
dst[x] = color;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
--code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst += 640;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-17 15:09:38 +00:00
|
|
|
void Graphics::decodeRLE_248(uint8 *dst, const uint8 *src, int w, int h, int y1, int y2, bool xflip, bool color248Only) {
|
2008-11-10 20:38:54 +00:00
|
|
|
int code = 0;
|
|
|
|
int color = 0;
|
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
for (int x = 0; x < w; ++x) {
|
2009-01-18 02:46:25 +00:00
|
|
|
const int offset = xflip ? (w - 1 - x) : x;
|
2008-11-10 20:38:54 +00:00
|
|
|
if (code == 0) {
|
2009-01-18 02:46:25 +00:00
|
|
|
color = *src++;
|
2008-11-10 20:38:54 +00:00
|
|
|
if (color == 0) {
|
2009-01-18 02:46:25 +00:00
|
|
|
code = *src++;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (color != 0) {
|
2011-02-17 15:09:38 +00:00
|
|
|
if ((color248Only || dst[offset] < 0xE0 || y + y1 < y2) && dst[offset] < 0xF8) {
|
2009-01-18 02:46:25 +00:00
|
|
|
dst[offset] = color;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
2009-01-18 02:46:25 +00:00
|
|
|
} else {
|
|
|
|
--code;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dst += 640;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Graphics::decodeRLE_320(uint8 *dst, const uint8 *src, int w, int h) {
|
|
|
|
int code = 0;
|
|
|
|
int color = 0;
|
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
for (int x = 0; x < w; ++x) {
|
|
|
|
if (code == 0) {
|
2009-01-18 02:46:25 +00:00
|
|
|
color = *src++;
|
2008-11-10 20:38:54 +00:00
|
|
|
if (color == 0) {
|
2009-01-18 02:46:25 +00:00
|
|
|
code = *src++;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (code == 0) {
|
|
|
|
dst[x] = color;
|
|
|
|
} else {
|
|
|
|
--code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst += 320;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-18 04:00:11 +00:00
|
|
|
void Graphics::copyRect(uint8 *dst, int dstPitch, uint8 *src, int srcPitch, int w, int h) {
|
2008-11-10 20:38:54 +00:00
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
memcpy(dst, src, w);
|
2009-01-18 04:00:11 +00:00
|
|
|
dst += dstPitch;
|
2008-11-10 20:38:54 +00:00
|
|
|
src += srcPitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-27 10:36:45 +00:00
|
|
|
void Graphics::drawStringChar(uint8 *dst, int xDst, int yDst, int pitch, uint8 chr, uint8 chrColor, const uint8 *src) {
|
2008-11-28 23:56:25 +00:00
|
|
|
if (chr < 32 || chr - 32 >= _charset.xCount * _charset.yCount) {
|
2008-11-10 20:38:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-09-27 10:36:45 +00:00
|
|
|
const int h = MIN(_charset.charH, 200 - yDst);
|
|
|
|
const int w = MIN(_charset.charW, pitch - xDst);
|
|
|
|
dst += yDst * pitch + xDst;
|
2008-11-28 23:56:25 +00:00
|
|
|
int offset = (chr - 32) * _charset.charH * _charset.charW;
|
2009-09-27 10:36:45 +00:00
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
for (int x = 0; x < w; ++x) {
|
2008-11-10 20:38:54 +00:00
|
|
|
const int color = src[offset++];
|
|
|
|
if (color != 0) {
|
2008-11-28 23:56:25 +00:00
|
|
|
if (_charsetType == kCharsetTypeCredits) {
|
2008-11-11 13:10:34 +00:00
|
|
|
dst[x] = color;
|
|
|
|
} else {
|
|
|
|
dst[x] = (color == 128) ? color : chrColor;
|
|
|
|
}
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dst += pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-28 23:56:25 +00:00
|
|
|
void Graphics::setCharset(CharsetType type) {
|
2009-10-17 20:06:46 +00:00
|
|
|
_charsetType = type;
|
2008-11-28 23:56:25 +00:00
|
|
|
switch (type) {
|
2008-12-16 22:05:16 +00:00
|
|
|
case kCharsetTypeDefault:
|
2008-11-28 23:56:25 +00:00
|
|
|
_charset.charW = 10;
|
2008-12-16 22:05:16 +00:00
|
|
|
_charset.charH = 10;
|
2008-11-28 23:56:25 +00:00
|
|
|
_charset.xCount = 32;
|
2008-12-16 22:05:16 +00:00
|
|
|
_charset.yCount = 7;
|
2008-11-28 23:56:25 +00:00
|
|
|
break;
|
2008-12-16 22:05:16 +00:00
|
|
|
case kCharsetTypeEng:
|
2008-11-28 23:56:25 +00:00
|
|
|
_charset.charW = 10;
|
2008-12-16 22:05:16 +00:00
|
|
|
_charset.charH = 8;
|
2008-11-28 23:56:25 +00:00
|
|
|
_charset.xCount = 32;
|
2008-12-16 22:05:16 +00:00
|
|
|
_charset.yCount = 3;
|
2008-11-28 23:56:25 +00:00
|
|
|
break;
|
|
|
|
case kCharsetTypeCredits:
|
|
|
|
_charset.charW = 19;
|
|
|
|
_charset.charH = 10;
|
|
|
|
_charset.xCount = 16;
|
|
|
|
_charset.yCount = 7;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Charset Graphics::_charset;
|
|
|
|
|
|
|
|
CharsetType Graphics::_charsetType;
|
|
|
|
|
2008-11-10 20:38:54 +00:00
|
|
|
} // namespace Tucker
|