blob: 109c08d8ac6cda1d54ba0430a8e5bc1ae7f0c226 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2006 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.java2d.cmm;
27
28import java.awt.color.ColorSpace;
29import java.awt.color.ICC_Profile;
30import java.awt.color.CMMException;
31import java.awt.image.BufferedImage;
32import java.awt.image.Raster;
33import java.awt.image.WritableRaster;
34import java.security.AccessController;
35import java.security.PrivilegedAction;
36import sun.security.action.GetPropertyAction;
37import java.util.ServiceLoader;
38
39public 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.println("(ID=" + profileID + ")");
104 return profileID;
105 }
106
107 public void freeProfile(long profileID) {
108 System.err.println(cName + ".freeProfile(ID=" + 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.print(cName + ".getTagSize(ID=" + profileID +
127 ", TagSig=" + 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.print(cName + ".getTagData(ID=" + profileID +
136 ", TagSig=" + 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}