def create_Protune(gamut, transfer_function, lut_directory, lut_resolution_1D, aliases): """ Creates colorspace covering the conversion from *ProTune* to *ACES*, with various transfer functions and encoding gamuts covered. Parameters ---------- gamut : str The name of the encoding gamut to use. transfer_function : str The name of the transfer function to use. lut_directory : str or unicode The directory to use when generating LUTs. lut_resolution_1D : int The resolution of generated 1D LUTs. aliases : list of str Aliases for this colorspace. Returns ------- ColorSpace A ColorSpace container class referencing the LUTs, matrices and identifying information for the requested colorspace. """ # The gamut should be marked as experimental until matrices are fully # verified. name = '{0} - {1} - Experimental'.format(transfer_function, gamut) if transfer_function == '': name = 'Linear - {0} - Experimental'.format(gamut) if gamut == '': name = 'Curve - {0}'.format(transfer_function) cs = ColorSpace(name) cs.description = name cs.aliases = aliases cs.equality_group = '' cs.family = 'Input/GoPro' cs.is_data = False # A linear space needs allocation variables. if transfer_function == '': cs.allocation_type = ocio.Constants.ALLOCATION_LG2 cs.allocation_vars = [-8, 5, 0.00390625] def Protune_to_linear(normalized_code_value): c1 = 113.0 c2 = 1.0 c3 = 112.0 linear = ((pow(c1, normalized_code_value) - c2) / c3) return linear cs.to_reference_transforms = [] if transfer_function == 'Protune Flat': data = array.array('f', b'\0' * lut_resolution_1D * 4) for c in range(lut_resolution_1D): data[c] = Protune_to_linear(float(c) / (lut_resolution_1D - 1)) lut = '{0}_to_linear.spi1d'.format(transfer_function) lut = sanitize(lut) genlut.write_SPI_1D( os.path.join(lut_directory, lut), 0, 1, data, lut_resolution_1D, 1) cs.to_reference_transforms.append({ 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', 'direction': 'forward' }) if gamut == 'Protune Native': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': [ 0.533448429, 0.32413911, 0.142412421, 0, -0.050729924, 1.07572006, -0.024990416, 0, 0.071419661, -0.290521962, 1.219102381, 0, 0, 0, 0, 1 ], 'direction': 'forward' }) cs.from_reference_transforms = [] return cs
def create_VLog(gamut, transfer_function, lut_directory, lut_resolution_1D, aliases): """ Creates colorspace covering the conversion from *VLog* to *ACES*, with various transfer functions and encoding gamuts covered. Parameters ---------- gamut : str The name of the encoding gamut to use. transfer_function : str The name of the transfer function to use. lut_directory : str or unicode The directory to use when generating LUTs. lut_resolution_1D : int The resolution of generated 1D LUTs. aliases : list of str Aliases for this colorspace. Returns ------- ColorSpace A ColorSpace container class referencing the LUTs, matrices and identifying information for the requested colorspace. """ name = '{0} - {1}'.format(transfer_function, gamut) if transfer_function == '': name = 'Linear - {0}'.format(gamut) if gamut == '': name = 'Curve - {0}'.format(transfer_function) cs = ColorSpace(name) cs.description = name cs.aliases = aliases cs.equality_group = '' cs.family = 'Input/Panasonic' cs.is_data = False # A linear space needs allocation variables if transfer_function == '': cs.allocation_type = ocio.Constants.ALLOCATION_LG2 cs.allocation_vars = [-8, 5, 0.00390625] def VLog_to_linear(x): cut_inv = 0.181 b = 0.00873 c = 0.241514 d = 0.598206 if x <= cut_inv: return (x - 0.125) / 5.6 else: return pow(10, (x - d) / c) - b cs.to_reference_transforms = [] if transfer_function == 'V-Log': data = array.array('f', b'\0' * lut_resolution_1D * 4) for c in range(lut_resolution_1D): data[c] = VLog_to_linear(float(c) / (lut_resolution_1D - 1)) lut = '{0}_to_linear.spi1d'.format(transfer_function) genlut.write_SPI_1D(os.path.join(lut_directory, lut), 0.0, 1.0, data, lut_resolution_1D, 1) cs.to_reference_transforms.append({ 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', 'direction': 'forward' }) if gamut == 'V-Gamut': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': [ 0.724382758, 0.166748484, 0.108497411, 0.0, 0.021354009, 0.985138372, -0.006319092, 0.0, -0.009234278, -0.00104295, 1.010272625, 0.0, 0, 0, 0, 1.0 ], 'direction': 'forward' }) cs.from_reference_transforms = [] return cs
def create_SLog(gamut, transfer_function, lut_directory, lut_resolution_1D, aliases): """ Creates colorspace covering the conversion from *Sony* spaces to *ACES*, with various transfer functions and encoding gamuts covered. Parameters ---------- gamut : str The name of the encoding gamut to use. transfer_function : str The name of the transfer function to use. lut_directory : str or unicode The directory to use when generating LUTs. lut_resolution_1D : int The resolution of generated 1D LUTs. aliases : list of str Aliases for this colorspace. Returns ------- ColorSpace A ColorSpace container class referencing the LUTs, matrices and identifying information for the requested colorspace. """ name = '{0} - {1}'.format(transfer_function, gamut) if transfer_function == '': name = 'Linear - {0}'.format(gamut) if gamut == '': name = 'Curve - {0}'.format(transfer_function) cs = ColorSpace(name) cs.description = name cs.aliases = aliases cs.equality_group = '' cs.family = 'Input/Sony' cs.is_data = False if gamut and transfer_function: cs.aces_transform_id = 'IDT.Sony.{0}_{1}_10i.a1.v1'.format( transfer_function.replace('-', ''), gamut.replace('-', '').replace(' ', '_')) # A linear space needs allocation variables. if transfer_function == '': cs.allocation_type = ocio.Constants.ALLOCATION_LG2 cs.allocation_vars = [-8, 5, 0.00390625] def SLog1_to_linear(s_log): b = 64. ab = 90. w = 940. if s_log >= ab: linear = ((pow(10., ( ((s_log - b) / (w - b) - 0.616596 - 0.03) / 0.432699)) - 0.037584) * 0.9) else: linear = (( (s_log - b) / (w - b) - 0.030001222851889303) / 5.) * 0.9 return linear def SLog2_to_linear(s_log): b = 64. ab = 90. w = 940. if s_log >= ab: linear = ((219. * (pow(10., ( ((s_log - b) / (w - b) - 0.616596 - 0.03) / 0.432699)) - 0.037584) / 155.) * 0.9) else: linear = ( ((s_log - b) / (w - b) - 0.030001222851889303) / 3.53881278538813) * 0.9 return linear def SLog3_to_linear(code_value): if code_value >= 171.2102946929: linear = (pow(10, ((code_value - 420) / 261.5)) * (0.18 + 0.01) - 0.01) else: linear = (code_value - 95) * 0.01125000 / (171.2102946929 - 95) return linear cs.to_reference_transforms = [] if transfer_function == 'S-Log1': data = array.array('f', b'\0' * lut_resolution_1D * 4) for c in range(lut_resolution_1D): data[c] = SLog1_to_linear(1023 * c / (lut_resolution_1D - 1)) lut = '{0}_to_linear.spi1d'.format(transfer_function) genlut.write_SPI_1D( os.path.join(lut_directory, lut), 0, 1, data, lut_resolution_1D, 1) cs.to_reference_transforms.append({ 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', 'direction': 'forward' }) elif transfer_function == 'S-Log2': data = array.array('f', b'\0' * lut_resolution_1D * 4) for c in range(lut_resolution_1D): data[c] = SLog2_to_linear(1023 * c / (lut_resolution_1D - 1)) lut = '{0}_to_linear.spi1d'.format(transfer_function) genlut.write_SPI_1D( os.path.join(lut_directory, lut), 0, 1, data, lut_resolution_1D, 1) cs.to_reference_transforms.append({ 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', 'direction': 'forward' }) elif transfer_function == 'S-Log3': data = array.array('f', b'\0' * lut_resolution_1D * 4) for c in range(lut_resolution_1D): data[c] = SLog3_to_linear(1023 * c / (lut_resolution_1D - 1)) lut = '{0}_to_linear.spi1d'.format(transfer_function) genlut.write_SPI_1D( os.path.join(lut_directory, lut), 0, 1, data, lut_resolution_1D, 1) cs.to_reference_transforms.append({ 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', 'direction': 'forward' }) if gamut == 'S-Gamut': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.754338638, 0.133697046, 0.111968437, 0.021198141, 1.005410934, -0.026610548, -0.009756991, 0.004508563, 1.005253201 ]), 'direction': 'forward' }) elif gamut == 'S-Gamut Daylight': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.8764457030, 0.0145411681, 0.1090131290, 0.0774075345, 0.9529571767, -0.0303647111, 0.0573564351, -0.1151066335, 1.0577501984 ]), 'direction': 'forward' }) elif gamut == 'S-Gamut Tungsten': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 1.0110238740, -0.1362526051, 0.1252287310, 0.1011994504, 0.9562196265, -0.0574190769, 0.0600766530, -0.1010185315, 1.0409418785 ]), 'direction': 'forward' }) elif gamut == 'S-Gamut3.Cine': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.6387886672, 0.2723514337, 0.0888598992, -0.0039159061, 1.0880732308, -0.0841573249, -0.0299072021, -0.0264325799, 1.0563397820 ]), 'direction': 'forward' }) elif gamut == 'S-Gamut3': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.7529825954, 0.1433702162, 0.1036471884, 0.0217076974, 1.0153188355, -0.0370265329, -0.0094160528, 0.0033704179, 1.0060456349 ]), 'direction': 'forward' }) elif gamut == 'Venice S-Gamut3': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.7933297411, 0.0890786256, 0.1175916333, 0.0155810585, 1.0327123069, -0.0482933654, -0.0188647478, 0.0127694121, 1.0060953358 ]), 'direction': 'forward' }) elif gamut == 'Venice S-Gamut3.Cine': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.6742570921, 0.2205717359, 0.1051711720, -0.0093136061, 1.1059588614, -0.0966452553, -0.0382090673, -0.0179383766, 1.0561474439 ]), 'direction': 'forward' }) cs.from_reference_transforms = [] return cs
def create_LogC(gamut, transfer_function, exposure_index, lut_directory, lut_resolution_1D, aliases): """ Creates a colorspace covering the conversion from *LogC* to *ACES*, with various transfer functions and encoding gamuts covered. Parameters ---------- gamut : str The name of the encoding gamut to use. transfer_function : str The name of the transfer function to use. exposure_index : str The exposure index to use. lut_directory : str or unicode The directory to use when generating LUTs. lut_resolution_1D : int The resolution of generated 1D LUTs. aliases : list of str Aliases for this colorspace. Returns ------- ColorSpace A ColorSpace container class referencing the LUTs, matrices and identifying information for the requested colorspace. """ name = '{0} (EI{1}) - {2}'.format(transfer_function, exposure_index, gamut) if transfer_function == '': name = 'Linear - ALEXA {0}'.format(gamut) if gamut == '': name = 'Curve - {0} (EI{1})'.format(transfer_function, exposure_index) cs = ColorSpace(name) cs.description = name cs.aliases = aliases cs.equality_group = '' cs.family = 'Input/ARRI' cs.is_data = False if gamut and transfer_function: cs.aces_transform_id = ( 'IDT.ARRI.Alexa-v3-logC-EI{0}.a1.v1'.format(exposure_index)) # A linear space needs allocation variables. if transfer_function == '': cs.allocation_type = ocio.Constants.ALLOCATION_LG2 cs.allocation_vars = [-8, 5, 0.00390625] IDT_maker_version = '0.09' nominal_exposure_index = 400 black_signal = 16 / 4095 # 0.003907 mid_gray_signal = 0.01 encoding_gain = 500 / 1023 * 0.525 # 0.256598 encoding_offset = 400 / 1023 # 0.391007 def gain_for_EI(ei): return (math.log(ei / nominal_exposure_index) / math.log(2) * (0.89 - 1) / 3 + 1) * encoding_gain def hermite_weights(x, x1, x2): d = x2 - x1 s = (x - x1) / d s2 = 1 - s return [(1 + 2 * s) * s2 * s2, (3 - 2 * s) * s * s, d * s * s2 * s2, -d * s * s * s2] def normalized_sensor_to_relative_exposure(ns, ei): return (ns - black_signal) * ( 0.18 / (mid_gray_signal * nominal_exposure_index / ei)) def normalized_LogC_to_linear(code_value, exposure_index): cut = 1 / 9 slope = 1 / (cut * math.log(10)) offset = math.log10(cut) - slope * cut gain = exposure_index / nominal_exposure_index gray = mid_gray_signal / gain # The higher the EI, the lower the gamma. enc_gain = (math.log(gain) / math.log(2) * (0.89 - 1) / 3 + 1) * encoding_gain enc_offset = encoding_offset for i in range(0, 3): nz = ((95 / 1023 - enc_offset) / enc_gain - offset) / slope enc_offset = encoding_offset - math.log10(1 + nz) * enc_gain # see if we need to bring the hermite spline into play xm = math.log10((1 - black_signal) / gray + nz) * enc_gain + enc_offset if xm > 1.0: if code_value > 0.8: hw = hermite_weights(code_value, 0.8, 1) d = 0.2 / (xm - 0.8) v = [0.8, xm, 1.0, 1 / (d * d)] # reconstruct code value from spline code_value = 0 for i in range(0, 4): code_value += (hw[i] * v[i]) code_value = (code_value - enc_offset) / enc_gain # compute normalized sensor value ns = pow(10, code_value) if (code_value - offset) / slope > cut else ( code_value - offset) / slope ns = (ns - nz) * gray + black_signal return normalized_sensor_to_relative_exposure(ns, exposure_index) cs.to_reference_transforms = [] if transfer_function == 'V3 LogC': data = array.array('f', b'\0' * lut_resolution_1D * 4) for c in range(lut_resolution_1D): data[c] = normalized_LogC_to_linear(c / (lut_resolution_1D - 1), int(exposure_index)) lut = '{0}_to_linear.spi1d'.format('{0}_{1}'.format( transfer_function, exposure_index)) lut = sanitize(lut) genlut.write_SPI_1D(os.path.join(lut_directory, lut), 0, 1, data, lut_resolution_1D, 1) cs.to_reference_transforms.append({ 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', 'direction': 'forward' }) if gamut == 'Wide Gamut': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.680206, 0.236137, 0.083658, 0.085415, 1.017471, -0.102886, 0.002057, -0.062563, 1.060506 ]), 'direction': 'forward' }) cs.from_reference_transforms = [] return cs
def create_REDLog_film(gamut, transfer_function, lut_directory, lut_resolution_1D, aliases=None): """ Creates colorspace covering the conversion from *RED* spaces to *ACES*, with various transfer functions and encoding gamuts covered. Parameters ---------- gamut : str The name of the encoding gamut to use. transfer_function : str The name of the transfer function to use. lut_directory : str or unicode The directory to use when generating LUTs. lut_resolution_1D : int The resolution of generated 1D LUTs. aliases : list of str Aliases for this colorspace. Returns ------- ColorSpace A ColorSpace container class referencing the LUTs, matrices and identifying information for the requested colorspace. """ if aliases is None: aliases = [] name = '{0} - {1}'.format(transfer_function, gamut) if transfer_function == '': name = 'Linear - {0}'.format(gamut) if gamut == '': name = 'Curve - {0}'.format(transfer_function) cs = ColorSpace(name) cs.description = name cs.aliases = aliases cs.equality_group = '' cs.family = 'Input/RED' cs.is_data = False # A linear space needs allocation variables if transfer_function == '': cs.allocation_type = ocio.Constants.ALLOCATION_LG2 cs.allocation_vars = [-8, 5, 0.00390625] def Cineon_to_linear(code_value): n_gamma = 0.6 black_point = 95 white_point = 685 code_value_to_density = 0.002 black_linear = pow(10, (black_point - white_point) * (code_value_to_density / n_gamma)) code_linear = pow(10, (code_value - white_point) * (code_value_to_density / n_gamma)) return (code_linear - black_linear) / (1 - black_linear) def Log3G10_to_linear(code_value): a = 0.224282 b = 155.975327 c = 0.01 normalized_log = code_value / 1023.0 mirror = 1.0 if normalized_log < 0.0: mirror = -1.0 normalized_log = -normalized_log linear = (pow(10.0, normalized_log / a) - 1) / b linear = linear * mirror - c return linear cs.to_reference_transforms = [] if transfer_function: if transfer_function == 'REDlogFilm': lut_name = "CineonLog" data = array.array('f', b'\0' * lut_resolution_1D * 4) for c in range(lut_resolution_1D): data[c] = Cineon_to_linear(1023 * c / (lut_resolution_1D - 1)) elif transfer_function == 'REDLog3G10': lut_name = "REDLog3G10" data = array.array('f', b'\0' * lut_resolution_1D * 4) for c in range(lut_resolution_1D): data[c] = Log3G10_to_linear(1023 * c / (lut_resolution_1D - 1)) lut = '{0}_to_linear.spi1d'.format(lut_name) genlut.write_SPI_1D(os.path.join(lut_directory, lut), 0, 1, data, lut_resolution_1D, 1) cs.to_reference_transforms.append({ 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', 'direction': 'forward' }) if gamut == 'DRAGONcolor': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.532279, 0.376648, 0.091073, 0.046344, 0.974513, -0.020860, -0.053976, -0.000320, 1.054267 ]), 'direction': 'forward' }) elif gamut == 'DRAGONcolor2': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.468452, 0.331484, 0.200064, 0.040787, 0.857658, 0.101553, -0.047504, -0.000282, 1.047756 ]), 'direction': 'forward' }) elif gamut == 'REDcolor': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.451464, 0.388498, 0.160038, 0.062716, 0.866790, 0.070491, -0.017541, 0.086921, 0.930590 ]), 'direction': 'forward' }) elif gamut == 'REDcolor2': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.480997, 0.402289, 0.116714, -0.004938, 1.000154, 0.004781, -0.105257, 0.025320, 1.079907 ]), 'direction': 'forward' }) elif gamut == 'REDcolor3': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.512136, 0.360370, 0.127494, 0.070377, 0.903884, 0.025737, -0.020824, 0.017671, 1.003123 ]), 'direction': 'forward' }) elif gamut == 'REDcolor4': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.474202, 0.333677, 0.192121, 0.065164, 0.836932, 0.097901, -0.019281, 0.016362, 1.002889 ]), 'direction': 'forward' }) elif gamut == 'REDWideGamutRGB': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33([ 0.785043, 0.083844, 0.131118, 0.023172, 1.087892, -0.111055, -0.073769, -0.314639, 1.388537 ]), 'direction': 'forward' }) cs.from_reference_transforms = [] return cs
def create_matrix_plus_transfer_colorspace( name='matrix_plus_transfer', transfer_function_name='transfer_function', transfer_function=lambda x: x, lut_directory='/tmp', lut_resolution_1D=1024, from_reference_values=None, to_reference_values=None, aliases=None): """ Creates a colorspace expressed as a single or multiple *MatrixTransform* and 1D LUT *FileTransform* transformations. Parameters ---------- name : str, optional Aliases for this colorspace. transfer_function_name : str, optional The name of the transfer function. transfer_function : function, optional The transfer function to be evaluated. lut_directory : str or unicode The directory to use when generating LUTs. lut_resolution_1D : int The resolution of generated 1D LUTs. from_reference_values : list of matrices List of matrices to convert from the reference colorspace to this colorspace. to_reference_values : list of matrices List of matrices to convert to the reference colorspace from this colorspace. aliases : list of str Aliases for this colorspace. Returns ------- ColorSpace A colorspace expressed as a single or multiple *MatrixTransform* and 1D LUT *FileTransform* transformations. """ if from_reference_values is None: from_reference_values = [] if to_reference_values is None: to_reference_values = [] if aliases is None: aliases = [] cs = ColorSpace(name) cs.description = 'The {0} color space'.format(name) cs.aliases = aliases cs.equality_group = name cs.family = 'Utility' cs.is_data = False # A linear space needs allocation variables. cs.allocation_type = ocio.Constants.ALLOCATION_UNIFORM cs.allocation_vars = [0, 1] # Sampling the transfer function. data = array.array('f', b'\0' * lut_resolution_1D * 4) for c in range(lut_resolution_1D): data[c] = transfer_function(c / (lut_resolution_1D - 1)) # Writing the sampled data to a *LUT*. lut = 'linear_to_{0}.spi1d'.format(transfer_function_name) genlut.write_SPI_1D(os.path.join(lut_directory, lut), 0, 1, data, lut_resolution_1D, 1) # Creating the *to_reference* transforms. cs.to_reference_transforms = [] if to_reference_values: cs.to_reference_transforms.append({ 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', 'direction': 'inverse' }) for matrix in to_reference_values: cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33(matrix), 'direction': 'forward' }) # Creating the *from_reference* transforms. cs.from_reference_transforms = [] if from_reference_values: for matrix in from_reference_values: cs.from_reference_transforms.append({ 'type': 'matrix', 'matrix': mat44_from_mat33(matrix), 'direction': 'forward' }) cs.from_reference_transforms.append({ 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', 'direction': 'forward' }) return cs
def create_CLog(gamut, transfer_function, lut_directory, lut_resolution_1D, aliases): """ Creates a colorspace covering the conversion from *CLog* to *ACES*, with various transfer functions and encoding gamuts covered. Parameters ---------- gamut : str The name of the encoding gamut to use. transfer_function : str The name of the transfer function to use lut_directory : str or unicode The directory to use when generating LUTs lut_resolution_1D : int The resolution of generated 1D LUTs aliases : list of str Aliases for this colorspace. Returns ------- ColorSpace A ColorSpace container class referencing the LUTs, matrices and identifying information for the requested colorspace. """ name = '{0} - {1}'.format(transfer_function, gamut) if transfer_function == '': name = 'Linear - Canon {0}'.format(gamut) if gamut == '': name = 'Curve - {0}'.format(transfer_function) cs = ColorSpace(name) cs.description = name cs.aliases = aliases cs.equality_group = '' cs.family = 'Input/Canon' cs.is_data = False # A linear space needs allocation variables. if transfer_function == '': cs.allocation_type = ocio.Constants.ALLOCATION_LG2 cs.allocation_vars = [-8, 5, 0.00390625] def legal_to_full(code_value): return (code_value - 64) / (940 - 64) def CLog_to_linear(code_value): # log = fullToLegal(c1 * log10(c2*linear + 1) + c3) # linear = (pow(10, (legalToFul(log) - c3)/c1) - 1)/c2 c1 = 0.529136 c2 = 10.1596 c3 = 0.0730597 linear = (pow(10, (legal_to_full(code_value) - c3) / c1) - 1) / c2 linear *= 0.9 return linear def CLog2_to_linear(code_value): # log = fullToLegal(c1 * log10(c2*linear + 1) + c3) # linear = (pow(10, (legalToFul(log) - c3)/c1) - 1)/c2 c1 = 0.281863093 c2 = 87.09937546 c3 = 0.035388128 linear = (pow(10, (legal_to_full(code_value) - c3) / c1) - 1) / c2 linear *= 0.9 return linear def CLog3_to_linear(code_value): # if(CLog3_ire < 0.04076162) # out = -( pow( 10, ( 0.07623209 - CLog3_ire ) / 0.42889912 ) # - 1 ) / 14.98325; # else if(CLog3_ire <= 0.105357102) # out = ( CLog3_ire - 0.073059361 ) / 2.3069815; # else # out = ( pow( 10, ( CLog3_ire - 0.069886632 ) / 0.42889912 ) # - 1 ) / 14.98325; c1 = 0.42889912 c2 = 14.98325 c3 = 0.069886632 c4 = 0.04076162 c5 = 0.07623209 c6 = 0.105357102 c7 = 0.073059361 c8 = 2.3069815 CLog3_ire = legal_to_full(code_value) if CLog3_ire < c4: linear = -(pow(10, (c5 - CLog3_ire) / c1) - 1) / c2 elif CLog3_ire <= c6: linear = (CLog3_ire - c7) / c8 else: linear = (pow(10, (CLog3_ire - c3) / c1) - 1) / c2 linear *= 0.9 return linear cs.to_reference_transforms = [] if transfer_function: if transfer_function == 'Canon-Log': data = array.array('f', b'\0' * lut_resolution_1D * 4) for c in range(lut_resolution_1D): data[c] = CLog_to_linear(1023 * c / (lut_resolution_1D - 1)) elif transfer_function == 'Canon-Log2': data = array.array('f', b'\0' * lut_resolution_1D * 4) for c in range(lut_resolution_1D): data[c] = CLog2_to_linear(1023 * c / (lut_resolution_1D - 1)) elif transfer_function == 'Canon-Log3': data = array.array('f', b'\0' * lut_resolution_1D * 4) for c in range(lut_resolution_1D): data[c] = CLog3_to_linear(1023 * c / (lut_resolution_1D - 1)) lut = '{0}_to_linear.spi1d'.format(transfer_function) genlut.write_SPI_1D(os.path.join(lut_directory, lut), 0, 1, data, lut_resolution_1D, 1) cs.to_reference_transforms.append({ 'type': 'lutFile', 'path': lut, 'interpolation': 'linear', 'direction': 'forward' }) if gamut == 'Rec. 709 Daylight': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': [ 0.561538969, 0.402060105, 0.036400926, 0, 0.092739623, 0.924121198, -0.016860821, 0, 0.084812961, 0.006373835, 0.908813204, 0, 0, 0, 0, 1 ], 'direction': 'forward' }) elif gamut == 'Rec. 709 Tungsten': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': [ 0.566996399, 0.365079418, 0.067924183, 0, 0.070901044, 0.880331008, 0.048767948, 0, 0.073013542, -0.066540862, 0.99352732, 0, 0, 0, 0, 1 ], 'direction': 'forward' }) elif gamut == 'DCI-P3 Daylight': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': [ 0.607160575, 0.299507286, 0.093332140, 0, 0.004968120, 1.050982224, -0.055950343, 0, -0.007839939, 0.000809127, 1.007030813, 0, 0, 0, 0, 1 ], 'direction': 'forward' }) elif gamut == 'DCI-P3 Tungsten': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': [ 0.650279125, 0.253880169, 0.095840706, 0, -0.026137986, 1.017900530, 0.008237456, 0, 0.007757558, -0.063081669, 1.055324110, 0, 0, 0, 0, 1 ], 'direction': 'forward' }) elif gamut == 'Cinema Gamut Daylight': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': [ 0.763064455, 0.149021161, 0.087914384, 0, 0.003657457, 1.10696038, -0.110617837, 0, -0.009407794, -0.218383305, 1.227791099, 0, 0, 0, 0, 1 ], 'direction': 'forward' }) elif gamut == 'Cinema Gamut Tungsten': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': [ 0.817416293, 0.090755698, 0.091828009, 0, -0.035361374, 1.065690585, -0.030329211, 0, 0.010390366, -0.299271107, 1.288880741, 0, 0, 0, 0, 1 ], 'direction': 'forward' }) elif gamut == 'Rec. 2020 Daylight': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': [ 0.678891151, 0.158868422, 0.162240427, 0, 0.045570831, 0.860712772, 0.093716397, 0, -0.000485710, 0.025060196, 0.975425515, 0, 0, 0, 0, 1 ], 'direction': 'forward' }) elif gamut == 'Rec. 2020 Tungsten': cs.to_reference_transforms.append({ 'type': 'matrix', 'matrix': [ 0.724488568, 0.115140904, 0.160370529, 0, 0.010659276, 0.839605344, 0.149735380, 0, 0.014560161, -0.028562057, 1.014001897, 0, 0, 0, 0, 1 ], 'direction': 'forward' }) cs.from_reference_transforms = [] return cs