Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | // -=- PixelBuffer.h |
| 20 | // |
| 21 | // The PixelBuffer class encapsulates the PixelFormat and dimensions |
| 22 | // of a block of pixel data. |
| 23 | |
| 24 | #ifndef __RFB_PIXEL_BUFFER_H__ |
| 25 | #define __RFB_PIXEL_BUFFER_H__ |
| 26 | |
| 27 | #include <rfb/ImageGetter.h> |
| 28 | #include <rfb/PixelFormat.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 29 | #include <rfb/Rect.h> |
| 30 | #include <rfb/Pixel.h> |
| 31 | |
| 32 | namespace rfb { |
| 33 | |
| 34 | class Region; |
| 35 | |
| 36 | class PixelBuffer : public ImageGetter { |
| 37 | public: |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 38 | PixelBuffer(const PixelFormat& pf, int width, int height); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 39 | virtual ~PixelBuffer(); |
| 40 | |
| 41 | /////////////////////////////////////////////// |
| 42 | // Format / Layout |
| 43 | // |
| 44 | |
| 45 | // Set/get pixel format & colourmap |
Pierre Ossman | 1ed4d50 | 2014-01-07 15:28:45 +0000 | [diff] [blame] | 46 | protected: |
| 47 | // Only for subclasses that support changing parameters |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 48 | virtual void setPF(const PixelFormat &pf); |
Pierre Ossman | 1ed4d50 | 2014-01-07 15:28:45 +0000 | [diff] [blame] | 49 | public: |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 50 | virtual const PixelFormat &getPF() const; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 51 | |
| 52 | // Get width, height and number of pixels |
| 53 | int width() const { return width_; } |
| 54 | int height() const { return height_; } |
| 55 | int area() const { return width_ * height_; } |
| 56 | |
| 57 | // Get rectangle encompassing this buffer |
| 58 | // Top-left of rectangle is either at (0,0), or the specified point. |
| 59 | Rect getRect() const { return Rect(0, 0, width_, height_); } |
| 60 | Rect getRect(const Point& pos) const { |
| 61 | return Rect(pos, pos.translate(Point(width_, height_))); |
| 62 | } |
| 63 | |
| 64 | /////////////////////////////////////////////// |
| 65 | // Access to pixel data |
| 66 | // |
| 67 | |
| 68 | // Get a pointer into the buffer |
| 69 | // The pointer is to the top-left pixel of the specified Rect. |
| 70 | // The buffer stride (in pixels) is returned. |
Pierre Ossman | 945cdda | 2014-01-28 14:13:12 +0100 | [diff] [blame] | 71 | virtual const rdr::U8* getBuffer(const Rect& r, int* stride) = 0; |
| 72 | virtual rdr::U8* getBufferRW(const Rect& r, int* stride) = 0; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 73 | |
| 74 | // Get pixel data for a given part of the buffer |
| 75 | // Data is copied into the supplied buffer, with the specified |
| 76 | // stride. |
| 77 | virtual void getImage(void* imageBuf, const Rect& r, int stride=0); |
| 78 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 79 | /////////////////////////////////////////////// |
| 80 | // Framebuffer update methods |
| 81 | // |
| 82 | |
| 83 | // Ensure that the specified rectangle of buffer is up to date. |
| 84 | // Overridden by derived classes implementing framebuffer access |
| 85 | // to copy the required display data into place. |
| 86 | virtual void grabRegion(const Region& region) {} |
| 87 | |
| 88 | protected: |
| 89 | PixelBuffer(); |
| 90 | PixelFormat format; |
| 91 | int width_, height_; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | // FullFramePixelBuffer |
| 95 | |
| 96 | class FullFramePixelBuffer : public PixelBuffer { |
| 97 | public: |
| 98 | FullFramePixelBuffer(const PixelFormat& pf, int width, int height, |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 99 | rdr::U8* data_); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 100 | virtual ~FullFramePixelBuffer(); |
| 101 | |
Pierre Ossman | 1ed4d50 | 2014-01-07 15:28:45 +0000 | [diff] [blame] | 102 | protected: |
| 103 | virtual void setPF(const PixelFormat &pf); |
| 104 | |
| 105 | public: |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 106 | // - Get the number of pixels per row in the actual pixel buffer data area |
| 107 | // This may in some cases NOT be the same as width(). |
| 108 | virtual int getStride() const; |
| 109 | |
| 110 | // Get a pointer to specified pixel data |
Pierre Ossman | 945cdda | 2014-01-28 14:13:12 +0100 | [diff] [blame] | 111 | virtual const rdr::U8* getBuffer(const Rect& r, int* stride) { |
| 112 | return getBufferRW(r, stride); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 113 | } |
Pierre Ossman | 945cdda | 2014-01-28 14:13:12 +0100 | [diff] [blame] | 114 | virtual rdr::U8* getBufferRW(const Rect& r, int* stride); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 115 | |
| 116 | /////////////////////////////////////////////// |
| 117 | // Basic rendering operations |
| 118 | // These operations DO NOT clip to the pixelbuffer area, or trap overruns. |
| 119 | |
| 120 | // Fill a rectangle |
| 121 | virtual void fillRect(const Rect &dest, Pixel pix); |
| 122 | |
| 123 | // Copy pixel data to the buffer |
| 124 | virtual void imageRect(const Rect &dest, const void* pixels, int stride=0); |
| 125 | |
| 126 | // Copy pixel data from one PixelBuffer location to another |
| 127 | virtual void copyRect(const Rect &dest, const Point &move_by_delta); |
| 128 | |
| 129 | // Copy pixel data to the buffer through a mask |
| 130 | // pixels is a pointer to the pixel to be copied to r.tl. |
| 131 | // maskPos specifies the pixel offset in the mask to start from. |
| 132 | // mask_ is a pointer to the mask bits at (0,0). |
| 133 | // pStride and mStride are the strides of the pixel and mask buffers. |
| 134 | virtual void maskRect(const Rect& r, const void* pixels, const void* mask_); |
| 135 | |
| 136 | // pixel is the Pixel value to be used where mask_ is set |
| 137 | virtual void maskRect(const Rect& r, Pixel pixel, const void* mask_); |
| 138 | |
| 139 | // *** Should this be visible? |
| 140 | rdr::U8* data; |
| 141 | |
| 142 | protected: |
| 143 | FullFramePixelBuffer(); |
DRC | 4f24c1a | 2011-11-03 23:56:10 +0000 | [diff] [blame] | 144 | void (*fillRectFn)(rdr::U8 *, int, const Rect&, Pixel); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | // -=- Managed pixel buffer class |
| 148 | // Automatically allocates enough space for the specified format & area |
| 149 | |
| 150 | class ManagedPixelBuffer : public FullFramePixelBuffer { |
| 151 | public: |
| 152 | ManagedPixelBuffer(); |
| 153 | ManagedPixelBuffer(const PixelFormat& pf, int width, int height); |
| 154 | virtual ~ManagedPixelBuffer(); |
| 155 | |
| 156 | // Manage the pixel buffer layout |
| 157 | virtual void setPF(const PixelFormat &pf); |
| 158 | virtual void setSize(int w, int h); |
| 159 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 160 | // Return the total number of bytes of pixel data in the buffer |
| 161 | int dataLen() const { return width_ * height_ * (format.bpp/8); } |
| 162 | |
| 163 | protected: |
| 164 | unsigned long datasize; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 165 | void checkDataSize(); |
| 166 | }; |
| 167 | |
| 168 | }; |
| 169 | |
| 170 | #endif // __RFB_PIXEL_BUFFER_H__ |