blob: 4a13923c5b469ff9b8ce2b797860797ae5155425 [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
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;
71
72 // Get pixel data for a given part of the buffer
73 // Data is copied into the supplied buffer, with the specified
74 // stride.
75 virtual void getImage(void* imageBuf, const Rect& r, int stride=0);
76
77 // Get the data at (x,y) as a Pixel.
78 // VERY INEFFICIENT!!!
79 // *** Pixel getPixel(const Point& p);
80
81 ///////////////////////////////////////////////
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
105 // - Get the number of pixels per row in the actual pixel buffer data area
106 // This may in some cases NOT be the same as width().
107 virtual int getStride() const;
108
109 // Get a pointer to specified pixel data
110 virtual rdr::U8* getPixelsRW(const Rect& r, int* stride);
111 virtual const rdr::U8* getPixelsR(const Rect& r, int* stride) {
112 return getPixelsRW(r, stride);
113 }
114
115 ///////////////////////////////////////////////
116 // Basic rendering operations
117 // These operations DO NOT clip to the pixelbuffer area, or trap overruns.
118
119 // Fill a rectangle
120 virtual void fillRect(const Rect &dest, Pixel pix);
121
122 // Copy pixel data to the buffer
123 virtual void imageRect(const Rect &dest, const void* pixels, int stride=0);
124
125 // Copy pixel data from one PixelBuffer location to another
126 virtual void copyRect(const Rect &dest, const Point &move_by_delta);
127
128 // Copy pixel data to the buffer through a mask
129 // pixels is a pointer to the pixel to be copied to r.tl.
130 // maskPos specifies the pixel offset in the mask to start from.
131 // mask_ is a pointer to the mask bits at (0,0).
132 // pStride and mStride are the strides of the pixel and mask buffers.
133 virtual void maskRect(const Rect& r, const void* pixels, const void* mask_);
134
135 // pixel is the Pixel value to be used where mask_ is set
136 virtual void maskRect(const Rect& r, Pixel pixel, const void* mask_);
137
138 // *** Should this be visible?
139 rdr::U8* data;
140
141 protected:
142 FullFramePixelBuffer();
143 };
144
145 // -=- Managed pixel buffer class
146 // Automatically allocates enough space for the specified format & area
147
148 class ManagedPixelBuffer : public FullFramePixelBuffer {
149 public:
150 ManagedPixelBuffer();
151 ManagedPixelBuffer(const PixelFormat& pf, int width, int height);
152 virtual ~ManagedPixelBuffer();
153
154 // Manage the pixel buffer layout
155 virtual void setPF(const PixelFormat &pf);
156 virtual void setSize(int w, int h);
157
158 // Assign a colour map to the buffer
159 virtual void setColourMap(ColourMap* cm, bool own_cm);
160
161 // Return the total number of bytes of pixel data in the buffer
162 int dataLen() const { return width_ * height_ * (format.bpp/8); }
163
164 protected:
165 unsigned long datasize;
166 bool own_colourmap;
167 void checkDataSize();
168 };
169
170};
171
172#endif // __RFB_PIXEL_BUFFER_H__