jdk/src/share/native/sun/awt/image/BufImgSurfaceData.c
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 "BufImgSurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "malloc.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "sun_awt_image_BufImgSurfaceData.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "img_util_md.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/* Define uintptr_t */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "gdefs.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This include file contains support code for loops using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * SurfaceData interface to talk to an X11 drawable from native
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
static LockFunc                 BufImg_Lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
static GetRasInfoFunc           BufImg_GetRasInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
static ReleaseFunc              BufImg_Release;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
static DisposeFunc              BufImg_Dispose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
static ColorData *BufImg_SetupICM(JNIEnv *env, BufImgSDOps *bisdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
static jfieldID         rgbID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
static jfieldID         mapSizeID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
static jfieldID         CMpDataID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
static jfieldID         allGrayID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Class:     sun_awt_image_BufImgSurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Method:    initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
Java_sun_awt_image_BufImgSurfaceData_initIDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    (JNIEnv *env, jclass bisd, jclass icm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    if (sizeof(BufImgRIPrivate) > SD_RASINFO_PRIVATE_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        JNU_ThrowInternalError(env, "Private RasInfo structure too large!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    rgbID = (*env)->GetFieldID(env, icm, "rgb", "[I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    allGrayID = (*env)->GetFieldID(env, icm, "allgrayopaque", "Z");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    mapSizeID = (*env)->GetFieldID(env, icm, "map_size", "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    CMpDataID = (*env)->GetFieldID(env, icm, "pData", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    if (allGrayID == 0 || rgbID == 0 || mapSizeID == 0 || CMpDataID == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        JNU_ThrowInternalError(env, "Could not get field IDs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * Class:     sun_java2d_SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * Method:    freeNativeICMData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * Signature: (Ljava/awt/image/IndexColorModel;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
Java_sun_awt_image_BufImgSurfaceData_freeNativeICMData
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    (JNIEnv *env, jclass sd, jobject icm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    jlong pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    ColorData *cdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    if (JNU_IsNull(env, icm)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        JNU_ThrowNullPointerException(env, "IndexColorModel cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    pData = (*env)->GetLongField (env, icm, CMpDataID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    cdata = (ColorData *)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    freeICMColorData(cdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * Class:     sun_awt_image_BufImgSurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * Method:    initOps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * Signature: (Ljava/lang/Object;IIIII)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
Java_sun_awt_image_BufImgSurfaceData_initRaster(JNIEnv *env, jobject bisd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                                jobject array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                                                jint offset, jint bitoffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                                jint width, jint height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                                jint pixStr, jint scanStr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                                jobject icm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    BufImgSDOps *bisdo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        (BufImgSDOps*)SurfaceData_InitOps(env, bisd, sizeof(BufImgSDOps));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    bisdo->sdOps.Lock = BufImg_Lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    bisdo->sdOps.GetRasInfo = BufImg_GetRasInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    bisdo->sdOps.Release = BufImg_Release;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    bisdo->sdOps.Unlock = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    bisdo->sdOps.Dispose = BufImg_Dispose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    bisdo->array = (*env)->NewWeakGlobalRef(env, array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    bisdo->offset = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    bisdo->bitoffset = bitoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    bisdo->scanStr = scanStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    bisdo->pixStr = pixStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    if (JNU_IsNull(env, icm)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        bisdo->lutarray = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        bisdo->lutsize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        bisdo->icm = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        jobject lutarray = (*env)->GetObjectField(env, icm, rgbID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        bisdo->lutarray = (*env)->NewWeakGlobalRef(env, lutarray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        bisdo->lutsize = (*env)->GetIntField(env, icm, mapSizeID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        bisdo->icm = (*env)->NewWeakGlobalRef(env, icm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    bisdo->rasbounds.x1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    bisdo->rasbounds.y1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    bisdo->rasbounds.x2 = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    bisdo->rasbounds.y2 = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * Method for disposing native BufImgSD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
static void BufImg_Dispose(JNIEnv *env, SurfaceDataOps *ops)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /* ops is assumed non-null as it is checked in SurfaceData_DisposeOps */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    BufImgSDOps *bisdo = (BufImgSDOps *)ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    (*env)->DeleteWeakGlobalRef(env, bisdo->array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    if (bisdo->lutarray != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        (*env)->DeleteWeakGlobalRef(env, bisdo->lutarray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    if (bisdo->icm != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        (*env)->DeleteWeakGlobalRef(env, bisdo->icm);
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
static jint BufImg_Lock(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                        SurfaceDataOps *ops,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                        SurfaceDataRasInfo *pRasInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                        jint lockflags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    BufImgSDOps *bisdo = (BufImgSDOps *)ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    BufImgRIPrivate *bipriv = (BufImgRIPrivate *) &(pRasInfo->priv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    if ((lockflags & (SD_LOCK_LUT)) != 0 && JNU_IsNull(env, bisdo->lutarray)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        /* REMIND: Should this be an InvalidPipe exception? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        JNU_ThrowNullPointerException(env, "Attempt to lock missing colormap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return SD_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    if ((lockflags & SD_LOCK_INVCOLOR) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        (lockflags & SD_LOCK_INVGRAY) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        bipriv->cData = BufImg_SetupICM(env, bisdo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (bipriv->cData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            JNU_ThrowNullPointerException(env, "Could not initialize "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                          "inverse tables");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return SD_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        bipriv->cData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    bipriv->lockFlags = lockflags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    bipriv->base = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    bipriv->lutbase = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    SurfaceData_IntersectBounds(&pRasInfo->bounds, &bisdo->rasbounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    return SD_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
static void BufImg_GetRasInfo(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                              SurfaceDataOps *ops,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                              SurfaceDataRasInfo *pRasInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    BufImgSDOps *bisdo = (BufImgSDOps *)ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    BufImgRIPrivate *bipriv = (BufImgRIPrivate *) &(pRasInfo->priv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    if ((bipriv->lockFlags & (SD_LOCK_RD_WR)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        bipriv->base =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            (*env)->GetPrimitiveArrayCritical(env, bisdo->array, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    if ((bipriv->lockFlags & (SD_LOCK_LUT)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        bipriv->lutbase =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            (*env)->GetPrimitiveArrayCritical(env, bisdo->lutarray, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    if (bipriv->base == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        pRasInfo->rasBase = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        pRasInfo->pixelStride = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        pRasInfo->pixelBitOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        pRasInfo->scanStride = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        pRasInfo->rasBase = (void *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            (((uintptr_t) bipriv->base) + bisdo->offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        pRasInfo->pixelStride = bisdo->pixStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        pRasInfo->pixelBitOffset = bisdo->bitoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        pRasInfo->scanStride = bisdo->scanStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    if (bipriv->lutbase == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        pRasInfo->lutBase = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        pRasInfo->lutSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        pRasInfo->lutBase = bipriv->lutbase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        pRasInfo->lutSize = bisdo->lutsize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    if (bipriv->cData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        pRasInfo->invColorTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        pRasInfo->redErrTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        pRasInfo->grnErrTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        pRasInfo->bluErrTable = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        pRasInfo->invColorTable = bipriv->cData->img_clr_tbl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        pRasInfo->redErrTable = bipriv->cData->img_oda_red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        pRasInfo->grnErrTable = bipriv->cData->img_oda_green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        pRasInfo->bluErrTable = bipriv->cData->img_oda_blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        pRasInfo->invGrayTable = bipriv->cData->pGrayInverseLutData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
static void BufImg_Release(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                           SurfaceDataOps *ops,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                           SurfaceDataRasInfo *pRasInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    BufImgSDOps *bisdo = (BufImgSDOps *)ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    BufImgRIPrivate *bipriv = (BufImgRIPrivate *) &(pRasInfo->priv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    if (bipriv->base != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        jint mode = (((bipriv->lockFlags & (SD_LOCK_WRITE)) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                     ? 0 : JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        (*env)->ReleasePrimitiveArrayCritical(env, bisdo->array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                              bipriv->base, mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    if (bipriv->lutbase != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        (*env)->ReleasePrimitiveArrayCritical(env, bisdo->lutarray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                              bipriv->lutbase, JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
static ColorData *BufImg_SetupICM(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                  BufImgSDOps *bisdo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    ColorData *cData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    if (JNU_IsNull(env, bisdo->icm)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return (ColorData *) NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    cData = (ColorData *) JNU_GetLongFieldAsPtr(env, bisdo->icm, CMpDataID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    if (cData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        cData = (ColorData*)calloc(1, sizeof(ColorData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (cData != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            jboolean allGray
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                = (*env)->GetBooleanField(env, bisdo->icm, allGrayID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            int *pRgb = (int *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                ((*env)->GetPrimitiveArrayCritical(env, bisdo->lutarray, NULL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            cData->img_clr_tbl = initCubemap(pRgb, bisdo->lutsize, 32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            if (allGray == JNI_TRUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                initInverseGrayLut(pRgb, bisdo->lutsize, cData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            (*env)->ReleasePrimitiveArrayCritical(env, bisdo->lutarray, pRgb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                                  JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            initDitherTables(cData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            JNU_SetLongFieldFromPtr(env, bisdo->icm, CMpDataID, cData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    return cData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
}