Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
dib.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/dib.cpp $*
26 * *
27 * $Author:: Eric_c $*
28 * *
29 * $Modtime:: 3/29/99 5:11p $*
30 * *
31 * $Revision:: 3 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * DIB8C::DIB8Class -- constructor *
36 * DIB8C::~DIB8Class -- destructor *
37 * DIB8C::Clear -- clears the DIB *
38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39
40#include "always.h"
41#include "dib.h"
42#include <math.h>
43
44/***********************************************************************************************
45 * DIB8C::DIB8Class -- constructor *
46 * *
47 * INPUT: *
48 * *
49 * OUTPUT: *
50 * *
51 * WARNINGS: *
52 * *
53 * HISTORY: *
54 * 04/18/1997 GH : Created. *
55 *=============================================================================================*/
56DIB8Class::DIB8Class(HWND hwnd,int width,int height,PaletteClass & pal):
57 IsZombie(false),
58 Info(NULL),
59 Handle(0),
60 Pixels(NULL),
61 Width(width),
62 Height(height),
63 PixelBase(NULL),
64 Pitch(NULL),
65 Surface(NULL)
66{
67 // Allocate a BITMAPINFO structure
68 Info = (BITMAPINFO *) new char [sizeof(BITMAPINFO) + 256*sizeof(RGBQUAD)];
69
70 if (Info == NULL) {
71 IsZombie = true;
72 return;
73 }
74
75 // Describe the type of DIB we want.
76 Info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
77 Info->bmiHeader.biWidth = width;
78 Info->bmiHeader.biHeight = -height; //ask for a top-down dib.
79 Info->bmiHeader.biPlanes = 1;
80 Info->bmiHeader.biBitCount = 8;
81 Info->bmiHeader.biCompression = BI_RGB;
82 Info->bmiHeader.biSizeImage = 0;
83 Info->bmiHeader.biXPelsPerMeter = 0;
84 Info->bmiHeader.biYPelsPerMeter = 0;
85 Info->bmiHeader.biClrUsed = 256;
86 Info->bmiHeader.biClrImportant = 256;
87
88 // Fill in the DIB's palette.
89 for (int i=0; i<256; i++) {
90 Info->bmiColors[i].rgbBlue = (unsigned char)pal[i].Get_Blue();
91 Info->bmiColors[i].rgbGreen = (unsigned char)pal[i].Get_Green();
92 Info->bmiColors[i].rgbRed = (unsigned char)pal[i].Get_Red();
93 Info->bmiColors[i].rgbReserved = 0;
94 }
95
96 // Create the DIB.
97 HDC hdc = GetDC(hwnd);
98 Handle = CreateDIBSection(hdc, Info, DIB_RGB_COLORS,(void**)&Pixels, NULL, 0);
99 ReleaseDC(hwnd, hdc);
100
101 if (!Handle) {
102 IsZombie = true;
103 return;
104 }
105
106 Width = Info->bmiHeader.biWidth;
107 Height = abs(Info->bmiHeader.biHeight);
108 Pitch = (Width + 3) & 0xfffffffC;
109
110 // Check if the DIB is bottom-up or top-down.
111 // (it better be top-down, thats what I'm asking for!!!)
112 if (Info->bmiHeader.biHeight > 0) {
113
114 // bottom-up DIB
115 PixelBase = (Pixels + (Height - 1) * Width);
116 Pitch = -Pitch;
117
118 } else {
119
120 // top-down DIB
121 PixelBase = Pixels;
122 Pitch = Pitch;
123 }
124
125 // Now, wrap a BSurface around the DIB.
126 int surfwid = abs(Pitch);
127 Surface = new BSurface(surfwid,Height,1,Pixels);
128
129 if (Surface == NULL) {
130 IsZombie = true;
131 return;
132 }
133}
134
135
136/***********************************************************************************************
137 * DIB8C::~DIB8Class -- destructor *
138 * *
139 * INPUT: *
140 * *
141 * OUTPUT: *
142 * *
143 * WARNINGS: *
144 * *
145 * HISTORY: *
146 * 04/18/1997 GH : Created. *
147 *=============================================================================================*/
149{
150 if (Info) delete [] Info;
151 if (Handle) DeleteObject(Handle);
152 if (Surface) delete Surface;
153}
154
155
156/***********************************************************************************************
157 * DIB8C::Clear -- clears the DIB *
158 * *
159 * INPUT: *
160 * *
161 * OUTPUT: *
162 * *
163 * WARNINGS: *
164 * *
165 * HISTORY: *
166 * 04/18/1997 GH : Created. *
167 *=============================================================================================*/
168void DIB8Class::Clear(unsigned char color)
169{
170 if (Pixels) {
171 memset(Pixels, color, Width*Height);
172 }
173}
174
#define NULL
Definition BaseType.h:92
@ false
Definition bool.h:59
DIB8Class(HWND hwnd, int width, int height, PaletteClass &pal)
Definition dib.cpp:56
~DIB8Class(void)
Definition dib.cpp:148
void Clear(unsigned char color)
Definition dib.cpp:168