jdk/src/solaris/native/sun/awt/X11Color.c
author anthony
Wed, 06 May 2009 20:06:23 +0400
changeset 2760 f038acdbdf9c
parent 2758 d2fbe9b5857a
child 2807 db01a7f6d657
permissions -rw-r--r--
6838046: Rollback 6762511 due to build failure (6838003) Reviewed-by: yan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1995-2004 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *      Image dithering and rendering code for X11.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <math.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <sys/time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <sys/resource.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <alloca.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <X11/Xlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <X11/Xatom.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <X11/Xutil.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "awt_p.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "java_awt_Color.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "java_awt_SystemColor.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "java_awt_color_ColorSpace.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "java_awt_Transparency.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#include "java_awt_image_DataBuffer.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#include "img_colors.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#include "imageInitIDs.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#include "dither.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#include <jni_util.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
static int debug_colormap = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#define MAX_PALETTE8_SIZE (256)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#define MAX_PALETTE12_SIZE (4096)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
#define MAX_PALETTE_SIZE MAX_PALETTE12_SIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
/* returns the absolute value x */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#define ABS(x) ((x) < 0 ? -(x) : (x))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define CLIP(val,min,max)       ((val < min) ? min : ((val > max) ? max : val))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#define RGBTOGRAY(r, g, b) ((int) (.299 * r + .587 * g + .114 * b + 0.5))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    FREE_COLOR          = 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    LIKELY_COLOR        = 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    UNAVAILABLE_COLOR   = 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    ALLOCATED_COLOR     = 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * Constants to control the filling of the colormap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * By default, try to allocate colors in the default colormap until
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * CMAP_ALLOC_DEFAULT colors are being used (by Java and/or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * applications).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * For cases where the default colormap may already have a large
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * number of colors in it, make sure that we ourselves try to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * at least CMAP_ALLOC_MIN new colors, even if we need to allocate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * more than the DEFAULT to do that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Under no circumstances will the colormap be filled to more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * CMAP_ALLOC_MAX colors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
#define CMAP_ALLOC_MIN          100     /* minimum number of colors to "add" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
#define CMAP_ALLOC_DEFAULT      200     /* default number of colors in cmap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
#define CMAP_ALLOC_MAX          245     /* maximum number of colors in cmap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
#include <sys/utsname.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    char *machine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    int  cubesize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
} machinemap[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    { "i86pc", LOOKUPSIZE / 4 }, /* BugTraq ID 4102599 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    { "sun4c", LOOKUPSIZE / 4 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    { "sun4m", LOOKUPSIZE / 2 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    { "sun4d", LOOKUPSIZE / 2 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    { "sun4u", LOOKUPSIZE / 1 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
#define MACHMAPSIZE     (sizeof(machinemap) / sizeof(machinemap[0]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
int getVirtCubeSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    struct utsname name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    int i, ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    ret = uname(&name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    if (ret < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
#include <errno.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        jio_fprintf(stderr, "uname errno = %d, using default cubesize %d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    errno, LOOKUPSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return LOOKUPSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    for (i = 0; i < MACHMAPSIZE; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (strcmp(name.machine, machinemap[i].machine) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            if (debug_colormap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                jio_fprintf(stderr, "'%s'.cubesize = '%d'\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                            machinemap[i].machine, machinemap[i].cubesize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            return machinemap[i].cubesize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    if (debug_colormap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        jio_fprintf(stderr, "unknown machine '%s' using cubesize %d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    name.machine, LOOKUPSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    return LOOKUPSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
#else /* __solaris__ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
#define getVirtCubeSize()       (LOOKUPSIZE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
#endif /* __solaris__ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
unsigned char img_bwgamma[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
uns_ordered_dither_array img_oda_alpha;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
#ifdef NEED_IMAGE_CONVERT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
ImgConvertFcn DirectImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
ImgConvertFcn Dir16IcmOpqUnsImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
ImgConvertFcn Dir16IcmTrnUnsImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
ImgConvertFcn Dir16IcmOpqSclImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
ImgConvertFcn Dir16DcmOpqUnsImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
ImgConvertFcn Dir16DcmTrnUnsImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
ImgConvertFcn Dir16DcmOpqSclImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
ImgConvertFcn Dir32IcmOpqUnsImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
ImgConvertFcn Dir32IcmTrnUnsImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
ImgConvertFcn Dir32IcmOpqSclImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
ImgConvertFcn Dir32DcmOpqUnsImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
ImgConvertFcn Dir32DcmTrnUnsImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
ImgConvertFcn Dir32DcmOpqSclImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
ImgConvertFcn PseudoImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
ImgConvertFcn PseudoFSImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
ImgConvertFcn FSColorIcmOpqUnsImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
ImgConvertFcn FSColorDcmOpqUnsImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
ImgConvertFcn OrdColorIcmOpqUnsImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
ImgConvertFcn OrdColorDcmOpqUnsImageConvert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
#endif /* NEED_IMAGE_CONVERT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * Find the best color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
awt_color_matchTC(int r, int g, int b, AwtGraphicsConfigDataPtr awt_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    r = CLIP(r, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    g = CLIP(g, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    b = CLIP(b, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    return (((r >> awt_data->awtImage->clrdata.rScale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                << awt_data->awtImage->clrdata.rOff) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            ((g >> awt_data->awtImage->clrdata.gScale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                << awt_data->awtImage->clrdata.gOff) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            ((b >> awt_data->awtImage->clrdata.bScale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                << awt_data->awtImage->clrdata.bOff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
awt_color_matchGS(int r, int g, int b, AwtGraphicsConfigDataPtr awt_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    r = CLIP(r, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    g = CLIP(g, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    b = CLIP(b, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    return awt_data->color_data->img_grays[RGBTOGRAY(r, g, b)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
awt_color_match(int r, int g, int b, AwtGraphicsConfigDataPtr awt_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    int besti = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    int mindist, i, t, d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    ColorEntry *p = awt_data->color_data->awt_Colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    r = CLIP(r, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    g = CLIP(g, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    b = CLIP(b, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /* look for pure gray match */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    if ((r == g) && (g == b)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
      mindist = 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
      for (i = 0 ; i < awt_data->awt_num_colors ; i++, p++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (p->flags == ALLOCATED_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
          if (! ((p->r == p->g) && (p->g == p->b)) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
              continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
          d = ABS(p->r - r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
          if (d == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
              return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
          if (d < mindist) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
              besti = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
              mindist = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
      return besti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /* look for non-pure gray match */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    mindist = 256 * 256 * 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    for (i = 0 ; i < awt_data->awt_num_colors ; i++, p++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (p->flags == ALLOCATED_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            t = p->r - r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            d = t * t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (d >= mindist)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            t = p->g - g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            d += t * t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            if (d >= mindist)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            t = p->b - b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            d += t * t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            if (d >= mindist)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            if (d == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            if (d < mindist) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                besti = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                mindist = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    return besti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 * Allocate a color in the X color map and return the pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 * If the "expected pixel" is non-negative then we will only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 * accept the allocation if we get exactly that pixel value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 * This prevents us from seeing a bunch of ReadWrite pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 * allocated by another imaging application and duplicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * that set of inaccessible pixels in our precious remaining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * ReadOnly colormap cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
alloc_col(Display *dpy, Colormap cm, int r, int g, int b, int pixel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
          AwtGraphicsConfigDataPtr awt_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    XColor col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    r = CLIP(r, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    g = CLIP(g, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    b = CLIP(b, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    col.flags = DoRed | DoGreen | DoBlue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    col.red   = (r << 8) | r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    col.green = (g << 8) | g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    col.blue  = (b << 8) | b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    if (XAllocColor(dpy, cm, &col)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (debug_colormap)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            jio_fprintf(stdout, "allocated %d (%d,%d, %d)\n", col.pixel, r, g, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (pixel >= 0 && col.pixel != (unsigned long)pixel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
             * If we were trying to allocate a shareable "ReadOnly"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
             * color then we would have gotten back the expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
             * pixel.  If the returned pixel was different, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
             * the source color that we were attempting to gain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
             * access to must be some other application's ReadWrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
             * private color.  We free the returned pixel so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
             * we won't waste precious colormap entries by duplicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
             * that color in the as yet unallocated entries.  We
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
             * return -1 here to indicate the failure to get the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
             * expected pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            if (debug_colormap)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                jio_fprintf(stdout, "   used by other app, freeing\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            awt_data->color_data->awt_Colors[pixel].flags = UNAVAILABLE_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            XFreeColors(dpy, cm, &col.pixel, 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
         * Our current implementation doesn't support pixels which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
         * don't fit in 8 bit (even for 12-bit visuals)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (col.pixel > 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            if (debug_colormap)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                jio_fprintf(stdout, "pixel %d for (%d,%d, %d) is > 8 bit, releasing.\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                            col.pixel, r, g, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            XFreeColors(dpy, cm, &col.pixel, 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            return awt_color_match(r, g, b, awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        awt_data->color_data->awt_Colors[col.pixel].flags = ALLOCATED_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        awt_data->color_data->awt_Colors[col.pixel].r = col.red   >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        awt_data->color_data->awt_Colors[col.pixel].g = col.green >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        awt_data->color_data->awt_Colors[col.pixel].b = col.blue  >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (awt_data->color_data->awt_icmLUT != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            awt_data->color_data->awt_icmLUT2Colors[col.pixel] = col.pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            awt_data->color_data->awt_icmLUT[col.pixel] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                0xff000000 |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                (awt_data->color_data->awt_Colors[col.pixel].r<<16) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                (awt_data->color_data->awt_Colors[col.pixel].g<<8) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                (awt_data->color_data->awt_Colors[col.pixel].b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return col.pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    } else if (debug_colormap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        jio_fprintf(stdout, "can't allocate (%d,%d, %d)\n", r, g, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    return awt_color_match(r, g, b, awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
awt_allocate_systemcolors(XColor *colorsPtr, int num_pixels, AwtGraphicsConfigDataPtr awtData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    int r, g, b, pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    for (i=0; i < num_pixels; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        r = colorsPtr[i].red   >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        g = colorsPtr[i].green >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        b = colorsPtr[i].blue  >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        pixel = alloc_col(awt_display, awtData->awt_cmap, r, g, b, -1, awtData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
awt_fill_imgcv(ImgConvertFcn **array, int mask, int value, ImgConvertFcn fcn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    for (i = 0; i < NUM_IMGCV; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if ((i & mask) == value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            array[i] = fcn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
 * called from X11Server_create() in xlib.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
awt_allocate_colors(AwtGraphicsConfigDataPtr awt_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    Display *dpy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    unsigned long freecolors[MAX_PALETTE_SIZE], plane_masks[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    int paletteSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    XColor cols[MAX_PALETTE_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    unsigned char reds[256], greens[256], blues[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    int indices[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    Colormap cm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    int i, j, k, cmapsize, nfree, depth, bpp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    int allocatedColorsNum, unavailableColorsNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    XPixmapFormatValues *pPFV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    int numpfv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    XVisualInfo *pVI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    char *forcemono;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    char *forcegray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    make_uns_ordered_dither_array(img_oda_alpha, 256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    forcemono = getenv("FORCEMONO");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    forcegray = getenv("FORCEGRAY");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    if (forcemono && !forcegray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        forcegray = forcemono;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Get the colormap and make sure we have the right visual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    dpy = awt_display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    cm = awt_data->awt_cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    depth = awt_data->awt_depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    pVI = &awt_data->awt_visInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    awt_data->awt_num_colors = awt_data->awt_visInfo.colormap_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    awt_data->awtImage = (awtImageData *) calloc (1, sizeof (awtImageData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    pPFV = XListPixmapFormats(dpy, &numpfv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    if (pPFV) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        for (i = 0; i < numpfv; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            if (pPFV[i].depth == depth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                awt_data->awtImage->wsImageFormat = pPFV[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        XFree(pPFV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    bpp = awt_data->awtImage->wsImageFormat.bits_per_pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    if (bpp == 24) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        bpp = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    awt_data->awtImage->clrdata.bitsperpixel = bpp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    awt_data->awtImage->Depth = depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    if ((bpp == 32 || bpp == 16) && pVI->class == TrueColor && depth >= 15) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        awt_data->AwtColorMatch = awt_color_matchTC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        awt_data->awtImage->clrdata.rOff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        for (i = pVI->red_mask; (i & 1) == 0; i >>= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            awt_data->awtImage->clrdata.rOff++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        awt_data->awtImage->clrdata.rScale = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        while (i < 0x80) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            awt_data->awtImage->clrdata.rScale++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            i <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        awt_data->awtImage->clrdata.gOff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        for (i = pVI->green_mask; (i & 1) == 0; i >>= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            awt_data->awtImage->clrdata.gOff++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        awt_data->awtImage->clrdata.gScale = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        while (i < 0x80) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            awt_data->awtImage->clrdata.gScale++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            i <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        awt_data->awtImage->clrdata.bOff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        for (i = pVI->blue_mask; (i & 1) == 0; i >>= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            awt_data->awtImage->clrdata.bOff++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        awt_data->awtImage->clrdata.bScale = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        while (i < 0x80) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            awt_data->awtImage->clrdata.bScale++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            i <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
#ifdef NEED_IMAGE_CONVERT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        awt_fill_imgcv(awt_data->awtImage->convert, 0, 0, DirectImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                        | IMGCV_ALPHABITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                       (IMGCV_UNSCALED | IMGCV_BYTEIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                        | IMGCV_OPAQUE | IMGCV_ICM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                       (bpp == 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                        ? Dir32IcmOpqUnsImageConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                        : Dir16IcmOpqUnsImageConvert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                        | IMGCV_ALPHABITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                       (IMGCV_UNSCALED | IMGCV_BYTEIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                        | IMGCV_ALPHA | IMGCV_ICM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                       (bpp == 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                        ? Dir32IcmTrnUnsImageConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                        : Dir16IcmTrnUnsImageConvert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                        | IMGCV_ALPHABITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                       (IMGCV_SCALED | IMGCV_BYTEIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                        | IMGCV_OPAQUE | IMGCV_ICM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                       (bpp == 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                        ? Dir32IcmOpqSclImageConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                        : Dir16IcmOpqSclImageConvert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                        | IMGCV_ALPHABITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                       (IMGCV_UNSCALED | IMGCV_INTIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                        | IMGCV_OPAQUE | IMGCV_DCM8),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                       (bpp == 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                        ? Dir32DcmOpqUnsImageConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                        : Dir16DcmOpqUnsImageConvert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                        | IMGCV_ALPHABITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                       (IMGCV_UNSCALED | IMGCV_INTIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                        | IMGCV_ALPHA | IMGCV_DCM8),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                       (bpp == 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                        ? Dir32DcmTrnUnsImageConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                        : Dir16DcmTrnUnsImageConvert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                        | IMGCV_ALPHABITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                       (IMGCV_SCALED | IMGCV_INTIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                        | IMGCV_OPAQUE | IMGCV_DCM8),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                       (bpp == 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                        ? Dir32DcmOpqSclImageConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                        : Dir16DcmOpqSclImageConvert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
#endif /* NEED_IMAGE_CONVERT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    } else if (bpp <= 16 && (pVI->class == StaticGray
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                            || pVI->class == GrayScale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                            || (pVI->class == PseudoColor && forcegray))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        awt_data->AwtColorMatch = awt_color_matchGS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        awt_data->awtImage->clrdata.grayscale = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        awt_data->awtImage->clrdata.bitsperpixel = MAX(bpp, 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
#ifdef NEED_IMAGE_CONVERT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        awt_fill_imgcv(awt_data->awtImage->convert, 0, 0, PseudoImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        if (getenv("NOFSDITHER") == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                           IMGCV_ORDERBITS, IMGCV_TDLRORDER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                           PseudoFSImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
#endif /* NEED_IMAGE_CONVERT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    } else if (depth <= 12 && (pVI->class == PseudoColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                             || pVI->class == TrueColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                             || pVI->class == StaticColor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        if (pVI->class == TrueColor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
           awt_data->awt_num_colors = (1 << pVI->depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        awt_data->AwtColorMatch = awt_color_match;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        awt_data->awtImage->clrdata.bitsperpixel = MAX(bpp, 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
#ifdef NEED_IMAGE_CONVERT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        awt_fill_imgcv(awt_data->awtImage->convert, 0, 0, PseudoImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (getenv("NOFSDITHER") == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            awt_fill_imgcv(awt_data->awtImage->convert, IMGCV_ORDERBITS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                           IMGCV_TDLRORDER, PseudoFSImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                           (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                            | IMGCV_ALPHABITS | IMGCV_ORDERBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                            | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                           (IMGCV_UNSCALED | IMGCV_BYTEIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                            | IMGCV_OPAQUE | IMGCV_TDLRORDER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                            | IMGCV_ICM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                           FSColorIcmOpqUnsImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                           (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                            | IMGCV_ALPHABITS | IMGCV_ORDERBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                            | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                           (IMGCV_UNSCALED | IMGCV_INTIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                            | IMGCV_OPAQUE | IMGCV_TDLRORDER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                            | IMGCV_DCM8),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                           FSColorDcmOpqUnsImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS | IMGCV_ALPHABITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                        | IMGCV_ORDERBITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                       (IMGCV_UNSCALED | IMGCV_BYTEIN | IMGCV_OPAQUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                        | IMGCV_RANDORDER | IMGCV_ICM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                       OrdColorIcmOpqUnsImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS | IMGCV_ALPHABITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                        | IMGCV_ORDERBITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                       (IMGCV_UNSCALED | IMGCV_INTIN | IMGCV_OPAQUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                        | IMGCV_RANDORDER | IMGCV_DCM8),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                       OrdColorDcmOpqUnsImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
#endif /* NEED_IMAGE_CONVERT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        free (awt_data->awtImage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    if (depth > 12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    if (depth == 12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        paletteSize = MAX_PALETTE12_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        paletteSize = MAX_PALETTE8_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    if (awt_data->awt_num_colors > paletteSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        free (awt_data->awtImage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    /* Allocate ColorData structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    awt_data->color_data = ZALLOC (_ColorData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    awt_data->color_data->screendata = 1; /* This ColorData struct corresponds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                             to some AWT screen/visual, so when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                             any IndexColorModel using this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                                             struct is finalized, don't free
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                                             the struct in freeICMColorData.
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
     * Initialize colors array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    for (i = 0; i < awt_data->awt_num_colors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        cols[i].pixel = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    awt_data->color_data->awt_Colors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        (ColorEntry *)calloc(paletteSize, sizeof (ColorEntry));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    XQueryColors(dpy, cm, cols, awt_data->awt_num_colors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    for (i = 0; i < awt_data->awt_num_colors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        awt_data->color_data->awt_Colors[i].r = cols[i].red >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        awt_data->color_data->awt_Colors[i].g = cols[i].green >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        awt_data->color_data->awt_Colors[i].b = cols[i].blue >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        awt_data->color_data->awt_Colors[i].flags = LIKELY_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * Determine which colors in the colormap can be allocated and mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * them in the colors array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    nfree = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    for (i = (paletteSize / 2); i > 0; i >>= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        if (XAllocColorCells(dpy, cm, False, plane_masks, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                             freecolors + nfree, i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            nfree += i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    for (i = 0; i < nfree; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        awt_data->color_data->awt_Colors[freecolors[i]].flags = FREE_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    if (debug_colormap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        jio_fprintf(stdout, "%d free.\n", nfree);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    XFreeColors(dpy, cm, freecolors, nfree, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * Allocate the colors that are already allocated by other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * applications
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    for (i = 0; i < awt_data->awt_num_colors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        if (awt_data->color_data->awt_Colors[i].flags == LIKELY_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            awt_data->color_data->awt_Colors[i].flags = FREE_COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            alloc_col(dpy, cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                      awt_data->color_data->awt_Colors[i].r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                      awt_data->color_data->awt_Colors[i].g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                      awt_data->color_data->awt_Colors[i].b, i, awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    if (debug_colormap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        jio_fprintf(stdout, "got the already allocated ones\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * Allocate more colors, filling the color space evenly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    alloc_col(dpy, cm, 255, 255, 255, -1, awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    alloc_col(dpy, cm, 0, 0, 0, -1, awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    if (awt_data->awtImage->clrdata.grayscale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        int g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        ColorEntry *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        if (!forcemono) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            for (i = 128; i > 0; i >>= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                for (g = i; g < 256; g += (i * 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                    alloc_col(dpy, cm, g, g, g, -1, awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        awt_data->color_data->img_grays =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            (unsigned char *)calloc(256, sizeof(unsigned char));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        for (g = 0; g < 256; g++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            int mindist, besti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            int d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            p = awt_data->color_data->awt_Colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            mindist = 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            besti = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            for (i = 0 ; i < awt_data->awt_num_colors ; i++, p++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                if (forcegray && (p->r != p->g || p->g != p->b))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                if (forcemono && p->g != 0 && p->g != 255)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                if (p->flags == ALLOCATED_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    d = p->g - g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    if (d < 0) d = -d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    if (d < mindist) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                        besti = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                        if (d == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                        mindist = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            awt_data->color_data->img_grays[g] = besti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        if (forcemono || (depth == 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            char *gammastr = getenv("HJGAMMA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            double gamma = atof(gammastr ? gammastr : "1.6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            if (gamma < 0.01) gamma = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            if (debug_colormap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                jio_fprintf(stderr, "gamma = %f\n", gamma);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            for (i = 0; i < 256; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                img_bwgamma[i] = (int) (pow(i/255.0, gamma) * 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                if (debug_colormap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    jio_fprintf(stderr, "%3d ", img_bwgamma[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                    if ((i & 7) == 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                        jio_fprintf(stderr, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            for (i = 0; i < 256; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                img_bwgamma[i] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        if (debug_colormap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            jio_fprintf(stderr, "GrayScale initialized\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            jio_fprintf(stderr, "color table:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            for (i = 0; i < awt_data->awt_num_colors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                jio_fprintf(stderr, "%3d: %3d %3d %3d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                        i, awt_data->color_data->awt_Colors[i].r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                        awt_data->color_data->awt_Colors[i].g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                        awt_data->color_data->awt_Colors[i].b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            jio_fprintf(stderr, "gray table:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            for (i = 0; i < 256; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                jio_fprintf(stderr, "%3d ", awt_data->color_data->img_grays[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                if ((i & 7) == 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                    jio_fprintf(stderr, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        alloc_col(dpy, cm, 255, 0, 0, -1, awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        alloc_col(dpy, cm, 0, 255, 0, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        alloc_col(dpy, cm, 0, 0, 255, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        alloc_col(dpy, cm, 255, 255, 0, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        alloc_col(dpy, cm, 255, 0, 255, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        alloc_col(dpy, cm, 0, 255, 255, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        alloc_col(dpy, cm, 192, 192, 192, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        alloc_col(dpy, cm, 255, 128, 128, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        alloc_col(dpy, cm, 128, 255, 128, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        alloc_col(dpy, cm, 128, 128, 255, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        alloc_col(dpy, cm, 255, 255, 128, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        alloc_col(dpy, cm, 255, 128, 255, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        alloc_col(dpy, cm, 128, 255, 255, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    allocatedColorsNum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    unavailableColorsNum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    /* we do not support more than 256 entries in the colormap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
       even for 12-bit PseudoColor visuals */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    for (i = 0; i < MAX_PALETTE8_SIZE; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        if (awt_data->color_data->awt_Colors[i].flags == ALLOCATED_COLOR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            reds[allocatedColorsNum] = awt_data->color_data->awt_Colors[i].r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            greens[allocatedColorsNum] = awt_data->color_data->awt_Colors[i].g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            blues[allocatedColorsNum] = awt_data->color_data->awt_Colors[i].b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            allocatedColorsNum++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        } else if (awt_data->color_data->awt_Colors[i].flags ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                                                        UNAVAILABLE_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            unavailableColorsNum++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    if (depth > 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        cmapsize = MAX_PALETTE8_SIZE - unavailableColorsNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        cmapsize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        if (getenv("CMAPSIZE") != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            cmapsize = atoi(getenv("CMAPSIZE"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        if (cmapsize <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            cmapsize = CMAP_ALLOC_DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        if (cmapsize < allocatedColorsNum + unavailableColorsNum + CMAP_ALLOC_MIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            cmapsize = allocatedColorsNum + unavailableColorsNum + CMAP_ALLOC_MIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        if (cmapsize > CMAP_ALLOC_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            cmapsize = CMAP_ALLOC_MAX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        if (cmapsize < allocatedColorsNum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            cmapsize = allocatedColorsNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        cmapsize -= unavailableColorsNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    k = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    if (getenv("VIRTCUBESIZE") != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        k = atoi(getenv("VIRTCUBESIZE"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    if (k == 0 || (k & (k - 1)) != 0 || k > 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        k = getVirtCubeSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    awt_data->color_data->img_clr_tbl =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        (unsigned char *)calloc(LOOKUPSIZE * LOOKUPSIZE * LOOKUPSIZE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                                sizeof(unsigned char));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    img_makePalette(cmapsize, k, LOOKUPSIZE, 50, 250,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                    allocatedColorsNum, TRUE, reds, greens, blues,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                    awt_data->color_data->img_clr_tbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                    /*img_clr_tbl);*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    for (i = 0; i < cmapsize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        indices[i] = alloc_col(dpy, cm, reds[i], greens[i], blues[i], -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                               awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    for (i = 0; i < LOOKUPSIZE * LOOKUPSIZE * LOOKUPSIZE  ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        awt_data->color_data->img_clr_tbl[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            indices[awt_data->color_data->img_clr_tbl[i]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    awt_data->color_data->img_oda_red   = &(std_img_oda_red[0][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    awt_data->color_data->img_oda_green = &(std_img_oda_green[0][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    awt_data->color_data->img_oda_blue  = &(std_img_oda_blue[0][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    make_dither_arrays(cmapsize, awt_data->color_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    std_odas_computed = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    if (debug_colormap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        int alloc_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        int reuse_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        int free_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        for (i = 0; i < awt_data->awt_num_colors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            switch (awt_data->color_data->awt_Colors[i].flags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
              case ALLOCATED_COLOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                alloc_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
              case LIKELY_COLOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                reuse_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
              case FREE_COLOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                free_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        jio_fprintf(stdout, "%d total, %d allocated, %d reused, %d still free.\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                    awt_data->awt_num_colors, alloc_count, reuse_count, free_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    /* Fill in the ICM lut and lut2cmap mapping */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    awt_data->color_data->awt_numICMcolors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    awt_data->color_data->awt_icmLUT2Colors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        (unsigned char *)calloc(paletteSize, sizeof (unsigned char));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    awt_data->color_data->awt_icmLUT = (int *)calloc(paletteSize, sizeof(int));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    for (i=0; i < paletteSize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        /* Keep the mapping between this lut and the actual cmap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        awt_data->color_data->awt_icmLUT2Colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            [awt_data->color_data->awt_numICMcolors] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        if (awt_data->color_data->awt_Colors[i].flags == ALLOCATED_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            /* Screen IndexColorModel LUTS are always xRGB */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            awt_data->color_data->awt_icmLUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                    [awt_data->color_data->awt_numICMcolors++] = 0xff000000 |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                (awt_data->color_data->awt_Colors[i].r<<16) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                (awt_data->color_data->awt_Colors[i].g<<8) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                (awt_data->color_data->awt_Colors[i].b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            /* Screen IndexColorModel LUTS are always xRGB */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            awt_data->color_data->awt_icmLUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                        [awt_data->color_data->awt_numICMcolors++] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
#define red(v)          (((v) >> 16) & 0xFF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
#define green(v)        (((v) >>  8) & 0xFF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
#define blue(v)         (((v) >>  0) & 0xFF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
jobject awtJNI_GetColorModel(JNIEnv *env, AwtGraphicsConfigDataPtr aData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    jobject awt_colormodel = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    jmethodID mid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    if ((*env)->PushLocalFrame(env, 16) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    if ((aData->awt_visInfo.class == TrueColor) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        (aData->awt_depth >= 15))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        clazz = (*env)->FindClass(env,"java/awt/image/DirectColorModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
2760
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   903
        mid = (*env)->GetMethodID(env,clazz,"<init>","(IIIII)V");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
2760
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   905
        if (mid == NULL) {
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   906
            (*env)->PopLocalFrame(env, 0);
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   907
            return NULL;
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   908
        }
2758
d2fbe9b5857a 6762511: Translucency is not working on Linux using Metacity
anthony
parents: 2
diff changeset
   909
2760
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   910
        awt_colormodel = (*env)->NewObject(env,clazz, mid,
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   911
                                           aData->awt_visInfo.depth,
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   912
                                           aData->awt_visInfo.red_mask,
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   913
                                           aData->awt_visInfo.green_mask,
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   914
                                           aData->awt_visInfo.blue_mask,
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   915
                                           0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        if(awt_colormodel == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    else if (aData->awt_visInfo.class == StaticGray &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
             aData->awt_num_colors == 256) {
2760
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   926
        jclass clazz1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        jobject cspace = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        jint bits[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        jintArray bitsArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        jboolean falseboolean = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
2760
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   932
        clazz1 = (*env)->FindClass(env,"java/awt/color/ColorSpace");
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   933
        mid = (*env)->GetStaticMethodID(env, clazz1, "getInstance",
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   934
              "(I)Ljava/awt/color/ColorSpace;");
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   935
        if (mid == NULL) {
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   936
            (*env)->PopLocalFrame(env, 0);
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   937
            return NULL;
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   938
        }
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   939
        /* SECURITY: This is safe, because static methods cannot
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   940
         *           be overridden, and this method does not invoke
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   941
         *           client code
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   942
         */
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   943
        cspace = (*env)->CallStaticObjectMethod(env, clazz1, mid,
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   944
            java_awt_color_ColorSpace_CS_GRAY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        if (cspace == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        bits[0] = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        bitsArray = (*env)->NewIntArray(env, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        if (bitsArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            (*env)->SetIntArrayRegion(env, bitsArray, 0, 1, bits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        clazz = (*env)->FindClass(env,"java/awt/image/ComponentColorModel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        mid = (*env)->GetMethodID(env,clazz,"<init>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            "(Ljava/awt/color/ColorSpace;[IZZII)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        if (mid == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        awt_colormodel = (*env)->NewObject(env,clazz, mid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                                           cspace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                                           bitsArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                                           falseboolean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                                           falseboolean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                                           java_awt_Transparency_OPAQUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                                           java_awt_image_DataBuffer_TYPE_BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        if(awt_colormodel == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        jint rgb[MAX_PALETTE_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        jbyte valid[MAX_PALETTE_SIZE / 8], *pValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        jintArray hArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        jobject validBits = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        ColorEntry *c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        int i, allocAllGray, b, allvalid, paletteSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        jlong pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        if (aData->awt_visInfo.depth == 12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            paletteSize = MAX_PALETTE12_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            paletteSize = MAX_PALETTE8_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        c = aData->color_data->awt_Colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        pValid = &valid[sizeof(valid)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        allocAllGray = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        b = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        allvalid = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        for (i = 0; i < paletteSize; i++, c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            if (c->flags == ALLOCATED_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                rgb[i] = (0xff000000 |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                          (c->r << 16) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                          (c->g <<  8) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                          (c->b <<  0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                if (c->r != c->g || c->g != c->b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                    allocAllGray = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                b |= (1 << (i % 8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                rgb[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                b &= ~(1 << (i % 8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                allvalid = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            if ((i % 8) == 7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                *--pValid = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                /* b = 0; not needed as each bit is explicitly set */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        if (allocAllGray && (aData->awtImage->clrdata.grayscale == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
              Fix for 4351638 - Gray scale HW mode on Dome frame buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                                crashes VM on Solaris.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
              It is possible for an X11 frame buffer to advertise a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
              PseudoColor visual, but to force all allocated colormap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
              entries to be gray colors.  The Dome card does this when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
              HW is jumpered for a grayscale monitor, but the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
              visual is set to PseudoColor.  In that case awtJNI_GetColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
              will be called with aData->awtImage->clrdata.grayscale == 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
              but the IndexColorModel created below will detect that only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
              gray colors exist and expect the inverse gray LUT to exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
              So above when filling the hR, hG, and hB arrays we detect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
              whether all allocated colors are gray.  If so, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
              aData->awtImage->clrdata.grayscale == 0, we fall into this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
              code to set aData->awtImage->clrdata.grayscale = 1 and do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
              other things needed for the grayscale case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            int g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            ColorEntry *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            aData->awtImage->clrdata.grayscale = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            aData->color_data->img_grays =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                (unsigned char *)calloc(256, sizeof(unsigned char));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            if (aData->color_data->img_grays == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            for (g = 0; g < 256; g++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                int mindist, besti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                int d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                p = aData->color_data->awt_Colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                mindist = 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                besti = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                for (i = 0 ; i < paletteSize; i++, p++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                    if (p->flags == ALLOCATED_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                        d = p->g - g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                        if (d < 0) d = -d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                        if (d < mindist) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                            besti = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                            if (d == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                            mindist = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                aData->color_data->img_grays[g] = besti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            for (i = 0; i < 256; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                img_bwgamma[i] = i;    /* REMIND: what is img_bwgamma?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                                        *         is it still used anywhere?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                                        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        if (aData->awtImage->clrdata.grayscale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            ColorEntry *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            /* For purposes of creating an IndexColorModel, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
               transparent black for non-allocated or non-gray colors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            p = aData->color_data->awt_Colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            b = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            pValid = &valid[sizeof(valid)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            for (i = 0; i < paletteSize; i++, p++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                if ((p->flags != ALLOCATED_COLOR) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                    (p->r != p->g || p->g != p->b))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                    rgb[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                    b &= ~(1 << (i % 8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                    allvalid = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                    b |= (1 << (i % 8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                if ((i % 8) == 7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                    *--pValid = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                    /* b = 0; not needed as each bit is explicitly set */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            if (aData->color_data->pGrayInverseLutData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                /* Compute the inverse gray LUT for this aData->color_data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                   struct, if not already computed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                initInverseGrayLut(rgb, aData->awt_num_colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                                   aData->color_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        if (!allvalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            jobject bArray = (*env)->NewByteArray(env, sizeof(valid));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            if (bArray == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                (*env)->SetByteArrayRegion(env, bArray, 0, sizeof(valid),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                                           valid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            validBits = JNU_NewObjectByName(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                                            "java/math/BigInteger",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                                            "([B)V", bArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            if (validBits == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        hArray = (*env)->NewIntArray(env, paletteSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        if (hArray == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            (*env)->SetIntArrayRegion(env, hArray, 0, paletteSize, rgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        if (aData->awt_visInfo.depth == 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            awt_colormodel =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                JNU_NewObjectByName(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                                    "java/awt/image/IndexColorModel",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                                    "(II[IIILjava/math/BigInteger;)V",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                                    8, 256, hArray, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                                    java_awt_image_DataBuffer_TYPE_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                                    validBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            awt_colormodel =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                JNU_NewObjectByName(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                                    "java/awt/image/IndexColorModel",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                                    "(II[IIILjava/math/BigInteger;)V",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                                    12, 4096, hArray, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                                    java_awt_image_DataBuffer_TYPE_USHORT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                                    validBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        if (awt_colormodel == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        /* Set pData field of ColorModel to point to ColorData */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        JNU_SetLongFieldFromPtr(env, awt_colormodel, g_CMpDataID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                                aData->color_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    return (*env)->PopLocalFrame(env, awt_colormodel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
extern jfieldID colorValueID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
int awtJNI_GetColor(JNIEnv *env,jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
    /* REMIND: should not be defaultConfig. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    return awtJNI_GetColorForVis (env, this, getDefaultConfig(DefaultScreen(awt_display)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
int awtJNI_GetColorForVis (JNIEnv *env,jobject this, AwtGraphicsConfigDataPtr awt_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
    int col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    jclass SYSCLR_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    if (!JNU_IsNull(env,this))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        SYSCLR_class = (*env)->FindClass(env, "java/awt/SystemColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        if ((*env)->IsInstanceOf(env, this, SYSCLR_class)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                /* SECURITY: This is safe, because there is no way
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                 *           for client code to insert an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                 *           that is a subclass of SystemColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                col = (int) JNU_CallMethodByName(env
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                                          ,NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                                          ,this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                                          ,"getRGB"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                                          ,"()I").i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                col = (int)(*env)->GetIntField(env,this,colorValueID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        if (awt_data->awt_cmap == (Colormap) NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            awtJNI_CreateColorData (env, awt_data, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        col = awt_data->AwtColorMatch(red(col), green(col), blue(col),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                                      awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        return col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
awt_allocate_systemrgbcolors (jint *rgbColors, int num_colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                              AwtGraphicsConfigDataPtr awtData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    int i, pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    for (i = 0; i < num_colors; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        pixel = alloc_col (awt_display, awtData->awt_cmap, red (rgbColors [i]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                           green (rgbColors [i]), blue (rgbColors [i]), -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                           awtData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
awtCreateX11Colormap(AwtGraphicsConfigDataPtr adata) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
    int screen = adata->awt_visInfo.screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    Colormap cmap = (Colormap)NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    if (adata->awt_visInfo.visual == DefaultVisual(awt_display, screen)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        cmap = DefaultColormap(awt_display, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        Window root = RootWindow(awt_display, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        if (adata->awt_visInfo.visual->class % 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            Atom actual_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            int actual_format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            unsigned long nitems, bytes_after;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
            XStandardColormap *scm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            XGetWindowProperty (awt_display, root, XA_RGB_DEFAULT_MAP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                                0L, 1L, False, AnyPropertyType, &actual_type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                                &actual_format, &nitems, &bytes_after,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                                (unsigned char **) &scm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            XGetWindowProperty (awt_display, root, XA_RGB_DEFAULT_MAP, 0L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                                bytes_after/4 + 1, False, AnyPropertyType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                                &actual_type, &actual_format, &nitems,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                                &bytes_after, (unsigned char **) &scm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            nitems /= (sizeof (XStandardColormap)/4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            for (; nitems > 0; ++scm, --nitems)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                if (scm->visualid == adata->awt_visInfo.visualid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                    cmap = scm->colormap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        if (!cmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            cmap = XCreateColormap (awt_display, root,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                                    adata->awt_visInfo.visual,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                                    AllocNone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    adata->awt_cmap = cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    if (!awt_allocate_colors(adata)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        XFreeColormap(awt_display, adata->awt_cmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        adata->awt_cmap = (Colormap)NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
awtJNI_CreateColorData(JNIEnv *env, AwtGraphicsConfigDataPtr adata,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                       int lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    /* Create Colormap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    if (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        AWT_LOCK ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    awtCreateX11Colormap(adata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    /* If depth is 8, allocate system colors also...  Here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * we just get the array of System Colors and allocate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * it which may be a bit wasteful (if only some were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * changed). But we don't know which ones were changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     * and alloc-ing a pixel that is already allocated won't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     * hurt. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    if (adata->awt_depth == 8 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        (adata->awt_depth == 12 && adata->awt_visInfo.class == PseudoColor))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        jint colorVals [java_awt_SystemColor_NUM_COLORS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        jclass sysColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        jfieldID colorID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        jintArray colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        /* Unlock now to initialize the SystemColor class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        if (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            AWT_UNLOCK ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        sysColors = (*env)->FindClass (env, "java/awt/SystemColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        if (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            AWT_LOCK ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        colorID = (*env)->GetStaticFieldID (env, sysColors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                                                   "systemColors",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                                                   "[I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        colors = (jintArray) (*env)->GetStaticObjectField
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                                                (env, sysColors, colorID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        (*env)->GetIntArrayRegion (env, colors, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                                     java_awt_SystemColor_NUM_COLORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                                     (jint *) colorVals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        awt_allocate_systemrgbcolors (colorVals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                        (java_awt_SystemColor_NUM_COLORS - 1), adata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    if (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        AWT_UNLOCK ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
#endif /* !HEADLESS */