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> |
| 29 | #include <rfb/ColourMap.h> |
| 30 | #include <rfb/Rect.h> |
| 31 | #include <rfb/Pixel.h> |
| 32 | |
| 33 | namespace rfb { |
| 34 | |
| 35 | class Region; |
| 36 | |
| 37 | class PixelBuffer : public ImageGetter { |
| 38 | public: |
| 39 | PixelBuffer(const PixelFormat& pf, int width, int height, ColourMap* cm); |
| 40 | virtual ~PixelBuffer(); |
| 41 | |
| 42 | /////////////////////////////////////////////// |
| 43 | // Format / Layout |
| 44 | // |
| 45 | |
| 46 | // Set/get pixel format & colourmap |
| 47 | virtual void setPF(const PixelFormat &pf); |
| 48 | virtual const PixelFormat &getPF() const; |
| 49 | virtual ColourMap* getColourMap() const; |
| 50 | |
| 51 | // Get width, height and number of pixels |
| 52 | int width() const { return width_; } |
| 53 | int height() const { return height_; } |
| 54 | int area() const { return width_ * height_; } |
| 55 | |
| 56 | // Get rectangle encompassing this buffer |
| 57 | // Top-left of rectangle is either at (0,0), or the specified point. |
| 58 | Rect getRect() const { return Rect(0, 0, width_, height_); } |
| 59 | Rect getRect(const Point& pos) const { |
| 60 | return Rect(pos, pos.translate(Point(width_, height_))); |
| 61 | } |
| 62 | |
| 63 | /////////////////////////////////////////////// |
| 64 | // Access to pixel data |
| 65 | // |
| 66 | |
| 67 | // Get a pointer into the buffer |
| 68 | // The pointer is to the top-left pixel of the specified Rect. |
| 69 | // The buffer stride (in pixels) is returned. |
| 70 | virtual const rdr::U8* getPixelsR(const Rect& r, int* stride) = 0; |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 71 | virtual rdr::U8* getPixelsRW(const Rect& r, int* stride) = 0; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 72 | |
| 73 | // Get pixel data for a given part of the buffer |
| 74 | // Data is copied into the supplied buffer, with the specified |
| 75 | // stride. |
| 76 | virtual void getImage(void* imageBuf, const Rect& r, int stride=0); |
| 77 | |
| 78 | // Get the data at (x,y) as a Pixel. |
| 79 | // VERY INEFFICIENT!!! |
| 80 | // *** Pixel getPixel(const Point& p); |
| 81 | |
| 82 | /////////////////////////////////////////////// |
| 83 | // Framebuffer update methods |
| 84 | // |
| 85 | |
| 86 | // Ensure that the specified rectangle of buffer is up to date. |
| 87 | // Overridden by derived classes implementing framebuffer access |
| 88 | // to copy the required display data into place. |
| 89 | virtual void grabRegion(const Region& region) {} |
| 90 | |
| 91 | protected: |
| 92 | PixelBuffer(); |
| 93 | PixelFormat format; |
| 94 | int width_, height_; |
| 95 | ColourMap* colourmap; |
| 96 | }; |
| 97 | |
| 98 | // FullFramePixelBuffer |
| 99 | |
| 100 | class FullFramePixelBuffer : public PixelBuffer { |
| 101 | public: |
| 102 | FullFramePixelBuffer(const PixelFormat& pf, int width, int height, |
| 103 | rdr::U8* data_, ColourMap* cm); |
| 104 | virtual ~FullFramePixelBuffer(); |
| 105 | |
| 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 |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 111 | rdr::U8* getPixelsRW(const Rect& r, int* stride); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 112 | virtual const rdr::U8* getPixelsR(const Rect& r, int* stride) { |
| 113 | return getPixelsRW(r, stride); |
| 114 | } |
| 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 | |
| 160 | // Assign a colour map to the buffer |
| 161 | virtual void setColourMap(ColourMap* cm, bool own_cm); |
| 162 | |
| 163 | // Return the total number of bytes of pixel data in the buffer |
| 164 | int dataLen() const { return width_ * height_ * (format.bpp/8); } |
| 165 | |
| 166 | protected: |
| 167 | unsigned long datasize; |
| 168 | bool own_colourmap; |
| 169 | void checkDataSize(); |
| 170 | }; |
| 171 | |
| 172 | }; |
| 173 | |
| 174 | #endif // __RFB_PIXEL_BUFFER_H__ |