0N/A/*
3261N/A * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d.cmm;
0N/A
0N/Aimport java.awt.color.ColorSpace;
0N/Aimport java.awt.color.ICC_Profile;
0N/Aimport java.awt.color.CMMException;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.Raster;
0N/Aimport java.awt.image.WritableRaster;
0N/Aimport java.security.AccessController;
0N/Aimport java.security.PrivilegedAction;
0N/Aimport sun.security.action.GetPropertyAction;
0N/Aimport java.util.ServiceLoader;
0N/A
0N/Apublic class CMSManager {
0N/A public static ColorSpace GRAYspace; // These two fields allow access
0N/A public static ColorSpace LINEAR_RGBspace; // to java.awt.color.ColorSpace
0N/A // private fields from other
0N/A // packages. The fields are set
0N/A // by java.awt.color.ColorSpace
0N/A // and read by
0N/A // java.awt.image.ColorModel.
0N/A
0N/A private static PCMM cmmImpl = null;
0N/A
0N/A public static synchronized PCMM getModule() {
0N/A if (cmmImpl != null) {
0N/A return cmmImpl;
0N/A }
0N/A
0N/A cmmImpl = (PCMM)AccessController.doPrivileged(new PrivilegedAction() {
0N/A public Object run() {
0N/A String cmmClass = System.getProperty(
0N/A "sun.java2d.cmm", "sun.java2d.cmm.kcms.CMM");
0N/A
0N/A ServiceLoader<PCMM> cmmLoader
0N/A = ServiceLoader.loadInstalled(PCMM.class);
0N/A
0N/A PCMM service = null;
0N/A
0N/A for (PCMM cmm : cmmLoader) {
0N/A service = cmm;
0N/A if (cmm.getClass().getName().equals(cmmClass)) {
0N/A break;
0N/A }
0N/A }
0N/A return service;
0N/A }
0N/A });
0N/A
0N/A if (cmmImpl == null) {
0N/A throw new CMMException("Cannot initialize Color Management System."+
0N/A "No CM module found");
0N/A }
0N/A
0N/A GetPropertyAction gpa = new GetPropertyAction("sun.java2d.cmm.trace");
0N/A String cmmTrace = (String)AccessController.doPrivileged(gpa);
0N/A if (cmmTrace != null) {
0N/A cmmImpl = new CMMTracer(cmmImpl);
0N/A }
0N/A
0N/A return cmmImpl;
0N/A }
0N/A
0N/A /* CMM trace routines */
0N/A
0N/A public static class CMMTracer implements PCMM {
0N/A PCMM tcmm;
0N/A String cName ;
0N/A
0N/A public CMMTracer(PCMM tcmm) {
0N/A this.tcmm = tcmm;
0N/A cName = tcmm.getClass().getName();
0N/A }
0N/A
0N/A public long loadProfile(byte[] data) {
0N/A System.err.print(cName + ".loadProfile");
0N/A long profileID = tcmm.loadProfile(data);
2693N/A System.err.printf("(ID=%x)\n", profileID);
0N/A return profileID;
0N/A }
0N/A
0N/A public void freeProfile(long profileID) {
2693N/A System.err.printf(cName + ".freeProfile(ID=%x)\n", profileID);
0N/A tcmm.freeProfile(profileID);
0N/A }
0N/A
0N/A public int getProfileSize(long profileID) {
0N/A System.err.print(cName + ".getProfileSize(ID=" + profileID + ")");
0N/A int size = tcmm.getProfileSize(profileID);
0N/A System.err.println("=" + size);
0N/A return size;
0N/A }
0N/A
0N/A public void getProfileData(long profileID, byte[] data) {
0N/A System.err.print(cName + ".getProfileData(ID=" + profileID + ") ");
0N/A System.err.println("requested " + data.length + " byte(s)");
0N/A tcmm.getProfileData(profileID, data);
0N/A }
0N/A
0N/A public int getTagSize(long profileID, int tagSignature) {
2693N/A System.err.printf(cName + ".getTagSize(ID=%x, TagSig=%s)",
2693N/A profileID, signatureToString(tagSignature));
0N/A int size = tcmm.getTagSize(profileID, tagSignature);
0N/A System.err.println("=" + size);
0N/A return size;
0N/A }
0N/A
0N/A public void getTagData(long profileID, int tagSignature,
0N/A byte[] data) {
2693N/A System.err.printf(cName + ".getTagData(ID=%x, TagSig=%s)",
2693N/A profileID, signatureToString(tagSignature));
0N/A System.err.println(" requested " + data.length + " byte(s)");
0N/A tcmm.getTagData(profileID, tagSignature, data);
0N/A }
0N/A
0N/A public void setTagData(long profileID, int tagSignature,
0N/A byte[] data) {
0N/A System.err.print(cName + ".setTagData(ID=" + profileID +
0N/A ", TagSig=" + tagSignature + ")");
0N/A System.err.println(" sending " + data.length + " byte(s)");
0N/A tcmm.setTagData(profileID, tagSignature, data);
0N/A }
0N/A
0N/A /* methods for creating ColorTransforms */
0N/A public ColorTransform createTransform(ICC_Profile profile,
0N/A int renderType,
0N/A int transformType) {
0N/A System.err.println(cName + ".createTransform(ICC_Profile,int,int)");
0N/A return tcmm.createTransform(profile, renderType, transformType);
0N/A }
0N/A
0N/A public ColorTransform createTransform(ColorTransform[] transforms) {
0N/A System.err.println(cName + ".createTransform(ColorTransform[])");
0N/A return tcmm.createTransform(transforms);
0N/A }
2693N/A
2693N/A private static String signatureToString(int sig) {
2693N/A return String.format("%c%c%c%c",
2693N/A (char)(0xff & (sig >> 24)),
2693N/A (char)(0xff & (sig >> 16)),
2693N/A (char)(0xff & (sig >> 8)),
2693N/A (char)(0xff & (sig )));
2693N/A }
0N/A }
0N/A}