• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17 /**
18  * @author Oleg V. Khaschansky
19  * @version $Revision$
20  */
21 package org.apache.harmony.awt.gl.color;
22 
23 import java.awt.color.ICC_Profile;
24 import java.security.AccessController;
25 import java.security.PrivilegedAction;
26 import java.util.HashMap;
27 
28 /**
29  * This class is a wrapper for the native CMM library
30  */
31 public class NativeCMM {
32 
33     /**
34      * Storage for profile handles, since they are private
35      * in ICC_Profile, but we need access to them.
36      */
37     private static HashMap<ICC_Profile, Long> profileHandles = new HashMap<ICC_Profile, Long>();
38 
39     private static boolean isCMMLoaded;
40 
addHandle(ICC_Profile key, long handle)41     public static void addHandle(ICC_Profile key, long handle) {
42         profileHandles.put(key, new Long(handle));
43     }
44 
removeHandle(ICC_Profile key)45     public static void removeHandle(ICC_Profile key) {
46         profileHandles.remove(key);
47     }
48 
getHandle(ICC_Profile key)49     public static long getHandle(ICC_Profile key) {
50         return profileHandles.get(key).longValue();
51     }
52 
53     /* ICC profile management */
cmmOpenProfile(byte[] data)54     public static native long cmmOpenProfile(byte[] data);
cmmCloseProfile(long profileID)55     public static native void cmmCloseProfile(long profileID);
cmmGetProfileSize(long profileID)56     public static native int cmmGetProfileSize(long profileID);
cmmGetProfile(long profileID, byte[] data)57     public static native void cmmGetProfile(long profileID, byte[] data);
cmmGetProfileElementSize(long profileID, int signature)58     public static native int cmmGetProfileElementSize(long profileID, int signature);
cmmGetProfileElement(long profileID, int signature, byte[] data)59     public static native void cmmGetProfileElement(long profileID, int signature,
60                                            byte[] data);
cmmSetProfileElement(long profileID, int tagSignature, byte[] data)61     public static native void cmmSetProfileElement(long profileID, int tagSignature,
62                                            byte[] data);
63 
64 
65     /* ICC transforms */
cmmCreateMultiprofileTransform( long[] profileHandles, int[] renderingIntents )66     public static native long cmmCreateMultiprofileTransform(
67             long[] profileHandles,
68             int[] renderingIntents
69         );
cmmDeleteTransform(long transformHandle)70     public static native void cmmDeleteTransform(long transformHandle);
cmmTranslateColors(long transformHandle, NativeImageFormat src, NativeImageFormat dest)71     public static native void cmmTranslateColors(long transformHandle,
72             NativeImageFormat src,
73             NativeImageFormat dest);
74 
loadCMM()75     static void loadCMM() {
76         if (!isCMMLoaded) {
77             AccessController.doPrivileged(
78                   new PrivilegedAction<Void>() {
79                     public Void run() {
80                         System.loadLibrary("lcmm"); //$NON-NLS-1$
81                         return null;
82                     }
83             } );
84             isCMMLoaded = true;
85         }
86     }
87 
88     /* load native CMM library */
89     static {
loadCMM()90         loadCMM();
91     }
92 }
93