Path: blob/master/src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMS.java
41161 views
/*1* Copyright (c) 2007, 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.lcms;2627import java.awt.color.CMMException;28import java.awt.color.ICC_Profile;2930import sun.java2d.cmm.ColorTransform;31import sun.java2d.cmm.PCMM;32import sun.java2d.cmm.Profile;3334final class LCMS implements PCMM {3536/* methods invoked from ICC_Profile */37@Override38public Profile loadProfile(byte[] data) {39final Object disposerRef = new Object();4041final long ptr = loadProfileNative(data, disposerRef);4243if (ptr != 0L) {44return new LCMSProfile(ptr, disposerRef);45}46return null;47}4849private static LCMSProfile getLcmsProfile(Profile p) {50if (p instanceof LCMSProfile) {51return (LCMSProfile)p;52}53throw new CMMException("Invalid profile: " + p);54}5556/**57* Writes supplied data as a tag into the profile.58* Destroys old profile, if new one was successfully59* created.60*61* Returns valid pointer to new profile.62*63* Throws CMMException if operation fails, preserve old profile from64* destruction.65*/66static native void setTagDataNative(long ptr, int tagSignature, byte[] data);67static native byte[] getProfileDataNative(long ptr);68static native byte[] getTagNative(long profileID, int signature);69private static native long loadProfileNative(byte[] data, Object ref);7071@Override72public byte[] getProfileData(Profile p) {73return getLcmsProfile(p).getProfileData();74}7576@Override77public byte[] getTagData(Profile p, int tagSignature) {78return getLcmsProfile(p).getTag(tagSignature);79}8081@Override82public synchronized void setTagData(Profile p, int tagSignature, byte[] data) {83getLcmsProfile(p).setTag(tagSignature, data);84}8586static synchronized native LCMSProfile getProfileID(ICC_Profile profile);8788/* Helper method used from LCMSColorTransfrom */89static long createTransform(90LCMSProfile[] profiles, int renderType,91int inFormatter, boolean isInIntPacked,92int outFormatter, boolean isOutIntPacked,93Object disposerRef)94{95long[] ptrs = new long[profiles.length];9697for (int i = 0; i < profiles.length; i++) {98if (profiles[i] == null) throw new CMMException("Unknown profile ID");99100ptrs[i] = profiles[i].getLcmsPtr();101}102103return createNativeTransform(ptrs, renderType, inFormatter,104isInIntPacked, outFormatter, isOutIntPacked, disposerRef);105}106107private static native long createNativeTransform(108long[] profileIDs, int renderType,109int inFormatter, boolean isInIntPacked,110int outFormatter, boolean isOutIntPacked,111Object disposerRef);112113/**114* Constructs ColorTransform object corresponding to an ICC_profile115*/116public ColorTransform createTransform(ICC_Profile profile,117int renderType,118int transformType)119{120return new LCMSTransform(profile, renderType, renderType);121}122123/**124* Constructs an ColorTransform object from a list of ColorTransform125* objects126*/127public synchronized ColorTransform createTransform(128ColorTransform[] transforms)129{130return new LCMSTransform(transforms);131}132133/* methods invoked from LCMSTransform */134public static native void colorConvert(LCMSTransform trans,135LCMSImageLayout src,136LCMSImageLayout dest);137138public static native void initLCMS(Class<?> Trans, Class<?> IL, Class<?> Pf);139140private LCMS() {};141142private static LCMS theLcms = null;143144@SuppressWarnings("removal")145static synchronized PCMM getModule() {146if (theLcms != null) {147return theLcms;148}149150java.security.AccessController.doPrivileged(151new java.security.PrivilegedAction<Object>() {152public Object run() {153/* We need to load awt here because of usage trace and154* disposer frameworks155*/156System.loadLibrary("awt");157System.loadLibrary("lcms");158return null;159}160});161162initLCMS(LCMSTransform.class, LCMSImageLayout.class, ICC_Profile.class);163164theLcms = new LCMS();165166return theLcms;167}168}169170171