diff options
author | 2012-01-02 04:59:11 +0000 | |
---|---|---|
committer | 2012-01-02 04:59:11 +0000 | |
commit | 80cd316a2ad134c67ca028a606266bb733a025b6 (patch) | |
tree | e198baaf50207b99fd46fb4696cdcda17e94ab65 /src/lib/util/bitmap.c | |
parent | 1ded844ee73ec0768de1b7ccba5491c92fd4ad5a (diff) |
Bulk conversion of bitmap_t * to bitmap_t & . With this change the
parameters for the global SCREEN_UPDATE callback match the parameters
for the driver_device version. Added allocate() and deallocate()
methods to bitmap_t to permit cleaner handling of bitmaps in drivers
and modern devices. [Aaron Giles]
Diffstat (limited to 'src/lib/util/bitmap.c')
-rw-r--r-- | src/lib/util/bitmap.c | 101 |
1 files changed, 61 insertions, 40 deletions
diff --git a/src/lib/util/bitmap.c b/src/lib/util/bitmap.c index cf870dc632c..f64302e9567 100644 --- a/src/lib/util/bitmap.c +++ b/src/lib/util/bitmap.c @@ -56,26 +56,26 @@ bitmap_t::bitmap_t() : m_alloc(NULL), - m_base(NULL), - m_rowpixels(0), - m_width(0), - m_height(0), - m_format(BITMAP_FORMAT_INVALID), - m_bpp(0), - m_palette(NULL), - m_cliprect(0, 0, 0, 0) + m_palette(NULL) { + // deallocate intializes all other fields + deallocate(); } -//------------------------------------------------- -// bitmap_t - basic constructor -//------------------------------------------------- - bitmap_t::bitmap_t(int width, int height, bitmap_format format, int xslop, int yslop) : m_alloc(NULL), - m_base(NULL), - m_rowpixels((width + 2 * xslop + 7) & ~7), + m_palette(NULL) +{ + // allocate intializes all other fields + allocate(width, height, format, xslop, yslop); +} + + +bitmap_t::bitmap_t(void *base, int width, int height, int rowpixels, bitmap_format format) + : m_alloc(NULL), + m_base(base), + m_rowpixels(rowpixels), m_width(width), m_height(height), m_format(format), @@ -86,52 +86,73 @@ bitmap_t::bitmap_t(int width, int height, bitmap_format format, int xslop, int y // fail if invalid format if (m_bpp == 0) throw std::bad_alloc(); +} - // allocate memory for the bitmap itself - size_t allocbytes = m_rowpixels * (m_height + 2 * yslop) * m_bpp / 8; - m_alloc = new UINT8[allocbytes]; - // clear to 0 by default - memset(m_alloc, 0, allocbytes); +//------------------------------------------------- +// ~bitmap_t - basic destructor +//------------------------------------------------- - // compute the base - m_base = m_alloc + (m_rowpixels * yslop + xslop) * (m_bpp / 8); +bitmap_t::~bitmap_t() +{ + // delete any existing stuff + deallocate(); } //------------------------------------------------- -// bitmap_t - basic constructor +// allocate -- (re)allocate memory for the bitmap +// at the given size, destroying anything that +// already exists //------------------------------------------------- -bitmap_t::bitmap_t(void *base, int width, int height, int rowpixels, bitmap_format format) - : m_alloc(NULL), - m_base(base), - m_rowpixels(rowpixels), - m_width(width), - m_height(height), - m_format(format), - m_bpp(format_to_bpp(format)), - m_palette(NULL), - m_cliprect(0, width - 1, 0, height - 1) +void bitmap_t::allocate(int width, int height, bitmap_format format, int xslop, int yslop) { - // fail if invalid format + // delete any existing stuff + deallocate(); + + // initialize fields + m_rowpixels = (width + 2 * xslop + 7) & ~7; + m_width = width; + m_height = height; + m_format = format; + m_bpp = format_to_bpp(format); if (m_bpp == 0) throw std::bad_alloc(); + m_cliprect.set(0, width - 1, 0, height - 1); + + // allocate memory for the bitmap itself + size_t allocbytes = m_rowpixels * (m_height + 2 * yslop) * m_bpp / 8; + m_alloc = new UINT8[allocbytes]; + + // clear to 0 by default + memset(m_alloc, 0, allocbytes); + + // compute the base + m_base = m_alloc + (m_rowpixels * yslop + xslop) * (m_bpp / 8); } //------------------------------------------------- -// ~bitmap_t - basic destructor +// deallocate -- reset to an invalid bitmap, +// deleting all allocated stuff //------------------------------------------------- -bitmap_t::~bitmap_t() +void bitmap_t::deallocate() { - // dereference the palette - if (m_palette != NULL) - palette_deref(m_palette); - - // free any allocated memory + // delete any existing stuff + set_palette(NULL); delete[] m_alloc; + m_alloc = NULL; + m_base = NULL; + + // reset all fields + m_rowpixels = 0; + m_width = 0; + m_height = 0; + m_format = BITMAP_FORMAT_INVALID; + m_bpp = 0; + m_cliprect.set(0, -1, 0, -1); } |