Francesco Romani wrote:
I'm not sure that I've fully understood what you're saying here.
What you mean with "define some pixels"?
The whole video_buf_RGB data must have valid meaning, otherwise a
conversion to YUV will give senseless results.
I do not want to convert a whole frame; I only want to draw a few pixels
as RGB, then convert them into YUV; the rest of the frame is already in
YUV format.
The only reason I am using RGB at all is because I do not really
understand the YUV format, and I thought it would be easier to draw in
RGB and then convert it to YUV.
For example, if I want to draw a yellow pixel, I know that it is R255,
G255, B0, but what is it in YUV?
According to the conversion formulae I have already seen, that should be
something like Y210, U16, V146, or Y226, U0, V149, which are basically
the same. But when I try to put that into the video_buf_Y, _U, and _V
arrays, the resulting colour is not yellow. (Note: I think that in char
values, those should be Y82, U-112, V18; or Y98, U-128, V21; am I right?
See below for more details.)
Here is how I put it into the arrays (note: during testing, I am
actually reading the values for RGB through the optstr / config strings,
in other words command line options, but for this example I'll keep it
simple) :
int R, G, B;
R=255;
G=255;
B=0;
int Y, U, V;
Y = 0.299*R + 0.587*G + 0.114*B;
U = (B-Y)*0.565;
V = (R-Y)*0.713;
//since char has a range of (-128 to 127), but Y above is (0 to 255),
//I move Y into the proper range:
Y -= 128;
//Now, Y, U, and V should be in the range (-128 to 127); but just to
//make sure, I do clipping:
if(Y > 127) Y = 127; if(Y < -128) Y = -128;
if(U > 127) U = 127; if(U < -128) U = -128;
if(V > 127) V = 127; if(V < -128) V = -128;
//and finally, I apply the colours to my pixels:
int w = vframe_list_t->v_width;
int h = vframe_list_t->v_height;
for(int y=0; y<h; y++) {
for(int x=0; x<w; x++) {
if(I want to draw on this particular pixel) {
//note that I am applying an int to a char, but since the int is
//in the range (-128 to 127), it shouldn't matter, should it?
video_buf_Y[0][(y*w) + x] = Y;
video_buf_Y[1][(y*w) + x] = Y;
if(y%2 == 0 && x%2 == 0) {
video_buf_U[0][(y*w)/4 + x/2] = U;
video_buf_U[1][(y*w)/4 + x/2] = U;
video_buf_V[0][(y*w)/4 + x/2] = V;
video_buf_V[1][(y*w)/4 + x/2] = V;
} //end U&V drawing
} //end drawing
} //end x loop
} //end y loop
Is my conversion wrong, or is it something else?
--
James G. Flewelling,
Registered Linux User #327359
Linux From Scratch User #15607