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 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. virtual const char *className() const {
  35. return "Image";
  36. }
  37. virtual const char *classDesc() const {
  38. return "basic Xlib image";
  39. }
  40. virtual void get(Window wnd, int x = 0, int y = 0);
  41. virtual void get(Window wnd, int x, int y, int w, int h,
  42. int dst_x = 0, int dst_y = 0);
  43. // Copying pixels from one image to another.
  44. virtual void updateRect(XImage *src, int dst_x = 0, int dst_y = 0);
  45. virtual void updateRect(Image *src, int dst_x = 0, int dst_y = 0);
  46. virtual void updateRect(XImage *src, int dst_x, int dst_y, int w, int h);
  47. virtual void updateRect(Image *src, int dst_x, int dst_y, int w, int h);
  48. virtual void updateRect(XImage *src, int dst_x, int dst_y,
  49. int src_x, int src_y, int w, int h);
  50. virtual void updateRect(Image *src, int dst_x, int dst_y,
  51. int src_x, int src_y, int w, int h);
  52. // Pointer to corresponding XImage, made public for efficiency.
  53. // NOTE: if this field is NULL, then no methods other than Init()
  54. // may be called.
  55. XImage *xim;
  56. // Get a pointer to the data corresponding to the given coordinates.
  57. inline char *locatePixel(int x, int y) const {
  58. return (xim->data +
  59. y * xim->bytes_per_line +
  60. x * (xim->bits_per_pixel / 8));
  61. }
  62. protected:
  63. void Init(int width, int height);
  64. // Like updateRect(), but does not check arguments.
  65. void copyPixels(XImage *src,
  66. int dst_x, int dst_y,
  67. int src_x, int src_y,
  68. int w, int h);
  69. Display *dpy;
  70. };
  71. //
  72. // ShmImage uses MIT-SHM extension of an X server to get image data.
  73. //
  74. #include <X11/extensions/XShm.h>
  75. class ShmImage : public Image {
  76. public:
  77. ShmImage(Display *d);
  78. ShmImage(Display *d, int width, int height);
  79. virtual ~ShmImage();
  80. virtual const char *className() const {
  81. return "ShmImage";
  82. }
  83. virtual const char *classDesc() const {
  84. return "shared memory image";
  85. }
  86. virtual void get(Window wnd, int x = 0, int y = 0);
  87. virtual void get(Window wnd, int x, int y, int w, int h,
  88. int dst_x = 0, int dst_y = 0);
  89. protected:
  90. void Init(int width, int height, const XVisualInfo *vinfo = NULL);
  91. XShmSegmentInfo *shminfo;
  92. };
  93. //
  94. // ImageFactory class is used to produce instances of Image-derived
  95. // objects that are most appropriate for current X server and user
  96. // settings.
  97. //
  98. class ImageFactory {
  99. public:
  100. ImageFactory(bool allowShm);
  101. virtual ~ImageFactory();
  102. bool isShmAllowed() { return mayUseShm; }
  103. virtual Image *newImage(Display *d, int width, int height);
  104. protected:
  105. bool mayUseShm;
  106. };
  107. #endif // __IMAGE_H__