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,
43 Parameter description.
48 Return value description.
51 # The gamut should be marked as experimental until
52 # matrices are fully verified
53 name = '%s - %s - Experimental' % (transfer_function, gamut)
54 if transfer_function == '':
55 name = 'Linear - %s - Experimental' % gamut
57 name = 'Curve - %s' % transfer_function
62 cs.equality_group = ''
63 cs.family = 'Input/GoPro'
66 # A linear space needs allocation variables
67 if transfer_function == '':
68 cs.allocation_type = ocio.Constants.ALLOCATION_LG2
69 cs.allocation_vars = [-8, 5, 0.00390625]
71 def protune_to_linear(normalized_code_value):
75 linear = ((pow(c1, (normalized_code_value)) - c2) / c3)
79 cs.to_reference_transforms = []
81 if transfer_function == 'Protune Flat':
82 data = array.array('f', '\0' * lut_resolution_1d * 4)
83 for c in range(lut_resolution_1d):
84 data[c] = protune_to_linear(float(c) / (lut_resolution_1d - 1))
86 lut = '%s_to_linear.spi1d' % transfer_function
89 os.path.join(lut_directory, lut),
96 cs.to_reference_transforms.append({
99 'interpolation': 'linear',
100 'direction': 'forward'})
102 if gamut == 'Protune Gamut':
103 cs.to_reference_transforms.append({
105 'matrix': [0.533448429, 0.32413911, 0.142412421, 0,
106 -0.050729924, 1.07572006, -0.024990416, 0,
107 0.071419661, -0.290521962, 1.219102381, 0,
109 'direction': 'forward'})
111 cs.from_reference_transforms = []
115 def create_colorspaces(lut_directory, lut_resolution_1d):
117 Generates the colorspace conversions.
122 Parameter description.
127 Return value description.
133 protune_1 = create_protune(
139 ["protuneflat_protunegamutexp"])
140 colorspaces.append(protune_1)
143 protune_2 = create_protune(
150 colorspaces.append(protune_2)
153 protune_3 = create_protune(
159 ["lin_protunegamutexp"])
160 colorspaces.append(protune_3)