Isle
Loading...
Searching...
No Matches
legoimage.cpp
Go to the documentation of this file.
1#include "legoimage.h"
2
3#include "decomp.h"
4#include "legostorage.h"
5#include "memory.h"
6
9
10// FUNCTION: LEGO1 0x100994c0
12{
13 m_red = 0;
14 m_green = 0;
15 m_blue = 0;
16}
17
18// FUNCTION: LEGO1 0x100994d0
20{
21 LegoResult result;
22 if ((result = p_storage->Read(&m_red, sizeof(m_red))) != SUCCESS) {
23 return result;
24 }
25 if ((result = p_storage->Read(&m_green, sizeof(m_green))) != SUCCESS) {
26 return result;
27 }
28 if ((result = p_storage->Read(&m_blue, sizeof(m_blue))) != SUCCESS) {
29 return result;
30 }
31 return SUCCESS;
32}
33
34// FUNCTION: LEGO1 0x10099520
36{
37 LegoResult result;
38 if ((result = p_storage->Write(&m_red, sizeof(m_red))) != SUCCESS) {
39 return result;
40 }
41 if ((result = p_storage->Write(&m_green, sizeof(m_green))) != SUCCESS) {
42 return result;
43 }
44 if ((result = p_storage->Write(&m_blue, sizeof(m_blue))) != SUCCESS) {
45 return result;
46 }
47 return SUCCESS;
48}
49
50// FUNCTION: LEGO1 0x10099570
52{
53 m_width = 0;
54 m_height = 0;
55 m_count = 0;
56 m_bits = NULL;
57}
58
59// FUNCTION: LEGO1 0x100995a0
61{
62 m_width = p_width;
63 m_height = p_height;
64 m_count = 0;
66}
67
68// FUNCTION: LEGO1 0x100995f0
70{
71 if (m_bits) {
72 delete[] m_bits;
73 }
74}
75
76// FUNCTION: LEGO1 0x10099610
78{
79 LegoResult result;
80 if ((result = p_storage->Read(&m_width, sizeof(m_width))) != SUCCESS) {
81 return result;
82 }
83 if ((result = p_storage->Read(&m_height, sizeof(m_height))) != SUCCESS) {
84 return result;
85 }
86 if ((result = p_storage->Read(&m_count, sizeof(m_height))) != SUCCESS) {
87 return result;
88 }
89 for (LegoU32 i = 0; i < m_count; i++) {
90 if ((result = m_palette[i].Read(p_storage)) != SUCCESS) {
91 return result;
92 }
93 }
94 if (m_bits) {
95 delete[] m_bits;
96 }
98 if ((result = p_storage->Read(m_bits, m_width * m_height)) != SUCCESS) {
99 return result;
100 }
101
102 if (p_square && m_width != m_height) {
103 LegoU8* newBits;
104
105 if (m_height < m_width) {
106 LegoU32 aspect = m_width / m_height;
107 newBits = new LegoU8[m_width * m_width];
108 LegoU8* src = m_bits;
109 LegoU8* dst = newBits;
110
111 for (LegoU32 row = 0; row < m_height; row++) {
112 if (aspect) {
113 for (LegoU32 dup = aspect; dup; dup--) {
114 memcpy(dst, src, m_width);
115 dst += m_width;
116 }
117 }
118 src += m_width;
119 }
120
122 }
123 else {
124 LegoU32 aspect = m_height / m_width;
125 newBits = new LegoU8[m_height * m_height];
126 LegoU8* src = m_bits;
127 LegoU8* dst = newBits;
128
129 for (LegoU32 row = 0; row < m_height; row++) {
130 for (LegoU32 col = 0; col < m_width; col++) {
131 if (aspect) {
132 for (LegoU32 dup = aspect; dup; dup--) {
133 *dst = *src;
134 dst++;
135 }
136 }
137
138 src++;
139 }
140 }
141
143 }
144
145 delete[] m_bits;
146 m_bits = newBits;
147 }
148
149 return SUCCESS;
150}
151
152// FUNCTION: LEGO1 0x100997e0
154{
155 LegoResult result;
156 if ((result = p_storage->Write(&m_width, sizeof(m_width))) != SUCCESS) {
157 return result;
158 }
159 if ((result = p_storage->Write(&m_height, sizeof(m_height))) != SUCCESS) {
160 return result;
161 }
162 if ((result = p_storage->Write(&m_count, sizeof(m_height))) != SUCCESS) {
163 return result;
164 }
165 for (LegoU32 i = 0; i < m_count; i++) {
166 if ((result = m_palette[i].Write(p_storage)) != SUCCESS) {
167 return result;
168 }
169 }
170 if (m_bits) {
171 if ((result = p_storage->Write(m_bits, m_width * m_height)) != SUCCESS) {
172 return result;
173 }
174 }
175 return SUCCESS;
176}
[AI] Class representing an 8-bit palettized image with up to 256 palette entries and indexed pixel da...
Definition: legoimage.h:68
LegoPaletteEntry m_palette[256]
[AI] Full palette array (256 possible 8-bit RGB entries).
Definition: legoimage.h:136
LegoResult Read(LegoStorage *p_storage, LegoU32 p_square)
[AI] Reads the full image from the storage source, including width, height, count,...
Definition: legoimage.cpp:77
LegoU8 * m_bits
[AI] Pointer to the image bits. Each byte is a palette index; size = width*height.
Definition: legoimage.h:137
LegoImage()
[AI] Constructs an empty image object. Palette is not initialized; bits is nullptr.
Definition: legoimage.cpp:51
LegoU32 m_count
[AI] Number of palette entries in use (<= 256).
Definition: legoimage.h:135
~LegoImage()
[AI] Destructor; releases any allocated pixel buffer memory.
Definition: legoimage.cpp:69
LegoU32 m_width
[AI] Image width, in pixels.
Definition: legoimage.h:133
LegoResult Write(LegoStorage *p_storage)
[AI] Writes the full image to the given storage: width, height, count, palette, pixel indices.
Definition: legoimage.cpp:153
LegoU32 m_height
[AI] Image height, in pixels.
Definition: legoimage.h:134
[AI] Represents a single entry in an 8-bit RGB palette with red, green, and blue components.
Definition: legoimage.h:12
LegoResult Read(LegoStorage *p_storage)
[AI] Reads the palette entry data from a storage object.
Definition: legoimage.cpp:19
LegoResult Write(LegoStorage *p_storage)
[AI] Writes the palette entry data to a storage object.
Definition: legoimage.cpp:35
LegoU8 m_blue
[AI] Blue channel (0-255). Offset 0x02.
Definition: legoimage.h:59
LegoPaletteEntry()
[AI] Constructs an empty palette entry with all components initialized to 0. [Existing comment: Defau...
Definition: legoimage.cpp:11
LegoU8 m_red
[AI] Red channel (0-255). Offset 0x00.
Definition: legoimage.h:57
LegoU8 m_green
[AI] Green channel (0-255). Offset 0x01.
Definition: legoimage.h:58
Abstract base class providing an interface for file-like storage with binary and text read/write oper...
Definition: legostorage.h:16
virtual LegoResult Write(const void *p_buffer, LegoU32 p_size)=0
Write bytes from buffer into storage.
virtual LegoResult Read(void *p_buffer, LegoU32 p_size)=0
Read bytes from storage into buffer.
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
unsigned long LegoU32
[AI] Unsigned 32-bit integer type for cross-platform compatibility.
Definition: legotypes.h:71
unsigned char LegoU8
[AI] Unsigned 8-bit integer type used throughout LEGO Island.
Definition: legotypes.h:47
LegoS32 LegoResult
[AI] Function result type (return code): typically SUCCESS (0) or FAILURE (-1).
Definition: legotypes.h:101
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
Definition: legotypes.h:30