History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/java2d/cmm (22 of 18352 files). Show all

Unified · Split

22 files
  1. java/pkg/sun/java2d/cmm/CMSManager$1.class +0 −0
  2. java/pkg/sun/java2d/cmm/CMSManager$CMMTracer.class +0 −0
  3. java/pkg/sun/java2d/cmm/CMSManager.class +0 −0
  4. java/pkg/sun/java2d/cmm/CMSManager.java +170 −0
  5. java/pkg/sun/java2d/cmm/ColorTransform.class +0 −0
  6. java/pkg/sun/java2d/cmm/ColorTransform.java +53 −0
  7. java/pkg/sun/java2d/cmm/PCMM.class +0 −0
  8. java/pkg/sun/java2d/cmm/PCMM.java +48 −0
  9. java/pkg/sun/java2d/cmm/ProfileActivator.class +0 −0
  10. java/pkg/sun/java2d/cmm/ProfileActivator.java +41 −0
  11. java/pkg/sun/java2d/cmm/ProfileDeferralInfo.class +0 −0
  12. java/pkg/sun/java2d/cmm/ProfileDeferralInfo.java +61 −0
  13. java/pkg/sun/java2d/cmm/ProfileDeferralMgr.class +0 −0
  14. java/pkg/sun/java2d/cmm/ProfileDeferralMgr.java +119 −0
  15. java/pkg/sun/java2d/cmm/lcms/LCMS.java +104 −0
  16. java/pkg/sun/java2d/cmm/lcms/LCMSImageLayout.java +235 −0
  17. java/pkg/sun/java2d/cmm/lcms/LCMSTransform.java +609 −0
  18. java/pkg/sun/java2d/cmm/lcms/META-INF/mkfile +6 −0
  19. java/pkg/sun/java2d/cmm/lcms/META-INF/services/mkfile +2 −0
  20. java/pkg/sun/java2d/cmm/lcms/META-INF/services/sun.java2d.cmm.PCMM +2 −0
  21. java/pkg/sun/java2d/cmm/lcms/mkfile +14 −0
  22. java/pkg/sun/java2d/cmm/mkfile +17 −0
java/pkg/sun/java2d/cmm/CMSManager$1.class+0−0

Binary file not shown.

java/pkg/sun/java2d/cmm/CMSManager$CMMTracer.class+0−0

Binary file not shown.

java/pkg/sun/java2d/cmm/CMSManager.class+0−0

Binary file not shown.

java/pkg/sun/java2d/cmm/CMSManager.java+170−0
@@ -0,0 +1,170 @@
1+/*
2+ * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package sun.java2d.cmm;
27+
28+import java.awt.color.ColorSpace;
29+import java.awt.color.ICC_Profile;
30+import java.awt.color.CMMException;
31+import java.awt.image.BufferedImage;
32+import java.awt.image.Raster;
33+import java.awt.image.WritableRaster;
34+import java.security.AccessController;
35+import java.security.PrivilegedAction;
36+import sun.security.action.GetPropertyAction;
37+import java.util.ServiceLoader;
38+
39+public class CMSManager {
40+ public static ColorSpace GRAYspace; // These two fields allow access
41+ public static ColorSpace LINEAR_RGBspace; // to java.awt.color.ColorSpace
42+ // private fields from other
43+ // packages. The fields are set
44+ // by java.awt.color.ColorSpace
45+ // and read by
46+ // java.awt.image.ColorModel.
47+
48+ private static PCMM cmmImpl = null;
49+
50+ public static synchronized PCMM getModule() {
51+ if (cmmImpl != null) {
52+ return cmmImpl;
53+ }
54+
55+ cmmImpl = (PCMM)AccessController.doPrivileged(new PrivilegedAction() {
56+ public Object run() {
57+ String cmmClass = System.getProperty(
58+ "sun.java2d.cmm", "sun.java2d.cmm.kcms.CMM");
59+
60+ ServiceLoader<PCMM> cmmLoader
61+ = ServiceLoader.loadInstalled(PCMM.class);
62+
63+ PCMM service = null;
64+
65+ for (PCMM cmm : cmmLoader) {
66+ service = cmm;
67+ if (cmm.getClass().getName().equals(cmmClass)) {
68+ break;
69+ }
70+ }
71+ return service;
72+ }
73+ });
74+
75+ if (cmmImpl == null) {
76+ throw new CMMException("Cannot initialize Color Management System."+
77+ "No CM module found");
78+ }
79+
80+ GetPropertyAction gpa = new GetPropertyAction("sun.java2d.cmm.trace");
81+ String cmmTrace = (String)AccessController.doPrivileged(gpa);
82+ if (cmmTrace != null) {
83+ cmmImpl = new CMMTracer(cmmImpl);
84+ }
85+
86+ return cmmImpl;
87+ }
88+
89+ /* CMM trace routines */
90+
91+ public static class CMMTracer implements PCMM {
92+ PCMM tcmm;
93+ String cName ;
94+
95+ public CMMTracer(PCMM tcmm) {
96+ this.tcmm = tcmm;
97+ cName = tcmm.getClass().getName();
98+ }
99+
100+ public long loadProfile(byte[] data) {
101+ System.err.print(cName + ".loadProfile");
102+ long profileID = tcmm.loadProfile(data);
103+ System.err.printf("(ID=%x)\n", profileID);
104+ return profileID;
105+ }
106+
107+ public void freeProfile(long profileID) {
108+ System.err.printf(cName + ".freeProfile(ID=%x)\n", profileID);
109+ tcmm.freeProfile(profileID);
110+ }
111+
112+ public int getProfileSize(long profileID) {
113+ System.err.print(cName + ".getProfileSize(ID=" + profileID + ")");
114+ int size = tcmm.getProfileSize(profileID);
115+ System.err.println("=" + size);
116+ return size;
117+ }
118+
119+ public void getProfileData(long profileID, byte[] data) {
120+ System.err.print(cName + ".getProfileData(ID=" + profileID + ") ");
121+ System.err.println("requested " + data.length + " byte(s)");
122+ tcmm.getProfileData(profileID, data);
123+ }
124+
125+ public int getTagSize(long profileID, int tagSignature) {
126+ System.err.printf(cName + ".getTagSize(ID=%x, TagSig=%s)",
127+ profileID, signatureToString(tagSignature));
128+ int size = tcmm.getTagSize(profileID, tagSignature);
129+ System.err.println("=" + size);
130+ return size;
131+ }
132+
133+ public void getTagData(long profileID, int tagSignature,
134+ byte[] data) {
135+ System.err.printf(cName + ".getTagData(ID=%x, TagSig=%s)",
136+ profileID, signatureToString(tagSignature));
137+ System.err.println(" requested " + data.length + " byte(s)");
138+ tcmm.getTagData(profileID, tagSignature, data);
139+ }
140+
141+ public void setTagData(long profileID, int tagSignature,
142+ byte[] data) {
143+ System.err.print(cName + ".setTagData(ID=" + profileID +
144+ ", TagSig=" + tagSignature + ")");
145+ System.err.println(" sending " + data.length + " byte(s)");
146+ tcmm.setTagData(profileID, tagSignature, data);
147+ }
148+
149+ /* methods for creating ColorTransforms */
150+ public ColorTransform createTransform(ICC_Profile profile,
151+ int renderType,
152+ int transformType) {
153+ System.err.println(cName + ".createTransform(ICC_Profile,int,int)");
154+ return tcmm.createTransform(profile, renderType, transformType);
155+ }
156+
157+ public ColorTransform createTransform(ColorTransform[] transforms) {
158+ System.err.println(cName + ".createTransform(ColorTransform[])");
159+ return tcmm.createTransform(transforms);
160+ }
161+
162+ private static String signatureToString(int sig) {
163+ return String.format("%c%c%c%c",
164+ (char)(0xff & (sig >> 24)),
165+ (char)(0xff & (sig >> 16)),
166+ (char)(0xff & (sig >> 8)),
167+ (char)(0xff & (sig )));
168+ }
169+ }
170+}
java/pkg/sun/java2d/cmm/ColorTransform.class+0−0

