Esempio n. 1
0
def generate_3d_LUT_image(ramp_3d_path, resolution=32):
    """
    Generates a 3D LUT image covering the specified resolution
    Relies on OCIO's ociolutimage command

    Parameters
    ----------
    ramp_3d_path : str or unicode
        The path of the 3D ramp image to be written
    resolution : int, optional
        The resolution of the 3D ramp image to be written

    Returns
    -------
    None
    """

    args = ['--generate',
            '--cubesize',
            str(resolution),
            '--maxwidth',
            str(resolution * resolution),
            '--output',
            ramp_3d_path]
    lut_extract = Process(description='generate a 3d LUT image',
                          cmd='ociolutimage',
                          args=args)
    lut_extract.execute()
def idiff_images(image_1, image_2, difference_image):
    """
    Generates an image encoding the difference between two images
    Relies on the OIIO idiff command

    Parameters
    ----------
    dest_image_1 : str or unicode
        The path to the first image
    dest_image_2 : str or unicode
        The path to the second image
    difference_image : str or unicode
        The path to write the result of the difference

    Returns
    -------
    None
    """

    args = []
    args += [image_1, image_2]
    args += ["-abs", "-o", difference_image]

    idiffp = Process(description="an idiff process", cmd="idiff", args=args)

    idiffp.execute()
Esempio n. 3
0
def idiff_images(image_1, image_2, difference_image):
    """
    Generates an image encoding the difference between two images
    Relies on the OIIO idiff command

    Parameters
    ----------
    dest_image_1 : str or unicode
        The path to the first image
    dest_image_2 : str or unicode
        The path to the second image
    difference_image : str or unicode
        The path to write the result of the difference

    Returns
    -------
    None
    """

    args = []
    args += [image_1, image_2]
    args += ["-abs", "-o", difference_image]

    idiffp = Process(description='an idiff process', cmd='idiff', args=args)

    idiffp.execute()
Esempio n. 4
0
def apply_ocio_to_image(input_image, input_colorspace, output_image,
                        output_colorspace, ocio_config):
    """
    Applies an *OCIO* colorspace transform to an input image and writes a new
    image.

    Relies on the *OCIO* *ocioconvert* command.

    Parameters
    ----------
    input_image : str or unicode
        The path to the image to transform using the CTL files.
    input_colorspace : str or unicode
        The colorspace of the input image.
    output_image : str or unicode
        The path to write the result of the transforms.
    output_colorspace : str or unicode
        The colorspace for the output image.
    ocio_config : str or unicode, optional
        The path to the *OCIO* config.
    """

    ocioenv = os.environ
    ocioenv['OCIO'] = ocio_config

    args = []
    args += [input_image, input_colorspace]
    args += [output_image, output_colorspace]

    ociop = Process(description='an ocioconvert process',
                    cmd='ocioconvert',
                    args=args,
                    env=ocioenv)

    ociop.execute()
def apply_OCIO_to_image(input_image, input_colorspace, output_image, output_colorspace, ocio_config):
    """
    Applies an OCIO colorspace transform to an input image and writes a new image.
    Relies on the OCIO ocioconvert command

    Parameters
    ----------
    input_image : str or unicode
        The path to the image to transform using the CTL files
    input_colorspace : str or unicode
        The colorspace of the input image
    output_image : str or unicode
        The path to write the result of the transforms
    output_colorspace : str or unicode
        The colorspace for the output image
    ocio_config : str or unicode, optional
        The path to the OCIO config

    Returns
    -------
    None
    """

    ocioenv = os.environ
    ocioenv["OCIO"] = ocio_config

    args = []
    args += [input_image, input_colorspace]
    args += [output_image, output_colorspace]

    ociop = Process(description="an ocioconvert process", cmd="ocioconvert", args=args, env=ocioenv)

    ociop.execute()
