blob: 0d1526357af000efffcd41a464a6037b33559abb [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
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000081 ///////////////////////////////////////////////
82 // Framebuffer update methods
83 //
84
85 // Ensure that the specified rectangle of buffer is up to date.
86 // Overridden by derived classes implementing framebuffer access
87 // to copy the required display data into place.
88 virtual void grabRegion(const Region& region) {}
89
90 protected:
91 PixelBuffer();
92 PixelFormat format;
93 int width_, height_;
94 ColourMap* colourmap;
95 };
96
97 // FullFramePixelBuffer
98
99 class FullFramePixelBuffer : public PixelBuffer {
100 public:
101 FullFramePixelBuffer(const PixelFormat& pf, int width, int height,
102 rdr::U8* data_, ColourMap* cm);
103 virtual ~FullFramePixelBuffer();
104
Pierre Ossman1ed4d502014-01-07 15:28:45 +0000105 protected:
106 virtual void setPF(const PixelFormat &pf);
107
108 public:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000109 // - Get the number of pixels per row in the actual pixel buffer data area
110 // This may in some cases NOT be the same as width().
111 virtual int getStride() const;
112
113 // Get a pointer to specified pixel data
DRCffe09d62011-08-17 02:27:59 +0000114 rdr::U8* getPixelsRW(const Rect& r, int* stride);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000115 virtual const rdr::U8* getPixelsR(const Rect& r, int* stride) {
116 return getPixelsRW(r, stride);
117 }
118
119 ///////////////////////////////////////////////
120 // Basic rendering operations
121 // These operations DO NOT clip to the pixelbuffer area, or trap overruns.
122
123 // Fill a rectangle
124 virtual void fillRect(const Rect &dest, Pixel pix);
125
126 // Copy pixel data to the buffer
127 virtual void imageRect(const Rect &dest, const void* pixels, int stride=0);
128
129 // Copy pixel data from one PixelBuffer location to another
130 virtual void copyRect(const Rect &dest, const Point &move_by_delta);
131
132 // Copy pixel data to the buffer through a mask
133 // pixels is a pointer to the pixel to be copied to r.tl.
134 // maskPos specifies the pixel offset in the mask to start from.
135 // mask_ is a pointer to the mask bits at (0,0).
136 // pStride and mStride are the strides of the pixel and mask buffers.
137 virtual void maskRect(const Rect& r, const void* pixels, const void* mask_);
138
139 // pixel is the Pixel value to be used where mask_ is set
140 virtual void maskRect(const Rect& r, Pixel pixel, const void* mask_);
141
142 // *** Should this be visible?
143 rdr::U8* data;
144
145 protected:
146 FullFramePixelBuffer();
DRC4f24c1a2011-11-03 23:56:10 +0000147 void (*fillRectFn)(rdr::U8 *, int, const Rect&, Pixel);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000148 };
149
150 // -=- Managed pixel buffer class
151 // Automatically allocates enough space for the specified format & area
152
153 class ManagedPixelBuffer : public FullFramePixelBuffer {
154 public:
155 ManagedPixelBuffer();
156 ManagedPixelBuffer(const PixelFormat& pf, int width, int height);
157 virtual ~ManagedPixelBuffer();
158
159 // Manage the pixel buffer layout
160 virtual void setPF(const PixelFormat &pf);
161 virtual void setSize(int w, int h);
162
163 // Assign a colour map to the buffer
164 virtual void setColourMap(ColourMap* cm, bool own_cm);
165
166 // Return the total number of bytes of pixel data in the buffer
167 int dataLen() const { return width_ * height_ * (format.bpp/8); }
168
169 protected:
170 unsigned long datasize;
171 bool own_colourmap;
172 void checkDataSize();
173 };
174
175};
176
177#endif // __RFB_PIXEL_BUFFER_H__