src/java.desktop/share/native/liblcms/LCMS.c
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 33653 jdk/src/java.desktop/share/native/liblcms/LCMS.c@c1ee09fe3274
child 48566 6c986cf7299a
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 28059
diff changeset
     2
 * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2801
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2801
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2801
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2801
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2801
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "sun_java2d_cmm_lcms_LCMS.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "Trace.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "Disposer.h"
24540
41aa84a568f3 8042159: Allow using a system-installed lcms2
omajid
parents: 23010
diff changeset
    33
#include <lcms2.h>
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
    34
#include "jlong.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    36
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    37
#define ALIGNLONG(x) (((x)+3) & ~(3))         // Aligns to DWORD boundary
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    38
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    39
#ifdef USE_BIG_ENDIAN
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    40
#define AdjustEndianess32(a)
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    41
#else
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    42
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    43
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    44
void AdjustEndianess32(cmsUInt8Number *pByte)
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    45
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    46
    cmsUInt8Number temp1;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    47
    cmsUInt8Number temp2;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    48
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    49
    temp1 = *pByte++;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    50
    temp2 = *pByte++;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    51
    *(pByte-1) = *pByte;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    52
    *pByte++ = temp2;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    53
    *(pByte-3) = *pByte;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    54
    *pByte = temp1;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    55
}
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    56
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    57
#endif
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    58
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    59
// Transports to properly encoded values - note that icc profiles does use
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    60
// big endian notation.
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    61
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    62
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    63
cmsInt32Number TransportValue32(cmsInt32Number Value)
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    64
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    65
    cmsInt32Number Temp = Value;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    66
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    67
    AdjustEndianess32((cmsUInt8Number*) &Temp);
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    68
    return Temp;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    69
}
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    70
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#define SigMake(a,b,c,d) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                    ( ( ((int) ((unsigned char) (a))) << 24) | \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                      ( ((int) ((unsigned char) (b))) << 16) | \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                      ( ((int) ((unsigned char) (c))) <<  8) | \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                          (int) ((unsigned char) (d)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
#define TagIdConst(a, b, c, d) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                ((int) SigMake ((a), (b), (c), (d)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
#define SigHead TagIdConst('h','e','a','d')
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#define DT_BYTE     0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
#define DT_SHORT    1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#define DT_INT      2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
#define DT_DOUBLE   3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
/* Default temp profile list size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
#define DF_ICC_BUF_SIZE 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    90
#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
    91
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    92
#ifdef _MSC_VER
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    93
# ifndef snprintf
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    94
#       define snprintf  _snprintf
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    95
# endif
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    96
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
    98
typedef struct lcmsProfile_s {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
    99
    cmsHPROFILE pf;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   100
} lcmsProfile_t, *lcmsProfile_p;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   101
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   102
typedef union {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   103
    cmsTagSignature cms;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   104
    jint j;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   105
} TagSignature_t, *TagSignature_p;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   106
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
static jfieldID Trans_renderType_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
static jfieldID Trans_ID_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
static jfieldID IL_isIntPacked_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
static jfieldID IL_dataType_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
static jfieldID IL_pixelType_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
static jfieldID IL_dataArray_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
static jfieldID IL_offset_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
static jfieldID IL_nextRowOffset_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
static jfieldID IL_width_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
static jfieldID IL_height_fID;
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   117
static jfieldID IL_imageAtOnce_fID;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
JavaVM *javaVM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   121
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
   122
                  const char *errorText) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    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
   125
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   126
    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
   127
                          "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
   128
    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
   129
        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
   130
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   131
    errMsg[count] = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    (*javaVM)->AttachCurrentThread(javaVM, (void**)&env, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    JNU_ThrowByName(env, "java/awt/color/CMMException", errMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 28059
diff changeset
   137
JNIEXPORT jint JNICALL DEF_JNI_OnLoad(JavaVM *jvm, void *reserved) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    javaVM = jvm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   140
    cmsSetLogErrorHandler(errorHandler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    return JNI_VERSION_1_6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   144
void LCMS_freeProfile(JNIEnv *env, jlong ptr) {
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   145
    lcmsProfile_p p = (lcmsProfile_p)jlong_to_ptr(ptr);
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   146
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   147
    if (p != NULL) {
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   148
        if (p->pf != NULL) {
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   149
            cmsCloseProfile(p->pf);
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   150
        }
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   151
        free(p);
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   152
    }
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   153
}
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   154
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
void LCMS_freeTransform(JNIEnv *env, jlong ID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
{
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   157
    cmsHTRANSFORM sTrans = jlong_to_ptr(ID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /* Passed ID is always valid native ref so there is no check for zero */
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   159
    cmsDeleteTransform(sTrans);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * Method:    createNativeTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * Signature: ([JI)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_createNativeTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
  (JNIEnv *env, jclass cls, jlongArray profileIDs, jint renderType,
14884
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   169
   jint inFormatter, jboolean isInIntPacked,
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   170
   jint outFormatter, jboolean isOutIntPacked, jobject disposerRef)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   172
    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
   173
    cmsHPROFILE *iccArray = &_iccArray[0];
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   174
    cmsHTRANSFORM sTrans = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    int i, j, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    jlong* ids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    size = (*env)->GetArrayLength (env, profileIDs);
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   179
    ids = (*env)->GetLongArrayElements(env, profileIDs, 0);
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   180
    if (ids == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   181
        // An exception should have already been thrown.
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   182
        return 0L;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   183
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
14884
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   185
#ifdef _LITTLE_ENDIAN
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   186
    /* Reversing data packed into int for LE archs */
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   187
    if (isInIntPacked) {
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   188
        inFormatter ^= DOSWAP_SH(1);
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   189
    }
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   190
    if (isOutIntPacked) {
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   191
        outFormatter ^= DOSWAP_SH(1);
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   192
    }
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   193
#endif
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   194
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    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
   196
        iccArray = (cmsHPROFILE*) malloc(
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   197
            size*2*sizeof(cmsHPROFILE));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (iccArray == NULL) {
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   199
            (*env)->ReleaseLongArrayElements(env, profileIDs, ids, 0);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   200
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            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
   202
            return 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    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
   208
        cmsColorSpaceSignature cs;
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   209
        lcmsProfile_p profilePtr = (lcmsProfile_p)jlong_to_ptr(ids[i]);
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   210
        cmsHPROFILE icc = profilePtr->pf;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   211
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        iccArray[j++] = icc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        /* Middle non-abstract profiles should be doubled before passing to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         * the cmsCreateMultiprofileTransform function
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         */
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   217
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   218
        cs = cmsGetColorSpace(icc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        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
   220
            cs != cmsSigXYZData && cs != cmsSigLabData)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            iccArray[j++] = icc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   226
    sTrans = cmsCreateMultiprofileTransform(iccArray, j,
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   227
        inFormatter, outFormatter, renderType, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   229
    (*env)->ReleaseLongArrayElements(env, profileIDs, ids, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   231
    if (sTrans == NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        J2dRlsTraceLn(J2D_TRACE_ERROR, "LCMS_createNativeTransform: "
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   233
                                       "sTrans == NULL");
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   234
        if ((*env)->ExceptionOccurred(env) == NULL) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   235
            JNU_ThrowByName(env, "java/awt/color/CMMException",
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   236
                            "Cannot get color transform");
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   237
        }
6868
f9131565859e 6963489: ZDI-CAN-803: Sun JRE ICC Profile Device Information Tag Remote Code Execution Vulnerability
bae
parents: 5506
diff changeset
   238
    } else {
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   239
        Disposer_AddRecord(env, disposerRef, LCMS_freeTransform, ptr_to_jlong(sTrans));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    if (iccArray != &_iccArray[0]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        free(iccArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   245
    return ptr_to_jlong(sTrans);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * Method:    loadProfile
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   252
 * Signature: ([B,Lsun/java2d/cmm/lcms/LCMSProfile;)V
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 */
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   254
JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_loadProfileNative
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   255
  (JNIEnv *env, jobject obj, jbyteArray data, jobject disposerRef)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    jbyte* dataArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    jint dataSize;
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   259
    lcmsProfile_p sProf = NULL;
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   260
    cmsHPROFILE pf;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   262
    if (JNU_IsNull(env, data)) {
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   263
        JNU_ThrowIllegalArgumentException(env, "Invalid profile data");
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   264
        return 0L;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   265
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   266
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    dataArray = (*env)->GetByteArrayElements (env, data, 0);
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   268
    if (dataArray == NULL) {
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   269
        // An exception should have already been thrown.
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   270
        return 0L;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   271
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   272
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   273
    dataSize = (*env)->GetArrayLength (env, data);
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   274
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   275
    pf = cmsOpenProfileFromMem((const void *)dataArray,
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   276
                                     (cmsUInt32Number) dataSize);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   278
    (*env)->ReleaseByteArrayElements (env, data, dataArray, 0);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   279
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   280
    if (pf == NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        JNU_ThrowIllegalArgumentException(env, "Invalid profile data");
14154
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   282
    } else {
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   283
        /* Sanity check: try to save the profile in order
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   284
         * to force basic validation.
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   285
         */
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   286
        cmsUInt32Number pfSize = 0;
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   287
        if (!cmsSaveProfileToMem(pf, NULL, &pfSize) ||
14154
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   288
            pfSize < sizeof(cmsICCHeader))
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   289
        {
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   290
            JNU_ThrowIllegalArgumentException(env, "Invalid profile data");
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   291
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   292
            cmsCloseProfile(pf);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   293
            pf = NULL;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   294
        }
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   295
    }
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   296
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   297
    if (pf != NULL) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   298
        // create profile holder
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   299
        sProf = (lcmsProfile_p)malloc(sizeof(lcmsProfile_t));
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   300
        if (sProf != NULL) {
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   301
            // register the disposer record
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   302
            sProf->pf = pf;
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   303
            Disposer_AddRecord(env, disposerRef, LCMS_freeProfile, ptr_to_jlong(sProf));
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   304
        } else {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   305
            cmsCloseProfile(pf);
14154
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   306
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   309
    return ptr_to_jlong(sProf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
 * Class:     sun_java2d_cmm_lcms_LCMS
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   314
 * Method:    getProfileSizeNative
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
 * Signature: (J)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
 */
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   317
JNIEXPORT jint JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileSizeNative
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
  (JNIEnv *env, jobject obj, jlong id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
{
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   320
    lcmsProfile_p sProf = (lcmsProfile_p)jlong_to_ptr(id);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   321
    cmsUInt32Number pfSize = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   323
    if (cmsSaveProfileToMem(sProf->pf, NULL, &pfSize) && ((jint)pfSize > 0)) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   324
        return (jint)pfSize;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   325
    } else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   326
      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
   327
                      "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
   328
        return -1;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   329
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
 * Class:     sun_java2d_cmm_lcms_LCMS
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   334
 * Method:    getProfileDataNative
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
 * Signature: (J[B)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
 */
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   337
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileDataNative
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
  (JNIEnv *env, jobject obj, jlong id, jbyteArray data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
{
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   340
    lcmsProfile_p sProf = (lcmsProfile_p)jlong_to_ptr(id);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    jint size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    jbyte* dataArray;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   343
    cmsUInt32Number pfSize = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   344
    cmsBool status;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   346
    // determine actual profile size
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   347
    if (!cmsSaveProfileToMem(sProf->pf, NULL, &pfSize)) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   348
        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
   349
                        "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
   350
        return;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   351
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   352
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   353
    // verify java buffer capacity
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   354
    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
   355
    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
   356
        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
   357
                        "Insufficient buffer capacity.");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   358
        return;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   359
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    dataArray = (*env)->GetByteArrayElements (env, data, 0);
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   362
    if (dataArray == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   363
        // An exception should have already been thrown.
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   364
        return;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   365
    }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   366
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   367
    status = cmsSaveProfileToMem(sProf->pf, dataArray, &pfSize);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   368
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   369
    (*env)->ReleaseByteArrayElements (env, data, dataArray, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   371
    if (!status) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   372
        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
   373
                        "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
   374
        return;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   375
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   378
/* Get profile header info */
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   379
static cmsBool _getHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   380
static cmsBool _setHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize);
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   381
static cmsHPROFILE _writeCookedTag(cmsHPROFILE pfTarget, cmsTagSignature sig, jbyte *pData, jint size);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   382
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
 * Method:    getTagData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
 * Signature: (JI[B)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
 */
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   389
JNIEXPORT jbyteArray JNICALL Java_sun_java2d_cmm_lcms_LCMS_getTagNative
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   390
  (JNIEnv *env, jobject obj, jlong id, jint tagSig)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
{
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   392
    lcmsProfile_p sProf = (lcmsProfile_p)jlong_to_ptr(id);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   393
    TagSignature_t sig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   394
    cmsInt32Number tagSize;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   395
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   396
    jbyte* dataArray = NULL;
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   397
    jbyteArray data = NULL;
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   398
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   399
    jint bufSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   401
    sig.j = tagSig;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    if (tagSig == SigHead) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   404
        cmsBool status;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   405
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   406
        // allocate java array
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   407
        bufSize = sizeof(cmsICCHeader);
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   408
        data = (*env)->NewByteArray(env, bufSize);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   409
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   410
        if (data == NULL) {
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   411
            // An exception should have already been thrown.
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   412
            return NULL;
6482
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        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
   416
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   417
        if (dataArray == NULL) {
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   418
            // An exception should have already been thrown.
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   419
            return NULL;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   420
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   421
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   422
        status = _getHeaderInfo(sProf->pf, dataArray, bufSize);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   423
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        (*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
   425
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   426
        if (!status) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   427
            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
   428
                            "ICC Profile header not found");
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   429
            return NULL;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   430
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   431
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   432
        return data;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   435
    if (cmsIsTag(sProf->pf, sig.cms)) {
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   436
        tagSize = cmsReadRawTag(sProf->pf, sig.cms, NULL, 0);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   437
    } else {
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
                        "ICC profile tag not found");
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   440
        return NULL;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   441
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   443
    // allocate java array
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   444
    data = (*env)->NewByteArray(env, tagSize);
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   445
    if (data == NULL) {
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   446
        // An exception should have already been thrown.
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   447
        return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   450
    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
   451
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   452
    if (dataArray == NULL) {
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   453
        // An exception should have already been thrown.
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   454
        return NULL;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   455
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   456
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   457
    bufSize = cmsReadRawTag(sProf->pf, sig.cms, dataArray, tagSize);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   458
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   459
    (*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
   460
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   461
    if (bufSize != tagSize) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   462
        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
   463
                        "Can not get tag data.");
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   464
        return NULL;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   465
    }
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   466
    return data;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
 * Method:    setTagData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
 * Signature: (JI[B)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
 */
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   474
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_setTagDataNative
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
  (JNIEnv *env, jobject obj, jlong id, jint tagSig, jbyteArray data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
{
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   477
    lcmsProfile_p sProf = (lcmsProfile_p)jlong_to_ptr(id);
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   478
    cmsHPROFILE pfReplace = NULL;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   479
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   480
    TagSignature_t sig;
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   481
    cmsBool status = FALSE;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   482
    jbyte* dataArray;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   483
    int tagSize;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   484
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   485
    sig.j = tagSig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   486
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   487
    if (JNU_IsNull(env, data)) {
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   488
        JNU_ThrowIllegalArgumentException(env, "Can not write tag data.");
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   489
        return;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   490
    }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   491
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   492
    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
   493
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   494
    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
   495
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   496
    if (dataArray == NULL) {
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   497
        // An exception should have already been thrown.
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   498
        return;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   499
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   500
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   501
    if (tagSig == SigHead) {
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   502
        status  = _setHeaderInfo(sProf->pf, dataArray, tagSize);
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   503
    } else {
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   504
        /*
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   505
        * New strategy for generic tags: create a place holder,
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   506
        * dump all existing tags there, dump externally supplied
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   507
        * tag, and return the new profile to the java.
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   508
        */
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   509
        pfReplace = _writeCookedTag(sProf->pf, sig.cms, dataArray, tagSize);
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   510
        status = (pfReplace != NULL);
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   511
    }
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   512
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   513
    (*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
   514
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   515
    if (!status) {
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   516
        JNU_ThrowIllegalArgumentException(env, "Can not write tag data.");
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   517
    } else if (pfReplace != NULL) {
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   518
        cmsCloseProfile(sProf->pf);
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   519
        sProf->pf = pfReplace;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   520
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
void* getILData (JNIEnv *env, jobject img, jint* pDataType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                 jobject* pDataObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    void* result = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    *pDataType = (*env)->GetIntField (env, img, IL_dataType_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    *pDataObject = (*env)->GetObjectField(env, img, IL_dataArray_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    switch (*pDataType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        case DT_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            result = (*env)->GetByteArrayElements (env, *pDataObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        case DT_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            result = (*env)->GetShortArrayElements (env, *pDataObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        case DT_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            result = (*env)->GetIntArrayElements (env, *pDataObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        case DT_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            result = (*env)->GetDoubleArrayElements (env, *pDataObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
void releaseILData (JNIEnv *env, void* pData, jint dataType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    jobject dataObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    switch (dataType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        case DT_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            (*env)->ReleaseByteArrayElements(env,dataObject,(jbyte*)pData,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        case DT_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            (*env)->ReleaseShortArrayElements(env,dataObject,(jshort*)pData, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        case DT_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            (*env)->ReleaseIntArrayElements(env,dataObject,(jint*)pData,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        case DT_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            (*env)->ReleaseDoubleArrayElements(env,dataObject,(jdouble*)pData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                                               0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
 * Method:    colorConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
 * Signature: (Lsun/java2d/cmm/lcms/LCMSTransform;Lsun/java2d/cmm/lcms/LCMSImageLayout;Lsun/java2d/cmm/lcms/LCMSImageLayout;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_colorConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
  (JNIEnv *env, jclass obj, jobject trans, jobject src, jobject dst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
{
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   573
    cmsHTRANSFORM sTrans = NULL;
14884
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   574
    int srcDType, dstDType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    int srcOffset, srcNextRowOffset, dstOffset, dstNextRowOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    int width, height, i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    void* inputBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    void* outputBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    char* inputRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    char* outputRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    jobject srcData, dstData;
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   582
    jboolean srcAtOnce = JNI_FALSE, dstAtOnce = JNI_FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    srcOffset = (*env)->GetIntField (env, src, IL_offset_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    srcNextRowOffset = (*env)->GetIntField (env, src, IL_nextRowOffset_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    dstOffset = (*env)->GetIntField (env, dst, IL_offset_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    dstNextRowOffset = (*env)->GetIntField (env, dst, IL_nextRowOffset_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    width = (*env)->GetIntField (env, src, IL_width_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    height = (*env)->GetIntField (env, src, IL_height_fID);
14884
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   590
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   591
    srcAtOnce = (*env)->GetBooleanField(env, src, IL_imageAtOnce_fID);
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   592
    dstAtOnce = (*env)->GetBooleanField(env, dst, IL_imageAtOnce_fID);
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   593
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   594
    sTrans = jlong_to_ptr((*env)->GetLongField (env, trans, Trans_ID_fID));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   596
    if (sTrans == NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        J2dRlsTraceLn(J2D_TRACE_ERROR, "LCMS_colorConvert: transform == NULL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        JNU_ThrowByName(env, "java/awt/color/CMMException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                        "Cannot get color transform");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    inputBuffer = getILData (env, src, &srcDType, &srcData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    if (inputBuffer == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        J2dRlsTraceLn(J2D_TRACE_ERROR, "");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   608
        // An exception should have already been thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    outputBuffer = getILData (env, dst, &dstDType, &dstData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    if (outputBuffer == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        releaseILData(env, inputBuffer, srcDType, srcData);
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   616
        // An exception should have already been thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    inputRow = (char*)inputBuffer + srcOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    outputRow = (char*)outputBuffer + dstOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   623
    if (srcAtOnce && dstAtOnce) {
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   624
        cmsDoTransform(sTrans, inputRow, outputRow, width * height);
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   625
    } else {
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   626
        for (i = 0; i < height; i++) {
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   627
            cmsDoTransform(sTrans, inputRow, outputRow, width);
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   628
            inputRow += srcNextRowOffset;
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   629
            outputRow += dstNextRowOffset;
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   630
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    releaseILData(env, inputBuffer, srcDType, srcData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    releaseILData(env, outputBuffer, dstDType, dstData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
 * Method:    getProfileID
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   640
 * Signature: (Ljava/awt/color/ICC_Profile;)Lsun/java2d/cmm/lcms/LCMSProfile
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
 */
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   642
JNIEXPORT jobject JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileID
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
  (JNIEnv *env, jclass cls, jobject pf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
{
21228
53476a342542 8026702: Fix for 8025429 breaks jdk build on windows
bae
parents: 21226
diff changeset
   645
    jclass clsLcmsProfile;
53476a342542 8026702: Fix for 8025429 breaks jdk build on windows
bae
parents: 21226
diff changeset
   646
    jobject cmmProfile;
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   647
    jfieldID fid = (*env)->GetFieldID (env,
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   648
        (*env)->GetObjectClass(env, pf),
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   649
        "cmmProfile", "Lsun/java2d/cmm/Profile;");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   650
    if (fid == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   651
        return NULL;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   652
    }
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   653
21228
53476a342542 8026702: Fix for 8025429 breaks jdk build on windows
bae
parents: 21226
diff changeset
   654
    clsLcmsProfile = (*env)->FindClass(env,
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   655
            "sun/java2d/cmm/lcms/LCMSProfile");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   656
    if (clsLcmsProfile == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   657
        return NULL;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   658
    }
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   659
21228
53476a342542 8026702: Fix for 8025429 breaks jdk build on windows
bae
parents: 21226
diff changeset
   660
    cmmProfile = (*env)->GetObjectField (env, pf, fid);
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   661
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   662
    if (JNU_IsNull(env, cmmProfile)) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   663
        return NULL;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   664
    }
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   665
    if ((*env)->IsInstanceOf(env, cmmProfile, clsLcmsProfile)) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   666
        return cmmProfile;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   667
    }
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   668
    return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
 * Method:    initLCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
 * Signature: (Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_initLCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
  (JNIEnv *env, jclass cls, jclass Trans, jclass IL, jclass Pf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    /* TODO: move initialization of the IDs to the static blocks of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * corresponding classes to avoid problems with invalidating ids by class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * unloading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    Trans_renderType_fID = (*env)->GetFieldID (env, Trans, "renderType", "I");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   684
    if (Trans_renderType_fID == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   685
        return;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   686
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    Trans_ID_fID = (*env)->GetFieldID (env, Trans, "ID", "J");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   688
    if (Trans_ID_fID == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   689
        return;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   690
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    IL_isIntPacked_fID = (*env)->GetFieldID (env, IL, "isIntPacked", "Z");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   693
    if (IL_isIntPacked_fID == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   694
        return;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   695
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    IL_dataType_fID = (*env)->GetFieldID (env, IL, "dataType", "I");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   697
    if (IL_dataType_fID == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   698
        return;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   699
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    IL_pixelType_fID = (*env)->GetFieldID (env, IL, "pixelType", "I");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   701
    if (IL_pixelType_fID == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   702
        return;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   703
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    IL_dataArray_fID = (*env)->GetFieldID(env, IL, "dataArray",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                                          "Ljava/lang/Object;");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   706
    if (IL_dataArray_fID == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   707
        return;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   708
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    IL_width_fID = (*env)->GetFieldID (env, IL, "width", "I");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   710
    if (IL_width_fID == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   711
        return;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   712
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    IL_height_fID = (*env)->GetFieldID (env, IL, "height", "I");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   714
    if (IL_height_fID == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   715
        return;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   716
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    IL_offset_fID = (*env)->GetFieldID (env, IL, "offset", "I");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   718
    if (IL_offset_fID == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   719
        return;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   720
    }
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   721
    IL_imageAtOnce_fID = (*env)->GetFieldID (env, IL, "imageAtOnce", "Z");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   722
    if (IL_imageAtOnce_fID == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   723
        return;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   724
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    IL_nextRowOffset_fID = (*env)->GetFieldID (env, IL, "nextRowOffset", "I");
21226
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   726
    if (IL_nextRowOffset_fID == NULL) {
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   727
        return;
51ad6a10c2d4 8025429: [parfait] warnings from b107 for sun.java2d.cmm: JNI exception pending
jchen
parents: 19787
diff changeset
   728
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
}
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   730
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   731
static cmsBool _getHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize)
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   732
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   733
  cmsUInt32Number pfSize = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   734
  cmsUInt8Number* pfBuffer = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   735
  cmsBool status = FALSE;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   736
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   737
  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
   738
      pfSize < sizeof(cmsICCHeader) ||
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   739
      bufferSize < (jint)sizeof(cmsICCHeader))
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   740
  {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   741
    return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   742
  }
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   743
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   744
  pfBuffer = malloc(pfSize);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   745
  if (pfBuffer == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   746
    return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   747
  }
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   748
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   749
  // 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
   750
  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
   751
    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
   752
    status = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   753
  }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   754
  free(pfBuffer);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   755
  return status;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   756
}
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   757
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   758
static cmsBool _setHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize)
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   759
{
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   760
  cmsICCHeader pfHeader;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   761
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   762
  if (pBuffer == NULL || bufferSize < (jint)sizeof(cmsICCHeader)) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   763
    return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   764
  }
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   765
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   766
  memcpy(&pfHeader, pBuffer, sizeof(cmsICCHeader));
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   767
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   768
  // 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
   769
  cmsSetHeaderFlags(pf, pfHeader.flags);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   770
  cmsSetHeaderManufacturer(pf, pfHeader.manufacturer);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   771
  cmsSetHeaderModel(pf, pfHeader.model);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   772
  cmsSetHeaderAttributes(pf, pfHeader.attributes);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   773
  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
   774
  cmsSetHeaderRenderingIntent(pf, pfHeader.renderingIntent);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   775
  cmsSetPCS(pf, pfHeader.pcs);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   776
  cmsSetColorSpace(pf, pfHeader.colorSpace);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   777
  cmsSetDeviceClass(pf, pfHeader.deviceClass);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   778
  cmsSetEncodedICCversion(pf, pfHeader.version);
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   779
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   780
  return TRUE;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   781
}
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   782
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   783
/* Returns new profile handler, if it was created successfully,
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   784
   NULL otherwise.
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   785
   */
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   786
static cmsHPROFILE _writeCookedTag(const cmsHPROFILE pfTarget,
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   787
                               const cmsTagSignature sig,
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   788
                               jbyte *pData, jint size)
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   789
{
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   790
    cmsUInt32Number pfSize = 0;
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   791
    const cmsInt32Number tagCount = cmsGetTagCount(pfTarget);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   792
    cmsInt32Number i;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   793
    cmsHPROFILE pfSanity = NULL;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   794
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   795
    cmsICCHeader hdr;
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   796
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   797
    cmsHPROFILE p = cmsCreateProfilePlaceholder(NULL);
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   798
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   799
    if (NULL == p) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   800
        return NULL;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   801
    }
21232
049cc21737df 8026780: Crash on PPC and PPC v2 for Java_awt test suit
bae
parents: 21228
diff changeset
   802
    memset(&hdr, 0, sizeof(cmsICCHeader));
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   803
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   804
    // Populate the placeholder's header according to target profile
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   805
    hdr.flags = cmsGetHeaderFlags(pfTarget);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   806
    hdr.renderingIntent = cmsGetHeaderRenderingIntent(pfTarget);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   807
    hdr.manufacturer = cmsGetHeaderManufacturer(pfTarget);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   808
    hdr.model = cmsGetHeaderModel(pfTarget);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   809
    hdr.pcs = cmsGetPCS(pfTarget);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   810
    hdr.colorSpace = cmsGetColorSpace(pfTarget);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   811
    hdr.deviceClass = cmsGetDeviceClass(pfTarget);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   812
    hdr.version = cmsGetEncodedICCversion(pfTarget);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   813
    cmsGetHeaderAttributes(pfTarget, &hdr.attributes);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   814
    cmsGetHeaderProfileID(pfTarget, (cmsUInt8Number*)&hdr.profileID);
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   815
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   816
    cmsSetHeaderFlags(p, hdr.flags);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   817
    cmsSetHeaderManufacturer(p, hdr.manufacturer);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   818
    cmsSetHeaderModel(p, hdr.model);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   819
    cmsSetHeaderAttributes(p, hdr.attributes);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   820
    cmsSetHeaderProfileID(p, (cmsUInt8Number*)&(hdr.profileID));
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   821
    cmsSetHeaderRenderingIntent(p, hdr.renderingIntent);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   822
    cmsSetPCS(p, hdr.pcs);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   823
    cmsSetColorSpace(p, hdr.colorSpace);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   824
    cmsSetDeviceClass(p, hdr.deviceClass);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   825
    cmsSetEncodedICCversion(p, hdr.version);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   826
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   827
    // now write the user supplied tag
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   828
    if (size <= 0 || !cmsWriteRawTag(p, sig, pData, size)) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   829
        cmsCloseProfile(p);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   830
        return NULL;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   831
    }
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   832
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   833
    // copy tags from the original profile
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   834
    for (i = 0; i < tagCount; i++) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   835
        cmsBool isTagReady = FALSE;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   836
        const cmsTagSignature s = cmsGetTagSignature(pfTarget, i);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   837
        const cmsInt32Number tagSize = cmsReadRawTag(pfTarget, s, NULL, 0);
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   838
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   839
        if (s == sig) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   840
            // skip the user supplied tag
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   841
            continue;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   842
        }
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   843
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   844
        // read raw tag from the original profile
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   845
        if (tagSize > 0) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   846
            cmsUInt8Number* buf = (cmsUInt8Number*)malloc(tagSize);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   847
            if (buf != NULL) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   848
                if (tagSize ==  cmsReadRawTag(pfTarget, s, buf, tagSize)) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   849
                    // now we are ready to write the tag
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   850
                    isTagReady = cmsWriteRawTag(p, s, buf, tagSize);
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   851
                }
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   852
                free(buf);
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   853
            }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   854
        }
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   855
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   856
        if (!isTagReady) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   857
            cmsCloseProfile(p);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   858
            return NULL;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   859
        }
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   860
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   861
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   862
    // now we have all tags moved to the new profile.
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   863
    // do some sanity checks: write it to a memory buffer and read again.
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   864
    if (cmsSaveProfileToMem(p, NULL, &pfSize)) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   865
        void* buf = malloc(pfSize);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   866
        if (buf != NULL) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   867
            // load raw profile data into the buffer
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   868
            if (cmsSaveProfileToMem(p, buf, &pfSize)) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   869
                pfSanity = cmsOpenProfileFromMem(buf, pfSize);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   870
            }
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   871
            free(buf);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   872
        }
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   873
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   874
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   875
    if (pfSanity == NULL) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   876
        // for some reason, we failed to save and read the updated profile
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   877
        // It likely indicates that the profile is not correct, so we report
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   878
        // a failure here.
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   879
        cmsCloseProfile(p);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   880
        p =  NULL;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   881
    } else {
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   882
        // do final check whether we can read and handle the target tag.
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   883
        const void* pTag = cmsReadTag(pfSanity, sig);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   884
        if (pTag == NULL) {
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   885
            // the tag can not be cooked
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   886
            cmsCloseProfile(p);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   887
            p = NULL;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   888
        }
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   889
        cmsCloseProfile(pfSanity);
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   890
        pfSanity = NULL;
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   891
    }
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   892
19783
88ce9a76c992 7043064: sun/java2d/cmm/ tests failed against RI b141 & b138-nightly
bae
parents: 15974
diff changeset
   893
    return p;
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   894
}