You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Image.h 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved.
  2. * Copyright (C) 2004-2005 Constantin Kaplinsky. All Rights Reserved.
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. //
  20. // Image.h
  21. //
  22. #ifndef __IMAGE_H__
  23. #define __IMAGE_H__
  24. #include <X11/Xlib.h>
  25. #include <X11/Xutil.h>
  26. //
  27. // Image class is an Xlib-based implementation of screen image storage.
  28. //
  29. class Image {
  30. public:
  31. Image(Display *d);
  32. Image(Display *d, int width, int height);
  33. virtual ~Image();
  34. bool isTrueColor() const { return trueColor; }
  35. virtual const char *className() const {
  36. return "Image";
  37. }
  38. virtual const char *classDesc() const {
  39. return "basic Xlib image";
  40. }
  41. virtual void get(Window wnd, int x = 0, int y = 0);
  42. virtual void get(Window wnd, int x, int y, int w, int h,
  43. int dst_x = 0, int dst_y = 0);
  44. // Copying pixels from one image to another.
  45. virtual void updateRect(XImage *src, int dst_x = 0, int dst_y = 0);
  46. virtual void updateRect(Image *src, int dst_x = 0, int dst_y = 0);
  47. virtual void updateRect(XImage *src, int dst_x, int dst_y, int w, int h);
  48. virtual void updateRect(Image *src, int dst_x, int dst_y, int w, int h);
  49. virtual void updateRect(XImage *src, int dst_x, int dst_y,
  50. int src_x, int src_y, int w, int h);
  51. virtual void updateRect(Image *src, int dst_x, int dst_y,
  52. int src_x, int src_y, int w, int h);
  53. // Pointer to corresponding XImage, made public for efficiency.
  54. // NOTE: if this field is NULL, then no methods other than Init()
  55. // may be called.
  56. XImage *xim;
  57. // Get a pointer to the data corresponding to the given coordinates.
  58. inline char *locatePixel(int x, int y) const {
  59. return (xim->data +
  60. y * xim->bytes_per_line +
  61. x * (xim->bits_per_pixel / 8));
  62. }
  63. protected:
  64. void Init(int width, int height);
  65. // Like updateRect(), but does not check arguments.
  66. void copyPixels(XImage *src,
  67. int dst_x, int dst_y,
  68. int src_x, int src_y,
  69. int w, int h);
  70. Display *dpy;
  71. bool trueColor;
  72. };
  73. //
  74. // ShmImage uses MIT-SHM extension of an X server to get image data.
  75. //
  76. #ifdef HAVE_MITSHM
  77. #include <X11/extensions/XShm.h>
  78. class ShmImage : public Image {
  79. public:
  80. ShmImage(Display *d);
  81. ShmImage(Display *d, int width, int height);
  82. virtual ~ShmImage();
  83. virtual const char *className() const {
  84. return "ShmImage";
  85. }
  86. virtual const char *classDesc() const {
  87. return "shared memory image";
  88. }
  89. virtual void get(Window wnd, int x = 0, int y = 0);
  90. virtual void get(Window wnd, int x, int y, int w, int h,
  91. int dst_x = 0, int dst_y = 0);
  92. protected:
  93. void Init(int width, int height, const XVisualInfo *vinfo = NULL);
  94. XShmSegmentInfo *shminfo;
  95. };
  96. //
  97. // IrixOverlayShmImage uses ReadDisplay extension of an X server to
  98. // get truecolor image data, regardless of the default X visual type.
  99. // This method is available on Irix only.
  100. //
  101. #ifdef HAVE_READDISPLAY
  102. #include <X11/extensions/readdisplay.h>
  103. class IrixOverlayShmImage : public ShmImage {
  104. public:
  105. IrixOverlayShmImage(Display *d);
  106. IrixOverlayShmImage(Display *d, int width, int height);
  107. virtual ~IrixOverlayShmImage();
  108. virtual const char *className() const {
  109. return "IrixOverlayShmImage";
  110. }
  111. virtual const char *classDesc() const {
  112. return "IRIX-specific SHM-aware overlay image";
  113. }
  114. virtual void get(Window wnd, int x = 0, int y = 0);
  115. virtual void get(Window wnd, int x, int y, int w, int h,
  116. int dst_x = 0, int dst_y = 0);
  117. protected:
  118. void Init(int width, int height);
  119. // This method searches available X visuals for one that matches
  120. // actual pixel format returned by XReadDisplay(). Returns true on
  121. // success, false if there is no matching visual. On success, visual
  122. // information is placed into the structure pointed by vinfo_ret.
  123. bool getOverlayVisualInfo(XVisualInfo *vinfo_ret);
  124. ShmReadDisplayBuf *readDisplayBuf;
  125. };
  126. #endif // HAVE_READDISPLAY
  127. #endif // HAVE_MITSHM
  128. //
  129. // SolarisOverlayImage uses SUN_OVL extension of an X server to get
  130. // truecolor image data, regardless of the default X visual type. This
  131. // method is available on Solaris only.
  132. //
  133. #ifdef HAVE_SUN_OVL
  134. #include <X11/extensions/transovl.h>
  135. class SolarisOverlayImage : public Image {
  136. public:
  137. SolarisOverlayImage(Display *d);
  138. SolarisOverlayImage(Display *d, int width, int height);
  139. virtual ~SolarisOverlayImage();
  140. virtual const char *className() const {
  141. return "SolarisOverlayImage";
  142. }
  143. virtual const char *classDesc() const {
  144. return "Solaris-specific non-SHM overlay image";
  145. }
  146. virtual void get(Window wnd, int x = 0, int y = 0);
  147. virtual void get(Window wnd, int x, int y, int w, int h,
  148. int dst_x = 0, int dst_y = 0);
  149. protected:
  150. void Init(int width, int height);
  151. };
  152. #endif // HAVE_SUN_OVL
  153. //
  154. // ImageFactory class is used to produce instances of Image-derived
  155. // objects that are most appropriate for current X server and user
  156. // settings.
  157. //
  158. class ImageFactory {
  159. public:
  160. ImageFactory(bool allowShm, bool allowOverlay);
  161. virtual ~ImageFactory();
  162. bool isShmAllowed() { return mayUseShm; }
  163. bool isOverlayAllowed() { return mayUseOverlay; }
  164. virtual Image *newImage(Display *d, int width, int height);
  165. protected:
  166. bool mayUseShm;
  167. bool mayUseOverlay;
  168. };
  169. #endif // __IMAGE_H__