src/java.desktop/share/native/libawt/awt/image/cvutils/img_colors.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47216 71c04702a3d5
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1996, 2000, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
/* Iterative color palette generation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <math.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#ifdef TIMES
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#endif /* TIMES */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#ifndef MAKECUBE_EXE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "jvm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
extern JavaVM *jvm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#define jio_fprintf fprintf
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#define TRUE 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#define FALSE 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
static float monitor_gamma[3] = {2.6f, 2.6f, 2.4f}; /* r,g,b */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
static float mat[3][3] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    {0.3811f, 0.2073f, 0.0213f},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    {0.3203f, 0.6805f, 0.1430f},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    {0.2483f, 0.1122f, 1.2417f}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
static float whiteXYZ[3] = { 0.9497f, 1.0000f, 1.4060f };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#define whitex (0.9497f / (0.9497f + 1.0000f + 1.4060f))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#define whitey (1.0000f / (0.9497f + 1.0000f + 1.4060f))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
static float uwht = 4*whitex/(-2*whitex + 12*whitey + 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
static float vwht = 9*whitey/(-2*whitex + 12*whitey + 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
static float Rmat[3][256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
static float Gmat[3][256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
static float Bmat[3][256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
static float Ltab[256], Utab[256], Vtab[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    unsigned char red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    unsigned char green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    unsigned char blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    unsigned char bestidx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    int nextidx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    float L, U, V;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    float dist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    float dE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    float dL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
} CmapEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
static int num_virt_cmap_entries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
static CmapEntry *virt_cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
static int prevtest[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
static int nexttest[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
static float Lscale = 10.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
/* this is a multiplier--it should not be zero */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
static float Weight = 250.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#define WEIGHT_DIST(d,l)   (Weight*(d)/(Weight+(l)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
#define UNWEIGHT_DIST(d,l) ((Weight+(l))*(d)/Weight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#if 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
#define WEIGHT_DIST(d,l) (d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
#define UNWEIGHT_DIST(d,l) (d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
static void
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
    93
init_matrices(void)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    static int done = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    if (done) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    for (i = 0; i < 256; ++i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        float iG = (float) pow(i/255.0, monitor_gamma[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        Rmat[0][i] = mat[0][0] * iG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        Rmat[1][i] = mat[0][1] * iG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        Rmat[2][i] = mat[0][2] * iG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        iG = (float) pow(i/255.0, monitor_gamma[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        Gmat[0][i] = mat[1][0] * iG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        Gmat[1][i] = mat[1][1] * iG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        Gmat[2][i] = mat[1][2] * iG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        iG = (float) pow(i/255.0, monitor_gamma[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        Bmat[0][i] = mat[2][0] * iG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        Bmat[1][i] = mat[2][1] * iG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        Bmat[2][i] = mat[2][2] * iG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    done = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
LUV_convert(int red, int grn, int blu, float *L, float *u, float *v)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    float X = Rmat[0][red] + Gmat[0][grn] + Bmat[0][blu];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    float Y = Rmat[1][red] + Gmat[1][grn] + Bmat[1][blu];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    float Z = Rmat[2][red] + Gmat[2][grn] + Bmat[2][blu];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    float sum = X+Y+Z;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    if (sum != 0.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        float x    = X/sum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        float y    = Y/sum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        float dnm  = -2*x + 12*y + 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        float ytmp = (float) pow(Y/whiteXYZ[1], 1.0/3.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (ytmp < .206893f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            *L = 903.3f*Y/whiteXYZ[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            *L = 116*(ytmp) - 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (dnm != 0.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            float uprm = 4*x/dnm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            float vprm = 9*y/dnm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            *u = 13*(*L)*(uprm-uwht);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            *v = 13*(*L)*(vprm-vwht);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            *u = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            *v = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        *L = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        *u = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        *v = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
static int cmapmax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
static int total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
static unsigned char cmap_r[256], cmap_g[256], cmap_b[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
#define DIST_THRESHOLD 7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
no_close_color(float l, float u, float v, int c_tot, int exact) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    for (i = 0; i < c_tot; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        float t, dist = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        t = Ltab[i] - l; dist += t*t*Lscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        t = Utab[i] - u; dist += t*t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        t = Vtab[i] - v; dist += t*t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (dist < (exact ? 0.1 : DIST_THRESHOLD))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
add_color(int r, int g, int b, int f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    if (total >= cmapmax)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    cmap_r[total] = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    cmap_g[total] = g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    cmap_b[total] = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    LUV_convert(cmap_r[total],cmap_g[total],cmap_b[total],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                Ltab + total, Utab + total, Vtab + total);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    if (no_close_color(Ltab[total], Utab[total], Vtab[total], total-1, f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        ++total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
static void
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   196
init_primaries(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    int r, g, b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    for (r = 0; r < 256; r += (r?128:127)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        for (g = 0; g < 256; g += (g?128:127)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            for (b = 0; b < 256; b += (b?128:127)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                if ((r == g) && (g == b)) continue; /* black or white */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                add_color(r, g, b, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
static void
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   210
init_pastels(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /* very light colors */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    for (i = 6; i >= 0; --i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        add_color((i&4) ? 0xff : 0xf0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                  (i&2) ? 0xff : 0xf0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                  (i&1) ? 0xff : 0xf0, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
static void
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   220
init_grays(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    for (i = 15; i < 255; i += 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        add_color(i, i, i, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
static void
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   227
init_mac_palette(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    add_color(255, 255, 204, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    add_color(255, 255, 0,   TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    add_color(255, 204, 153, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    add_color(255, 102, 204, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    add_color(255, 102, 51,  TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    add_color(221, 0, 0,     TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    add_color(204, 204, 255, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    add_color(204, 153, 102, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    add_color(153, 255, 255, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    add_color(153, 153, 255, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    add_color(153, 102, 153, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    add_color(153, 0, 102,   TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    add_color(102, 102, 204, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    add_color(51, 255, 153,  TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    add_color(51, 153, 102,  TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    add_color(51, 102, 102,  TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    add_color(51, 51, 102,   TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    add_color(51, 0, 153,    TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    add_color(0, 187, 0,     TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    add_color(0, 153, 255,   TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    add_color(0, 0, 221,     TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
init_virt_cmap(int tablesize, int testsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    int r, g, b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    int gray = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    CmapEntry *pCmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    unsigned int dotest[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    if (virt_cmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        free(virt_cmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        virt_cmap = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    num_virt_cmap_entries = tablesize * tablesize * tablesize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    virt_cmap = malloc(sizeof(CmapEntry) * num_virt_cmap_entries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Fix for bug 4070647 malloc return value not check in img_colors.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * We have to handle the malloc failure differently under
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Win32 and Solaris since under Solaris this file is linked with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * libawt.so and under Win32 it's a separate awt_makecube.exe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    if (virt_cmap == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
#ifndef MAKECUBE_EXE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        JNU_ThrowOutOfMemoryError(env, "init_virt_cmap: OutOfMemoryError");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        fprintf(stderr,"init_virt_cmap: OutOfMemoryError\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        exit(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    pCmap = virt_cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    for (r = 0; r < total; r++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (cmap_r[r] == cmap_g[r] && cmap_g[r] == cmap_b[r]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            if (gray < 0 || cmap_r[gray] < cmap_r[r]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                gray = r;
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
    if (gray < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        jio_fprintf(stderr, "Didn't find any grays in color table!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
#endif /* DEBUG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        gray = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    g = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    b = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    for (r = 0; r < tablesize - 1; ++r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (g >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            b = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            dotest[r] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            g -= tablesize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            dotest[r] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        prevtest[r] = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        g += testsize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    b = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    prevtest[r] = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    dotest[r] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    for (r = tablesize - 1; r >= 0; --r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (prevtest[r] == r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            b = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        nexttest[r] = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    for (r = 0; r < tablesize; ++r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (dotest[r]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            if (prevtest[r] != r || nexttest[r] != r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                jio_fprintf(stderr, "prev/next != r!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
#endif /* DEBUG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    for (r = 0; r < tablesize; ++r)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        int red = (int)(floor(r*255.0/(tablesize - 1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        for (g = 0; g < tablesize; ++g)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            int green = (int)(floor(g*255.0/(tablesize - 1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            for (b = 0; b < tablesize; ++b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                int blue = (int)(floor(b*255.0/(tablesize - 1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                float t, d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                if (pCmap >= virt_cmap + num_virt_cmap_entries) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    jio_fprintf(stderr, "OUT OF pCmap CONVERSION SPACE!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
#endif /* DEBUG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    continue;           /* Shouldn't happen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                pCmap->red = red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                pCmap->green = green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                pCmap->blue = blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                LUV_convert(red, green, blue, &pCmap->L, &pCmap->U, &pCmap->V);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                if ((red != green || green != blue) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    (!dotest[r] || !dotest[g] || !dotest[b]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    pCmap->nextidx = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                    pCmap++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                pCmap->bestidx = gray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                pCmap->nextidx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                t = Ltab[gray] - pCmap->L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                d = t * t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                if (red == green && green == blue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    pCmap->dist = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    d *= Lscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    d *= Lscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    t = Utab[gray] - pCmap->U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    d += t * t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    t = Vtab[gray] - pCmap->V;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    d += t * t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    pCmap->dist = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                pCmap->dE = WEIGHT_DIST(d, pCmap->L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                pCmap++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    if (pCmap < virt_cmap + num_virt_cmap_entries) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        jio_fprintf(stderr, "Didn't fill pCmap conversion table!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
#endif /* DEBUG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
find_nearest(CmapEntry *pCmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    int red = pCmap->red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    int grn = pCmap->green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    int blu = pCmap->blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    float L = pCmap->L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    float dist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    if ((red == grn) && (grn == blu)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        dist = pCmap->dist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        for (i = pCmap->nextidx; i < total; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            float dL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            if (cmap_r[i] != cmap_g[i] || cmap_g[i] != cmap_b[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            dL = Ltab[i] - L; dL *= dL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            if (dL < dist) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                dist = dL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                pCmap->dist = dist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                pCmap->dL = dist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                pCmap->dE = WEIGHT_DIST(dist*Lscale,L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                pCmap->bestidx = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        pCmap->nextidx = total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        float U = pCmap->U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        float V = pCmap->V;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        dist = pCmap->dist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        for (i = pCmap->nextidx; i < total; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            float dL, dU, dV, dE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            dL = Ltab[i] - L; dL *= (dL*Lscale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            dU = Utab[i] - U; dU *= dU;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            dV = Vtab[i] - V; dV *= dV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            dE = dL + dU + dV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            if (dE < dist)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                dist = dE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                /* *delta = (dL/4) + dU + dV; */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                /* *delta = dist */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                /* *delta = dL + 100*(dU+dV)/(100+L); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                pCmap->dist = dist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                pCmap->dE = WEIGHT_DIST(dE, L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                pCmap->dL = dL/Lscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                pCmap->bestidx = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        pCmap->nextidx = total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    return pCmap->bestidx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
#define MAX_OFFENDERS 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
static CmapEntry *offenders[MAX_OFFENDERS + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
static int num_offenders;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
insert_in_list(CmapEntry *pCmap)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    float dE = pCmap->dE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    for (i = num_offenders; i > 0; --i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if (dE < offenders[i-1]->dE) break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        offenders[i] = offenders[i-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    offenders[i] = pCmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    if (num_offenders < MAX_OFFENDERS) ++num_offenders;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
handle_biggest_offenders(int testtblsize, int maxcolors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    int i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    float dEthresh = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    CmapEntry *pCmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    num_offenders = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    for (pCmap = virt_cmap, i = 0; i < num_virt_cmap_entries; i++, pCmap++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (pCmap->nextidx < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (num_offenders == MAX_OFFENDERS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            && pCmap->dE < offenders[MAX_OFFENDERS-1]->dE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        find_nearest(pCmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        insert_in_list(pCmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    if (num_offenders > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        dEthresh = offenders[num_offenders-1]->dE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    for (i = 0; (total < maxcolors) && (i < num_offenders); ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        pCmap = offenders[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if (!pCmap) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        j = add_color(pCmap->red, pCmap->green, pCmap->blue, FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if (j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            for (j = i+1; j < num_offenders; ++j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                float dE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                pCmap = offenders[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                if (!pCmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                find_nearest(pCmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                dE = pCmap->dE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                if (dE < dEthresh) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                    offenders[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    if (offenders[i+1] == 0 || dE > offenders[i+1]->dE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                        offenders[j] = offenders[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                        offenders[i+1] = pCmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
img_makePalette(int cmapsize, int tablesize, int lookupsize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                float lscale, float weight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                int prevclrs, int doMac,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                unsigned char *reds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                unsigned char *greens,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                unsigned char *blues,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                unsigned char *lookup)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    CmapEntry *pCmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    int i, ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
#ifdef STATS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    double ave_dL, ave_dE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    double max_dL, max_dE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
#endif /* STATS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
#ifdef TIMES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    clock_t start, mid, tbl, end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    start = clock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
#endif /* TIMES */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    init_matrices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    Lscale = lscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    Weight = weight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    cmapmax = cmapsize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    total = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    for (i = 0; i < prevclrs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        add_color(reds[i], greens[i], blues[i], TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    add_color(0, 0, 0, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    add_color(255,255,255, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    /* do grays next; otherwise find_nearest may break! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    init_grays();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    if (doMac) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        init_mac_palette();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    init_pastels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    init_primaries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    /* special case some blues */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    add_color(0,0,192,TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    add_color(0x30,0x20,0x80,TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    add_color(0x20,0x60,0xc0,TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    init_virt_cmap(lookupsize, tablesize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    while (total < cmapsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        handle_biggest_offenders(tablesize, cmapsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    memcpy(reds, cmap_r, cmapsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    memcpy(greens, cmap_g, cmapsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    memcpy(blues, cmap_b, cmapsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
#ifdef TIMES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    mid = clock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
#endif /* TIMES */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    pCmap = virt_cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    for (i = 0; i < num_virt_cmap_entries; i++, pCmap++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        if (pCmap->nextidx < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        if (pCmap->nextidx < total) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            ix = find_nearest(pCmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
#ifdef TIMES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    tbl = clock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
#endif /* TIMES */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    pCmap = virt_cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    if (tablesize != lookupsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        int r, g, b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        for (r = 0; r < lookupsize; ++r)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            for (g = 0; g < lookupsize; ++g)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                for (b = 0; b < lookupsize; ++b, pCmap++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                    float L, U, V;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                    float bestd = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                    CmapEntry *pTest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    if (pCmap->nextidx >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                    if (r == g && g == b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                        jio_fprintf(stderr, "GRAY VALUE!?\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
#endif /* DEBUG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                    L = pCmap->L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                    U = pCmap->U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                    V = pCmap->V;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    for (i = 0; i < 8; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                        int ri, gi, bi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                        float d, t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                        ri = (i & 1) ? prevtest[r] : nexttest[r];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                        gi = (i & 2) ? prevtest[g] : nexttest[g];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                        bi = (i & 4) ? prevtest[b] : nexttest[b];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                        pTest = &virt_cmap[((ri * lookupsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                                            + gi) * lookupsize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                                           + bi];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                        if (pTest->nextidx < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                            jio_fprintf(stderr, "OOPS!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
#endif /* DEBUG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                        ix = pTest->bestidx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                        t = Ltab[ix] - L; d  = t * t * Lscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                        if (i != 0 && d > bestd) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                        t = Utab[ix] - U; d += t * t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                        if (i != 0 && d > bestd) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                        t = Vtab[ix] - V; d += t * t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                        if (i != 0 && d > bestd) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                        bestd = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                        pCmap->bestidx = ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    pCmap = virt_cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    for (i = 0; i < num_virt_cmap_entries; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        *lookup++ = (pCmap++)->bestidx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
#ifdef TIMES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    end = clock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
#endif /* TIMES */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
#ifdef STATS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    max_dL = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    max_dE = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    ave_dL = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    ave_dE = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    pCmap = virt_cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    for (i = 0; i < num_virt_cmap_entries; i++, pCmap++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        double t, dL, dU, dV, dE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        if (pCmap->nextidx < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            int ix = pCmap->bestidx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            dL = pCmap->L - Ltab[ix]; dL *= dL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            dU = pCmap->U - Utab[ix]; dU *= dU;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            dV = pCmap->V - Vtab[ix]; dV *= dV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            dE = dL * Lscale + dU + dV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            dE = WEIGHT_DIST(dE, pCmap->L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            dL = pCmap->dL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            dE = pCmap->dE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        if (dL > max_dL) max_dL = dL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        t = UNWEIGHT_DIST(dE,dL) - dL*(Lscale-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        if (t > max_dE) max_dE = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        ave_dL += (dL > 0) ? sqrt(dL) : 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        ave_dE += (t > 0) ? sqrt(t) : 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    jio_fprintf(stderr, "colors=%d, tablesize=%d, cubesize=%d, ",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            cmapsize, tablesize, lookupsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    jio_fprintf(stderr, "Lscale=%5.3f, Weight=%5.3f mac=%s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            (double)lscale, (double)weight, doMac ? "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    jio_fprintf(stderr, "Worst case error dL = %5.3f, dE = %5.3f\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            sqrt(max_dL), sqrt(max_dE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    jio_fprintf(stderr, "Average error dL = %5.3f, dE = %5.3f\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            ave_dL / num_virt_cmap_entries,  ave_dE / num_virt_cmap_entries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
#endif /* STATS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
#ifdef TIMES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    jio_fprintf(stderr, "%f seconds to find colors\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            (double)(mid - start) / CLOCKS_PER_SEC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    jio_fprintf(stderr, "%f seconds to finish nearest colors\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            (double)(tbl - mid) / CLOCKS_PER_SEC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    jio_fprintf(stderr, "%f seconds to make lookup table\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            (double)(end - tbl) / CLOCKS_PER_SEC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    jio_fprintf(stderr, "%f seconds total\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            (double)(end - start) / CLOCKS_PER_SEC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
#endif /* TIMES */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    free(virt_cmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    virt_cmap = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
}