Isle
Loading...
Searching...
No Matches
mxbitmap.h
Go to the documentation of this file.
1#ifndef MXBITMAP_H
2#define MXBITMAP_H
3
4#include "mxcore.h"
5#include "mxtypes.h"
6
7#include <ddraw.h>
8#include <stdlib.h>
9
10class MxPalette;
11
12// The stock BITMAPINFO struct from wingdi.h only makes room for one color
13// in the palette. It seems like the expectation (if you use the struct)
14// is to malloc as much as you actually need, and then index into the array
15// anyway even though its stated size is [1].
16// https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfo
17// In our case, the size 0x428 is used frequently, which matches
18// a 40-byte header plus 256 colors, so just use that as our template.
19
26 BITMAPINFOHEADER m_bmiHeader;
27 RGBQUAD m_bmiColors[256];
33 static MxU32 Size() { return sizeof(MxBITMAPINFO); }
34};
35
36// Non-standard value for biCompression in the BITMAPINFOHEADER struct.
37// By default, uncompressed bitmaps (BI_RGB) are stored in bottom-up order.
38// You can specify that the bitmap has top-down order instead by providing
39// a negative number for biHeight. It could be that Mindscape decided on a
40// belt & suspenders approach here.
46#define BI_RGB_TOPDOWN 0x10
47
55class MxBitmap : public MxCore {
56public:
60 MxBitmap();
61
65 ~MxBitmap() override; // vtable+00
66
72 virtual MxResult ImportBitmap(MxBitmap* p_bitmap); // vtable+0x14
73
79 virtual MxResult ImportBitmapInfo(MxBITMAPINFO* p_info); // vtable+0x18
80
89 virtual MxResult SetSize(MxS32 p_width, MxS32 p_height, MxPalette* p_palette, MxBool); // vtable+0x1c
90
96 virtual MxResult LoadFile(HANDLE p_handle); // vtable+0x20
97
103 virtual MxLong Read(const char* p_filename); // vtable+0x24
104
110 virtual MxS32 VTable0x28(MxS32) { return -1; } // vtable+0x28
111
123 virtual void BitBlt(
124 MxBitmap* p_src,
125 MxS32 p_left,
126 MxS32 p_top,
127 MxS32 p_right,
128 MxS32 p_bottom,
129 MxS32 p_width,
130 MxS32 p_height
131 ); // vtable+0x2c
132
144 virtual void BitBltTransparent(
145 MxBitmap* p_src,
146 MxS32 p_left,
147 MxS32 p_top,
148 MxS32 p_right,
149 MxS32 p_bottom,
150 MxS32 p_width,
151 MxS32 p_height
152 ); // vtable+0x30
153
159 virtual MxPalette* CreatePalette(); // vtable+0x34
160
166 virtual void ImportPalette(MxPalette* p_palette); // vtable+0x38
167
174 virtual MxResult SetBitDepth(MxBool); // vtable+0x3c
175
188 virtual MxResult StretchBits(
189 HDC p_hdc,
190 MxS32 p_xSrc,
191 MxS32 p_ySrc,
192 MxS32 p_xDest,
193 MxS32 p_yDest,
194 MxS32 p_destWidth,
195 MxS32 p_destHeight
196 ); // vtable+0x40
197
204 MxLong AlignToFourByte(MxLong p_value) const { return (p_value + 3) & -4; }
205
212 static MxLong HeightAbs(MxLong p_value) { return p_value > 0 ? p_value : -p_value; }
213
218 BITMAPINFOHEADER* GetBmiHeader() const { return m_bmiHeader; }
219
224 MxLong GetBmiWidth() const { return m_bmiHeader->biWidth; }
225
230 MxLong GetBmiStride() const { return ((m_bmiHeader->biWidth + 3) & -4); }
231
236 MxLong GetBmiHeight() const { return m_bmiHeader->biHeight; }
237
242 MxLong GetBmiHeightAbs() const { return HeightAbs(m_bmiHeader->biHeight); }
243
248 MxU8* GetImage() const { return m_data; }
249
254 MxBITMAPINFO* GetBitmapInfo() const { return m_info; }
255
260 MxLong GetDataSize() const { return AlignToFourByte(m_bmiHeader->biWidth) * GetBmiHeightAbs(); }
261
268 {
269 if (m_bmiHeader->biCompression == BI_RGB_TOPDOWN) {
270 return TRUE;
271 }
272 else {
273 return m_bmiHeader->biHeight < 0;
274 }
275 }
276
277#define GetAdjustedStride(p_bitmap) \
278 (p_bitmap->IsTopDown() ? p_bitmap->AlignToFourByte(p_bitmap->GetBmiWidth()) \
279 : -p_bitmap->AlignToFourByte(p_bitmap->GetBmiWidth()))
280
288 MxU8* GetStart(MxS32 p_left, MxS32 p_top) const
289 {
290 if (m_bmiHeader->biCompression == BI_RGB) {
291 return m_data + p_left +
292 AlignToFourByte(GetBmiWidth()) * (IsTopDown() ? p_top : (GetBmiHeightAbs() - 1) - p_top);
293 }
294 else if (m_bmiHeader->biCompression == BI_RGB_TOPDOWN) {
295 return m_data;
296 }
297 else {
298 return m_data + AlignToFourByte(GetBmiWidth()) * (IsTopDown() ? 0 : (GetBmiHeightAbs() - 1));
299 }
300 }
301
302 // SYNTHETIC: LEGO1 0x100bc9f0
303 // SYNTHETIC: BETA10 0x1013dcd0
304 // MxBitmap::`scalar deleting destructor'
305
306private:
311 MxLong MxBitmapInfoSize() const { return sizeof(MxBITMAPINFO); }
312
317 MxBool IsBottomUp()
318 {
319 if (m_bmiHeader->biCompression == BI_RGB_TOPDOWN) {
320 return FALSE;
321 }
322 else {
323 return m_bmiHeader->biHeight > 0;
324 }
325 }
326
333 MxResult ImportColorsToPalette(RGBQUAD*, MxPalette*);
334
335 MxBITMAPINFO* m_info;
336 BITMAPINFOHEADER* m_bmiHeader;
337 RGBQUAD* m_paletteData;
338 MxU8* m_data;
339 MxBool m_isHighColor;
340 MxPalette* m_palette;
341};
342
343#endif // MXBITMAP_H
[AI] Represents an 8bpp or high color device-independent bitmap (DIB) and provides operations for bit...
Definition: mxbitmap.h:55
MxBool IsTopDown() const
[AI] Checks if the bitmap is stored in top-down scanline order.
Definition: mxbitmap.h:267
virtual MxResult StretchBits(HDC p_hdc, MxS32 p_xSrc, MxS32 p_ySrc, MxS32 p_xDest, MxS32 p_yDest, MxS32 p_destWidth, MxS32 p_destHeight)
[AI] Draws (blits) a scaled region of the bitmap to a Windows device context.
Definition: mxbitmap.cpp:454
MxLong GetBmiStride() const
[AI] Computes the stride (bytes per scanline, aligned to 4 bytes).
Definition: mxbitmap.h:230
MxBITMAPINFO * GetBitmapInfo() const
[AI] Retrieves the pointer to the underlying MxBITMAPINFO struct (header and palette).
Definition: mxbitmap.h:254
virtual MxS32 VTable0x28(MxS32)
[AI] Placeholder or unused virtual; always returns -1.
Definition: mxbitmap.h:110
virtual MxResult SetBitDepth(MxBool)
[AI] Changes the bit depth mode for the bitmap (palettized or high color).
Definition: mxbitmap.cpp:404
virtual MxPalette * CreatePalette()
[AI] Allocates or clones the current palette for the bitmap.
Definition: mxbitmap.cpp:352
MxLong AlignToFourByte(MxLong p_value) const
[AI] Aligns a value up to the nearest multiple of four (stride alignment for DIBs).
Definition: mxbitmap.h:204
MxBitmap()
[AI] Constructs an empty MxBitmap instance, initializing all data pointers to NULL.
Definition: mxbitmap.cpp:16
static MxLong HeightAbs(MxLong p_value)
[AI] Returns the absolute value of the input height (for DIBs).
Definition: mxbitmap.h:212
virtual MxResult ImportBitmap(MxBitmap *p_bitmap)
[AI] Imports the contents of another bitmap into this bitmap, allocating new storage and copying meta...
Definition: mxbitmap.cpp:136
MxLong GetBmiHeightAbs() const
[AI] Returns the absolute value of the bitmap's height.
Definition: mxbitmap.h:242
virtual void BitBltTransparent(MxBitmap *p_src, MxS32 p_left, MxS32 p_top, MxS32 p_right, MxS32 p_bottom, MxS32 p_width, MxS32 p_height)
[AI] Copies a rectangular region from a source bitmap to this bitmap, but skips "transparent" (index ...
Definition: mxbitmap.cpp:306
~MxBitmap() override
[AI] Frees allocated memory for bitmap info, pixel data, and palette.
Definition: mxbitmap.cpp:28
MxLong GetBmiHeight() const
[AI] Fetches the height (could be negative if top-down) of the bitmap.
Definition: mxbitmap.h:236
virtual MxResult SetSize(MxS32 p_width, MxS32 p_height, MxPalette *p_palette, MxBool)
[AI] Allocates the bitmap to a specified width and height, attaches a palette, and configures bit dep...
Definition: mxbitmap.cpp:43
virtual MxLong Read(const char *p_filename)
[AI] Loads a bitmap from a file given its filename.
Definition: mxbitmap.cpp:175
virtual MxResult LoadFile(HANDLE p_handle)
[AI] Loads a bitmap from a file handle, populating header, palette data and pixel data.
Definition: mxbitmap.cpp:202
MxU8 * GetStart(MxS32 p_left, MxS32 p_top) const
[AI] Returns a pointer to the starting address of the pixel data at the specified coordinates.
Definition: mxbitmap.h:288
virtual void ImportPalette(MxPalette *p_palette)
[AI] Attaches or clones a palette for the bitmap and updates color data as needed.
Definition: mxbitmap.cpp:387
MxLong GetDataSize() const
[AI] Computes the total size in bytes for the bitmap's pixel data buffer.
Definition: mxbitmap.h:260
BITMAPINFOHEADER * GetBmiHeader() const
[AI] Returns a pointer to the underlying BITMAPINFOHEADER.
Definition: mxbitmap.h:218
virtual void BitBlt(MxBitmap *p_src, MxS32 p_left, MxS32 p_top, MxS32 p_right, MxS32 p_bottom, MxS32 p_width, MxS32 p_height)
[AI] Copies a rectangular area from a source bitmap into this bitmap (BitBlt).
Definition: mxbitmap.cpp:267
MxLong GetBmiWidth() const
[AI] Fetches the width (in pixels) encoded in this bitmap's header.
Definition: mxbitmap.h:224
virtual MxResult ImportBitmapInfo(MxBITMAPINFO *p_info)
[AI] Imports bitmap header/palette info (but not pixel data) from the given info block.
Definition: mxbitmap.cpp:98
MxU8 * GetImage() const
[AI] Retrieves the pointer to the image pixel data.
Definition: mxbitmap.h:248
[AI] Base virtual class for all Mindscape engine (Mx) objects.
Definition: mxcore.h:15
[AI] Encapsulates a DirectDraw 8-bit (256 color) palette for use with DirectX rendering.
Definition: mxpalette.h:17
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define BI_RGB_TOPDOWN
[AI] Non-standard biCompression value indicating top-down row order for uncompressed bitmaps.
Definition: mxbitmap.h:46
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
MxLong MxResult
[AI]
Definition: mxtypes.h:106
int MxLong
[AI]
Definition: mxtypes.h:83
unsigned char MxU8
[AI]
Definition: mxtypes.h:8
signed int MxS32
[AI]
Definition: mxtypes.h:38
unsigned int MxU32
[AI]
Definition: mxtypes.h:32
[AI] Represents a bitmap information header plus a 256-color palette, matching the layout for 8-bit D...
Definition: mxbitmap.h:25
static MxU32 Size()
[AI] Returns the size of this structure in bytes (0x428 for 256 colors).
Definition: mxbitmap.h:33
RGBQUAD m_bmiColors[256]
[AI] 256-entry color palette for 8bpp images.
Definition: mxbitmap.h:27
BITMAPINFOHEADER m_bmiHeader
[AI] Standard DIB bitmap header (size 0x28 bytes).
Definition: mxbitmap.h:26