Skip to content

Commit

Permalink
Implement support for "Python" 3 and "OpenImageIO" 2.
Browse files Browse the repository at this point in the history
Note that the order of the "ColorSpace"s is different because of changes in YamlCpp version.
  • Loading branch information
KelSolaar committed Jan 26, 2020
1 parent c281984 commit c3de77c
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 279 deletions.
470 changes: 235 additions & 235 deletions aces_1.2/config.ocio

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions aces_1.2/python/aces_ocio/colorspaces/aces.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import copy
import math
import numpy
import numpy as np
import os
import pprint
import shutil
Expand Down Expand Up @@ -474,7 +474,7 @@ def create_ADX(lut_directory, bit_depth=10, name='ADX'):
# Copied from *Alex Fry*'s *adx_cid_to_rle.py*
def create_CID_to_RLE_LUT():
def interpolate_1d(x, xp, fp):
return numpy.interp(x, xp, fp)
return np.interp(x, xp, fp)

LUT_1D_XP = [
-0.190000000000000, 0.010000000000000, 0.028000000000000,
Expand Down Expand Up @@ -1414,7 +1414,7 @@ def create_LMTs(aces_ctl_directory, lut_directory, lut_resolution_1D,
shaper_input_scale_generic_log2, lmt_params
]

sorted_lmts = sorted(iter(lmt_info.items()), key=lambda x: x[1])
sorted_lmts = sorted(lmt_info.items(), key=lambda x: tuple(x[1].items()))
print(sorted_lmts)
for lmt in sorted_lmts:
lmt_name, lmt_values = lmt
Expand Down Expand Up @@ -1692,7 +1692,7 @@ def create_output_transforms(aces_ctl_directory, lut_directory,
'48 nits', '4000 nits')]

sorted_output_transforms = sorted(
iter(output_transform_info.items()), key=lambda x: x[1])
iter(output_transform_info.items()), key=lambda x: tuple(x[1].items()))

