2 # -*- coding: utf-8 -*-
5 Implements support for *GoPro* colorspaces conversions and transfer functions.
8 from __future__ import division
13 import PyOpenColorIO as ocio
15 import aces_ocio.generate_lut as genlut
16 from aces_ocio.utilities import (ColorSpace, sanitize)
18 __author__ = 'ACES Developers'
19 __copyright__ = 'Copyright (C) 2014 - 2015 - ACES Developers'
21 __maintainer__ = 'ACES Developers'
22 __email__ = 'aces@oscars.org'
23 __status__ = 'Production'
25 __all__ = ['create_protune',
29 def create_protune(gamut,
35 Creates colorspace covering the conversion from ProTune to ACES, with various transfer
36 functions and encoding gamuts covered
41 The name of the encoding gamut to use.
42 transfer_function : str
43 The name of the transfer function to use
44 lut_directory : str or unicode
45 The directory to use when generating LUTs
46 lut_resolution_1d : int
47 The resolution of generated 1D LUTs
49 Aliases for this colorspace
54 A ColorSpace container class referencing the LUTs, matrices and identifying
55 information for the requested colorspace.
58 # The gamut should be marked as experimental until matrices are fully
60 name = '%s - %s - Experimental' % (transfer_function, gamut)
61 if transfer_function == '':
62 name = 'Linear - %s - Experimental' % gamut
64 name = 'Curve - %s' % transfer_function
69 cs.equality_group = ''
70 cs.family = 'Input/GoPro'
73 # A linear space needs allocation variables.
74 if transfer_function == '':
75 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
76 cs.allocation_vars = [-8, 5, 0.00390625]
78 def protune_to_linear(normalized_code_value):
82 linear = ((pow(c1, normalized_code_value) - c2) / c3)
86 cs.to_reference_transforms = []
88 if transfer_function == 'Protune Flat':
89 data = array.array('f', '\0' * lut_resolution_1d * 4)
90 for c in range(lut_resolution_1d):
91 data[c] = protune_to_linear(float(c) / (lut_resolution_1d - 1))
93 lut = '%s_to_linear.spi1d' % transfer_function
96 os.path.join(lut_directory, lut),
103 cs.to_reference_transforms.append({
106 'interpolation': 'linear',
107 'direction': 'forward'})
109 if gamut == 'Protune Native':
110 cs.to_reference_transforms.append({
112 'matrix': [0.533448429, 0.32413911, 0.142412421, 0,
113 -0.050729924, 1.07572006, -0.024990416, 0,
114 0.071419661, -0.290521962, 1.219102381, 0,
116 'direction': 'forward'})
118 cs.from_reference_transforms = []
122 def create_colorspaces(lut_directory, lut_resolution_1d):
124 Generates the colorspace conversions.
128 lut_directory : str or unicode
129 The directory to use when generating LUTs
130 lut_resolution_1d : int
131 The resolution of generated 1D LUTs
136 A list of colorspaces for GoPro cameras and encodings
142 protune_1 = create_protune(
147 ['protuneflat_protunegamutexp'])
148 colorspaces.append(protune_1)
151 protune_2 = create_protune(
157 colorspaces.append(protune_2)
160 protune_3 = create_protune(
165 ['lin_protunegamutexp'])
166 colorspaces.append(protune_3)