X-Git-Url: http://users.mur.at/ms/git/gitweb/?p=OpenColorIO-Configs.git;a=blobdiff_plain;f=aces_1.0.0%2Fpython%2Faces_ocio%2Fgenerate_lut.py;h=f94bf34efa2b600041727f3a54806a73e2e6d03d;hp=66a0d6e8f2b1ea2bd54194050888673c28c69f7d;hb=0343914c3673898a5b2356eb37eded81e47ae02a;hpb=cc938ac1df50558dfc72eecf934c820660357f34 diff --git a/aces_1.0.0/python/aces_ocio/generate_lut.py b/aces_1.0.0/python/aces_ocio/generate_lut.py index 66a0d6e..f94bf34 100755 --- a/aces_1.0.0/python/aces_ocio/generate_lut.py +++ b/aces_1.0.0/python/aces_ocio/generate_lut.py @@ -78,12 +78,12 @@ def generate_1d_LUT_image(ramp_1d_path, ramp.close() -def write_SPI_1d(filename, - from_min, - from_max, - data, - entries, - channels, +def write_SPI_1d(filename, + from_min, + from_max, + data, + entries, + channels, components=3): """ Object description. @@ -120,12 +120,12 @@ def write_SPI_1d(filename, fp.write('}\n') -def write_CSP_1d(filename, - from_min, - from_max, - data, - entries, - channels, +def write_CSP_1d(filename, + from_min, + from_max, + data, + entries, + channels, components=3): """ Object description. @@ -168,25 +168,26 @@ def write_CSP_1d(filename, fp.write('%d\n' % entries) if components == 1: - for i in range(0, entries): - entry = '' - for j in range(3): - entry = '%s %s' % (entry, data[i * channels]) - fp.write('%s\n' % entry) + for i in range(0, entries): + entry = '' + for j in range(3): + entry = '%s %s' % (entry, data[i * channels]) + fp.write('%s\n' % entry) else: - for i in range(entries): - entry = '' - for j in range(components): - entry = '%s %s' % (entry, data[i * channels + j]) - fp.write('%s\n' % entry) + for i in range(entries): + entry = '' + for j in range(components): + entry = '%s %s' % (entry, data[i * channels + j]) + fp.write('%s\n' % entry) fp.write('\n') -def write_CTL_1d(filename, - from_min, - from_max, - data, - entries, - channels, + +def write_CTL_1d(filename, + from_min, + from_max, + data, + entries, + channels, components=3): """ Object description. @@ -208,7 +209,7 @@ def write_CTL_1d(filename, with open(filename, 'w') as fp: fp.write('// %d x %d LUT generated by "generate_lut"\n' % ( - entries, components)) + entries, components)) fp.write('\n') fp.write('const float min1d = %3.9f;\n' % from_min) fp.write('const float max1d = %3.9f;\n' % from_max) @@ -216,24 +217,24 @@ def write_CTL_1d(filename, # Write LUT if components == 1: - fp.write('const float lut[] = {\n') - for i in range(0, entries): - fp.write('%s' % data[i * channels]) - if i != (entries-1): - fp.write(',') - fp.write('\n') - fp.write('};\n') - fp.write('\n') - else: - for j in range(components): - fp.write('const float lut%d[] = {\n' % j) + fp.write('const float lut[] = {\n') for i in range(0, entries): fp.write('%s' % data[i * channels]) - if i != (entries-1): - fp.write(',') + if i != (entries - 1): + fp.write(',') fp.write('\n') fp.write('};\n') fp.write('\n') + else: + for j in range(components): + fp.write('const float lut%d[] = {\n' % j) + for i in range(0, entries): + fp.write('%s' % data[i * channels]) + if i != (entries - 1): + fp.write(',') + fp.write('\n') + fp.write('};\n') + fp.write('\n') fp.write('void main\n') fp.write('(\n') @@ -253,13 +254,13 @@ def write_CTL_1d(filename, fp.write('\n') fp.write(' // Apply LUT\n') if components == 1: - fp.write(' r = lookup1D(lut, min1d, max1d, r);\n') - fp.write(' g = lookup1D(lut, min1d, max1d, g);\n') - fp.write(' b = lookup1D(lut, min1d, max1d, b);\n') + fp.write(' r = lookup1D(lut, min1d, max1d, r);\n') + fp.write(' g = lookup1D(lut, min1d, max1d, g);\n') + fp.write(' b = lookup1D(lut, min1d, max1d, b);\n') elif components == 3: - fp.write(' r = lookup1D(lut0, min1d, max1d, r);\n') - fp.write(' g = lookup1D(lut1, min1d, max1d, g);\n') - fp.write(' b = lookup1D(lut2, min1d, max1d, b);\n') + fp.write(' r = lookup1D(lut0, min1d, max1d, r);\n') + fp.write(' g = lookup1D(lut1, min1d, max1d, g);\n') + fp.write(' b = lookup1D(lut2, min1d, max1d, b);\n') fp.write('\n') fp.write(' rOut = r;\n') fp.write(' gOut = g;\n') @@ -267,12 +268,13 @@ def write_CTL_1d(filename, fp.write(' aOut = aIn;\n') fp.write('}\n') -def write_1d(filename, - from_min, - from_max, - data, - data_entries, - data_channels, + +def write_1d(filename, + from_min, + from_max, + data, + data_entries, + data_channels, lut_components=3, format='spi1d'): """ @@ -289,38 +291,39 @@ def write_1d(filename, Return value description. """ - ocioFormatsToExtensions = {'cinespace' : 'csp', - 'flame' : '3dl', - 'icc' : 'icc', - 'houdini' : 'lut', - 'lustre' : '3dl', - 'ctl' : 'ctl'} + ocioFormatsToExtensions = {'cinespace': 'csp', + 'flame': '3dl', + 'icc': 'icc', + 'houdini': 'lut', + 'lustre': '3dl', + 'ctl': 'ctl'} if format in ocioFormatsToExtensions: - if ocioFormatsToExtensions[format] == 'csp': - write_CSP_1d(filename, - from_min, - from_max, - data, - data_entries, - data_channels, - lut_components) - elif ocioFormatsToExtensions[format] == 'ctl': - write_CTL_1d(filename, + if ocioFormatsToExtensions[format] == 'csp': + write_CSP_1d(filename, + from_min, + from_max, + data, + data_entries, + data_channels, + lut_components) + elif ocioFormatsToExtensions[format] == 'ctl': + write_CTL_1d(filename, + from_min, + from_max, + data, + data_entries, + data_channels, + lut_components) + else: + write_SPI_1d(filename, from_min, from_max, data, data_entries, data_channels, lut_components) - else: - write_SPI_1d(filename, - from_min, - from_max, - data, - data_entries, - data_channels, - lut_components) + def generate_1d_LUT_from_image(ramp_1d_path, output_path=None, @@ -356,8 +359,8 @@ def generate_1d_LUT_from_image(ramp_1d_path, type = oiio.FLOAT ramp_data = ramp.read_image(type) - write_1d(output_path, min_value, max_value, - ramp_data, ramp_width, ramp_channels, channels, format) + write_1d(output_path, min_value, max_value, + ramp_data, ramp_width, ramp_channels, channels, format) def generate_3d_LUT_image(ramp_3d_path, resolution=32): @@ -388,8 +391,8 @@ def generate_3d_LUT_image(ramp_3d_path, resolution=32): lut_extract.execute() -def generate_3d_LUT_from_image(ramp_3d_path, - output_path=None, +def generate_3d_LUT_from_image(ramp_3d_path, + output_path=None, resolution=32, format='spi3d'): """ @@ -409,56 +412,56 @@ def generate_3d_LUT_from_image(ramp_3d_path, if output_path is None: output_path = '%s.%s' % (ramp_3d_path, 'spi3d') - ocioFormatsToExtensions = {'cinespace' : 'csp', - 'flame' : '3dl', - 'icc' : 'icc', - 'houdini' : 'lut', - 'lustre' : '3dl'} + ocioFormatsToExtensions = {'cinespace': 'csp', + 'flame': '3dl', + 'icc': 'icc', + 'houdini': 'lut', + 'lustre': '3dl'} if format == 'spi3d' or not (format in ocioFormatsToExtensions): - # Extract a spi3d LUT - args = ['--extract', - '--cubesize', - str(resolution), - '--maxwidth', - str(resolution * resolution), - '--input', - ramp_3d_path, - '--output', - output_path] - lut_extract = Process(description='extract a 3d LUT', - cmd='ociolutimage', - args=args) - lut_extract.execute() + # Extract a spi3d LUT + args = ['--extract', + '--cubesize', + str(resolution), + '--maxwidth', + str(resolution * resolution), + '--input', + ramp_3d_path, + '--output', + output_path] + lut_extract = Process(description='extract a 3d LUT', + cmd='ociolutimage', + args=args) + lut_extract.execute() else: - output_path_spi3d = '%s.%s' % (output_path, 'spi3d') - - # Extract a spi3d LUT - args = ['--extract', - '--cubesize', - str(resolution), - '--maxwidth', - str(resolution * resolution), - '--input', - ramp_3d_path, - '--output', - output_path_spi3d] - lut_extract = Process(description='extract a 3d LUT', - cmd='ociolutimage', - args=args) - lut_extract.execute() - - # Convert to a different format - args = ['--lut', - output_path_spi3d, - '--format', - format, - output_path] - lut_convert = Process(description='convert a 3d LUT', - cmd='ociobakelut', - args=args) - lut_convert.execute() + output_path_spi3d = '%s.%s' % (output_path, 'spi3d') + + # Extract a spi3d LUT + args = ['--extract', + '--cubesize', + str(resolution), + '--maxwidth', + str(resolution * resolution), + '--input', + ramp_3d_path, + '--output', + output_path_spi3d] + lut_extract = Process(description='extract a 3d LUT', + cmd='ociolutimage', + args=args) + lut_extract.execute() + + # Convert to a different format + args = ['--lut', + output_path_spi3d, + '--format', + format, + output_path] + lut_convert = Process(description='convert a 3d LUT', + cmd='ociobakelut', + args=args) + lut_convert.execute() def apply_CTL_to_image(input_image, @@ -739,9 +742,9 @@ def generate_3d_LUT_from_CTL(lut_path, corrected_LUT_image, lut_resolution) - generate_3d_LUT_from_image(corrected_LUT_image, - lut_path, - lut_resolution, + generate_3d_LUT_from_image(corrected_LUT_image, + lut_path, + lut_resolution, format) if cleanup: @@ -755,6 +758,7 @@ def generate_3d_LUT_from_CTL(lut_path, lut_path_spi3d = '%s.%s' % (lut_path, 'spi3d') os.remove(lut_path_spi3d) + def main(): """ Object description.