diff --git a/src/gba/video.h b/src/gba/video.h index 774f8de99..2221b9100 100644 --- a/src/gba/video.h +++ b/src/gba/video.h @@ -17,6 +17,14 @@ #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, diff --git a/src/platform/qt/PaletteView.cpp b/src/platform/qt/PaletteView.cpp index 448003e38..421cd6de2 100644 --- a/src/platform/qt/PaletteView.cpp +++ b/src/platform/qt/PaletteView.cpp @@ -53,9 +53,9 @@ void PaletteView::updatePalette() { 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'))); diff --git a/src/platform/qt/Swatch.cpp b/src/platform/qt/Swatch.cpp index 8fd834fb6..f3332274b 100644 --- a/src/platform/qt/Swatch.cpp +++ b/src/platform/qt/Swatch.cpp @@ -8,6 +8,10 @@ #include #include +extern "C" { +#include "gba/video.h" +} + using namespace QGBA; Swatch::Swatch(QWidget* parent) @@ -35,9 +39,9 @@ void Swatch::setDimensions(const QSize& size) { 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); }