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 #include "kyra/graphics/screen_hof.h"
24 #include "kyra/engine/kyra_hof.h"
25 
26 namespace Kyra {
27 
Screen_HoF(KyraEngine_HoF * vm,OSystem * system)28 Screen_HoF::Screen_HoF(KyraEngine_HoF *vm, OSystem *system)
29 	: Screen_v2(vm, system, _screenDimTable, _screenDimTableCount), _vm(vm) {
30 }
31 
generateGrayOverlay(const Palette & srcPal,uint8 * grayOverlay,int factor,int addR,int addG,int addB,int lastColor,bool flag)32 void Screen_HoF::generateGrayOverlay(const Palette &srcPal, uint8 *grayOverlay, int factor, int addR, int addG, int addB, int lastColor, bool flag) {
33 	Palette tmpPal(lastColor);
34 
35 	for (int i = 0; i != lastColor; i++) {
36 		if (flag) {
37 			int v = ((((srcPal[3 * i] & 0x3F) + (srcPal[3 * i + 1] & 0x3F)
38 				+ (srcPal[3 * i + 2] & 0x3F)) / 3) * factor) / 0x40;
39 			tmpPal[3 * i] = tmpPal[3 * i + 1] = tmpPal[3 * i + 2] = v & 0xFF;
40 		} else {
41 			int v = (((srcPal[3 * i] & 0x3F) * factor) / 0x40) + addR;
42 			tmpPal[3 * i] = (v > 0x3F) ? 0x3F : v & 0xFF;
43 			v = (((srcPal[3 * i + 1] & 0x3F) * factor) / 0x40) + addG;
44 			tmpPal[3 * i + 1] = (v > 0x3F) ? 0x3F : v & 0xFF;
45 			v = (((srcPal[3 * i + 2] & 0x3F) * factor) / 0x40) + addB;
46 			tmpPal[3 * i + 2] = (v > 0x3F) ? 0x3F : v & 0xFF;
47 		}
48 	}
49 
50 	for (int i = 0; i < lastColor; i++)
51 		grayOverlay[i] = findLeastDifferentColor(tmpPal.getData() + 3 * i, srcPal, 0, lastColor);
52 }
53 
cmpFadeFrameStep(int srcPage,int srcW,int srcH,int srcX,int srcY,int dstPage,int dstW,int dstH,int dstX,int dstY,int cmpW,int cmpH,int cmpPage)54 void Screen_HoF::cmpFadeFrameStep(int srcPage, int srcW, int srcH, int srcX, int srcY, int dstPage, int dstW,
55 	int dstH, int dstX, int dstY, int cmpW, int cmpH, int cmpPage) {
56 
57 	if (!cmpW || !cmpH)
58 		return;
59 
60 	int r1, r2, r3, r4, r5, r6;
61 
62 	int X1 = srcX;
63 	int Y1 = srcY;
64 	int W1 = cmpW;
65 	int H1 = cmpH;
66 
67 	if (!calcBounds(srcW, srcH, X1, Y1, W1, H1, r1, r2, r3))
68 		return;
69 
70 	int X2 = dstX;
71 	int Y2 = dstY;
72 	int W2 = W1;
73 	int H2 = H1;
74 
75 	if (!calcBounds(dstW, dstH, X2, Y2, W2, H2, r4, r5, r6))
76 		return;
77 
78 	const uint8 *src = getPagePtr(srcPage) + srcW * (Y1 + r5);
79 	uint8 *dst = getPagePtr(dstPage) + dstW * (Y2 + r2);
80 	const uint8 *cmp = getPagePtr(cmpPage);
81 
82 	while (H2--) {
83 		const uint8 *s = src + r4 + X1;
84 		uint8 *d = dst + r1 + X2;
85 
86 		for (int i = 0; i < W2; i++) {
87 			int ix = (*s++ << 8) + *d;
88 			*d++ = cmp[ix];
89 		}
90 
91 		src += W1;
92 		dst += W2;
93 	}
94 }
95 
96 } // End of namespace Kyra
97