From a1d35e5abf431e03e06d55b96379a3b14753ed4d Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sun, 27 Sep 2020 14:00:42 +1000 Subject: Cleaned up bitmap API. Made const-qualified pixel accessors (pix, pixt, raw_pixptr) return const-qualified references/pointers to pixesl, and added non-const versions. This makes bitmap more like standard library containers where const protects the content as well as the dimensions. Made the templated pixt accessor protected - having it public makes it too easy to inadvertently get a pointer to the wrong location. Removed the pix(8|16|32|64) accessors from the specific bitmaps. You could only use the "correct" one anyway, and having the "incorrect" ones available prevented explicit instantiations of the class template because the static assertions would fail. You can still see the pixel type in the bitmap class names, and you can't assign the result of &pix(y, x) to the wrong kind of pointer without a cast. Added fill member functions to the specific bitmap template, and added a explicit instantiations. This allows the bitmap size check to be skipped on most bitmap fills, although the clipping check is still there. Also fixed a couple of places that were trying to fill an indexed 16-bit bitmap with rgb_t::black() exposed by this (replaced with zero to get the same net effect). The explicit template instantiations in the .cpp file mean the compiler can inline the function if necessary, but don't need to generate a local out-of-line body if it chooses not to. Extended the size of the fill value parameter in the base bitmap class to 64 bits so it works correctly for 64-bit bitmaps. Fixed places where IE15 and VGM visualiser weren't accounting for row bytes potentially being larger than width. Fixed an off-by-one in an HP-DIO card where it was treating the Topcat cursor right edge as exclusive. Updated everything to work with the API changes, reduced the scope of many variables, added more const, and replaced a few fill/copy loops with stuff from . --- src/lib/util/bitmap.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/lib/util/bitmap.cpp') diff --git a/src/lib/util/bitmap.cpp b/src/lib/util/bitmap.cpp index 2b7cd74b5a1..fc05b89f1b6 100644 --- a/src/lib/util/bitmap.cpp +++ b/src/lib/util/bitmap.cpp @@ -10,7 +10,6 @@ #include "bitmap.h" -#include #include #include @@ -360,7 +359,7 @@ void bitmap_t::wrap(void *base, int width, int height, int rowpixels) * @param subrect The subrect. */ -void bitmap_t::wrap(const bitmap_t &source, const rectangle &subrect) +void bitmap_t::wrap(bitmap_t &source, const rectangle &subrect) { assert(m_format == source.m_format); assert(m_bpp == source.m_bpp); @@ -406,7 +405,7 @@ void bitmap_t::set_palette(palette_t *palette) } /** - * @fn void bitmap_t::fill(uint32_t color, const rectangle &cliprect) + * @fn void bitmap_t::fill(uint64_t color, const rectangle &bounds) * * @brief ------------------------------------------------- * fill -- fill a bitmap with a solid color @@ -416,10 +415,10 @@ void bitmap_t::set_palette(palette_t *palette) * @param cliprect The cliprect. */ -void bitmap_t::fill(uint32_t color, const rectangle &cliprect) +void bitmap_t::fill(uint64_t color, const rectangle &bounds) { // if we have a cliprect, intersect with that - rectangle fill(cliprect); + rectangle fill(bounds); fill &= m_cliprect; if (!fill.empty()) { @@ -448,3 +447,13 @@ void bitmap_t::fill(uint32_t color, const rectangle &cliprect) } } } + + +//************************************************************************** +// EXPLICIT TEMPLATE INSTANTIATIONS +//************************************************************************** + +template class bitmap_specific; +template class bitmap_specific; +template class bitmap_specific; +template class bitmap_specific; -- cgit v1.2.3-70-g09d2