X11workbench Toolkit  1.0
pixmap_helper.h
1 // _ _ _ _ //
3 // _ __ (_)__ __ _ __ ___ __ _ _ __ | |__ ___ | | _ __ ___ _ __ | |__ //
4 // | '_ \ | |\ \/ /| '_ ` _ \ / _` || '_ \ | '_ \ / _ \| || '_ \ / _ \| '__|| '_ \ //
5 // | |_) || | > < | | | | | || (_| || |_) | | | | || __/| || |_) || __/| | _ | | | | //
6 // | .__/ |_|/_/\_\|_| |_| |_| \__,_|| .__/_____|_| |_| \___||_|| .__/ \___||_|(_)|_| |_| //
7 // |_| |_| |_____| |_| //
8 // //
9 // pixmap and icon helpers (ultimately providing universal support) //
10 // //
12 
13 /*****************************************************************************
14 
15  X11workbench - X11 programmer's 'work bench' application and toolkit
16  Copyright (c) 2010-2018 by Bob Frazier (aka 'Big Bad Bombastic Bob')
17  all rights reserved
18 
19  DISCLAIMER: The X11workbench application and toolkit software are supplied
20  'as-is', with no warranties, either implied or explicit.
21  Any claims to alleged functionality or features should be
22  considered 'preliminary', and might not function as advertised.
23 
24  BSD-like license:
25 
26  There is no restriction as to what you can do with this software, so long
27  as you include the above copyright notice and DISCLAIMER for any distributed
28  work that is equal to or derived from this one, along with this paragraph
29  that explains the terms of the license if the source is also being made
30  available. A "derived work" describes a work that uses a significant portion
31  of the source files or algorithms that are included with this one.
32  Specifically excluded from this are files that were generated by the software,
33  or anything that is included with the software that is part of another package
34  (such as files that were created or added during the 'configure' process).
35  Specifically included is the use of part or all of any of the X11 workbench
36  toolkit source or header files in your distributed application. If you do not
37  ship the source, the above copyright statement is still required to be placed
38  in a reasonably prominent place, such as documentation, splash screens, and/or
39  'about the application' dialog boxes.
40 
41  Use and distribution are in accordance with GPL, LGPL, and/or the above
42  BSD-like license. See COPYING and README files for more information.
43 
44 
45  Additional information at http://sourceforge.net/projects/X11workbench
46 
47 ******************************************************************************/
48 
49 
50 #ifndef _PIXMAP_HELPER_H_
51 #define _PIXMAP_HELPER_H_
52 
53 #include "window_helper.h" // if not already included, I must include this
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif // __cplusplus
58 
59 
60 #define ID_ICON_FIRST 101
61 #define ID_APPLICATION 101 /* 19x19 application icon */
62 #define ID_ICON_OK 102
63 #define ID_ICON_STOP 103
64 #define ID_ICON_WARN 104 /* yellow triangle, ! */
65 #define ID_ICON_WHAT 105
66 #define ID_ICON_QUESTION 105
67 #define ID_ICON_SPLAT 106
68 #define ID_ICON_ASTERISK 106
69 #define ID_ICON_BANG 107 /* yellow circle, ! */
70 #define ID_ICON_TRIANGLE 108
71 #define ID_ICON_WHAT_BOLD 109
72 #define ID_ICON_WTF 110
73 #define ID_ICON_DEATH 111
74 #define ID_ICON_FINGER 112
75 #define ID_ICON_SKULL 113
76 #define ID_ICON_THUMBUP 114
77 #define ID_ICON_THUMBDOWN 115
78 #define ID_ICON_BEAR 116
79 #define ID_ICON_BARNEY 117
80 #define ID_ICON_APP 118 /* 36x36 application icon */
81 #define ID_ICON_LAST 118 /* must alter this if new items added */
82 
83 
95 #define RGB255_TO_XCOLOR(R,G,B,X) { (X).red = ((unsigned int)(R) << 8) & 0xffff; \
96  (X).green = ((unsigned int)(G) << 8) & 0xffff; \
97  (X).blue = ((unsigned int)(B) << 8) & 0xffff; \
98  (X).flags = DoRed | DoGreen | DoBlue; }
99 
111 #define RGB_TO_XCOLOR(R,G,B,X) { (X).red = ((unsigned int)(R)) & 0xffff; \
112  (X).green = ((unsigned int)(G)) & 0xffff; \
113  (X).blue = ((unsigned int)(B)) & 0xffff; \
114  (X).flags = DoRed | DoGreen | DoBlue; }
115 
116 
130 #define RGB255_FROM_XCOLOR(X,R,G,B) {register unsigned short __iR,__iG,__iB; RGB_FROM_XCOLOR(X,__iR, __iG, __iB); \
131  if(__iR < 0xff80){ __iR += 0x80; } \
132  if(__iG < 0xff80){ __iG += 0x80; } \
133  if(__iB < 0xff80){ __iB += 0x80; } \
134  __iR = __iR >> 8; __iG = __iG >> 8; __iB = __iB >> 8; \
135  __iR &= 0xff; __iG &= 0xff; __iB &= 0xff; \
136  (R) = __iR; (G) = __iG; (B) = __iB; }
137 
151 #define RGB_FROM_XCOLOR(X,R,G,B) { (R) = (((X).flags) & DoRed) ? ((unsigned int)(X).red) & 0xffff : 0; \
152  (G) = (((X).flags) & DoGreen) ? ((unsigned int)(X).green) & 0xffff : 0; \
153  (B) = (((X).flags) & DoBlue) ? ((unsigned int)(X).blue) & 0xffff : 0; }
154 
155 
170 static __inline__ XStandardColormap *PXM_StandardColormapFromColormap(Display *pDisplay, Colormap colormap)
171 {
172 extern XStandardColormap PXM_StandardColormapFromColormap_rval; // declare extern rather than static, for single mem spot
173 
174  if(!pDisplay)
175  {
176  pDisplay = WBGetDefaultDisplay();
177  }
178 
179  WBDefaultStandardColormap(pDisplay, &PXM_StandardColormapFromColormap_rval);
180 
181  PXM_StandardColormapFromColormap_rval.colormap = colormap;
182 
183  return &PXM_StandardColormapFromColormap_rval;
184 }
185 
214 void PXM_RGBToYUV(int iR, int iG, int iB, int *piY, int *piU, int *piV);
215 
216 
234 void PXM_RGBToHSV(int iR, int iG, int iB, int *piH, int *piS, int *piV);
235 
236 
265 void PXM_YUVToRGB(int iY, int iU, int iV, int *piR, int *piG, int *piB);
266 
267 
285 void PXM_HSVToRGB(int iH, int iS, int iV, int *piR, int *piG, int *piB);
286 
287 
299 void PXM_PixelToRGB(XStandardColormap *pMap, XColor *pColor);
300 
301 
313 void PXM_RGBToPixel(XStandardColormap *pMap, XColor *pColor);
314 
315 
328 void PXM_RegisterAppIcons(char *ppRegAppLarge[], char *ppRegAppSmall[]);
329 
330 
343 int PXM_RegisterPixmapResource(Atom aResource, char *ppResource[]);
344 
345 
346 
360 Pixmap PXM_GetIconPixmap(int idIcon, XPM_ATTRIBUTES *pAttr, Pixmap *pMask /* = NULL*/);
361 
362 
376 Pixmap PXM_GetIconPixmapFromAtom(Atom aIcon, XPM_ATTRIBUTES *pAttr, Pixmap *pMask /* = NULL*/);
377 
378 
379 
395 Pixmap PXM_LoadPixmap(char *ppXPM[], XPM_ATTRIBUTES *pAttr, Pixmap *pMask /* = NULL*/);
396 
397 
398 
418 Pixmap PXM_ImageToPixmap(Display *pDisplay, Drawable dw, XImage *pImage,
419  unsigned long clrFGPixel, unsigned long clrBGPixel);
420 
421 
422 
441 Pixmap PXM_ImageToPixmap0(Display *pDisplay, Drawable dw, XImage *pImage);
442 
443 
444 
462 XImage *PXM_PixmapToImage(Display *pDisplay, Pixmap pxImage);
463 
464 
465 
466 
474 void PXM_OnExit(void);
475 
476 
477 //-------------------
478 // HELPERS FOR XColor
479 //-------------------
480 
491 void WBDebugDumpXColor(const char *szTitle, const XColor *pColor);
492 
503 void WBDebugDumpColormap(const char *szTitle, const XStandardColormap *pMap);
504 
505 
506 //--------------------
507 // HELPERS FOR XImage
508 //--------------------
509 
510 
522 static __inline__ void *PXM_GetImageDataPtr(XImage *pImage)
523 {
524  return pImage->data;
525 }
526 
538 static __inline__ unsigned long PXM_GetImageDataLength(XImage *pImage)
539 {
540  if(pImage->depth <= 1)
541  {
542  return (unsigned long)pImage->bytes_per_line * (unsigned long)pImage->height; // TODO: is this right?
543  }
544 
545  return (unsigned long)pImage->bytes_per_line * (unsigned long)pImage->height
546  * (unsigned long)pImage->depth;
547 }
548 
566 void WBSimpleAntiAliasPixmap(Display *pDisplay, const XStandardColormap *pMap, Pixmap pxImage,
567  unsigned long lPixel, WB_GEOM *pGeom);
568 
585 void WBSimpleAntiAliasImage(const XStandardColormap *pMap, XImage *pImage, unsigned long lPixel, WB_GEOM *pGeom);
586 
587 
588 
598 unsigned char WB_isqrt(unsigned char iVal);
599 
609 unsigned char WB_icos0(unsigned char iVal);
610 
620 char WB_icos(int iVal);
621 
631 #define WB_isin(X) WB_icos((X) - 256) /* subtract 256, i.e. pi/2 radians, to convert a cos to a sin */
632 
633 
634 
635 
636 #ifdef __cplusplus
637 };
638 #endif // __cplusplus
639 
640 #endif // _PIXMAP_HELPER_H_
641 
static __inline__ XStandardColormap * PXM_StandardColormapFromColormap(Display *pDisplay, Colormap colormap)
create temporary XStandardColormap from a Colormap
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.
&#39;window helper&#39; main header file for the X11workbench Toolkit API
static __inline__ Display * WBGetDefaultDisplay(void)
Returns the default Display.
static __inline__ unsigned long PXM_GetImageDataLength(XImage *pImage)
Returns the length of XImage data.
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
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 &#39;large&#39; and &#39;small&#39; icons.
Pixmap PXM_LoadPixmap(char *ppXPM[], XPM_ATTRIBUTES *pAttr, Pixmap *pMask)
Create pixmap or pixmap pair using an XPM array.
void PXM_OnExit(void)
Frees resources allocated by Pixmap utility functions.
void PXM_RGBToPixel(XStandardColormap *pMap, XColor *pColor)
Icon Registration for application &#39;large&#39; and &#39;small&#39; icons.
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.
Pixmap PXM_ImageToPixmap(Display *pDisplay, Drawable dw, XImage *pImage, unsigned long clrFGPixel, unsigned long clrBGPixel)
Convert &#39;locally stored&#39; XImage to &#39;server object&#39; Pixmap.
int PXM_RegisterPixmapResource(Atom aResource, char *ppResource[])
Register an icon (or pixmap) resource using an Atom.
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 WBDebugDumpXColor(const char *szTitle, const XColor *pColor)
Dump XColor members for debugging.
static __inline__ void * PXM_GetImageDataPtr(XImage *pImage)
Returns pointer to XImage data.
XImage * PXM_PixmapToImage(Display *pDisplay, Pixmap pxImage)
Convert pixmap to image (a wrapper for XGetImage on a pixmap)
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.
Definition: x.c:237
char WB_icos(int iVal)
integer 127 * cos(iVal * pi / 512) calculation via lookup table
Pixmap PXM_ImageToPixmap0(Display *pDisplay, Drawable dw, XImage *pImage)
Convert &#39;locally stored&#39; XImage to &#39;server object&#39; Pixmap using default FG/BG colors for monochrome...
Compatibility structure for use with MyLoadPixmapFromData() whenever libXpm is not in use...
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.
Definition: x.c:125
internal wrapper struct for X11 &#39;geometry&#39; definition
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.