def generate_3d_LUT_image(ramp_3d_path, resolution=32):
    """
    Generates a 3D LUT image covering the specified resolution
    Relies on OCIO's ociolutimage command

    Parameters
    ----------
    ramp_3d_path : str or unicode
        The path of the 3D ramp image to be written
    resolution : int, optional
        The resolution of the 3D ramp image to be written

    Returns
    -------
    None
    """

    args = ['--generate',
            '--cubesize',
            str(resolution),
            '--maxwidth',
            str(resolution * resolution),
            '--output',
            ramp_3d_path]
    lut_extract = Process(description='generate a 3d LUT image',
                          cmd='ociolutimage',
                          args=args)
    lut_extract.execute()
def convert_bit_depth(input_image, output_image, depth):
    """
    Convert the input image to the specified bit depth and write a new image
    Relies on the OIIO oiiotool command

    Parameters
    ----------
    input_image : str or unicode
        The path to the image to transform using the CTL files
    output_image : str or unicode
        The path to write the result of the transforms
    depth : str or unicode
        The bit depth of the output image
        Data types include: uint8, sint8, uint10, uint12, uint16, sint16, half, float, double

    Returns
    -------
    None
    """

    args = [input_image,
            '-d',
            depth,
            '-o',
            output_image]
    convert = Process(description='convert image bit depth',
                      cmd='oiiotool',
                      args=args)
    convert.execute()
def generate_3d_LUT_image(ramp_3d_path, resolution=32):
    """
    Object description.

    Parameters
    ----------
    parameter : type
        Parameter description.

    Returns
    -------
    type
         Return value description.
    """

    args = ['--generate',
            '--cubesize',
            str(resolution),
            '--maxwidth',
            str(resolution * resolution),
            '--output',
            ramp_3d_path]
    lut_extract = Process(description='generate a 3d LUT image',
                          cmd='ociolutimage',
                          args=args)
    lut_extract.execute()
Esempio n. 9
0
def convert_bit_depth(input_image, output_image, depth):
    """
    Convert the input image to the specified bit depth and write a new image
    Relies on the OIIO oiiotool command

    Parameters
    ----------
    input_image : str or unicode
        The path to the image to transform using the CTL files
    output_image : str or unicode
        The path to write the result of the transforms
    depth : str or unicode
        The bit depth of the output image
        Data types include: uint8, sint8, uint10, uint12, uint16, sint16, half, float, double

    Returns
    -------
    None
    """

    args = [input_image,
            '-d',
            depth,
            '-o',
            output_image]
    convert = Process(description='convert image bit depth',
                      cmd='oiiotool',
                      args=args)
    convert.execute()
def apply_CTL_to_image(input_image,
                       output_image,
                       ctl_paths=None,
                       input_scale=1,
                       output_scale=1,
                       global_params=None,
                       aces_ctl_directory=None):
    """
    Object description.

    Parameters
    ----------
    parameter : type
        Parameter description.

    Returns
    -------
    type
         Return value description.
    """

    if ctl_paths is None:
        ctl_paths = []
    if global_params is None:
        global_params = {}

    if len(ctl_paths) > 0:
        ctlenv = os.environ
        if aces_ctl_directory is not None:
            if os.path.split(aces_ctl_directory)[1] != 'utilities':
                ctl_module_path = os.path.join(aces_ctl_directory, 'utilities')
            else:
                ctl_module_path = aces_ctl_directory
            ctlenv['CTL_MODULE_PATH'] = ctl_module_path

        args = []
        for ctl in ctl_paths:
            args += ['-ctl', ctl]
        args += ['-force']
        args += ['-input_scale', str(input_scale)]
        args += ['-output_scale', str(output_scale)]
        args += ['-global_param1', 'aIn', '1.0']
        for key, value in global_params.iteritems():
            args += ['-global_param1', key, str(value)]
        args += [input_image]
        args += [output_image]

        ctlp = Process(description='a ctlrender process',
                       cmd='ctlrender',
                       args=args, env=ctlenv)

        ctlp.execute()
