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

Commit

Permalink
Merge branch 'feature/add_pre_post_lut' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mfe committed Sep 20, 2013
2 parents cae8735 + cb40ee0 commit 46d4fa9
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 107 deletions.
12 changes: 3 additions & 9 deletions plotThatLut/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ Tested config

Command line usage
-----
* Dispay a cube (17 segments) for 3D LUTs and matrixes or a curve (256 points) for 1D/2D LUTs :
`plot_that_lut.py < path to a LUT >`

* Display a curve with x points (default value : 256) :
`plot_that_lut.py < path to a LUT > curve [points count]`

* Display a cube with x segments (default value : 17) :
`plot_that_lut.py < path to a LUT > cube [cube size]`
See command line help :
`ptlut.py -h`

Web app usage
-------------
Expand All @@ -48,4 +42,4 @@ Screenshots

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

![Web app](https://dl.dropboxusercontent.com/u/2979643/PlotThatLUT_webapp.png "Web app")
![Web app](https://dl.dropboxusercontent.com/u/2979643/PlotThatLUT_webapp2.png "Web app")
12 changes: 11 additions & 1 deletion plotThatLut/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ a:active {color: #666;} /* selected link */
line-height:40px;
}


#content {
width: 640px;
height: 600px;
Expand All @@ -38,4 +37,15 @@ a:active {color: #666;} /* selected link */
left: 0;
right: 0;
margin: auto;
}

#advanced {
background-color: #eee;
padding-left: 10px;
padding-top: 5px;
padding-bottom: 5px;
}

input[type="file"] {
width: 80%
}
127 changes: 52 additions & 75 deletions plotThatLut/plot_that_lut.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

## imports
import os
import sys
# OpenColorIO
from PyOpenColorIO import Config, ColorSpace, FileTransform
from PyOpenColorIO.Constants import INTERP_LINEAR, COLORSPACE_DIR_TO_REFERENCE
from PyOpenColorIO import (
Config, ColorSpace, FileTransform, GroupTransform,
)
from PyOpenColorIO.Constants import (
INTERP_LINEAR, COLORSPACE_DIR_TO_REFERENCE,
TRANSFORM_DIR_FORWARD, TRANSFORM_DIR_INVERSE,
)
# matplotlib
import matplotlib


cherry_py_mode = True
web_mode = False


class PlotThatLutException(Exception):
Expand All @@ -26,11 +30,11 @@ class PlotThatLutException(Exception):
def set_matplotlib_backend():
""" Select display backend
.. todo:: Externalize this and remove cherry_py_mode global var
.. todo:: Externalize this and remove web_mode global var
"""

if cherry_py_mode:
if web_mode:
matplotlib.use('Agg')
else:
matplotlib.use('Qt4Agg')
Expand All @@ -52,26 +56,24 @@ def show_plot(fig, filename):
Returns:
str.
if in cherrypy mode, an html string,
if in web mode, an html string,
else a void string.
"""
if cherry_py_mode:
if web_mode:
split_filename = os.path.splitext(filename)
filename = '{0}{1}'.format(split_filename[0],
split_filename[1].replace(".", "_"))
export_path = 'img/export_{0}.png'.format(filename)
fig.savefig(export_path)
return (
'<img src="/{0}" width="640" height="480"'
'border="0"/>'
).format(export_path)
return export_path
else:
matplotlib.pyplot.show()
return ""


def create_ocio_processor(lutfile, interpolation):
def create_ocio_processor(lutfile, interpolation, inverse, prelutfile=None,
postlutfile=None):
"""Create an OpenColorIO processor for lutfile
Args:
Expand All @@ -80,15 +82,38 @@ def create_ocio_processor(lutfile, interpolation):
interpolation (int): can be INTERP_NEAREST, INTERP_LINEAR or
INTERP_TETRAHEDRAL (only for 3D LUT)
inverse (bool): get an inverse direction processor
Kwargs:
prelutfile (str): path to a pre LUT
postlutfile (str): path to a post LUT
Returns:
PyOpenColorIO.config.Processor.
"""
if inverse:
direction = TRANSFORM_DIR_INVERSE
else:
direction = TRANSFORM_DIR_FORWARD
config = Config()
# In colorspace (LUT)
colorspace = ColorSpace(name='RawInput')
t = FileTransform(lutfile, interpolation=interpolation)
colorspace.setTransform(t, COLORSPACE_DIR_TO_REFERENCE)
mainLut = FileTransform(lutfile, interpolation=interpolation,
direction=direction)
group = GroupTransform()
# Prelut
if prelutfile:
prelut = FileTransform(prelutfile, interpolation=interpolation)
group.push_back(prelut)
# Mainlut
group.push_back(mainLut)
# Postlut
if postlutfile:
postlut = FileTransform(postlutfile, interpolation=interpolation)
group.push_back(postlut)
colorspace.setTransform(group, COLORSPACE_DIR_TO_REFERENCE)
config.addColorSpace(colorspace)
# Out colorspace
colorspace = ColorSpace(name='ProcessedOutput')
Expand Down Expand Up @@ -226,29 +251,8 @@ def supported_formats():
return "Supported LUT formats : {0}".format(', '.join(OCIO_LUTS_FORMATS))


def help():
"""Return help
Returns:
str.
"""
return (
"----\n"
"plot_that_lut.py <path to a LUT>\n"
" dispay a cube ({0} segments) for 3D LUTs and matrixes\n"
" or a curve ({1} points) for 1D/2D LUTs.\n"

"plot_that_lut.py <path to a LUT> curve [points count]\n"
" display a curve with x points (default value : {2}).\n"
" plot_that_lut.py <path to a LUT> cube [cube size]\n"
" display a cube with x segments (default value : {3}).\n"
"\n{4}"
).format(DEFAULT_CUBE_SIZE, DEFAULT_SAMPLE, DEFAULT_SAMPLE,
DEFAULT_CUBE_SIZE, supported_formats())


def plot_that_lut(lutfile, plot_type=None, count=None):
def plot_that_lut(lutfile, plot_type=None, count=None, inverse=False,
prelutfile=None, postlutfile=None):
"""Plot a lut depending on its type and/or args
Args:
Expand All @@ -259,8 +263,13 @@ def plot_that_lut(lutfile, plot_type=None, count=None):
count: possible values are curve size or curve samples count or 'auto'
prelutfile (str): path to a pre LUT
postlutfile (str): path to a post LUT
Raises:
Exception
PlotThatLutException
Exception from OpenColorIO binding
"""
set_matplotlib_backend()
Expand All @@ -275,7 +284,8 @@ def plot_that_lut(lutfile, plot_type=None, count=None):
raise PlotThatLutException("Error: {0} file aren't supported.\n{1}"
.format(fileext, supported_formats()))
# create OCIO processor
processor = create_ocio_processor(lutfile, INTERP_LINEAR)
processor = create_ocio_processor(lutfile, INTERP_LINEAR, inverse,
prelutfile, postlutfile)
# init args
if not plot_type or plot_type == 'auto':
if processor.hasChannelCrosstalk() or fileext == '.spimtx':
Expand All @@ -297,38 +307,5 @@ def plot_that_lut(lutfile, plot_type=None, count=None):
else:
raise PlotThatLutException((
"Unknown plot type : {0}\n"
"Plot type should be curve or cube.\n{1}"
).format(plot_type, help()))

if __name__ == '__main__':
""" Command line interface for plot_that_lut
.. todo:: use optparse (or argparse)
"""
cherry_py_mode = False
params_count = len(sys.argv)
lutfile = ""
plot_type = None
count = None
if params_count < 2:
print "Syntax error !"
print help()
sys.exit(1)
elif params_count == 2:
lutfile = sys.argv[1]
elif params_count == 3:
lutfile = sys.argv[1]
plot_type = sys.argv[2]
elif params_count == 4:
lutfile = sys.argv[1]
plot_type = sys.argv[2]
count = int(sys.argv[3])
else:
print "Syntax error !"
print help()
sys.exit(1)
try:
plot_that_lut(lutfile, plot_type, count)
except Exception, e:
print "Watch out !\n%s" % e
"Plot type should be curve or cube.\n"
).format(plot_type))
Loading

0 comments on commit 46d4fa9

Please sign in to comment.