for output_transform in sorted_output_transforms:
output_transform_name, output_transform_values = output_transform
Expand Down Expand Up @@ -1754,7 +1754,7 @@ def get_transform_info(ctl_transform):
Full / Legal switch and whether it is *SSTS* based.
"""

with open(ctl_transform, 'rb') as fp:
with open(ctl_transform, 'r') as fp:
lines = fp.readlines()

# Retrieving the *transform ID* and *User Name*.
Expand Down
2 changes: 1 addition & 1 deletion aces_1.2/python/aces_ocio/colorspaces/arri.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def normalized_LogC_to_linear(code_value, exposure_index):
cs.to_reference_transforms = []

if transfer_function == 'V3 LogC':
data = array.array('f', '\0' * lut_resolution_1D * 4)
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))
Expand Down
6 changes: 3 additions & 3 deletions aces_1.2/python/aces_ocio/colorspaces/canon.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ def CLog3_to_linear(code_value):

if transfer_function:
if transfer_function == 'Canon-Log':
data = array.array('f', '\0' * lut_resolution_1D * 4)
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', '\0' * lut_resolution_1D * 4)
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', '\0' * lut_resolution_1D * 4)
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))

Expand Down
4 changes: 2 additions & 2 deletions aces_1.2/python/aces_ocio/colorspaces/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def create_transfer_colorspace(name='transfer',
cs.allocation_vars = [0, 1]

# Sampling the transfer function.
data = array.array('f', '\0' * lut_resolution_1D * 4)
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))

Expand Down Expand Up @@ -246,7 +246,7 @@ def create_matrix_plus_transfer_colorspace(
cs.allocation_vars = [0, 1]

# Sampling the transfer function.
data = array.array('f', '\0' * lut_resolution_1D * 4)
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))

Expand Down
2 changes: 1 addition & 1 deletion aces_1.2/python/aces_ocio/colorspaces/gopro.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def Protune_to_linear(normalized_code_value):
cs.to_reference_transforms = []

if transfer_function == 'Protune Flat':
data = array.array('f', '\0' * lut_resolution_1D * 4)
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))

Expand Down
2 changes: 1 addition & 1 deletion aces_1.2/python/aces_ocio/colorspaces/panasonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def VLog_to_linear(x):
cs.to_reference_transforms = []

if transfer_function == 'V-Log':
data = array.array('f', '\0' * lut_resolution_1D * 4)
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))

Expand Down
4 changes: 2 additions & 2 deletions aces_1.2/python/aces_ocio/colorspaces/red.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ def Log3G10_to_linear(code_value):
if transfer_function:
if transfer_function == 'REDlogFilm':
lut_name = "CineonLog"
data = array.array('f', '\0' * lut_resolution_1D * 4)
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', '\0' * lut_resolution_1D * 4)
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))

Expand Down
6 changes: 3 additions & 3 deletions aces_1.2/python/aces_ocio/colorspaces/sony.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def SLog3_to_linear(code_value):
cs.to_reference_transforms = []

if transfer_function == 'S-Log1':
data = array.array('f', '\0' * lut_resolution_1D * 4)
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))

Expand All @@ -130,7 +130,7 @@ def SLog3_to_linear(code_value):
'direction': 'forward'
})
elif transfer_function == 'S-Log2':
data = array.array('f', '\0' * lut_resolution_1D * 4)
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))

Expand All @@ -145,7 +145,7 @@ def SLog3_to_linear(code_value):
'direction': 'forward'
})
elif transfer_function == 'S-Log3':
data = array.array('f', '\0' * lut_resolution_1D * 4)
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))

Expand Down
4 changes: 2 additions & 2 deletions aces_1.2/python/aces_ocio/generate_comparison_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ def generate_comparison_images(aces_ctl_directory,
if specific_odts and odt_name not in specific_odts:
continue

print('')
print('\n')
print('Output Transform - {0}'.format(odt_name))
print('')
print('\n')

# Forward Output Transform
# Generate difference images for the forward Output Transform
Expand Down
26 changes: 14 additions & 12 deletions aces_1.2/python/aces_ocio/generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from __future__ import division

import copy
import functools
import optparse
import os
import shutil
Expand All @@ -24,7 +25,7 @@
from aces_ocio.process import Process

from aces_ocio.utilities import (ColorSpace, colorspace_prefixed_name, compact,
replace, unpack_default)
replace, unpack_default, cmp)

__author__ = 'ACES Developers'
__copyright__ = 'Copyright (C) 2014 - 2016 - ACES Developers'
Expand Down Expand Up @@ -422,7 +423,7 @@ def add_look(config, look, custom_lut_dir, reference_name, config_data):

config_data['colorSpaces'].append(colorspace)

print('')
print('\n')


def add_looks_to_views(looks,
Expand Down Expand Up @@ -624,7 +625,7 @@ def add_custom_output(custom_output,
print('Making {0} the default Display'.format(custom_output_name))
config_data['defaultDisplay'] = custom_output_name

print('')
print('\n')


def create_config(config_data,
Expand Down Expand Up @@ -720,7 +721,7 @@ def create_config(config_data,
alias_colorspaces.append(
[reference_data, reference_data, reference_data.aliases])

print('')
print('\n')

if look_info:
print('Adding looks')
Expand All @@ -734,7 +735,7 @@ def create_config(config_data,
add_looks_to_views(look_info, reference_data.name, config_data,
multiple_displays)

print('')
print('\n')

if custom_output_info:
print('Adding custom output transforms')
Expand All @@ -743,13 +744,14 @@ def create_config(config_data,
add_custom_output(custom_output, custom_lut_dir, reference_data,
config_data)

print('')
print('\n')

print('Adding regular colorspaces')

for colorspace in sorted(
config_data['colorSpaces'],
cmp=lambda x, y: cmp(x.family.lower(), y.family.lower())):
key=functools.cmp_to_key(
lambda x, y: cmp(x.family.lower(), y.family.lower()))):
# Adding the colorspace *Family* into the name which helps with
# applications that present colorspaces as one a flat list.
if prefix:
Expand Down Expand Up @@ -799,9 +801,9 @@ def create_config(config_data,
alias_colorspaces.append(
[reference_data, colorspace, colorspace.aliases])

print('')
print('\n')

print('')
print('\n')

# Adding roles early so that alias colorspaces can be created
# with roles names before remaining colorspace aliases are added
Expand Down Expand Up @@ -903,7 +905,7 @@ def create_config(config_data,
add_colorspace_aliases(config, reference_data, role_colorspace,
[role_name_alias2], 'Utility/Roles')

print('')
print('\n')

# Adding alias colorspaces at the end as some applications use
# colorspaces definitions order of the configuration to order
Expand All @@ -916,7 +918,7 @@ def create_config(config_data,
add_colorspace_aliases(config, reference, colorspace, aliases,
'Utility/Aliases')

print('')
print('\n')

print('Adding the diplays and views')

Expand Down Expand Up @@ -1042,7 +1044,7 @@ def create_config(config_data,
config.setActiveDisplays(','.join(sorted(displays)))
config.setActiveViews(','.join(views))

print('')
print('\n')

# Ensuring the configuration is valid.
config.sanityCheck()
Expand Down
23 changes: 18 additions & 5 deletions aces_1.2/python/aces_ocio/generate_lut.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from __future__ import division

import array
import numpy as np
import os
import re

Expand Down Expand Up @@ -77,18 +78,18 @@ def generate_1D_LUT_image(ramp_1d_path,
spec.height = 1
spec.nchannels = 3

ramp.open(ramp_1d_path, spec, oiio.Create)
ramp.open(ramp_1d_path, spec)

data = array.array('f',
'\0' * spec.width * spec.height * spec.nchannels * 4)
b'\0' * spec.width * spec.height * spec.nchannels * 4)
for i in range(resolution):
value = float(i) / (resolution - 1) * (
max_value - min_value) + min_value
data[i * spec.nchannels + 0] = value
data[i * spec.nchannels + 1] = value
data[i * spec.nchannels + 2] = value

ramp.write_image(spec.format, data)
ramp.write_image(data)
ramp.close()


Expand Down Expand Up @@ -123,6 +124,10 @@ def write_SPI_1D(filename,
The number of channels in the data to actually write.
"""

