Login
Back to forumSee the full topicGo to last reply

Posted By

IstvanV
on 2007-09-10
16:08:41
 Re: So I want to do plus/4 gfx...

I simply used screenshots from tvtime, with various tricks to get the most accurate results. But I think the main reason why you get different values is actually the formulas used. Here is some simple code with which I convert r, g, and b (in the range 0 to 1) to y, u, v, p (phase), and c (chroma level):

double y = 0.299 * r + 0.587 * g + 0.114 * b;
double u = 0.492 * (b - y);
//u /= (0.886 * 0.492);
double v = 0.877 * (r - y);
//v /= (0.701 * 0.877);
double p = std::atan2(v, u) * 45.0 / std::atan(1.0);
if (p < 0.0)
p += 360.0;
double c = std::sqrt(u * u + v * v);

Notice the commented out lines. Those would normalize u and v to the range -1 to 1. From a screenshot of YAPE, I assume that you use equations where u and v are normalized. That is, I get more consistent results when I enable the commented out code. The following table shows the phase angles of simple RGB colors like #ff0000 etc. calculated with either formulas:

Red 103.5 108.6
Green 240.7 231.6
Yellow 167.1 170.8
Blue 347.1 350.8
Magenta 60.7 51.6
Cyan 283.5 288.6

The ones on the left are based on my conversion code, and should look familiar.



Back to top


Copyright © Plus/4 World Team, 2001-2024