Skip to content

Commit c9b903b

Browse files
committed
Final Checkpoint. Quick bugfix in palette conversion
1 parent c8a4307 commit c9b903b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

chrgfx/src/conv_pal.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ u8 *cvto_pal(paldef const &to_paldef, coldef const &to_coldef,
170170

171171
// provision and initialize output palette data
172172
unsigned int out_datasize{outpal_length *
173-
(entry_datasize * subpal_length < subpal_datasize
173+
(entry_datasize * subpal_length <= subpal_datasize
174174
? subpal_datasize / 8
175175
: entry_datasize_bytes)};
176176
u8 *out{new u8[out_datasize]};
177-
std::fill(out, out + out_datasize, 0);
177+
std::fill_n(out, out_datasize, 0);
178178

179179
// prepare space and function for data layout depending on endianness
180180
u8 entry_temp[entry_datasize_bytes];
@@ -210,7 +210,7 @@ u8 *cvto_pal(paldef const &to_paldef, coldef const &to_coldef,
210210

211211
if(entry_datasize < 8) {
212212
// color entries are less than one byte in size
213-
out[byte_offset] |= this_color << bit_offset;
213+
out[byte_offset] |= (this_color << bit_offset);
214214
} else {
215215
// color entries are one byte or larger
216216
for(size_t s{0}; s < entry_datasize_bytes; ++s) {
@@ -222,6 +222,8 @@ u8 *cvto_pal(paldef const &to_paldef, coldef const &to_coldef,
222222

223223
outdata_bit_ptr += entry_datasize;
224224
}
225+
// account for subpalette size
226+
// (really only needed when subpal data size > data size of all entries)
225227
outdata_bit_ptr += (subpal_datasize - (entry_datasize * subpal_length));
226228
}
227229

0 commit comments

Comments
 (0)