5312
|
1 Huh. The planar YUV modes.
|
|
2 ==========================
|
|
3
|
|
4 The most missunderstood thingie...
|
|
5
|
|
6 Let's see: (some cut'n'paste from www and maillist)
|
|
7
|
|
8 RGB to YUV Conversion:
|
|
9 Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
|
|
10 Cr = V = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
|
|
11 Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128
|
|
12 YUV to RGB Conversion:
|
|
13 B = 1.164(Y - 16) + 2.018(U - 128)
|
|
14 G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128)
|
|
15 R = 1.164(Y - 16) + 1.596(V - 128)
|
|
16
|
|
17 In both these cases, you have to clamp the output values to keep them in
|
|
18 the [0-255] range. Rumour has it that the valid range is actually a subset
|
|
19 of [0-255] (I've seen an RGB range of [16-235] mentioned) but clamping the
|
|
20 values into [0-255] seems to produce acceptable results to me.
|
|
21
|
|
22 Julien (surname unknown) suggests that there are problems with the above
|
|
23 formulae and suggests the following instead:
|
|
24 Y = 0.299R + 0.587G + 0.114B
|
|
25 Cb = U'= (B-Y)*0.565
|
|
26 Cr = V'= (R-Y)*0.713
|
|
27 with reciprocal versions:
|
|
28 R = Y + 1.403V'
|
|
29 G = Y - 0.344U' - 0.714V'
|
|
30 B = Y + 1.770U'
|
|
31 note: this formule doesn't contain the +128 offsets of U,V values!
|
|
32
|
|
33 Conclusion:
|
|
34 Y = luminance, the weighted average of R G B components. (0=black 255=white)
|
|
35 U = Cb = blue component (0=green 128=grey 255=blue)
|
5314
|
36 V = Cr = red component (0=green 128=grey 255=red)
|
5312
|
37
|
|
38 MPlayer side:
|
|
39 =============
|
|
40 In MPlayer, we usually have 3 pointers to the Y, U and V planes, so it
|
5314
|
41 doesn't matter what is they order in memory:
|
|
42 for mp_image_t and libvo's draw_slice():
|
|
43 planes[0] = Y = luminance
|
|
44 planes[1] = U = Cb = blue
|
|
45 planes[2] = V = Cr = red
|
|
46
|
5312
|
47 But there are some codecs (vfw, dshow) and vo drivers (xv) ignoring the 2nd
|
|
48 and 3rd pointer, and use only a single pointer to the planar yuv image. In
|
|
49 this case we must know the right order and alignment of planes in the memory!
|
|
50
|
|
51 from the webartz fourcc list:
|
|
52 YV12: 12 bpp, full sized Y plane followed by 2x2 subsampled V and U planes
|
|
53 I420: 12 bpp, full sized Y plane followed by 2x2 subsampled U and V planes
|
|
54 IYUV: the same as I420
|
|
55 YVU9: 9 bpp, full sized Y plane followed by 4x4 subsampled V and U planes
|
|
56
|