Use std::bitset to track used colors
This reduces memory usage over using std::array<bool> for the same number of bits.
This commit is contained in:
parent
6af56a27f2
commit
8cc7be4986
|
@ -137,7 +137,7 @@ void gr_init_sub_bitmap (grs_bitmap &bm, grs_bitmap &bmParent, uint16_t x, uint1
|
|||
bm.bm_data = &bmParent.bm_data[static_cast<uint32_t>((y*bmParent.bm_rowsize)+x)];
|
||||
}
|
||||
|
||||
void decode_data(ubyte *data, uint_fast32_t num_pixels, std::array<color_t, 256> &colormap, std::array<bool, 256> &used)
|
||||
void decode_data(uint8_t *data, uint_fast32_t num_pixels, std::array<color_t, 256> &colormap, std::bitset<256> &used)
|
||||
{
|
||||
const auto a = [&](uint8_t mapped) {
|
||||
return used[mapped] = true, colormap[mapped];
|
||||
|
@ -169,7 +169,7 @@ void gr_remap_bitmap_good(grs_bitmap &bmp, palette_array_t &palette, uint_fast32
|
|||
if (transparent_color < colormap.size())
|
||||
colormap[transparent_color] = TRANSPARENCY_COLOR;
|
||||
|
||||
std::array<bool, 256> freq{};
|
||||
std::bitset<256> freq{};
|
||||
if (bmp.bm_w == bmp.bm_rowsize)
|
||||
decode_data(bmp.get_bitmap_data(), bmp.bm_w * bmp.bm_h, colormap, freq );
|
||||
else {
|
||||
|
|
|
@ -11,10 +11,11 @@
|
|||
#ifdef __cplusplus
|
||||
#include "palette.h"
|
||||
#include <array>
|
||||
#include <bitset>
|
||||
|
||||
namespace dcx {
|
||||
void build_colormap_good(const palette_array_t &palette, std::array<color_t, 256> &colormap);
|
||||
void decode_data(ubyte *data, uint_fast32_t num_pixels, std::array<color_t, 256> &colormap, std::array<bool, 256> &used);
|
||||
void decode_data(uint8_t *data, uint_fast32_t num_pixels, std::array<color_t, 256> &colormap, std::bitset<256> &used);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1013,10 +1013,11 @@ static std::unique_ptr<grs_font> gr_internal_init_font(const char *fontname)
|
|||
std::array<uint8_t, 256> colormap;
|
||||
/* `freq` exists so that decode_data can write to it, but it is
|
||||
* otherwise unused. `decode_data` is not guaranteed to write
|
||||
* to every element, so `freq` must not be read without first
|
||||
* adding an initialization step.
|
||||
* to every element, but the bitset constructor will initialize
|
||||
* the storage, so reading unwritten fields will always return
|
||||
* false.
|
||||
*/
|
||||
std::array<bool, 256> freq;
|
||||
std::bitset<256> freq;
|
||||
|
||||
PHYSFS_read(fontfile,&palette[0],sizeof(palette[0]),palette.size()); //read the palette
|
||||
|
||||
|
|
Loading…
Reference in a new issue