diff options
author | 2020-09-27 14:00:42 +1000 | |
---|---|---|
committer | 2020-09-27 14:00:42 +1000 | |
commit | a1d35e5abf431e03e06d55b96379a3b14753ed4d (patch) | |
tree | 506ffe906e707f50eca2306da80b1657644e0507 /src/devices/sound/vgm_visualizer.cpp | |
parent | d294948a3bb8c6e8fdbc96841ceae30ec6687870 (diff) |
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 <algorithm>.
Diffstat (limited to 'src/devices/sound/vgm_visualizer.cpp')
-rw-r--r-- | src/devices/sound/vgm_visualizer.cpp | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/src/devices/sound/vgm_visualizer.cpp b/src/devices/sound/vgm_visualizer.cpp index c1f438f2b2c..bab3c909ddf 100644 --- a/src/devices/sound/vgm_visualizer.cpp +++ b/src/devices/sound/vgm_visualizer.cpp @@ -158,7 +158,7 @@ void vgmviz_device::apply_fft() void vgmviz_device::apply_waterfall() { - int total_bars = FFT_LENGTH / 2; + const int total_bars = FFT_LENGTH / 2; WDL_FFT_COMPLEX* bins[2] = { (WDL_FFT_COMPLEX*)m_fft_buf[0], (WDL_FFT_COMPLEX*)m_fft_buf[1] }; for (int bar = 0; bar < std::min<int>(total_bars, SCREEN_HEIGHT); bar++) { @@ -555,7 +555,7 @@ template <int BarSize, int SpecMode> void vgmviz_device::draw_spectrogram(bitmap m_clear_pending = false; } - const pen_t *pal = m_palette->pens(); + pen_t const *const pal = m_palette->pens(); int width = SCREEN_WIDTH; switch (SpecMode) @@ -563,31 +563,26 @@ template <int BarSize, int SpecMode> void vgmviz_device::draw_spectrogram(bitmap case SPEC_VIZ_PILLAR: for (int y = 2; y < SCREEN_HEIGHT; y++) { - uint32_t *src = &m_bitmap.pix32(y); - uint32_t *dst = &bitmap.pix32(y - 2); + uint32_t const *const src = &m_bitmap.pix(y); + uint32_t *const dst = &bitmap.pix(y - 2); for (int x = SCREEN_WIDTH - 1; x >= 1; x--) { dst[x] = src[x - 1]; } } - width = (int)(SCREEN_WIDTH * 0.75f); + width = int(SCREEN_WIDTH * 0.75f); break; case SPEC_VIZ_TOP: for (int y = 1; y < SCREEN_HEIGHT; y++) { - uint32_t *src = &m_bitmap.pix32(y); - uint32_t *dst = &bitmap.pix32(y - 1); - for (int x = 0; x < SCREEN_WIDTH; x++) - { - dst[x] = src[x]; - } + std::copy_n(&m_bitmap.pix(y), SCREEN_WIDTH, &bitmap.pix(y - 1)); } break; default: break; } - int total_bars = FFT_LENGTH / 2; + const int total_bars = FFT_LENGTH / 2; WDL_FFT_COMPLEX *bins[2] = { (WDL_FFT_COMPLEX *)m_fft_buf[0], (WDL_FFT_COMPLEX *)m_fft_buf[1] }; for (int bar = 2; bar < total_bars && bar < width; bar += BarSize) @@ -614,8 +609,8 @@ template <int BarSize, int SpecMode> void vgmviz_device::draw_spectrogram(bitmap } for (int y = 0; y < SCREEN_HEIGHT; y++) { - int bar_y = SCREEN_HEIGHT - y; - uint32_t *line = &bitmap.pix32(y); + const int bar_y = SCREEN_HEIGHT - y; + uint32_t *const line = &bitmap.pix(y); for (int x = 0; x < BarSize; x++) { line[(bar - 2) + x] = bar_y <= level ? pal[256 + pal_index] : pal[black_index]; @@ -631,8 +626,8 @@ template <int BarSize, int SpecMode> void vgmviz_device::draw_spectrogram(bitmap for (int y = 0; y < SCREEN_HEIGHT; y++) { - int bar_y = SCREEN_HEIGHT - y; - uint32_t *line = &bitmap.pix32(y); + const int bar_y = SCREEN_HEIGHT - y; + uint32_t *const line = &bitmap.pix(y); line[0] = 0; if (bar_y > level) { @@ -643,9 +638,9 @@ template <int BarSize, int SpecMode> void vgmviz_device::draw_spectrogram(bitmap { if (bar_y < (level - 1)) { - const uint8_t r = (uint8_t)(((entry >> 16) & 0xff) * 0.75f); - const uint8_t g = (uint8_t)(((entry >> 8) & 0xff) * 0.75f); - const uint8_t b = (uint8_t)(((entry >> 0) & 0xff) * 0.75f); + const uint8_t r = uint8_t(((entry >> 16) & 0xff) * 0.75f); + const uint8_t g = uint8_t(((entry >> 8) & 0xff) * 0.75f); + const uint8_t b = uint8_t(((entry >> 0) & 0xff) * 0.75f); line[(bar - 2) + x] = 0xff000000 | (r << 16) | (g << 8) | b; } else @@ -653,9 +648,9 @@ template <int BarSize, int SpecMode> void vgmviz_device::draw_spectrogram(bitmap line[(bar - 2) + x] = pal[256 + pal_index]; } } - const uint8_t r = (uint8_t)(((entry >> 16) & 0xff) * 0.5f); - const uint8_t g = (uint8_t)(((entry >> 8) & 0xff) * 0.5f); - const uint8_t b = (uint8_t)(((entry >> 0) & 0xff) * 0.5f); + const uint8_t r = uint8_t(((entry >> 16) & 0xff) * 0.5f); + const uint8_t g = uint8_t(((entry >> 8) & 0xff) * 0.5f); + const uint8_t b = uint8_t(((entry >> 0) & 0xff) * 0.5f); line[(bar - 2) + (BarSize - 1)] = 0xff000000 | (r << 16) | (g << 8) | b; if (bar_y < level) { @@ -664,10 +659,11 @@ template <int BarSize, int SpecMode> void vgmviz_device::draw_spectrogram(bitmap } for (int x = 0; x < SCREEN_WIDTH; x++) { - bitmap.pix32(SCREEN_HEIGHT - 1, x) = 0; - bitmap.pix32(SCREEN_HEIGHT - 2, x) = 0; + bitmap.pix(SCREEN_HEIGHT - 1, x) = 0; + bitmap.pix(SCREEN_HEIGHT - 2, x) = 0; } - memcpy(&m_bitmap.pix32(0), &bitmap.pix32(0), sizeof(uint32_t) * SCREEN_WIDTH * SCREEN_HEIGHT); + for (int y = 0; y < SCREEN_HEIGHT; y++) + std::copy_n(&bitmap.pix(y), SCREEN_WIDTH, &m_bitmap.pix(y)); break; case SPEC_VIZ_TOP: level = int(raw_level * 63.0f); @@ -678,10 +674,11 @@ template <int BarSize, int SpecMode> void vgmviz_device::draw_spectrogram(bitmap for (int x = 0; x < BarSize; x++) { - bitmap.pix32(SCREEN_HEIGHT - 1, (bar - 2) + x) = level > 0 ? pal[256 + pal_index] : pal[black_index]; + bitmap.pix(SCREEN_HEIGHT - 1, (bar - 2) + x) = level > 0 ? pal[256 + pal_index] : pal[black_index]; } - memcpy(&m_bitmap.pix32(0), &bitmap.pix32(0), sizeof(uint32_t) * SCREEN_WIDTH * SCREEN_HEIGHT); + for (int y = 0; y < SCREEN_HEIGHT; y++) + std::copy_n(&bitmap.pix(y), SCREEN_WIDTH, &m_bitmap.pix(y)); break; } } @@ -700,7 +697,7 @@ void vgmviz_device::draw_waterfall(bitmap_rgb32 &bitmap) const int v0_index = (int)v0h; const int v1_index = (int)v1h; const float interp = v0h - (float)v0_index; - uint32_t* line = &bitmap.pix32(y); + uint32_t* line = &bitmap.pix(y); for (int x = 0; x < SCREEN_WIDTH; x++) { if (m_waterfall_length < SCREEN_WIDTH) @@ -736,8 +733,8 @@ void vgmviz_device::draw_waveform(bitmap_rgb32 &bitmap) for (int x = 0; x < SCREEN_WIDTH; x++) { - bitmap.pix32(CHANNEL_CENTER, x) = MED_GRAY; - bitmap.pix32(CHANNEL_HEIGHT + 1 + CHANNEL_CENTER, x) = MED_GRAY; + bitmap.pix(CHANNEL_CENTER, x) = MED_GRAY; + bitmap.pix(CHANNEL_HEIGHT + 1 + CHANNEL_CENTER, x) = MED_GRAY; const float raw_l = m_audio_buf[1 - m_audio_fill_index][0][((int)m_history_length + 1 + x) % FFT_LENGTH]; const int sample_l = (int)((raw_l - 0.5f) * (CHANNEL_HEIGHT - 1)); @@ -746,7 +743,7 @@ void vgmviz_device::draw_waveform(bitmap_rgb32 &bitmap) int y = endy_l - sample_l; do { - bitmap.pix32(y, x) = LEFT_COLOR; + bitmap.pix(y, x) = LEFT_COLOR; y += dy_l; } while(y != endy_l); @@ -757,11 +754,11 @@ void vgmviz_device::draw_waveform(bitmap_rgb32 &bitmap) y = endy_r - sample_r; do { - bitmap.pix32(y, x) = RIGHT_COLOR; + bitmap.pix(y, x) = RIGHT_COLOR; y += dy_r; } while(y != endy_r); - bitmap.pix32(CHANNEL_HEIGHT, x) = WHITE; - bitmap.pix32(CHANNEL_HEIGHT + 1, x) = WHITE; + bitmap.pix(CHANNEL_HEIGHT, x) = WHITE; + bitmap.pix(CHANNEL_HEIGHT + 1, x) = WHITE; } } |