mirror of https://github.com/mgba-emu/mgba.git
GBA Video: Add convenience macros for extracting color bits
This commit is contained in:
parent
a73cfe4496
commit
56e876f362
|
@ -17,6 +17,14 @@
|
||||||
#define BYTES_PER_PIXEL 4
|
#define BYTES_PER_PIXEL 4
|
||||||
#endif
|
#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 {
|
enum {
|
||||||
VIDEO_CYCLES_PER_PIXEL = 4,
|
VIDEO_CYCLES_PER_PIXEL = 4,
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,9 @@ void PaletteView::updatePalette() {
|
||||||
void PaletteView::selectIndex(int index) {
|
void PaletteView::selectIndex(int index) {
|
||||||
uint16_t color = m_controller->thread()->gba->video.palette[index];
|
uint16_t color = m_controller->thread()->gba->video.palette[index];
|
||||||
m_ui.selected->setColor(0, color);
|
m_ui.selected->setColor(0, color);
|
||||||
uint32_t r = color & 0x1F;
|
uint32_t r = GBA_R5(color);
|
||||||
uint32_t g = (color >> 5) & 0x1F;
|
uint32_t g = GBA_G5(color);
|
||||||
uint32_t b = (color >> 10) & 0x1F;
|
uint32_t b = GBA_B5(color);
|
||||||
uint32_t hexcode = (r << 19) | (g << 11) | (b << 3);
|
uint32_t hexcode = (r << 19) | (g << 11) | (b << 3);
|
||||||
m_ui.hexcode->setText(tr("#%0").arg(hexcode, 6, 16, QChar('0')));
|
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_ui.value->setText(tr("0x%0").arg(color, 4, 16, QChar('0')));
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "gba/video.h"
|
||||||
|
}
|
||||||
|
|
||||||
using namespace QGBA;
|
using namespace QGBA;
|
||||||
|
|
||||||
Swatch::Swatch(QWidget* parent)
|
Swatch::Swatch(QWidget* parent)
|
||||||
|
@ -35,9 +39,9 @@ void Swatch::setDimensions(const QSize& size) {
|
||||||
|
|
||||||
void Swatch::setColor(int index, uint16_t color) {
|
void Swatch::setColor(int index, uint16_t color) {
|
||||||
m_colors[index].setRgb(
|
m_colors[index].setRgb(
|
||||||
(color << 3) & 0xF8,
|
GBA_R8(color),
|
||||||
(color >> 2) & 0xF8,
|
GBA_G8(color),
|
||||||
(color >> 7) & 0xF8);
|
GBA_B8(color));
|
||||||
updateFill(index);
|
updateFill(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue