Last active
December 26, 2015 06:19
-
-
Save gcorallo/7107014 to your computer and use it in GitHub Desktop.
ICC Profiles for PImage in Processing.
This file contains 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
/* | |
ICC Profiles for PImage in Processing. | |
Press spacebar to switch between default and loaded profile (first time takes a while...) | |
*/ | |
import java.awt.color.ColorSpace; | |
import java.awt.color.ICC_Profile; | |
import java.awt.color.ICC_ColorSpace; | |
import java.awt.image.ColorConvertOp; | |
import java.io.FileInputStream; | |
PImage img, img2; | |
boolean showICC=false; | |
ICC_Profile icc1; | |
ColorConvertOp op1; | |
ColorSpace cs=null; | |
void setup() { | |
size(800, 450); | |
img=loadImage("img.jpg"); | |
//only works for "output" profiles (ie: printer profiles) | |
//http://docs.oracle.com/javase/7/docs/api/java/awt/color/ICC_ColorSpace.html | |
//String profilePath="/Library/ColorSync/Profiles/550 Megaphoto Frontier FF 23072012.icc"; | |
String profilePath=dataPath("hp_pspro_b8800_ilford_galerie_classic_gloss.icc"); | |
try { | |
ICC_Profile icc1=ICC_Profile.getInstance(new | |
FileInputStream(profilePath)); | |
println("iccType: "+icc1.getColorSpaceType() ); | |
//color space types: | |
// http://dcs.oracle.com/javase/6/docs/api/constant-values.html#java.awt.color.ColorSpace.TYPE_XYZ | |
cs=new ICC_ColorSpace(icc1); | |
} | |
catch(IOException e) { | |
println(e); | |
} | |
op1 = new ColorConvertOp(cs, null); | |
} | |
void draw() { | |
background(0); | |
if (!showICC) { | |
image(img, 0, 0, img.width, img.height); | |
} | |
else { | |
if (img2==null) { | |
println("applying icc profile"); | |
java.awt.image.BufferedImage result = op1.filter( (java.awt.image.BufferedImage)img.getImage(), null ); | |
try { | |
img2=new PImage(result.getWidth(), result.getHeight(), PConstants.RGB); | |
result.getRGB(0, 0, img2.width, img2.height, img2.pixels, 0, img2.width); | |
img2.updatePixels(); | |
} | |
catch(Exception e) { | |
e.printStackTrace(); | |
} | |
println("icc profile ready"); | |
} | |
else { | |
image(img2, 0, 0, img2.width, img2.height); | |
} | |
} | |
} | |
void keyPressed() { | |
if (key==' ') { | |
showICC=!showICC; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment