5586
|
1 In general
|
|
2 ==========
|
|
3
|
|
4 There are planar and packed modes.
|
|
5 - Planar mode means: you have 3 separated image, one for each component,
|
5735
|
6 each image 8 bits/pixel. To get the real colored pixel, you have to
|
5586
|
7 mix the components from all planes. The resolution of planes may differ!
|
|
8 - Packed mode means: you have all components mixed/interleaved together,
|
|
9 so you have small "packs" of components in a single, big image.
|
5312
|
10
|
5586
|
11 There are RGB and YUV colorspaces.
|
|
12 - RGB: Read, Green and Blue components. Used by analog VGA monitors.
|
|
13 - YUV: Luminance (Y) and Chrominance (U,V) components. Used by some
|
|
14 video systems, like PAL. Also most m(j)peg/dct based codecs use this.
|
5312
|
15
|
5586
|
16 With YUV, they used to reduce the resolution of U,V planes:
|
|
17 The most common YUV formats:
|
|
18 fourcc: bpp: IEEE: plane sizes: (w=width h=height of original image)
|
7833
|
19 444P 24 YUV 4:4:4 Y: w * h U,V: w * h
|
|
20 YUY2,UYVY 16 YUV 4:2:2 Y: w * h U,V: (w/2) * h [MJPEG]
|
|
21 YV12,I420 12 YUV 4:2:0 Y: w * h U,V: (w/2) * (h/2) [MPEG, h263]
|
|
22 411P 12 YUV 4:1:1 Y: w * h U,V: (w/4) * h [DV-NTSC, CYUV]
|
|
23 YVU9,IF09 9 YUV 4:1:0 Y: w * h U,V: (w/4) * (h/4) [Sorenson, Indeo]
|
5586
|
24
|
|
25 conversion: (some cut'n'paste from www and maillist)
|
5312
|
26
|
|
27 RGB to YUV Conversion:
|
|
28 Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
|
|
29 Cr = V = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
|
|
30 Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128
|
|
31 YUV to RGB Conversion:
|
|
32 B = 1.164(Y - 16) + 2.018(U - 128)
|
|
33 G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128)
|
|
34 R = 1.164(Y - 16) + 1.596(V - 128)
|
|
35
|
|
36 In both these cases, you have to clamp the output values to keep them in
|
|
37 the [0-255] range. Rumour has it that the valid range is actually a subset
|
|
38 of [0-255] (I've seen an RGB range of [16-235] mentioned) but clamping the
|
|
39 values into [0-255] seems to produce acceptable results to me.
|
|
40
|
5735
|
41 Julien (sorry, I can't call back his surname) suggests that there are
|
|
42 problems with the above formula and suggests the following instead:
|
|
43 Y = 0.299R + 0.587G + 0.114B
|
5312
|
44 Cb = U'= (B-Y)*0.565
|
|
45 Cr = V'= (R-Y)*0.713
|
|
46 with reciprocal versions:
|
|
47 R = Y + 1.403V'
|
|
48 G = Y - 0.344U' - 0.714V'
|
|
49 B = Y + 1.770U'
|
5735
|
50 note: this formula doesn't contain the +128 offsets of U,V values!
|
5312
|
51
|
|
52 Conclusion:
|
|
53 Y = luminance, the weighted average of R G B components. (0=black 255=white)
|
|
54 U = Cb = blue component (0=green 128=grey 255=blue)
|
5314
|
55 V = Cr = red component (0=green 128=grey 255=red)
|
5312
|
56
|
5586
|
57
|
|
58 Huh. The planar YUV modes.
|
|
59 ==========================
|
|
60
|
5735
|
61 The most misunderstood thingie...
|
5586
|
62
|
5312
|
63 In MPlayer, we usually have 3 pointers to the Y, U and V planes, so it
|
5586
|
64 doesn't matter what is the order of the planes in the memory:
|
5314
|
65 for mp_image_t and libvo's draw_slice():
|
|
66 planes[0] = Y = luminance
|
|
67 planes[1] = U = Cb = blue
|
|
68 planes[2] = V = Cr = red
|
5322
|
69 Note: planes[1] is ALWAYS U, and planes[2] is V, the fourcc
|
|
70 (YV12 vs. I420) doesn't matter here! So, every codecs using 3 pointers
|
|
71 (not only the first one) normally supports YV12 and I420 (=IYUV) too!
|
5314
|
72
|
5312
|
73 But there are some codecs (vfw, dshow) and vo drivers (xv) ignoring the 2nd
|
|
74 and 3rd pointer, and use only a single pointer to the planar yuv image. In
|
|
75 this case we must know the right order and alignment of planes in the memory!
|
|
76
|
|
77 from the webartz fourcc list:
|
|
78 YV12: 12 bpp, full sized Y plane followed by 2x2 subsampled V and U planes
|
|
79 I420: 12 bpp, full sized Y plane followed by 2x2 subsampled U and V planes
|
|
80 IYUV: the same as I420
|
|
81 YVU9: 9 bpp, full sized Y plane followed by 4x4 subsampled V and U planes
|
|
82
|
5587
|
83 Huh 2. RGB vs. BGR ?
|
|
84 ====================
|
|
85
|
5735
|
86 The 2nd most misunderstood thingie...
|
5587
|
87
|
|
88 You know, there are Intel and Motorola, and they use different byteorder.
|
|
89 There are also others, like MIPS or Alpha, they all follow either Intel
|
|
90 or Motorola byteorder.
|
5735
|
91 Unfortunately, the packed colorspaces depend on CPU byteorder. So, RGB
|
5587
|
92 on Intel and Motorola means different order of bytes.
|
|
93
|
|
94 In MPlayer, we have constants IMGFMT_RGBxx and IMGFMT_BGRxx.
|
5735
|
95 Unfortunately, some codecs and vo drivers follow Intel, some follow Motorola
|
5587
|
96 byteorder, so they are incompatible. We had to find a stable base, so long
|
5735
|
97 time ago I've chosen OpenGL, as it's a wide-spreaded standard, and it well
|
|
98 defines what RGB is and what BGR is. So, MPlayer's RGB is compatible with
|
|
99 OpenGL's GL_RGB on all platforms, and the same goes for BGR - GL_BGR.
|
|
100 Unfortunately, most of the x86 codecs call our BGR to RGB, so it sometimes
|
5587
|
101 confuse developers.
|
|
102
|
|
103 If you are unsure, try the OpenGL driver (-vo gl). There is at least software
|
5735
|
104 OpenGL implementation for all major platforms and OS's.
|