X11 Work Bench 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-2016 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 
145 void PXM_RGBToYUV(int iR, int iG, int iB, int *piY, int *piU, int *piV);
146 
147 
165 void PXM_RGBToHSV(int iR, int iG, int iB, int *piH, int *piS, int *piV);
166 
167 
196 void PXM_YUVToRGB(int iY, int iU, int iV, int *piR, int *piG, int *piB);
197 
198 
216 void PXM_HSVToRGB(int iH, int iS, int iV, int *piR, int *piG, int *piB);
217 
218 
229 void PXM_PixelToRGB(XStandardColormap *pMap, XColor *pColor);
230 
231 
243 void PXM_RGBToPixel(XStandardColormap *pMap, XColor *pColor);
244 
245 
258 void PXM_RegisterAppIcons(char *ppRegAppLarge[], char *ppRegAppSmall[]);
259 
260 
273 int PXM_RegisterPixmapResource(Atom aResource, char *ppResource[]);
274 
275 
276 
290 Pixmap PXM_GetIconPixmap(int idIcon, XPM_ATTRIBUTES *pAttr, Pixmap *pMask /* = NULL*/);
291 
292 
306 Pixmap PXM_GetIconPixmapFromAtom(Atom aIcon, XPM_ATTRIBUTES *pAttr, Pixmap *pMask /* = NULL*/);
307 
308 
309 
325 Pixmap PXM_LoadPixmap(char *ppXPM[], XPM_ATTRIBUTES *pAttr, Pixmap *pMask /* = NULL*/);
326 
327 
328 
348 Pixmap PXM_ImageToPixmap(Display *pDisplay, Drawable dw, XImage *pImage,
349  unsigned long clrFGPixel, unsigned long clrBGPixel);
350 
351 
352 
371 Pixmap PXM_ImageToPixmap0(Display *pDisplay, Drawable dw, XImage *pImage);
372 
373 
374 
392 XImage *PXM_PixmapToImage(Display *pDisplay, Pixmap pxImage);
393 
394 
395 
396 
404 void PXM_OnExit(void);
405 
406 
407 //--------------------
408 // HELPERS FOR XImage
409 //--------------------
410 
411 
423 static __inline void *PXM_GetImageDataPtr(XImage *pImage)
424 {
425  return pImage->data;
426 }
427 
439 static __inline unsigned long PXM_GetImageDataLength(XImage *pImage)
440 {
441  if(pImage->depth <= 1)
442  {
443  return (unsigned long)pImage->bytes_per_line * (unsigned long)pImage->height; // TODO: is this right?
444  }
445 
446  return (unsigned long)pImage->bytes_per_line * (unsigned long)pImage->height
447  * (unsigned long)pImage->depth;
448 }
449 
450 
451 #ifdef __cplusplus
452 };
453 #endif // __cplusplus
454 
455 #endif // _PIXMAP_HELPER_H_
456 
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 unsigned long PXM_GetImageDataLength(XImage *pImage)
Returns the length of XImage data.
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.
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 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.
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.