J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | #ifdef HEADLESS |
| 27 | #error This file should not be included in headless library |
| 28 | #endif |
| 29 | |
| 30 | #include "robot_common.h" |
| 31 | |
| 32 | /* |
| 33 | * QueryColorMap is taken from multiVis.c, part of the xwd distribution from |
| 34 | * X.org. It was moved here so it can be shared with awt_DataTransferer.c |
| 35 | */ |
| 36 | int32_t |
| 37 | QueryColorMap(Display *disp, |
| 38 | Colormap src_cmap, |
| 39 | Visual *src_vis, |
| 40 | XColor **src_colors, |
| 41 | int32_t *rShift, int32_t *gShift, int32_t *bShift) |
| 42 | |
| 43 | { |
| 44 | int32_t ncolors, i; |
| 45 | unsigned long redMask, greenMask, blueMask; |
| 46 | int32_t redShift, greenShift, blueShift; |
| 47 | XColor *colors ; |
| 48 | |
| 49 | ncolors = src_vis->map_entries ; |
| 50 | *src_colors = colors = (XColor *)calloc(ncolors,sizeof(XColor) ) ; |
| 51 | |
| 52 | if(src_vis->class != TrueColor && src_vis->class != DirectColor) |
| 53 | { |
| 54 | for(i=0 ; i < ncolors ; i++) |
| 55 | { |
| 56 | colors[i].pixel = i ; |
| 57 | colors[i].pad = 0; |
| 58 | colors[i].flags = DoRed|DoGreen|DoBlue; |
| 59 | } |
| 60 | } |
| 61 | else /** src is decomposed rgb ***/ |
| 62 | { |
| 63 | /* Get the X colormap */ |
| 64 | redMask = src_vis->red_mask; |
| 65 | greenMask = src_vis->green_mask; |
| 66 | blueMask = src_vis->blue_mask; |
| 67 | redShift = 0; while (!(redMask&0x1)) { |
| 68 | redShift++; |
| 69 | redMask = redMask>>1; |
| 70 | } |
| 71 | greenShift = 0; while (!(greenMask&0x1)) { |
| 72 | greenShift++; |
| 73 | greenMask = greenMask>>1; |
| 74 | } |
| 75 | blueShift = 0; while (!(blueMask&0x1)) { |
| 76 | blueShift++; |
| 77 | blueMask = blueMask>>1; |
| 78 | } |
| 79 | *rShift = redShift ; |
| 80 | *gShift = greenShift ; |
| 81 | *bShift = blueShift ; |
| 82 | for (i=0; i<ncolors; i++) { |
| 83 | if( (uint32_t)i <= redMask) colors[i].pixel = (i<<redShift) ; |
| 84 | if( (uint32_t)i <= greenMask) colors[i].pixel |= (i<<greenShift) ; |
| 85 | if( (uint32_t)i <= blueMask) colors[i].pixel |= (i<<blueShift) ; |
| 86 | /***** example :for gecko's 3-3-2 map, blue index should be <= 3 |
| 87 | . |
| 88 | colors[i].pixel = (i<<redShift)|(i<<greenShift)|(i<<blueShift); |
| 89 | *****/ |
| 90 | colors[i].pad = 0; |
| 91 | colors[i].flags = DoRed|DoGreen|DoBlue; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | XQueryColors(disp, src_cmap, colors, ncolors); |
| 96 | return ncolors ; |
| 97 | } |