src/java.desktop/unix/native/common/awt/X11Color.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47216 71c04702a3d5
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
     2
 * Copyright (c) 1995, 2014, 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
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   108
int getVirtCubeSize(void) {
2
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
awt_allocate_systemcolors(XColor *colorsPtr, int num_pixels, AwtGraphicsConfigDataPtr awtData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    int r, g, b, pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    for (i=0; i < num_pixels; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        r = colorsPtr[i].red   >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        g = colorsPtr[i].green >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        b = colorsPtr[i].blue  >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        pixel = alloc_col(awt_display, awtData->awt_cmap, r, g, b, -1, awtData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
awt_fill_imgcv(ImgConvertFcn **array, int mask, int value, ImgConvertFcn fcn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    for (i = 0; i < NUM_IMGCV; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        if ((i & mask) == value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            array[i] = fcn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
 * called from X11Server_create() in xlib.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
awt_allocate_colors(AwtGraphicsConfigDataPtr awt_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    Display *dpy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    unsigned long freecolors[MAX_PALETTE_SIZE], plane_masks[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    int paletteSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    XColor cols[MAX_PALETTE_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    unsigned char reds[256], greens[256], blues[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    int indices[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    Colormap cm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    int i, j, k, cmapsize, nfree, depth, bpp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    int allocatedColorsNum, unavailableColorsNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    XPixmapFormatValues *pPFV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    int numpfv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    XVisualInfo *pVI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    char *forcemono;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    char *forcegray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    make_uns_ordered_dither_array(img_oda_alpha, 256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    forcemono = getenv("FORCEMONO");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    forcegray = getenv("FORCEGRAY");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    if (forcemono && !forcegray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        forcegray = forcemono;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Get the colormap and make sure we have the right visual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    dpy = awt_display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    cm = awt_data->awt_cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    depth = awt_data->awt_depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    pVI = &awt_data->awt_visInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    awt_data->awt_num_colors = awt_data->awt_visInfo.colormap_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    awt_data->awtImage = (awtImageData *) calloc (1, sizeof (awtImageData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    pPFV = XListPixmapFormats(dpy, &numpfv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    if (pPFV) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        for (i = 0; i < numpfv; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if (pPFV[i].depth == depth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                awt_data->awtImage->wsImageFormat = pPFV[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        XFree(pPFV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    bpp = awt_data->awtImage->wsImageFormat.bits_per_pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    if (bpp == 24) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        bpp = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    awt_data->awtImage->clrdata.bitsperpixel = bpp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    awt_data->awtImage->Depth = depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    if ((bpp == 32 || bpp == 16) && pVI->class == TrueColor && depth >= 15) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        awt_data->AwtColorMatch = awt_color_matchTC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        awt_data->awtImage->clrdata.rOff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        for (i = pVI->red_mask; (i & 1) == 0; i >>= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            awt_data->awtImage->clrdata.rOff++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        awt_data->awtImage->clrdata.rScale = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        while (i < 0x80) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            awt_data->awtImage->clrdata.rScale++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            i <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        awt_data->awtImage->clrdata.gOff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        for (i = pVI->green_mask; (i & 1) == 0; i >>= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            awt_data->awtImage->clrdata.gOff++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        awt_data->awtImage->clrdata.gScale = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        while (i < 0x80) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            awt_data->awtImage->clrdata.gScale++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            i <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        awt_data->awtImage->clrdata.bOff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        for (i = pVI->blue_mask; (i & 1) == 0; i >>= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            awt_data->awtImage->clrdata.bOff++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        awt_data->awtImage->clrdata.bScale = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        while (i < 0x80) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            awt_data->awtImage->clrdata.bScale++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            i <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
#ifdef NEED_IMAGE_CONVERT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        awt_fill_imgcv(awt_data->awtImage->convert, 0, 0, DirectImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                        | IMGCV_ALPHABITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                       (IMGCV_UNSCALED | IMGCV_BYTEIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                        | IMGCV_OPAQUE | IMGCV_ICM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                       (bpp == 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                        ? Dir32IcmOpqUnsImageConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                        : Dir16IcmOpqUnsImageConvert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                        | IMGCV_ALPHABITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                       (IMGCV_UNSCALED | IMGCV_BYTEIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                        | IMGCV_ALPHA | IMGCV_ICM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                       (bpp == 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                        ? Dir32IcmTrnUnsImageConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                        : Dir16IcmTrnUnsImageConvert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                        | IMGCV_ALPHABITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                       (IMGCV_SCALED | IMGCV_BYTEIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                        | IMGCV_OPAQUE | IMGCV_ICM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                       (bpp == 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                        ? Dir32IcmOpqSclImageConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                        : Dir16IcmOpqSclImageConvert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                        | IMGCV_ALPHABITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                       (IMGCV_UNSCALED | IMGCV_INTIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                        | IMGCV_OPAQUE | IMGCV_DCM8),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                       (bpp == 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                        ? Dir32DcmOpqUnsImageConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                        : Dir16DcmOpqUnsImageConvert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                        | IMGCV_ALPHABITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                       (IMGCV_UNSCALED | IMGCV_INTIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                        | IMGCV_ALPHA | IMGCV_DCM8),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                       (bpp == 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                        ? Dir32DcmTrnUnsImageConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                        : Dir16DcmTrnUnsImageConvert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                        | IMGCV_ALPHABITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                       (IMGCV_SCALED | IMGCV_INTIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                        | IMGCV_OPAQUE | IMGCV_DCM8),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                       (bpp == 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                        ? Dir32DcmOpqSclImageConvert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                        : Dir16DcmOpqSclImageConvert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
#endif /* NEED_IMAGE_CONVERT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    } else if (bpp <= 16 && (pVI->class == StaticGray
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                            || pVI->class == GrayScale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                            || (pVI->class == PseudoColor && forcegray))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        awt_data->AwtColorMatch = awt_color_matchGS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        awt_data->awtImage->clrdata.grayscale = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        awt_data->awtImage->clrdata.bitsperpixel = MAX(bpp, 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
#ifdef NEED_IMAGE_CONVERT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        awt_fill_imgcv(awt_data->awtImage->convert, 0, 0, PseudoImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        if (getenv("NOFSDITHER") == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                           IMGCV_ORDERBITS, IMGCV_TDLRORDER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                           PseudoFSImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
#endif /* NEED_IMAGE_CONVERT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    } else if (depth <= 12 && (pVI->class == PseudoColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                             || pVI->class == TrueColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                             || pVI->class == StaticColor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if (pVI->class == TrueColor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
           awt_data->awt_num_colors = (1 << pVI->depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        awt_data->AwtColorMatch = awt_color_match;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        awt_data->awtImage->clrdata.bitsperpixel = MAX(bpp, 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
#ifdef NEED_IMAGE_CONVERT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        awt_fill_imgcv(awt_data->awtImage->convert, 0, 0, PseudoImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        if (getenv("NOFSDITHER") == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            awt_fill_imgcv(awt_data->awtImage->convert, IMGCV_ORDERBITS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                           IMGCV_TDLRORDER, PseudoFSImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                           (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                            | IMGCV_ALPHABITS | IMGCV_ORDERBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                            | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                           (IMGCV_UNSCALED | IMGCV_BYTEIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                            | IMGCV_OPAQUE | IMGCV_TDLRORDER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                            | IMGCV_ICM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                           FSColorIcmOpqUnsImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                           (IMGCV_SCALEBITS | IMGCV_INSIZEBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                            | IMGCV_ALPHABITS | IMGCV_ORDERBITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                            | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                           (IMGCV_UNSCALED | IMGCV_INTIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                            | IMGCV_OPAQUE | IMGCV_TDLRORDER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                            | IMGCV_DCM8),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                           FSColorDcmOpqUnsImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS | IMGCV_ALPHABITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        | IMGCV_ORDERBITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                       (IMGCV_UNSCALED | IMGCV_BYTEIN | IMGCV_OPAQUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                        | IMGCV_RANDORDER | IMGCV_ICM),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                       OrdColorIcmOpqUnsImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        awt_fill_imgcv(awt_data->awtImage->convert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                       (IMGCV_SCALEBITS | IMGCV_INSIZEBITS | IMGCV_ALPHABITS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                        | IMGCV_ORDERBITS | IMGCV_CMBITS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                       (IMGCV_UNSCALED | IMGCV_INTIN | IMGCV_OPAQUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                        | IMGCV_RANDORDER | IMGCV_DCM8),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                       OrdColorDcmOpqUnsImageConvert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
#endif /* NEED_IMAGE_CONVERT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        free (awt_data->awtImage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return 0;
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 (depth > 12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    if (depth == 12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        paletteSize = MAX_PALETTE12_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        paletteSize = MAX_PALETTE8_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    if (awt_data->awt_num_colors > paletteSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        free (awt_data->awtImage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    /* Allocate ColorData structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    awt_data->color_data = ZALLOC (_ColorData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    awt_data->color_data->screendata = 1; /* This ColorData struct corresponds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                             to some AWT screen/visual, so when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                             any IndexColorModel using this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                             struct is finalized, don't free
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                                             the struct in freeICMColorData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                                           */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * Initialize colors array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    for (i = 0; i < awt_data->awt_num_colors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        cols[i].pixel = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    awt_data->color_data->awt_Colors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        (ColorEntry *)calloc(paletteSize, sizeof (ColorEntry));
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));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        for (g = 0; g < 256; g++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            int mindist, besti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            int d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            p = awt_data->color_data->awt_Colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            mindist = 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            besti = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            for (i = 0 ; i < awt_data->awt_num_colors ; i++, p++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                if (forcegray && (p->r != p->g || p->g != p->b))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                if (forcemono && p->g != 0 && p->g != 255)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                if (p->flags == ALLOCATED_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                    d = p->g - g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    if (d < 0) d = -d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    if (d < mindist) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                        besti = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                        if (d == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                        mindist = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            awt_data->color_data->img_grays[g] = besti;
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
        if (forcemono || (depth == 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            char *gammastr = getenv("HJGAMMA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            double gamma = atof(gammastr ? gammastr : "1.6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            if (gamma < 0.01) gamma = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            if (debug_colormap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                jio_fprintf(stderr, "gamma = %f\n", gamma);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            for (i = 0; i < 256; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                img_bwgamma[i] = (int) (pow(i/255.0, gamma) * 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                if (debug_colormap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                    jio_fprintf(stderr, "%3d ", img_bwgamma[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    if ((i & 7) == 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                        jio_fprintf(stderr, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            for (i = 0; i < 256; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                img_bwgamma[i] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        if (debug_colormap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            jio_fprintf(stderr, "GrayScale initialized\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            jio_fprintf(stderr, "color table:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            for (i = 0; i < awt_data->awt_num_colors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                jio_fprintf(stderr, "%3d: %3d %3d %3d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                        i, awt_data->color_data->awt_Colors[i].r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                        awt_data->color_data->awt_Colors[i].g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                        awt_data->color_data->awt_Colors[i].b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            jio_fprintf(stderr, "gray table:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            for (i = 0; i < 256; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                jio_fprintf(stderr, "%3d ", awt_data->color_data->img_grays[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                if ((i & 7) == 7)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                    jio_fprintf(stderr, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        alloc_col(dpy, cm, 255, 0, 0, -1, awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        alloc_col(dpy, cm, 0, 255, 0, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        alloc_col(dpy, cm, 0, 0, 255, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        alloc_col(dpy, cm, 255, 255, 0, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        alloc_col(dpy, cm, 255, 0, 255, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        alloc_col(dpy, cm, 0, 255, 255, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        alloc_col(dpy, cm, 192, 192, 192, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        alloc_col(dpy, cm, 255, 128, 128, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        alloc_col(dpy, cm, 128, 255, 128, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        alloc_col(dpy, cm, 128, 128, 255, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        alloc_col(dpy, cm, 255, 255, 128, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        alloc_col(dpy, cm, 255, 128, 255, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        alloc_col(dpy, cm, 128, 255, 255, -1,awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    allocatedColorsNum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    unavailableColorsNum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    /* we do not support more than 256 entries in the colormap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
       even for 12-bit PseudoColor visuals */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    for (i = 0; i < MAX_PALETTE8_SIZE; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        if (awt_data->color_data->awt_Colors[i].flags == ALLOCATED_COLOR)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            reds[allocatedColorsNum] = awt_data->color_data->awt_Colors[i].r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            greens[allocatedColorsNum] = awt_data->color_data->awt_Colors[i].g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            blues[allocatedColorsNum] = awt_data->color_data->awt_Colors[i].b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            allocatedColorsNum++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        } else if (awt_data->color_data->awt_Colors[i].flags ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                                                        UNAVAILABLE_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            unavailableColorsNum++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    if (depth > 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        cmapsize = MAX_PALETTE8_SIZE - unavailableColorsNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        cmapsize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        if (getenv("CMAPSIZE") != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            cmapsize = atoi(getenv("CMAPSIZE"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        if (cmapsize <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            cmapsize = CMAP_ALLOC_DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        if (cmapsize < allocatedColorsNum + unavailableColorsNum + CMAP_ALLOC_MIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            cmapsize = allocatedColorsNum + unavailableColorsNum + CMAP_ALLOC_MIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        if (cmapsize > CMAP_ALLOC_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            cmapsize = CMAP_ALLOC_MAX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        if (cmapsize < allocatedColorsNum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            cmapsize = allocatedColorsNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        cmapsize -= unavailableColorsNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    k = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    if (getenv("VIRTCUBESIZE") != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        k = atoi(getenv("VIRTCUBESIZE"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    if (k == 0 || (k & (k - 1)) != 0 || k > 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        k = getVirtCubeSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    awt_data->color_data->img_clr_tbl =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        (unsigned char *)calloc(LOOKUPSIZE * LOOKUPSIZE * LOOKUPSIZE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                                sizeof(unsigned char));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    img_makePalette(cmapsize, k, LOOKUPSIZE, 50, 250,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                    allocatedColorsNum, TRUE, reds, greens, blues,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                    awt_data->color_data->img_clr_tbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                    /*img_clr_tbl);*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    for (i = 0; i < cmapsize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        indices[i] = alloc_col(dpy, cm, reds[i], greens[i], blues[i], -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                               awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    for (i = 0; i < LOOKUPSIZE * LOOKUPSIZE * LOOKUPSIZE  ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        awt_data->color_data->img_clr_tbl[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            indices[awt_data->color_data->img_clr_tbl[i]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    awt_data->color_data->img_oda_red   = &(std_img_oda_red[0][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    awt_data->color_data->img_oda_green = &(std_img_oda_green[0][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    awt_data->color_data->img_oda_blue  = &(std_img_oda_blue[0][0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    make_dither_arrays(cmapsize, awt_data->color_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    std_odas_computed = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    if (debug_colormap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        int alloc_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        int reuse_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        int free_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        for (i = 0; i < awt_data->awt_num_colors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            switch (awt_data->color_data->awt_Colors[i].flags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
              case ALLOCATED_COLOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                alloc_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
              case LIKELY_COLOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                reuse_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
              case FREE_COLOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                free_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        jio_fprintf(stdout, "%d total, %d allocated, %d reused, %d still free.\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                    awt_data->awt_num_colors, alloc_count, reuse_count, free_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    /* Fill in the ICM lut and lut2cmap mapping */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    awt_data->color_data->awt_numICMcolors = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    awt_data->color_data->awt_icmLUT2Colors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        (unsigned char *)calloc(paletteSize, sizeof (unsigned char));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    awt_data->color_data->awt_icmLUT = (int *)calloc(paletteSize, sizeof(int));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    for (i=0; i < paletteSize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        /* Keep the mapping between this lut and the actual cmap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        awt_data->color_data->awt_icmLUT2Colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            [awt_data->color_data->awt_numICMcolors] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        if (awt_data->color_data->awt_Colors[i].flags == ALLOCATED_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            /* Screen IndexColorModel LUTS are always xRGB */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            awt_data->color_data->awt_icmLUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                    [awt_data->color_data->awt_numICMcolors++] = 0xff000000 |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                (awt_data->color_data->awt_Colors[i].r<<16) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                (awt_data->color_data->awt_Colors[i].g<<8) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                (awt_data->color_data->awt_Colors[i].b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            /* Screen IndexColorModel LUTS are always xRGB */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            awt_data->color_data->awt_icmLUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                        [awt_data->color_data->awt_numICMcolors++] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
#define red(v)          (((v) >> 16) & 0xFF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
#define green(v)        (((v) >>  8) & 0xFF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
#define blue(v)         (((v) >>  0) & 0xFF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
#ifndef HEADLESS
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   888
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   889
jobject getColorSpace(JNIEnv* env, jint csID) {
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   890
    jclass clazz;
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   891
    jobject cspaceL;
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   892
    jmethodID mid;
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   893
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   894
    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
   895
    CHECK_NULL_RETURN(clazz, NULL);
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   896
    mid = (*env)->GetStaticMethodID(env, clazz, "getInstance",
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   897
                                    "(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
   898
    CHECK_NULL_RETURN(mid, NULL);
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   899
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   900
    /* SECURITY: This is safe, because static methods cannot
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   901
     *           be overridden, and this method does not invoke
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   902
     *           client code
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   903
     */
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
    return (*env)->CallStaticObjectMethod(env, clazz, mid, csID);
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   906
}
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   907
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
jobject awtJNI_GetColorModel(JNIEnv *env, AwtGraphicsConfigDataPtr aData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    jobject awt_colormodel = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    jclass clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    jmethodID mid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    if ((*env)->PushLocalFrame(env, 16) < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    if ((aData->awt_visInfo.class == TrueColor) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        (aData->awt_depth >= 15))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        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
   921
        if (clazz == NULL) {
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
   922
            (*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
   923
            return NULL;
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
   924
        }
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
   925
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   926
        if (!aData->isTranslucencySupported) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   928
            mid = (*env)->GetMethodID(env,clazz,"<init>","(IIIII)V");
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   929
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   930
            if (mid == NULL) {
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   931
                (*env)->PopLocalFrame(env, 0);
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   932
                return NULL;
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   933
            }
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   934
            awt_colormodel = (*env)->NewObject(env,clazz, mid,
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   935
                    aData->awt_visInfo.depth,
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   936
                    aData->awt_visInfo.red_mask,
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   937
                    aData->awt_visInfo.green_mask,
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   938
                    aData->awt_visInfo.blue_mask,
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   939
                    0);
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   940
        } else {
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   941
            clazz = (*env)->FindClass(env,"sun/awt/X11GraphicsConfig");
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   942
            if (clazz == NULL) {
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   943
                (*env)->PopLocalFrame(env, 0);
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   944
                return NULL;
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
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   947
            if (aData->renderPictFormat.direct.red == 16) {
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   948
                mid = (*env)->GetStaticMethodID( env,clazz,"createDCM32",
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   949
                        "(IIIIZ)Ljava/awt/image/DirectColorModel;");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   951
                if (mid == NULL) {
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   952
                    (*env)->PopLocalFrame(env, 0);
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   953
                    return NULL;
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   954
                }
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   955
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   956
                awt_colormodel = (*env)->CallStaticObjectMethod(
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   957
                        env,clazz, mid,
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   958
                        aData->renderPictFormat.direct.redMask
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   959
                            << aData->renderPictFormat.direct.red,
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   960
                        aData->renderPictFormat.direct.greenMask
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   961
                            << aData->renderPictFormat.direct.green,
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   962
                        aData->renderPictFormat.direct.blueMask
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   963
                            << aData->renderPictFormat.direct.blue,
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   964
                        aData->renderPictFormat.direct.alphaMask
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   965
                            << aData->renderPictFormat.direct.alpha,
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   966
                        JNI_TRUE);
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   967
            } else {
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   968
                mid = (*env)->GetStaticMethodID( env,clazz,"createABGRCCM",
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   969
                        "()Ljava/awt/image/ComponentColorModel;");
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
                if (mid == NULL) {
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   972
                    (*env)->PopLocalFrame(env, 0);
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   973
                    return NULL;
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   974
                }
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   975
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   976
                awt_colormodel = (*env)->CallStaticObjectMethod(
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   977
                        env,clazz, mid);
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   978
            }
2760
f038acdbdf9c 6838046: Rollback 6762511 due to build failure (6838003)
anthony
parents: 2758
diff changeset
   979
        }
2758
d2fbe9b5857a 6762511: Translucency is not working on Linux using Metacity
anthony
parents: 2
diff changeset
   980
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        if(awt_colormodel == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    else if (aData->awt_visInfo.class == StaticGray &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
             aData->awt_num_colors == 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        jobject cspace = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        jint bits[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        jintArray bitsArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        jboolean falseboolean = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   995
        cspace = getColorSpace(env, java_awt_color_ColorSpace_CS_GRAY);
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   996
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        if (cspace == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        bits[0] = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        bitsArray = (*env)->NewIntArray(env, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        if (bitsArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            (*env)->SetIntArrayRegion(env, bitsArray, 0, 1, bits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        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
  1012
        if (clazz == NULL) {
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
  1013
            (*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
  1014
            return NULL;
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
  1015
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        mid = (*env)->GetMethodID(env,clazz,"<init>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            "(Ljava/awt/color/ColorSpace;[IZZII)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        if (mid == 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
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        awt_colormodel = (*env)->NewObject(env,clazz, mid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                                           cspace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                                           bitsArray,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                                           falseboolean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                                           falseboolean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                                           java_awt_Transparency_OPAQUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                                           java_awt_image_DataBuffer_TYPE_BYTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        if(awt_colormodel == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        jint rgb[MAX_PALETTE_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        jbyte valid[MAX_PALETTE_SIZE / 8], *pValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        jintArray hArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        jobject validBits = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        ColorEntry *c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        int i, allocAllGray, b, allvalid, paletteSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        jlong pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        if (aData->awt_visInfo.depth == 12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            paletteSize = MAX_PALETTE12_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            paletteSize = MAX_PALETTE8_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        c = aData->color_data->awt_Colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        pValid = &valid[sizeof(valid)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        allocAllGray = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        b = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        allvalid = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        for (i = 0; i < paletteSize; i++, c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            if (c->flags == ALLOCATED_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                rgb[i] = (0xff000000 |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                          (c->r << 16) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                          (c->g <<  8) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                          (c->b <<  0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                if (c->r != c->g || c->g != c->b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                    allocAllGray = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                b |= (1 << (i % 8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                rgb[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                b &= ~(1 << (i % 8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                allvalid = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            if ((i % 8) == 7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                *--pValid = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                /* b = 0; not needed as each bit is explicitly set */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        if (allocAllGray && (aData->awtImage->clrdata.grayscale == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
              Fix for 4351638 - Gray scale HW mode on Dome frame buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                                crashes VM on Solaris.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
              It is possible for an X11 frame buffer to advertise a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
              PseudoColor visual, but to force all allocated colormap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
              entries to be gray colors.  The Dome card does this when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
              HW is jumpered for a grayscale monitor, but the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
              visual is set to PseudoColor.  In that case awtJNI_GetColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
              will be called with aData->awtImage->clrdata.grayscale == 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
              but the IndexColorModel created below will detect that only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
              gray colors exist and expect the inverse gray LUT to exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
              So above when filling the hR, hG, and hB arrays we detect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
              whether all allocated colors are gray.  If so, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
              aData->awtImage->clrdata.grayscale == 0, we fall into this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
              code to set aData->awtImage->clrdata.grayscale = 1 and do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
              other things needed for the grayscale case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            int g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            ColorEntry *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            aData->awtImage->clrdata.grayscale = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            aData->color_data->img_grays =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                (unsigned char *)calloc(256, sizeof(unsigned char));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            if (aData->color_data->img_grays == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            for (g = 0; g < 256; g++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                int mindist, besti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                int d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                p = aData->color_data->awt_Colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                mindist = 256;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                besti = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                for (i = 0 ; i < paletteSize; i++, p++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                    if (p->flags == ALLOCATED_COLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                        d = p->g - g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                        if (d < 0) d = -d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                        if (d < mindist) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                            besti = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                            if (d == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                            mindist = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                aData->color_data->img_grays[g] = besti;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            for (i = 0; i < 256; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                img_bwgamma[i] = i;    /* REMIND: what is img_bwgamma?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                                        *         is it still used anywhere?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                                        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        if (aData->awtImage->clrdata.grayscale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            ColorEntry *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            /* For purposes of creating an IndexColorModel, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
               transparent black for non-allocated or non-gray colors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            p = aData->color_data->awt_Colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            b = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            pValid = &valid[sizeof(valid)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            for (i = 0; i < paletteSize; i++, p++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                if ((p->flags != ALLOCATED_COLOR) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                    (p->r != p->g || p->g != p->b))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                    rgb[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                    b &= ~(1 << (i % 8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                    allvalid = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                    b |= (1 << (i % 8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                if ((i % 8) == 7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                    *--pValid = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                    /* b = 0; not needed as each bit is explicitly set */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            if (aData->color_data->pGrayInverseLutData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                /* Compute the inverse gray LUT for this aData->color_data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                   struct, if not already computed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                initInverseGrayLut(rgb, aData->awt_num_colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                                   aData->color_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        if (!allvalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            jobject bArray = (*env)->NewByteArray(env, sizeof(valid));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            if (bArray == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                (*env)->SetByteArrayRegion(env, bArray, 0, sizeof(valid),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                                           valid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            validBits = JNU_NewObjectByName(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                                            "java/math/BigInteger",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                                            "([B)V", bArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            if (validBits == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        hArray = (*env)->NewIntArray(env, paletteSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        if (hArray == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            (*env)->SetIntArrayRegion(env, hArray, 0, paletteSize, rgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        if (aData->awt_visInfo.depth == 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            awt_colormodel =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                JNU_NewObjectByName(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                                    "java/awt/image/IndexColorModel",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                                    "(II[IIILjava/math/BigInteger;)V",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                                    8, 256, hArray, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                                    java_awt_image_DataBuffer_TYPE_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                                    validBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            awt_colormodel =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                JNU_NewObjectByName(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                                    "java/awt/image/IndexColorModel",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                                    "(II[IIILjava/math/BigInteger;)V",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                                    12, 4096, hArray, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                                    java_awt_image_DataBuffer_TYPE_USHORT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                                    validBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        if (awt_colormodel == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            (*env)->PopLocalFrame(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        /* Set pData field of ColorModel to point to ColorData */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        JNU_SetLongFieldFromPtr(env, awt_colormodel, g_CMpDataID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                                aData->color_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    return (*env)->PopLocalFrame(env, awt_colormodel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
extern jfieldID colorValueID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
int awtJNI_GetColor(JNIEnv *env,jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    /* REMIND: should not be defaultConfig. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    return awtJNI_GetColorForVis (env, this, getDefaultConfig(DefaultScreen(awt_display)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
int awtJNI_GetColorForVis (JNIEnv *env,jobject this, AwtGraphicsConfigDataPtr awt_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
    int col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    jclass SYSCLR_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    if (!JNU_IsNull(env,this))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        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
  1264
        CHECK_NULL_RETURN(SYSCLR_class, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        if ((*env)->IsInstanceOf(env, this, SYSCLR_class)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                /* SECURITY: This is safe, because there is no way
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                 *           for client code to insert an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                 *           that is a subclass of SystemColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                col = (int) JNU_CallMethodByName(env
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                                          ,NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                                          ,this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                                          ,"getRGB"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                                          ,"()I").i;
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
  1276
                JNU_CHECK_EXCEPTION_RETURN(env, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                col = (int)(*env)->GetIntField(env,this,colorValueID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        if (awt_data->awt_cmap == (Colormap) NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            awtJNI_CreateColorData (env, awt_data, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        col = awt_data->AwtColorMatch(red(col), green(col), blue(col),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                                      awt_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        return col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
awt_allocate_systemrgbcolors (jint *rgbColors, int num_colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                              AwtGraphicsConfigDataPtr awtData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    int i, pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    for (i = 0; i < num_colors; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        pixel = alloc_col (awt_display, awtData->awt_cmap, red (rgbColors [i]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                           green (rgbColors [i]), blue (rgbColors [i]), -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                           awtData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
awtCreateX11Colormap(AwtGraphicsConfigDataPtr adata) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    int screen = adata->awt_visInfo.screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    Colormap cmap = (Colormap)NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    if (adata->awt_visInfo.visual == DefaultVisual(awt_display, screen)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        cmap = DefaultColormap(awt_display, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        Window root = RootWindow(awt_display, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        if (adata->awt_visInfo.visual->class % 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            Atom actual_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            int actual_format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            unsigned long nitems, bytes_after;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            XStandardColormap *scm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
            XGetWindowProperty (awt_display, root, XA_RGB_DEFAULT_MAP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                                0L, 1L, False, AnyPropertyType, &actual_type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                                &actual_format, &nitems, &bytes_after,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                                (unsigned char **) &scm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            XGetWindowProperty (awt_display, root, XA_RGB_DEFAULT_MAP, 0L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                                bytes_after/4 + 1, False, AnyPropertyType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                                &actual_type, &actual_format, &nitems,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                                &bytes_after, (unsigned char **) &scm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            nitems /= (sizeof (XStandardColormap)/4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            for (; nitems > 0; ++scm, --nitems)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                if (scm->visualid == adata->awt_visInfo.visualid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                    cmap = scm->colormap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        if (!cmap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            cmap = XCreateColormap (awt_display, root,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                                    adata->awt_visInfo.visual,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                                    AllocNone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
    adata->awt_cmap = cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    if (!awt_allocate_colors(adata)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        XFreeColormap(awt_display, adata->awt_cmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        adata->awt_cmap = (Colormap)NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
awtJNI_CreateColorData(JNIEnv *env, AwtGraphicsConfigDataPtr adata,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                       int lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    /* Create Colormap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    if (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        AWT_LOCK ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
    awtCreateX11Colormap(adata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
    /* If depth is 8, allocate system colors also...  Here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * we just get the array of System Colors and allocate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     * it which may be a bit wasteful (if only some were
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
     * changed). But we don't know which ones were changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
     * and alloc-ing a pixel that is already allocated won't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     * hurt. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
    if (adata->awt_depth == 8 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        (adata->awt_depth == 12 && adata->awt_visInfo.class == PseudoColor))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        jint colorVals [java_awt_SystemColor_NUM_COLORS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        jclass sysColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        jfieldID colorID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        jintArray colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        /* Unlock now to initialize the SystemColor class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        if (lock) {
26343
cf09debe8a4b 8046894: JNI exception pending in jdk/src/solaris/native/sun/awt/X11Color.c
serb
parents: 24130
diff changeset
  1380
            AWT_UNLOCK_CHECK_EXCEPTION(env);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        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
  1383
        CHECK_NULL(sysColors);
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
  1384
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        if (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
            AWT_LOCK ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        colorID = (*env)->GetStaticFieldID (env, sysColors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                                                   "systemColors",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                                                   "[I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
  1392
        if (colorID == NULL) {
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
  1393
            if (lock) {
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
  1394
                AWT_UNLOCK();
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
  1395
            }
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
  1396
            return;
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
  1397
        }
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 23010
diff changeset
  1398
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        colors = (jintArray) (*env)->GetStaticObjectField
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                                                (env, sysColors, colorID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        (*env)->GetIntArrayRegion (env, colors, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                                     java_awt_SystemColor_NUM_COLORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                                     (jint *) colorVals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        awt_allocate_systemrgbcolors (colorVals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                        (java_awt_SystemColor_NUM_COLORS - 1), adata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
    if (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
        AWT_UNLOCK ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
#endif /* !HEADLESS */