From b6e2205b9fa37f943b7f2ab3d3d37fec15c98643 Mon Sep 17 00:00:00 2001 From: Kp Date: Thu, 8 Mar 2018 04:21:18 +0000 Subject: [PATCH] Simplify palette color tracking Callers only care whether a color is used, not how often it is used. --- common/2d/bitmap.cpp | 8 ++++---- common/2d/bitmap.h | 4 ++-- similar/2d/font.cpp | 2 +- similar/main/piggy.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/common/2d/bitmap.cpp b/common/2d/bitmap.cpp index c47919078..1258cd076 100644 --- a/common/2d/bitmap.cpp +++ b/common/2d/bitmap.cpp @@ -135,10 +135,10 @@ void gr_init_sub_bitmap (grs_bitmap &bm, grs_bitmap &bmParent, uint16_t x, uint1 bm.bm_data = &bmParent.bm_data[static_cast((y*bmParent.bm_rowsize)+x)]; } -void decode_data(ubyte *data, uint_fast32_t num_pixels, array &colormap, array &count) +void decode_data(ubyte *data, uint_fast32_t num_pixels, array &colormap, array &used) { const auto a = [&](uint8_t mapped) { - return ++count[mapped], colormap[mapped]; + return used[mapped] = true, colormap[mapped]; }; std::transform(data, data + num_pixels, data, a); } @@ -148,7 +148,7 @@ static void gr_set_super_transparent(grs_bitmap &bm, bool bOpaque) bm.set_flag_mask(!bOpaque, BM_FLAG_SUPER_TRANSPARENT); } -void build_colormap_good(const palette_array_t &palette, array &colormap, array &freq) +void build_colormap_good(const palette_array_t &palette, array &colormap, array &freq) { const auto a = [](const rgb_t &p) { return gr_find_closest_color(p.r, p.g, p.b); @@ -160,7 +160,7 @@ void build_colormap_good(const palette_array_t &palette, array &co void gr_remap_bitmap_good(grs_bitmap &bmp, palette_array_t &palette, uint_fast32_t transparent_color, uint_fast32_t super_transparent_color) { array colormap; - array freq; + array freq; build_colormap_good( palette, colormap, freq ); if (super_transparent_color < colormap.size()) diff --git a/common/2d/bitmap.h b/common/2d/bitmap.h index a2c9349e2..89bcd2946 100644 --- a/common/2d/bitmap.h +++ b/common/2d/bitmap.h @@ -13,8 +13,8 @@ #include "compiler-array.h" namespace dcx { -void build_colormap_good(const palette_array_t &palette, array &colormap, array &freq); -void decode_data(ubyte *data, uint_fast32_t num_pixels, array &colormap, array &count); +void build_colormap_good(const palette_array_t &palette, array &colormap, array &used); +void decode_data(ubyte *data, uint_fast32_t num_pixels, array &colormap, array &used); } #endif diff --git a/similar/2d/font.cpp b/similar/2d/font.cpp index 3e48ef358..b3c768388 100644 --- a/similar/2d/font.cpp +++ b/similar/2d/font.cpp @@ -1004,7 +1004,7 @@ static std::unique_ptr gr_internal_init_font(const char *fontname) if (font->ft_flags & FT_COLOR) { //remap palette palette_array_t palette; array colormap; - array freq; + array freq; PHYSFS_read(fontfile,&palette[0],sizeof(palette[0]),palette.size()); //read the palette diff --git a/similar/main/piggy.cpp b/similar/main/piggy.cpp index 2a64d73e1..641d14dd3 100644 --- a/similar/main/piggy.cpp +++ b/similar/main/piggy.cpp @@ -1778,7 +1778,7 @@ static int get_d1_colormap( palette_array_t &d1_palette, array &co if (!palette_file || PHYSFS_fileLength(palette_file) != 9472) return -1; PHYSFS_read( palette_file, &d1_palette[0], sizeof(d1_palette[0]), d1_palette.size() ); - array freq; + array freq; build_colormap_good( d1_palette, colormap, freq ); // don't change transparencies: colormap[254] = 254;