Actually working pip install now. Added OpenGL modularity.
parent
913d6904bc
commit
59f42a2622
74
README.md
74
README.md
|
@ -25,14 +25,22 @@ using openlut's toolkit.
|
|||
|
||||
Installation
|
||||
-----
|
||||
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 openlut.py, 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 main.py -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 http://brew.sh/ ) 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...
|
||||
|
||||
|
||||
Dependencies
|
||||
|
@ -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 openlut.py -t to see it work)
|
||||
|
||||
```python
|
||||
#Open any format image. Try it with exr/dpx/anything!
|
||||
img = ColMap.open('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!
|
||||
oLut.save('testpath/sRGB-->Lin.cube') #Saves the LUT to a format inferred from the extension. cube only for now!
|
||||
|
||||
#Opening LUTs from .cube files.
|
||||
lut = LUT.open('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)
|
||||
tImg.save('testpath/output.exr')
|
||||
tImg.save('testpath/output.dpx')
|
||||
tImg.save('testpath/output.png')
|
||||
tImg.save('testpath/output.jpg')
|
||||
tImg.save('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.
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
import pygame
|
||||
from pygame.locals import *
|
||||
from OpenGL.GL import *
|
||||
from OpenGL.GLU import *
|
||||
|
||||
MOD_OPENGL = True
|
||||
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!')
|
||||
MOD_OPENGL = False
|
||||
|
||||
|
||||
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)
|
||||
v.bindTex(img)
|
||||
|
||||
|
|
14
setup.py
14
setup.py
|
@ -1,21 +1,33 @@
|
|||
#!/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 = 'sofus@sofusrose.com',
|
||||
|
|
Loading…
Reference in New Issue