Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/java2d/cmm/CMSManager.java
38918 views
/*1* Copyright (c) 2006, 2013, 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.ColorSpace;28import java.awt.color.ICC_Profile;29import java.awt.color.CMMException;30import java.awt.image.BufferedImage;31import java.awt.image.Raster;32import java.awt.image.WritableRaster;33import java.security.AccessController;34import java.security.PrivilegedAction;35import sun.security.action.GetPropertyAction;36import java.util.ServiceLoader;3738public class CMSManager {39public static ColorSpace GRAYspace; // These two fields allow access40public static ColorSpace LINEAR_RGBspace; // to java.awt.color.ColorSpace41// private fields from other42// packages. The fields are set43// by java.awt.color.ColorSpace44// and read by45// java.awt.image.ColorModel.4647private static PCMM cmmImpl = null;4849public static synchronized PCMM getModule() {50if (cmmImpl != null) {51return cmmImpl;52}5354CMMServiceProvider spi = AccessController.doPrivileged(55new PrivilegedAction<CMMServiceProvider>() {56public CMMServiceProvider run() {57String cmmClass = System.getProperty(58"sun.java2d.cmm", "sun.java2d.cmm.lcms.LcmsServiceProvider");5960ServiceLoader<CMMServiceProvider> cmmLoader61= ServiceLoader.loadInstalled(CMMServiceProvider.class);6263CMMServiceProvider spi = null;6465for (CMMServiceProvider cmm : cmmLoader) {66spi = cmm;67if (cmm.getClass().getName().equals(cmmClass)) {68break;69}70}71return spi;72}73});7475cmmImpl = spi.getColorManagementModule();7677if (cmmImpl == null) {78throw new CMMException("Cannot initialize Color Management System."+79"No CM module found");80}8182GetPropertyAction gpa = new GetPropertyAction("sun.java2d.cmm.trace");83String cmmTrace = (String)AccessController.doPrivileged(gpa);84if (cmmTrace != null) {85cmmImpl = new CMMTracer(cmmImpl);86}8788return cmmImpl;89}9091static synchronized boolean canCreateModule() {92return (cmmImpl == null);93}9495/* CMM trace routines */9697public static class CMMTracer implements PCMM {98PCMM tcmm;99String cName ;100101public CMMTracer(PCMM tcmm) {102this.tcmm = tcmm;103cName = tcmm.getClass().getName();104}105106public Profile loadProfile(byte[] data) {107System.err.print(cName + ".loadProfile");108Profile p = tcmm.loadProfile(data);109System.err.printf("(ID=%s)\n", p.toString());110return p;111}112113public void freeProfile(Profile p) {114System.err.printf(cName + ".freeProfile(ID=%s)\n", p.toString());115tcmm.freeProfile(p);116}117118public int getProfileSize(Profile p) {119System.err.print(cName + ".getProfileSize(ID=" + p + ")");120int size = tcmm.getProfileSize(p);121System.err.println("=" + size);122return size;123}124125public void getProfileData(Profile p, byte[] data) {126System.err.print(cName + ".getProfileData(ID=" + p + ") ");127System.err.println("requested " + data.length + " byte(s)");128tcmm.getProfileData(p, data);129}130131public int getTagSize(Profile p, int tagSignature) {132System.err.printf(cName + ".getTagSize(ID=%x, TagSig=%s)",133p, signatureToString(tagSignature));134int size = tcmm.getTagSize(p, tagSignature);135System.err.println("=" + size);136return size;137}138139public void getTagData(Profile p, int tagSignature,140byte[] data) {141System.err.printf(cName + ".getTagData(ID=%x, TagSig=%s)",142p, signatureToString(tagSignature));143System.err.println(" requested " + data.length + " byte(s)");144tcmm.getTagData(p, tagSignature, data);145}146147public void setTagData(Profile p, int tagSignature,148byte[] data) {149System.err.print(cName + ".setTagData(ID=" + p +150", TagSig=" + tagSignature + ")");151System.err.println(" sending " + data.length + " byte(s)");152tcmm.setTagData(p, tagSignature, data);153}154155/* methods for creating ColorTransforms */156public ColorTransform createTransform(ICC_Profile profile,157int renderType,158int transformType) {159System.err.println(cName + ".createTransform(ICC_Profile,int,int)");160return tcmm.createTransform(profile, renderType, transformType);161}162163public ColorTransform createTransform(ColorTransform[] transforms) {164System.err.println(cName + ".createTransform(ColorTransform[])");165return tcmm.createTransform(transforms);166}167168private static String signatureToString(int sig) {169return String.format("%c%c%c%c",170(char)(0xff & (sig >> 24)),171(char)(0xff & (sig >> 16)),172(char)(0xff & (sig >> 8)),173(char)(0xff & (sig )));174}175}176}177178179