blob: e870622e18bc3100f72df561f42d1fa1d55ba942 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* 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
33namespace 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
Pierre Ossman1ed4d502014-01-07 15:28:45 +000047 protected:
48 // Only for subclasses that support changing parameters
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000049 virtual void setPF(const PixelFormat &pf);
Pierre Ossman1ed4d502014-01-07 15:28:45 +000050 public:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000051 virtual const PixelFormat &getPF() const;
52 virtual ColourMap* getColourMap() const;
53
54 // Get width, height and number of pixels
55 int width() const { return width_; }
56 int height() const { return height_; }
57 int area() const { return width_ * height_; }
58
59 // Get rectangle encompassing this buffer
60 // Top-left of rectangle is either at (0,0), or the specified point.
61 Rect getRect() const { return Rect(0, 0, width_, height_); }
62 Rect getRect(const Point& pos) const {
63 return Rect(pos, pos.translate(Point(width_, height_)));
64 }
65
66 ///////////////////////////////////////////////
67 // Access to pixel data
68 //
69
70 // Get a pointer into the buffer
71 // The pointer is to the top-left pixel of the specified Rect.
72 // The buffer stride (in pixels) is returned.
73 virtual const rdr::U8* getPixelsR(const Rect& r, int* stride) = 0;
DRCffe09d62011-08-17 02:27:59 +000074 virtual rdr::U8* getPixelsRW(const Rect& r, int* stride) = 0;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000075
76 // Get pixel data for a given part of the buffer
77 // Data is copied into the supplied buffer, with the specified
78 // stride.
79 virtual void getImage(void* imageBuf, const Rect& r, int stride=0);
80
81 // Get the data at (x,y) as a Pixel.
82 // VERY INEFFICIENT!!!
83 // *** Pixel getPixel(const Point& p);
84
85 ///////////////////////////////////////////////
86 // Framebuffer update methods
87 //
88
89 // Ensure that the specified rectangle of buffer is up to date.
90 // Overridden by derived classes implementing framebuffer access
91 // to copy the required display data into place.
92 virtual void grabRegion(const Region& region) {}
93
94 protected:
95 PixelBuffer();
96 PixelFormat format;
97 int width_, height_;
98 ColourMap* colourmap;
99 };
100
101 // FullFramePixelBuffer
102
103 class FullFramePixelBuffer : public PixelBuffer {
104 public:
105 FullFramePixelBuffer(const PixelFormat& pf, int width, int height,
106 rdr::U8* data_, ColourMap* cm);
107 virtual ~FullFramePixelBuffer();
108
Pierre Ossman1ed4d502014-01-07 15:28:45 +0000109 protected:
110 virtual void setPF(const PixelFormat &pf);
111
112 public:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000113 // - Get the number of pixels per row in the actual pixel buffer data area
114 // This may in some cases NOT be the same as width().
115 virtual int getStride() const;
116
117 // Get a pointer to specified pixel data
DRCffe09d62011-08-17 02:27:59 +0000118 rdr::U8* getPixelsRW(const Rect& r, int* stride);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000119 virtual const rdr::U8* getPixelsR(const Rect& r, int* stride) {
120 return getPixelsRW(r, stride);
121 }
122
123 ///////////////////////////////////////////////
124 // Basic rendering operations
125 // These operations DO NOT clip to the pixelbuffer area, or trap overruns.
126
127 // Fill a rectangle
128 virtual void fillRect(const Rect &dest, Pixel pix);
129
130 // Copy pixel data to the buffer
131 virtual void imageRect(const Rect &dest, const void* pixels, int stride=0);
132
133 // Copy pixel data from one PixelBuffer location to another
134 virtual void copyRect(const Rect &dest, const Point &move_by_delta);
135
136 // Copy pixel data to the buffer through a mask
137 // pixels is a pointer to the pixel to be copied to r.tl.
138 // maskPos specifies the pixel offset in the mask to start from.
139 // mask_ is a pointer to the mask bits at (0,0).
140 // pStride and mStride are the strides of the pixel and mask buffers.
141 virtual void maskRect(const Rect& r, const void* pixels, const void* mask_);
142
143 // pixel is the Pixel value to be used where mask_ is set
144 virtual void maskRect(const Rect& r, Pixel pixel, const void* mask_);
145
146 // *** Should this be visible?
147 rdr::U8* data;
148
149 protected:
150 FullFramePixelBuffer();
DRC4f24c1a2011-11-03 23:56:10 +0000151 void (*fillRectFn)(rdr::U8 *, int, const Rect&, Pixel);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000152 };
153
154 // -=- Managed pixel buffer class
155 // Automatically allocates enough space for the specified format & area
156
157 class ManagedPixelBuffer : public FullFramePixelBuffer {
158 public:
159 ManagedPixelBuffer();
160 ManagedPixelBuffer(const PixelFormat& pf, int width, int height);
161 virtual ~ManagedPixelBuffer();
162
163 // Manage the pixel buffer layout
164 virtual void setPF(const PixelFormat &pf);
165 virtual void setSize(int w, int h);
166
167 // Assign a colour map to the buffer
168 virtual void setColourMap(ColourMap* cm, bool own_cm);
169
170 // Return the total number of bytes of pixel data in the buffer
171 int dataLen() const { return width_ * height_ * (format.bpp/8); }
172
173 protected:
174 unsigned long datasize;
175 bool own_colourmap;
176 void checkDataSize();
177 };
178
179};
180
181#endif // __RFB_PIXEL_BUFFER_H__