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,
42 Parameter description.
47 Return value description.
50 # The gamut should be marked as experimental until matrices are fully
52 name = '%s - %s - Experimental' % (transfer_function, gamut)
53 if transfer_function == '':
54 name = 'Linear - %s - Experimental' % gamut
56 name = 'Curve - %s' % transfer_function
61 cs.equality_group = ''
62 cs.family = 'Input/GoPro'
65 # A linear space needs allocation variables.
66 if transfer_function == '':
67 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
68 cs.allocation_vars = [-8, 5, 0.00390625]
70 def protune_to_linear(normalized_code_value):
74 linear = ((pow(c1, normalized_code_value) - c2) / c3)
78 cs.to_reference_transforms = []
80 if transfer_function == 'Protune Flat':
81 data = array.array('f', '\0' * lut_resolution_1d * 4)
82 for c in range(lut_resolution_1d):
83 data[c] = protune_to_linear(float(c) / (lut_resolution_1d - 1))
85 lut = '%s_to_linear.spi1d' % transfer_function
88 os.path.join(lut_directory, lut),
95 cs.to_reference_transforms.append({
98 'interpolation': 'linear',
99 'direction': 'forward'})
101 if gamut == 'Protune Native':
102 cs.to_reference_transforms.append({
104 'matrix': [0.533448429, 0.32413911, 0.142412421, 0,
105 -0.050729924, 1.07572006, -0.024990416, 0,
106 0.071419661, -0.290521962, 1.219102381, 0,
108 'direction': 'forward'})
110 cs.from_reference_transforms = []
114 def create_colorspaces(lut_directory, lut_resolution_1d):
116 Generates the colorspace conversions.
121 Parameter description.
126 Return value description.
132 protune_1 = create_protune(
137 ['protuneflat_protunegamutexp'])
138 colorspaces.append(protune_1)
141 protune_2 = create_protune(
147 colorspaces.append(protune_2)
150 protune_3 = create_protune(
155 ['lin_protunegamutexp'])
156 colorspaces.append(protune_3)