From 1c4c96a0cf8f0499d264bc9ddbe7b05743276cd6 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Tue, 15 Aug 2017 18:19:18 +1000 Subject: [PATCH] add a not BIOS machine filter (useful in composite filters), support RGB PNG with transparent pen because why not --- src/frontend/mame/ui/utils.cpp | 27 +++++++++++++++++---------- src/frontend/mame/ui/utils.h | 1 + src/lib/util/png.cpp | 26 +++++++++++++++++++------- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/frontend/mame/ui/utils.cpp b/src/frontend/mame/ui/utils.cpp index ccc8ee34892..9013a07b0c9 100644 --- a/src/frontend/mame/ui/utils.cpp +++ b/src/frontend/mame/ui/utils.cpp @@ -44,6 +44,7 @@ constexpr char const *machine_filter_names[machine_filter::COUNT] = { __("Category"), __("Favorites"), __("BIOS"), + __("Not BIOS"), __("Parents"), __("Clones"), __("Manufacturer"), @@ -635,6 +636,16 @@ public: }; +template +class bios_machine_filter_impl : public simple_filter_impl_base +{ +public: + bios_machine_filter_impl(char const *value, emu_file *file, unsigned indent) { } + + virtual bool apply(game_driver const &driver) const override { return driver.flags & machine_flags::IS_BIOS_ROOT; } +}; + + template class parents_machine_filter_impl : public simple_filter_impl_base { @@ -694,15 +705,6 @@ public: // concrete machine filters //------------------------------------------------- -class bios_machine_filter : public simple_filter_impl_base -{ -public: - bios_machine_filter(char const *value, emu_file *file, unsigned indent) { } - - virtual bool apply(game_driver const &driver) const override { return driver.flags & machine_flags::IS_BIOS_ROOT; } -}; - - class manufacturer_machine_filter : public choice_filter_impl_base { public: @@ -752,6 +754,7 @@ public: using working_machine_filter = working_machine_filter_impl<>; using mechanical_machine_filter = mechanical_machine_filter_impl<>; +using bios_machine_filter = bios_machine_filter_impl<>; using parents_machine_filter = parents_machine_filter_impl<>; using save_machine_filter = save_machine_filter_impl<>; using chd_machine_filter = chd_machine_filter_impl<>; @@ -759,6 +762,7 @@ using vertical_machine_filter = vertical_machine_filter_impl<>; using not_working_machine_filter = inverted_machine_filter; using not_mechanical_machine_filter = inverted_machine_filter; +using not_bios_machine_filter = inverted_machine_filter; using clones_machine_filter = inverted_machine_filter; using nosave_machine_filter = inverted_machine_filter; using nochd_machine_filter = inverted_machine_filter; @@ -1150,6 +1154,8 @@ public: case NOT_WORKING: return WORKING == m; case MECHANICAL: return NOT_MECHANICAL == m; case NOT_MECHANICAL: return MECHANICAL == m; + case BIOS: return NOT_BIOS == m; + case NOT_BIOS: return BIOS == m; case PARENTS: return CLONES == m; case CLONES: return PARENTS == m; case SAVE: return NOSAVE == m; @@ -1162,7 +1168,6 @@ public: case ALL: case CATEGORY: case FAVORITE: - case BIOS: case MANUFACTURER: case YEAR: case CUSTOM: @@ -1433,6 +1438,8 @@ machine_filter::ptr machine_filter::create(type n, char const *value, emu_file * return std::make_unique(value, file, indent); case BIOS: return std::make_unique(value, file, indent); + case NOT_BIOS: + return std::make_unique(value, file, indent); case PARENTS: return std::make_unique(value, file, indent); case CLONES: diff --git a/src/frontend/mame/ui/utils.h b/src/frontend/mame/ui/utils.h index 394bcc86244..4aa9b9ef9aa 100644 --- a/src/frontend/mame/ui/utils.h +++ b/src/frontend/mame/ui/utils.h @@ -133,6 +133,7 @@ public: CATEGORY, FAVORITE, BIOS, + NOT_BIOS, PARENTS, CLONES, MANUFACTURER, diff --git a/src/lib/util/png.cpp b/src/lib/util/png.cpp index 409d8806f3d..54f943e3955 100644 --- a/src/lib/util/png.cpp +++ b/src/lib/util/png.cpp @@ -543,15 +543,16 @@ public: // handle grayscale non-alpha case uint32_t const bpp(pnginfo.bit_depth >> 3); std::uint16_t const transpen(pnginfo.trans ? fetch_16bit(pnginfo.trans.get()) : 0U); + unsigned const samp_shift((8 < pnginfo.bit_depth) ? 8 : 0); for (std::uint32_t y = 0; dimensions.second > y; ++y) { for (std::uint32_t x = 0; dimensions.first > x; ++x, src += bpp) { - std::uint16_t i((8 < pnginfo.bit_depth) ? fetch_16bit(src) : fetch_8bit(src)); - std::uint8_t const a((pnginfo.trans && (transpen == i)) ? 0x00 : 0xff); - i >>= (8 < pnginfo.bit_depth) ? 8 : 0; - accumalpha &= a; - bitmap.pix32((y << y_shift) + y_offs, (x << x_shift) + x_offs) = rgb_t(a, i, i, i); + std::uint16_t i_val((8 < pnginfo.bit_depth) ? fetch_16bit(src) : fetch_8bit(src)); + std::uint8_t const a_val((pnginfo.trans && (transpen == i_val)) ? 0x00 : 0xff); + i_val >>= samp_shift; + accumalpha &= a_val; + bitmap.pix32((y << y_shift) + y_offs, (x << x_shift) + x_offs) = rgb_t(a_val, i_val, i_val, i_val); } } } @@ -576,12 +577,23 @@ public: uint32_t const r(0 * bps); uint32_t const g(1 * bps); uint32_t const b(2 * bps); + std::uint16_t const transpen_r(pnginfo.trans ? fetch_16bit(&pnginfo.trans[0]) : 0U); + std::uint16_t const transpen_g(pnginfo.trans ? fetch_16bit(&pnginfo.trans[2]) : 0U); + std::uint16_t const transpen_b(pnginfo.trans ? fetch_16bit(&pnginfo.trans[4]) : 0U); + unsigned const samp_shift((8 < pnginfo.bit_depth) ? 8 : 0); for (std::uint32_t y = 0; dimensions.second > y; ++y) { for (std::uint32_t x = 0; dimensions.first > x; ++x, src += bpp) { - rgb_t const pix(0xff, src[r], src[g], src[b]); - bitmap.pix32((y << y_shift) + y_offs, (x << x_shift) + x_offs) = pix; + uint16_t r_val((8 < pnginfo.bit_depth) ? fetch_16bit(src) : fetch_8bit(src + r)); + uint16_t g_val((8 < pnginfo.bit_depth) ? fetch_16bit(src) : fetch_8bit(src + g)); + uint16_t b_val((8 < pnginfo.bit_depth) ? fetch_16bit(src) : fetch_8bit(src + b)); + std::uint8_t const a_val((pnginfo.trans && (transpen_r == r_val) && (transpen_g == g_val) && (transpen_b == b_val)) ? 0x00 : 0xff); + r_val >>= samp_shift; + g_val >>= samp_shift; + b_val >>= samp_shift; + accumalpha &= a_val; + bitmap.pix32((y << y_shift) + y_offs, (x << x_shift) + x_offs) = rgb_t(a_val, r_val, g_val, b_val); } } }