Skip to content
This repository was archived by the owner on Nov 22, 2019. It is now read-only.

Commit 46d4fa9

Browse files
author
mfe
committed
Merge branch 'feature/add_pre_post_lut' into develop
2 parents cae8735 + cb40ee0 commit 46d4fa9

File tree

5 files changed

+210
-107
lines changed

5 files changed

+210
-107
lines changed

plotThatLut/README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,8 @@ Tested config
2323

2424
Command line usage
2525
-----
26-
* Dispay a cube (17 segments) for 3D LUTs and matrixes or a curve (256 points) for 1D/2D LUTs :
27-
`plot_that_lut.py < path to a LUT >`
28-
29-
* Display a curve with x points (default value : 256) :
30-
`plot_that_lut.py < path to a LUT > curve [points count]`
31-
32-
* Display a cube with x segments (default value : 17) :
33-
`plot_that_lut.py < path to a LUT > cube [cube size]`
26+
See command line help :
27+
`ptlut.py -h`
3428

3529
Web app usage
3630
-------------
@@ -48,4 +42,4 @@ Screenshots
4842

4943
![Rec709 1D](https://dl.dropboxusercontent.com/u/2979643/Rec709_1D_LUT.png "Rec709 1D")
5044

51-
![Web app](https://dl.dropboxusercontent.com/u/2979643/PlotThatLUT_webapp.png "Web app")
45+
![Web app](https://dl.dropboxusercontent.com/u/2979643/PlotThatLUT_webapp2.png "Web app")

plotThatLut/css/style.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ a:active {color: #666;} /* selected link */
2828
line-height:40px;
2929
}
3030

31-
3231
#content {
3332
width: 640px;
3433
height: 600px;
@@ -38,4 +37,15 @@ a:active {color: #666;} /* selected link */
3837
left: 0;
3938
right: 0;
4039
margin: auto;
40+
}
41+
42+
#advanced {
43+
background-color: #eee;
44+
padding-left: 10px;
45+
padding-top: 5px;
46+
padding-bottom: 5px;
47+
}
48+
49+
input[type="file"] {
50+
width: 80%
4151
}

plotThatLut/plot_that_lut.py

Lines changed: 52 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88

99
## imports
1010
import os
11-
import sys
1211
# OpenColorIO
13-
from PyOpenColorIO import Config, ColorSpace, FileTransform
14-
from PyOpenColorIO.Constants import INTERP_LINEAR, COLORSPACE_DIR_TO_REFERENCE
12+
from PyOpenColorIO import (
13+
Config, ColorSpace, FileTransform, GroupTransform,
14+
)
15+
from PyOpenColorIO.Constants import (
16+
INTERP_LINEAR, COLORSPACE_DIR_TO_REFERENCE,
17+
TRANSFORM_DIR_FORWARD, TRANSFORM_DIR_INVERSE,
18+
)
1519
# matplotlib
1620
import matplotlib
1721

1822

19-
cherry_py_mode = True
23+
web_mode = False
2024

2125

2226
class PlotThatLutException(Exception):
@@ -26,11 +30,11 @@ class PlotThatLutException(Exception):
2630
def set_matplotlib_backend():
2731
""" Select display backend
2832
29-
.. todo:: Externalize this and remove cherry_py_mode global var
33+
.. todo:: Externalize this and remove web_mode global var
3034
3135
"""
3236

33-
if cherry_py_mode:
37+
if web_mode:
3438
matplotlib.use('Agg')
3539
else:
3640
matplotlib.use('Qt4Agg')
@@ -52,26 +56,24 @@ def show_plot(fig, filename):
5256
5357
Returns:
5458
str.
55-
if in cherrypy mode, an html string,
59+
if in web mode, an html string,
5660
else a void string.
5761
5862
"""
59-
if cherry_py_mode:
63+
if web_mode:
6064
split_filename = os.path.splitext(filename)
6165
filename = '{0}{1}'.format(split_filename[0],
6266
split_filename[1].replace(".", "_"))
6367
export_path = 'img/export_{0}.png'.format(filename)
6468
fig.savefig(export_path)
65-
return (
66-
'<img src="/{0}" width="640" height="480"'
67-
'border="0"/>'
68-
).format(export_path)
69+
return export_path
6970
else:
7071
matplotlib.pyplot.show()
7172
return ""
7273

7374

74-
def create_ocio_processor(lutfile, interpolation):
75+
def create_ocio_processor(lutfile, interpolation, inverse, prelutfile=None,
76+
postlutfile=None):
7577
"""Create an OpenColorIO processor for lutfile
7678
7779
Args:
@@ -80,15 +82,38 @@ def create_ocio_processor(lutfile, interpolation):
8082
interpolation (int): can be INTERP_NEAREST, INTERP_LINEAR or
8183
INTERP_TETRAHEDRAL (only for 3D LUT)
8284
85+
inverse (bool): get an inverse direction processor
86+
87+
Kwargs:
88+
prelutfile (str): path to a pre LUT
89+
90+
postlutfile (str): path to a post LUT
91+
8392
Returns:
8493
PyOpenColorIO.config.Processor.
8594
8695
"""
96+
if inverse:
97+
direction = TRANSFORM_DIR_INVERSE
98+
else:
99+
direction = TRANSFORM_DIR_FORWARD
87100
config = Config()
88101
# In colorspace (LUT)
89102
colorspace = ColorSpace(name='RawInput')
90-
t = FileTransform(lutfile, interpolation=interpolation)
91-
colorspace.setTransform(t, COLORSPACE_DIR_TO_REFERENCE)
103+
mainLut = FileTransform(lutfile, interpolation=interpolation,
104+
direction=direction)
105+
group = GroupTransform()
106+
# Prelut
107+
if prelutfile:
108+
prelut = FileTransform(prelutfile, interpolation=interpolation)
109+
group.push_back(prelut)
110+
# Mainlut
111+
group.push_back(mainLut)
112+
# Postlut
113+
if postlutfile:
114+
postlut = FileTransform(postlutfile, interpolation=interpolation)
115+
group.push_back(postlut)
116+
colorspace.setTransform(group, COLORSPACE_DIR_TO_REFERENCE)
92117
config.addColorSpace(colorspace)
93118
# Out colorspace
94119
colorspace = ColorSpace(name='ProcessedOutput')
@@ -226,29 +251,8 @@ def supported_formats():
226251
return "Supported LUT formats : {0}".format(', '.join(OCIO_LUTS_FORMATS))
227252

228253

229-
def help():
230-
"""Return help
231-
232-
Returns:
233-
str.
234-
235-
"""
236-
return (
237-
"----\n"
238-
"plot_that_lut.py <path to a LUT>\n"
239-
" dispay a cube ({0} segments) for 3D LUTs and matrixes\n"
240-
" or a curve ({1} points) for 1D/2D LUTs.\n"
241-
242-
"plot_that_lut.py <path to a LUT> curve [points count]\n"
243-
" display a curve with x points (default value : {2}).\n"
244-
" plot_that_lut.py <path to a LUT> cube [cube size]\n"
245-
" display a cube with x segments (default value : {3}).\n"
246-
"\n{4}"
247-
).format(DEFAULT_CUBE_SIZE, DEFAULT_SAMPLE, DEFAULT_SAMPLE,
248-
DEFAULT_CUBE_SIZE, supported_formats())
249-
250-
251-
def plot_that_lut(lutfile, plot_type=None, count=None):
254+
def plot_that_lut(lutfile, plot_type=None, count=None, inverse=False,
255+
prelutfile=None, postlutfile=None):
252256
"""Plot a lut depending on its type and/or args
253257
254258
Args:
@@ -259,8 +263,13 @@ def plot_that_lut(lutfile, plot_type=None, count=None):
259263
260264
count: possible values are curve size or curve samples count or 'auto'
261265
266+
prelutfile (str): path to a pre LUT
267+
268+
postlutfile (str): path to a post LUT
269+
262270
Raises:
263-
Exception
271+
PlotThatLutException
272+
Exception from OpenColorIO binding
264273
265274
"""
266275
set_matplotlib_backend()
@@ -275,7 +284,8 @@ def plot_that_lut(lutfile, plot_type=None, count=None):
275284
raise PlotThatLutException("Error: {0} file aren't supported.\n{1}"
276285
.format(fileext, supported_formats()))
277286
# create OCIO processor
278-
processor = create_ocio_processor(lutfile, INTERP_LINEAR)
287+
processor = create_ocio_processor(lutfile, INTERP_LINEAR, inverse,
288+
prelutfile, postlutfile)
279289
# init args
280290
if not plot_type or plot_type == 'auto':
281291
if processor.hasChannelCrosstalk() or fileext == '.spimtx':
@@ -297,38 +307,5 @@ def plot_that_lut(lutfile, plot_type=None, count=None):
297307
else:
298308
raise PlotThatLutException((
299309
"Unknown plot type : {0}\n"
300-
"Plot type should be curve or cube.\n{1}"
301-
).format(plot_type, help()))
302-
303-
if __name__ == '__main__':
304-
""" Command line interface for plot_that_lut
305-
306-
.. todo:: use optparse (or argparse)
307-
308-
"""
309-
cherry_py_mode = False
310-
params_count = len(sys.argv)
311-
lutfile = ""
312-
plot_type = None
313-
count = None
314-
if params_count < 2:
315-
print "Syntax error !"
316-
print help()
317-
sys.exit(1)
318-
elif params_count == 2:
319-
lutfile = sys.argv[1]
320-
elif params_count == 3:
321-
lutfile = sys.argv[1]
322-
plot_type = sys.argv[2]
323-
elif params_count == 4:
324-
lutfile = sys.argv[1]
325-
plot_type = sys.argv[2]
326-
count = int(sys.argv[3])
327-
else:
328-
print "Syntax error !"
329-
print help()
330-
sys.exit(1)
331-
try:
332-
plot_that_lut(lutfile, plot_type, count)
333-
except Exception, e:
334-
print "Watch out !\n%s" % e
310+
"Plot type should be curve or cube.\n"
311+
).format(plot_type))

0 commit comments

Comments
 (0)