Binary file not shown.

java/pkg/sun/java2d/cmm/ColorTransform.java+53−0
@@ -0,0 +1,53 @@
1+/*
2+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package sun.java2d.cmm;
27+
28+import java.awt.image.BufferedImage;
29+import java.awt.image.Raster;
30+import java.awt.image.WritableRaster;
31+
32+public interface ColorTransform {
33+ public int Any = -1;/* any rendering type, whichever is
34+ available */
35+ /* search order is icPerceptual,
36+ icRelativeColorimetric, icSaturation */
37+
38+ /* Transform types */
39+ public int In = 1;
40+ public int Out = 2;
41+ public int Gamut = 3;
42+ public int Simulation = 4;
43+
44+ public int getNumInComponents();
45+ public int getNumOutComponents();
46+ public void colorConvert(BufferedImage src, BufferedImage dst);
47+ public void colorConvert(Raster src, WritableRaster dst,
48+ float[] srcMinVal, float[]srcMaxVal,
49+ float[] dstMinVal, float[]dstMaxVal);
50+ public void colorConvert(Raster src, WritableRaster dst);
51+ public short[] colorConvert(short[] src, short[] dest);
52+ public byte[] colorConvert (byte[] src, byte[] dest);
53+}
java/pkg/sun/java2d/cmm/PCMM.class+0−0

Binary file not shown.

java/pkg/sun/java2d/cmm/PCMM.java+48−0
@@ -0,0 +1,48 @@
1+/*
2+ * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package sun.java2d.cmm;
27+
28+import java.awt.color.ICC_Profile;
29+
30+/* Pluggable CMM interface */
31+
32+public interface PCMM {
33+
34+ /* methods invoked from ICC_Profile */
35+ public long loadProfile(byte[] data);
36+ public void freeProfile(long profileID);
37+ public int getProfileSize(long profileID);
38+ public void getProfileData(long profileID, byte[] data);
39+ public void getTagData(long profileID, int tagSignature, byte[] data);
40+ public int getTagSize(long profileID, int tagSignature);
41+ public void setTagData(long profileID, int tagSignature, byte[] data);
42+
43+ /* methods for creating ColorTransforms */
44+ public ColorTransform createTransform(ICC_Profile profile, int renderType,
45+ int transformType);
46+
47+ public ColorTransform createTransform(ColorTransform[] transforms);
48+}
java/pkg/sun/java2d/cmm/ProfileActivator.class+0−0

Binary file not shown.

java/pkg/sun/java2d/cmm/ProfileActivator.java+41−0
@@ -0,0 +1,41 @@
1+/*
2+ * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package sun.java2d.cmm;
27+
28+import java.awt.color.ProfileDataException;
29+
30+/**
31+ * An interface to allow the ProfileDeferralMgr to activate a
32+ * deferred profile.
33+ */
34+public interface ProfileActivator {
35+
36+ /**
37+ * Activate a previously deferred ICC_Profile object.
38+ */
39+ public void activate() throws ProfileDataException;
40+
41+}
java/pkg/sun/java2d/cmm/ProfileDeferralInfo.class+0−0

Binary file not shown.

java/pkg/sun/java2d/cmm/ProfileDeferralInfo.java+61−0
@@ -0,0 +1,61 @@
1+/*
2+ * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package sun.java2d.cmm;
27+
28+import java.io.InputStream;
29+import java.io.IOException;
30+
31+
32+/**
33+ * A class to pass information about a profile to be loaded from
34+ * a file to the static getInstance(InputStream) method of
35+ * ICC_Profile. Loading of the profile data and initialization
36+ * of the CMM is to be deferred as long as possible.
37+ */
38+public class ProfileDeferralInfo extends InputStream {
39+
40+ public int colorSpaceType, numComponents, profileClass;
41+ public String filename;
42+
43+ public ProfileDeferralInfo(String fn, int type, int ncomp, int pclass) {
44+
45+ super();
46+ filename = fn;
47+ colorSpaceType = type;
48+ numComponents = ncomp;
49+ profileClass = pclass;
50+ }
51+
52+
53+ /**
54+ * Implements the abstract read() method of InputStream.
55+ */
56+ public int read() throws IOException {
57+
58+ return 0;
59+ }
60+
61+}
java/pkg/sun/java2d/cmm/ProfileDeferralMgr.class+0−0

Binary file not shown.

