jdk/src/share/native/sun/java2d/cmm/lcms/LCMS.c
author bae
Sat, 04 Jun 2011 23:08:38 +0400
changeset 9784 3a0ebf0b855d
parent 9035 1255eb81cc2f
child 14154 9acc7f86a458
permissions -rw-r--r--
7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64. Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7951
diff changeset
     2
 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2801
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2801
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2801
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2801
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2801
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <stdio.h>
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    27
#include <stdlib.h>
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    28
#include <memory.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "sun_java2d_cmm_lcms_LCMS.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "Trace.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "Disposer.h"
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    33
#include "lcms2.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    35
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    36
#define ALIGNLONG(x) (((x)+3) & ~(3))         // Aligns to DWORD boundary
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    37
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    38
#ifdef USE_BIG_ENDIAN
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    39
#define AdjustEndianess32(a)
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    40
#else
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    41
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    42
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    43
void AdjustEndianess32(cmsUInt8Number *pByte)
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    44
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    45
    cmsUInt8Number temp1;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    46
    cmsUInt8Number temp2;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    47
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    48
    temp1 = *pByte++;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    49
    temp2 = *pByte++;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    50
    *(pByte-1) = *pByte;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    51
    *pByte++ = temp2;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    52
    *(pByte-3) = *pByte;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    53
    *pByte = temp1;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    54
}
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    55
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    56
#endif
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    57
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    58
// Transports to properly encoded values - note that icc profiles does use
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    59
// big endian notation.
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    60
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    61
static
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    62
cmsInt32Number TransportValue32(cmsInt32Number Value)
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    63
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    64
    cmsInt32Number Temp = Value;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    65
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    66
    AdjustEndianess32((cmsUInt8Number*) &Temp);
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    67
    return Temp;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    68
}
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
    69
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#define SigMake(a,b,c,d) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                    ( ( ((int) ((unsigned char) (a))) << 24) | \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                      ( ((int) ((unsigned char) (b))) << 16) | \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                      ( ((int) ((unsigned char) (c))) <<  8) | \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                          (int) ((unsigned char) (d)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#define TagIdConst(a, b, c, d) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                ((int) SigMake ((a), (b), (c), (d)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
#define SigHead TagIdConst('h','e','a','d')
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
#define DT_BYTE     0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#define DT_SHORT    1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
#define DT_INT      2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#define DT_DOUBLE   3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
/* Default temp profile list size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#define DF_ICC_BUF_SIZE 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    89
#define ERR_MSG_SIZE 256
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    90
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    91
#ifdef _MSC_VER
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    92
# ifndef snprintf
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    93
#       define snprintf  _snprintf
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    94
# endif
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
    95
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
static jfieldID PF_ID_fID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
JavaVM *javaVM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   124
void errorHandler(cmsContext ContextID, cmsUInt32Number errorCode,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   125
                  const char *errorText) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    char errMsg[ERR_MSG_SIZE];
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   128
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   129
    int count = snprintf(errMsg, ERR_MSG_SIZE,
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   130
                          "LCMS error %d: %s", errorCode, errorText);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   131
    if (count < 0 || count >= ERR_MSG_SIZE) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   132
        count = ERR_MSG_SIZE - 1;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   133
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   134
    errMsg[count] = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    (*javaVM)->AttachCurrentThread(javaVM, (void**)&env, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    JNU_ThrowByName(env, "java/awt/color/CMMException", errMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
7951
8479f9f404f8 7002766: Java2d: Changes to correct c/c++ language issues for use of parfait
bae
parents: 7668
diff changeset
   140
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    javaVM = jvm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   143
    cmsSetLogErrorHandler(errorHandler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    return JNI_VERSION_1_6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
void LCMS_freeTransform(JNIEnv *env, jlong ID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    storeID_t sTrans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    sTrans.j = ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /* Passed ID is always valid native ref so there is no check for zero */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    cmsDeleteTransform(sTrans.xf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * Method:    createNativeTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * Signature: ([JI)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_createNativeTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
  (JNIEnv *env, jclass cls, jlongArray profileIDs, jint renderType,
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   162
   jint inFormatter, jint outFormatter, jobject disposerRef)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   164
    cmsHPROFILE _iccArray[DF_ICC_BUF_SIZE];
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   165
    cmsHPROFILE *iccArray = &_iccArray[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    storeID_t sTrans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    int i, j, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    jlong* ids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    size = (*env)->GetArrayLength (env, profileIDs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    ids = (*env)->GetPrimitiveArrayCritical(env, profileIDs, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    if (DF_ICC_BUF_SIZE < size*2) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   174
        iccArray = (cmsHPROFILE*) malloc(
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   175
            size*2*sizeof(cmsHPROFILE));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (iccArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            J2dRlsTraceLn(J2D_TRACE_ERROR, "getXForm: iccArray == NULL");
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   178
            return 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    for (i = 0; i < size; i++) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   184
        cmsHPROFILE icc;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   185
        cmsColorSpaceSignature cs;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   186
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        sTrans.j = ids[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        icc = sTrans.pf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        iccArray[j++] = icc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        /* Middle non-abstract profiles should be doubled before passing to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         * the cmsCreateMultiprofileTransform function
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         */
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   194
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   195
        cs = cmsGetColorSpace(icc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (size > 2 && i != 0 && i != size - 1 &&
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   197
            cs != cmsSigXYZData && cs != cmsSigLabData)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            iccArray[j++] = icc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    sTrans.xf = cmsCreateMultiprofileTransform(iccArray, j,
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   204
        inFormatter, outFormatter, renderType, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    (*env)->ReleasePrimitiveArrayCritical(env, profileIDs, ids, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    if (sTrans.xf == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        J2dRlsTraceLn(J2D_TRACE_ERROR, "LCMS_createNativeTransform: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                       "sTrans.xf == NULL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        JNU_ThrowByName(env, "java/awt/color/CMMException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                        "Cannot get color transform");
6868
f9131565859e 6963489: ZDI-CAN-803: Sun JRE ICC Profile Device Information Tag Remote Code Execution Vulnerability
bae
parents: 5506
diff changeset
   213
    } else {
f9131565859e 6963489: ZDI-CAN-803: Sun JRE ICC Profile Device Information Tag Remote Code Execution Vulnerability
bae
parents: 5506
diff changeset
   214
        Disposer_AddRecord(env, disposerRef, LCMS_freeTransform, sTrans.j);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    if (iccArray != &_iccArray[0]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        free(iccArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    return sTrans.j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * Method:    loadProfile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * Signature: ([B)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_loadProfile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
  (JNIEnv *env, jobject obj, jbyteArray data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    jbyte* dataArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    jint dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    storeID_t sProf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   236
    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
   237
        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
   238
        return 0L;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   239
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   240
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    dataArray = (*env)->GetByteArrayElements (env, data, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    dataSize = (*env)->GetArrayLength (env, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   244
    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
   245
        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
   246
        return 0L;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   247
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   248
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   249
    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
   250
                                     (cmsUInt32Number) dataSize);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   252
    (*env)->ReleaseByteArrayElements (env, data, dataArray, 0);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   253
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    if (sProf.pf == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        JNU_ThrowIllegalArgumentException(env, "Invalid profile data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    return sProf.j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * Method:    freeProfile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 * Signature: (J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_freeProfile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
  (JNIEnv *env, jobject obj, jlong id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    storeID_t sProf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    sProf.j = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    if (cmsCloseProfile(sProf.pf) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        J2dRlsTraceLn1(J2D_TRACE_ERROR, "LCMS_freeProfile: cmsCloseProfile(%d)"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                       "== 0", id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        JNU_ThrowByName(env, "java/awt/color/CMMException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                        "Cannot close profile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 * Method:    getProfileSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 * Signature: (J)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
JNIEXPORT jint JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
  (JNIEnv *env, jobject obj, jlong id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    storeID_t sProf;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   290
    cmsUInt32Number pfSize = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    sProf.j = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   293
    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
   294
        return (jint)pfSize;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   295
    } else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   296
      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
   297
                      "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
   298
        return -1;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   299
    }
2
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
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 * Method:    getProfileData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 * Signature: (J[B)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
  (JNIEnv *env, jobject obj, jlong id, jbyteArray data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    storeID_t sProf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    jint size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    jbyte* dataArray;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   313
    cmsUInt32Number pfSize = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   314
    cmsBool status;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    sProf.j = id;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   317
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   318
    // determine actual profile size
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   319
    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
   320
        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
   321
                        "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
   322
        return;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   323
    }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   324
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   325
    // verify java buffer capacity
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   326
    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
   327
    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
   328
        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
   329
                        "Insufficient buffer capacity.");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   330
        return;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   331
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    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
   334
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   335
    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
   336
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   337
    (*env)->ReleaseByteArrayElements (env, data, dataArray, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   339
    if (!status) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   340
        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
   341
                        "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
   342
        return;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   343
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   346
/* 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
   347
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
   348
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
   349
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
   350
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
 * Method:    getTagSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
 * Signature: (JI)I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
JNIEXPORT jint JNICALL Java_sun_java2d_cmm_lcms_LCMS_getTagSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
  (JNIEnv *env, jobject obj, jlong id, jint tagSig)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    storeID_t sProf;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   360
    TagSignature_t sig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   361
    jint result = -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    sProf.j = id;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   364
    sig.j = tagSig;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    if (tagSig == SigHead) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   367
        result = sizeof(cmsICCHeader);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    } else {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   369
      if (cmsIsTag(sProf.pf, sig.cms)) {
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   370
          result = cmsReadRawTag(sProf.pf, sig.cms, NULL, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            JNU_ThrowByName(env, "java/awt/color/CMMException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                            "ICC profile tag not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
 * Method:    getTagData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
 * Signature: (JI[B)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_getTagData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
  (JNIEnv *env, jobject obj, jlong id, jint tagSig, jbyteArray data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    storeID_t sProf;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   389
    TagSignature_t sig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   390
    cmsInt32Number tagSize;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   391
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    jbyte* dataArray;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   393
    jint bufSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    sProf.j = id;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   396
    sig.j = tagSig;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    if (tagSig == SigHead) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   399
        cmsBool status;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   400
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   401
        bufSize =(*env)->GetArrayLength(env, data);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   402
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   403
        if (bufSize < sizeof(cmsICCHeader)) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   404
           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
   405
                            "Insufficient buffer capacity");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   406
           return;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   407
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   408
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        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
   410
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   411
        if (dataArray == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   412
           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
   413
                            "Unable to get buffer");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   414
           return;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   415
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   416
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   417
        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
   418
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        (*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
   420
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   421
        if (!status) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   422
            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
   423
                            "ICC Profile header not found");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   424
        }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   425
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   429
    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
   430
        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
   431
    } else {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   432
        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
   433
                        "ICC profile tag not found");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   434
        return;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   435
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   437
    // verify data buffer capacity
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   438
    bufSize = (*env)->GetArrayLength(env, data);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   439
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   440
    if (tagSize < 0 || 0 > bufSize || tagSize > bufSize) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   441
        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
   442
                        "Insufficient buffer capacity.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   446
    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
   447
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   448
    if (dataArray == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   449
        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
   450
                        "Unable to get buffer");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   451
        return;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   452
    }
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
    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
   455
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   456
    (*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
   457
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   458
    if (bufSize != tagSize) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   459
        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
   460
                        "Can not get tag data.");
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   461
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
 * Method:    setTagData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
 * Signature: (JI[B)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_setTagData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
  (JNIEnv *env, jobject obj, jlong id, jint tagSig, jbyteArray data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
{
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   473
    storeID_t sProf;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   474
    TagSignature_t sig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   475
    cmsBool status;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   476
    jbyte* dataArray;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   477
    int tagSize;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   478
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   479
    sProf.j = id;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   480
    sig.j = tagSig;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   481
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   482
    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
   483
        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
   484
        return;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   485
    }
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   486
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   487
    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
   488
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   489
    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
   490
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   491
    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
   492
        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
   493
        return;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   494
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   495
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   496
    if (tagSig == SigHead) {
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   497
        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
   498
    } else {
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   499
        status = _writeCookedTag(sProf.pf, sig.cms, dataArray, tagSize);
2392
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
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   502
    (*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
   503
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   504
    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
   505
        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
   506
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
void* getILData (JNIEnv *env, jobject img, jint* pDataType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                 jobject* pDataObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    void* result = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    *pDataType = (*env)->GetIntField (env, img, IL_dataType_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    *pDataObject = (*env)->GetObjectField(env, img, IL_dataArray_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    switch (*pDataType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        case DT_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            result = (*env)->GetByteArrayElements (env, *pDataObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        case DT_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            result = (*env)->GetShortArrayElements (env, *pDataObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        case DT_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            result = (*env)->GetIntArrayElements (env, *pDataObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        case DT_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            result = (*env)->GetDoubleArrayElements (env, *pDataObject, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
void releaseILData (JNIEnv *env, void* pData, jint dataType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    jobject dataObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    switch (dataType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        case DT_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            (*env)->ReleaseByteArrayElements(env,dataObject,(jbyte*)pData,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        case DT_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            (*env)->ReleaseShortArrayElements(env,dataObject,(jshort*)pData, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        case DT_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            (*env)->ReleaseIntArrayElements(env,dataObject,(jint*)pData,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        case DT_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            (*env)->ReleaseDoubleArrayElements(env,dataObject,(jdouble*)pData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                                               0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            break;
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
 * Method:    colorConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
 * Signature: (Lsun/java2d/cmm/lcms/LCMSTransform;Lsun/java2d/cmm/lcms/LCMSImageLayout;Lsun/java2d/cmm/lcms/LCMSImageLayout;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_colorConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
  (JNIEnv *env, jclass obj, jobject trans, jobject src, jobject dst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    storeID_t sTrans;
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   560
    int inFmt, outFmt, srcDType, dstDType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    int srcOffset, srcNextRowOffset, dstOffset, dstNextRowOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    int width, height, i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    void* inputBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    void* outputBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    char* inputRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    char* outputRow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    jobject srcData, dstData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    inFmt = (*env)->GetIntField (env, src, IL_pixelType_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    outFmt = (*env)->GetIntField (env, dst, IL_pixelType_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    srcOffset = (*env)->GetIntField (env, src, IL_offset_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    srcNextRowOffset = (*env)->GetIntField (env, src, IL_nextRowOffset_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    dstOffset = (*env)->GetIntField (env, dst, IL_offset_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    dstNextRowOffset = (*env)->GetIntField (env, dst, IL_nextRowOffset_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    width = (*env)->GetIntField (env, src, IL_width_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    height = (*env)->GetIntField (env, src, IL_height_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
#ifdef _LITTLE_ENDIAN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    /* Reversing data packed into int for LE archs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    if ((*env)->GetBooleanField (env, src, IL_isIntPacked_fID) == JNI_TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        inFmt ^= DOSWAP_SH(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    if ((*env)->GetBooleanField (env, dst, IL_isIntPacked_fID) == JNI_TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        outFmt ^= DOSWAP_SH(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    sTrans.j = (*env)->GetLongField (env, trans, Trans_ID_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    if (sTrans.xf == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        J2dRlsTraceLn(J2D_TRACE_ERROR, "LCMS_colorConvert: transform == NULL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        JNU_ThrowByName(env, "java/awt/color/CMMException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                        "Cannot get color transform");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    inputBuffer = getILData (env, src, &srcDType, &srcData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    if (inputBuffer == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        J2dRlsTraceLn(J2D_TRACE_ERROR, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        JNU_ThrowByName(env, "java/awt/color/CMMException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                        "Cannot get input data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    outputBuffer = getILData (env, dst, &dstDType, &dstData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    if (outputBuffer == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        releaseILData(env, inputBuffer, srcDType, srcData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        JNU_ThrowByName(env, "java/awt/color/CMMException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                        "Cannot get output data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    inputRow = (char*)inputBuffer + srcOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    outputRow = (char*)outputBuffer + dstOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    for (i = 0; i < height; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        cmsDoTransform(sTrans.xf, inputRow, outputRow, width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        inputRow += srcNextRowOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        outputRow += dstNextRowOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    releaseILData(env, inputBuffer, srcDType, srcData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    releaseILData(env, outputBuffer, dstDType, dstData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
 * Method:    getProfileID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
 * Signature: (Ljava/awt/color/ICC_Profile;)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_getProfileID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
  (JNIEnv *env, jclass cls, jobject pf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    return (*env)->GetLongField (env, pf, PF_ID_fID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
 * Class:     sun_java2d_cmm_lcms_LCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
 * Method:    initLCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
 * Signature: (Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
JNIEXPORT void JNICALL Java_sun_java2d_cmm_lcms_LCMS_initLCMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
  (JNIEnv *env, jclass cls, jclass Trans, jclass IL, jclass Pf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    /* TODO: move initialization of the IDs to the static blocks of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * corresponding classes to avoid problems with invalidating ids by class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * unloading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    Trans_profileIDs_fID = (*env)->GetFieldID (env, Trans, "profileIDs", "[J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    Trans_renderType_fID = (*env)->GetFieldID (env, Trans, "renderType", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    Trans_ID_fID = (*env)->GetFieldID (env, Trans, "ID", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    IL_isIntPacked_fID = (*env)->GetFieldID (env, IL, "isIntPacked", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    IL_dataType_fID = (*env)->GetFieldID (env, IL, "dataType", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    IL_pixelType_fID = (*env)->GetFieldID (env, IL, "pixelType", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    IL_dataArray_fID = (*env)->GetFieldID(env, IL, "dataArray",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                                          "Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    IL_width_fID = (*env)->GetFieldID (env, IL, "width", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    IL_height_fID = (*env)->GetFieldID (env, IL, "height", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    IL_offset_fID = (*env)->GetFieldID (env, IL, "offset", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    IL_nextRowOffset_fID = (*env)->GetFieldID (env, IL, "nextRowOffset", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    PF_ID_fID = (*env)->GetFieldID (env, Pf, "ID", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
}
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   666
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   667
static cmsBool _getHeaderInfo(cmsHPROFILE pf, jbyte* pBuffer, jint bufferSize)
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   668
{
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   669
  cmsUInt32Number pfSize = 0;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   670
  cmsUInt8Number* pfBuffer = NULL;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   671
  cmsBool status = FALSE;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   672
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   673
  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
   674
      pfSize < sizeof(cmsICCHeader) ||
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   675
      bufferSize < sizeof(cmsICCHeader))
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   676
  {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   677
    return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   678
  }
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   679
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   680
  pfBuffer = malloc(pfSize);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   681
  if (pfBuffer == NULL) {
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   682
    return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   683
  }
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   684
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   685
  // 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
   686
  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
   687
    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
   688
    status = TRUE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   689
  }
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   690
  free(pfBuffer);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   691
  return status;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   692
}
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   693
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   694
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
   695
{
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   696
  cmsICCHeader pfHeader = { 0 };
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   697
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   698
  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
   699
    return FALSE;
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   700
  }
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
  memcpy(&pfHeader, pBuffer, sizeof(cmsICCHeader));
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   703
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   704
  // 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
   705
  cmsSetHeaderFlags(pf, pfHeader.flags);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   706
  cmsSetHeaderManufacturer(pf, pfHeader.manufacturer);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   707
  cmsSetHeaderModel(pf, pfHeader.model);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   708
  cmsSetHeaderAttributes(pf, pfHeader.attributes);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   709
  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
   710
  cmsSetHeaderRenderingIntent(pf, pfHeader.renderingIntent);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   711
  cmsSetPCS(pf, pfHeader.pcs);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   712
  cmsSetColorSpace(pf, pfHeader.colorSpace);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   713
  cmsSetDeviceClass(pf, pfHeader.deviceClass);
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   714
  cmsSetEncodedICCversion(pf, pfHeader.version);
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   715
6482
0f6a4442b29e 6523398: OSS CMM: Need to implement writing ICC profile tags in new lcms library
bae
parents: 5506
diff changeset
   716
  return TRUE;
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents: 2
diff changeset
   717
}
9784
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   718
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   719
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
   720
                               cmsTagSignature sig,
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   721
                               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
   722
{
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   723
    cmsBool status;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   724
    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
   725
    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
   726
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   727
    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
   728
    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
   729
        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
   730
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   731
        /* 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
   732
        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
   733
        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
   734
        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
   735
        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
   736
        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
   737
        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
   738
        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
   739
        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
   740
        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
   741
        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
   742
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   743
        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
   744
        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
   745
        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
   746
        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
   747
        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
   748
        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
   749
        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
   750
        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
   751
        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
   752
        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
   753
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   754
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   755
        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
   756
            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
   757
                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
   758
                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
   759
                    /* 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
   760
                    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
   761
                        free(pfBuffer);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   762
                        pfBuffer = NULL;
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
            }
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
        cmsCloseProfile(p);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   768
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   769
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   770
    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
   771
        return FALSE;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   772
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   773
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   774
    /* 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
   775
    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
   776
    free(pfBuffer);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   777
    status = FALSE;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   778
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   779
    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
   780
        /* 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
   781
         * 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
   782
         */
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   783
        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
   784
        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
   785
            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
   786
        }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   787
        pCookedTag = NULL;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   788
        cmsCloseProfile(p);
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   789
    }
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   790
    return status;
3a0ebf0b855d 7042594: 3 testis api/java_awt/Color/ICC_ProfileRGB/index.html fail against RI b138 OEL6x64.
bae
parents: 9035
diff changeset
   791
}