data = np.squeeze(data)
if data.ndim == 1:
data = data[..., np.newaxis]

# May want to use fewer components than there are channels in the data
# Most commonly used for single channel LUTs
components = min(3, components, channels)
Expand All @@ -136,7 +141,7 @@ def write_SPI_1D(filename,
for i in range(0, entries):
entry = ''
for j in range(0, components):
entry = '{0} {1:.10e}'.format(entry, data[i * channels + j])
entry = '{0} {1:.10e}'.format(entry, data[i, j])
fp.write('{0}\n'.format(entry))
fp.write('}\n')

Expand Down Expand Up @@ -169,6 +174,10 @@ def write_CSP_1D(filename,
The number of channels in the data to actually write.
"""

data = np.squeeze(data)
if data.ndim == 1:
data = data[..., np.newaxis]

# May want to use fewer components than there are channels in the data
# Most commonly used for single channel LUTs
components = min(3, components, channels)
Expand Down Expand Up @@ -239,6 +248,10 @@ def write_CTL_1D(filename,
The number of channels in the data to actually write.
"""

data = np.squeeze(data)
if data.ndim == 1:
data = data[..., np.newaxis]

# May want to use fewer components than there are channels in the data
# Most commonly used for single channel LUTs
components = min(3, components, channels)
Expand Down Expand Up @@ -745,7 +758,7 @@ def correct_LUT_image(transformed_lut_image, corrected_lut_image,
correct.open(corrected_lut_image, correct_spec, oiio.Create)

dest_data = array.array(
'f', ('\0' * correct_spec.width * correct_spec.height *
'f', (b'\0' * correct_spec.width * correct_spec.height *
correct_spec.nchannels * 4))
for j in range(0, correct_spec.height):
for i in range(0, correct_spec.width):
Expand Down
Loading

0 comments on commit c3de77c

Please sign in to comment.