Path: blob/master/src/java.desktop/share/classes/sun/java2d/cmm/CMSManager.java
41159 views
/*1* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.cmm;2627import java.awt.color.CMMException;28import java.awt.color.ICC_Profile;29import java.security.AccessController;3031import sun.security.action.GetPropertyAction;3233public final class CMSManager {3435private static volatile PCMM cmmImpl;3637public static PCMM getModule() {38PCMM loc = cmmImpl;39return loc != null ? loc : createModule();40}4142private static synchronized PCMM createModule() {43if (cmmImpl != null) {44return cmmImpl;45}4647GetPropertyAction gpa = new GetPropertyAction("sun.java2d.cmm");48@SuppressWarnings("removal")49String cmmProviderClass = AccessController.doPrivileged(gpa);50CMMServiceProvider provider = null;51if (cmmProviderClass != null) {52try {53Class<?> cls = Class.forName(cmmProviderClass);54provider = (CMMServiceProvider)cls.getConstructor().newInstance();55} catch (ReflectiveOperationException e) {56}57}58if (provider == null) {59provider = new sun.java2d.cmm.lcms.LcmsServiceProvider();60}6162cmmImpl = provider.getColorManagementModule();6364if (cmmImpl == null) {65throw new CMMException("Cannot initialize Color Management System."+66"No CM module found");67}6869gpa = new GetPropertyAction("sun.java2d.cmm.trace");70@SuppressWarnings("removal")71String cmmTrace = AccessController.doPrivileged(gpa);72if (cmmTrace != null) {73cmmImpl = new CMMTracer(cmmImpl);74}7576return cmmImpl;77}7879static synchronized boolean canCreateModule() {80return (cmmImpl == null);81}8283/* CMM trace routines */8485public static class CMMTracer implements PCMM {86PCMM tcmm;87String cName ;8889public CMMTracer(PCMM tcmm) {90this.tcmm = tcmm;91cName = tcmm.getClass().getName();92}9394public Profile loadProfile(byte[] data) {95System.err.print(cName + ".loadProfile");96Profile p = tcmm.loadProfile(data);97System.err.printf("(ID=%s)\n", p.toString());98return p;99}100101public byte[] getProfileData(Profile p) {102System.err.print(cName + ".getProfileData(ID=" + p + ") ");103byte[] data = tcmm.getProfileData(p);104System.err.println("requested " + data.length + " byte(s)");105return data;106}107108public byte[] getTagData(Profile p, int tagSignature) {109System.err.printf(cName + ".getTagData(ID=%x, TagSig=%s)",110p, signatureToString(tagSignature));111byte[] data = tcmm.getTagData(p, tagSignature);112System.err.println(" requested " + data.length + " byte(s)");113return data;114}115116public void setTagData(Profile p, int tagSignature,117byte[] data) {118System.err.print(cName + ".setTagData(ID=" + p +119", TagSig=" + tagSignature + ")");120System.err.println(" sending " + data.length + " byte(s)");121tcmm.setTagData(p, tagSignature, data);122}123124/* methods for creating ColorTransforms */125public ColorTransform createTransform(ICC_Profile profile,126int renderType,127int transformType) {128System.err.println(cName + ".createTransform(ICC_Profile,int,int)");129return tcmm.createTransform(profile, renderType, transformType);130}131132public ColorTransform createTransform(ColorTransform[] transforms) {133System.err.println(cName + ".createTransform(ColorTransform[])");134return tcmm.createTransform(transforms);135}136137private static String signatureToString(int sig) {138return String.format("%c%c%c%c",139(char)(0xff & (sig >> 24)),140(char)(0xff & (sig >> 16)),141(char)(0xff & (sig >> 8)),142(char)(0xff & (sig )));143}144}145}146147148