home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / compress / research / 128 < prev    next >
Encoding:
Text File  |  1992-08-21  |  3.5 KB  |  121 lines

  1. Newsgroups: comp.compression.research
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!nntp-server.caltech.edu!madler
  3. From: madler@cco.caltech.edu (Mark Adler)
  4. Subject: Re: MPEG decoder
  5. Message-ID: <1992Aug22.052425.13034@cco.caltech.edu>
  6. Keywords: MPEG
  7. Sender: news@cco.caltech.edu
  8. Nntp-Posting-Host: sandman
  9. Organization: California Institute of Technology, Pasadena
  10. References: <170o7oINN7lk@agate.berkeley.edu>
  11. Date: Sat, 22 Aug 1992 05:24:25 GMT
  12. Lines: 107
  13.  
  14.  
  15. ketan patel requests:
  16. >> the proper matrix to use for
  17. >> straight MPEG YCrCb -> RGB conversion? 
  18.  
  19. I have appended my "y2rmatrx.h" file, which contains (to the best of
  20. my knowledge) the correct conversion matrix based on the standard
  21. definition of the y, u, and v signals, and the CCIR-601 digitization
  22. of those.
  23.  
  24. I also have programs that use the .h file (of course), and they can
  25. be had for the asking.
  26.  
  27. Mark Adler
  28. madler@tybalt.caltech.edu
  29. ---- y2rmatrx.h ----
  30. /*
  31.    y2rmatrx.h    Mark Adler    28 August 1991
  32.  
  33.    This file defines the constants y2rNS, y2rXY, y2rRV, y2rGU, y2rGV, and
  34.    y2rBU.  The first is a shift factor, and the rest are components of the
  35.    conversion matrix.  The comments below describe the meaning and
  36.    derivation of those constants.
  37. */
  38.  
  39. /* The following constants are derived from the observed relative brightness
  40.    of red, green, and blue to define luminance, Y = 0.299R + 0.587G + 0.114B.
  41.    Then the color difference signals, B-Y and R-Y, are normalized to the
  42.    range -0.5 to 0.5 (for R, G, and B in 0 to 1) to the signals U and V,
  43.    respectively.  This RGB to YUV matrix is then inverted to give the YUV to
  44.    RGB conversion matrix (here in its exact rational form):
  45.  
  46.     1    0        701/500
  47.     1    -25251/73375    -209599/293500
  48.     1    443/250        0
  49.  
  50.    This applies to the electrical signals.  The digital versions are
  51.    scaled and shifted as follows (lower case is the digital form):
  52.  
  53.     y = 219*Y + 16        or    Y = (y - 16)/219
  54.     u = 224*U + 128        or    U = (u - 128)/224
  55.     v = 224*V + 128        or    V = (v - 128)/224
  56.  
  57.    Since we are converting for the purpose of display, we will use the
  58.    entire range for eight bit RGB values and define:
  59.  
  60.         r = 256*R
  61.     g = 256*G
  62.     b = 256*B
  63.  
  64.    where the r, g, and b values are rounded down or clipped to the range
  65.    of 0..255.  This breaks the interval [0,1] into 256 equal size pieces.
  66.    Then 0 covers [0,1/256) and negative values, 1 covers [1/256,2/256),
  67.    ..., and 255 covers [255/256,1] and values greater than one.
  68.  
  69.    We will offset the y, u, and v values first (to improve the accuracy
  70.    of the calculation--we could just bring an overall constant in front
  71.    instead), and then the transformation matrix becomes, in its exact
  72.    rational form:
  73.  
  74.      256/219        0        1402/875
  75.     256/219        -202008/513625    -419198/513625
  76.     256/219        1772/875    0
  77.  
  78.    This gives five non-zero constants (aside from the offsets) that
  79.    define the conversion.  They are multiplied by a power of two and
  80.    rounded for the integer calculation. */
  81.  
  82. /* The constants below correspond to the above matrix as follows:
  83.  
  84.     y2rXY        0        y2rRV
  85.     y2rXY        y2rGU        y2rGV
  86.     y2rXY        y2rBU        0
  87.  
  88.    where the whole matrix is multiplied by 2**(-y2rNS). */
  89.  
  90. /*
  91. #define y2rNS 8
  92. #define y2rXY 299
  93. #define y2rRV 410
  94. #define y2rGU (-101)
  95. #define y2rGV (-209)
  96. #define y2rBU 518
  97. */
  98.  
  99. #define y2rNS 12
  100. #define y2rXY 4788
  101. #define y2rRV 6563
  102. #define y2rGU (-1611)
  103. #define y2rGV (-3343)
  104. #define y2rBU 8295
  105.  
  106. /*
  107. #define y2rNS 16
  108. #define y2rXY 76608L
  109. #define y2rRV 105007L
  110. #define y2rGU (-25775L)
  111. #define y2rGV (-53488L)
  112. #define y2rBU 132720L
  113.  
  114. #define y2rNS 22
  115. #define y2rXY 4902931L
  116. #define y2rRV 6720473L
  117. #define y2rGU (-1649614L)
  118. #define y2rGV (-3423205L)
  119. #define y2rBU 8494065L
  120. */
  121.