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