annotate DOCS/tech/colorspaces.txt @ 5314:ba5c92e64c5d

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