def convert_bit_depth(input_image, output_image, depth):
    """
    Object description.

    Parameters
    ----------
    parameter : type
        Parameter description.

    Returns
    -------
    type
         Return value description.
    """

    args = [input_image,
            '-d',
            depth,
            '-o',
            output_image]
    convert = Process(description='convert image bit depth',
                      cmd='oiiotool',
                      args=args)
    convert.execute()
def apply_CTL_to_image(input_image,
                       output_image,
                       ctl_paths=None,
                       input_scale=1,
                       output_scale=1,
                       global_params=None,
                       aces_ctl_directory=None):
    """
    Applies a set of Academy Color Transformation Language .ctl files to 
    an input image and writes a new image.
    Relies on the ACES ctlrender command

    Parameters
    ----------
    input_image : str or unicode
        The path to the image to transform using the CTL files
    output_image : str or unicode
        The path to write the result of the transforms
    ctl_paths : array of str or unicode, optional
        The path to write the result of the transforms
    input_scale : float, optional
        The argument to the ctlrender -input_scale parameter
        For images with integer bit depths, this divides image code values 
        before they are sent to the ctl commands
        For images with float or half bit depths, this multiplies image code 
        values before they are sent to the ctl commands
    output_scale : float, optional
        The argument to the ctlrender -output_scale parameter
        For images with integer bit depths, this multiplies image code values 
        before they are written to a file.
        For images with float or half bit depths, this divides image code values 
        before they are sent to the ctl commands
    global_params : dict of key value pairs, optional
        The set of parameter names and values to pass to the ctlrender 
        -global_param1 parameter
    aces_ctl_directory : str or unicode, optional
        The path to the aces 'transforms/ctl/utilities'

    Returns
    -------
    None
    """

    if ctl_paths is None:
        ctl_paths = []
    if global_params is None:
        global_params = {}

    if len(ctl_paths) > 0:
        ctlenv = os.environ

        if "/usr/local/bin" not in ctlenv['PATH'].split(':'):
            ctlenv['PATH'] = "%s:/usr/local/bin" % ctlenv['PATH']

        if aces_ctl_directory is not None:
            if os.path.split(aces_ctl_directory)[1] != 'utilities':
                ctl_module_path = os.path.join(aces_ctl_directory, 'utilities')
            else:
                ctl_module_path = aces_ctl_directory
            ctlenv['CTL_MODULE_PATH'] = ctl_module_path

        args = []
        for ctl in ctl_paths:
            args += ['-ctl', ctl]
        args += ['-force']
        args += ['-input_scale', str(input_scale)]
        args += ['-output_scale', str(output_scale)]
        args += ['-global_param1', 'aIn', '1.0']
        for key, value in global_params.iteritems():
            args += ['-global_param1', key, str(value)]
        args += [input_image]
        args += [output_image]

        ctlp = Process(description='a ctlrender process',
                       cmd='ctlrender',
                       args=args, env=ctlenv)

        ctlp.execute()
def generate_3d_LUT_from_image(ramp_3d_path,
                               output_path=None,
                               resolution=32,
                               format='spi3d'):
    """
    Reads a 3D LUT image and writes a 3D LUT in the specified format.
    Relies on OCIO's ociolutimage command

    Parameters
    ----------
    ramp_3d_path : str or unicode
        The path of the 3D ramp image to be read
    output_path : str or unicode, optional
        The path of the 1D LUT to be written
    resolution : int, optional
        The resolution of the 3D LUT represented in the image
    format : str or unicode, optional
        The format of the the 3D LUT that will be written

    Returns
    -------
    None
    """

    if output_path is None:
        output_path = '%s.%s' % (ramp_3d_path, 'spi3d')

    ocio_formats_to_extensions = {'cinespace': 'csp',
                                  'flame': '3dl',
                                  'icc': 'icc',
                                  'houdini': 'lut',
                                  'lustre': '3dl'}

    if format == 'spi3d' or not (format in ocio_formats_to_extensions):
        # Extract a spi3d LUT
        args = ['--extract',
                '--cubesize',
                str(resolution),
                '--maxwidth',
                str(resolution * resolution),
                '--input',
                ramp_3d_path,
                '--output',
                output_path]
        lut_extract = Process(description='extract a 3d LUT',
                              cmd='ociolutimage',
                              args=args)
        lut_extract.execute()

    else:
        output_path_spi3d = '%s.%s' % (output_path, 'spi3d')

        # Extract a spi3d LUT
        args = ['--extract',
                '--cubesize',
                str(resolution),
                '--maxwidth',
                str(resolution * resolution),
                '--input',
                ramp_3d_path,
                '--output',
                output_path_spi3d]
        lut_extract = Process(description='extract a 3d LUT',
                              cmd='ociolutimage',
                              args=args)
        lut_extract.execute()

        # Convert to a different format
        args = ['--lut',
                output_path_spi3d,
                '--format',
                format,
                output_path]
        lut_convert = Process(description='convert a 3d LUT',
                              cmd='ociobakelut',
                              args=args)
        lut_convert.execute()
