|
2 | 2 | #include "gdrv.h"
|
3 | 3 |
|
4 | 4 | #include "GroupData.h"
|
5 |
| -#include "memory.h" |
6 | 5 | #include "partman.h"
|
7 | 6 | #include "pb.h"
|
8 | 7 | #include "score.h"
|
9 | 8 | #include "winmain.h"
|
10 | 9 |
|
11 | 10 | ColorRgba gdrv::current_palette[256]{};
|
12 | 11 |
|
13 |
| -int gdrv::create_bitmap(gdrv_bitmap8* bmp, int width, int height, int stride, bool indexed) |
| 12 | +gdrv_bitmap8::gdrv_bitmap8(int width, int height, bool indexed) |
14 | 13 | {
|
15 | 14 | assertm(width >= 0 && height >= 0, "Negative bitmap8 dimensions");
|
16 | 15 |
|
17 |
| - bmp->Width = width; |
18 |
| - bmp->Height = height; |
19 |
| - bmp->Stride = width; |
20 |
| - bmp->BitmapType = BitmapTypes::DibBitmap; |
21 |
| - bmp->Texture = nullptr; |
22 |
| - |
23 |
| - if (stride >= 0) |
24 |
| - bmp->IndexedStride = stride; |
25 |
| - else |
26 |
| - { |
27 |
| - bmp->IndexedStride = width; |
28 |
| - if (width % 4) |
29 |
| - bmp->IndexedStride = width - width % 4 + 4; |
30 |
| - } |
| 16 | + Width = width; |
| 17 | + Height = height; |
| 18 | + Stride = width; |
| 19 | + IndexedStride = width; |
| 20 | + BitmapType = BitmapTypes::DibBitmap; |
| 21 | + Texture = nullptr; |
| 22 | + IndexedBmpPtr = nullptr; |
| 23 | + XPosition = 0; |
| 24 | + YPosition = 0; |
| 25 | + Resolution = 0; |
31 | 26 |
|
32 | 27 | if (indexed)
|
33 |
| - bmp->IndexedBmpPtr = memory::allocate(bmp->Height * bmp->IndexedStride); |
34 |
| - bmp->BmpBufPtr1 = memory::allocate<ColorRgba>(bmp->Height * bmp->Stride); |
35 |
| - if (bmp->BmpBufPtr1) |
36 |
| - { |
37 |
| - return 0; |
38 |
| - } |
39 |
| - return -1; |
| 28 | + IndexedBmpPtr = new char[Height * IndexedStride]; |
| 29 | + BmpBufPtr1 = new ColorRgba[Height * Stride]; |
40 | 30 | }
|
41 | 31 |
|
42 |
| -int gdrv::create_bitmap(gdrv_bitmap8& bmp, const dat8BitBmpHeader& header) |
| 32 | +gdrv_bitmap8::gdrv_bitmap8(const dat8BitBmpHeader& header) |
43 | 33 | {
|
44 | 34 | assertm(header.Width >= 0 && header.Height >= 0, "Negative bitmap8 dimensions");
|
45 | 35 |
|
46 | 36 | if (header.IsFlagSet(bmp8Flags::Spliced))
|
47 |
| - bmp.BitmapType = BitmapTypes::Spliced; |
| 37 | + BitmapType = BitmapTypes::Spliced; |
48 | 38 | else if (header.IsFlagSet(bmp8Flags::DibBitmap))
|
49 |
| - bmp.BitmapType = BitmapTypes::DibBitmap; |
| 39 | + BitmapType = BitmapTypes::DibBitmap; |
50 | 40 | else
|
51 |
| - bmp.BitmapType = BitmapTypes::RawBitmap; |
| 41 | + BitmapType = BitmapTypes::RawBitmap; |
52 | 42 |
|
53 |
| - bmp.Width = header.Width; |
54 |
| - bmp.Stride = header.Width; |
55 |
| - bmp.IndexedStride = header.Width; |
56 |
| - bmp.Height = header.Height; |
57 |
| - bmp.XPosition = header.XPosition; |
58 |
| - bmp.YPosition = header.YPosition; |
59 |
| - bmp.Resolution = header.Resolution; |
60 |
| - bmp.Texture = nullptr; |
| 43 | + Width = header.Width; |
| 44 | + Stride = header.Width; |
| 45 | + IndexedStride = header.Width; |
| 46 | + Height = header.Height; |
| 47 | + XPosition = header.XPosition; |
| 48 | + YPosition = header.YPosition; |
| 49 | + Resolution = header.Resolution; |
| 50 | + Texture = nullptr; |
61 | 51 |
|
62 | 52 | int sizeInBytes;
|
63 |
| - if (bmp.BitmapType == BitmapTypes::Spliced) |
| 53 | + if (BitmapType == BitmapTypes::Spliced) |
64 | 54 | {
|
65 | 55 | sizeInBytes = header.Size;
|
66 | 56 | }
|
67 | 57 | else
|
68 | 58 | {
|
69 |
| - if (bmp.BitmapType == BitmapTypes::RawBitmap) |
70 |
| - assertm(bmp.Width % 4 == 0 || header.IsFlagSet(bmp8Flags::RawBmpUnaligned), "Wrong raw bitmap align flag"); |
71 |
| - if (bmp.Width % 4) |
72 |
| - bmp.IndexedStride = bmp.Width - bmp.Width % 4 + 4; |
73 |
| - sizeInBytes = bmp.Height * bmp.IndexedStride; |
| 59 | + if (BitmapType == BitmapTypes::RawBitmap) |
| 60 | + assertm(Width % 4 == 0 || header.IsFlagSet(bmp8Flags::RawBmpUnaligned), "Wrong raw bitmap align flag"); |
| 61 | + if (Width % 4) |
| 62 | + IndexedStride = Width - Width % 4 + 4; |
| 63 | + sizeInBytes = Height * IndexedStride; |
74 | 64 | assertm(sizeInBytes == header.Size, "Wrong bitmap8 size");
|
75 | 65 | }
|
76 | 66 |
|
77 |
| - bmp.IndexedBmpPtr = memory::allocate(sizeInBytes); |
78 |
| - bmp.BmpBufPtr1 = memory::allocate<ColorRgba>(bmp.Stride * bmp.Height); |
79 |
| - if (bmp.BmpBufPtr1) |
| 67 | + IndexedBmpPtr = new char[sizeInBytes]; |
| 68 | + BmpBufPtr1 = new ColorRgba[Stride * Height]; |
| 69 | +} |
| 70 | + |
| 71 | +gdrv_bitmap8::~gdrv_bitmap8() |
| 72 | +{ |
| 73 | + if (BitmapType != BitmapTypes::None) |
80 | 74 | {
|
81 |
| - return 0; |
| 75 | + delete[] BmpBufPtr1; |
| 76 | + delete[] IndexedBmpPtr; |
| 77 | + if (Texture) |
| 78 | + SDL_DestroyTexture(Texture); |
82 | 79 | }
|
83 |
| - return -1; |
84 | 80 | }
|
85 | 81 |
|
86 | 82 | int gdrv::display_palette(ColorRgba* plt)
|
@@ -139,24 +135,6 @@ int gdrv::display_palette(ColorRgba* plt)
|
139 | 135 | return 0;
|
140 | 136 | }
|
141 | 137 |
|
142 |
| - |
143 |
| -int gdrv::destroy_bitmap(gdrv_bitmap8* bmp) |
144 |
| -{ |
145 |
| - if (!bmp) |
146 |
| - return -1; |
147 |
| - |
148 |
| - if (bmp->BitmapType != BitmapTypes::None) |
149 |
| - { |
150 |
| - memory::free(bmp->BmpBufPtr1); |
151 |
| - if (bmp->IndexedBmpPtr) |
152 |
| - memory::free(bmp->IndexedBmpPtr); |
153 |
| - if (bmp->Texture) |
154 |
| - SDL_DestroyTexture(bmp->Texture); |
155 |
| - } |
156 |
| - memset(bmp, 0, sizeof(gdrv_bitmap8)); |
157 |
| - return 0; |
158 |
| -} |
159 |
| - |
160 | 138 | void gdrv::fill_bitmap(gdrv_bitmap8* bmp, int width, int height, int xOff, int yOff, uint8_t fillChar)
|
161 | 139 | {
|
162 | 140 | auto color = current_palette[fillChar];
|
|
0 commit comments