java/pkg/sun/java2d/cmm/ProfileDeferralMgr.java+119−0
@@ -0,0 +1,119 @@
1+/*
2+ * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package sun.java2d.cmm;
27+
28+import java.awt.color.ProfileDataException;
29+import java.util.Vector;
30+
31+
32+/**
33+ * A class to manage the deferral of CMM initialization of profile
34+ * data for internal ICC_Profile objects - i.e. when we "trust" that
35+ * the profile data is valid and we think it may not be needed. An
36+ * example is the sRGB profile which gets loaded by any program doing
37+ * graphics, but which may not be needed if the program does not need
38+ * high quality color conversion.
39+ */
40+public class ProfileDeferralMgr {
41+
42+ public static boolean deferring = true;
43+ private static Vector<ProfileActivator> aVector;
44+
45+ /**
46+ * Records a ProfileActivator object whose activate method will
47+ * be called if the CMM needs to be activated.
48+ */
49+ public static void registerDeferral(ProfileActivator pa) {
50+
51+ if (!deferring) {
52+ return;
53+ }
54+ if (aVector == null) {
55+ aVector = new Vector<ProfileActivator>(3, 3);
56+ }
57+ aVector.addElement(pa);
58+ return;
59+ }
60+
61+
62+ /**
63+ * Removes a ProfileActivator object from the vector of ProfileActivator
64+ * objects whose activate method will be called if the CMM needs to be
65+ * activated.
66+ */
67+ public static void unregisterDeferral(ProfileActivator pa) {
68+
69+ if (!deferring) {
70+ return;
71+ }
72+ if (aVector == null) {
73+ return;
74+ }
75+ aVector.removeElement(pa);
76+ return;
77+ }
78+
79+ /**
80+ * Removes a ProfileActivator object from the vector of ProfileActivator
81+ * objects whose activate method will be called if the CMM needs to be
82+ * activated.
83+ */
84+ public static void activateProfiles() {
85+
86+ int i, n;
87+
88+ deferring = false;
89+ if (aVector == null) {
90+ return;
91+ }
92+ n = aVector.size();
93+ for (ProfileActivator pa : aVector) {
94+ try {
95+ pa.activate();
96+ } catch (ProfileDataException e) {
97+ /*
98+ * Ignore profile activation error for now:
99+ * such exception is pssible due to absence
100+ * or corruption of standard color profile.
101+ * As for now we expect all profiles should
102+ * be shiped with jre and presence of this
103+ * exception is indication of some configuration
104+ * problem in jre installation.
105+ *
106+ * NB: we still are greedy loading deferred profiles
107+ * and load them all if any of them is needed.
108+ * Therefore broken profile (if any) might be never used.
109+ * If there will be attempt to use broken profile then
110+ * it will result in CMMException.
111+ */
112+ }
113+ }
114+ aVector.removeAllElements();
115+ aVector = null;
116+ return;
117+ }
118+
119+}
java/pkg/sun/java2d/cmm/lcms/LCMS.java+104−0
@@ -0,0 +1,104 @@
1+/*
2+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package sun.java2d.cmm.lcms;
27+
28+import java.awt.color.ColorSpace;
29+import java.awt.color.ICC_Profile;
30+import java.awt.color.CMMException;
31+import sun.java2d.cmm.ColorTransform;
32+import sun.java2d.cmm.PCMM;
33+import sun.java2d.cmm.lcms.LCMS;
34+import sun.java2d.cmm.lcms.LCMSTransform;
35+
36+public class LCMS implements PCMM {
37+
38+ /* methods invoked from ICC_Profile */
39+ public native long loadProfile(byte[] data);
40+
41+ public native void freeProfile(long profileID);
42+
43+ public native synchronized int getProfileSize(long profileID);
44+
45+ public native synchronized void getProfileData(long profileID, byte[] data);
46+
47+ public native synchronized int getTagSize(long profileID, int tagSignature);
48+ public native synchronized void getTagData(long profileID, int tagSignature,
49+ byte[] data);
50+ public native synchronized void setTagData(long profileID, int tagSignature,
51+ byte[] data);
52+
53+ public static native long getProfileID(ICC_Profile profile);
54+
55+ public static native long createNativeTransform(
56+ long[] profileIDs, int renderType, int inFormatter, int outFormatter,
57+ Object disposerRef);
58+
59+ /**
60+ * Constructs ColorTransform object corresponding to an ICC_profile
61+ */
62+ public ColorTransform createTransform(ICC_Profile profile,
63+ int renderType,
64+ int transformType)
65+ {
66+ return new LCMSTransform(profile, renderType, renderType);
67+ }
68+
69+ /**
70+ * Constructs an ColorTransform object from a list of ColorTransform
71+ * objects
72+ */
73+ public synchronized ColorTransform createTransform(
74+ ColorTransform[] transforms)
75+ {
76+ return new LCMSTransform(transforms);
77+ }
78+
79+ /* methods invoked from LCMSTransform */
80+ public static native void colorConvert(LCMSTransform trans,
81+ LCMSImageLayout src,
82+ LCMSImageLayout dest);
83+ public static native void freeTransform(long ID);
84+
85+ public static native void initLCMS(Class Trans, Class IL, Class Pf);
86+
87+ /* the class initializer which loads the CMM */
88+ static {
89+ java.security.AccessController.doPrivileged(
90+ new java.security.PrivilegedAction() {
91+ public Object run() {
92+ /* We need to load awt here because of usage trace and
93+ * disposer frameworks
94+ */
95+ System.loadLibrary("awt");
96+ System.loadLibrary("lcms");
97+ return null;
98+ }
99+ }
100+ );
101+
102+ initLCMS(LCMSTransform.class, LCMSImageLayout.class, ICC_Profile.class);
103+ }
104+}
java/pkg/sun/java2d/cmm/lcms/LCMSImageLayout.java+235−0
@@ -0,0 +1,235 @@
1+/*
2+ * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package sun.java2d.cmm.lcms;
27+
28+import java.awt.Graphics2D;
29+import java.awt.image.BufferedImage;
30+import java.awt.image.ComponentColorModel;
31+import java.awt.image.Raster;
32+import java.awt.image.WritableRaster;
33+import java.awt.image.SinglePixelPackedSampleModel;
34+import java.awt.image.ComponentSampleModel;
35+import java.awt.image.DataBuffer;
36+import java.awt.image.DataBufferByte;
37+import java.awt.image.DataBufferUShort;
38+import java.awt.image.DataBufferInt;
39+import java.awt.image.ColorModel;
40+import sun.awt.image.ByteComponentRaster;
41+import sun.awt.image.ShortComponentRaster;
42+import sun.awt.image.IntegerComponentRaster;
43+
44+
45+class LCMSImageLayout {
46+
47+ public static int BYTES_SH(int x) {
48+ return x;
49+ }
50+
51+ public static int EXTRA_SH(int x) {
52+ return x<<7;
53+ }
54+
55+ public static int CHANNELS_SH(int x) {
56+ return x<<3;
57+ }
58+
59+ public static final int SWAPFIRST = 1<<14;
60+
61+ public static final int DOSWAP = 1<<10;
62+
63+ public static final int PT_RGB_8 =
64+ CHANNELS_SH(3) | BYTES_SH(1);
65+
66+ public static final int PT_GRAY_8 =
67+ CHANNELS_SH(1) | BYTES_SH(1);
68+
69+ public static final int PT_GRAY_16 =
70+ CHANNELS_SH(1) | BYTES_SH(2);
71+
72+ public static final int PT_RGBA_8 =
73+ EXTRA_SH(1) | CHANNELS_SH(3) | BYTES_SH(1);
74+
75+ public static final int PT_ARGB_8 =
76+ EXTRA_SH(1) | CHANNELS_SH(3) | BYTES_SH(1) | SWAPFIRST;
77+
78+ public static final int PT_BGR_8 =
79+ DOSWAP | CHANNELS_SH(3) | BYTES_SH(1);
80+
81+ public static final int PT_ABGR_8 =
82+ DOSWAP | EXTRA_SH(1) | CHANNELS_SH(3) | BYTES_SH(1);
83+
84+ public static final int PT_BGRA_8 = EXTRA_SH(1) | CHANNELS_SH(3) |
85+ BYTES_SH(1) | DOSWAP | SWAPFIRST;
86+
87+ public static final int DT_BYTE = 0;
88+ public static final int DT_SHORT = 1;
89+ public static final int DT_INT = 2;
90+ public static final int DT_DOUBLE = 3;
91+
92+
93+ boolean isIntPacked = false;
94+ int pixelType;
95+ int dataType;
96+ int width;
97+ int height;
98+ int nextRowOffset;
99+ int offset;
100+
101+ Object dataArray;
102+ private LCMSImageLayout(int np, int pixelType, int pixelSize) {
103+ this.pixelType = pixelType;
104+ width = np;
105+ height = 1;
106+ nextRowOffset = np*pixelSize;
107+ offset = 0;
108+ }
109+
110+ private LCMSImageLayout(int width, int height, int pixelType,
111+ int pixelSize) {
112+ this.pixelType = pixelType;
113+ this.width = width;
114+ this.height = height;
115+ nextRowOffset = width*pixelSize;
116+ offset = 0;
117+ }
118+
119+
120+ public LCMSImageLayout(byte[] data, int np, int pixelType, int pixelSize) {
121+ this(np, pixelType, pixelSize);
122+ dataType = DT_BYTE;
123+ dataArray = data;
124+ }
125+
126+ public LCMSImageLayout(short[] data, int np, int pixelType, int pixelSize) {
127+ this(np, pixelType, pixelSize);
128+ dataType = DT_SHORT;
129+ dataArray = data;
130+ }
131+
132+ public LCMSImageLayout(int[] data, int np, int pixelType, int pixelSize) {
133+ this(np, pixelType, pixelSize);
134+ dataType = DT_INT;
135+ dataArray = data;
136+ }
137+
138+ public LCMSImageLayout(double[] data, int np, int pixelType, int pixelSize)
139+ {
140+ this(np, pixelType, pixelSize);
141+ dataType = DT_DOUBLE;
142+ dataArray = data;
143+ }
144+
145+ public LCMSImageLayout(BufferedImage image) {
146+ ShortComponentRaster shortRaster;
147+ IntegerComponentRaster intRaster;
148+ ByteComponentRaster byteRaster;
149+ switch (image.getType()) {
150+ case BufferedImage.TYPE_INT_RGB:
151+ pixelType = PT_ARGB_8;
152+ isIntPacked = true;
153+ break;
154+ case BufferedImage.TYPE_INT_ARGB:
155+ pixelType = PT_ARGB_8;
156+ isIntPacked = true;
157+ break;
158+ case BufferedImage.TYPE_INT_BGR:
159+ pixelType = PT_ABGR_8;
160+ isIntPacked = true;
161+ break;
162+ case BufferedImage.TYPE_3BYTE_BGR:
163+ pixelType = PT_BGR_8;
164+ break;
165+ case BufferedImage.TYPE_4BYTE_ABGR:
166+ pixelType = PT_ABGR_8;
167+ break;
168+ case BufferedImage.TYPE_BYTE_GRAY:
169+ pixelType = PT_GRAY_8;
170+ break;
171+ case BufferedImage.TYPE_USHORT_GRAY:
172+ pixelType = PT_GRAY_16;
173+ break;
174+ default:
175+ // TODO: Add support for some images having
176+ // SinglePixelPackedModel and ComponentSampleModel
177+ throw new IllegalArgumentException(
178+ "CMMImageLayout - bad image type passed to constructor");
179+ }
180+
181+ width = image.getWidth();
182+ height = image.getHeight();
183+
184+ switch (image.getType()) {
185+ case BufferedImage.TYPE_INT_RGB:
186+ case BufferedImage.TYPE_INT_ARGB:
187+ case BufferedImage.TYPE_INT_BGR:
188+ intRaster = (IntegerComponentRaster)image.getRaster();
189+ nextRowOffset = intRaster.getScanlineStride()*4;
190+ offset = intRaster.getDataOffset(0)*4;
191+ dataArray = intRaster.getDataStorage();
192+ dataType = DT_INT;
193+ break;
194+
195+ case BufferedImage.TYPE_3BYTE_BGR:
196+ case BufferedImage.TYPE_4BYTE_ABGR:
197+ byteRaster = (ByteComponentRaster)image.getRaster();
198+ nextRowOffset = byteRaster.getScanlineStride();
199+ offset = byteRaster.getDataOffset(0);
200+ dataArray = byteRaster.getDataStorage();
201+ dataType = DT_BYTE;
202+ break;
203+
204+ case BufferedImage.TYPE_BYTE_GRAY:
205+ byteRaster = (ByteComponentRaster)image.getRaster();
206+ nextRowOffset = byteRaster.getScanlineStride();
207+ offset = byteRaster.getDataOffset(0);
208+ dataArray = byteRaster.getDataStorage();
209+ dataType = DT_BYTE;
210+ break;
211+
212+ case BufferedImage.TYPE_USHORT_GRAY:
213+ shortRaster = (ShortComponentRaster)image.getRaster();
214+ nextRowOffset = shortRaster.getScanlineStride()*2;
215+ offset = shortRaster.getDataOffset(0) * 2;
216+ dataArray = shortRaster.getDataStorage();
217+ dataType = DT_SHORT;
218+ break;
219+ }
220+ }
221+
222+ public static boolean isSupported(BufferedImage image) {
223+ switch (image.getType()) {
224+ case BufferedImage.TYPE_INT_RGB:
225+ case BufferedImage.TYPE_INT_ARGB:
226+ case BufferedImage.TYPE_INT_BGR:
227+ case BufferedImage.TYPE_3BYTE_BGR:
228+ case BufferedImage.TYPE_4BYTE_ABGR:
229+ case BufferedImage.TYPE_BYTE_GRAY:
230+ case BufferedImage.TYPE_USHORT_GRAY:
231+ return true;
232+ }
233+ return false;
234+ }
235+}
java/pkg/sun/java2d/cmm/lcms/LCMSTransform.java+609−0
@@ -0,0 +1,609 @@
1+/*
2+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+/**********************************************************************
27+ **********************************************************************
28+ **********************************************************************
29+ *** COPYRIGHT (c) Eastman Kodak Company, 1997 ***
30+ *** As an unpublished work pursuant to Title 17 of the United ***
31+ *** States Code. All rights reserved. ***
32+ **********************************************************************
33+ **********************************************************************
34+ **********************************************************************/
35+
36+package sun.java2d.cmm.lcms;
37+
38+import java.awt.color.ICC_Profile;
39+import java.awt.color.ProfileDataException;
40+import java.awt.color.CMMException;
41+import java.awt.color.ColorSpace;
42+import java.awt.image.BufferedImage;
43+import java.awt.image.Raster;
44+import java.awt.image.WritableRaster;
45+import java.awt.image.ColorModel;
46+import java.awt.image.DirectColorModel;
47+import java.awt.image.ComponentColorModel;
48+import java.awt.image.SampleModel;
49+import java.awt.image.DataBuffer;
50+import java.awt.image.SinglePixelPackedSampleModel;
51+import java.awt.image.ComponentSampleModel;
52+import sun.java2d.cmm.*;
53+import sun.java2d.cmm.lcms.*;
54+
55+
56+public class LCMSTransform implements ColorTransform {
57+ long ID;
58+ private int inFormatter;
59+ private int outFormatter;
60+
61+ ICC_Profile[] profiles;
62+ long [] profileIDs;
63+ int renderType;
64+ int transformType;
65+
66+ private int numInComponents = -1;
67+ private int numOutComponents = -1;
68+
69+ private Object disposerReferent = new Object();
70+
71+ /* the class initializer */
72+ static {
73+ if (ProfileDeferralMgr.deferring) {
74+ ProfileDeferralMgr.activateProfiles();
75+ }
76+ }
77+
78+ public LCMSTransform(ICC_Profile profile, int renderType,
79+ int transformType)
80+ {
81+ /* Actually, it is not a complete transform but just part of it */
82+ profiles = new ICC_Profile[1];
83+ profiles[0] = profile;
84+ profileIDs = new long[1];
85+ profileIDs[0] = LCMS.getProfileID(profile);
86+ this.renderType = (renderType == ColorTransform.Any)?
87+ ICC_Profile.icPerceptual : renderType;
88+ this.transformType = transformType;
89+
90+ /* Note that ICC_Profile.getNumComponents() is quite expensive
91+ * (it may results in a reading of the profile header).
92+ * So, here we cache the number of components of input and
93+ * output profiles for further usage.
94+ */
95+ numInComponents = profiles[0].getNumComponents();
96+ numOutComponents = profiles[profiles.length - 1].getNumComponents();
97+ }
98+
99+ public LCMSTransform (ColorTransform[] transforms) {
100+ int size = 0;
101+ for (int i=0; i < transforms.length; i++) {
102+ size+=((LCMSTransform)transforms[i]).profiles.length;
103+ }
104+ profiles = new ICC_Profile[size];
105+ profileIDs = new long[size];
106+ int j = 0;
107+ for (int i=0; i < transforms.length; i++) {
108+ LCMSTransform curTrans = (LCMSTransform)transforms[i];
109+ System.arraycopy(curTrans.profiles, 0, profiles, j,
110+ curTrans.profiles.length);
111+ System.arraycopy(curTrans.profileIDs, 0, profileIDs, j,
112+ curTrans.profileIDs.length);
113+ j += curTrans.profiles.length;
114+ }
115+ renderType = ((LCMSTransform)transforms[0]).renderType;
116+
117+ /* Note that ICC_Profile.getNumComponents() is quite expensive
118+ * (it may results in a reading of the profile header).
119+ * So, here we cache the number of components of input and
120+ * output profiles for further usage.
121+ */
122+ numInComponents = profiles[0].getNumComponents();
123+ numOutComponents = profiles[profiles.length - 1].getNumComponents();
124+ }
125+
126+ public int getNumInComponents() {
127+ return numInComponents;
128+ }
129+
130+ public int getNumOutComponents() {
131+ return numOutComponents;
132+ }
133+
134+ private synchronized void doTransform(LCMSImageLayout in,
135+ LCMSImageLayout out) {
136+ // update native transfrom if needed
137+ if (ID == 0L ||
138+ inFormatter != in.pixelType ||
139+ outFormatter != out.pixelType) {
140+
141+ if (ID != 0L) {
142+ // Disposer will destroy forgotten transform
143+ disposerReferent = new Object();
144+ }
145+ inFormatter = in.pixelType;
146+ outFormatter = out.pixelType;
147+
148+ ID = LCMS.createNativeTransform(profileIDs, renderType,
149+ inFormatter, outFormatter,
150+ disposerReferent);
151+ }
152+
153+ LCMS.colorConvert(this, in, out);
154+ }
155+
156+ public void colorConvert(BufferedImage src, BufferedImage dst) {
157+ if (LCMSImageLayout.isSupported(src) &&
158+ LCMSImageLayout.isSupported(dst))
159+ {
160+ doTransform(new LCMSImageLayout(src), new LCMSImageLayout(dst));
161+ return;
162+ }
163+ LCMSImageLayout srcIL, dstIL;
164+ Raster srcRas = src.getRaster();
165+ WritableRaster dstRas = dst.getRaster();
166+ ColorModel srcCM = src.getColorModel();
167+ ColorModel dstCM = dst.getColorModel();
168+ int w = src.getWidth();
169+ int h = src.getHeight();
170+ int srcNumComp = srcCM.getNumColorComponents();
171+ int dstNumComp = dstCM.getNumColorComponents();
172+ int precision = 8;
173+ float maxNum = 255.0f;
174+ for (int i = 0; i < srcNumComp; i++) {
175+ if (srcCM.getComponentSize(i) > 8) {
176+ precision = 16;
177+ maxNum = 65535.0f;
178+ }
179+ }
180+ for (int i = 0; i < dstNumComp; i++) {
181+ if (dstCM.getComponentSize(i) > 8) {
182+ precision = 16;
183+ maxNum = 65535.0f;
184+ }
185+ }
186+ float[] srcMinVal = new float[srcNumComp];
187+ float[] srcInvDiffMinMax = new float[srcNumComp];
188+ ColorSpace cs = srcCM.getColorSpace();
189+ for (int i = 0; i < srcNumComp; i++) {
190+ srcMinVal[i] = cs.getMinValue(i);
191+ srcInvDiffMinMax[i] = maxNum / (cs.getMaxValue(i) - srcMinVal[i]);
192+ }
193+ cs = dstCM.getColorSpace();
194+ float[] dstMinVal = new float[dstNumComp];
195+ float[] dstDiffMinMax = new float[dstNumComp];
196+ for (int i = 0; i < dstNumComp; i++) {
197+ dstMinVal[i] = cs.getMinValue(i);
198+ dstDiffMinMax[i] = (cs.getMaxValue(i) - dstMinVal[i]) / maxNum;
199+ }
200+ boolean dstHasAlpha = dstCM.hasAlpha();
201+ boolean needSrcAlpha = srcCM.hasAlpha() && dstHasAlpha;
202+ float[] dstColor;
203+ if (dstHasAlpha) {
204+ dstColor = new float[dstNumComp + 1];
205+ } else {
206+ dstColor = new float[dstNumComp];
207+ }
208+ if (precision == 8) {
209+ byte[] srcLine = new byte[w * srcNumComp];
210+ byte[] dstLine = new byte[w * dstNumComp];
211+ Object pixel;
212+ float[] color;
213+ float[] alpha = null;
214+ if (needSrcAlpha) {
215+ alpha = new float[w];
216+ }
217+ int idx;
218+ // TODO check for src npixels = dst npixels
219+ srcIL = new LCMSImageLayout(
220+ srcLine, srcLine.length/getNumInComponents(),
221+ LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
222+ LCMSImageLayout.BYTES_SH(1), getNumInComponents());
223+ dstIL = new LCMSImageLayout(
224+ dstLine, dstLine.length/getNumOutComponents(),
225+ LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
226+ LCMSImageLayout.BYTES_SH(1), getNumOutComponents());
227+ // process each scanline
228+ for (int y = 0; y < h; y++) {
229+ // convert src scanline
230+ pixel = null;
231+ color = null;
232+ idx = 0;
233+ for (int x = 0; x < w; x++) {
234+ pixel = srcRas.getDataElements(x, y, pixel);
235+ color = srcCM.getNormalizedComponents(pixel, color, 0);
236+ for (int i = 0; i < srcNumComp; i++) {
237+ srcLine[idx++] = (byte)
238+ ((color[i] - srcMinVal[i]) * srcInvDiffMinMax[i] +
239+ 0.5f);
240+ }
241+ if (needSrcAlpha) {
242+ alpha[x] = color[srcNumComp];
243+ }
244+ }
245+ // color convert srcLine to dstLine
246+ doTransform(srcIL, dstIL);
247+
248+ // convert dst scanline
249+ pixel = null;
250+ idx = 0;
251+ for (int x = 0; x < w; x++) {
252+ for (int i = 0; i < dstNumComp; i++) {
253+ dstColor[i] = ((float) (dstLine[idx++] & 0xff)) *
254+ dstDiffMinMax[i] + dstMinVal[i];
255+ }
256+ if (needSrcAlpha) {
257+ dstColor[dstNumComp] = alpha[x];
258+ } else if (dstHasAlpha) {
259+ dstColor[dstNumComp] = 1.0f;
260+ }
261+ pixel = dstCM.getDataElements(dstColor, 0, pixel);
262+ dstRas.setDataElements(x, y, pixel);
263+ }
264+ }
265+ } else {
266+ short[] srcLine = new short[w * srcNumComp];
267+ short[] dstLine = new short[w * dstNumComp];
268+ Object pixel;
269+ float[] color;
270+ float[] alpha = null;
271+ if (needSrcAlpha) {
272+ alpha = new float[w];
273+ }
274+ int idx;
275+ srcIL = new LCMSImageLayout(
276+ srcLine, srcLine.length/getNumInComponents(),
277+ LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
278+ LCMSImageLayout.BYTES_SH(2), getNumInComponents()*2);
279+
280+ dstIL = new LCMSImageLayout(
281+ dstLine, dstLine.length/getNumOutComponents(),
282+ LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
283+ LCMSImageLayout.BYTES_SH(2), getNumOutComponents()*2);
284+
285+ // process each scanline
286+ for (int y = 0; y < h; y++) {
287+ // convert src scanline
288+ pixel = null;
289+ color = null;
290+ idx = 0;
291+ for (int x = 0; x < w; x++) {
292+ pixel = srcRas.getDataElements(x, y, pixel);
293+ color = srcCM.getNormalizedComponents(pixel, color, 0);
294+ for (int i = 0; i < srcNumComp; i++) {
295+ srcLine[idx++] = (short)
296+ ((color[i] - srcMinVal[i]) * srcInvDiffMinMax[i] +
297+ 0.5f);
298+ }
299+ if (needSrcAlpha) {
300+ alpha[x] = color[srcNumComp];
301+ }
302+ }
303+ // color convert srcLine to dstLine
304+ doTransform(srcIL, dstIL);
305+
306+ // convert dst scanline
307+ pixel = null;
308+ idx = 0;
309+ for (int x = 0; x < w; x++) {
310+ for (int i = 0; i < dstNumComp; i++) {
311+ dstColor[i] = ((float) (dstLine[idx++] & 0xffff)) *
312+ dstDiffMinMax[i] + dstMinVal[i];
313+ }
314+ if (needSrcAlpha) {
315+ dstColor[dstNumComp] = alpha[x];
316+ } else if (dstHasAlpha) {
317+ dstColor[dstNumComp] = 1.0f;
318+ }
319+ pixel = dstCM.getDataElements(dstColor, 0, pixel);
320+ dstRas.setDataElements(x, y, pixel);
321+ }
322+ }
323+ }
324+ }
325+
326+ public void colorConvert(Raster src, WritableRaster dst,
327+ float[] srcMinVal, float[]srcMaxVal,
328+ float[] dstMinVal, float[]dstMaxVal) {
329+ LCMSImageLayout srcIL, dstIL;
330+
331+ // Can't pass src and dst directly to CMM, so process per scanline
332+ SampleModel srcSM = src.getSampleModel();
333+ SampleModel dstSM = dst.getSampleModel();
334+ int srcTransferType = src.getTransferType();
335+ int dstTransferType = dst.getTransferType();
336+ boolean srcIsFloat, dstIsFloat;
337+ if ((srcTransferType == DataBuffer.TYPE_FLOAT) ||
338+ (srcTransferType == DataBuffer.TYPE_DOUBLE)) {
339+ srcIsFloat = true;
340+ } else {
341+ srcIsFloat = false;
342+ }
343+ if ((dstTransferType == DataBuffer.TYPE_FLOAT) ||
344+ (dstTransferType == DataBuffer.TYPE_DOUBLE)) {
345+ dstIsFloat = true;
346+ } else {
347+ dstIsFloat = false;
348+ }
349+ int w = src.getWidth();
350+ int h = src.getHeight();
351+ int srcNumBands = src.getNumBands();
352+ int dstNumBands = dst.getNumBands();
353+ float[] srcScaleFactor = new float[srcNumBands];
354+ float[] dstScaleFactor = new float[dstNumBands];
355+ float[] srcUseMinVal = new float[srcNumBands];
356+ float[] dstUseMinVal = new float[dstNumBands];
357+ for (int i = 0; i < srcNumBands; i++) {
358+ if (srcIsFloat) {
359+ srcScaleFactor[i] = 65535.0f / (srcMaxVal[i] - srcMinVal[i]);
360+ srcUseMinVal[i] = srcMinVal[i];
361+ } else {
362+ if (srcTransferType == DataBuffer.TYPE_SHORT) {
363+ srcScaleFactor[i] = 65535.0f / 32767.0f;
364+ } else {
365+ srcScaleFactor[i] = 65535.0f /
366+ ((float) ((1 << srcSM.getSampleSize(i)) - 1));
367+ }
368+ srcUseMinVal[i] = 0.0f;
369+ }
370+ }
371+ for (int i = 0; i < dstNumBands; i++) {
372+ if (dstIsFloat) {
373+ dstScaleFactor[i] = (dstMaxVal[i] - dstMinVal[i]) / 65535.0f;
374+ dstUseMinVal[i] = dstMinVal[i];
375+ } else {
376+ if (dstTransferType == DataBuffer.TYPE_SHORT) {
377+ dstScaleFactor[i] = 32767.0f / 65535.0f;
378+ } else {
379+ dstScaleFactor[i] =
380+ ((float) ((1 << dstSM.getSampleSize(i)) - 1)) /
381+ 65535.0f;
382+ }
383+ dstUseMinVal[i] = 0.0f;
384+ }
385+ }
386+ int ys = src.getMinY();
387+ int yd = dst.getMinY();
388+ int xs, xd;
389+ float sample;
390+ short[] srcLine = new short[w * srcNumBands];
391+ short[] dstLine = new short[w * dstNumBands];
392+ int idx;
393+ srcIL = new LCMSImageLayout(
394+ srcLine, srcLine.length/getNumInComponents(),
395+ LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
396+ LCMSImageLayout.BYTES_SH(2), getNumInComponents()*2);
397+
398+ dstIL = new LCMSImageLayout(
399+ dstLine, dstLine.length/getNumOutComponents(),
400+ LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
401+ LCMSImageLayout.BYTES_SH(2), getNumOutComponents()*2);
402+
403+ // process each scanline
404+ for (int y = 0; y < h; y++, ys++, yd++) {
405+ // get src scanline
406+ xs = src.getMinX();
407+ idx = 0;
408+ for (int x = 0; x < w; x++, xs++) {
409+ for (int i = 0; i < srcNumBands; i++) {
410+ sample = src.getSampleFloat(xs, ys, i);
411+ srcLine[idx++] = (short)
412+ ((sample - srcUseMinVal[i]) * srcScaleFactor[i] + 0.5f);
413+ }
414+ }
415+
416+ // color convert srcLine to dstLine
417+ doTransform(srcIL, dstIL);
418+
419+ // store dst scanline
420+ xd = dst.getMinX();
421+ idx = 0;
422+ for (int x = 0; x < w; x++, xd++) {
423+ for (int i = 0; i < dstNumBands; i++) {
424+ sample = ((dstLine[idx++] & 0xffff) * dstScaleFactor[i]) +
425+ dstUseMinVal[i];
426+ dst.setSample(xd, yd, i, sample);
427+ }
428+ }
429+ }
430+ }
431+
432+ public void colorConvert(Raster src, WritableRaster dst) {
433+
434+ LCMSImageLayout srcIL, dstIL;
435+ // Can't pass src and dst directly to CMM, so process per scanline
436+ SampleModel srcSM = src.getSampleModel();
437+ SampleModel dstSM = dst.getSampleModel();
438+ int srcTransferType = src.getTransferType();
439+ int dstTransferType = dst.getTransferType();
440+ int w = src.getWidth();
441+ int h = src.getHeight();
442+ int srcNumBands = src.getNumBands();
443+ int dstNumBands = dst.getNumBands();
444+ int precision = 8;
445+ float maxNum = 255.0f;
446+ for (int i = 0; i < srcNumBands; i++) {
447+ if (srcSM.getSampleSize(i) > 8) {
448+ precision = 16;
449+ maxNum = 65535.0f;
450+ }
451+ }
452+ for (int i = 0; i < dstNumBands; i++) {
453+ if (dstSM.getSampleSize(i) > 8) {
454+ precision = 16;
455+ maxNum = 65535.0f;
456+ }
457+ }
458+ float[] srcScaleFactor = new float[srcNumBands];
459+ float[] dstScaleFactor = new float[dstNumBands];
460+ for (int i = 0; i < srcNumBands; i++) {
461+ if (srcTransferType == DataBuffer.TYPE_SHORT) {
462+ srcScaleFactor[i] = maxNum / 32767.0f;
463+ } else {
464+ srcScaleFactor[i] = maxNum /
465+ ((float) ((1 << srcSM.getSampleSize(i)) - 1));
466+ }
467+ }
468+ for (int i = 0; i < dstNumBands; i++) {
469+ if (dstTransferType == DataBuffer.TYPE_SHORT) {
470+ dstScaleFactor[i] = 32767.0f / maxNum;
471+ } else {
472+ dstScaleFactor[i] =
473+ ((float) ((1 << dstSM.getSampleSize(i)) - 1)) / maxNum;
474+ }
475+ }
476+ int ys = src.getMinY();
477+ int yd = dst.getMinY();
478+ int xs, xd;
479+ int sample;
480+ if (precision == 8) {
481+ byte[] srcLine = new byte[w * srcNumBands];
482+ byte[] dstLine = new byte[w * dstNumBands];
483+ int idx;
484+ // TODO check for src npixels = dst npixels
485+ srcIL = new LCMSImageLayout(
486+ srcLine, srcLine.length/getNumInComponents(),
487+ LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
488+ LCMSImageLayout.BYTES_SH(1), getNumInComponents());
489+ dstIL = new LCMSImageLayout(
490+ dstLine, dstLine.length/getNumOutComponents(),
491+ LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
492+ LCMSImageLayout.BYTES_SH(1), getNumOutComponents());
493+
494+ // process each scanline
495+ for (int y = 0; y < h; y++, ys++, yd++) {
496+ // get src scanline
497+ xs = src.getMinX();
498+ idx = 0;
499+ for (int x = 0; x < w; x++, xs++) {
500+ for (int i = 0; i < srcNumBands; i++) {
501+ sample = src.getSample(xs, ys, i);
502+ srcLine[idx++] = (byte)
503+ ((sample * srcScaleFactor[i]) + 0.5f);
504+ }
505+ }
506+
507+ // color convert srcLine to dstLine
508+ doTransform(srcIL, dstIL);
509+
510+ // store dst scanline
511+ xd = dst.getMinX();
512+ idx = 0;
513+ for (int x = 0; x < w; x++, xd++) {
514+ for (int i = 0; i < dstNumBands; i++) {
515+ sample = (int) (((dstLine[idx++] & 0xff) *
516+ dstScaleFactor[i]) + 0.5f);
517+ dst.setSample(xd, yd, i, sample);
518+ }
519+ }
520+ }
521+ } else {
522+ short[] srcLine = new short[w * srcNumBands];
523+ short[] dstLine = new short[w * dstNumBands];
524+ int idx;
525+ srcIL = new LCMSImageLayout(
526+ srcLine, srcLine.length/getNumInComponents(),
527+ LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
528+ LCMSImageLayout.BYTES_SH(2), getNumInComponents()*2);
529+
530+ dstIL = new LCMSImageLayout(
531+ dstLine, dstLine.length/getNumOutComponents(),
532+ LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
533+ LCMSImageLayout.BYTES_SH(2), getNumOutComponents()*2);
534+
535+ // process each scanline
536+ for (int y = 0; y < h; y++, ys++, yd++) {
537+ // get src scanline
538+ xs = src.getMinX();
539+ idx = 0;
540+ for (int x = 0; x < w; x++, xs++) {
541+ for (int i = 0; i < srcNumBands; i++) {
542+ sample = src.getSample(xs, ys, i);
543+ srcLine[idx++] = (short)
544+ ((sample * srcScaleFactor[i]) + 0.5f);
545+ }
546+ }
547+
548+ // color convert srcLine to dstLine
549+ doTransform(srcIL, dstIL);
550+
551+ // store dst scanline
552+ xd = dst.getMinX();
553+ idx = 0;
554+ for (int x = 0; x < w; x++, xd++) {
555+ for (int i = 0; i < dstNumBands; i++) {
556+ sample = (int) (((dstLine[idx++] & 0xffff) *
557+ dstScaleFactor[i]) + 0.5f);
558+ dst.setSample(xd, yd, i, sample);
559+ }
560+ }
561+ }
562+ }
563+ }
564+
565+ /* convert an array of colors in short format */
566+ /* each color is a contiguous set of array elements */
567+ /* the number of colors is (size of the array) / (number of input/output
568+ components */
569+ public short[] colorConvert(short[] src, short[] dst) {
570+
571+ if (dst == null) {
572+ dst = new short [(src.length/getNumInComponents())*getNumOutComponents()];
573+ }
574+
575+ LCMSImageLayout srcIL = new LCMSImageLayout(
576+ src, src.length/getNumInComponents(),
577+ LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
578+ LCMSImageLayout.BYTES_SH(2), getNumInComponents()*2);
579+
580+ LCMSImageLayout dstIL = new LCMSImageLayout(
581+ dst, dst.length/getNumOutComponents(),
582+ LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
583+ LCMSImageLayout.BYTES_SH(2), getNumOutComponents()*2);
584+
585+ doTransform(srcIL, dstIL);
586+
587+ return dst;
588+ }
589+
590+ public byte[] colorConvert(byte[] src, byte[] dst) {
591+ if (dst == null) {
592+ dst = new byte [(src.length/getNumInComponents())*getNumOutComponents()];
593+ }
594+
595+ LCMSImageLayout srcIL = new LCMSImageLayout(
596+ src, src.length/getNumInComponents(),
597+ LCMSImageLayout.CHANNELS_SH(getNumInComponents()) |
598+ LCMSImageLayout.BYTES_SH(1), getNumInComponents());
599+
600+ LCMSImageLayout dstIL = new LCMSImageLayout(
601+ dst, dst.length/getNumOutComponents(),
602+ LCMSImageLayout.CHANNELS_SH(getNumOutComponents()) |
603+ LCMSImageLayout.BYTES_SH(1), getNumOutComponents());
604+
605+ doTransform(srcIL, dstIL);
606+
607+ return dst;
608+ }
609+}
java/pkg/sun/java2d/cmm/lcms/META-INF/mkfile+6−0
@@ -0,0 +1,6 @@
1+<../../../../../../../mkconfig
2+
3+DIRS=\
4+ services\
5+
6+<$ROOT/mkfiles/mksubdirs
java/pkg/sun/java2d/cmm/lcms/META-INF/services/mkfile+2−0
@@ -0,0 +1,2 @@
1+<../../../../../../../../mkconfig
2+
java/pkg/sun/java2d/cmm/lcms/META-INF/services/sun.java2d.cmm.PCMM+2−0
@@ -0,0 +1,2 @@
1+# Little CMS color management module
2+sun.java2d.cmm.lcms.LCMS
java/pkg/sun/java2d/cmm/lcms/mkfile+14−0
@@ -0,0 +1,14 @@
1+<../../../../../../mkconfig
2+
3+DIRS=\
4+ META-INF\
5+
6+TARG=\
7+ LCMS.dis\
8+ LCMSImageLayout.dis\
9+ LCMSTransform.dis\
10+
11+DISBIN=$ROOT/java/dis/java/java/sun/java2d/cmm/lcms
12+
13+<$ROOT/mkfiles/mkjava
14+<$ROOT/mkfiles/mksubdirs
java/pkg/sun/java2d/cmm/mkfile+17−0
@@ -0,0 +1,17 @@
1+<../../../../../mkconfig
2+
3+DIRS=\
4+ lcms\
5+
6+TARG=\
7+ CMSManager.dis\
8+ ColorTransform.dis\
9+ PCMM.dis\
10+ ProfileActivator.dis\
11+ ProfileDeferralInfo.dis\
12+ ProfileDeferralMgr.dis\
13+
14+DISBIN=$ROOT/java/dis/java/java/sun/java2d/cmm
15+
16+<$ROOT/mkfiles/mkjava
17+<$ROOT/mkfiles/mksubdirs