src/java.desktop/share/native/libawt/awt/image/dither.c
author ihse
Wed, 28 Mar 2018 23:56:08 +0200
changeset 49440 396ea30afbd5
parent 47216 71c04702a3d5
child 56721 01b558efd286
permissions -rw-r--r--
8200178: Remove mapfiles for JDK native libraries Reviewed-by: erikj, alanb, mchung, prr, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
     2
 * Copyright (c) 2001, 2018, 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: 2385
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: 2385
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: 2385
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2385
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2385
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
    26
#include "jni.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "dither.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
    29
JNIEXPORT sgn_ordered_dither_array std_img_oda_red;
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
    30
JNIEXPORT sgn_ordered_dither_array std_img_oda_green;
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
    31
JNIEXPORT sgn_ordered_dither_array std_img_oda_blue;
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
    32
JNIEXPORT int std_odas_computed = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
    34
JNIEXPORT void JNICALL
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
    35
initInverseGrayLut(int* prgb, int rgbsize, ColorData *cData) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    int *inverse;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    int lastindex, lastgray, missing, i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    if (!cData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    inverse = calloc(256, sizeof(int));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    if (!inverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    cData->pGrayInverseLutData = inverse;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    for (i = 0; i < 256; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        inverse[i] = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /* First, fill the gray values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    for (i = 0; i < rgbsize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        int r, g, b, rgb = prgb[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        if (rgb == 0x0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            /* ignore transparent black */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        r = (rgb >> 16) & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        g = (rgb >> 8 ) & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        b = rgb & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        if (b == r && b == g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            inverse[b] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /* fill the missing gaps by taking the valid values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * on either side and filling them halfway into the gap
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    lastindex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    lastgray = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    missing = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    for (i = 0; i < 256; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (inverse[i] < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            inverse[i] = lastgray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            missing = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            lastgray = inverse[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            if (missing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                lastindex = lastindex < 0 ? 0 : (i+lastindex)/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                while (lastindex < i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                    inverse[lastindex++] = lastgray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            lastindex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            missing = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
void freeICMColorData(ColorData *pData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    if (CANFREE(pData)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (pData->img_clr_tbl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            free(pData->img_clr_tbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (pData->pGrayInverseLutData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            free(pData->pGrayInverseLutData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        free(pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
/* REMIND: does not deal well with bifurcation which happens when two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * palette entries map to the same cube vertex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
recurseLevel(CubeStateInfo *priorState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    CubeStateInfo currentState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    memcpy(&currentState, priorState, sizeof(CubeStateInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    currentState.rgb = (unsigned short *)malloc(6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                                * sizeof(unsigned short)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                                * priorState->activeEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    if (currentState.rgb == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    currentState.indices = (unsigned char *)malloc(6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                                * sizeof(unsigned char)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                                                * priorState->activeEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    if (currentState.indices == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        free(currentState.rgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    currentState.depth++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    if (currentState.depth > priorState->maxDepth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        priorState->maxDepth = currentState.depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    currentState.activeEntries = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    for (i=priorState->activeEntries - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        unsigned short rgb = priorState->rgb[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        unsigned char  index = priorState->indices[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        ACTIVATE(rgb, 0x7c00, 0x0400, currentState, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        ACTIVATE(rgb, 0x03e0, 0x0020, currentState, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        ACTIVATE(rgb, 0x001f, 0x0001, currentState, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    if (currentState.activeEntries) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (!recurseLevel(&currentState)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            free(currentState.rgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            free(currentState.indices);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    if (currentState.maxDepth > priorState->maxDepth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        priorState->maxDepth = currentState.maxDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    free(currentState.rgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    free(currentState.indices);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    return  1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * REMIND: take core inversedLUT calculation to the shared tree and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * recode the functions (Win32)awt_Image:initCubemap(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * (Win32)awt_Image:make_cubemap(), (Win32)AwtToolkit::GenerateInverseLUT(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * (Solaris)color:initCubemap() to call the shared codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
unsigned char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
initCubemap(int* cmap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            int  cmap_len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            int  cube_dim) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    CubeStateInfo currentState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    int cubesize = cube_dim * cube_dim * cube_dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    unsigned char *useFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    unsigned char *newILut = (unsigned char*)malloc(cubesize);
2385
bfc8967dfe97 6800846: REGRESSION: Printing quality degraded with Java 6 compared to 5.0
bae
parents: 2
diff changeset
   174
    int cmap_mid = (cmap_len >> 1) + (cmap_len & 0x1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    if (newILut) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      useFlags = (unsigned char *)calloc(cubesize, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
      if (useFlags == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
          free(newILut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        fprintf(stderr, "Out of memory in color:initCubemap()1\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
          return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        currentState.depth          = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        currentState.maxDepth       = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        currentState.usedFlags      = useFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        currentState.activeEntries  = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        currentState.iLUT           = newILut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        currentState.rgb = (unsigned short *)
2385
bfc8967dfe97 6800846: REGRESSION: Printing quality degraded with Java 6 compared to 5.0
bae
parents: 2
diff changeset
   194
                                malloc(cmap_len * sizeof(unsigned short));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (currentState.rgb == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            free(newILut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            free(useFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        fprintf(stderr, "Out of memory in color:initCubemap()2\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        currentState.indices = (unsigned char *)
2385
bfc8967dfe97 6800846: REGRESSION: Printing quality degraded with Java 6 compared to 5.0
bae
parents: 2
diff changeset
   205
                                malloc(cmap_len * sizeof(unsigned char));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (currentState.indices == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            free(currentState.rgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            free(newILut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            free(useFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        fprintf(stderr, "Out of memory in color:initCubemap()3\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
2385
bfc8967dfe97 6800846: REGRESSION: Printing quality degraded with Java 6 compared to 5.0
bae
parents: 2
diff changeset
   216
        for (i = 0; i < cmap_mid; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            unsigned short rgb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            int pixel = cmap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            rgb = (pixel & 0x00f80000) >> 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            rgb |= (pixel & 0x0000f800) >> 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            rgb |=  (pixel & 0xf8) >> 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            INSERTNEW(currentState, rgb, i);
2385
bfc8967dfe97 6800846: REGRESSION: Printing quality degraded with Java 6 compared to 5.0
bae
parents: 2
diff changeset
   223
            pixel = cmap[cmap_len - i - 1];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            rgb = (pixel & 0x00f80000) >> 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            rgb |= (pixel & 0x0000f800) >> 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            rgb |=  (pixel & 0xf8) >> 3;
2385
bfc8967dfe97 6800846: REGRESSION: Printing quality degraded with Java 6 compared to 5.0
bae
parents: 2
diff changeset
   227
            INSERTNEW(currentState, rgb, cmap_len - i - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (!recurseLevel(&currentState)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            free(newILut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            free(useFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            free(currentState.rgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            free(currentState.indices);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        fprintf(stderr, "Out of memory in color:initCubemap()4\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        free(useFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        free(currentState.rgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        free(currentState.indices);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return newILut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        fprintf(stderr, "Out of memory in color:initCubemap()5\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
initDitherTables(ColorData* cData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    if(std_odas_computed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        cData->img_oda_red   = &(std_img_oda_red[0][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        cData->img_oda_green = &(std_img_oda_green[0][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        cData->img_oda_blue  = &(std_img_oda_blue[0][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        cData->img_oda_red   = &(std_img_oda_red[0][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        cData->img_oda_green = &(std_img_oda_green[0][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        cData->img_oda_blue  = &(std_img_oda_blue[0][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        make_dither_arrays(256, cData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        std_odas_computed = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
49440
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
   272
JNIEXPORT void JNICALL
396ea30afbd5 8200178: Remove mapfiles for JDK native libraries
ihse
parents: 47216
diff changeset
   273
make_dither_arrays(int cmapsize, ColorData *cData) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    int i, j, k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Initialize the per-component ordered dithering arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Choose a size based on how far between elements in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * virtual cube.  Assume the cube has cuberoot(cmapsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * elements per axis and those elements are distributed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * over 256 colors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * The calculation should really divide by (#comp/axis - 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * since the first and last elements are at the extremes of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * the 256 levels, but in a practical sense this formula
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * produces a smaller error array which results in smoother
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * images that have slightly less color fidelity but much
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * less dithering noise, especially for grayscale images.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    i = (int) (256 / pow(cmapsize, 1.0/3.0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    make_sgn_ordered_dither_array(cData->img_oda_red, -i / 2, i / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    make_sgn_ordered_dither_array(cData->img_oda_green, -i / 2, i / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    make_sgn_ordered_dither_array(cData->img_oda_blue, -i / 2, i / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Flip green horizontally and blue vertically so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * the errors don't line up in the 3 primary components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    for (i = 0; i < 8; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        for (j = 0; j < 4; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            k = cData->img_oda_green[(i<<3)+j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            cData->img_oda_green[(i<<3)+j] = cData->img_oda_green[(i<<3)+7 - j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            cData->img_oda_green[(i<<3) + 7 - j] = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            k = cData->img_oda_blue[(j<<3)+i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            cData->img_oda_blue[(j<<3)+i] = cData->img_oda_blue[((7 - j)<<3)+i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            cData->img_oda_blue[((7 - j)<<3) + i] = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
}