home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FAQSYS18.ZIP / FAQS.DAT / COLORS.FAQ < prev    next >
Internet Message Format  |  1995-12-12  |  65KB

  1. Path: senator-bedfellow.mit.edu!turing!bourgin
  2. From: dbourgin@turing.imag.fr (David Bourgin (The best player).)
  3. Newsgroups: comp.graphics,sci.image.processing,comp.answers,sci.answers,news.answers
  4. Subject: Color space FAQ
  5. Supersedes: <graphics/colorspace-faq_796603144@rtfm.mit.edu>
  6. Followup-To: poster
  7. Date: 8 Apr 1995 00:07:05 GMT
  8. Organization: ufrima
  9. Lines: 1238
  10. Sender: dbourgin@ufrima.imag.fr (David Bourgin)
  11. Approved: news-answers-request@MIT.EDU
  12. Distribution: world
  13. Expires: 29 Apr 1995 00:05:56 GMT
  14. Message-ID: <graphics/colorspace-faq_797299556@rtfm.mit.edu>
  15. Reply-To: bourgin <dbourgin@ufrima.imag.fr>
  16. NNTP-Posting-Host: bloom-picayune.mit.edu
  17. Summary: This posting contains a list of Frequently Asked
  18.          Questions (and their answers) about colors and color spaces.
  19.          It provides an extension to the short 4 and 5 items
  20.          of comp.graphics FAQ. Read item 1 for more details.
  21.          A copy of this document is available by anonymous ftp
  22.          in rtfm.mit.edu: /pub/usenet/news.answers/graphics/colorspace-faq
  23.          or turing.imag.fr: /pub/compression/colorspace-faq
  24. Keywords: Color space FAQ
  25. X-Last-Updated: 1995/03/06
  26. Originator: faqserv@bloom-picayune.MIT.EDU
  27. Xref: senator-bedfellow.mit.edu comp.graphics:73872 sci.image.processing:13768 comp.answers:11084 sci.answers:2420 news.answers:41476
  28.  
  29. Archive-name: graphics/colorspace-faq
  30. Posting-Frequency: every 14 days
  31. Last-modified: 28/2/95
  32.  
  33. ###########################################################
  34. Color spaces FAQ - David Bourgin
  35. Date: 28/1/95 (Major modifications)
  36. Last update: 6/1/95 (23/1/95: minor modifications)
  37.  
  38. ---------------------------
  39.      Table of contents
  40. ---------------------------
  41. 1 - Purpose of this FAQ
  42. 2 - Some definitions
  43. 3 - What is an image based on a color look-up table (LUT)?
  44. 4 - What is this gamma component?
  45. 5 - Color space conversions
  46. 5.1 - RGB, CMY, and CMYK
  47. 5.2 - HSI and related color spaces
  48. 5.3 - CIE XYZ and gray level (monochrome included) pictures
  49. 5.4 - CIE Luv and CIE Lab
  50. 5.5 - LCH and CIE LSH
  51. 5.6 - The associated standards: YUV, YIQ, and YCbCr
  52. 5.7 - SMPTE-C RGB
  53. 5.8 - SMPTE-240M YPbPr (HD televisions)
  54. 5.9 - Xerox Corporation YES
  55. 5.10- Kodak Photo CD YCC
  56. 6 - References
  57. 7 - Comments and thanks
  58.  
  59. ---------------------------
  60.           Contents
  61. ---------------------------
  62. 1 - Purpose of this FAQ (D. Bourgin)
  63.  
  64.     I did a (too) long period of research in the video domain (video cards,
  65.     image file formats, and so on) and I've decided to provide to all people
  66.     who need some informations about that.
  67.     I aim to cover a part of the Frequently Asked Questions (FAQ) in the video
  68.     works, it means to provide some (useful?) informations about the colors,
  69.     and more especially about color spaces. If you have some informations
  70.     to ask/add to this document, please read item 7.
  71.  
  72. 2 - Some definitions (A. Ford, D.Bourgin)
  73.  
  74.     Color is defined as an experience in human perception. In physics terms, a
  75.     color is the result of an observed light on the retina of the eye. The
  76.     light must have a wavelength in the range of 400 to 700 nm. The radient
  77.     flux of observed light at each wavelength in the visible spectrum is
  78.     associated to a Spectral Power Distribution (SPD).
  79.     An SPD is created by cascading the SPD of the light source with the
  80.     Spectral Reflectance of the object in the scene. In addition the optics of
  81.     any imaging device will have an effect.
  82.     Strictly though, color is a visual sensation, so a `color' is created
  83.     when we observe a specific SPD.
  84.     We see color by means of cones in the retina. There are three types of
  85.     cones sensitive to wavelengths that approximately correspond to red, green
  86.     and blue light. Together with information from rod cells (which are not
  87.     sensitive to color) the cone information is encoded and sent to higher
  88.     brain centres along the optic nerve. The encoding, known as opponent
  89.     process theory, consists of three opponent channels, these are:
  90.  
  91.     Red     -       Green
  92.     Blue    -       Yellow
  93.     Black   -       White
  94.  
  95.     Note: Actually, recent studies show that eyes use addtionnal cone types.
  96.     (cf. "La Recherche", n.272, january, 1995)
  97.  
  98.     This is different to tri-chromatic theory (e.g. Red, Green, Blue additive
  99.     color) which you may be used to, but when we describe colors we do not say
  100.     "it is a reddy green" or "that's a bluey yellow".
  101.     Perceptually we require three attributes to describe a color. Generally
  102.     any three will do, but there need's to be three.
  103.  
  104.     For human purpose color descriptions these attributes have been by the CIE
  105.     recommendations, as follows:
  106.  
  107.     Brightness. The attribute of a visual sensation according to which an area
  108.     appears to exhibit more or less light. You can blurry or enhance an image
  109.     by modifying this attribute.
  110.  
  111.     Hue. The attribute of a visual sensation according to which an area appears
  112.     to be similar to one, or to proportions of two, of the perceived colors
  113.     red, yellow, green and blue.
  114.  
  115.     Colorfulness. The attribute of a visual sensation according to which an
  116.     area appears to exhibit more or less of its hue. You can go from a sky blue
  117.     to a deep blue by changing this attribute.
  118.  
  119.     So, a color is a visual sensation produced by a stimulus which is a
  120.     specific SPD. It should be noted however, that two different SPD's may
  121.     produce the same visual sensation - an effect known as metarmerism.
  122.  
  123.     What is a color space?
  124.  
  125.     A color space is a method by which we can specify, create and visualise
  126.     color. As human's, we may define a color by its attributes of brightness,
  127.     hue and colorfulness. A computer will define a color in terms of the
  128.     excitations of red, green and blue phosphors on the CRT faceplate. A
  129.     printing press defines color in terms of the reflectance and absorbance of
  130.     cyan, magenta, yellow and black inks on the paper.  
  131.  
  132.     If we imagine that each of the three attributes used to describe a color
  133.     are axes in a three dimensional space then this defines a color space.
  134.     The colors that we can percieve can be represented by the CIE system, other
  135.     color spaces are subsets of this perceptual space. For instance RGB color
  136.     space, as used by television displays, can be visualised as a cube with
  137.     red, green and blue axes. This cube lies within our perceptual space, since
  138.     the RGB space is smaller and represents less colors than we can see. CMY
  139.     space would be represented by a second cube, with a different orientation
  140.     and a different position within the perceptual space.
  141.  
  142.     So, a color space is a mathematical representation of our perceptions. E.g.
  143.     RGB is a tri-dimensional space with red, green and blue axes. It's useful
  144.     to think so because computers are in fond of numbers and equations...
  145.  
  146.     Why is there more than one color space?
  147.  
  148.     Different color spaces are better for different applications, some
  149.     equipment has limiting factors that dictate the size and type of color
  150.     space that can be used.  Some color spaces are perceptually linear, i.e. a
  151.     10 unit change in stimulus will produce the same change in perception
  152.     wherever it is applied. Many color spaces, particularly in computer
  153.     graphics are not linear in this way. Some color spaces are intuitive to
  154.     use, i.e. it is easy for the user to navigate within them and creating
  155.     desired colors is relativly easy. Finally, some color spaces are device
  156.     dependent while others are not (so called device independent).
  157.  
  158.     What's the difference between device dependent and device independent?
  159.  
  160.     A device dependent color space is a color space where the color produced
  161.     depends on the equipment and the set-up used to produce it. For example the
  162.     color produced using pixel values of [rgb = 250,134,67] will alter as you
  163.     change the brightness and contrast on your display. In the same way if you
  164.     change your monitor the red, green and blue phosphors will have slightly
  165.     different SPD's and the color produced will change. Thus RGB is a color
  166.     space that is dependent on the system being used, it is device dependent.
  167.     A device indepent color space is one where the coordinates used to specify
  168.     the color will produce the same color wherever they are applied.
  169.     An example of a device independent color space (if it has been implemented
  170.     properly) is the CIE L*a*b* color space (known as CIELab). This is based on
  171.     the HVS as described by the CIE system (see below to know what CIE stands
  172.     for).
  173.  
  174.     Another way of looking a device dependancy is to imagine our RGB cube
  175.     within our perceptual color space. We define a color by the values on the
  176.     three axes. However the exact color will depend on the position of the cube
  177.     within the perceptual color space, move the cube (by changing the set-up)
  178.     and the color will change even if the RGB values remain the same.
  179.     Some device dependent color spaces have their position within CIE space
  180.     defined, these are known as device callibrated color spaces and are a kind
  181.     of half way house between dependent and independent color spaces. For
  182.     example, a graphics file that contains colorimetric information, i.e. the
  183.     white point, transfer functions, and phosphor chromaticities, would enable
  184.     device dependent RGB data to be modified for whatever device was being used
  185.     - i.e. callibrated to specific devices. In other words, if you have a
  186.     device independent color space, you must adapt your device as defined in
  187.     the color space and not the color space to the device.
  188.  
  189.     What is a color gamut?
  190.  
  191.     A color gamut is the boundary of the color space. Gamut's are best
  192.     shown and evaluated using the CIE system.
  193.  
  194.     What is the CIE System?
  195.  
  196.     The CIE has defined a system that classifies color according to the HVS (it
  197.     started producing specifications in 1931). Using this system we can specify
  198.     any color in terms of its CIE coordinates. 
  199.  
  200.     The CIE system works by weighting the SPD of an object in terms of three
  201.     color matching functions. These functions are the sensitivities of a
  202.     standard observer to light of different wavelengths. The weighting is 
  203.     performed over the visual spectrum, from around 360nm to 830nm in 1nm 
  204.     intervals. However, the illuminant, and lighting and viewing geometry are 
  205.     carefully defined. This process produces three CIE tri-stimulus values, 
  206.     XYZ, which describe the color. 
  207.  
  208.     There are many measures that can be derived from the tri-stimulus values,
  209.     these include chromaticity coordinates and color spaces.
  210.  
  211.     What color space should I use?
  212.  
  213.     That depends on what you want to do, but heres a list of the pros and cons
  214.     of some of the more common, computer related, color spaces - we will see
  215.     in item 5 how to convert the (most common) color spaces between
  216.     themselves - :
  217.  
  218.     RGB (Red Green Blue)
  219.  
  220.     Additive color system based on trichromatic theory, commonly used by CRT
  221.     displays where proportions of excitation of red, green and blue emmiting
  222.     phosphors produce colors when visually fused. Easy to implement, non
  223.     linear, device dependent, unintuitive, common (used in television cameras,
  224.     computer graphics etc).
  225.  
  226.     CMY(K) (Cyan Magenta Yellow (Black))
  227.  
  228.     Subtractive color. Used in printing and photography. Printers often include
  229.     the fourth component, black ink, to improve the color gamut (by increasing
  230.     the density range), improving blacks, saving money and speeding drying (less
  231.     ink to dry). Fairly easy to implement, difficult to transfer *properly* from
  232.     RGB (simple transforms are, well, simple), device dependent, non-linear,
  233.     unintuitive.
  234.  
  235.     HSL (Hue Saturation and Lightness)
  236.  
  237.     This represents a wealth of similar color spaces, alternatives include HSI
  238.     (intensity), HSV (value), HCI (chroma / colorfulness),  HVC, TSD (hue
  239.     saturation and darkness) etc etc. All these color spaces are non-linear
  240.     transforms from RGB they are thus, device dependent, non-linear but very
  241.     intuitive. In addition the seperation of the luminance component has
  242.     advantages in image processing and other applications. (But take care, the
  243.     complete isolation of the separate components will require a space
  244.     optimised for your device. See later notes on CIE color spaces)
  245.  
  246.     YIQ, YUV, YCbCr, YCC  (Luminance - Chrominance)
  247.  
  248.     These are the television transmission color spaces (YIQ and YUV analogue
  249.     (NTSC and PAL) and YCbCr digital). They separate luminance from chrominance
  250.     (lightness from color) and are useful in compression and image processing
  251.     applications. YIQ and YUV are, if used according to their relative
  252.     specifications, linear. They are all device dependent and, unless you are a
  253.     TV engineer, unintuitive. Kodaks PhotoCD system uses a type of YCC color
  254.     space, PhotoYCC, which is a device calibrated color space.
  255.  
  256.     CIE 
  257.  
  258.     The HVS based color specification system. There are two CIE based color
  259.     spaces, CIELuv and CIELab. They are near linear (as close as any color
  260.     space is expected to sensibly get), device independent (unless your in the
  261.     habit of swapping your eye balls with aliens), but not very intuitive to
  262.     use. 
  263.  
  264.     From CIELuv you can derive CIELhs or CIELhc where h is the hue (an angle),
  265.     s the saturation and c the chroma. CIELuv has an associated chromaticity
  266.     diagram, a two dimensional chart which makes additive color mixing very
  267.     easy to visualise, hence CIELuv is widely used in additive color
  268.     applications, like television.
  269.     CIELab has no associated two dimensional chromaticity diagram and no 
  270.     correlate of saturation so only Lhc can be used.
  271.  
  272.     Since there is such a wide variet of color spaces, its useful to understand
  273.     a bit more about them and how to convert between them.
  274.  
  275.     The color space conversions are essentially provided for programmers. If
  276.     you are a specialist then skip to the references in item 6. Many of the
  277.     conversions are based on linear matrix transforms. (Was it Jim Blinn who
  278.     said that any problem in computer graphics can be solved by a matrix 
  279.     transform ?). As an example:
  280.  
  281.     E.g. RGB -> CIE XYZccir601-1 (D65) provides the following matrix of numbers
  282.     (see item 5.3):
  283.     |  0.607   0.174   0.200 |
  284.     |  0.299   0.587   0.114 |
  285.     |  0.000   0.066   1.111 |
  286.     and CIE XYZccir601-1 (D65) -> RGB provides the following matrix:
  287.     |  1.910  -0.5338 -0.2891  |
  288.     | -0.9844  1.9990 -0.0279 |
  289.     | 0.0585  -0.1187 -0.9017 |
  290.     
  291.     These two matrices are the (approximate) inversion of each other. If you
  292.     are a beginner in this mathematical stuff, skip the previous explainations,
  293.     and just use the results...
  294.  
  295.     Other definitions.
  296.  
  297.     Photometric terms:  illuminance   - luminous flux per unit area incident on
  298.                                         a surface
  299.                         luminance     - luminous flux per unit solid angle and
  300.                                         per unit projected area, in a given
  301.                                         direction, at a point on a surface.
  302.                         luminous flux - radient flux weighted by the V(landa)
  303.                                         function.
  304.                                     I.e. weighted by the eye's sensitivity.
  305.                         radient flux  - total power / energy of the incident
  306.                                         radiation.
  307.  
  308.     Other terms:        brightness    - the human sensation by which an area
  309.                                         exhibits more or less light.
  310.                         lightness     - the sensation of an area's brightness
  311.                                         relative to  a reference white in the
  312.                                         scene.
  313.                         chroma        - the colorfulness of an area relative to
  314.                                         the brightness of a reference white.
  315.                         saturation    - the colorfulness of an area relative to
  316.                                         its  brightness. 
  317.  
  318.     Note: This list is not exhaustive, some terms have alternative meanings
  319.     but we assume these to be the fundamentals.
  320.  
  321. 3 - What is an image based on a color look-up table (LUT)?
  322.  
  323.     All of the pictures don't use the full color space. That's why we often
  324.     use another scheme to improve the encoding of the picture (especially
  325.     to get a file which takes less space). To do so, you have two
  326.     possibilities:
  327.     - You reduce the bits/sample. It means you use less bits for each component
  328.     that describe the color. The colors are described as direct colors, it
  329.     means that all the pixels (or vectors, for vectorial descriptions) are
  330.     directly stored with the full components. For example, with a RGB (see
  331.     item 5.1 to know what RGB is) bitmapped image with a width of 5 pixels and
  332.     a height of 8 pixels, you have:
  333.     (R11,G11,B11) (R12,G12,B12) (R13,G13,B13) (R14,G14,B14) (R15,G15,B15)
  334.     (R21,G21,B21) (R22,G22,B22) (R23,G23,B23) (R24,G24,B24) (R25,G25,B25)
  335.     (R31,G31,B31) (R32,G32,B32) (R33,G33,B33) (R34,G34,B34) (R35,G35,B35)
  336.     (R41,G41,B41) (R42,G42,B42) (R43,G43,B43) (R44,G44,B44) (R45,G45,B45)
  337.     (R51,G51,B51) (R52,G52,B52) (R53,G53,B53) (R54,G54,B54) (R55,G55,B55)
  338.     (R61,G61,B61) (R62,G62,B62) (R63,G63,B63) (R64,G64,B64) (R65,G65,B65)
  339.     (R71,G71,B71) (R72,G72,B72) (R73,G73,B73) (R74,G74,B74) (R75,G75,B75)
  340.     (R81,G81,B81) (R82,G82,B82) (R83,G83,B83) (R84,G84,B84) (R85,G85,B85)
  341.     where Ryx, Gyx, Byx are respectively the Red, Green, and Blue components
  342.     you need to render a color for the pixel located at (x;y).
  343.     - You use a palette. In this case, all the colors are stored in a table
  344.     called a palette. This table is usually small. And the components of all
  345.     the colors for each pixel (or the vector data) are removed to be replaced
  346.     with a number. This number is an index in the palette. It explains why we
  347.     call the palette, a color look-up table (LUT or CLUT).
  348.  
  349. 4 - What is this gamma component?
  350.  
  351.     Many image processing operations, and also color space transforms that
  352.     involve device independent color spaces, like the CIE system based ones,
  353.     must be performed in a linear luminance domain.
  354.     By this we really mean that the relationship between pixel values specified
  355.     in software and the luminance of a specific area on the CRT display must be
  356.     known. CRTa will have a non-linear response.
  357.     The luminance of a CRT is generally modelled using a power function with an
  358.     exponent, gamma, somewhere between 2.2 [NTSC and SMPTE specifications] and
  359.     2.8 [as given by Hunt and Sproson]. Recent measurements performed at the
  360.     BBC in the UK (Richard Salmon and Alan Roberts) have shown that the actual
  361.     value of gamma is very dependent upon the accurate setting of the CRTs
  362.     black level. For correctly set-up CRTs gamma is 2.35 +/- 0.1. This
  363.     relationship is given as follows:
  364.  
  365.     Luminance = voltage ^ gamma
  366.  
  367.     Where luminance and voltage are normalised. For Liquid Crystal Displays the
  368.     response is more closely followed by an "S" shaped curve with a vicious
  369.     hook near black and a slow roll-off near white.
  370.  
  371.     In order to display image information as linear luminance we need to modify
  372.     the voltages sent to the CRT. This process stems from television systems
  373.     where the camera and reciever had different transfer functions (which,
  374.     unless corrected, would cause problems with tone reproduction). The
  375.     modification applied is known as gamma correction and is given below:
  376.  
  377.     New_Voltage = Old_Voltage ^ (1/gamma)
  378.  
  379.     (Both voltages are normalised and gamma is the value of the exponent of the
  380.     power function that most closely models the luminance-voltage relationship
  381.     of the display being used.)
  382.  
  383.     For a color computer system we can replace the voltages by the pixel
  384.     values selected, this of course assumes that your graphics card converts
  385.     digital values to analogue voltages in a linear way. (For precision work
  386.     you should check this). The color relationships are:
  387.  
  388.     Red  = a* (Red' ^gamma) +b
  389.     Green= a* (Green' ^gamma) +b
  390.     Blue = a* (Blue' ^gamma) +b
  391.  
  392.     where Red', Green', and Blue' are the normalised input RGB pixel values and
  393.     Red, Green, and Blue are the normalised gamma corrected signals sent to the
  394.     graphics card. The values of the constants a and b componsate for the
  395.     overall system gain and system offset respectively. (Essentially gain is
  396.     contrast and offset is intensity.) For basic applications the value of a,
  397.     b and gamma can be assumed to be consistent between color channels,
  398.     however for precise applications they must be measured for each channel
  399.     separatley.
  400.            
  401.     It is common to perform gamma correction by calculating the corrected value
  402.     for each possible input value and storing this in an array as a Look Up
  403.     Table (see item 3). In some cases the LUT is part of the graphics card, in
  404.     others it needs to be implemented in software.
  405.  
  406.     Research by Cowan and Post (see references in item 6) has shown that not
  407.     all CRT displays can be accurately modelled by a simple power relationship.
  408.     Cowan found errors of up to 100% between measured and calculated values. To
  409.     prevent this a simple LUT generating gamma correction function cannot be
  410.     used. The best method is to measure the absolute luminance of the display
  411.     at various pixel values and to linearily interpolate between them to
  412.     produce values for the LUT.
  413.  
  414.     It should be noted at this point that correct gamma correction depends on a
  415.     number of factors, in addition to the characteristics of the CRT display.
  416.     These include the gamma of the input device (scanner, video grabber etc),
  417.     the viewing conditions and target tone reproduction characteristics. In
  418.     addition linear luminance is not always desirable, for computer generated
  419.     images a system which is linear with our visual perception may be
  420.     preferable. If luminance is represented by L then lightness, our visual
  421.     sensation of an objects brightness relative to a similarly illuminated
  422.     area that appears white is given by L:
  423.  
  424.     { L=116*((Y/Yn)^(1/3))-16 if Y/Yn>0.008856
  425.     { L=903.3*Y/Yn            if Y/Yn<=0.008856
  426.  
  427.     This relationship is in fact the CIE 1976 Lightness (L*) equation which will
  428.     be discussed in section 5.4. 
  429.  
  430.     Most un-gamma corrected displays have a near linear L* response, thus for
  431.     computer generated applications, or applications where pixel values in an
  432.     image need to be intuitivly changed, this set up may be better.
  433.  
  434.     Note: Gamma correction performed in integer maths is prone to large
  435.     quantisation errors. For example, applying a gamma correction of 1/2.2
  436.     to an image with an original gamma of one (linear luminance) produced a
  437.     drop in the number of grey levels from 245 to 196. Take care not to alter
  438.     the transfer characteristics more than is necessary, if you need to gamma
  439.     correct images try to keep the originals so that you can pass them on to
  440.     others without passing on the degradations that you've produced ;-).
  441.  
  442.     In some image file formats or in graphics applications in general, you
  443.     need sometimes some other kinds of correction. These corrections provide
  444.     some specific processings rather than true gamma correction curves.
  445.     This is often the case, for examples, with the printing devices or
  446.     in animation. In the first case, it is interesting to specify that a color
  447.     must be re-affected in order you get a better rendering, as we see it later
  448.     in CMYK item. In the second case, some animations can need an extra
  449.     component associated to each pixel. This component can be, for example,
  450.     used as a transparency mask. We *improperly* call this extra component
  451.     gamma correction.
  452.     -> not to to be confused with gamma.
  453.  
  454. 5 - Color space conversions
  455.  
  456.     Except an historical point of view, most of you are - I hope - interested
  457.     in color spaces to make renderings and, if possible, on your favorite
  458.     computer. Most of computers display in the RGB color space but you may need
  459.     sometimes the CMYK color space for printing, the YCbCr or CIE Lab to
  460.     compress with JPEG scheme, and so on. That is why we are going to see,
  461.     from here, what are all these color spaces and how to convert them from one
  462.     to another (and primary from one to RGB and vice-versa, this was my purpose
  463.     when I started this FAQ).
  464.  
  465.     I provide the color space conversions for programmers. The specialists
  466.     don't need most of these infos or they can give a glance to all the stuff
  467.     and read carefully the item 6. Many of the conversions are based on linear
  468.     functions. The best example is given in item 5.3. These conversions can
  469.     be seen in matrices. A matrix is in mathematics an array of values. And to
  470.     go from one to another space color, you just make a matrix inversion.
  471.     E.g. RGB -> CIE XYZrec601-1 (C illuminant) provides the following matrix
  472.     of numbers (see item 5.3):
  473.     |  0.607   0.174   0.200 |
  474.     |  0.299   0.587   0.114 |
  475.     |  0.000   0.066   1.116 |
  476.     and CIE XYZrec601-1 (C illuminant) -> RGB provides the following matrix:
  477.     |  1.910  -0.532  -0.288 |
  478.     | -0.985   1.999  -0.028 |
  479.     |  0.058  -0.118   0.898 |
  480.     These two matrices are the (approximative) inversion of each other.
  481.     If you are a beginner in this mathematical stuff, skip the previous
  482.     explainations, and just use the result...
  483.  
  484. 5.1 - RGB, CMY, and CMYK
  485.  
  486.     The most popular color spaces are RGB and CMY. These two acronyms stand
  487.     for Red-Green-Blue and Cyan-Magenta-Yellow. They're device-dependent.
  488.     The first is normally used on monitors, the second on printers.
  489.  
  490.     RGB are known as additive primary colors, because a color is produced by
  491.     adding different qunatities of the three components, red, green, and blue.
  492.  
  493.     CMY are known as subtractive (or secondary) colors, because the color is
  494.     generated by subtracting different quantities of cyan, magenta and yellow
  495.     from white light.
  496.  
  497.     The primaries used by artists, red, yellow and blue are different because
  498.     they are concerned with mixing pigments rather than lights or dyes.
  499.  
  500.     RGB -> CMY                | CMY -> RGB
  501.     Red   = 1-Cyan    (0<=Cyan<=1)    | Cyan    = 1-Red (0<=Red<=1)
  502.     Green = 1-Magenta    (0<=Magenta<=1)    | Magenta = 1-Green (0<=Green<=1)
  503.     Blue  = 1-Yellow    (0<=Yellow<=1)    | Yellow  = 1-Blue (0<=Blue<=1)
  504.  
  505.     On printer devices, a component of black is added to the CMY, and the
  506.     second color space is then called CMYK (Cyan-Magenta-Yellow-blacK). This
  507.     component is actually used because cyan, magenta, and yellow set up to the
  508.     maximum should produce a black color. (The RGB components of the white are
  509.     completly substracted from the CMY components.) But the resulting color
  510.     isn't physically a 'true' black. The transforms from CMY to CMYK (and vice
  511.     versa) are given as shown below:
  512.     CMY -> CMYK                | CMYK -> CMY
  513.     Black=minimum(Cyan,Magenta,Yellow)    | Cyan=minimum(1,Cyan*(1-Black)+Black)
  514.     Cyan=(Cyan-Black)/(1-Black)        | Magenta=minimum(1,Magenta*(1-Black)+Black)
  515.     Magenta=(Magenta-Black)/(1-Black)    | Yellow=minimum(1,Yellow*(1-Black)+Black)
  516.     Yellow=(Yellow-Black)/(1-Black)    |
  517.  
  518.     Note, these differ to the descriptions often given, for example in Adobe
  519.     Postscript. For more information see FIELD in section 6. This is because
  520.     Adobe doesn't choose to use the most recent equations. (I don't know why!)
  521.  
  522.     RGB -> CMYK                | CMYK -> RGB
  523.     Black=minimum(1-Red,1-Green,1-Blue)    | Red=1-minimum(1,Cyan*(1-Black)+Black)
  524.     Cyan=(1-Red-Black)/(1-Black)    | Green=1-minimum(1,Magenta*(1-Black)+Black)
  525.     Magenta=(1-Green-Black)/(1-Black)    | Blue=1-minimum(1,Yellow*(1-Black)+Black)
  526.     Yellow=(1-Blue-Black)/(1-Black)    |
  527.  
  528.     Of course, I assume that C, M, Y, K, R, G, and B  have a range of [0;1].
  529.  
  530. 5.2 - HSI and related color spaces
  531.  
  532.     The representation of the colors in the RGB and CMY(K) color spaces are
  533.     designed for specific devices. But for a human observer, they are not
  534.     useful definitions. For user interfaces a more intuitive color space,
  535.     designed for the way we actually think about color is to be preferred.
  536.     Such a color space is HSI; Hue, Saturation and Intensity, which can be
  537.     thought of as an RGB cube tipped up onto one corner. The line from RGB=min
  538.     to RGB=max becomes verticle and is the intensity axis. The position of a
  539.     point on the circumference of a circle around this axis is the hue and the
  540.     saturation is the radius from the central intensity axis to the color.
  541.  
  542.                  Green
  543.                   /\
  544.                 /    \    ^
  545.               /V=1 x   \   \ Hue (angle, so that Hue(Red)=0, Hue(Green)=120, and Hue(blue)=240 deg)
  546.        Blue -------------- Red
  547.             \      |     /
  548.              \     |-> Saturation (distance from the central axis)
  549.               \    |   /
  550.                \   |  /
  551.                 \  | /
  552.                  \ |/
  553.                V=0 x (Intensity=0 at the top of the apex and =1 at the base of the cone)
  554.     
  555.     The big disadvantage of this model is the conversion which is mainly
  556.     because the hue is expressed as an angle. The transforms are given below:
  557.  
  558.     Hue = (Alpha-arctan((Red-intensity)*(3^0.5)/(Green-Blue)))/(2*PI)
  559.     with { Alpha=PI/2 if Green>Blue
  560.          { Aplha=3*PI/2 if Green<Blue
  561.          { Hue=1 if Green=Blue
  562.     Saturation = (Red^2+Green^2+Blue^2-Red*Green-Red*Blue-Blue*Green)^0.5
  563.     Intensity = (Red+Green+Blue)/3
  564.  
  565.     Note that you have to compute Intensity *before* Hue. If not, you must
  566.     assume that:
  567.     Hue = (Alpha-arctan((2*Red-Green-Blue)/((Green-Blue)*(3^0.5))))/(2*PI).
  568.  
  569.     I assume that H, S, L, R, G, and B are within range of [0;1].
  570.  
  571.     Another point of view of this cone is to project the coordinates onto the
  572.     base. The 2D projection is:
  573.     Red:   (1;0)
  574.     Green: (cos(120 deg);sin(120 deg)) = (-0.5; 0.866)
  575.     Blue:  (cos(240 deg);sin(240 deg)) = (-0.5;-0.866)
  576.     Now you need intermediate coordinates:
  577.     a = Red-0.5*(Green+Blue)
  578.     b = 0.866*(Green-Blue)
  579.     Finally, you have:
  580.     Hue = arctan2(x,y)/(2*PI) ; Just one formula, always in the correct quadrant
  581.     Saturation = (x^2+y^2)^0.5
  582.     Luminosity = (Red+Green+Blue)/3
  583.     This interesting point of view was provided by Christian Steyaert
  584.     (steyaert@vvs.innet.be).
  585.  
  586.     Another model close to HSI is HSL. It's actually a double cone with black
  587.     and white points placed at the two apexes of the double cone.
  588.     I don't provide formula, but feel free to send me the formula you could
  589.     find. ;-)
  590.  
  591.     Actually, here are many variations on HSI, e.g. HSL, HSV, HCI (chroma /
  592.     colorfulness), HVC, TSD (hue saturation and darkness) etc. But they all
  593.     do basically the same thing.
  594.  
  595. 5.3 - CIE XYZ and gray level pictures
  596.  
  597.     The CIE (presented in the item 2) has defined a human "Standard Observer",
  598.     based on measurements of the colour-matching abilities of the average human
  599.     eye. Using data from measurements made in 1931, a system of three primaries,
  600.     XYZ, was developed in which all visible colours can be represented using
  601.     only positive values of XY and Z. The Y primary is identical to Luminance,
  602.     X and Z give colouring information. This forms the basis of the CIE 1931
  603.     XYZ colour space, which is fundamental to all colorimetry. It is completely
  604.     device-independant and values are normally assumed to lie in the range
  605.     [0;1]. Colours are rarely specified in XYZ terms, it is far more common to
  606.     use "chromaticity coordinates" which are independant of the Luminance (Y).
  607.     The main advantage of CIE XYZ, and any color space or color definition
  608.     based on it, is that it is completely device independent. The main
  609.     disadvantage with CIE based spaces is the complexity of implementing them,
  610.     in addition some are not user intuitive. A complete description of the CIE
  611.     system is beyond the scope of this FAQ, we simply present useful formula to
  612.     convert between CIE values and between CIE and non-CIE color spaces. We
  613.     cannot recommend too highly that anyone wishing to implement any of the CIE
  614.     system in the digital domain reads the refs in section 6, specifically HUNT
  615.     1, SPROSON, BERNS and CIE 1.
  616.  
  617.     Chromaticity coordinates are derived from tristimulus values (the amounts
  618.     of the primaries) by normalising thus:
  619.  
  620.      x = X/(X+Y+Z)
  621.      y = Y/(X+Y+Z)
  622.      z = Z/(X+Y+Z)
  623.  
  624.     Chromaticity coordinates are *always* used in lower case. Because they have
  625.     been normalised, only two values are needed to specify the colour, and so z
  626.     is normally discarded (because x+y+z=1). Colours can be plotted on a
  627.     "chromaticity diagram" using x and y as coordinates, with Y (Luminance)
  628.     normal to the diagram. When a colour is specified in this form, it is
  629.     referred to as CIE 1931 Yxy. Tristimulus values can always be derived from
  630.     Yxy values:
  631.  
  632.     X = x*Y/y
  633.     Z = (1-x-y)*Y/y
  634.  
  635.     For scientists and programers, it is possible to convert between RGB as
  636.     displayed on a CRT and CIE tristimulus values.
  637.  
  638.     The first step is to ensure that you have either linear luminance
  639.     information, or that you know the transfer function (gamma correction) of
  640.     the display device. For further details on this see section 4. This will
  641.     give you the luminances of the red, green and blue phosphor emissions from
  642.     the red, green and blue pixel values that you specify.
  643.     The second stage is to perform a matrix transform (see item 5) to convert
  644.     the red, green, blue luminance information to CIE XYZ tristimulus values,
  645.     essentially. We can apply Grassman's Laws to establish conversion matrices
  646.     between the XYZ primaries and any other set of primaries, for instance (if
  647.     we consider RGB):
  648.  
  649.     |Red  |      -1 |X|         |X|       |Red  |
  650.     |Green| = |M|  *|Y|      and   |Y| = |M|*|Green|
  651.     |Blue |         |Z|         |Z|       |Blue |
  652.  
  653.     The matrix M is 3 by 3, and consists of the tristimulus values of the RGB
  654.     primaries in terms of the XYZ primaries (phosphors on *your* CRT).
  655.  
  656.     Ideally you would measure these - if you have a colorimeter or a
  657.     spectroradiometer / spectrophotometer handy. Alternativly you could assume
  658.     that your system corresponds to a particular specification, e.g. NTSC, and
  659.     use the figures given by the standard, however this is often not a valid
  660.     assumption - and if you need to make it it's probably not worth going to
  661.     the effort of implementing the transforms, the error's induced would outway
  662.     any advantages of the CIE system. The third method is to derive the figures
  663.     from other data.
  664.  
  665.     To solve this system we need some more data. The first data is the color
  666.     reference we use. With the CIE standard the reference of your rendering is
  667.     the white. White point is achromatic and is defined so that Y=1, and
  668.     Red=Green=Blue. To get the white point coordinates and put it into our
  669.     previous matrix system we use the CIE xyY diagram. This diagram is a 2D
  670.     diagram (based on tristimuli in regard with the wave lengths) where you get
  671.     a color as (x;y). To transform this 2D diagram into a 3D, we just consider:
  672.     z=1-(x+y)
  673.     X=x*Y/y
  674.     Z=z*Y/y
  675.     (Take care on these letters because these are case sensitive. Otherwise
  676.     you'd get unaccurate results!)
  677.     From there we must consider the coordinates of the vertices in your
  678.     triangle reference. The three vertices in your triangle reference are
  679.     of course the red, the green, and the blue in CIE xyY diagram. Those colors
  680.     are "pure values", it means the chromacity coordinates of red, green, and
  681.     blue are defined in the CIE xyY diagram:
  682.     Red:   (xr; yr; zr=1-(xr+yr))
  683.     Green: (xg; yg; zg=1-(xg+yg))
  684.     Blue:  (xb; yb; zb=1-(xb+yb))
  685.     And the white is defined as:
  686.     |Xn|   |r1 g1 b1|   |Redn  |   |r1 g1 b1|   |1|
  687.     |Yn| = |r2 g2 b2| * |Greenn| = |r2 g2 b2| * |1| (1)
  688.     |Zn|   |r3 g3 b3|   |Bluen |   |r3 g3 b3|   |1|
  689.     (1) becomes by invoking the white balance condition (Red=Green=Blue=1 for
  690.     white):
  691.     |Xn|   |ar*xr ag*xg ab*xb|   |1|   |xr xg xb|   |ar|
  692.     |Yn| = |ar*yr ag*yg ab*yb| * |1| = |yr yg yb| * |ag| (2)
  693.     |Zn|   |ar*zr ag*zg ab*zb|   |1|   |zr zg zb|   |ab|
  694.     But Xn, Yn, and Zn are also defined as (xn;yn) from the CIE xyY diagram:
  695.     zn=1-(xn+yn)
  696.     Xn=xn*Yn/yn=xn/yn
  697.     Yn=1 (always for white!)
  698.     Zn=zn*Yn/yn=zn/yn
  699.     So (2) becomes:
  700.     |xn/yn|   |xr xg xb|   |ar|
  701.     |  1  | = |yr yg yb| * |ag| (3)
  702.     |zn/yn|   |zr zg zb|   |ab|
  703.     Now, xn, yn, zn, xr, yr, zr, xg, yg, zg, xb, yb, and zb are all known
  704.     because they are supplied. Multiplying the chromaticity coordinates by
  705.     these values gives the the matrix in equation (1) (with a HP pocket
  706.     computer, for example) and get ar, ag, and ab. So:
  707.     |X|   |xr*ar xg*ag xb*ab|   |Red  |
  708.     |Y| = |yr*ar yg*ag xb*ab| * |Green|
  709.     |Z|   |zr*ar zg*ag xb*ab|   |Blue |
  710.     Let's take some examples. The CCIR (Comite Consultatif International des
  711.     Radiocommunications) defined several recommendations. The most popular
  712.     (they shouldn't be used anymore, we will see later why) are CCIR 601-1
  713.     and CCIR 709.
  714.     The CCIR 601-1 is the old NTSC (National Television System Committee)
  715.     standard. It uses a white point called "C Illuminant". The white point
  716.     coordinates in the CIE xyY diagram are (xn;yn)=(0.310063;0.316158). The
  717.     red, green, and blue chromacity coordinates are:
  718.     Red:   xr=0.67 yr=0.33 zr=1-(xr+yr)=0.00
  719.     Green: xg=0.21 yg=0.71 zg=1-(xg+yg)=0.08
  720.     Blue:  xb=0.14 yb=0.08 zb=1-(xb+yb)=0.78
  721.     zn=1-(xn+yn)=1-(0.310063+0.316158)=0.373779
  722.     Xn=xn/yn=0.310063/0.316158=0.980722
  723.     Yn=1 (always for white)
  724.     Zn=zn/yn=0.373779/0.316158=1.182254
  725.     We introduce all that in (3) and get:
  726.     ar=0.981854
  727.     ab=0.978423
  728.     ag=1.239129
  729.     Finally, we have RGB -> CIE XYZccir601-1 (C illuminant):
  730.     |X|   |0.606881 0.173505 0.200336|   |Red  |
  731.     |Y| = |0.298912 0.586611 0.114478| * |Green|
  732.     |Z|   |0.000000 0.066097 1.116157|   |Blue |
  733.     Because I'm a programer, I preferr to round these values up or down (in
  734.     regard with the new precision) and I get:
  735.     RGB -> CIE XYZccir601-1 (C illuminant)    | CIE XYZccir601-1 (C illuminant) -> RGB
  736.     X = 0.607*Red+0.174*Green+0.200*Blue    | Red   =  1.910*X-0.532*Y-0.288*Z
  737.     Y = 0.299*Red+0.587*Green+0.114*Blue    | Green = -0.985*X+1.999*Y-0.028*Z
  738.     Z = 0.000*Red+0.066*Green+1.116*Blue    | Blue  =  0.058*X-0.118*Y+0.898*Z
  739.     The other common recommendation is the 709. The white point is D65 and have
  740.     coordinates fixed as (xn;yn)=(0.312713;0.329016). The RGB chromacity
  741.     coordinates are:
  742.     Red:   xr=0.64 yr=0.33
  743.     Green: xg=0.30 yg=0.60
  744.     Blue:  xb=0.15 yb=0.06
  745.     Finally, we have RGB -> CIE XYZccir709 (709):
  746.     |X|   |0.412411 0.357585 0.180454|   |Red  |
  747.     |Y| = |0.212649 0.715169 0.072182| * |Green|
  748.     |Z|   |0.019332 0.119195 0.950390|   |Blue |
  749.     This provides the formula to transform RGB to CIE XYZccir709 and vice-versa:
  750.     RGB -> CIE XYZccir709 (D65)            | CIE XYZccir709 (D65) -> RGB
  751.     X = 0.412*Red+0.358*Green+0.180*Blue    | Red   =  3.241*X-1.537*Y-0.499*Z
  752.     Y = 0.213*Red+0.715*Green+0.072*Blue    | Green = -0.969*X+1.876*Y+0.042*Z
  753.     Z = 0.019*Red+0.119*Green+0.950*Blue    | Blue  =  0.056*X-0.204*Y+1.057*Z
  754.     Recently (about one year ago), CCIR and CCITT were both absorbed into their
  755.     parent body, the International Telecommunications Union (ITU). So you must
  756.     *not* use CCIR 601-1 and CCIR 709 anymore. Furthermore, their names have
  757.     changed  respectively to Rec 601-1 and Rec 709 ("Rec" stands for
  758.     Recommendation). Here is the new ITU recommendation.
  759.     The white point is D65 and have coordinates fixed as (xn;yn)=(0.312713;
  760.     0.329016). The RGB chromacity coordinates are:
  761.     Red:   xr=0.64 yr=0.33
  762.     Green: xg=0.29 yg=0.60
  763.     Blue:  xb=0.15 yb=0.06
  764.     Finally, we have RGB -> CIE XYZitu (D65):
  765.     |X|   |0.430574 0.341550 0.178325|   |Red  |
  766.     |Y| = |0.222015 0.706655 0.071330| * |Green|
  767.     |Z|   |0.020183 0.129553 0.939180|   |Blue |
  768.     This provides the formula to transform RGB to CIE XYZitu and vice-versa:
  769.     RGB -> CIE XYZitu (D65)            | CIE XYZitu (D65) -> RGB
  770.     X = 0.431*Red+0.342*Green+0.178*Blue    | Red   =  3.063*X-1.393*Y-0.476*Z
  771.     Y = 0.222*Red+0.707*Green+0.071*Blue    | Green = -0.969*X+1.876*Y+0.042*Z
  772.     Z = 0.020*Red+0.130*Green+0.939*Blue    | Blue  =  0.068*X-0.229*Y+1.069*Z
  773.  
  774.     You should remember that these transforms are only valid if you have
  775.     equipment that matches these specifications, or you have images that you
  776.     know have been encoded to these standards. If this is not the case, the
  777.     CIE values you calculate will not be true CIE.
  778.  
  779.     All these conversions are presented noit just as demonstrations, they can
  780.     be used for conversion between systems ;-).
  781.     For example, in most of your applications you have true color images in RGB
  782.     color space. How to render them fastly on your screen or on your favorite
  783.     printer. This is simple. You can convert your picture instantaneously in
  784.     gray scale pictures see even in a black and white pictures as a magician.
  785.     To do so, you just need to convert your RGB values into the Y component.
  786.     Actually, Y is linked to the luminosity (Y is an achromatic component) and
  787.     X and Z are linked to the colorfulness (X and Z are two chromatic
  788.     components). Old softwares used Rec 601-1 and produced:
  789.     Gray scale=Y=(299*Red+587*Green+114*Blue)/1000
  790.     With Rec 709, we have:
  791.     Gray scale=Y=(213*Red+715*Green+72*Blue)/1000
  792.     Some others do as if:
  793.     Gray scale=Green (They don't consider the red and blue components at all)
  794.     Or, alternativly, you can average the three color components so:
  795.     Gray scale=(Red+Green+Blue)/3
  796.     But now all people *should* use the most accurate, it means ITU standard:
  797.     Gray scale=Y=(222*Red+707*Green+71*Blue)/1000
  798.     (That's very close to Rec 709!)
  799.     I made some personal tests and have sorted them in regard with the global
  800.     resulting luminosity of the picture (from my eye point of view!). The
  801.     following summary gives what I found ordered increasingly:
  802.     +-----------------------------+----------------+
  803.     |Scheme                       |Luminosity level|
  804.     +-----------------------------+----------------+
  805.     |Gray=Green                   |        1       |
  806.     |Gray=ITU (D65)               |        2       |
  807.     |Gray=Rec 709 (D65)           |        3       |
  808.     |Gray=Rec 601-1 (C illuminant)|        4       |
  809.     |Gray=(Red+Green+Blue)/3      |        5       |
  810.     +-----------------------------+----------------+
  811.     So softwares with Gray=Rec 709 (D65) produce a more dark picture than with
  812.     Gray=Green. Even if you theorically lose many details with Gray=Green
  813.     scheme, in fact, and with the 64-gray levels of a VGA card of a PC it is
  814.     hard to distinguish the loss.
  815.  
  816. 5.4 - CIE Luv and CIE Lab
  817.  
  818.     In 1976, the CIE defined two new color spaces to enable us to get more
  819.     uniform and accurate models. The first of these two color spaces is the
  820.     CIE Luv which component are L*, u* and v*. L* component defines the
  821.     luminancy, and u*, v* define chrominancy. CIE Luv is very used in
  822.     calculation of small colors or color differences, especially with additive
  823.     colors. The CIE Luv color space is defined from CIE XYZ.
  824.  
  825.     CIE XYZ -> CIE Lab
  826.     { L* = 116*((Y/Yn)^(1/3)) with Y/Yn>0.008856
  827.     { L* = 903.3*Y/Yn with Y/Yn<=0.008856
  828.     u* = 13*(L*)*(u'-u'n)
  829.     v* = 13*(L*)*(v'-v'n)
  830.     where u'=4*X/(X+15*Y*+3*Z) and v'=9*Y/(X+15*Y+3*Z)
  831.     and u'n and v'n have the same definitions for u' and v' but applied to the
  832.     white point reference. So, you have:
  833.     u'n=4*Xn/(Xn+15*Yn*+3*Zn) and v'n=9*Yn/(Xn+15*Yn+3*Zn)
  834.  
  835.     See also item 5.3 about Xn, Yn, and Zn.
  836.  
  837.     As CIE Luv, CIE Lab is a color space introduced by CIE in 1976. It's a new
  838.     incorporated color space in TIFF specs. In this color space you use three
  839.     components: L* is the luminancy, a* and b* are respectively red/blue and
  840.     yellow/blue chrominancies.
  841.     This color space is also defined with regard to the CIE XYZ color spaces.
  842.  
  843.     CIE XYZ -> CIE Lab
  844.     { L=116*((Y/Yn)^(1/3))-16 if Y/Yn>0.008856
  845.     { L=903.3*Y/Yn            if Y/Yn<=0.008856
  846.     a=500*(f(X/Xn)-f(Y/Yn))
  847.     b=200*(f(Y/Yn)-f(Z/Zn))
  848.     where { f(t)=t^(1/3) with Y/Yn>0.008856
  849.           { f(t)=7.787*t+16/116 with Y/Yn<=0.008856
  850.  
  851.     See also item 5.3 about Xn, Yn, and Zn.
  852.  
  853. 5.5 - LCH and CIE LSH
  854.  
  855.     CIELab and CIELuv both have a disadvantage if used for a user interface,
  856.     they are unintuitive to use. To solve this we can use CIE definitions for
  857.     chroma, c, Hue angle, h and saturation, s (see section 1). Hue, chroma and
  858.     saturation can be derived from CIELuv, and Hue and chroma but *NOT*
  859.     saturation can be derived from CIELab (this is because CIELab has no
  860.     associated chromaticity diagram and so no correlation of saturation is
  861.     possible).
  862.  
  863.     To distinguish between LCH derived from CIELuv and CIELab the values of
  864.     Hue, H, and Chroma, C, are given the subscripts uv if from CIELuv and ab
  865.     if from CIELab.
  866.  
  867.  
  868.     CIELab -> LCH
  869.  
  870.     L = L*
  871.     C = (a*^2+b*^2)^0.5
  872.     { H=0                                 if a=0
  873.     { H=(arctan((b*)/(a*))+k*PI/2)/(2*PI) if a#0 (add PI/2 to H if H<0)
  874.     { and { k=0 if a*>=0 and b*>=0
  875.           { or k=1 if a*>0 and b*<0
  876.           { or k=2 if a*<0 and b*<0
  877.           { or k=3 if a*<0 and b*>0
  878.  
  879.     CIELuv -> LCH
  880.  
  881.     L = L*
  882.     C = (u*^2 + v*^2)^0.5     or   C = L*s
  883.     H = arctan[(v*)/(u*)]
  884.     { H=0                                 if u=0
  885.     { H=(arctan((v*)/(u*))+k*PI/2)/(2*PI) if u#0 (add PI/2 to H if H<0)
  886.     { and { k=0 if u*>=0 and v*>=0
  887.           { or k=1 if u*>0 and v*<0
  888.           { or k=2 if u*<0 and v*<0
  889.           { or k=3 if u*<0 and v*>0
  890.  
  891.     CIELuv -> CIE LSH
  892.  
  893.     L = L*
  894.     s = 13[(u' - u'n)^2 + (v' - v'n)^2]^0.5
  895.     H = arctan[(v*)/(u*)]
  896.     { H=0                                 if u=0
  897.     { H=(arctan((v*)/(u*))+k*PI/2)/(2*PI) if u#0 (add PI/2 to H if H<0)
  898.     { and { k=0 if u*>=0 and v*>=0
  899.           { or k=1 if u*>0 and v*<0
  900.           { or k=2 if u*<0 and v*<0
  901.           { or k=3 if u*<0 and v*>0
  902.  
  903. 5.6 - The associated standards: YUV, YIQ, and YCbCr
  904.  
  905.     YUV and YIQ are standard color spaces used for analogue television
  906.     transmission. YUV is used in European TVs (PAL) and YIQ in North American
  907.     TVs (NTSC). These colors spaces are device-dependent, like RGB, but they
  908.     are callibrated. This is because the primaries used in these television
  909.     systems are specified by the relative standards authorities. Y is the
  910.     luminance component and is usually referred to as the luma component (it
  911.     comes from CIE standard), U,V or I,Q are the chrominance components (i.e.
  912.     the color signals).
  913.  
  914.     YUV uses D65 white point which coordinates are (xn;yn)=(0.312713;0.329016).
  915.     The RGB chromacity coordinates are:
  916.     Red:   xr=0.64 yr=0.33
  917.     Green: xg=0.29 yg=0.60
  918.     Blue:  xb=0.15 yb=0.06
  919.     See item 5.3 to understand why the above values.
  920.  
  921.     RGB -> YUV                    | YUV -> RGB
  922.     Y =  0.299*Red+0.587*Green+0.114*Blue    | Red   = Y+0.000*U+1.140*V
  923.     U = -0.147*Red-0.289*Green+0.436*Blue    | Green = Y-0.396*U-0.581*V
  924.     V =  0.615*Red-0.515*Green-0.100*Blue    | Blue  = Y+2.029*U+0.000*V
  925.  
  926.     RGB -> YIQ                    | YUV -> RGB
  927.     Y =  0.299*Red+0.587*Green+0.114*Blue    | Red   = Y+0.956*I+0.621*Q
  928.     I =  0.596*Red-0.274*Green-0.322*Blue    | Green = Y-0.272*I-0.647*Q
  929.     Q =  0.212*Red-0.523*Green+0.311*Blue    | Blue  = Y-1.105*I+1.702*Q
  930.  
  931.     YUV -> YIQ                | YIQ -> YUV
  932.     Y = Y (no changes)            | Y = Y (no changes)
  933.     I = -0.2676*U+0.7361*V        | U = -1.1270*I+1.8050*Q
  934.     Q =  0.3869*U+0.4596*V        | V =  0.9489*I+0.6561*Q
  935.  
  936.     Note that Y has a range of [0;1] (if red, green, and blue have a range of
  937.     [0;1]) but U, V, I, and Q can be as well negative as positive. I can't give
  938.     the range of U, V, I, and Q because it depends on precision from Rec specs
  939.     To avoid such problems, you'll preferr the YCbCr. This color space is
  940.     similar to YUV and YIQ without the disadvantages. Y remains the component
  941.     of luminancy but Cb and Cr become the respective components of blue and
  942.     red. Futhermore, with YCbCr color space you can choose your luminancy from
  943.     your favorite recommendation. The most popular are given below:
  944.     +----------------+---------------+-----------------+----------------+
  945.     | Recommendation | Coef. for red | Coef. for Green | Coef. for Blue |
  946.     +----------------+---------------+-----------------+----------------+
  947.     | Rec 601-1      | 0.2989        | 0.5867          | 0.1144         |
  948.     | Rec 709        | 0.2126        | 0.7152          | 0.0722         |
  949.     | ITU            | 0.2220        | 0.7067          | 0.0713         |
  950.     +----------------+---------------+-----------------+----------------+
  951.     RGB -> YCbCr
  952.     Y  = Coef. for red*Red+Coef. for green*Green+Coef. for blue*Blue
  953.     Cb = (Blue-Y)/(2-2*Coef. for blue)
  954.     Cr = (Red-Y)/(2-2*Coef. for red)
  955.     YCbCr -> RGB
  956.     Red   = Cr*(2-2*Coef. for red)+Y
  957.     Green = (Y-Coef. for blue*Blue-Coef. for red*Red)/Coef. for green
  958.     Blue  = Cb*(2-2*Coef. for blue)+Y
  959.     (Note that the Green component must be computed *after* the two other
  960.     components because Green component use the values of the two others.)
  961.     Usually, you'll need the following conversions based on Rec 601-1
  962.     for TIFF and JPEG works:
  963.     RGB -> YCbCr (with Rec 601-1 specs)        | YCbCr (with Rec 601-1 specs) -> RGB
  964.     Y=  0.2989*Red+0.5867*Green+0.1144*Blue    | Red=  Y+0.0000*Cb+1.4022*Cr
  965.     Cb=-0.1687*Red-0.3312*Green+0.5000*Blue    | Green=Y-0.3456*Cb-0.7145*Cr
  966.     Cr= 0.5000*Red-0.4183*Green-0.0816*Blue    | Blue= Y+1.7710*Cb+0.0000*Cr
  967.  
  968.     Additional note: Tom Lane provided me implementation of the Baseline JPEG
  969.     compression system but after a close look I understood that their values
  970.     was an approximation of the previous values (you should preferr mine ;-).).
  971.  
  972.     I assume Y is within the range [0;1], and Cb and Cr are within the range
  973.     [-0.5;0.5].
  974.  
  975. 5.7 - SMPTE-C RGB
  976.  
  977.     SMPTE is an acronym which stands for Society of Motion Picture and Television
  978.     Engineers. They give a gamma (=2.2 with NTSC, and =2.8 with PAL) corrected
  979.     color space with RGB components (about RGB, see item 5.1).
  980.     The white point is D65. The white point coordinates are (xn;yn)=(0.312713;
  981.     0.329016). The RGB chromacity coordinates are:
  982.     Red:   xr=0.630 yr=0.340
  983.     Green: xg=0.310 yg=0.595
  984.     Blue:  xb=0.155 yb=0.070
  985.     See item 5.3 to understand why the above values.
  986.     To get the conversion from SMPTE-C RGB to CIE XYZ or from CIE XYZ to
  987.     SMPTE-C RGB, you have two steps:
  988.     SMPTE-C RGB -> CIE XYZ (D65)        | CIE XYZ (D65) -> SMPTE-C RGB
  989.     - Gamma correction                | - Linear transformations:
  990.     Red=f1(Red')                | Red  = 3.5058*X-1.7397*Y-0.5440*Z
  991.     Green=f1(Green')                | Green=-1.0690*X+1.9778*Y+0.0352*Z
  992.     Blue=f1(Blue')                | Blue = 0.0563*X-0.1970*Y+1.0501*Z
  993.     where { f1(t)=t^2.2 whether t>=0.0        | - Gamma correction
  994.           { f1(t)-(abs(t)^2.2) whether t<0.0    | Red'=f2(Red)
  995.     - Linear transformations:            | Green'=f2(Green)
  996.     X=0.3935*Red+0.3653*Green+0.1916*Blue    | Blue'=f2(Blue)
  997.     Y=0.2124*Red+0.7011*Green+0.0866*Blue    | where { f2(t)=t^(1/2.2) whether t>=0.0
  998.     Z=0.0187*Red+0.1119*Green+0.9582*Blue    |       { f2(t)-(abs(t)^(1/2.2)) whether t<0.0
  999.  
  1000. 5.8 - SMPTE-240M YPbPr (HD televisions)
  1001.  
  1002.     SMPTE gives a gamma (=0.45) corrected color space with RGB components
  1003.     (about RGB, see item 5.1). With this space color, you have three components
  1004.     Y, Pb, and Pr respectively linked to luminancy (see item 2), green, and
  1005.     blue. The white point is D65. The white point coordinates are
  1006.     (xn;yn)=(0.312713;0.329016). The RGB chromacity coordinates are:
  1007.     Red:   xr=0.67 yr=0.33
  1008.     Green: xg=0.21 yg=0.71
  1009.     Blue:  xb=0.15 yb=0.06
  1010.     See item 5.3 to understand why the above values.
  1011.     Conversion from SMPTE-240M RGB to CIE XYZ (D65) or from CIE XYZ (D65) to
  1012.     SMPTE-240M RGB, you have two steps:
  1013.     YPbPr -> RGB                | RGB -> YPbPr
  1014.     - Gamma correction                | - Linear transformations:
  1015.     Red=f(Red')                    | Red  =1*Y+0.0000*Pb+1.5756*Pr
  1016.     Green=f(Green')                | Green=1*Y-0.2253*Pb+0.5000*Pr
  1017.     Blue=f(Blue')                | Blue =1*Y+1.8270*Pb+0.0000*Pr
  1018.     where { f(t)=t^0.45 whether t>=0.0        | - Gamma correction
  1019.           { f(t)-(abs(t)^0.45) whether t<0.0    | Red'=f(Red)
  1020.     - Linear transformations:            | Green'=f(Red)
  1021.     Y=  0.2122*Red+0.7013*Green+0.0865*Blue    | Blue'=f(Red)
  1022.     Pb=-0.1162*Red-0.3838*Green+0.5000*Blue    | where { f(t)=t^(1/0.45) whether t>=0.0
  1023.     Pr= 0.5000*Red-0.4451*Green-0.0549*Blue    |       { f(t)-(abs(t)^(1/0.45)) whether t<0.0
  1024.  
  1025. 5.9 - Xerox Corporation YES
  1026.  
  1027.     YES have three components which are Y (see Luminancy, item 2), E (chrominancy
  1028.     of red-green axis), and S (chrominancy of yellow-blue axis)
  1029.     Conversion from YES to CIE XYZ (D50) or from CIE XYZ (D50) to YES, you have two
  1030.     steps:
  1031.     YES -> CIE XYZ (D50)            | CIE XYZ (D50) -> YES
  1032.     - Gamma correction                | - Linear transformations:
  1033.     Y=f1(Y')                    | Y= 0.000*X+1.000*Y+0.000*Z
  1034.     E=f1(E')                    | E= 1.783*X-1.899*Y+0.218*Z
  1035.     S=f1(S')                    | S=-0.374*X-0.245*Y+0.734*Z
  1036.     where { f1(t)=t^2.2 whether t>=0.0        | - Gamma correction
  1037.           { f1(t)-(abs(t)^2.2) whether t<0.0    | Y'=f2(Y)
  1038.     - Linear transformations:            | E'=f2(E)
  1039.     X=0.964*Y+0.528*E-0.157*S            | S'=f2(S)
  1040.     Y=1.000*Y+0.000*E+0.000*S            | where { f2(t)=t^(1/2.2) whether t>=0.0
  1041.     Z=0.825*Y+0.269*E+1.283*S            |       { f2(t)-(abs(t)^(1/2.2)) whether t<0.0
  1042.  
  1043.     Conversion from YES to CIE XYZ (D65) or from CIE XYZ (D65) to YES, you have two
  1044.     steps:
  1045.     YES -> CIE XYZ (D65)            | CIE XYZ (D65) -> YES
  1046.     - Gamma correction                | - Linear transformations:
  1047.     Y=f1(Y')                    | Y= 0.000*X+1.000*Y+0.000*Z
  1048.     E=f1(E')                    | E=-2.019*X+1.743*Y-0.246*Z
  1049.     S=f1(S')                    | S= 0.423*X+0.227*Y-0.831*Z
  1050.     where { f1(t)=t^2.2 whether t>=0.0        | - Gamma correction
  1051.           { f1(t)-(abs(t)^2.2) whether t<0.0    | Y'=f2(Y)
  1052.     - Linear transformations:            | E'=f2(E)
  1053.     X=0.782*Y-0.466*E+0.138*S            | S'=f2(S)
  1054.     Y=1.000*Y+0.000*E+0.000*S            | where { f2(t)=t^(1/2.2) whether t>=0.0
  1055.     Z=0.671*Y-0.237*E-1.133*S            |       { f2(t)-(abs(t)^(1/2.2)) whether t<0.0
  1056.  
  1057.     Usually, you should use YES <-> CIE XYZ (D65) conversions because your
  1058.     screen and the usual pictures have D65 as white point. Of course, sometime
  1059.     you'll need the first conversions. Just take care on your pictures.
  1060.  
  1061. 5.10- Kodak Photo CD YCC
  1062.  
  1063.     The Kodak PhotoYCC color space was designed for encoding images with the
  1064.     PhotoCD system. It is based on both ITU Recommendations 709 and 601-1,
  1065.     having a color gamut defined by the ITU 709 primaries and a luminance -
  1066.     chrominance representation of color like ITU 601-1's YCbCr. The main
  1067.     attraction of PhotoYCC is that it calibrated color space, each image being
  1068.     tracable to Kodak's standard image-capturing device and the CIE Standard
  1069.     Illuminant for daylight, D65. In addition PhotoYCC provides a color gamut
  1070.     that is greater than that which can currently be displayed, thus it is
  1071.     suitable not only for both additive and subtractive (RGB and CMY(K))
  1072.     reproduction, but also for archieving since it offers a degree of
  1073.     protection against future progress in display technology.
  1074.     Images are scanned by a standardised image-capturing device, calibrated
  1075.     accoring to the type of photographic material being scanned. The scanner is
  1076.     sensitive to any color currently producable by photographic materials (and
  1077.     more besides). The image is encoded into a color space based on the ITU
  1078.     Rec 709 reference primaries and the CIE standard illuminant D65 (standard
  1079.     daylight). The extended color gamut obtainable by the PhotoCD system is
  1080.     achieved by allowing both positive and negative values for each primary.
  1081.     This means that whereas conventional ITU 709 encoded data is limited by
  1082.     the boundary of the triangle linking the three primaries (the color gamut),
  1083.     PhotoYCC can encode data outside the boundary, thus colors that are not
  1084.     realiseable by the CCIR primary set can be recorded. This feature means
  1085.     that PhotoCD stores more information (as a larger color gamut) than
  1086.     current display devices, such as CRT monitors and dye-sublimination
  1087.     printers, can produce. In this respect it is good for archieval storage of
  1088.     images since the pictures we see now will keep up with improving display
  1089.     technology.
  1090.     When an image is scanned it is stored in terms of the three reference
  1091.     primaries, these values, Rp, Gp and Bp are defined as follows:
  1092.  
  1093.     Rp = kr {integral of (Planda planda rlanda) dlanda}
  1094.     Gp = kg{integral of (Planda planda glanda) dlanda}
  1095.     Bp = kb{integral of (Planda planda blanda) dlanda}
  1096.  
  1097.     where Rp Gp and Bp are the CCIR 709 primaries although not constrained to
  1098.     positive values.
  1099.     kr kg kb are normalising constants;
  1100.     Planda is the spectral power distribution of the light source (CIE D65);
  1101.     planda is the spectral power distribution of the scene at a specific point
  1102.     (pixel);
  1103.     rlanda glanda and blanda are the spectral power distributions of the
  1104.     scanner components primaries.
  1105.  
  1106.     kr kg kb are specified as kr = 1 / {integral of (Planda * rlanda) dlanda}
  1107.     as similairly for kg and kb replacing rlanda with glanda and blanda
  1108.     respectivly.
  1109.  
  1110.     Let's stop with the theory and let's see how to make transforms.
  1111.     To be stored on a CD rom, the Rp Gp and Bp values are transformed into
  1112.     Kodak's PhotoYCC color space. This is performed in three stages. Firstly a
  1113.     non-linear transform is applied to the image signals (this is because
  1114.     scanners tend to be linear devices while CRT displays are not), the
  1115.     transform used is as follows:
  1116.     Y (see Luminancy, item 2) and C1 and C2 (both are linked to chrominancy).
  1117.     YC1C2->RGB                        | RGB->YC1C2
  1118.     - Gamma correction:                    | Y' =1.3584*Y
  1119.     Red  =f(red')                    | C1'=2.2179*(C1-156)
  1120.     Green=f(Green')                    | C2'=1.8215*(C2-137)
  1121.     Blue =f(Blue')                    | Red  =Y'+C2'
  1122.     where { f(t)=-1.099*abs(t)^0.45+0.999 if t<=-0.018    | Green=Y'-0.194*C1'-0.509*C2'
  1123.           { f(t)=4.5*t if -0.018<t<0.018        | Blue =Y'+C1'
  1124.           { f(t)=1.099*t^0.45-0.999 if t>=0.018        |
  1125.     - Linear transforms:                |
  1126.     Y' = 0.299*Red+0.587*Green+0.114*Blue        |
  1127.     C1'=-0.299*Red-0.587*Green+0.886*Blue        |
  1128.     C2'= 0.701*Red-0.587*Green-0.114*Blue        |
  1129.     - To fit it into 8-bit data:            |
  1130.     Y =(255/1.402)*Y'                    |
  1131.     C1=111.40*C1'+156                    |
  1132.     C2=135.64*C2'+137                    |
  1133.  
  1134.     Finally, I assume Red, Green, Blue, Y, C1, and C2 are in the range of
  1135.     [0;255]. Take care that your RGB values are not constrainted to positive
  1136.     values. So, some colors can be outside the Rec 709 display phosphor
  1137.     limit, it means some colors can be outside the trangle I defined in
  1138.     item 5.3. This can be explained because Kodak want to preserve some
  1139.     accurate infos, such as specular highlight information.
  1140.     You can note that the relations to transform YC1C2 to RGB is not exactly
  1141.     the reverse to transform RGB to YC1C2. This can be explained (from Kodak
  1142.     point of view) because the output displays are limited in the range of
  1143.     their capabilities.
  1144.  
  1145.     Converting stored PhotoYCC data to RGB 24bit data for display by computers
  1146.     on CRT's is achieved as follows;
  1147.  
  1148.     Firstly normal Luma and Chroma data are recovered:
  1149.  
  1150.     Luma     = 1.3584 * Luma(8bit)
  1151.     Chroma1     = 2.2179 * (Chroma1(8bit) - 156)
  1152.     Chroma2    = 1.8215 * (Chroma2(8bit) - 137)
  1153.  
  1154.     Assuming your display uses phosphors that are, or are very close to, ITU
  1155.     Rec 709 primaries in their chromaticities, then (* see below)
  1156.  
  1157.     Rdisplay    = L + Chroma2
  1158.     Gdisplay    = L - 0.194Chroma1 - 0.509Chroma2
  1159.     Bdisplay     = L + Chroma1
  1160.  
  1161.     Two things to watch are:
  1162.  
  1163.     a) this results in RGB values from 0 to 346 (instead of the more usual 0 to
  1164.     255) if this is simply ignored the resulting clipping will cause severe
  1165.     loss of highlight information in the displayed image, a look-up-table is
  1166.     usually used to convert these through a non-linear function to 8 bit data.
  1167.     For example:
  1168.  
  1169.     Y =(255/1.402)*Y'                    
  1170.     C1=111.40*C1'+156                    
  1171.     C2=135.64*C2'+137    
  1172.  
  1173.     b) if the display phosphors differ from CCIR 709 primaries then further
  1174.     conversion will be necessary, possibly through an intermediate device
  1175.     independedent color space such as CIE XYZ.
  1176.  
  1177.     * as a note -> do the phosphors need to match with regard to their
  1178.     chromaticities or is a spectral match required? Two different spectral
  1179.     distributed phosphors may have same chromaticites but may not be a
  1180.     metameric match since metarimerism only applies to spectral distribution of
  1181.     color matching functions.
  1182.     Another point to note is that PhotoCD images are chroma subsampled, that is
  1183.     to say for each 2 x 2 block of pixels, 4 luma and 1 of each chroma
  1184.     component are sampled (i.e. chroma data is averaged over 2x2 pixel blocks).
  1185.     This technique uses the fact that the HVS is less sensitive to luminance
  1186.     than chromaince diferences so color information can be stored at a lower
  1187.     precision without percievable loss in visual quality.
  1188.  
  1189. 6 - References (most of them are provided by Adrian Ford)
  1190.  
  1191.     "An inexpensive scheme for calibration of a color monitor in terms of CIE
  1192.     standard coordinates" W.B. Cowan, Computer Graphics, Vol. 17 No. 3, 1983
  1193.  
  1194.     "Calibration of a computer controlled color monitor", Brainard, D.H, Color 
  1195.     Research & Application, 14, 1, pp 23-34 (1989).
  1196.  
  1197.     "Color Monitor Colorimetry", SMPTE Recommended Practice RP 145-1987
  1198.  
  1199.     "Color Temperature for Color Television Studio Monitors", SMPTE Recommended
  1200.     Practice RP 37
  1201.  
  1202.     SPROSON: "Color Science in Television and Display Systems" Sproson, W, N, 
  1203.     Adam Hilger Ltd, 1983. ISBN 0-85274-413-7
  1204.     (Color measuring from soft displays.
  1205.     Alan Roberts and Richard Salmon talk about it as a reference)
  1206.  
  1207.     CIE 1: "CIE Colorimetry" Official recommendations of the International
  1208.     Commission on Illumination, Publication 15.2 1986
  1209.  
  1210.     BERNS: "CRT Colorimetry:Part 1 Theory and Practice, Part 2 Metrology",
  1211.     Berns, R.S., Motta, R.J. and Gorzynski, M.E., Color Research and
  1212.     Appliation, 18, (1993).
  1213.     (Adrian Ford talks about it as a must about CIE implementations on CRT's)
  1214.  
  1215.     "Effective Color Displays. Theory and Practice", Travis, D, Academic Press,
  1216.     1991. ISBN 0-12-697690-2
  1217.     (Color applications in computer graphics)
  1218.  
  1219.     FIELD: Field, G.G., Color and Its Reproduction, Graphics Arts Technical
  1220.     Foundation, 1988, pp. 320-9
  1221.     (Read this about CMY/CMYK)
  1222.  
  1223.     POYNTON: "Gamma and its disguises: The nonlinear mappings of intensity in
  1224.     perception, CRT's, Film and Video" C. A. Poynton, SMPTE Journal, December
  1225.     1993
  1226.  
  1227.     HUNT 1: "Measuring Color" second edition, R. W. G. Hunt, Ellis Horwood
  1228.     1991, ISBN 0-13-567686-x
  1229.     (Calculation of CIE Luv and other CIE standard colors spaces)
  1230.  
  1231.     "On the Gun Independance and Phosphor Consistancy of Color Video Monitors"
  1232.     W.B. Cowan N. Rowell, Color Research and Application, V.11 Supplement 1986
  1233.  
  1234.     "Precision requirements for digital color reproduction", M Stokes
  1235.     MD Fairchild RS Berns, ACM Transactions on graphics, v11 n4 1992
  1236.  
  1237.     CIE 2: "The colorimetry of self luminous displays - a bibliography" CIE
  1238.     Publication n.87, Central Bureau of the CIE, Vienna 1990
  1239.  
  1240.     HUNT 2: "The Reproduction of Color in PhotoGraphy, Printing and
  1241.     Television", R. W. G. Hunt, Fountain Press, Tolworth, England, 1987
  1242.  
  1243.     "Fully Utilizing Photo CD Images, Article No. 4, PhotoYCC Color Encoding
  1244.     and Compression Schemes" Eastman Kodak Company, Rochester NY (USA) (1993).
  1245.  
  1246. 7 - Comments and thanks
  1247.  
  1248.     Whenever you would like to comment or suggest me some informations about
  1249.     this or about the color space transformations in general, please use email:
  1250.     dbourgin@ufrima.imag.fr (David Bourgin)
  1251.  
  1252.     Special thanks to the following persons (there are actually many other
  1253.     people to cite) for contributing to valid, see even to write some part of
  1254.     the items:
  1255.     - Adrian Ford (ajoec1@westminster.ac.uk)
  1256.     - Tom Lane (Tom_Lane@G.GP.CS.CMU.EDU)
  1257.     - Alan Roberts and Richard Salmon (Alan.Roberts@rd.bbc.co.uk,
  1258.                                        Richard.Salmon@rd.eng.bbc.co.uk)
  1259.     - Grant Sayer (grants@research.canon.oz.au)
  1260.     - Steve Westland (coa23@potter.cc.keele.ac.uk)
  1261.  
  1262.     Note: I'm doing my national service on 4 next months, it means up to the
  1263.     begining of july. I'll try to read and answer to my e-mails.
  1264.     Thanks to not be in a hurry ;-).
  1265.  
  1266. ###########################################################
  1267.