////////////////////////////////////////////////////////////////////////////////
// Palette.cpp
// Copyright Bjoern Ganster
// Developed since 2022
////////////////////////////////////////////////////////////////////////////////

#include "BGBase.h"
#include "Palette.h"

#define FILE_NUMBER FILE_NO_PALETTE_CPP

// Get palette entry
void Palette::getRGB(uint8_t index, uint8_t& r, uint8_t& g, uint8_t& b) const
{
	if (index < 256) {
		SET_SCOPE;
		size_t palIndex = 3*((size_t)index);
		r = values[palIndex];
		g = values[palIndex+1];
		b = values[palIndex+2];
		RETURN;
	}
}

// Set palette entry
void Palette::setRGB(uint8_t index, uint8_t r, uint8_t g, uint8_t b)
{
	if (index < 256) {
		SET_SCOPE;
		size_t palIndex = 3*((size_t)index);
		values[palIndex]   = r;
		values[palIndex+1] = g;
		values[palIndex+2] = b;
		RETURN;
	}
}

// Set random palette
void Palette::randomize()
{
	for (int i = 0; i < 768; ++i) {
		values[i] = irand(0, 255);
	}
}
