0N/A/*
2362N/A * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#ifdef HEADLESS
0N/A #error This file should not be included in headless library
0N/A#endif
0N/A
4632N/A#ifdef MACOSX
4632N/A#include <stdlib.h>
4632N/A#endif
4632N/A
0N/A#include "robot_common.h"
0N/A
0N/A/*
0N/A * QueryColorMap is taken from multiVis.c, part of the xwd distribution from
0N/A * X.org. It was moved here so it can be shared with awt_DataTransferer.c
0N/A */
0N/Aint32_t
0N/AQueryColorMap(Display *disp,
0N/A Colormap src_cmap,
0N/A Visual *src_vis,
0N/A XColor **src_colors,
0N/A int32_t *rShift, int32_t *gShift, int32_t *bShift)
0N/A
0N/A{
0N/A int32_t ncolors, i;
0N/A unsigned long redMask, greenMask, blueMask;
0N/A int32_t redShift, greenShift, blueShift;
0N/A XColor *colors ;
0N/A
0N/A ncolors = src_vis->map_entries ;
0N/A *src_colors = colors = (XColor *)calloc(ncolors,sizeof(XColor) ) ;
0N/A
0N/A if(src_vis->class != TrueColor && src_vis->class != DirectColor)
0N/A {
0N/A for(i=0 ; i < ncolors ; i++)
0N/A {
0N/A colors[i].pixel = i ;
0N/A colors[i].pad = 0;
0N/A colors[i].flags = DoRed|DoGreen|DoBlue;
0N/A }
0N/A }
0N/A else /** src is decomposed rgb ***/
0N/A {
0N/A /* Get the X colormap */
0N/A redMask = src_vis->red_mask;
0N/A greenMask = src_vis->green_mask;
0N/A blueMask = src_vis->blue_mask;
0N/A redShift = 0; while (!(redMask&0x1)) {
0N/A redShift++;
0N/A redMask = redMask>>1;
0N/A }
0N/A greenShift = 0; while (!(greenMask&0x1)) {
0N/A greenShift++;
0N/A greenMask = greenMask>>1;
0N/A }
0N/A blueShift = 0; while (!(blueMask&0x1)) {
0N/A blueShift++;
0N/A blueMask = blueMask>>1;
0N/A }
0N/A *rShift = redShift ;
0N/A *gShift = greenShift ;
0N/A *bShift = blueShift ;
0N/A for (i=0; i<ncolors; i++) {
0N/A if( (uint32_t)i <= redMask) colors[i].pixel = (i<<redShift) ;
0N/A if( (uint32_t)i <= greenMask) colors[i].pixel |= (i<<greenShift) ;
0N/A if( (uint32_t)i <= blueMask) colors[i].pixel |= (i<<blueShift) ;
0N/A /***** example :for gecko's 3-3-2 map, blue index should be <= 3
0N/A.
0N/A colors[i].pixel = (i<<redShift)|(i<<greenShift)|(i<<blueShift);
0N/A *****/
0N/A colors[i].pad = 0;
0N/A colors[i].flags = DoRed|DoGreen|DoBlue;
0N/A }
0N/A }
0N/A
0N/A XQueryColors(disp, src_cmap, colors, ncolors);
0N/A return ncolors ;
0N/A}