Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 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 | |
| 23 | #ifndef __IMAGE_H__ |
| 24 | #define __IMAGE_H__ |
| 25 | |
| 26 | #include <X11/Xlib.h> |
| 27 | #include <X11/Xutil.h> |
| 28 | |
| 29 | // |
| 30 | // Image class is an Xlib-based implementation of screen image storage. |
| 31 | // |
| 32 | |
| 33 | class Image { |
| 34 | |
| 35 | public: |
| 36 | |
| 37 | Image(Display *d); |
| 38 | Image(Display *d, int width, int height); |
| 39 | virtual ~Image(); |
| 40 | |
| 41 | bool isTrueColor() const { return trueColor; } |
| 42 | |
| 43 | virtual const char *className() const { |
| 44 | return "Image"; |
| 45 | } |
| 46 | virtual const char *classDesc() const { |
| 47 | return "basic Xlib image"; |
| 48 | } |
| 49 | |
| 50 | virtual void get(Window wnd, int x = 0, int y = 0); |
Constantin Kaplinsky | cffb691 | 2007-09-03 10:17:19 +0000 | [diff] [blame] | 51 | virtual void get(Window wnd, int x, int y, int w, int h, |
| 52 | int dst_x = 0, int dst_y = 0); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 53 | |
Constantin Kaplinsky | cffb691 | 2007-09-03 10:17:19 +0000 | [diff] [blame] | 54 | // Copying pixels from one image to another. |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 55 | virtual void updateRect(XImage *src, int dst_x = 0, int dst_y = 0); |
| 56 | virtual void updateRect(Image *src, int dst_x = 0, int dst_y = 0); |
| 57 | virtual void updateRect(XImage *src, int dst_x, int dst_y, int w, int h); |
| 58 | virtual void updateRect(Image *src, int dst_x, int dst_y, int w, int h); |
| 59 | virtual void updateRect(XImage *src, int dst_x, int dst_y, |
| 60 | int src_x, int src_y, int w, int h); |
| 61 | virtual void updateRect(Image *src, int dst_x, int dst_y, |
| 62 | int src_x, int src_y, int w, int h); |
| 63 | |
| 64 | // Pointer to corresponding XImage, made public for efficiency. |
| 65 | // NOTE: if this field is NULL, then no methods other than Init() |
| 66 | // may be called. |
Constantin Kaplinsky | 801123d | 2008-01-18 15:23:11 +0000 | [diff] [blame] | 67 | XImage *xim; |
| 68 | |
| 69 | // Get a pointer to the data corresponding to the given coordinates. |
| 70 | inline char *locatePixel(int x, int y) const { |
| 71 | return (xim->data + |
| 72 | y * xim->bytes_per_line + |
| 73 | x * (xim->bits_per_pixel / 8)); |
| 74 | } |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 75 | |
| 76 | protected: |
| 77 | |
| 78 | void Init(int width, int height); |
| 79 | |
| 80 | // Like updateRect(), but does not check arguments. |
| 81 | void copyPixels(XImage *src, |
| 82 | int dst_x, int dst_y, |
| 83 | int src_x, int src_y, |
| 84 | int w, int h); |
| 85 | |
| 86 | Display *dpy; |
| 87 | bool trueColor; |
| 88 | |
| 89 | }; |
| 90 | |
| 91 | // |
| 92 | // ShmImage uses MIT-SHM extension of an X server to get image data. |
| 93 | // |
| 94 | |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 95 | #include <X11/extensions/XShm.h> |
| 96 | |
| 97 | class ShmImage : public Image { |
| 98 | |
| 99 | public: |
| 100 | |
| 101 | ShmImage(Display *d); |
| 102 | ShmImage(Display *d, int width, int height); |
| 103 | virtual ~ShmImage(); |
| 104 | |
| 105 | virtual const char *className() const { |
| 106 | return "ShmImage"; |
| 107 | } |
| 108 | virtual const char *classDesc() const { |
| 109 | return "shared memory image"; |
| 110 | } |
| 111 | |
| 112 | virtual void get(Window wnd, int x = 0, int y = 0); |
Constantin Kaplinsky | cffb691 | 2007-09-03 10:17:19 +0000 | [diff] [blame] | 113 | virtual void get(Window wnd, int x, int y, int w, int h, |
| 114 | int dst_x = 0, int dst_y = 0); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 115 | |
| 116 | protected: |
| 117 | |
| 118 | void Init(int width, int height, const XVisualInfo *vinfo = NULL); |
| 119 | |
| 120 | XShmSegmentInfo *shminfo; |
| 121 | |
| 122 | }; |
| 123 | |
| 124 | // |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 125 | // ImageFactory class is used to produce instances of Image-derived |
| 126 | // objects that are most appropriate for current X server and user |
| 127 | // settings. |
| 128 | // |
| 129 | |
| 130 | class ImageFactory { |
| 131 | |
| 132 | public: |
| 133 | |
Peter Åstrand (astrand) | dcd0b13 | 2017-10-16 15:18:00 +0200 | [diff] [blame^] | 134 | ImageFactory(bool allowShm); |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 135 | virtual ~ImageFactory(); |
| 136 | |
| 137 | bool isShmAllowed() { return mayUseShm; } |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 138 | |
| 139 | virtual Image *newImage(Display *d, int width, int height); |
| 140 | |
| 141 | protected: |
| 142 | |
| 143 | bool mayUseShm; |
Constantin Kaplinsky | b30ae7f | 2006-05-25 05:04:46 +0000 | [diff] [blame] | 144 | |
| 145 | }; |
| 146 | |
| 147 | #endif // __IMAGE_H__ |