Forked from fish2000/original-photoshop-acv-reader.py
Created
October 29, 2023 14:18
-
-
Save PacoH/0f717926ab4d5edd30c952ecb87d6108 to your computer and use it in GitHub Desktop.
Original Photoshop ACV File Reader Python Code from (Now-Defunct) WeemoApps.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
DESCRIPTION | |
Prints the polynomials that describe a photoshop curve. | |
There are three curves (one per RGB channel) which you can later | |
use to make a custom filter for your image. | |
See http://www.weemoapps.com/creating-retro-and-analog-image-filters-in-mobile-apps | |
for the theory behind this method. | |
USAGE | |
python extractCurvesFromACVFile.py theCurveFile.acv | |
You need to have scipy and numpy installed. | |
AUTHOR | |
email: [email protected] | |
twitter: @weemoapps | |
LICENSE | |
Do whatever you want, but please mention this code in your code if you modify it. | |
VERSION | |
0.1 | |
""" | |
import sys, os, traceback, optparse, time | |
from struct import unpack | |
from scipy import interpolate | |
import numpy as np | |
#Here we read the .acv curve file. It will help to take a look at see the link below to lean about the .acv file format specifications | |
# http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/PhotoshopFileFormats.htm#50577411_pgfId-1056330 | |
def read_curve(acv_file): | |
curve = [] | |
number_of_points_in_curve, = unpack("!h", acv_file.read(2)) | |
for j in range(number_of_points_in_curve): | |
y, x = unpack("!hh", acv_file.read(4)) | |
curve.append((x, y)) | |
return curve | |
#Here we do the interpolation in order to get a curve out of the curve points we already have. | |
def return_polynomial_coefficients(curve_list): | |
xdata = [x[0] for x in curve_list] | |
ydata = [x[1] for x in curve_list] | |
np.set_printoptions(precision=6) | |
np.set_printoptions(suppress=True) | |
p = interpolate.lagrange(xdata, ydata) | |
coefficients = p.c | |
print coefficients | |
return p | |
def main(): | |
if (len(sys.argv) != 1): | |
acv_file = open(sys.argv[1], "rb") | |
else: | |
print "Wrong args. Usage: python extractCurvesFromACVFile.py curveFile.acv" | |
os._exit(1) | |
_, nr_curves = unpack("!hh", acv_file.read(4)) | |
curves = [] | |
for i in range(nr_curves): | |
curves.append(read_curve(acv_file)) | |
compositeCurve = curves[0] | |
redCurve = curves[1] | |
greenCurve = curves[2] | |
blueCurve = curves[3] | |
print "************* Red Curve *************" | |
print "" | |
pRed = return_polynomial_coefficients(redCurve) | |
print pRed | |
print "" | |
print "*************************************\n" | |
print "" | |
print "************* Green Curve *************" | |
print "" | |
pGreen = return_polynomial_coefficients(greenCurve) | |
print pGreen | |
print "" | |
print "***************************************\n" | |
print "" | |
print "************* Blue Curve *************" | |
print "" | |
pBlue = return_polynomial_coefficients(blueCurve) | |
print pBlue | |
print "" | |
print "**************************************\n" | |
print "" | |
if __name__ == '__main__': | |
try: | |
sys.argv.append( | |
'/Users/fish/Praxa/django-instakit/instance/django_instakit/static/django_instakit/acv/country.acv') | |
main() | |
except Exception, e: | |
print 'ERROR, UNEXPECTED EXCEPTION' | |
print str(e) | |
traceback.print_exc() | |
os._exit(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This does not work with python3. Had to convert to python3 compatible using 2to3 — Automated Python 2 to 3 code translation and then manually add parentheses to all the print statements and exception statement.