From: Billy B. <ve...@du...> - 2001-10-12 22:30:18
|
James Courtier-Dutton (Ja...@su...): > There are some very good sites on the web explaining how to convert > YUV to RGB and all sorts of other different formats. > About the simplest one I can find is: - > http://www.cse.msu.edu/%7Ecbowen/docs/yuvtorgb.html Unfortunately, the transfer function described on that web page is NOT what you want to do in xine. In digital video we don't actually use the YUV colour space. We use a very specific digital representation known as Y'CbCr. Using the correct name is important since it avoids finding the wrong conversion function on google (bad James!). :) So, Y == Y', U == Cb, V == Cr. Poynton's colour FAQ[1] gives the following conversion matrix: R' = 1 [ 298.082 0 408.583 ] ([ Y' ] [ 16 ]) G' = --- * [ 298.082 -100.291 -208.120 ] * ([ Cb ] - [ 128 ]) B' = 256 [ 298.082 516.411 0 ] ([ Cr ] [ 128 ]) The 1/256 is a bit deceiving, since for 8-bit values you'll be inaccurate if you round badly. So, if you're using doubles, just be honest: R' = [ 1.1644 0 1.5960 ] ([ Y' ] [ 16 ]) G' = [ 1.1644 -0.3918 -0.8130 ] * ([ Cb ] - [ 128 ]) B' = [ 1.1644 2.0172 0 ] ([ Cr ] [ 128 ]) You'll need to clip R',G',B' at 255. The primes denote non-linearity. If you MMX-ify, please give some numbers showing what percentage of your converted values are wrong, it helps when people want to adapt your code and may be looking for accuracy over speed. The code in snapshot.c recently posted here is incorrect, afaict. [1] http://www.inforamp.net/~poynton/notes/colour_and_gamma/ColorFAQ.html#RTFToC30 -- Billy Biggs ve...@du... |