def generate_baked_LUTs(odt_info,
                        shaper_name,
                        baked_directory,
                        config_path,
                        lut_resolution_1d,
                        lut_resolution_3d,
                        lut_resolution_shaper=1024):
    """
    Object description.

    Parameters
    ----------
    parameter : type
        Parameter description.

    Returns
    -------
    type
         Return value description.
    """

    # Create two entries for ODTs that have full and legal range support
    odt_info_C = dict(odt_info)
    for odt_ctl_name, odt_values in odt_info.iteritems():
        if odt_values['transformHasFullLegalSwitch']:
            odt_name = odt_values['transformUserName']

            odt_values_legal = dict(odt_values)
            odt_values_legal['transformUserName'] = '******' % odt_name
            odt_info_C['%s - Legal' % odt_ctl_name] = odt_values_legal

            odt_values_full = dict(odt_values)
            odt_values_full['transformUserName'] = '******' % odt_name
            odt_info_C['%s - Full' % odt_ctl_name] = odt_values_full

            del (odt_info_C[odt_ctl_name])

    # Generate appropriate LUTs for each ODT
    for odt_ctl_name, odt_values in odt_info_C.iteritems():
        odt_prefix = odt_values['transformUserNamePrefix']
        odt_name = odt_values['transformUserName']

        # *Photoshop*
        for input_space in ['ACEScc', 'ACESproxy']:
            args = ['--iconfig', config_path,
                    '-v',
                    '--inputspace', input_space]
            args += ['--outputspace', '%s' % odt_name]
            args += ['--description',
                     '%s - %s for %s data' % (odt_prefix,
                                              odt_name,
                                              input_space)]
            args += ['--shaperspace', shaper_name,
                     '--shapersize', str(lut_resolution_shaper)]
            args += ['--cubesize', str(lut_resolution_3d)]
            args += ['--format',
                     'icc',
                     os.path.join(baked_directory,
                                  'photoshop',
                                  '%s for %s.icc' % (odt_name, input_space))]

            bake_lut = Process(description='bake a LUT',
                               cmd='ociobakelut',
                               args=args)
            bake_lut.execute()

        # *Flame*, *Lustre*
        for input_space in ['ACEScc', 'ACESproxy']:
            args = ['--iconfig', config_path,
                    '-v',
                    '--inputspace', input_space]
            args += ['--outputspace', '%s' % odt_name]
            args += ['--description',
                     '%s - %s for %s data' % (
                         odt_prefix, odt_name, input_space)]
            args += ['--shaperspace', shaper_name,
                     '--shapersize', str(lut_resolution_shaper)]
            args += ['--cubesize', str(lut_resolution_3d)]

            fargs = ['--format',
                     'flame',
                     os.path.join(
                         baked_directory,
                         'flame',
                         '%s for %s Flame.3dl' % (odt_name, input_space))]
            bake_lut = Process(description='bake a LUT',
                               cmd='ociobakelut',
                               args=(args + fargs))
            bake_lut.execute()

            largs = ['--format',
                     'lustre',
                     os.path.join(
                         baked_directory,
                         'lustre',
                         '%s for %s Lustre.3dl' % (odt_name, input_space))]
            bake_lut = Process(description='bake a LUT',
                               cmd='ociobakelut',
                               args=(args + largs))
            bake_lut.execute()

        # *Maya*, *Houdini*
        for input_space in ['ACEScg', 'ACES2065-1']:
            args = ['--iconfig', config_path,
                    '-v',
                    '--inputspace', input_space]
            args += ['--outputspace', '%s' % odt_name]
            args += ['--description',
                     '%s - %s for %s data' % (
                         odt_prefix, odt_name, input_space)]
            if input_space == 'ACEScg':
                lin_shaper_name = '%s - AP1' % shaper_name
            else:
                lin_shaper_name = shaper_name
            args += ['--shaperspace', lin_shaper_name,
                     '--shapersize', str(lut_resolution_shaper)]

            args += ['--cubesize', str(lut_resolution_3d)]

            margs = ['--format',
                     'cinespace',
                     os.path.join(
                         baked_directory,
                         'maya',
                         '%s for %s Maya.csp' % (odt_name, input_space))]
            bake_lut = Process(description='bake a LUT',
                               cmd='ociobakelut',
                               args=(args + margs))
            bake_lut.execute()

            hargs = ['--format',
                     'houdini',
                     os.path.join(
                         baked_directory,
                         'houdini',
                         '%s for %s Houdini.lut' % (odt_name, input_space))]
            bake_lut = Process(description='bake a LUT',
                               cmd='ociobakelut',
                               args=(args + hargs))
            bake_lut.execute()
