Verified Commit 59f42a26 authored by Sofus Albert Høgsbro Rose's avatar Sofus Albert Høgsbro Rose
Browse files

Actually working pip install now. Added OpenGL modularity.

parent 913d6904
......@@ -25,14 +25,22 @@ using openlut's toolkit.
I'll put it on pip eventually (when I figure out how!). For now, just download the repository.
Simply use pip: `sudo pip3 install openlut` (pip3 denotes that you must use a Python 3 version of pip). Keep in mind, there are some external dependencies:
* **Python 3.5**: This is Python; you need Python.
* **gcc**: This is needed to compile the C++ extensions.
* **pybind11**: This is a library needed to link the C++ extension into Python. pip version is being difficult...
* **imagemagick**: For all file IO. It's not like I was gonna write that myself :) .
To run, first make sure you have the *Dependencies*. To run the test code at the bottom (make sure openlut is in the same
directory as testpath; it needs to load test.exr), you can then run:
*If it's breaking, try running `sudo pip3 install -U pip setuptools`. Sometimes they are out of date.*
`python3 -t`
Installing Dependencies
Not Difficult, I promise!
To use in your code, simply `import` the module at the top of your file.
On Debian/Ubuntu: `sudo apt-get install python3-pip gcc pybind11-dev libmagickwand-dev`
On Mac: `brew install python3 gcc pybind11 imagemagick`
* You will need Homebrew ( copy/paste a command from ) and XCode Command Line Tools for gcc (it should prompt you to install this).
* Disclaimer - gcc took its sweet time compiling/installing on my old Mac...
......@@ -44,7 +52,8 @@ If you're on a **Mac**, run this to get python3 and pip3: `brew install python3;
If you're on **Linux**, you should already have python3 and pip3 - otherwise see your distribution repositories.
### Dependency Installation
Run this to get all deps: `sudo pip3 install numpy wand numba scipy`
You need **Python 3.5**, **Pip**, a newer version (must support C++14) of **gcc**, and pybind11 in your `includes`. This is trivial on Debian/Ubuntu:
* `sudo apt-get install python3-pip
Basic Library Usage
......@@ -57,55 +66,4 @@ The **Transform** objects themselves have plenty of features - like LUT, with `o
input matrices, or automatic spline-based interpolation of very small 1D LUTs - to make them helpful in and of themselves!
The best way to demonstrate this, I think, is to show some test code: (run python3 -t to see it work)
#Open any format image. Try it with exr/dpx/anything!
img ='testpath/test.exr') #Opens a test image 'test.exr', creating a ColMap object, automatically using the best image backend available to load the image at the correct bit depth.
Gamma has gamma functions like Gamma.sRGB, called by value like Gamma.sRGB(val). All take one argument, the value (x), and returns the transformed value. Color doesn't matter for gamma.
TransMat has matrices, in 3x3 numpy array form. All are relative to ACES, with direction aptly named. So, TransMat.XYZ is a matrix from ACES --> XYZ, while TransMat.XYZinv goes from XYZ --> ACES. All use/are converted to the D65 illuminant, for consistency sake.
#Gamma Functions: sRGB --> Linear.
gFunc = Gamma(Gamma.sRGBinv) #A Gamma Transform object using the sRGB-->Linear gamma formula. Apply to ColMaps!
gFuncManualsRGB = Gamma(lambda val: ((val + 0.055) / 1.055) ** 2.4 if val > 0.04045 else val / 12.92) #It's generic - specify any gamma function, even inline with a lambda!
#LUT from Function: sRGB --> Linear
oLut = LUT.lutFunc(Gamma.sRGBinv) #A LUT Transform object, created from a gamma function. Size is 16384 by default. LUTs are faster!'testpath/sRGB-->Lin.cube') #Saves the LUT to a format inferred from the extension. cube only for now!
#Opening LUTs from .cube files.
lut ='testpath/sRGB-->Lin.cube') #Opens the lut we just made into a different LUT object.
lut.resized(17).save('testpath/sRGB-->Lin_tiny.cube') #Resizes the LUT, then saves it again to a much smaller file!
#Matrix Transformations
simpleMat = TransMat(TransMat.sRGBinv) #A Matrix Transform (TransMat) object, created from a color transform matrix for gamut transformations! This one is sRGB --> ACES.
mat = TransMat(TransMat.sRGBinv, TransMat.XYZ, TransMat.XYZinv, TransMat.aRGB) * TransMat.aRGBinv
#Indeed, specify many matrices which auto-multiply into a single one! You can also combine them after, with simple multiplication.
#Applying and saving.
img.apply(gFunc).save('testpath/openlut_gammafunc.png') #save saves an image using the appropriate image backend, based on the extension.
img.apply(lut).save('testpath/openlut_lut-lin-16384.png') #apply applies any color transformation object that inherits from Transform - LUT, Gamma, TransMat, etc., or make your own! It's easy ;) .
img.apply(lut.resized(17)).save('testpath/openlut_lut-lin-17.png') #Why so small? Because spline interpolation automatically turns on. It's identical to the larger LUT!
img.apply(mat).save('testpath/openlut_mat.png') #Applies the gamut transformation.
#As a proof of concept, here's a long list of transformations that should, in sum, do nothing :) :
img.apply(lut).apply(LUT.lutFunc(Gamma.sRGB)).apply(mat).apply(~mat).save('testpath/openlut_noop.png') #~mat is the inverse of mat. Easily undo the gamut operation!
#Format Test: All output images are in Linear ACES.
tImg = img.apply(mat)'testpath/output.exr')'testpath/output.dpx')'testpath/output.png')'testpath/output.jpg')'testpath/output.tif') #All sorts of formats work! Bit depth is 16, unless you say something else.
#Compression is impossible right now - wand is being difficult.
#Keep in mind, values are clipped from 0 to 1 when done. Scary transforms can make this an issue!
#Color management of openlut itself is simple: openlut doesn't touch your data, unless you tell it to with a Transform. So, the data that goes in, goes out, unless a Transform was applied.
Take a look at the test code under tests for examples.
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
try :
from OpenGL.GL import *
from OpenGL.GLU import *
except :
print('Unable to load OpenGL. Make sure your graphics drivers are installed & up to date!')
import sys, os, os.path
......@@ -99,6 +106,8 @@ class Viewer :
img is an rgb array.
if not MOD_OPENGL: print("OpenGL not enabled. Viewer won't start."); return
v = Viewer((xRes, yRes), title)
#!/usr/bin/env python3
import sys, os
import os.path as path
#~ from sysconfig import get_python_version, get_path
from setuptools import setup
from setuptools import Extension
from setuptools import find_packages
#Weirdly long way to get to the actual header files we need to include.
#~ pyPath = path.join(path.abspath(get_path('include') + os.sep + '..'), 'site/python{}'.format(get_python_version()))
#Better - Mac & Linux only.
#~ pyPath = '/usr/local/include/python{}'.format(get_python_version())'
cpp_args = ['-fopenmp', '-std=gnu++14']
link_args = ['-fopenmp']
olOpt = Extension( 'openlut.lib.olOpt',
sources = ['openlut/lib/olOpt.cpp'],
#~ include_dirs=[pyPath], #Include from the the python3 source code.
language = 'c++',
extra_compile_args = cpp_args,
extra_link_args = cpp_args
setup( name = 'openlut',
version = '0.1.1',
version = '0.1.4',
description = 'OpenLUT is a practical color management library.',
author = 'Sofus Rose',
author_email = '',
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment