Login
Back to forumSee the full topicGo to last reply

Posted By

IstvanV
on 2007-09-02
06:47:38
 Re: So I want to do plus/4 gfx...

Looks like I was a bit late with posting happy By the way, the actual formulas used for calculating these colors might be more useful than just the resulting table. The following code converts 'color' (0 to 255) to red, green, and blue values that are identical to those in p4pal1.txt. colorPhaseTable[] is mostly based on the TED documentation, while brightnessToYTable[] and the constants 0.032 (for black) and 0.18 (chroma level) are from the picture of my Plus/4.


static const float brightnessToYTable[8] = {
0.180f, 0.238f, 0.265f, 0.345f, 0.508f, 0.661f, 0.748f, 0.993f
};

static const float colorPhaseTable[16] = {
0.0f, 0.0f, 103.0f, 283.0f, 53.0f, 241.0f, 347.0f, 167.0f, 127.5f, 148.0f,
195.0f, 83.0f, 265.0f, 323.0f, 1.5f, 213.0f
};

int c = color & 0x0F;
int b = (color & 0x70) >> 4;
float y = 0.032f;
float u = 0.0f, v = 0.0f;
if (c)
y = brightnessToYTable;
if (c > 1) {
float phs = colorPhaseTable[c] * 3.14159265f / 180.0f;
u = float(std::cos(phs)) * 0.18f;
v = float(std::sin(phs)) * 0.18f;
if (y > 0.975f)
y = 0.975f;
}

float red_f = (v / 0.877f) + y;
float blue_f = (u / 0.492f) + y;
float green_f = (y - ((red_f * 0.299f) + (blue_f * 0.114f))) / 0.587f;

int red = int((red_f > 0.0f ? (red_f < 1.0f ? red_f : 1.0f) : 0.0f) * 255.0f + 0.5f);
int green = int((green_f > 0.0f ? (green_f < 1.0f ? green_f : 1.0f) : 0.0f) * 255.0f + 0.5f);
int blue = int((blue_f > 0.0f ? (blue_f < 1.0f ? blue_f : 1.0f) : 0.0f) * 255.0f + 0.5f);




Back to top


Copyright © Plus/4 World Team, 2001-2024