jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c
author bae
Thu, 07 Mar 2013 14:05:21 +0400
changeset 15974 91b0e63e6e83
parent 14884 74d1acdb7ee4
child 19783 88ce9a76c992
permissions -rw-r--r--
8005530: [lcms] Improve performance of ColorConverOp for default destinations Reviewed-by: prr, jgodinez
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
typedef union storeID_s {    /* store SProfile stuff in a Java Long */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    cmsHPROFILE pf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    cmsHTRANSFORM xf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    jobject jobj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    jlong j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
} storeID_t, *storeID_p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   104
typedef union {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   105
    cmsTagSignature cms;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   106
    jint j;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   107
} TagSignature_t, *TagSignature_p;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   108
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
static jfieldID Trans_profileIDs_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
static jfieldID Trans_renderType_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
static jfieldID Trans_ID_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
static jfieldID IL_isIntPacked_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
static jfieldID IL_dataType_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
static jfieldID IL_pixelType_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
static jfieldID IL_dataArray_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
static jfieldID IL_offset_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
static jfieldID IL_nextRowOffset_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
static jfieldID IL_width_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
static jfieldID IL_height_fID;
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   120
static jfieldID IL_imageAtOnce_fID;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
static jfieldID PF_ID_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
JavaVM *javaVM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   125
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
   126
                  const char *errorText) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    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
   129
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   130
    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
   131
                          "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
   132
    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
   133
        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
   134
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   135
    errMsg[count] = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    (*javaVM)->AttachCurrentThread(javaVM, (void**)&env, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    JNU_ThrowByName(env, "java/awt/color/CMMException", errMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
7951
8479f9f404f8 7002766: Java2d: Changes to correct c/c++ language issues for use of parfait
bae
parents: 7668
diff changeset
   141
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    javaVM = jvm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   144
    cmsSetLogErrorHandler(errorHandler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    return JNI_VERSION_1_6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
void LCMS_freeTransform(JNIEnv *env, jlong ID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    storeID_t sTrans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    sTrans.j = ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /* Passed ID is always valid native ref so there is no check for zero */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    cmsDeleteTransform(sTrans.xf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * Method:    createNativeTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * Signature: ([JI)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_createNativeTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
  (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
   163
   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
   164
   jint outFormatter, jboolean isOutIntPacked, jobject disposerRef)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   166
    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
   167
    cmsHPROFILE *iccArray = &_iccArray[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    storeID_t sTrans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    int i, j, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    jlong* ids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    size = (*env)->GetArrayLength (env, profileIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    ids = (*env)->GetPrimitiveArrayCritical(env, profileIDs, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
14884
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   175
#ifdef _LITTLE_ENDIAN
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   176
    /* 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
   177
    if (isInIntPacked) {
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   178
        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
   179
    }
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   180
    if (isOutIntPacked) {
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   181
        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
   182
    }
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   183
#endif
74d1acdb7ee4 7124245: [lcms] ColorConvertOp to color space CS_GRAY apparently converts orange to 244,244,0
bae
parents: 14154
diff changeset
   184
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    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
   186
        iccArray = (cmsHPROFILE*) malloc(
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   187
            size*2*sizeof(cmsHPROFILE));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (iccArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            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
   190
            return 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    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
   196
        cmsHPROFILE icc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   197
        cmsColorSpaceSignature cs;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   198
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        sTrans.j = ids[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        icc = sTrans.pf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        iccArray[j++] = icc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        /* Middle non-abstract profiles should be doubled before passing to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         * the cmsCreateMultiprofileTransform function
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
         */
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   206
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   207
        cs = cmsGetColorSpace(icc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        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
   209
            cs != cmsSigXYZData && cs != cmsSigLabData)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            iccArray[j++] = icc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    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
   216
        inFormatter, outFormatter, renderType, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    (*env)->ReleasePrimitiveArrayCritical(env, profileIDs, ids, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    if (sTrans.xf == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        J2dRlsTraceLn(J2D_TRACE_ERROR, "LCMS_createNativeTransform: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                       "sTrans.xf == NULL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        JNU_ThrowByName(env, "java/awt/color/CMMException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                        "Cannot get color transform");
6868
f9131565859e 6963489: ZDI-CAN-803: Sun JRE ICC Profile Device Information Tag Remote Code Execution Vulnerability
bae
parents: 5506
diff changeset
   225
    } else {
f9131565859e 6963489: ZDI-CAN-803: Sun JRE ICC Profile Device Information Tag Remote Code Execution Vulnerability
bae
parents: 5506
diff changeset
   226
        Disposer_AddRecord(env, disposerRef, LCMS_freeTransform, sTrans.j);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    if (iccArray != &_iccArray[0]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        free(iccArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    return sTrans.j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * Method:    loadProfile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 * Signature: ([B)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 */
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   241
JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_loadProfileNative
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
  (JNIEnv *env, jobject obj, jbyteArray data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    jbyte* dataArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    jint dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    storeID_t sProf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   248
    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
   249
        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
   250
        return 0L;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   251
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   252
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    dataArray = (*env)->GetByteArrayElements (env, data, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    dataSize = (*env)->GetArrayLength (env, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   256
    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
   257
        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
   258
        return 0L;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   259
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   260
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   261
    sProf.pf = cmsOpenProfileFromMem((const void *)dataArray,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   262
                                     (cmsUInt32Number) dataSize);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   264
    (*env)->ReleaseByteArrayElements (env, data, dataArray, 0);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   265
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    if (sProf.pf == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        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
   268
    } else {
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   269
        /* 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
   270
         * to force basic validation.
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   271
         */
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   272
        cmsUInt32Number pfSize = 0;
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   273
        if (!cmsSaveProfileToMem(sProf.pf, NULL, &pfSize) ||
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   274
            pfSize < sizeof(cmsICCHeader))
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   275
        {
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   276
            JNU_ThrowIllegalArgumentException(env, "Invalid profile data");
9acc7f86a458 7051394: NullPointerException when running regression tests LoadProfileTest by using openjdk-7-b144
bae
parents: 9784
diff changeset
   277
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    return sProf.j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 * Method:    freeProfile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 * Signature: (J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 */
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   288
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_freeProfileNative
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
  (JNIEnv *env, jobject obj, jlong id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    storeID_t sProf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    sProf.j = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    if (cmsCloseProfile(sProf.pf) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        J2dRlsTraceLn1(J2D_TRACE_ERROR, "LCMS_freeProfile: cmsCloseProfile(%d)"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                       "== 0", id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        JNU_ThrowByName(env, "java/awt/color/CMMException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        "Cannot close profile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 * Method:    getProfileSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 * Signature: (J)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
JNIEXPORT jint JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
  (JNIEnv *env, jobject obj, jlong id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    storeID_t sProf;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   312
    cmsUInt32Number pfSize = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    sProf.j = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   315
    if (cmsSaveProfileToMem(sProf.pf, NULL, &pfSize) && ((jint)pfSize > 0)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   316
        return (jint)pfSize;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   317
    } else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   318
      JNU_ThrowByName(env, "java/awt/color/CMMException",
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   319
                      "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
   320
        return -1;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   321
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
 * Method:    getProfileData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
 * Signature: (J[B)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
  (JNIEnv *env, jobject obj, jlong id, jbyteArray data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    storeID_t sProf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    jint size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    jbyte* dataArray;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   335
    cmsUInt32Number pfSize = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   336
    cmsBool status;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    sProf.j = id;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   339
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   340
    // determine actual profile size
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   341
    if (!cmsSaveProfileToMem(sProf.pf, NULL, &pfSize)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   342
        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
   343
                        "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
   344
        return;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   345
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   346
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   347
    // verify java buffer capacity
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   348
    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
   349
    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
   350
        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
   351
                        "Insufficient buffer capacity.");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   352
        return;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   353
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    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
   356
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   357
    status = cmsSaveProfileToMem(sProf.pf, dataArray, &pfSize);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   358
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   359
    (*env)->ReleaseByteArrayElements (env, data, dataArray, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   361
    if (!status) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   362
        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
   363
                        "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
   364
        return;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   365
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   368
/* 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
   369
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
   370
static cmsBool _setHeaderInfo(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
   371
static cmsBool _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
   372
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
 * Method:    getTagData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
 * Signature: (JI[B)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
 */
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   379
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
   380
  (JNIEnv *env, jobject obj, jlong id, jint tagSig)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    storeID_t sProf;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   383
    TagSignature_t sig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   384
    cmsInt32Number tagSize;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   385
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   386
    jbyte* dataArray = NULL;
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   387
    jbyteArray data = NULL;
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   388
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   389
    jint bufSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    sProf.j = id;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   392
    sig.j = tagSig;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    if (tagSig == SigHead) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   395
        cmsBool status;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   396
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   397
        // allocate java array
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   398
        bufSize = sizeof(cmsICCHeader);
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   399
        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
   400
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   401
        if (data == NULL) {
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   402
            JNU_ThrowByName(env, "java/awt/color/CMMException",
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   403
                            "Unable to allocate buffer");
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   404
            return NULL;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   405
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   406
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        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
   408
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   409
        if (dataArray == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   410
           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
   411
                            "Unable to get buffer");
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   412
           return NULL;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   413
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   414
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   415
        status = _getHeaderInfo(sProf.pf, dataArray, bufSize);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   416
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        (*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
   418
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   419
        if (!status) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   420
            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
   421
                            "ICC Profile header not found");
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   422
            return NULL;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   423
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   424
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   425
        return data;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   428
    if (cmsIsTag(sProf.pf, sig.cms)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   429
        tagSize = cmsReadRawTag(sProf.pf, sig.cms, NULL, 0);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   430
    } else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   431
        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
   432
                        "ICC profile tag not found");
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   433
        return NULL;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   434
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   436
    // allocate java array
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   437
    data = (*env)->NewByteArray(env, tagSize);
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   438
    if (data == NULL) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   439
        JNU_ThrowByName(env, "java/awt/color/CMMException",
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   440
                        "Unable to allocate buffer");
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   441
        return NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   444
    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
   445
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   446
    if (dataArray == NULL) {
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
                        "Unable to get buffer");
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
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   451
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   452
    bufSize = cmsReadRawTag(sProf.pf, sig.cms, dataArray, tagSize);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   453
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   454
    (*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
   455
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   456
    if (bufSize != tagSize) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   457
        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
   458
                        "Can not get tag data.");
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   459
        return NULL;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   460
    }
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   461
    return data;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
 * Method:    setTagData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
 * Signature: (JI[B)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
 */
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   469
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_setTagDataNative
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
  (JNIEnv *env, jobject obj, jlong id, jint tagSig, jbyteArray data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
{
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   472
    storeID_t sProf;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   473
    TagSignature_t sig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   474
    cmsBool status;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   475
    jbyte* dataArray;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   476
    int tagSize;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   477
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   478
    sProf.j = id;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   479
    sig.j = tagSig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   480
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   481
    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
   482
        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
   483
        return;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   484
    }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   485
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   486
    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
   487
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   488
    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
   489
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   490
    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
   491
        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
   492
        return;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   493
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   494
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   495
    if (tagSig == SigHead) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   496
        status = _setHeaderInfo(sProf.pf, dataArray, tagSize);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   497
    } else {
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   498
        status = _writeCookedTag(sProf.pf, sig.cms, dataArray, tagSize);
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   499
    }
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   500
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   501
    (*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
   502
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   503
    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
   504
        JNU_ThrowIllegalArgumentException(env, "Can not write tag data.");
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   505
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
void* getILData (JNIEnv *env, jobject img, jint* pDataType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                 jobject* pDataObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    void* result = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    *pDataType = (*env)->GetIntField (env, img, IL_dataType_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    *pDataObject = (*env)->GetObjectField(env, img, IL_dataArray_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    switch (*pDataType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        case DT_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            result = (*env)->GetByteArrayElements (env, *pDataObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        case DT_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            result = (*env)->GetShortArrayElements (env, *pDataObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        case DT_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            result = (*env)->GetIntArrayElements (env, *pDataObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        case DT_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            result = (*env)->GetDoubleArrayElements (env, *pDataObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
void releaseILData (JNIEnv *env, void* pData, jint dataType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    jobject dataObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    switch (dataType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        case DT_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            (*env)->ReleaseByteArrayElements(env,dataObject,(jbyte*)pData,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        case DT_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            (*env)->ReleaseShortArrayElements(env,dataObject,(jshort*)pData, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        case DT_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            (*env)->ReleaseIntArrayElements(env,dataObject,(jint*)pData,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        case DT_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            (*env)->ReleaseDoubleArrayElements(env,dataObject,(jdouble*)pData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                                               0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
 * Method:    colorConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
 * Signature: (Lsun/java2d/cmm/lcms/LCMSTransform;Lsun/java2d/cmm/lcms/LCMSImageLayout;Lsun/java2d/cmm/lcms/LCMSImageLayout;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_colorConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
  (JNIEnv *env, jclass obj, jobject trans, jobject src, jobject dst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    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
   559
    int srcDType, dstDType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    int srcOffset, srcNextRowOffset, dstOffset, dstNextRowOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    int width, height, i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    void* inputBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    void* outputBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    char* inputRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    char* outputRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    jobject srcData, dstData;
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   567
    jboolean srcAtOnce = JNI_FALSE, dstAtOnce = JNI_FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    srcOffset = (*env)->GetIntField (env, src, IL_offset_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    srcNextRowOffset = (*env)->GetIntField (env, src, IL_nextRowOffset_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    dstOffset = (*env)->GetIntField (env, dst, IL_offset_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    dstNextRowOffset = (*env)->GetIntField (env, dst, IL_nextRowOffset_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    width = (*env)->GetIntField (env, src, IL_width_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    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
   575
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   576
    srcAtOnce = (*env)->GetBooleanField(env, src, IL_imageAtOnce_fID);
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   577
    dstAtOnce = (*env)->GetBooleanField(env, dst, IL_imageAtOnce_fID);
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   578
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    sTrans.j = (*env)->GetLongField (env, trans, Trans_ID_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    if (sTrans.xf == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        J2dRlsTraceLn(J2D_TRACE_ERROR, "LCMS_colorConvert: transform == NULL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        JNU_ThrowByName(env, "java/awt/color/CMMException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                        "Cannot get color transform");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    inputBuffer = getILData (env, src, &srcDType, &srcData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    if (inputBuffer == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        J2dRlsTraceLn(J2D_TRACE_ERROR, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        JNU_ThrowByName(env, "java/awt/color/CMMException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                        "Cannot get input data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    outputBuffer = getILData (env, dst, &dstDType, &dstData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    if (outputBuffer == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        releaseILData(env, inputBuffer, srcDType, srcData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        JNU_ThrowByName(env, "java/awt/color/CMMException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                        "Cannot get output data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    inputRow = (char*)inputBuffer + srcOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    outputRow = (char*)outputBuffer + dstOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
15974
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   610
    if (srcAtOnce && dstAtOnce) {
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   611
        cmsDoTransform(sTrans.xf, inputRow, outputRow, width * height);
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   612
    } else {
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   613
        for (i = 0; i < height; i++) {
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   614
            cmsDoTransform(sTrans.xf, inputRow, outputRow, width);
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   615
            inputRow += srcNextRowOffset;
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   616
            outputRow += dstNextRowOffset;
91b0e63e6e83 8005530: [lcms] Improve performance of ColorConverOp for default destinations
bae
parents: 14884
diff changeset
   617
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    releaseILData(env, inputBuffer, srcDType, srcData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    releaseILData(env, outputBuffer, dstDType, dstData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
 * Method:    getProfileID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
 * Signature: (Ljava/awt/color/ICC_Profile;)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
  (JNIEnv *env, jclass cls, jobject pf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    return (*env)->GetLongField (env, pf, PF_ID_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
 * Method:    initLCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
 * Signature: (Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_initLCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
  (JNIEnv *env, jclass cls, jclass Trans, jclass IL, jclass Pf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    /* TODO: move initialization of the IDs to the static blocks of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * corresponding classes to avoid problems with invalidating ids by class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * unloading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    Trans_profileIDs_fID = (*env)->GetFieldID (env, Trans, "profileIDs", "[J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    Trans_renderType_fID = (*env)->GetFieldID (env, Trans, "renderType", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    Trans_ID_fID = (*env)->GetFieldID (env, Trans, "ID", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    IL_isIntPacked_fID = (*env)->GetFieldID (env, IL, "isIntPacked", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    IL_dataType_fID = (*env)->GetFieldID (env, IL, "dataType", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    IL_pixelType_fID = (*env)->GetFieldID (env, IL, "pixelType", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    IL_dataArray_fID = (*env)->GetFieldID(env, IL, "dataArray",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                                          "Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    IL_width_fID = (*env)->GetFieldID (env, IL, "width", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    IL_height_fID = (*env)->GetFieldID (env, IL, "height", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    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
   659
    IL_imageAtOnce_fID = (*env)->GetFieldID (env, IL, "imageAtOnce", "Z");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    IL_nextRowOffset_fID = (*env)->GetFieldID (env, IL, "nextRowOffset", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    PF_ID_fID = (*env)->GetFieldID (env, Pf, "ID", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
}
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   664
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   665
static cmsBool _getHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize)
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   666
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   667
  cmsUInt32Number pfSize = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   668
  cmsUInt8Number* pfBuffer = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   669
  cmsBool status = FALSE;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   670
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   671
  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
   672
      pfSize < sizeof(cmsICCHeader) ||
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   673
      bufferSize < sizeof(cmsICCHeader))
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   674
  {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   675
    return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   676
  }
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   677
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   678
  pfBuffer = malloc(pfSize);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   679
  if (pfBuffer == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   680
    return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   681
  }
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   682
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   683
  // 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
   684
  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
   685
    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
   686
    status = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   687
  }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   688
  free(pfBuffer);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   689
  return status;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   690
}
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   691
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   692
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
   693
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   694
  cmsICCHeader pfHeader = { 0 };
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   695
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   696
  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
   697
    return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   698
  }
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   699
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   700
  memcpy(&pfHeader, pBuffer, sizeof(cmsICCHeader));
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   701
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   702
  // 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
   703
  cmsSetHeaderFlags(pf, pfHeader.flags);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   704
  cmsSetHeaderManufacturer(pf, pfHeader.manufacturer);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   705
  cmsSetHeaderModel(pf, pfHeader.model);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   706
  cmsSetHeaderAttributes(pf, pfHeader.attributes);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   707
  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
   708
  cmsSetHeaderRenderingIntent(pf, pfHeader.renderingIntent);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   709
  cmsSetPCS(pf, pfHeader.pcs);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   710
  cmsSetColorSpace(pf, pfHeader.colorSpace);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   711
  cmsSetDeviceClass(pf, pfHeader.deviceClass);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   712
  cmsSetEncodedICCversion(pf, pfHeader.version);
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   713
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   714
  return TRUE;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   715
}
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   716
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   717
static cmsBool _writeCookedTag(cmsHPROFILE pfTarget,
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   718
                               cmsTagSignature sig,
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   719
                               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
   720
{
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   721
    cmsBool status;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   722
    cmsUInt32Number pfSize = 0;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   723
    cmsUInt8Number* pfBuffer = NULL;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   724
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   725
    cmsHPROFILE p = cmsCreateProfilePlaceholder(NULL);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   726
    if (NULL != p) {
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   727
        cmsICCHeader hdr = { 0 };
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   728
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   729
        /* Populate the placeholder's header according to target profile */
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   730
        hdr.flags = cmsGetHeaderFlags(pfTarget);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   731
        hdr.renderingIntent = cmsGetHeaderRenderingIntent(pfTarget);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   732
        hdr.manufacturer = cmsGetHeaderManufacturer(pfTarget);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   733
        hdr.model = cmsGetHeaderModel(pfTarget);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   734
        hdr.pcs = cmsGetPCS(pfTarget);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   735
        hdr.colorSpace = cmsGetColorSpace(pfTarget);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   736
        hdr.deviceClass = cmsGetDeviceClass(pfTarget);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   737
        hdr.version = cmsGetEncodedICCversion(pfTarget);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   738
        cmsGetHeaderAttributes(pfTarget, &hdr.attributes);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   739
        cmsGetHeaderProfileID(pfTarget, (cmsUInt8Number*)&hdr.profileID);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   740
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   741
        cmsSetHeaderFlags(p, hdr.flags);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   742
        cmsSetHeaderManufacturer(p, hdr.manufacturer);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   743
        cmsSetHeaderModel(p, hdr.model);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   744
        cmsSetHeaderAttributes(p, hdr.attributes);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   745
        cmsSetHeaderProfileID(p, (cmsUInt8Number*)&(hdr.profileID));
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   746
        cmsSetHeaderRenderingIntent(p, hdr.renderingIntent);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   747
        cmsSetPCS(p, hdr.pcs);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   748
        cmsSetColorSpace(p, hdr.colorSpace);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   749
        cmsSetDeviceClass(p, hdr.deviceClass);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   750
        cmsSetEncodedICCversion(p, hdr.version);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   751
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   752
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   753
        if (cmsWriteRawTag(p, sig, pData, size)) {
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   754
            if (cmsSaveProfileToMem(p, NULL, &pfSize)) {
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   755
                pfBuffer = malloc(pfSize);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   756
                if (pfBuffer != NULL) {
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   757
                    /* load raw profile data into the buffer */
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   758
                    if (!cmsSaveProfileToMem(p, pfBuffer, &pfSize)) {
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   759
                        free(pfBuffer);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   760
                        pfBuffer = NULL;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   761
                    }
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
            }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   764
        }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   765
        cmsCloseProfile(p);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   766
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   767
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   768
    if (pfBuffer == NULL) {
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   769
        return FALSE;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   770
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   771
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   772
    /* re-open the placeholder profile */
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   773
    p = cmsOpenProfileFromMem(pfBuffer, pfSize);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   774
    free(pfBuffer);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   775
    status = FALSE;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   776
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   777
    if (p != NULL) {
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   778
        /* Note that pCookedTag points to internal structures of the placeholder,
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   779
         * so this data is valid only while the placeholder is open.
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   780
         */
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   781
        void *pCookedTag = cmsReadTag(p, sig);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   782
        if (pCookedTag != NULL) {
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   783
            status = cmsWriteTag(pfTarget, sig, pCookedTag);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   784
        }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   785
        pCookedTag = NULL;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   786
        cmsCloseProfile(p);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   787
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   788
    return status;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   789
}