62 #include "pixmap_helper.h" 65 #if !defined(WIN32) && defined(X11WORKBENCH_TOOLKIT_HAVE_XSHM_EXTENSION) 68 #include <X11/extensions/XShm.h> 69 #endif // !defined(WIN32) && defined(X11WORKBENCH_TOOLKIT_HAVE_XSHM_EXTENSION) 71 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 72 #include <X11/Xft/Xft.h> 73 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 78 #include "icon_ok.xpm" 79 #include "icon_stop.xpm" 80 #include "icon_warn.xpm" 81 #include "icon_what.xpm" 82 #include "icon_splat.xpm" 85 #include "icon_bang.xpm" 86 #include "icon_barney.xpm" 87 #include "icon_bear.xpm" 88 #include "icon_death.xpm" 89 #include "icon_finger.xpm" 90 #include "icon_skull.xpm" 91 #include "icon_triangle.xpm" 92 #include "icon_what_bold.xpm" 93 #include "icon_wtf.xpm" 94 #include "icon_thumbup.xpm" 95 #include "icon_thumbdown.xpm" 100 #define DEBUG_DUMP_XPM_ATTRIBUTES(X) 101 #define DEBUG_DUMP_COLORMAP(X) 103 static void DebugDumpXpmAttributes(
const char *szFunction,
int nLine,
XPM_ATTRIBUTES *pAttr);
104 #define DEBUG_DUMP_XPM_ATTRIBUTES(X) DebugDumpXpmAttributes(__FUNCTION__, __LINE__, X) 105 #define DEBUG_DUMP_COLORMAP(X) WBDebugDumpColormap("Called from " __FUNCTION__, X) 109 #define _PI_ 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 112 #define MINIMUM_ATOM_RESOURCE_LIST_SIZE 256 114 typedef struct __INTERNAL_ATOM_RESOURCE_LIST__
118 } INTERNAL_ATOM_RESOURCE_LIST;
120 static INTERNAL_ATOM_RESOURCE_LIST *pAtomResourceList = NULL;
121 static int nAtomResourceList = 0, nAtomResourceListMax = 0;
123 static char **ppRegAppLarge_Internal = NULL;
124 static char **ppRegAppSmall_Internal = NULL;
126 XStandardColormap PXM_StandardColormapFromColormap_rval;
135 if(pAtomResourceList)
137 WBFree(pAtomResourceList);
138 pAtomResourceList = NULL;
141 nAtomResourceList = 0;
142 nAtomResourceListMax = 0;
144 ppRegAppLarge_Internal = NULL;
145 ppRegAppSmall_Internal = NULL;
155 static const unsigned char aAnswers[256] =
157 0,1,1,2,2,2,2,3,3,3,3,3,3,4,4,4,
158 4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,6,
159 6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,
160 7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,
161 8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,
162 9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,
163 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,
164 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
165 11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,
166 12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,
167 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
168 13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,
169 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
170 14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,
171 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
172 15,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16
176 return aAnswers[iVal & 0xff];
181 static const unsigned char aAnswers[256] =
183 255,255,255,255,255,255,255,255,255,255,255,254,254,254,254,254,
184 254,254,253,253,253,253,253,252,252,252,252,252,251,251,251,250,
185 250,250,249,249,249,248,248,248,247,247,247,246,246,245,245,244,
186 244,244,243,243,242,242,241,241,240,240,239,238,238,237,237,236,
187 236,235,234,234,233,232,232,231,231,230,229,228,228,227,226,226,
188 225,224,223,223,222,221,220,220,219,218,217,216,215,215,214,213,
189 212,211,210,209,208,208,207,206,205,204,203,202,201,200,199,198,
190 197,196,195,194,193,192,191,190,189,188,187,186,185,184,183,181,
191 180,179,178,177,176,175,174,172,171,170,169,168,167,165,164,163,
192 162,161,159,158,157,156,154,153,152,151,149,148,147,146,144,143,
193 142,140,139,138,136,135,134,132,131,130,128,127,126,124,123,122,
194 120,119,117,116,115,113,112,110,109,108,106,105,103,102,100,99,
195 98,96,95,93,92,90,89,87,86,84,83,81,80,79,77,76,
196 74,73,71,70,68,67,65,63,62,60,59,57,56,54,53,51,
197 50,48,47,45,44,42,41,39,37,36,34,33,31,30,28,27,
198 25,23,22,20,19,17,16,14,13,11,9,8,6,5,3,2
202 return aAnswers[iVal & 0xff];
205 static const char aCosAnswers[0x400] =
207 127, 127, 127, 127, 127, 127, 127, 127,
208 127, 127, 127, 127, 127, 127, 127, 126,
209 126, 126, 126, 126, 126, 126, 126, 126,
210 126, 126, 125, 125, 125, 125, 125, 125,
211 125, 124, 124, 124, 124, 124, 124, 123,
212 123, 123, 123, 123, 122, 122, 122, 122,
213 122, 121, 121, 121, 121, 120, 120, 120,
214 120, 119, 119, 119, 118, 118, 118, 118,
215 117, 117, 117, 116, 116, 116, 115, 115,
216 115, 114, 114, 114, 113, 113, 113, 112,
217 112, 112, 111, 111, 111, 110, 110, 109,
218 109, 109, 108, 108, 107, 107, 106, 106,
219 106, 105, 105, 104, 104, 103, 103, 102,
220 102, 102, 101, 101, 100, 100, 99, 99,
221 98, 98, 97, 97, 96, 96, 95, 95,
222 94, 94, 93, 93, 92, 91, 91, 90,
223 90, 89, 89, 88, 88, 87, 86, 86,
224 85, 85, 84, 84, 83, 82, 82, 81,
225 81, 80, 79, 79, 78, 78, 77, 76,
226 76, 75, 74, 74, 73, 72, 72, 71,
227 71, 70, 69, 69, 68, 67, 67, 66,
228 65, 65, 64, 63, 63, 62, 61, 61,
229 60, 59, 58, 58, 57, 56, 56, 55,
230 54, 54, 53, 52, 51, 51, 50, 49,
231 49, 48, 47, 46, 46, 45, 44, 44,
232 43, 42, 41, 41, 40, 39, 38, 38,
233 37, 36, 35, 35, 34, 33, 32, 32,
234 31, 30, 29, 29, 28, 27, 26, 26,
235 25, 24, 23, 22, 22, 21, 20, 19,
236 19, 18, 17, 16, 16, 15, 14, 13,
237 12, 12, 11, 10, 9, 9, 8, 7,
238 6, 5, 5, 4, 3, 2, 2, 1,
239 0, -1, -2, -2, -3, -4, -5, -5,
240 -6, -7, -8, -9, -9, -10, -11, -12,
241 -12, -13, -14, -15, -16, -16, -17, -18,
242 -19, -19, -20, -21, -22, -22, -23, -24,
243 -25, -26, -26, -27, -28, -29, -29, -30,
244 -31, -32, -32, -33, -34, -35, -35, -36,
245 -37, -38, -38, -39, -40, -41, -41, -42,
246 -43, -44, -44, -45, -46, -46, -47, -48,
247 -49, -49, -50, -51, -51, -52, -53, -54,
248 -54, -55, -56, -56, -57, -58, -58, -59,
249 -60, -61, -61, -62, -63, -63, -64, -65,
250 -65, -66, -67, -67, -68, -69, -69, -70,
251 -71, -71, -72, -72, -73, -74, -74, -75,
252 -76, -76, -77, -78, -78, -79, -79, -80,
253 -81, -81, -82, -82, -83, -84, -84, -85,
254 -85, -86, -86, -87, -88, -88, -89, -89,
255 -90, -90, -91, -91, -92, -93, -93, -94,
256 -94, -95, -95, -96, -96, -97, -97, -98,
257 -98, -99, -99, -100, -100, -101, -101, -102,
258 -102, -102, -103, -103, -104, -104, -105, -105,
259 -106, -106, -106, -107, -107, -108, -108, -109,
260 -109, -109, -110, -110, -111, -111, -111, -112,
261 -112, -112, -113, -113, -113, -114, -114, -114,
262 -115, -115, -115, -116, -116, -116, -117, -117,
263 -117, -118, -118, -118, -118, -119, -119, -119,
264 -120, -120, -120, -120, -121, -121, -121, -121,
265 -122, -122, -122, -122, -122, -123, -123, -123,
266 -123, -123, -124, -124, -124, -124, -124, -124,
267 -125, -125, -125, -125, -125, -125, -125, -126,
268 -126, -126, -126, -126, -126, -126, -126, -126,
269 -126, -126, -127, -127, -127, -127, -127, -127,
270 -127, -127, -127, -127, -127, -127, -127, -127,
271 -127, -127, -127, -127, -127, -127, -127, -127,
272 -127, -127, -127, -127, -127, -127, -127, -126,
273 -126, -126, -126, -126, -126, -126, -126, -126,
274 -126, -126, -125, -125, -125, -125, -125, -125,
275 -125, -124, -124, -124, -124, -124, -124, -123,
276 -123, -123, -123, -123, -122, -122, -122, -122,
277 -122, -121, -121, -121, -121, -120, -120, -120,
278 -120, -119, -119, -119, -118, -118, -118, -118,
279 -117, -117, -117, -116, -116, -116, -115, -115,
280 -115, -114, -114, -114, -113, -113, -113, -112,
281 -112, -112, -111, -111, -111, -110, -110, -109,
282 -109, -109, -108, -108, -107, -107, -106, -106,
283 -106, -105, -105, -104, -104, -103, -103, -102,
284 -102, -102, -101, -101, -100, -100, -99, -99,
285 -98, -98, -97, -97, -96, -96, -95, -95,
286 -94, -94, -93, -93, -92, -91, -91, -90,
287 -90, -89, -89, -88, -88, -87, -86, -86,
288 -85, -85, -84, -84, -83, -82, -82, -81,
289 -81, -80, -79, -79, -78, -78, -77, -76,
290 -76, -75, -74, -74, -73, -72, -72, -71,
291 -71, -70, -69, -69, -68, -67, -67, -66,
292 -65, -65, -64, -63, -63, -62, -61, -61,
293 -60, -59, -58, -58, -57, -56, -56, -55,
294 -54, -54, -53, -52, -51, -51, -50, -49,
295 -49, -48, -47, -46, -46, -45, -44, -44,
296 -43, -42, -41, -41, -40, -39, -38, -38,
297 -37, -36, -35, -35, -34, -33, -32, -32,
298 -31, -30, -29, -29, -28, -27, -26, -26,
299 -25, -24, -23, -22, -22, -21, -20, -19,
300 -19, -18, -17, -16, -16, -15, -14, -13,
301 -12, -12, -11, -10, -9, -9, -8, -7,
302 -6, -5, -5, -4, -3, -2, -2, -1,
303 0, 1, 2, 2, 3, 4, 5, 5,
304 6, 7, 8, 9, 9, 10, 11, 12,
305 12, 13, 14, 15, 16, 16, 17, 18,
306 19, 19, 20, 21, 22, 22, 23, 24,
307 25, 26, 26, 27, 28, 29, 29, 30,
308 31, 32, 32, 33, 34, 35, 35, 36,
309 37, 38, 38, 39, 40, 41, 41, 42,
310 43, 44, 44, 45, 46, 46, 47, 48,
311 49, 49, 50, 51, 51, 52, 53, 54,
312 54, 55, 56, 56, 57, 58, 58, 59,
313 60, 61, 61, 62, 63, 63, 64, 65,
314 65, 66, 67, 67, 68, 69, 69, 70,
315 71, 71, 72, 72, 73, 74, 74, 75,
316 76, 76, 77, 78, 78, 79, 79, 80,
317 81, 81, 82, 82, 83, 84, 84, 85,
318 85, 86, 86, 87, 88, 88, 89, 89,
319 90, 90, 91, 91, 92, 93, 93, 94,
320 94, 95, 95, 96, 96, 97, 97, 98,
321 98, 99, 99, 100, 100, 101, 101, 102,
322 102, 102, 103, 103, 104, 104, 105, 105,
323 106, 106, 106, 107, 107, 108, 108, 109,
324 109, 109, 110, 110, 111, 111, 111, 112,
325 112, 112, 113, 113, 113, 114, 114, 114,
326 115, 115, 115, 116, 116, 116, 117, 117,
327 117, 118, 118, 118, 118, 119, 119, 119,
328 120, 120, 120, 120, 121, 121, 121, 121,
329 122, 122, 122, 122, 122, 123, 123, 123,
330 123, 123, 124, 124, 124, 124, 124, 124,
331 125, 125, 125, 125, 125, 125, 125, 126,
332 126, 126, 126, 126, 126, 126, 126, 126,
333 126, 126, 127, 127, 127, 127, 127, 127,
334 127, 127, 127, 127, 127, 127, 127, 127
340 return aCosAnswers[iVal & 0x3ff];
343 unsigned int WB_iatan(
int iX,
int iY)
357 static int clip255(
int iIn)
371 void PXM_RGBToYUV(
int iR,
int iG,
int iB,
int *piY,
int *piU,
int *piV)
379 iY = clip255((( 66 * iR + 129 * iG + 25 * iB + 128) >> 8) + 16);
380 iU = clip255((( -38 * iR - 74 * iG + 112 * iB + 128) >> 8) + 128);
381 iV = clip255((( 112 * iR - 94 * iG - 18 * iB + 128) >> 8) + 128);
399 void PXM_YUVToRGB(
int iY,
int iU,
int iV,
int *piR,
int *piG,
int *piB)
406 iR = clip255(( 298 * iC + 409 * iE + 128) >> 8);
407 iG = clip255(( 298 * iC - 100 * iD - 208 * iE + 128) >> 8);
408 iB = clip255(( 298 * iC + 516 * iD + 128) >> 8);
426 void PXM_HSVToRGB(
int iH,
int iS,
int iV,
int *piR,
int *piG,
int *piB)
435 double dH, dS, dV, dFracH, dR, dG, dB;
437 double dUnSat, dLinDn, dLinUp;
446 dH = (6.0 / 256.0) * iH;
447 iQuadrant = (int)floor(dH);
448 dFracH = dH - iQuadrant;
453 dUnSat = dV * (1.0 - dS);
454 dLinDn = dV * (1.0 - dS * dFracH);
455 dLinUp = dV * (1.0 - dS * (1.0 - dFracH));
466 else if(iQuadrant == 1)
487 else if(iQuadrant == 4)
501 iR = clip255((
int)floor(256 * dR));
502 iG = clip255((
int)floor(256 * dG));
503 iB = clip255((
int)floor(256 * dB));
522 void PXM_RGBToHSV(
int iR,
int iG,
int iB,
int *piH,
int *piS,
int *piV)
530 double dH, dS, dV, dDelta;
531 int iMinRGB, iMaxRGB;
551 dV = iMaxRGB / 255.0;
567 dS = 1.0 * (iMaxRGB - iMinRGB)
572 *piS = clip255((
int)floor(256.0 * dS));
582 if(iMaxRGB == iMinRGB)
590 dDelta = iMaxRGB - iMinRGB;
595 dH = (iG - iB) / dDelta;
597 else if(iG == iMaxRGB)
599 dH = 2.0 + (iB - iR) / dDelta;
603 dH = 4.0 + (iR - iG) / dDelta;
620 *piH = clip255((
int)floor((256.0 / 6.0) * dH));
624 static unsigned short internal_get_rgb_from_pixel(
long lPixel,
int iMult,
int iMax)
631 lVal = lPixel / 65536;
643 lVal = lPixel / iMult;
646 if(
WB_LIKELY(iMax == 65535 || iMax == 255))
672 #ifdef HAS_WB_UINT64_BUILTIN 676 #else // !HAS_WB_UINT64_BUILTIN 681 #endif // HAS_WB_UINT64_BUILTIN 685 return (
unsigned short)lVal;
690 unsigned long lColor;
691 XStandardColormap map;
709 lColor = pColor->pixel - pMap->base_pixel;
711 if(!pMap->red_mult && !pMap->green_mult && !pMap->blue_mult)
716 pColor->flags = DoRed | DoGreen | DoBlue;
718 if(!pMap->green_mult && !pMap->blue_mult)
722 pColor->red = internal_get_rgb_from_pixel(lColor, pMap->red_mult, pMap->red_max);
723 pColor->green = pColor->blue = pColor->red;
725 pColor->flags = DoRed;
729 pColor->red = internal_get_rgb_from_pixel(lColor, pMap->red_mult, pMap->red_max);
730 pColor->green = internal_get_rgb_from_pixel(lColor, pMap->green_mult, pMap->green_max);
731 pColor->blue = internal_get_rgb_from_pixel(lColor, pMap->blue_mult, pMap->blue_max);
737 unsigned long lR, lG, lB;
738 XStandardColormap map;
760 pColor->flags = DoRed | DoGreen | DoBlue;
763 if(pColor->flags & DoRed)
765 lR = ((
unsigned long)(pColor->red) * (
unsigned long)(pMap->red_max + 1))
766 / (
unsigned long)65536L;
774 if(lR > pMap->red_max)
779 if(pColor->flags & DoGreen)
781 lG = ((
unsigned long)(pColor->green) * (
unsigned long)(pMap->green_max + 1))
782 / (
unsigned long)65536L;
790 if(lG > pMap->green_max)
792 lG = pMap->green_max;
795 if(pColor->flags & DoBlue)
797 lB = (((
unsigned long)pColor->blue) * (
unsigned long)(pMap->blue_max + 1))
798 / (
unsigned long)65536L;
806 if(lB > pMap->blue_max)
811 pColor->pixel = (pMap->base_pixel
812 + lR * pMap->red_mult
813 + lG * pMap->green_mult
814 + lB * pMap->blue_mult)
827 ppRegAppLarge_Internal = ppRegAppLarge;
828 ppRegAppSmall_Internal = ppRegAppSmall;
831 static char **GetPreDefinedIconResource(
int idIcon)
838 if(ppRegAppSmall_Internal)
840 pData = ppRegAppSmall_Internal;
848 if(ppRegAppLarge_Internal)
850 pData = ppRegAppLarge_Internal;
861 pData = icon_stop_xpm;
864 pData = icon_warn_xpm;
867 pData = icon_what_xpm;
870 pData = icon_splat_xpm;
873 pData = icon_bang_xpm;
875 case ID_ICON_TRIANGLE:
876 pData = icon_triangle_xpm;
878 case ID_ICON_WHAT_BOLD:
879 pData = icon_what_bold_xpm;
882 pData = icon_wtf_xpm;
885 pData = icon_death_xpm;
888 pData = icon_finger_xpm;
891 pData = icon_skull_xpm;
893 case ID_ICON_THUMBUP:
894 pData = icon_thumbup_xpm;
896 case ID_ICON_THUMBDOWN:
897 pData = icon_thumbdown_xpm;
900 pData = icon_bear_xpm;
903 pData = icon_barney_xpm;
910 static void RegisterIconResource(Atom aIcon,
char **ppResource)
914 if(!pAtomResourceList)
916 pAtomResourceList = (INTERNAL_ATOM_RESOURCE_LIST *)
917 WBAlloc(MINIMUM_ATOM_RESOURCE_LIST_SIZE *
sizeof(*pAtomResourceList));
919 if(!pAtomResourceList)
921 WB_ERROR_PRINT(
"%s - not enough memoory for atom resource list\n", __FUNCTION__);
925 nAtomResourceList = 0;
926 nAtomResourceListMax = MINIMUM_ATOM_RESOURCE_LIST_SIZE;
929 for(i1=0; i1 < nAtomResourceList; i1++)
931 if(pAtomResourceList[i1].aAtom == aIcon)
933 WB_ERROR_PRINT(
"%s - matching atom already in the list (ignoring)\n", __FUNCTION__);
938 if((nAtomResourceList + 1) >= nAtomResourceListMax)
940 int iNewSize = MINIMUM_ATOM_RESOURCE_LIST_SIZE / 2 + nAtomResourceListMax;
942 void *pTemp =
WBReAlloc(pAtomResourceList, iNewSize);
945 WB_ERROR_PRINT(
"%s - not enough memoory for atom resource list re-alloc\n", __FUNCTION__);
949 pAtomResourceList = (INTERNAL_ATOM_RESOURCE_LIST *)pTemp;
950 nAtomResourceListMax += MINIMUM_ATOM_RESOURCE_LIST_SIZE / 2;
953 pAtomResourceList[nAtomResourceList].aAtom = aIcon;
954 pAtomResourceList[nAtomResourceList].ppResource = ppResource;
958 static const char *
const szPreDefinedIconResources[] =
982 static char **GetRegisteredIconResource(Atom aIcon)
984 static int iHasBeenRegistered = 0;
989 if(!iHasBeenRegistered)
991 for(i1=ID_ICON_FIRST, i2=0;
993 && i2 <
sizeof(szPreDefinedIconResources)/
sizeof(szPreDefinedIconResources[0]);
1000 RegisterIconResource(aTemp, GetPreDefinedIconResource(i1));
1004 iHasBeenRegistered = 1;
1007 for(i1=0; i1 < nAtomResourceList; i1++)
1009 if(pAtomResourceList[i1].aAtom == aIcon)
1011 return pAtomResourceList[i1].ppResource;
1025 pData = GetPreDefinedIconResource(idIcon);
1031 bzero(pAttr,
sizeof(*pAttr));
1051 pData = GetRegisteredIconResource(aIcon);
1057 bzero(pAttr,
sizeof(*pAttr));
1074 Pixmap pixRval = None, pixRval2 = None;
1085 bzero(pAttr,
sizeof(*pAttr));
1096 bzero(&xattr,
sizeof(xattr));
1100 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XPM 1102 #endif // X11WORKBENCH_TOOLKIT_HAVE_XPM 1104 ppXPM, &pixRval, &pixRval2, &xattr);
1105 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XPM 1107 #endif // X11WORKBENCH_TOOLKIT_HAVE_XPM 1113 memcpy(pAttr, &xattr,
sizeof(xattr));
1119 DEBUG_DUMP_XPM_ATTRIBUTES(&xattr);
1129 else if(pixRval2 != None)
1140 unsigned long clrFGPixel,
unsigned long clrBGPixel)
1159 iH = pImage->height;
1163 WB_ERROR_PRINT(
"%s - Image width/height not valid, iW=%d,iH=%d\n", __FUNCTION__, iW, iH);
1168 pxRval = XCreatePixmap(pDisplay, dw, iW, iH, DefaultDepth(pDisplay, DefaultScreen(pDisplay)));
1179 memset(&gcv, 0,
sizeof(gcv));
1180 gcv.foreground = clrFGPixel;
1181 gcv.background = clrBGPixel;
1186 gc =
WBCreateGC(pDisplay, dw, (GCForeground | GCBackground), &gcv);
1194 XFreePixmap(pDisplay, pxRval);
1201 WBXPutImage(pDisplay, pxRval, gc, pImage, 0, 0, 0, 0, iW, iH);
1219 BlackPixel(pDisplay, DefaultScreen(pDisplay)),
1220 WhitePixel(pDisplay, DefaultScreen(pDisplay)));
1229 unsigned int iWidth=0, iHeight=0, iBorder;
1230 unsigned int uiDepth = 0;
1248 XGetGeometry(pDisplay, pxImage, &winRoot, &iX, &iY, &iWidth, &iHeight, &iBorder, &uiDepth);
1250 if(!iWidth || !iHeight)
1257 pRval =
WBXGetImage(pDisplay, pxImage, 0, 0, iWidth, iHeight, -1L, ZPixmap);
1271 int iRet, iX=0, iY=0;
1272 unsigned int iWidth=0, iHeight=0, iBorder;
1273 unsigned int uiDepth = 0;
1281 if((CARD32)pxSource & 0xe0000000)
1283 WB_ERROR_PRINT(
"%s - invalid Pixmap - %d (%08xH)\n", __FUNCTION__, (
int)pxSource, (
int)pxSource);
1290 iRet = XGetGeometry(pDisplay, pxSource, &winRoot, &iX, &iY, &iWidth, &iHeight, &iBorder, &uiDepth);
1293 if(!iWidth || !iHeight)
1295 WB_ERROR_PRINT(
"%s - XGetGeometry failed, pxSource=%d (%08xH), iRet=%d\n",
1296 __FUNCTION__, (
int)pxSource, (
int)pxSource, iRet);
1302 pxRval = XCreatePixmap(pDisplay, dw, iWidth, iHeight, uiDepth);
1313 memset(&gcv, 0,
sizeof(gcv));
1314 gcv.foreground = BlackPixel(pDisplay, DefaultScreen(pDisplay));
1315 gcv.background = WhitePixel(pDisplay, DefaultScreen(pDisplay));
1320 gc = XCreateGC(pDisplay, dw, (GCForeground | GCBackground), &gcv);
1328 XFreePixmap(pDisplay, pxRval);
1335 XCopyArea(pDisplay, pxSource, pxRval, gc, 0, 0, iWidth, iHeight, 0, 0);
1336 XFreeGC(pDisplay, gc);
1347 XImage *pImage = NULL;
1350 XStandardColormap map;
1371 memcpy(&geom, pGeom,
sizeof(geom));
1378 unsigned int iWidth=0, iHeight=0, iBorder;
1379 unsigned int uiDepth = 0;
1383 XGetGeometry(pDisplay, pxImage, &winRoot, &iX, &iY, &iWidth, &iHeight, &iBorder, &uiDepth);
1388 geom.
width = iWidth;
1405 WB_ERROR_PRINT(
"ERROR: %s - unable to create image via XGetImage()\n", __FUNCTION__);
1411 memset(&gcv, 0,
sizeof(gcv));
1412 gcv.foreground = lPixel;
1413 gcv.background = lPixel;
1416 gc =
WBCreateGC(pDisplay, pxImage, (GCForeground | GCBackground), &gcv);
1438 static unsigned long __internal_grey_the_pixel(XStandardColormap *pMap,
unsigned long lPixel,
1439 int iR0,
int iG0,
int iB0)
1448 iR = (3 * iR + iR0 + 1) / 4;
1449 iG = (3 * iG + iG0 + 1) / 4;
1450 iB = (3 * iB + iB0 + 1) / 4;
1461 XStandardColormap map;
1462 int nX, nY, iR, iG, iB;
1479 memcpy(&map, pMap,
sizeof(map));
1484 memcpy(&geom, pGeom,
sizeof(geom));
1490 geom.
width = pImage->width;
1491 geom.
height = pImage->height;
1498 for(nX = geom.
x; nX < (geom.
x + geom.
width - 1); nX++)
1500 for(nY = geom.
y; nY < (geom.
y + geom.
height - 1); nY++)
1512 unsigned long lPixel1 = XGetPixel(pImage, nX, nY);
1513 unsigned long lPixel2 = XGetPixel(pImage, nX + 1, nY);
1514 unsigned long lPixel3 = XGetPixel(pImage, nX, nY + 1);
1515 unsigned long lPixel4 = XGetPixel(pImage, nX + 1, nY + 1);
1517 if(lPixel1 == lPixel && lPixel4 == lPixel)
1519 if(lPixel2 != lPixel)
1521 lPixel2 = __internal_grey_the_pixel(&map, lPixel2, iR, iG, iB);
1522 if(lPixel2 != lPixel)
1525 XPutPixel(pImage, nX + 1, nY, lPixel2);
1530 if(lPixel3 != lPixel)
1532 lPixel3 = __internal_grey_the_pixel(&map, lPixel3, iR, iG, iB);
1533 if(lPixel3 != lPixel)
1536 XPutPixel(pImage, nX, nY + 1, lPixel3);
1542 if(lPixel2 == lPixel && lPixel3 == lPixel)
1544 if(lPixel1 != lPixel)
1546 lPixel1 = __internal_grey_the_pixel(&map, lPixel1, iR, iG, iB);
1547 if(lPixel1 != lPixel)
1550 XPutPixel(pImage, nX, nY, lPixel1);
1555 if(lPixel4 != lPixel)
1557 lPixel4 = __internal_grey_the_pixel(&map, lPixel4, iR, iG, iB);
1558 if(lPixel4 != lPixel)
1561 XPutPixel(pImage, nX + 1, nY + 1, lPixel4);
1573 #if defined(X11WORKBENCH_TOOLKIT_HAVE_XSHM_EXTENSION) || defined(__DOXYGEN__) 1576 return XShmQueryExtension(pDisplay) ? 1 : 0;
1578 #endif // defined(X11WORKBENCH_TOOLKIT_HAVE_XSHM_EXTENSION) || defined(__DOXYGEN__) 1581 int src_x,
int src_y,
int dest_x,
int dest_y,
1582 unsigned int width,
unsigned int height)
1588 iRval = XPutImage(pDisplay, dw, gc->
gc, pImage, src_x, src_y, dest_x, dest_y, width, height);
1608 int x,
int y,
unsigned int width,
unsigned int height,
1609 unsigned long plane_mask,
int format)
1618 #if defined(X11WORKBENCH_TOOLKIT_HAVE_XSHM_EXTENSION) || defined(__DOXYGEN__) 1621 #endif // defined(X11WORKBENCH_TOOLKIT_HAVE_XSHM_EXTENSION) || defined(__DOXYGEN__) 1624 pImage = XGetImage(pDisplay, dw, x, y, width, height, plane_mask, format);
1627 #if defined(X11WORKBENCH_TOOLKIT_HAVE_XSHM_EXTENSION) || defined(__DOXYGEN__) 1634 pImage = XGetImage(pDisplay, dw, x, y, width, height, plane_mask, format);
1639 WB_ERROR_PRINT(
"ERROR - %s - Unable to get XImage: dw=%08xH x=%d y=%d width=%d height=%d plane_mask=%08lxH format=%d\n",
1640 __FUNCTION__, (
int)dw, x, y, width, height, (
unsigned long)plane_mask, format);
1644 XShmSegmentInfo shminfo;
1645 int screen = DefaultScreen(pDisplay);
1646 Visual *pVisual = DefaultVisual(pDisplay, screen);
1647 int depth = DefaultDepth(pDisplay, screen);
1649 if(format == XYBitmap)
1654 bzero(&shminfo,
sizeof(shminfo));
1656 pImage = XShmCreateImage(pDisplay, pVisual, depth, format, NULL, &shminfo, width, height);
1660 shminfo.readOnly = False;
1661 pImage->data = WBAllocShm(pDisplay, image->bytes_per_line * image->height, &shminfo, IPC_PRIVATE, PIC_CREAT | 0777);
1677 if(!XShmGetImage(pDisplay, dw, pImage, x, y, plane_mask))
1689 #endif // defined(X11WORKBENCH_TOOLKIT_HAVE_XSHM_EXTENSION) || defined(__DOXYGEN__) 1703 iRval = XDestroyImage(pImage);
1724 pRval = XCreateImage(pDisplay, DefaultVisual(pDisplay, DefaultScreen(pDisplay)),
1725 pImage->depth, pImage->format, pImage->xoffset,
1726 pImage->data, pImage->width, pImage->height,
1727 pImage->bitmap_pad, pImage->bytes_per_line);
1829 if(rgnSource == None)
1864 XPointInRegion(hGC->
clip_rgn, x, y))
1867 iRval = XPutPixel(pImage, x, y, hGC->
values.foreground);
1875 XPoint *points,
int npoints,
int mode)
1877 int i1, i2, iX, iY, iRval;
1881 if(!pImage || !hGC || !points || npoints <= 0 ||
1882 (mode != CoordModeOrigin && mode != CoordModePrevious))
1892 for(i1=0, iRval = 0; i1 < npoints; i1++)
1894 if(mode == CoordModeOrigin)
1908 if(!XPointInRegion(hGC->
clip_rgn, iX, iY))
1915 i2 = XPutPixel(pImage, iX, iY, hGC->
values.foreground);
1928 int x1,
int y1,
int x2,
int y2)
1938 return WBXDrawLines(pImage, hGC, &(pt[0]), 2, CoordModeOrigin);
1963 XPoint *points,
int npoints,
int mode)
1966 if(!pImage || !hGC || !points || npoints <= 0 ||
1967 (mode != CoordModeOrigin && mode != CoordModePrevious))
1986 int x,
int y,
unsigned int width,
unsigned int height)
1992 ptRect[1].x = x + width - 1;
1994 ptRect[2].x = ptRect[1].x;
1995 ptRect[2].y = y + height - 1;
1997 ptRect[3].y = ptRect[2].y;
2002 sizeof(ptRect) /
sizeof(ptRect[0]),
2007 int x,
int y,
unsigned int width,
unsigned int height)
2015 ptRect[1].x = x + width - 1;
2017 ptRect[2].x = ptRect[1].x;
2018 ptRect[2].y = y + height - 1;
2020 ptRect[3].y = ptRect[2].y;
2025 sizeof(ptRect) /
sizeof(ptRect[0]),
2026 Convex, CoordModeOrigin);
2033 sizeof(ptRect) /
sizeof(ptRect[0]),
2041 int x,
int y,
unsigned int width,
unsigned int height,
2042 int angle1,
int angle2)
2044 XPoint ptPoly[4096];
2045 XPoint *pPoly = &(ptPoly[0]);
2046 int iRval, nLines = 0;
2072 int x,
int y,
unsigned int width,
unsigned int height,
2073 int angle1,
int angle2)
2079 XPoint *points,
int npoints,
int shape,
int mode)
2081 if(!pImage || !hGC || !points || npoints <= 0 ||
2082 (shape != Convex && shape != Nonconvex && shape != Complex) ||
2083 (mode != CoordModeOrigin && mode != CoordModePrevious))
2108 int x,
int y,
const char *
string,
int length)
2116 #ifdef X11WORKBENCH_TOOLKIT_HAVE_XFT 2119 #warning TODO: IMPLEMENT THIS PART for Xft FONTS - this may require legacy font stuff too 2122 #endif // X11WORKBENCH_TOOLKIT_HAVE_XFT 2142 static void DebugDumpXpmAttributes(
const char *szFunction,
int nLine,
XPM_ATTRIBUTES *pAttr)
2144 WBDebugPrint(
"%s line %d XPM_ATTRIBUTES contain:\n", szFunction, nLine);
2145 #if defined(X11WORKBENCH_TOOLKIT_HAVE_XPM) 2148 WBDebugPrint(
" colormap: %p\n", (
void *)pAttr->colormap);
2149 #endif // defined(X11WORKBENCH_TOOLKIT_HAVE_XPM) 2156 #if defined(X11WORKBENCH_TOOLKIT_HAVE_XPM) 2162 WBDebugPrint(
" colorsymbols: %p\n", pAttr->colorsymbols);
2165 WBDebugPrint(
" nextensions: %u\n", pAttr->nextensions);
2170 WBDebugPrint(
" exactColors: %c\n", pAttr->exactColors ?
'T' :
'F');
2172 WBDebugPrint(
" red_closeness: %u\n", pAttr->red_closeness);
2173 WBDebugPrint(
" green_closeness: %u\n", pAttr->green_closeness);
2174 WBDebugPrint(
" blue_closeness: %u\n", pAttr->blue_closeness);
2176 WBDebugPrint(
" alloc_pixels: %p\n", pAttr->alloc_pixels);
2177 WBDebugPrint(
" nalloc_pixels: %d\n", pAttr->nalloc_pixels);
2178 WBDebugPrint(
" alloc_close_colors: %c\n", pAttr->alloc_close_colors ?
'T' :
'F');
2179 WBDebugPrint(
" bitmap_format: %d\n", pAttr->bitmap_format);
2180 WBDebugPrint(
" alloc_color: %p\n", pAttr->alloc_color);
2181 WBDebugPrint(
" free_colors: %p\n", pAttr->free_colors);
2182 WBDebugPrint(
" color_closure: %p\n", pAttr->color_closure);
2183 #endif // defined(X11WORKBENCH_TOOLKIT_HAVE_XPM) 2202 WBDebugPrint(
" base_pixel = %ld (%08lxH)\n", pMap->base_pixel, pMap->base_pixel);
2217 WBDebugPrint(
" pixel = %lu \"#%6.6lX\"\n", pColor->pixel, pColor->pixel);
2223 if(pColor->flags & DoRed)
2230 strcat(tbuf,
"DoRed");
2233 if(pColor->flags & DoGreen)
2237 strcat(tbuf,
" | ");
2240 strcat(tbuf,
"DoGreen");
2243 if(pColor->flags & DoBlue)
2247 strcat(tbuf,
" | ");
2250 strcat(tbuf,
"DoBlue");
2259 WBDebugPrint(
" flags = %d (%XH)\n", pColor->flags, pColor->flags);
int WBXDrawArc(XImage *pImage, WBGC hGC, int x, int y, unsigned int width, unsigned int height, int angle1, int angle2)
XImage version for XDrawArc()
Pixmap PXM_GetIconPixmap(int idIcon, XPM_ATTRIBUTES *pAttr, Pixmap *pMask)
Create Icon pixmap pair using pre-defined resource ID.
void PXM_RGBToYUV(int iR, int iG, int iB, int *piY, int *piU, int *piV)
Convert R, G, B values to Y, U, V with 0-255 range.
void WBDefaultStandardColormap(Display *pDisplay, XStandardColormap *pMap)
returns a default XStandardColormap structure for the default screen of the specified display
unsigned char WB_isqrt(unsigned char iVal)
integer square root of a value 0-255
XImage * WBXImageFromRegion(Region rgnSource, int width, int height)
Create a Region from an XImage.
int WBXFillPolygon(XImage *pImage, WBGC hGC, XPoint *points, int npoints, int shape, int mode)
XImage version for XFillPolygon()
void PXM_YUVToRGB(int iY, int iU, int iV, int *piR, int *piG, int *piB)
Convert Y, U, V values to R, G, B with 0-255 range.
void PXM_RegisterAppIcons(char *ppRegAppLarge[], char *ppRegAppSmall[])
Icon Registration for application 'large' and 'small' icons.
Pixmap PXM_LoadPixmap(char *ppXPM[], XPM_ATTRIBUTES *pAttr, Pixmap *pMask)
Create pixmap or pixmap pair using an XPM array.
Compatibility structure for use with MyLoadPixmapFromData() whenever libXpm is not in use.
int WBXDrawRectangle(XImage *pImage, WBGC hGC, int x, int y, unsigned int width, unsigned int height)
XImage version for XDrawRectangle()
int WBXPutImage(Display *pDisplay, Drawable dw, WBGC gc, XImage *pImage, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height)
Write contents of an XImage onto a Drawable.
#define XPM_FREE_ATTRIBUTES(pAttr)
Platform helper macro to free XPM_ATTRIBUTES filled in by XPM_CREATE_PIXMAP_FROM_DATA()
void PXM_OnExit(void)
Frees resources allocated by Pixmap utility functions.
static __inline__ Display * WBGetDefaultDisplay(void)
Returns the default Display.
internal wrapper struct for X11 'geometry' definition
void PXM_RGBToPixel(XStandardColormap *pMap, XColor *pColor)
Icon Registration for application 'large' and 'small' icons.
int WBXFillRectangle(XImage *pImage, WBGC hGC, int x, int y, unsigned int width, unsigned int height)
XImage version for XFillRectangle()
int width
The width of the returned pixmaps.
void PXM_PixelToRGB(XStandardColormap *pMap, XColor *pColor)
Convert the pixel menber of an XColor to RGB.
Pixmap PXM_GetIconPixmapFromAtom(Atom aIcon, XPM_ATTRIBUTES *pAttr, Pixmap *pMask)
Create Icon pixmap pair using a registered or pre-defined resource ID.
void * WBReAlloc(void *pBuf, int nNewSize)
High performance memory sub-allocator 're-allocate'.
int WBXDrawLine(XImage *pImage, WBGC hGC, int x1, int y1, int x2, int y2)
XImage version for XDrawLines()
XImage * WBXCopyImage(Display *pDisplay, XImage *pImage)
Make a copy of an XImage.
Pixmap PXM_ImageToPixmap(Display *pDisplay, Drawable dw, XImage *pImage, unsigned long clrFGPixel, unsigned long clrBGPixel)
Convert 'locally stored' XImage to 'server object' Pixmap.
int WBXShmQueryExtension(Display *pDisplay)
Indicates whether the 'XShm' extensions are available (libXext)
void WBDebugDumpColormap(const char *szTitle, const XStandardColormap *pMap)
Dump XStandardColormap members for debugging.
unsigned char WB_icos0(unsigned char iVal)
integer 255 * cos(iVal * pi / 512) calculation via lookup table (legacy, to be removed?...
void * WBAlloc(int nSize)
High performance memory sub-allocator 'allocate'.
#define END_XCALL_DEBUG_WRAPPER
wrapper macro for calls into the X11 library. This macro follows the call(s)
void WBDebugDumpXColor(const char *szTitle, const XColor *pColor)
Dump XColor members for debugging.
int WBXDrawPoint(XImage *pImage, WBGC hGC, int x, int y)
XImage version for XDrawPoint()
int WBXDrawString(XImage *pImage, WB_FONTC pFont, WBGC hGC, int x, int y, const char *string, int length)
XImage version for XDrawString() or DTDrawString()
#define WB_ERROR_PRINT(...)
Preferred method of implementing an 'error level' debug message for all subsystems.
Window WBGetHiddenHelperWindow(void)
Returns a special 'hidden' window used for information purposes.
int WBXDrawPoints(XImage *pImage, WBGC hGC, XPoint *points, int npoints, int mode)
XImage version for XDrawPoints()
void WBFree(void *pBuf)
High performance memory sub-allocator 'free'.
XGCValues values
cached XGCValues for the GC
WBGC WBCreateGC(Display *pDisplay, Drawable dw, unsigned long valuemask, const XGCValues *values)
Creates a WBGC, wrapper for XCreateGC()
XImage * PXM_PixmapToImage(Display *pDisplay, Pixmap pxImage)
Convert pixmap to image (a wrapper for XGetImage on a pixmap)
XImage * WBXGetImage(Display *pDisplay, Drawable dw, int x, int y, unsigned int width, unsigned int height, unsigned long plane_mask, int format)
Read contents of a Drawable onto an XImage.
void WBSimpleAntiAliasImage(const XStandardColormap *pMap, XImage *pImage, unsigned long lPixel, WB_GEOM *pGeom)
Simple anti-alias of an XImage using foreground pixel color.
void PXM_RGBToHSV(int iR, int iG, int iB, int *piH, int *piS, int *piV)
Convert R, G, B values to H, S, V with 0-255 range.
int WBXDestroyImage(XImage *pImage)
Destroy an XImage - call this instead of XDestroyImage()
char WB_icos(int iVal)
integer 127 * cos(iVal * pi / 512) calculation via lookup table
void WBFreeGC(WBGC hGC)
Free resources for a WBGC, wrapper for XFreeGC()
Pixmap PXM_ImageToPixmap0(Display *pDisplay, Drawable dw, XImage *pImage)
Convert 'locally stored' XImage to 'server object' Pixmap using default FG/BG colors for monochrome.
#define RGB_FROM_XCOLOR(X, R, G, B)
Simple RGB assignment from pixel, 0-65535 RGB.
int depth
depth of the returned 'image' pixmap. The mask pixmap always has a depth of '1'.
#define BEGIN_XCALL_DEBUG_WRAPPER
wrapper macro for calls into the X11 library. This macro precedes the call(s)
Region clip_rgn
clipping region (or None to use clip_image) - owned by the object
int WBXDrawLines(XImage *pImage, WBGC hGC, XPoint *points, int npoints, int mode)
XImage version for XDrawLine()
void WBDebugPrint(const char *pFmt,...) __attribute__((format(printf
conditional debug message output
An allocated structure containing XFontStruct, XFontInfo, and XftFont [as applicable] for a specified...
#define WB_IF_DEBUG_LEVEL(L)
Preferred method of implementing conditional debug 'if block' code.
#define XPM_CREATE_PIXMAP_FROM_DATA(A, B, C, D, E, F)
Platform helper macro to create a pixmap from data.
internal wrapper struct for GC with local cache
Pixmap PXM_CopyPixmap(Display *pDisplay, Drawable dw, Pixmap pxSource)
Copy a pixmap for the specified Display and Drawable.
void PXM_HSVToRGB(int iH, int iS, int iV, int *piR, int *piG, int *piB)
Convert H, S, V values to R, G, B with 0-255 range.
void WBSimpleAntiAliasPixmap(Display *pDisplay, const XStandardColormap *pMap, Pixmap pxImage, unsigned long lPixel, WB_GEOM *pGeom)
Simple anti-alias of a Pixmap using foreground pixel color.
int WBXFillArc(XImage *pImage, WBGC hGC, int x, int y, unsigned int width, unsigned int height, int angle1, int angle2)
XImage version for XFillArc()
int height
height of the returned pixmaps
#define RGB_TO_XCOLOR(R, G, B, X)
Simple RGB assignment to pixel, 0-65535 RGB.
Region WBXImageToRegion(const XImage *pImage)
Create a Region from an XImage.