Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMS.java
41161 views
1
/*
2
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.java2d.cmm.lcms;
27
28
import java.awt.color.CMMException;
29
import java.awt.color.ICC_Profile;
30
31
import sun.java2d.cmm.ColorTransform;
32
import sun.java2d.cmm.PCMM;
33
import sun.java2d.cmm.Profile;
34
35
final class LCMS implements PCMM {
36
37
/* methods invoked from ICC_Profile */
38
@Override
39
public Profile loadProfile(byte[] data) {
40
final Object disposerRef = new Object();
41
42
final long ptr = loadProfileNative(data, disposerRef);
43
44
if (ptr != 0L) {
45
return new LCMSProfile(ptr, disposerRef);
46
}
47
return null;
48
}
49
50
private static LCMSProfile getLcmsProfile(Profile p) {
51
if (p instanceof LCMSProfile) {
52
return (LCMSProfile)p;
53
}
54
throw new CMMException("Invalid profile: " + p);
55
}
56
57
/**
58
* Writes supplied data as a tag into the profile.
59
* Destroys old profile, if new one was successfully
60
* created.
61
*
62
* Returns valid pointer to new profile.
63
*
64
* Throws CMMException if operation fails, preserve old profile from
65
* destruction.
66
*/
67
static native void setTagDataNative(long ptr, int tagSignature, byte[] data);
68
static native byte[] getProfileDataNative(long ptr);
69
static native byte[] getTagNative(long profileID, int signature);
70
private static native long loadProfileNative(byte[] data, Object ref);
71
72
@Override
73
public byte[] getProfileData(Profile p) {
74
return getLcmsProfile(p).getProfileData();
75
}
76
77
@Override
78
public byte[] getTagData(Profile p, int tagSignature) {
79
return getLcmsProfile(p).getTag(tagSignature);
80
}
81
82
@Override
83
public synchronized void setTagData(Profile p, int tagSignature, byte[] data) {
84
getLcmsProfile(p).setTag(tagSignature, data);
85
}
86
87
static synchronized native LCMSProfile getProfileID(ICC_Profile profile);
88
89
/* Helper method used from LCMSColorTransfrom */
90
static long createTransform(
91
LCMSProfile[] profiles, int renderType,
92
int inFormatter, boolean isInIntPacked,
93
int outFormatter, boolean isOutIntPacked,
94
Object disposerRef)
95
{
96
long[] ptrs = new long[profiles.length];
97
98
for (int i = 0; i < profiles.length; i++) {
99
if (profiles[i] == null) throw new CMMException("Unknown profile ID");
100
101
ptrs[i] = profiles[i].getLcmsPtr();
102
}
103
104
return createNativeTransform(ptrs, renderType, inFormatter,
105
isInIntPacked, outFormatter, isOutIntPacked, disposerRef);
106
}
107
108
private static native long createNativeTransform(
109
long[] profileIDs, int renderType,
110
int inFormatter, boolean isInIntPacked,
111
int outFormatter, boolean isOutIntPacked,
112
Object disposerRef);
113
114
/**
115
* Constructs ColorTransform object corresponding to an ICC_profile
116
*/
117
public ColorTransform createTransform(ICC_Profile profile,
118
int renderType,
119
int transformType)
120
{
121
return new LCMSTransform(profile, renderType, renderType);
122
}
123
124
/**
125
* Constructs an ColorTransform object from a list of ColorTransform
126
* objects
127
*/
128
public synchronized ColorTransform createTransform(
129
ColorTransform[] transforms)
130
{
131
return new LCMSTransform(transforms);
132
}
133
134
/* methods invoked from LCMSTransform */
135
public static native void colorConvert(LCMSTransform trans,
136
LCMSImageLayout src,
137
LCMSImageLayout dest);
138
139
public static native void initLCMS(Class<?> Trans, Class<?> IL, Class<?> Pf);
140
141
private LCMS() {};
142
143
private static LCMS theLcms = null;
144
145
@SuppressWarnings("removal")
146
static synchronized PCMM getModule() {
147
if (theLcms != null) {
148
return theLcms;
149
}
150
151
java.security.AccessController.doPrivileged(
152
new java.security.PrivilegedAction<Object>() {
153
public Object run() {
154
/* We need to load awt here because of usage trace and
155
* disposer frameworks
156
*/
157
System.loadLibrary("awt");
158
System.loadLibrary("lcms");
159
return null;
160
}
161
});
162
163
initLCMS(LCMSTransform.class, LCMSImageLayout.class, ICC_Profile.class);
164
165
theLcms = new LCMS();
166
167
return theLcms;
168
}
169
}
170
171