def generate_3d_LUT_from_image(ramp_3d_path,
                               output_path=None,
                               resolution=32,
                               format='spi3d'):
    """
    Object description.

    Parameters
    ----------
    parameter : type
        Parameter description.

    Returns
    -------
    type
         Return value description.
    """

    if output_path is None:
        output_path = '%s.%s' % (ramp_3d_path, 'spi3d')

    ocio_formats_to_extensions = {'cinespace': 'csp',
                                  'flame': '3dl',
                                  'icc': 'icc',
                                  'houdini': 'lut',
                                  'lustre': '3dl'}

    if format == 'spi3d' or not (format in ocio_formats_to_extensions):
        # Extract a spi3d LUT
        args = ['--extract',
                '--cubesize',
                str(resolution),
                '--maxwidth',
                str(resolution * resolution),
                '--input',
                ramp_3d_path,
                '--output',
                output_path]
        lut_extract = Process(description='extract a 3d LUT',
                              cmd='ociolutimage',
                              args=args)
        lut_extract.execute()

    else:
        output_path_spi3d = '%s.%s' % (output_path, 'spi3d')

        # Extract a spi3d LUT
        args = ['--extract',
                '--cubesize',
                str(resolution),
                '--maxwidth',
                str(resolution * resolution),
                '--input',
                ramp_3d_path,
                '--output',
                output_path_spi3d]
        lut_extract = Process(description='extract a 3d LUT',
                              cmd='ociolutimage',
                              args=args)
        lut_extract.execute()

        # Convert to a different format
        args = ['--lut',
                output_path_spi3d,
                '--format',
                format,
                output_path]
        lut_convert = Process(description='convert a 3d LUT',
                              cmd='ociobakelut',
                              args=args)
        lut_convert.execute()
