Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
simpdib.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:: /Commando/Code/Tools/max2w3d/simpdib.cpp $*
26 * *
27 * $Author:: Greg_h $*
28 * *
29 * $Modtime:: 10/14/97 3:07p $*
30 * *
31 * $Revision:: 3 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#include "simpdib.h"
38
39
40SimpleDIBClass::SimpleDIBClass(HWND hwnd,int width,int height,PaletteClass & pal):
41 IsZombie(false),
42 Info(NULL),
43 Handle(0),
44 Pixels(NULL),
45 Width(width),
46 Height(height),
47 PixelBase(NULL),
48 Pitch(NULL)
49{
50 // Allocate a BITMAPINFO structure
51 Info = (BITMAPINFO *) new char [sizeof(BITMAPINFO) + 256*sizeof(RGBQUAD)];
52
53 if (Info == NULL) {
54 IsZombie = true;
55 return;
56 }
57
58 // Describe the type of DIB we want.
59 Info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
60 Info->bmiHeader.biWidth = width;
61 Info->bmiHeader.biHeight = -height; //ask for a top-down dib.
62 Info->bmiHeader.biPlanes = 1;
63 Info->bmiHeader.biBitCount = 8;
64 Info->bmiHeader.biCompression = BI_RGB;
65 Info->bmiHeader.biSizeImage = 0;
66 Info->bmiHeader.biXPelsPerMeter = 0;
67 Info->bmiHeader.biYPelsPerMeter = 0;
68 Info->bmiHeader.biClrUsed = 256;
69 Info->bmiHeader.biClrImportant = 256;
70
71 // Fill in the DIB's palette.
72 for (int i=0; i<256; i++) {
73 Info->bmiColors[i].rgbBlue = (unsigned char)pal[i].Get_Blue();
74 Info->bmiColors[i].rgbGreen = (unsigned char)pal[i].Get_Green();
75 Info->bmiColors[i].rgbRed = (unsigned char)pal[i].Get_Red();
76 Info->bmiColors[i].rgbReserved = 0;
77 }
78
79 // Create the DIB.
80 HDC hdc = GetDC(hwnd);
81 Handle = CreateDIBSection(hdc, Info, DIB_RGB_COLORS,(void**)&Pixels, NULL, 0);
82 ReleaseDC(hwnd, hdc);
83
84 if (!Handle) {
85 IsZombie = true;
86 return;
87 }
88
89 Width = Info->bmiHeader.biWidth;
90 Height = abs(Info->bmiHeader.biHeight);
91 Pitch = (Width + 3) & 0xfffffffC;
92
93 // Check if the DIB is bottom-up or top-down.
94 // (it better be top-down, thats what I'm asking for!!!)
95 if (Info->bmiHeader.biHeight > 0) {
96
97 // bottom-up DIB
98 PixelBase = (Pixels + (Height - 1) * Width);
99 Pitch = -Pitch;
100
101 } else {
102
103 // top-down DIB
104 PixelBase = Pixels;
105 Pitch = Pitch;
106 }
107}
108
110{
111 if (Info) delete [] Info;
112 if (Handle) DeleteObject(Handle);
113}
114
115
116void SimpleDIBClass::Clear(unsigned char color)
117{
118 if (Pixels) {
119 memset(Pixels, color, abs(Pitch)*Height);
120 }
121}
122
123void SimpleDIBClass::Set_Pixel(int i,int j,unsigned char color)
124{
125 if ((i < 0) || (j < 0) || (i >= Width) || (j >= Height)) {
126 return;
127 }
128
129 *(PixelBase + j*Pitch + i) = color;
130}
#define NULL
Definition BaseType.h:92
@ false
Definition bool.h:59
SimpleDIBClass(HWND hwnd, int width, int height, PaletteClass &pal)
Definition simpdib.cpp:40
void Clear(unsigned char color)
Definition simpdib.cpp:116
~SimpleDIBClass(void)
Definition simpdib.cpp:109
void Set_Pixel(int i, int j, unsigned char color)
Definition simpdib.cpp:123