GBA Video: Add convenience macros for extracting color bits
Jeffrey Pfau jeffrey@endrift.com
Thu, 28 May 2015 23:18:45 -0700
3 files changed,
18 insertions(+),
6 deletions(-)
M
src/gba/video.h
→
src/gba/video.h
@@ -17,6 +17,14 @@ #else
#define BYTES_PER_PIXEL 4 #endif +#define GBA_R5(X) ((X) & 0x1F) +#define GBA_G5(X) (((X) >> 5) & 0x1F) +#define GBA_B5(X) (((X) >> 10) & 0x1F) + +#define GBA_R8(X) (((X) << 3) & 0xF8) +#define GBA_G8(X) (((X) >> 2) & 0xF8) +#define GBA_B8(X) (((X) >> 7) & 0xF8) + enum { VIDEO_CYCLES_PER_PIXEL = 4,
M
src/platform/qt/PaletteView.cpp
→
src/platform/qt/PaletteView.cpp
@@ -53,9 +53,9 @@
void PaletteView::selectIndex(int index) { uint16_t color = m_controller->thread()->gba->video.palette[index]; m_ui.selected->setColor(0, color); - uint32_t r = color & 0x1F; - uint32_t g = (color >> 5) & 0x1F; - uint32_t b = (color >> 10) & 0x1F; + uint32_t r = GBA_R5(color); + uint32_t g = GBA_G5(color); + uint32_t b = GBA_B5(color); uint32_t hexcode = (r << 19) | (g << 11) | (b << 3); m_ui.hexcode->setText(tr("#%0").arg(hexcode, 6, 16, QChar('0'))); m_ui.value->setText(tr("0x%0").arg(color, 4, 16, QChar('0')));
M
src/platform/qt/Swatch.cpp
→
src/platform/qt/Swatch.cpp
@@ -8,6 +8,10 @@
#include <QMouseEvent> #include <QPainter> +extern "C" { +#include "gba/video.h" +} + using namespace QGBA; Swatch::Swatch(QWidget* parent)@@ -35,9 +39,9 @@ }
void Swatch::setColor(int index, uint16_t color) { m_colors[index].setRgb( - (color << 3) & 0xF8, - (color >> 2) & 0xF8, - (color >> 7) & 0xF8); + GBA_R8(color), + GBA_G8(color), + GBA_B8(color)); updateFill(index); }