Skip to content

Commit

Permalink
Merge branch 'feature/v0.3.12' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Nov 30, 2018
2 parents a0ef929 + b6c26f2 commit 6fa3189
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 32 deletions.
14 changes: 14 additions & 0 deletions BIBLIOGRAPHY.bib
Expand Up @@ -648,6 +648,14 @@ @misc{DigitalCinemaInitiatives2007b
url = {http://www.dcimovies.com/archives/spec_v1_1/DCI_DCinema_System_Spec_v1_1.pdf},
year = {2007}
}
@misc{DJI2017,
author = {Dji},
file = {:Users/kelsolaar/Google Drive/Documents/Mendeley Desktop/Dji - 2017 - White Paper on D-Log and D-Gamut of DJI Cinema Color System.pdf:pdf},
pages = {1--5},
title = {{White Paper on D-Log and D-Gamut of DJI Cinema Color System}},
url = {https://dl.djicdn.com/downloads/zenmuse+x7/20171010/D-Log_D-Gamut_Whitepaper.pdf},
year = {2017}
}
@misc{Dolby2016a,
author = {Dolby},
file = {:Users/kelsolaar/Google Drive/Documents/Mendeley Desktop/Dolby - 2016 - WHAT IS ICTCP - INTRODUCTION.pdf:pdf},
Expand Down Expand Up @@ -1693,6 +1701,12 @@ @misc{RenewableResourceDataCenter2003a
urldate = {2014-08-23},
year = {2003}
}
@misc{RisingSunResearch,
author = {{Rising Sun Research}},
title = {{cineSpace LUT Library}},
url = {https://sourceforge.net/projects/cinespacelutlib/},
urldate = {2018-11-30}
}
@misc{Saeedna,
author = {Saeedn},
title = {{Extend a line segment a specific distance}},
Expand Down
39 changes: 19 additions & 20 deletions colour/io/luts/__init__.py
Expand Up @@ -5,9 +5,12 @@
- :cite:`AdobeSystems2013b` : Adobe Systems. (2013). Cube LUT Specification.
Retrieved from https://drive.google.com/\
open?id=143Eh08ZYncCAMwJ1q4gWxVOqR_OSWYvs
- :cite:`Chamberlain2015` :Chamberlain, P. (2015). LUT documentation
- :cite:`Chamberlain2015` :Chamberlain, P. (2015). LUT documentation
(to create from another program). Retrieved August 23, 2018, from
https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=40284#p232952
- :cite:`RisingSunResearch` : Rising Sun Research. (n.d.). cineSpace LUT
Library. Retrieved November 30, 2018, from
https://sourceforge.net/projects/cinespacelutlib/
"""

from __future__ import absolute_import
Expand Down Expand Up @@ -47,11 +50,11 @@
"""

LUT_READ_METHODS = CaseInsensitiveMapping({
'Cinespace': read_LUT_Cinespace,
'Iridas Cube': read_LUT_IridasCube,
'Resolve Cube': read_LUT_ResolveCube,
'Sony SPI1D': read_LUT_SonySPI1D,
'Sony SPI3D': read_LUT_SonySPI3D,
'Cinespace': read_LUT_Cinespace,
})
LUT_READ_METHODS.__doc__ = """
Supported *LUT* reading methods.
Expand All @@ -61,11 +64,8 @@
:cite:`AdobeSystems2013b`, :cite:`Chamberlain2015`
LUT_READ_METHODS : CaseInsensitiveMapping
**{'Iridas Cube',
'Resolve Cube',
'Sony SPI1D',
'Sony SPI3D',
'Cinespace'}**
**{'Cinespace', 'Iridas Cube', 'Resolve Cube', 'Sony SPI1D',
'Sony SPI3D'}**
"""


Expand All @@ -78,9 +78,9 @@ def read_LUT(path, method=None, **kwargs):
path : unicode
*LUT* path.
method : unicode, optional
**{None, 'Iridas Cube', 'Resolve Cube', 'Sony SPI1D', 'Sony SPI3D'}**,
Reading method, if *None*, the method will be auto-detected according
to extension.
**{None, 'Cinespace', 'Iridas Cube', 'Resolve Cube', 'Sony SPI1D',
'Sony SPI3D'}**, Reading method, if *None*, the method will be
auto-detected according to extension.
Returns
-------
Expand All @@ -89,7 +89,8 @@ def read_LUT(path, method=None, **kwargs):
References
----------
:cite:`AdobeSystems2013b`, :cite:`Chamberlain2015`
:cite:`AdobeSystems2013b`, :cite:`Chamberlain2015`,
:cite:`RisingSunResearch`
Examples
--------
Expand Down Expand Up @@ -161,11 +162,8 @@ def read_LUT(path, method=None, **kwargs):
:cite:`AdobeSystems2013b`, :cite:`Chamberlain2015`
LUT_WRITE_METHODS : CaseInsensitiveMapping
**{'Iridas Cube',
'Resolve Cube',
'Sony SPI1D',
'Sony SPI3D'
'Cinespace'}**
**{'Cinespace', 'Iridas Cube', 'Resolve Cube', 'Sony SPI1D',
'Sony SPI3D'}**
"""


Expand All @@ -183,9 +181,9 @@ def write_LUT(LUT, path, decimals=7, method=None, **kwargs):
decimals : int, optional
Formatting decimals.
method : unicode, optional
**{None, 'Iridas Cube', 'Resolve Cube', 'Sony SPI1D', 'Sony SPI3D'}**,
Writing method, if *None*, the method will be auto-detected according
to extension.
**{None, 'Cinespace', 'Iridas Cube', 'Resolve Cube', 'Sony SPI1D',
'Sony SPI3D'}**, Writing method, if *None*, the method will be
auto-detected according to extension.
Returns
-------
Expand All @@ -194,7 +192,8 @@ def write_LUT(LUT, path, decimals=7, method=None, **kwargs):
References
----------
:cite:`AdobeSystems2013b`, :cite:`Chamberlain2015`
:cite:`AdobeSystems2013b`, :cite:`Chamberlain2015`,
:cite:`RisingSunResearch`
Examples
--------
Expand Down
51 changes: 41 additions & 10 deletions colour/io/luts/cinespace_csp.py
Expand Up @@ -6,11 +6,14 @@
Defines *Cinespace* *.csp* *LUT* Format related input / output utilities
objects.
- :func:`colour.io.read_LUT_Cinespace`
- :func:`colour.io.write_LUT_Cinespace`
References
----------
- :cite: https://sourceforge.net/p/cinespacelutlib/code/HEAD/tree/trunk/
- :cite:`RisingSunResearch` : Rising Sun Research. (n.d.). cineSpace LUT
Library. Retrieved November 30, 2018, from
https://sourceforge.net/projects/cinespacelutlib/
"""

from __future__ import division, unicode_literals
Expand Down Expand Up @@ -48,6 +51,10 @@ def read_LUT_Cinespace(path):
:class:`LUT2D` or :class:`LUT3D` or :class:`LUTSequence` class
instance.
References
----------
:cite:`RisingSunResearch`
Examples
--------
Reading a 2D *Cinespace* *.csp* *LUT*:
Expand Down Expand Up @@ -96,12 +103,14 @@ def _parse_metadata_section(lines):
else:
title = ''
comments = []

return title, comments

def _parse_domain_section(lines):
preLUT_size = max([int(lines[i]) for i in [0, 3, 6]])
preLUT = [_parse_array(lines[i].split()) for i in [1, 2, 4, 5, 7, 8]]
preLUT_padded = []

for row in preLUT:
if len(row) != preLUT_size:
preLUT_padded.append(
Expand All @@ -112,11 +121,13 @@ def _parse_domain_section(lines):
else:
preLUT_padded.append(row)
preLUT = np.asarray(preLUT_padded)

return preLUT

def _parse_table_section(lines):
size = _parse_array(lines[0].split()).astype(int)
table = np.array([_parse_array(line.split()) for line in lines[1:]])

return size, table

with open(path) as csp_file:
Expand Down Expand Up @@ -174,6 +185,7 @@ def _parse_table_section(lines):
name=title,
comments=comments,
table=table)

return LUT

if is_3D:
Expand All @@ -184,11 +196,13 @@ def _parse_table_section(lines):
table = table.reshape((size[0], size[1], size[2], 3), order='F')
LUT_A = LUT2D(pre_table, shaper_name, pre_domain)
LUT_B = LUT3D(table, cube_name, comments=comments)

return LUTSequence(LUT_A, LUT_B)

if not is_3D:
pre_domain = tstack((preLUT[0], preLUT[2], preLUT[4]))
pre_table = tstack((preLUT[1], preLUT[3], preLUT[5]))

if np.array_equal(table, unity_range):
return LUT2D(pre_table, title, pre_domain, comments=comments)
elif table.shape == (2, 3):
Expand All @@ -202,6 +216,7 @@ def _parse_table_section(lines):
table_name = '{0} - table'.format(title)
LUT_A = LUT2D(pre_table, pre_name, pre_domain)
LUT_B = LUT2D(table, table_name, comments=comments)

return LUTSequence(LUT_A, LUT_B)


Expand All @@ -224,6 +239,10 @@ def write_LUT_Cinespace(LUT, path, decimals=7):
bool
Definition success.
References
----------
:cite:`RisingSunResearch`
Examples
--------
Writing a 2D *Cinespace* *.csp* *LUT*:
Expand Down Expand Up @@ -253,8 +272,8 @@ def write_LUT_Cinespace(LUT, path, decimals=7):
if isinstance(LUT, LUTSequence):
assert (len(LUT) == 2 and
(isinstance(LUT[0], LUT1D) or isinstance(LUT[0], LUT2D)) and
isinstance(LUT[1], LUT3D)), \
'LUTSequence must be 1D+3D or 2D+3D!'
isinstance(LUT[1],
LUT3D)), ('LUTSequence must be 1D+3D or 2D+3D!')
has_2D = True
has_3D = True
name = LUT[1].name
Expand Down Expand Up @@ -284,16 +303,21 @@ def write_LUT_Cinespace(LUT, path, decimals=7):
assert False, 'LUT must be 1D, 2D, 3D, 1D+3D or 2D+3D!'

if has_2D:
assert 2 <= LUT[0].size <= 65536, \
'Shaper size must be in domain [2, 65536]!'
assert 2 <= LUT[0].size <= 65536, (
'Shaper size must be in domain [2, 65536]!')
if has_3D:
assert 2 <= LUT[1].size <= 256, 'Cube size must be in domain [2, 256]!'

def _ragged_size(table):
"""
Return the ragged size of given table.
"""

r, g, b = tsplit(table)
r_len = r.shape[-1] - np.sum(np.isnan(r))
g_len = g.shape[-1] - np.sum(np.isnan(g))
b_len = b.shape[-1] - np.sum(np.isnan(b))

return [r_len, g_len, b_len]

def _format_array(array):
Expand Down Expand Up @@ -340,7 +364,9 @@ def _format_tuple(array):
table_max = np.nanmax(LUT[0].table)
else:
size = LUT[0].size

csp_file.write('{0}\n'.format(size))

for j in range(size):
if LUT[0].is_domain_explicit():
entry = LUT[0].domain[j][i]
Expand All @@ -350,33 +376,37 @@ def _format_tuple(array):
(LUT[0].domain[1][i] - LUT[0].domain[0][i]) /
(LUT[0].size - 1))
csp_file.write('{0:.{1}f} '.format(entry, decimals))

csp_file.write('\n')

for j in range(size):
entry = LUT[0].table[j][i]
if non_uniform:
entry -= table_min
entry /= (table_max - table_min)
csp_file.write('{0:.{1}f} '.format(entry, decimals))

csp_file.write('\n')
else:
for i in range(3):
csp_file.write('2\n')
csp_file.write('{0}\n'.format(
_format_tuple(
[LUT[1].domain[0][i], LUT[1].domain[1][i]])))
csp_file.write(
'{0:.{2}f} {1:.{2}f}\n'.format(0, 1, decimals))
csp_file.write('{0:.{2}f} {1:.{2}f}\n'.format(
0, 1, decimals))
if non_uniform:
csp_file.write('\n{0}\n'.format(2))
row = [table_min, table_min, table_min]
csp_file.write('{0}\n'.format(_format_array(row)))
row = [table_max, table_max, table_max]
csp_file.write('{0}\n'.format(_format_array(row)))
else:
csp_file.write(
'\n{0} {1} {2}\n'.format(LUT[1].table.shape[0], LUT[
1].table.shape[1], LUT[1].table.shape[2]))
csp_file.write('\n{0} {1} {2}\n'.format(
LUT[1].table.shape[0], LUT[1].table.shape[1],
LUT[1].table.shape[2]))
table = LUT[1].table.reshape((-1, 3), order='F')

for row in table:
csp_file.write('{0}\n'.format(_format_array(row)))

Expand All @@ -388,6 +418,7 @@ def _format_tuple(array):
csp_file.write('0.0 1.0\n')
csp_file.write('\n{0}\n'.format(LUT[0].size))
table = LUT[0].table

for row in table:
csp_file.write('{0}\n'.format(_format_array(row)))

Expand Down
2 changes: 0 additions & 2 deletions colour/utilities/verbose.py
Expand Up @@ -19,8 +19,6 @@
from textwrap import TextWrapper
from warnings import filterwarnings, formatwarning, warn

from colour.utilities.documentation import DocstringInt

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2013-2018 - Colour Developers'
__license__ = 'New BSD License - http://opensource.org/licenses/BSD-3-Clause'
Expand Down
2 changes: 2 additions & 0 deletions docs/colour.io.rst
Expand Up @@ -55,6 +55,8 @@ Look Up Table (LUT) Data

AbstractLUTSequenceOperator
LUT_to_LUT
read_LUT_Cinespace
write_LUT_Cinespace
read_LUT_IridasCube
write_LUT_IridasCube
read_LUT_SonySPI1D
Expand Down

0 comments on commit 6fa3189

Please sign in to comment.