Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
convert.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : Command & Conquer *
24 * *
25 * $Archive:: /G/wwlib/Convert.cpp $*
26 * *
27 * $Author:: Eric_c $*
28 * *
29 * $Modtime:: 2/19/99 11:51a $*
30 * *
31 * $Revision:: 2 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#include "always.h"
38#include "blitblit.h"
39#include "convert.h"
40#include "dsurface.h"
41#include "hsv.h"
42#include "rlerle.h"
43
44
45ConvertClass::ConvertClass(PaletteClass const & artpalette, PaletteClass const & screenpalette, Surface const & surface) :
46 BBP(surface.Bytes_Per_Pixel()),
63{
64 /*
65 ** The draw data initialization is greatly dependant upon the pixel format
66 ** of the display surface. Check the pixel format and set the values accordingly.
67 */
68 if (BBP == 1) {
69
70 /*
71 ** Build the shadow table by creating a slightly darker version of
72 ** the color and then finding the closest match to it.
73 */
74 ShadowTable = W3DNEWARRAY unsigned char [256];
75 ShadowTable[0] = 0;
76 for (int shadow = 1; shadow < 256; shadow++) {
77 HSVClass hsv = artpalette[shadow];
78 hsv.Set_Value((unsigned char)(hsv.Get_Value() / 2));
79 ShadowTable[shadow] = (unsigned char)artpalette.Closest_Color(hsv);
80 }
81
82 /*
83 ** The translator table is created by finding the closest color
84 ** in the display palette from each color in the source art
85 ** palette.
86 */
87 unsigned char * trans = W3DNEWARRAY unsigned char [256];
88 trans[0] = 0;
89 for (int index = 1; index < 256; index++) {
90 trans[index] = (unsigned char)screenpalette.Closest_Color(artpalette[index]);
91 }
92 Translator = (void *)trans;
93
94 /*
95 ** Construct all the blitter objects necessary to support the functionality
96 ** required for the draw permutations.
97 */
105
106 /*
107 ** Create the RLE aware blitter objects.
108 */
115
116 } else {
117
118 /*
119 ** The hicolor translation table is constructed according to the pixel
120 ** format of the display and the source art palette.
121 */
122 //assert(surface.Is_Direct_Draw());
123 Translator = W3DNEWARRAY unsigned short [256];
124 ((DSurface &)surface).Build_Remap_Table((unsigned short *)Translator, artpalette);
125
126 /*
127 ** Fetch the pixel mask values to be used for the various algorithmic
128 ** pixel processing performed for hicolor displays.
129 */
130 int maskhalf = ((DSurface &)surface).Get_Halfbright_Mask();
131 int maskquarter = ((DSurface &)surface).Get_Quarterbright_Mask();
132
133 /*
134 ** Construct all the blitter objects necessary to support the functionality
135 ** required for the draw permutations.
136 */
140 ShadowBlitter = W3DNEW BlitTransDarken<unsigned short>((unsigned short)maskhalf);
141 Translucent1Blitter = W3DNEW BlitTransLucent75<unsigned short>((unsigned short const *)Translator, (unsigned short)maskquarter);
142 Translucent2Blitter = W3DNEW BlitTransLucent50<unsigned short>((unsigned short const *)Translator, (unsigned short)maskhalf);
143 Translucent3Blitter = W3DNEW BlitTransLucent25<unsigned short>((unsigned short const *)Translator, (unsigned short)maskquarter);
144
145 /*
146 ** Create the RLE aware blitter objects.
147 */
151 RLETranslucent1Blitter = W3DNEW RLEBlitTransLucent75<unsigned short>((unsigned short const *)Translator, (unsigned short)maskquarter);
152 RLETranslucent2Blitter = W3DNEW RLEBlitTransLucent50<unsigned short>((unsigned short const *)Translator, (unsigned short)maskhalf);
153 RLETranslucent3Blitter = W3DNEW RLEBlitTransLucent25<unsigned short>((unsigned short const *)Translator, (unsigned short)maskquarter);
154 }
155}
156
157
159{
160 delete PlainBlitter;
162
163 delete TransBlitter;
165
166 delete ShadowBlitter;
168
169 delete RemapBlitter;
171
172 delete Translucent1Blitter;
174
175 delete Translucent2Blitter;
177
178 delete Translucent3Blitter;
180
181 delete [] Translator;
183
184 delete [] ShadowTable;
186
187 delete RLETransBlitter;
189
190 delete RLEShadowBlitter;
192
193 delete RLERemapBlitter;
195
198
201
204}
205
206
208{
209 if (flags & SHAPE_REMAP) return(RemapBlitter);
210
211 /*
212 ** Quick check to see if this is a translucent operation. If so, then no
213 ** further examination of the flags is necessary.
214 */
217 return(Translucent3Blitter);
218
220 return(Translucent2Blitter);
221
223 return(Translucent1Blitter);
224 }
225
226 if (flags & SHAPE_DARKEN) return(ShadowBlitter);
227
228 if (flags & SHAPE_NOTRANS) return(PlainBlitter);
229
230 return(TransBlitter);
231}
232
233
235{
236 if (flags & SHAPE_REMAP) return(RLERemapBlitter);
237
238 /*
239 ** Quick check to see if this is a translucent operation. If so, then no
240 ** further examination of the flags is necessary.
241 */
245
248
251 }
252
253 if (flags & SHAPE_DARKEN) return(RLEShadowBlitter);
254
255 // This should be fixed to return the RLEPlainBlitter when one is available
256 // but if you need to use this in the mean time just don't RLE compress the
257 // shape (since it only compresses transparent pixels and the reason we compress
258 // them is so we can skip them easily.)
259 if (flags & SHAPE_NOTRANS) return(RLETransBlitter);
260
261 return(RLETransBlitter);
262}
263
264
265
266
#define NULL
Definition BaseType.h:92
ShapeFlags_Type
Definition Convert.h:50
@ SHAPE_NOTRANS
Definition Convert.h:63
@ SHAPE_TRANSLUCENT50
Definition Convert.h:59
@ SHAPE_TRANSLUCENT75
Definition Convert.h:60
@ SHAPE_TRANSLUCENT25
Definition Convert.h:58
@ SHAPE_DARKEN
Definition Convert.h:57
@ SHAPE_REMAP
Definition Convert.h:62
#define W3DNEWARRAY
Definition always.h:110
#define W3DNEW
Definition always.h:109
Blitter * ShadowBlitter
Definition Convert.h:136
RLEBlitter * RLETranslucent1Blitter
Definition Convert.h:149
Blitter * TransBlitter
Definition Convert.h:135
Blitter * RemapBlitter
Definition Convert.h:137
Blitter * Translucent1Blitter
Definition Convert.h:138
RLEBlitter * RLERemapBlitter
Definition Convert.h:148
RLEBlitter * RLETranslucent3Blitter
Definition Convert.h:151
RLEBlitter const * RLEBlitter_From_Flags(ShapeFlags_Type flags) const
Definition convert.cpp:234
Blitter * Translucent2Blitter
Definition Convert.h:139
RLEBlitter * RLETransBlitter
Definition Convert.h:146
Blitter * Translucent3Blitter
Definition Convert.h:140
Blitter const * Blitter_From_Flags(ShapeFlags_Type flags) const
Definition convert.cpp:207
unsigned char * ShadowTable
Definition Convert.h:163
int Bytes_Per_Pixel(void) const
Definition Convert.h:110
RLEBlitter * RLETranslucent2Blitter
Definition Convert.h:150
unsigned char const * RemapTable
Definition Convert.h:170
RLEBlitter * RLEShadowBlitter
Definition Convert.h:147
~ConvertClass(void)
Definition convert.cpp:158
Blitter * PlainBlitter
Definition Convert.h:134
void * Translator
Definition Convert.h:158
ConvertClass(PaletteClass const &artpalette, PaletteClass const &screenpalette, Surface const &typicalsurface)
Definition convert.cpp:45
Definition hsv.h:49
void Set_Value(unsigned char value)
Definition hsv.h:73
int Get_Value(void) const
Definition hsv.h:70
int Closest_Color(RGBClass const &rgb) const
Definition palette.cpp:254