.. _ColorOperations/ConvertingColorSpaces:

Convert a QuickTime's Color Space
=================================

Problem
-------

You have a QuickTime movie that is not in the desired color space.  For example, the QuickTime file has linear color but you want sRGB instead.

Solution
--------

Use the :class:`Draft.LUT` class:

::

    import Draft

    inFile = '/path/to/input.mov'
    outFile = '/path/to/output.mov'

    dec = Draft.VideoDecoder( inFile )
    enc = Draft.VideoEncoder( outFile, dec.fps, dec.width, dec.height )

    lut = Draft.LUT.CreateSRGB()

    img = Draft.Image.CreateImage( 1, 1 )

    while dec.DecodeNextFrame( img ):
        lut.Apply( img )
        enc.EncodeNextFrame( img )

    enc.FinalizeEncoding()

Discussion
----------

In our script above, two lines are repsonsible for performing the color conversion.  First, we call :meth:`Draft.LUT.CreateSRGB()` to create the LUT.  The returned LUT will convert images from Linear color to sRGB.

Next, we call :meth:`~Draft.LUT.Apply()` to apply our LUT to every frame in the movie before we encode it into our output movie.

Draft includes several LUTs in addition to sRGB:

================  =====================================
LUT               Draft command
================  =====================================
Cineon            :meth:`Draft.LUT.CreateCineon()`
Alexa V3 Log C    :meth:`Draft.LUT.CreateAlexaV3LogC()`
sRGB              :meth:`Draft.LUT.CreateSRGB()`
Rec. 709          :meth:`Draft.LUT.CreateRec709()`
Gamma correction  :meth:`Draft.LUT.CreateGamma()`
================  =====================================

See Also
--------

For the inverting a LUT please review :ref:`ColorOperations/BakingAColorTransform`.
