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