Esempio n. 16
0
def apply_CTL_to_image(input_image,
                       output_image,
                       ctl_paths=None,
                       input_scale=1,
                       output_scale=1,
                       global_params=None,
                       aces_ctl_directory=None):
    """
    Applies a set of Academy Color Transformation Language .ctl files to 
    an input image and writes a new image.
    Relies on the ACES ctlrender command

    Parameters
    ----------
    input_image : str or unicode
        The path to the image to transform using the CTL files
    output_image : str or unicode
        The path to write the result of the transforms
    ctl_paths : array of str or unicode, optional
        The path to write the result of the transforms
    input_scale : float, optional
        The argument to the ctlrender -input_scale parameter
        For images with integer bit depths, this divides image code values 
        before they are sent to the ctl commands
        For images with float or half bit depths, this multiplies image code 
        values before they are sent to the ctl commands
    output_scale : float, optional
        The argument to the ctlrender -output_scale parameter
        For images with integer bit depths, this multiplies image code values 
        before they are written to a file.
        For images with float or half bit depths, this divides image code values 
        before they are sent to the ctl commands
    global_params : dict of key value pairs, optional
        The set of parameter names and values to pass to the ctlrender 
        -global_param1 parameter
    aces_ctl_directory : str or unicode, optional
        The path to the aces 'transforms/ctl/utilities'

    Returns
    -------
    None
    """

    if ctl_paths is None:
        ctl_paths = []
    if global_params is None:
        global_params = {}

    if len(ctl_paths) > 0:
        ctlenv = os.environ

        if "/usr/local/bin" not in ctlenv['PATH'].split(':'):
            ctlenv['PATH'] = "%s:/usr/local/bin" % ctlenv['PATH']

        if aces_ctl_directory is not None:
            if os.path.split(aces_ctl_directory)[1] != 'utilities':
                ctl_module_path = os.path.join(aces_ctl_directory, 'utilities')
            else:
                ctl_module_path = aces_ctl_directory
            ctlenv['CTL_MODULE_PATH'] = ctl_module_path

        args = []
        for ctl in ctl_paths:
            args += ['-ctl', ctl]
        args += ['-force']
        args += ['-input_scale', str(input_scale)]
        args += ['-output_scale', str(output_scale)]
        args += ['-global_param1', 'aIn', '1.0']
        for key, value in global_params.iteritems():
            args += ['-global_param1', key, str(value)]
        args += [input_image]
        args += [output_image]

        ctlp = Process(description='a ctlrender process',
                       cmd='ctlrender',
                       args=args, env=ctlenv)

        ctlp.execute()
Esempio n. 17
0
def generate_3d_LUT_from_image(ramp_3d_path,
                               output_path=None,
                               resolution=32,
                               format='spi3d'):
    """
    Reads a 3D LUT image and writes a 3D LUT in the specified format.
    Relies on OCIO's ociolutimage command

    Parameters
    ----------
    ramp_3d_path : str or unicode
        The path of the 3D ramp image to be read
    output_path : str or unicode, optional
        The path of the 1D LUT to be written
    resolution : int, optional
        The resolution of the 3D LUT represented in the image
    format : str or unicode, optional
        The format of the the 3D LUT that will be written

    Returns
    -------
    None
    """

    if output_path is None:
        output_path = '%s.%s' % (ramp_3d_path, 'spi3d')

    ocio_formats_to_extensions = {'cinespace': 'csp',
                                  'flame': '3dl',
                                  'icc': 'icc',
                                  'houdini': 'lut',
                                  'lustre': '3dl'}

    if format == 'spi3d' or not (format in ocio_formats_to_extensions):
        # Extract a spi3d LUT
        args = ['--extract',
                '--cubesize',
                str(resolution),
                '--maxwidth',
                str(resolution * resolution),
                '--input',
                ramp_3d_path,
                '--output',
                output_path]
        lut_extract = Process(description='extract a 3d LUT',
                              cmd='ociolutimage',
                              args=args)
        lut_extract.execute()

    else:
        output_path_spi3d = '%s.%s' % (output_path, 'spi3d')

        # Extract a spi3d LUT
        args = ['--extract',
                '--cubesize',
                str(resolution),
                '--maxwidth',
                str(resolution * resolution),
                '--input',
                ramp_3d_path,
                '--output',
                output_path_spi3d]
        lut_extract = Process(description='extract a 3d LUT',
                              cmd='ociolutimage',
                              args=args)
        lut_extract.execute()

        # Convert to a different format
        args = ['--lut',
                output_path_spi3d,
                '--format',
                format,
                output_path]
        lut_convert = Process(description='convert a 3d LUT',
                              cmd='ociobakelut',
                              args=args)
        lut_convert.execute()