author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 6879 | 13924eecc282 |
child 7951 | 8479f9f404f8 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include <stdio.h> |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
27 |
#include <stdlib.h> |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
28 |
#include <memory.h> |
2 | 29 |
#include "sun_java2d_cmm_lcms_LCMS.h" |
30 |
#include "jni_util.h" |
|
31 |
#include "Trace.h" |
|
32 |
#include "Disposer.h" |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
33 |
#include "lcms2.h" |
2 | 34 |
|
2392 | 35 |
|
36 |
#define ALIGNLONG(x) (((x)+3) & ~(3)) // Aligns to DWORD boundary |
|
37 |
||
38 |
#ifdef USE_BIG_ENDIAN |
|
39 |
#define AdjustEndianess32(a) |
|
40 |
#else |
|
41 |
||
42 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
43 |
void AdjustEndianess32(cmsUInt8Number *pByte) |
2392 | 44 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
45 |
cmsUInt8Number temp1; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
46 |
cmsUInt8Number temp2; |
2392 | 47 |
|
48 |
temp1 = *pByte++; |
|
49 |
temp2 = *pByte++; |
|
50 |
*(pByte-1) = *pByte; |
|
51 |
*pByte++ = temp2; |
|
52 |
*(pByte-3) = *pByte; |
|
53 |
*pByte = temp1; |
|
54 |
} |
|
55 |
||
56 |
#endif |
|
57 |
||
58 |
// Transports to properly encoded values - note that icc profiles does use |
|
59 |
// big endian notation. |
|
60 |
||
61 |
static |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
62 |
cmsInt32Number TransportValue32(cmsInt32Number Value) |
2392 | 63 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
64 |
cmsInt32Number Temp = Value; |
2392 | 65 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
66 |
AdjustEndianess32((cmsUInt8Number*) &Temp); |
2392 | 67 |
return Temp; |
68 |
} |
|
69 |
||
2 | 70 |
#define SigMake(a,b,c,d) \ |
71 |
( ( ((int) ((unsigned char) (a))) << 24) | \ |
|
72 |
( ((int) ((unsigned char) (b))) << 16) | \ |
|
73 |
( ((int) ((unsigned char) (c))) << 8) | \ |
|
74 |
(int) ((unsigned char) (d))) |
|
75 |
||
76 |
#define TagIdConst(a, b, c, d) \ |
|
77 |
((int) SigMake ((a), (b), (c), (d))) |
|
78 |
||
79 |
#define SigHead TagIdConst('h','e','a','d') |
|
80 |
||
81 |
#define DT_BYTE 0 |
|
82 |
#define DT_SHORT 1 |
|
83 |
#define DT_INT 2 |
|
84 |
#define DT_DOUBLE 3 |
|
85 |
||
86 |
/* Default temp profile list size */ |
|
87 |
#define DF_ICC_BUF_SIZE 32 |
|
88 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
89 |
#define ERR_MSG_SIZE 256 |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
90 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
91 |
#ifdef _MSC_VER |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
92 |
# ifndef snprintf |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
93 |
# define snprintf _snprintf |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
94 |
# endif |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
95 |
#endif |
2 | 96 |
|
97 |
typedef union storeID_s { /* store SProfile stuff in a Java Long */ |
|
98 |
cmsHPROFILE pf; |
|
99 |
cmsHTRANSFORM xf; |
|
100 |
jobject jobj; |
|
101 |
jlong j; |
|
102 |
} storeID_t, *storeID_p; |
|
103 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
104 |
typedef union { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
105 |
cmsTagSignature cms; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
106 |
jint j; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
107 |
} TagSignature_t, *TagSignature_p; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
108 |
|
2 | 109 |
static jfieldID Trans_profileIDs_fID; |
110 |
static jfieldID Trans_renderType_fID; |
|
111 |
static jfieldID Trans_ID_fID; |
|
112 |
static jfieldID IL_isIntPacked_fID; |
|
113 |
static jfieldID IL_dataType_fID; |
|
114 |
static jfieldID IL_pixelType_fID; |
|
115 |
static jfieldID IL_dataArray_fID; |
|
116 |
static jfieldID IL_offset_fID; |
|
117 |
static jfieldID IL_nextRowOffset_fID; |
|
118 |
static jfieldID IL_width_fID; |
|
119 |
static jfieldID IL_height_fID; |
|
120 |
static jfieldID PF_ID_fID; |
|
121 |
||
122 |
JavaVM *javaVM; |
|
123 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
124 |
void errorHandler(cmsContext ContextID, cmsUInt32Number errorCode, |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
125 |
const char *errorText) { |
2 | 126 |
JNIEnv *env; |
127 |
char errMsg[ERR_MSG_SIZE]; |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
128 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
129 |
int count = snprintf(errMsg, ERR_MSG_SIZE, |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
130 |
"LCMS error %d: %s", errorCode, errorText); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
131 |
if (count < 0 || count >= ERR_MSG_SIZE) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
132 |
count = ERR_MSG_SIZE - 1; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
133 |
} |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
134 |
errMsg[count] = 0; |
2 | 135 |
|
136 |
(*javaVM)->AttachCurrentThread(javaVM, (void**)&env, NULL); |
|
137 |
JNU_ThrowByName(env, "java/awt/color/CMMException", errMsg); |
|
138 |
} |
|
139 |
||
140 |
JNIEXPORT int JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { |
|
141 |
javaVM = jvm; |
|
142 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
143 |
cmsSetLogErrorHandler(errorHandler); |
2 | 144 |
return JNI_VERSION_1_6; |
145 |
} |
|
146 |
||
147 |
void LCMS_freeTransform(JNIEnv *env, jlong ID) |
|
148 |
{ |
|
149 |
storeID_t sTrans; |
|
150 |
sTrans.j = ID; |
|
151 |
/* Passed ID is always valid native ref so there is no check for zero */ |
|
152 |
cmsDeleteTransform(sTrans.xf); |
|
153 |
} |
|
154 |
||
155 |
/* |
|
156 |
* Class: sun_java2d_cmm_lcms_LCMS |
|
157 |
* Method: createNativeTransform |
|
158 |
* Signature: ([JI)J |
|
159 |
*/ |
|
160 |
JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_createNativeTransform |
|
161 |
(JNIEnv *env, jclass cls, jlongArray profileIDs, jint renderType, |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
162 |
jint inFormatter, jint outFormatter, jobject disposerRef) |
2 | 163 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
164 |
cmsHPROFILE _iccArray[DF_ICC_BUF_SIZE]; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
165 |
cmsHPROFILE *iccArray = &_iccArray[0]; |
2 | 166 |
storeID_t sTrans; |
167 |
int i, j, size; |
|
168 |
jlong* ids; |
|
169 |
||
170 |
size = (*env)->GetArrayLength (env, profileIDs); |
|
171 |
ids = (*env)->GetPrimitiveArrayCritical(env, profileIDs, 0); |
|
172 |
||
173 |
if (DF_ICC_BUF_SIZE < size*2) { |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
174 |
iccArray = (cmsHPROFILE*) malloc( |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
175 |
size*2*sizeof(cmsHPROFILE)); |
2 | 176 |
if (iccArray == NULL) { |
177 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "getXForm: iccArray == NULL"); |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
178 |
return 0L; |
2 | 179 |
} |
180 |
} |
|
181 |
||
182 |
j = 0; |
|
183 |
for (i = 0; i < size; i++) { |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
184 |
cmsHPROFILE icc; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
185 |
cmsColorSpaceSignature cs; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
186 |
|
2 | 187 |
sTrans.j = ids[i]; |
188 |
icc = sTrans.pf; |
|
189 |
iccArray[j++] = icc; |
|
190 |
||
191 |
/* Middle non-abstract profiles should be doubled before passing to |
|
192 |
* the cmsCreateMultiprofileTransform function |
|
193 |
*/ |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
194 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
195 |
cs = cmsGetColorSpace(icc); |
2 | 196 |
if (size > 2 && i != 0 && i != size - 1 && |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
197 |
cs != cmsSigXYZData && cs != cmsSigLabData) |
2 | 198 |
{ |
199 |
iccArray[j++] = icc; |
|
200 |
} |
|
201 |
} |
|
202 |
||
203 |
sTrans.xf = cmsCreateMultiprofileTransform(iccArray, j, |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
204 |
inFormatter, outFormatter, renderType, 0); |
2 | 205 |
|
206 |
(*env)->ReleasePrimitiveArrayCritical(env, profileIDs, ids, 0); |
|
207 |
||
208 |
if (sTrans.xf == NULL) { |
|
209 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "LCMS_createNativeTransform: " |
|
210 |
"sTrans.xf == NULL"); |
|
211 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
|
212 |
"Cannot get color transform"); |
|
6868
f9131565859e
6963489: ZDI-CAN-803: Sun JRE ICC Profile Device Information Tag Remote Code Execution Vulnerability
bae
parents:
5506
diff
changeset
|
213 |
} else { |
f9131565859e
6963489: ZDI-CAN-803: Sun JRE ICC Profile Device Information Tag Remote Code Execution Vulnerability
bae
parents:
5506
diff
changeset
|
214 |
Disposer_AddRecord(env, disposerRef, LCMS_freeTransform, sTrans.j); |
2 | 215 |
} |
216 |
||
217 |
if (iccArray != &_iccArray[0]) { |
|
218 |
free(iccArray); |
|
219 |
} |
|
220 |
return sTrans.j; |
|
221 |
} |
|
222 |
||
223 |
||
224 |
/* |
|
225 |
* Class: sun_java2d_cmm_lcms_LCMS |
|
226 |
* Method: loadProfile |
|
227 |
* Signature: ([B)J |
|
228 |
*/ |
|
229 |
JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_loadProfile |
|
230 |
(JNIEnv *env, jobject obj, jbyteArray data) |
|
231 |
{ |
|
232 |
jbyte* dataArray; |
|
233 |
jint dataSize; |
|
234 |
storeID_t sProf; |
|
235 |
||
236 |
dataArray = (*env)->GetByteArrayElements (env, data, 0); |
|
237 |
dataSize = (*env)->GetArrayLength (env, data); |
|
238 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
239 |
sProf.pf = cmsOpenProfileFromMem((const void *)dataArray, |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
240 |
(cmsUInt32Number) dataSize); |
2 | 241 |
|
2392 | 242 |
(*env)->ReleaseByteArrayElements (env, data, dataArray, 0); |
243 |
||
2 | 244 |
if (sProf.pf == NULL) { |
245 |
JNU_ThrowIllegalArgumentException(env, "Invalid profile data"); |
|
246 |
} |
|
247 |
||
248 |
return sProf.j; |
|
249 |
} |
|
250 |
||
251 |
/* |
|
252 |
* Class: sun_java2d_cmm_lcms_LCMS |
|
253 |
* Method: freeProfile |
|
254 |
* Signature: (J)V |
|
255 |
*/ |
|
256 |
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_freeProfile |
|
257 |
(JNIEnv *env, jobject obj, jlong id) |
|
258 |
{ |
|
259 |
storeID_t sProf; |
|
260 |
||
261 |
sProf.j = id; |
|
262 |
if (cmsCloseProfile(sProf.pf) == 0) { |
|
263 |
J2dRlsTraceLn1(J2D_TRACE_ERROR, "LCMS_freeProfile: cmsCloseProfile(%d)" |
|
264 |
"== 0", id); |
|
265 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
|
266 |
"Cannot close profile"); |
|
267 |
} |
|
268 |
||
269 |
} |
|
270 |
||
271 |
/* |
|
272 |
* Class: sun_java2d_cmm_lcms_LCMS |
|
273 |
* Method: getProfileSize |
|
274 |
* Signature: (J)I |
|
275 |
*/ |
|
276 |
JNIEXPORT jint JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileSize |
|
277 |
(JNIEnv *env, jobject obj, jlong id) |
|
278 |
{ |
|
279 |
storeID_t sProf; |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
280 |
cmsUInt32Number pfSize = 0; |
2 | 281 |
sProf.j = id; |
282 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
283 |
if (cmsSaveProfileToMem(sProf.pf, NULL, &pfSize) && ((jint)pfSize > 0)) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
284 |
return (jint)pfSize; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
285 |
} else { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
286 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
287 |
"Can not access specified profile."); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
288 |
return -1; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
289 |
} |
2 | 290 |
} |
291 |
||
292 |
/* |
|
293 |
* Class: sun_java2d_cmm_lcms_LCMS |
|
294 |
* Method: getProfileData |
|
295 |
* Signature: (J[B)V |
|
296 |
*/ |
|
297 |
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileData |
|
298 |
(JNIEnv *env, jobject obj, jlong id, jbyteArray data) |
|
299 |
{ |
|
300 |
storeID_t sProf; |
|
301 |
jint size; |
|
302 |
jbyte* dataArray; |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
303 |
cmsUInt32Number pfSize = 0; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
304 |
cmsBool status; |
2 | 305 |
|
306 |
sProf.j = id; |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
307 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
308 |
// determine actual profile size |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
309 |
if (!cmsSaveProfileToMem(sProf.pf, NULL, &pfSize)) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
310 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
311 |
"Can not access specified profile."); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
312 |
return; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
313 |
} |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
314 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
315 |
// verify java buffer capacity |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
316 |
size = (*env)->GetArrayLength(env, data); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
317 |
if (0 >= size || pfSize > (cmsUInt32Number)size) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
318 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
319 |
"Insufficient buffer capacity."); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
320 |
return; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
321 |
} |
2 | 322 |
|
323 |
dataArray = (*env)->GetByteArrayElements (env, data, 0); |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
324 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
325 |
status = cmsSaveProfileToMem(sProf.pf, dataArray, &pfSize); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
326 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
327 |
(*env)->ReleaseByteArrayElements (env, data, dataArray, 0); |
2 | 328 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
329 |
if (!status) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
330 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
331 |
"Can not access specified profile."); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
332 |
return; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
333 |
} |
2 | 334 |
} |
335 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
336 |
/* Get profile header info */ |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
337 |
cmsBool _getHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
338 |
cmsBool _setHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
339 |
|
2 | 340 |
/* |
341 |
* Class: sun_java2d_cmm_lcms_LCMS |
|
342 |
* Method: getTagSize |
|
343 |
* Signature: (JI)I |
|
344 |
*/ |
|
345 |
JNIEXPORT jint JNICALL Java_sun_java2d_cmm_lcms_LCMS_getTagSize |
|
346 |
(JNIEnv *env, jobject obj, jlong id, jint tagSig) |
|
347 |
{ |
|
348 |
storeID_t sProf; |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
349 |
TagSignature_t sig; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
350 |
jint result = -1; |
2 | 351 |
|
352 |
sProf.j = id; |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
353 |
sig.j = tagSig; |
2 | 354 |
|
355 |
if (tagSig == SigHead) { |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
356 |
result = sizeof(cmsICCHeader); |
2 | 357 |
} else { |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
358 |
if (cmsIsTag(sProf.pf, sig.cms)) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
359 |
result = cmsReadRawTag(sProf.pf, sig.cms, NULL, 0); |
2 | 360 |
} else { |
361 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
|
362 |
"ICC profile tag not found"); |
|
363 |
} |
|
364 |
} |
|
365 |
||
366 |
return result; |
|
367 |
} |
|
368 |
||
369 |
/* |
|
370 |
* Class: sun_java2d_cmm_lcms_LCMS |
|
371 |
* Method: getTagData |
|
372 |
* Signature: (JI[B)V |
|
373 |
*/ |
|
374 |
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getTagData |
|
375 |
(JNIEnv *env, jobject obj, jlong id, jint tagSig, jbyteArray data) |
|
376 |
{ |
|
377 |
storeID_t sProf; |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
378 |
TagSignature_t sig; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
379 |
cmsInt32Number tagSize; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
380 |
|
2 | 381 |
jbyte* dataArray; |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
382 |
jint bufSize; |
2 | 383 |
|
384 |
sProf.j = id; |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
385 |
sig.j = tagSig; |
2 | 386 |
|
387 |
if (tagSig == SigHead) { |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
388 |
cmsBool status; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
389 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
390 |
bufSize =(*env)->GetArrayLength(env, data); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
391 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
392 |
if (bufSize < sizeof(cmsICCHeader)) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
393 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
394 |
"Insufficient buffer capacity"); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
395 |
return; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
396 |
} |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
397 |
|
2 | 398 |
dataArray = (*env)->GetByteArrayElements (env, data, 0); |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
399 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
400 |
if (dataArray == NULL) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
401 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
402 |
"Unable to get buffer"); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
403 |
return; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
404 |
} |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
405 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
406 |
status = _getHeaderInfo(sProf.pf, dataArray, bufSize); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
407 |
|
2 | 408 |
(*env)->ReleaseByteArrayElements (env, data, dataArray, 0); |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
409 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
410 |
if (!status) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
411 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
412 |
"ICC Profile header not found"); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
413 |
} |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
414 |
|
2 | 415 |
return; |
416 |
} |
|
417 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
418 |
if (cmsIsTag(sProf.pf, sig.cms)) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
419 |
tagSize = cmsReadRawTag(sProf.pf, sig.cms, NULL, 0); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
420 |
} else { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
421 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
422 |
"ICC profile tag not found"); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
423 |
return; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
424 |
} |
2 | 425 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
426 |
// verify data buffer capacity |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
427 |
bufSize = (*env)->GetArrayLength(env, data); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
428 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
429 |
if (tagSize < 0 || 0 > bufSize || tagSize > bufSize) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
430 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
431 |
"Insufficient buffer capacity."); |
2 | 432 |
return; |
433 |
} |
|
434 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
435 |
dataArray = (*env)->GetByteArrayElements (env, data, 0); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
436 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
437 |
if (dataArray == NULL) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
438 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
439 |
"Unable to get buffer"); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
440 |
return; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
441 |
} |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
442 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
443 |
bufSize = cmsReadRawTag(sProf.pf, sig.cms, dataArray, tagSize); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
444 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
445 |
(*env)->ReleaseByteArrayElements (env, data, dataArray, 0); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
446 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
447 |
if (bufSize != tagSize) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
448 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
449 |
"Can not get tag data."); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
450 |
} |
2 | 451 |
return; |
452 |
} |
|
453 |
||
454 |
/* |
|
455 |
* Class: sun_java2d_cmm_lcms_LCMS |
|
456 |
* Method: setTagData |
|
457 |
* Signature: (JI[B)V |
|
458 |
*/ |
|
459 |
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_setTagData |
|
460 |
(JNIEnv *env, jobject obj, jlong id, jint tagSig, jbyteArray data) |
|
461 |
{ |
|
2392 | 462 |
storeID_t sProf; |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
463 |
TagSignature_t sig; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
464 |
cmsBool status; |
2392 | 465 |
jbyte* dataArray; |
466 |
int tagSize; |
|
467 |
||
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
468 |
sProf.j = id; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
469 |
sig.j = tagSig; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
470 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
471 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
472 |
tagSize =(*env)->GetArrayLength(env, data); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
473 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
474 |
dataArray = (*env)->GetByteArrayElements(env, data, 0); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
475 |
|
2392 | 476 |
if (tagSig == SigHead) { |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
477 |
status = _setHeaderInfo(sProf.pf, dataArray, tagSize); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
478 |
} else { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
479 |
status = cmsWriteRawTag(sProf.pf, sig.cms, dataArray, tagSize); |
2392 | 480 |
} |
481 |
||
482 |
(*env)->ReleaseByteArrayElements(env, data, dataArray, 0); |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
483 |
|
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
484 |
if (!status) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
485 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
486 |
"Can not write tag data."); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
487 |
} |
2 | 488 |
} |
489 |
||
490 |
void* getILData (JNIEnv *env, jobject img, jint* pDataType, |
|
491 |
jobject* pDataObject) { |
|
492 |
void* result = NULL; |
|
493 |
*pDataType = (*env)->GetIntField (env, img, IL_dataType_fID); |
|
494 |
*pDataObject = (*env)->GetObjectField(env, img, IL_dataArray_fID); |
|
495 |
switch (*pDataType) { |
|
496 |
case DT_BYTE: |
|
497 |
result = (*env)->GetByteArrayElements (env, *pDataObject, 0); |
|
498 |
break; |
|
499 |
case DT_SHORT: |
|
500 |
result = (*env)->GetShortArrayElements (env, *pDataObject, 0); |
|
501 |
break; |
|
502 |
case DT_INT: |
|
503 |
result = (*env)->GetIntArrayElements (env, *pDataObject, 0); |
|
504 |
break; |
|
505 |
case DT_DOUBLE: |
|
506 |
result = (*env)->GetDoubleArrayElements (env, *pDataObject, 0); |
|
507 |
break; |
|
508 |
} |
|
509 |
||
510 |
return result; |
|
511 |
} |
|
512 |
||
513 |
void releaseILData (JNIEnv *env, void* pData, jint dataType, |
|
514 |
jobject dataObject) { |
|
515 |
switch (dataType) { |
|
516 |
case DT_BYTE: |
|
517 |
(*env)->ReleaseByteArrayElements(env,dataObject,(jbyte*)pData,0); |
|
518 |
break; |
|
519 |
case DT_SHORT: |
|
520 |
(*env)->ReleaseShortArrayElements(env,dataObject,(jshort*)pData, 0); |
|
521 |
break; |
|
522 |
case DT_INT: |
|
523 |
(*env)->ReleaseIntArrayElements(env,dataObject,(jint*)pData,0); |
|
524 |
break; |
|
525 |
case DT_DOUBLE: |
|
526 |
(*env)->ReleaseDoubleArrayElements(env,dataObject,(jdouble*)pData, |
|
527 |
0); |
|
528 |
break; |
|
529 |
} |
|
530 |
} |
|
531 |
||
532 |
/* |
|
533 |
* Class: sun_java2d_cmm_lcms_LCMS |
|
534 |
* Method: colorConvert |
|
535 |
* Signature: (Lsun/java2d/cmm/lcms/LCMSTransform;Lsun/java2d/cmm/lcms/LCMSImageLayout;Lsun/java2d/cmm/lcms/LCMSImageLayout;)V |
|
536 |
*/ |
|
537 |
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_colorConvert |
|
538 |
(JNIEnv *env, jclass obj, jobject trans, jobject src, jobject dst) |
|
539 |
{ |
|
540 |
storeID_t sTrans; |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
541 |
int inFmt, outFmt, srcDType, dstDType; |
2 | 542 |
int srcOffset, srcNextRowOffset, dstOffset, dstNextRowOffset; |
543 |
int width, height, i; |
|
544 |
void* inputBuffer; |
|
545 |
void* outputBuffer; |
|
546 |
char* inputRow; |
|
547 |
char* outputRow; |
|
548 |
jobject srcData, dstData; |
|
549 |
||
550 |
inFmt = (*env)->GetIntField (env, src, IL_pixelType_fID); |
|
551 |
outFmt = (*env)->GetIntField (env, dst, IL_pixelType_fID); |
|
552 |
srcOffset = (*env)->GetIntField (env, src, IL_offset_fID); |
|
553 |
srcNextRowOffset = (*env)->GetIntField (env, src, IL_nextRowOffset_fID); |
|
554 |
dstOffset = (*env)->GetIntField (env, dst, IL_offset_fID); |
|
555 |
dstNextRowOffset = (*env)->GetIntField (env, dst, IL_nextRowOffset_fID); |
|
556 |
width = (*env)->GetIntField (env, src, IL_width_fID); |
|
557 |
height = (*env)->GetIntField (env, src, IL_height_fID); |
|
558 |
#ifdef _LITTLE_ENDIAN |
|
559 |
/* Reversing data packed into int for LE archs */ |
|
560 |
if ((*env)->GetBooleanField (env, src, IL_isIntPacked_fID) == JNI_TRUE) { |
|
561 |
inFmt ^= DOSWAP_SH(1); |
|
562 |
} |
|
563 |
if ((*env)->GetBooleanField (env, dst, IL_isIntPacked_fID) == JNI_TRUE) { |
|
564 |
outFmt ^= DOSWAP_SH(1); |
|
565 |
} |
|
566 |
#endif |
|
567 |
sTrans.j = (*env)->GetLongField (env, trans, Trans_ID_fID); |
|
568 |
||
569 |
if (sTrans.xf == NULL) { |
|
570 |
J2dRlsTraceLn(J2D_TRACE_ERROR, "LCMS_colorConvert: transform == NULL"); |
|
571 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
|
572 |
"Cannot get color transform"); |
|
573 |
return; |
|
574 |
} |
|
575 |
||
576 |
||
577 |
inputBuffer = getILData (env, src, &srcDType, &srcData); |
|
578 |
||
579 |
if (inputBuffer == NULL) { |
|
580 |
J2dRlsTraceLn(J2D_TRACE_ERROR, ""); |
|
581 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
|
582 |
"Cannot get input data"); |
|
583 |
return; |
|
584 |
} |
|
585 |
||
586 |
outputBuffer = getILData (env, dst, &dstDType, &dstData); |
|
587 |
||
588 |
if (outputBuffer == NULL) { |
|
589 |
releaseILData(env, inputBuffer, srcDType, srcData); |
|
590 |
JNU_ThrowByName(env, "java/awt/color/CMMException", |
|
591 |
"Cannot get output data"); |
|
592 |
return; |
|
593 |
} |
|
594 |
||
595 |
inputRow = (char*)inputBuffer + srcOffset; |
|
596 |
outputRow = (char*)outputBuffer + dstOffset; |
|
597 |
||
598 |
for (i = 0; i < height; i++) { |
|
599 |
cmsDoTransform(sTrans.xf, inputRow, outputRow, width); |
|
600 |
inputRow += srcNextRowOffset; |
|
601 |
outputRow += dstNextRowOffset; |
|
602 |
} |
|
603 |
||
604 |
releaseILData(env, inputBuffer, srcDType, srcData); |
|
605 |
releaseILData(env, outputBuffer, dstDType, dstData); |
|
606 |
} |
|
607 |
||
608 |
/* |
|
609 |
* Class: sun_java2d_cmm_lcms_LCMS |
|
610 |
* Method: getProfileID |
|
611 |
* Signature: (Ljava/awt/color/ICC_Profile;)J |
|
612 |
*/ |
|
613 |
JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileID |
|
614 |
(JNIEnv *env, jclass cls, jobject pf) |
|
615 |
{ |
|
616 |
return (*env)->GetLongField (env, pf, PF_ID_fID); |
|
617 |
} |
|
618 |
||
619 |
/* |
|
620 |
* Class: sun_java2d_cmm_lcms_LCMS |
|
621 |
* Method: initLCMS |
|
622 |
* Signature: (Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;)V |
|
623 |
*/ |
|
624 |
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_initLCMS |
|
625 |
(JNIEnv *env, jclass cls, jclass Trans, jclass IL, jclass Pf) |
|
626 |
{ |
|
627 |
/* TODO: move initialization of the IDs to the static blocks of |
|
628 |
* corresponding classes to avoid problems with invalidating ids by class |
|
629 |
* unloading |
|
630 |
*/ |
|
631 |
Trans_profileIDs_fID = (*env)->GetFieldID (env, Trans, "profileIDs", "[J"); |
|
632 |
Trans_renderType_fID = (*env)->GetFieldID (env, Trans, "renderType", "I"); |
|
633 |
Trans_ID_fID = (*env)->GetFieldID (env, Trans, "ID", "J"); |
|
634 |
||
635 |
IL_isIntPacked_fID = (*env)->GetFieldID (env, IL, "isIntPacked", "Z"); |
|
636 |
IL_dataType_fID = (*env)->GetFieldID (env, IL, "dataType", "I"); |
|
637 |
IL_pixelType_fID = (*env)->GetFieldID (env, IL, "pixelType", "I"); |
|
638 |
IL_dataArray_fID = (*env)->GetFieldID(env, IL, "dataArray", |
|
639 |
"Ljava/lang/Object;"); |
|
640 |
IL_width_fID = (*env)->GetFieldID (env, IL, "width", "I"); |
|
641 |
IL_height_fID = (*env)->GetFieldID (env, IL, "height", "I"); |
|
642 |
IL_offset_fID = (*env)->GetFieldID (env, IL, "offset", "I"); |
|
643 |
IL_nextRowOffset_fID = (*env)->GetFieldID (env, IL, "nextRowOffset", "I"); |
|
644 |
||
645 |
PF_ID_fID = (*env)->GetFieldID (env, Pf, "ID", "J"); |
|
646 |
} |
|
2392 | 647 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
648 |
cmsBool _getHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize) |
2392 | 649 |
{ |
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
650 |
cmsUInt32Number pfSize = 0; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
651 |
cmsUInt8Number* pfBuffer = NULL; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
652 |
cmsBool status = FALSE; |
2392 | 653 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
654 |
if (!cmsSaveProfileToMem(pf, NULL, &pfSize) || |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
655 |
pfSize < sizeof(cmsICCHeader) || |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
656 |
bufferSize < sizeof(cmsICCHeader)) |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
657 |
{ |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
658 |
return FALSE; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
659 |
} |
2392 | 660 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
661 |
pfBuffer = malloc(pfSize); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
662 |
if (pfBuffer == NULL) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
663 |
return FALSE; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
664 |
} |
2392 | 665 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
666 |
// load raw profile data into the buffer |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
667 |
if (cmsSaveProfileToMem(pf, pfBuffer, &pfSize)) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
668 |
memcpy(pBuffer, pfBuffer, sizeof(cmsICCHeader)); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
669 |
status = TRUE; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
670 |
} |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
671 |
free(pfBuffer); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
672 |
return status; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
673 |
} |
2392 | 674 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
675 |
cmsBool _setHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize) |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
676 |
{ |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
677 |
cmsICCHeader pfHeader = { 0 }; |
2392 | 678 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
679 |
if (pBuffer == NULL || bufferSize < sizeof(cmsICCHeader)) { |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
680 |
return FALSE; |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
681 |
} |
2392 | 682 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
683 |
memcpy(&pfHeader, pBuffer, sizeof(cmsICCHeader)); |
2392 | 684 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
685 |
// now set header fields, which we can access using the lcms2 public API |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
686 |
cmsSetHeaderFlags(pf, pfHeader.flags); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
687 |
cmsSetHeaderManufacturer(pf, pfHeader.manufacturer); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
688 |
cmsSetHeaderModel(pf, pfHeader.model); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
689 |
cmsSetHeaderAttributes(pf, pfHeader.attributes); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
690 |
cmsSetHeaderProfileID(pf, (cmsUInt8Number*)&(pfHeader.profileID)); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
691 |
cmsSetHeaderRenderingIntent(pf, pfHeader.renderingIntent); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
692 |
cmsSetPCS(pf, pfHeader.pcs); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
693 |
cmsSetColorSpace(pf, pfHeader.colorSpace); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
694 |
cmsSetDeviceClass(pf, pfHeader.deviceClass); |
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
695 |
cmsSetEncodedICCversion(pf, pfHeader.version); |
2392 | 696 |
|
6482
0f6a4442b29e
6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents:
5506
diff
changeset
|
697 |
return TRUE; |
2392 | 698 |
} |