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-2019 by Bob Frazier (aka 'Big Bad Bombastic Bob')
17 
18  DISCLAIMER: The X11workbench application and toolkit software are supplied
19  'as-is', with no warranties, either implied or explicit.
20  Any claims to alleged functionality or features should be
21  considered 'preliminary', and might not function as advertised.
22 
23  MIT-like license:
24 
25  There is no restriction as to what you can do with this software, so long
26  as you include the above copyright notice and DISCLAIMER for any distributed
27  work that is equal to or derived from this one, along with this paragraph
28  that explains the terms of the license if the source is also being made
29  available. A "derived work" describes a work that uses a significant portion
30  of the source files or algorithms that are included with this one.
31  Specifically excluded from this are files that were generated by the software,
32  or anything that is included with the software that is part of another package
33  (such as files that were created or added during the 'configure' process).
34  Specifically included is the use of part or all of any of the X11 workbench
35  toolkit source or header files in your distributed application. If you do not
36  ship the source, the above copyright statement is still required to be placed
37  in a reasonably prominent place, such as documentation, splash screens, and/or
38  'about the application' dialog boxes.
39 
40  Use and distribution are in accordance with GPL, LGPL, and/or the above
41  MIT-like license. See COPYING and README files for more information.
42 
43 
44  Additional information at http://sourceforge.net/projects/X11workbench
45 
46 ******************************************************************************/
47 
48 
49 #ifndef _PIXMAP_HELPER_H_
50 #define _PIXMAP_HELPER_H_
51 
52 #include "window_helper.h" // if not already included, I must include this
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif // __cplusplus
57 
58 
59 #define ID_ICON_FIRST 101
60 #define ID_APPLICATION 101 /* 19x19 application icon */
61 #define ID_ICON_OK 102
62 #define ID_ICON_STOP 103
63 #define ID_ICON_WARN 104 /* yellow triangle, ! */
64 #define ID_ICON_WHAT 105
65 #define ID_ICON_QUESTION 105
66 #define ID_ICON_SPLAT 106
67 #define ID_ICON_ASTERISK 106
68 #define ID_ICON_BANG 107 /* yellow circle, ! */
69 #define ID_ICON_TRIANGLE 108
70 #define ID_ICON_WHAT_BOLD 109
71 #define ID_ICON_WTF 110
72 #define ID_ICON_DEATH 111
73 #define ID_ICON_FINGER 112
74 #define ID_ICON_SKULL 113
75 #define ID_ICON_THUMBUP 114
76 #define ID_ICON_THUMBDOWN 115
77 #define ID_ICON_BEAR 116
78 #define ID_ICON_BARNEY 117
79 #define ID_ICON_APP 118 /* 36x36 application icon */
80 #define ID_ICON_LAST 118 /* must alter this if new items added */
81 
82 
94 #define RGB255_TO_XCOLOR(R,G,B,X) { (X).red = ((unsigned int)(R) << 8) & 0xffff; \
95  (X).green = ((unsigned int)(G) << 8) & 0xffff; \
96  (X).blue = ((unsigned int)(B) << 8) & 0xffff; \
97  (X).flags = DoRed | DoGreen | DoBlue; }
98 
110 #define RGB_TO_XCOLOR(R,G,B,X) { (X).red = ((unsigned int)(R)) & 0xffff; \
111  (X).green = ((unsigned int)(G)) & 0xffff; \
112  (X).blue = ((unsigned int)(B)) & 0xffff; \
113  (X).flags = DoRed | DoGreen | DoBlue; }
114 
115 
129 #define RGB255_FROM_XCOLOR(X,R,G,B) {register unsigned short __iR,__iG,__iB; RGB_FROM_XCOLOR(X,__iR, __iG, __iB); \
130  if(__iR < 0xff80){ __iR += 0x80; } \
131  if(__iG < 0xff80){ __iG += 0x80; } \
132  if(__iB < 0xff80){ __iB += 0x80; } \
133  __iR = __iR >> 8; __iG = __iG >> 8; __iB = __iB >> 8; \
134  __iR &= 0xff; __iG &= 0xff; __iB &= 0xff; \
135  (R) = __iR; (G) = __iG; (B) = __iB; }
136 
150 #define RGB_FROM_XCOLOR(X,R,G,B) { (R) = (((X).flags) & DoRed) ? ((unsigned int)(X).red) & 0xffff : 0; \
151  (G) = (((X).flags) & DoGreen) ? ((unsigned int)(X).green) & 0xffff : 0; \
152  (B) = (((X).flags) & DoBlue) ? ((unsigned int)(X).blue) & 0xffff : 0; }
153 
154 
162 void PXM_OnExit(void);
163 
164 
179 static __inline__ XStandardColormap *PXM_StandardColormapFromColormap(Display *pDisplay, Colormap colormap)
180 {
181 extern XStandardColormap PXM_StandardColormapFromColormap_rval; // declare extern rather than static, for single mem spot
182 
183  if(!pDisplay)
184  {
185  pDisplay = WBGetDefaultDisplay();
186  }
187 
188  WBDefaultStandardColormap(pDisplay, &PXM_StandardColormapFromColormap_rval);
189 
190  PXM_StandardColormapFromColormap_rval.colormap = colormap;
191 
192  return &PXM_StandardColormapFromColormap_rval;
193 }
194 
223 void PXM_RGBToYUV(int iR, int iG, int iB, int *piY, int *piU, int *piV);
224 
225 
243 void PXM_RGBToHSV(int iR, int iG, int iB, int *piH, int *piS, int *piV);
244 
245 
274 void PXM_YUVToRGB(int iY, int iU, int iV, int *piR, int *piG, int *piB);
275 
276 
294 void PXM_HSVToRGB(int iH, int iS, int iV, int *piR, int *piG, int *piB);
295 
296 
308 void PXM_PixelToRGB(XStandardColormap *pMap, XColor *pColor);
309 
310 
322 void PXM_RGBToPixel(XStandardColormap *pMap, XColor *pColor);
323 
324 
337 void PXM_RegisterAppIcons(char *ppRegAppLarge[], char *ppRegAppSmall[]);
338 
339 
352 int PXM_RegisterPixmapResource(Atom aResource, char *ppResource[]);
353 
354 
355 
369 Pixmap PXM_GetIconPixmap(int idIcon, XPM_ATTRIBUTES *pAttr, Pixmap *pMask /* = NULL*/);
370 
371 
385 Pixmap PXM_GetIconPixmapFromAtom(Atom aIcon, XPM_ATTRIBUTES *pAttr, Pixmap *pMask /* = NULL*/);
386 
387 
388 
404 Pixmap PXM_LoadPixmap(char *ppXPM[], XPM_ATTRIBUTES *pAttr, Pixmap *pMask /* = NULL*/);
405 
406 
407 
427 Pixmap PXM_ImageToPixmap(Display *pDisplay, Drawable dw, XImage *pImage,
428  unsigned long clrFGPixel, unsigned long clrBGPixel);
429 
430 
431 
450 Pixmap PXM_ImageToPixmap0(Display *pDisplay, Drawable dw, XImage *pImage);
451 
452 
453 
471 XImage *PXM_PixmapToImage(Display *pDisplay, Pixmap pxImage);
472 
473 
475 // _ _ _ //
476 // | | ___ __ __ | | ___ __ __ ___ | | //
477 // | | / _ \\ \ /\ / /_____ | | / _ \\ \ / // _ \| | //
478 // | |___| (_) |\ V V /|_____|| |___| __/ \ V /| __/| | //
479 // |_____|\___/ \_/\_/ |_____|\___| \_/ \___||_| //
480 // //
482 
483 
500 Pixmap PXM_CreatePixmap(Display *pDisplay, Drawable dw, unsigned int width,
501  unsigned int height, unsigned int depth);
502 
516 int PXM_FreePixmap(Display *pDisplay, Pixmap pxImage);
517 
518 
534 Pixmap PXM_CopyPixmap(Display *pDisplay, Drawable dw, Pixmap pxImage);
535 
536 
537 
538 
539 
541 // __ __ _ _ _____ _ _ //
542 // \ \/ // |/ | | ____|__ __| |_ ___ _ __ ___ (_) ___ _ __ ___ //
543 // \ / | || | | _| \ \/ /| __|/ _ \| '_ \ / __|| | / _ \ | '_ \ / __| //
544 // / \ | || | | |___ > < | |_| __/| | | |\__ \| || (_) || | | |\__ \ //
545 // /_/\_\|_||_| |_____|/_/\_\ \__|\___||_| |_||___/|_| \___/ |_| |_||___/ //
546 // //
548 
549 #if defined(X11WORKBENCH_TOOLKIT_HAVE_XSHM_EXTENSION) || defined(__DOXYGEN__)
550 
561 int WBXShmQueryExtension(Display *pDisplay);
562 
563 #else // !X11WORKBENCH_TOOLKIT_HAVE_XSHM_EXTENSION
564 
565 #define WBXShmQueryExtension(X) (0)
566 
567 #endif // X11WORKBENCH_TOOLKIT_HAVE_XSHM_EXTENSION, __DOXYGEN__
568 
569 
570 
572 // __ __ ___ ____ _ //
573 // \ \/ /|_ _| _ __ ___ __ _ __ _ ___ / ___| _ _ _ __ _ __ ___ _ __ | |_ //
574 // \ / | | | '_ ` _ \ / _` | / _` | / _ \ \___ \ | | | || '_ \ | '_ \ / _ \ | '__|| __| //
575 // / \ | | | | | | | || (_| || (_| || __/ ___) || |_| || |_) || |_) || (_) || | | |_ //
576 // /_/\_\|___||_| |_| |_| \__,_| \__, | \___| |____/ \__,_|| .__/ | .__/ \___/ |_| \__| //
577 // |___/ |_| |_| //
579 
580 
600 int WBXPutImage(Display *pDisplay, Drawable dw, WBGC gc, XImage *pImage,
601  int src_x, int src_y, int dest_x, int dest_y,
602  unsigned int width, unsigned int height);
603 
625 XImage *WBXGetImage(Display *pDisplay, Drawable dw,
626  int x, int y, unsigned int width, unsigned int height,
627  unsigned long plane_mask, int format);
628 
642 int WBXDestroyImage(XImage *pImage);
643 
644 
656 XImage * WBXCopyImage(Display *pDisplay, XImage *pImage);
657 
658 
659 
661 // __ __ ___ ____ _ _ //
662 // \ \/ /|_ _| _ __ ___ __ _ __ _ ___ / ___| _ __ __ _ _ __ | |__ (_) ___ ___ //
663 // \ / | | | '_ ` _ \ / _` | / _` | / _ \ | | _ | '__|/ _` || '_ \ | '_ \ | | / __|/ __| //
664 // / \ | | | | | | | || (_| || (_| || __/ | |_| || | | (_| || |_) || | | || || (__ \__ \ //
665 // /_/\_\|___||_| |_| |_| \__,_| \__, | \___| \____||_| \__,_|| .__/ |_| |_||_| \___||___/ //
666 // |___/ |_| //
668 
669 
681 Region WBXImageToRegion(const XImage *pImage);
682 
683 
699 XImage * WBXImageFromRegion(Region rgnSource, int width, int height);
700 
701 
720 int WBXDrawPoint(XImage *pImage, WBGC hGC, int x, int y);
721 
722 
742 int WBXDrawPoints(XImage *pImage, WBGC hGC,
743  XPoint *points, int npoints, int mode);
744 
745 
766 int WBXDrawLine(XImage *pImage, WBGC hGC,
767  int x1, int y1, int x2, int y2);
768 
769 
789 int WBXDrawLines(XImage *pImage, WBGC hGC,
790  XPoint *points, int npoints, int mode);
791 
792 
813 int WBXDrawRectangle(XImage *pImage, WBGC hGC,
814  int x, int y, unsigned int width, unsigned int height);
815 
816 
837 int WBXFillRectangle(XImage *pImage, WBGC hGC,
838  int x, int y, unsigned int width, unsigned int height);
839 
840 
863 int WBXDrawArc(XImage *pImage, WBGC hGC,
864  int x, int y, unsigned int width, unsigned int height,
865  int angle1, int angle2);
866 
867 
890 int WBXFillArc(XImage *pImage, WBGC hGC,
891  int x, int y, unsigned int width, unsigned int height,
892  int angle1, int angle2);
893 
894 
915 int WBXFillPolygon(XImage *pImage, WBGC hGC,
916  XPoint *points, int npoints, int shape, int mode);
917 
918 
940 int WBXDrawString(XImage *pImage, WB_FONTC pFont, WBGC hGC,
941  int x, int y, const char *string, int length);
942 
943 
944 
945 
946 
947 
948 //-------------------
949 // HELPERS FOR XColor
950 //-------------------
951 
962 void WBDebugDumpXColor(const char *szTitle, const XColor *pColor);
963 
974 void WBDebugDumpColormap(const char *szTitle, const XStandardColormap *pMap);
975 
976 
977 //--------------------
978 // HELPERS FOR XImage
979 //--------------------
980 
981 
993 static __inline__ void *PXM_GetImageDataPtr(XImage *pImage)
994 {
995  return pImage->data;
996 }
997 
1009 static __inline__ unsigned long PXM_GetImageDataLength(XImage *pImage)
1010 {
1011  if(pImage->depth <= 1)
1012  {
1013  return (unsigned long)pImage->bytes_per_line * (unsigned long)pImage->height; // TODO: is this right?
1014  }
1015 
1016  return (unsigned long)pImage->bytes_per_line * (unsigned long)pImage->height
1017  * (unsigned long)pImage->depth;
1018 }
1019 
1037 void WBSimpleAntiAliasPixmap(Display *pDisplay, const XStandardColormap *pMap, Pixmap pxImage,
1038  unsigned long lPixel, WB_GEOM *pGeom);
1039 
1056 void WBSimpleAntiAliasImage(const XStandardColormap *pMap, XImage *pImage, unsigned long lPixel, WB_GEOM *pGeom);
1057 
1058 
1059 
1069 unsigned char WB_isqrt(unsigned char iVal);
1070 
1080 unsigned char WB_icos0(unsigned char iVal);
1081 
1091 char WB_icos(int iVal);
1092 
1102 #define WB_isin(X) WB_icos((X) - 256) /* subtract 256, i.e. pi/2 radians, to convert a cos to a sin */
1103 
1104 
1105 
1106 
1107 #ifdef __cplusplus
1108 };
1109 #endif // __cplusplus
1110 
1111 #endif // _PIXMAP_HELPER_H_
1112 
int WBXDrawArc(XImage *pImage, WBGC hGC, int x, int y, unsigned int width, unsigned int height, int angle1, int angle2)
XImage version for XDrawArc()
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.
'window helper' main header file for the X11workbench Toolkit API
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
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.
int PXM_FreePixmap(Display *pDisplay, Pixmap pxImage)
Wrapper for XCreatePixmap()
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.
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()
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.
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 PXM_RegisterPixmapResource(Atom aResource, char *ppResource[])
Register an icon (or pixmap) resource using an Atom.
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 WBDebugDumpXColor(const char *szTitle, const XColor *pColor)
Dump XColor members for debugging.
static __inline__ void * PXM_GetImageDataPtr(XImage *pImage)
Returns pointer to XImage data.
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()
int WBXDrawPoints(XImage *pImage, WBGC hGC, XPoint *points, int npoints, int mode)
XImage version for XDrawPoints()
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
Pixmap PXM_ImageToPixmap0(Display *pDisplay, Drawable dw, XImage *pImage)
Convert 'locally stored' XImage to 'server object' Pixmap using default FG/BG colors for monochrome.
int WBXDrawLines(XImage *pImage, WBGC hGC, XPoint *points, int npoints, int mode)
XImage version for XDrawLine()
An allocated structure containing XFontStruct, XFontInfo, and XftFont [as applicable] for a specified...
Definition: font_helper.h:152
internal wrapper struct for GC with local cache
Pixmap PXM_CopyPixmap(Display *pDisplay, Drawable dw, Pixmap pxImage)
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()
Pixmap PXM_CreatePixmap(Display *pDisplay, Drawable dw, unsigned int width, unsigned int height, unsigned int depth)
Wrapper for XCreatePixmap()
Region WBXImageToRegion(const XImage *pImage)
Create a Region from an XImage.