blob: 5328e6d0a47d3553df662ea85e04620501c486f9 [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// TransImageGetter - class to perform translation between pixel formats,
20// implementing the ImageGetter interface.
21//
22
23#ifndef __RFB_TRANSIMAGEGETTER_H__
24#define __RFB_TRANSIMAGEGETTER_H__
25
26#include <rfb/Rect.h>
27#include <rfb/PixelFormat.h>
28#include <rfb/ImageGetter.h>
29
30namespace rfb {
31 typedef void (*transFnType)(void* table_,
32 const PixelFormat& inPF, void* inPtr,
33 int inStride,
34 const PixelFormat& outPF, void* outPtr,
35 int outStride, int width, int height);
36
37 class SMsgWriter;
38 class ColourMap;
39 class PixelBuffer;
40 class ColourCube;
41
42 class TransImageGetter : public ImageGetter {
43 public:
44
45 TransImageGetter(bool econ=false);
46 virtual ~TransImageGetter();
47
48 // init() is called to initialise the translation tables. The PixelBuffer
49 // argument gives the source data and format details, outPF gives the
50 // client's pixel format. If the client has a colour map, then the writer
51 // argument is used to send a SetColourMapEntries message to the client.
52
53 void init(PixelBuffer* pb, const PixelFormat& outPF, SMsgWriter* writer=0,
54 ColourCube* cube=0);
55
56 // setColourMapEntries() is called when the PixelBuffer has a colour map
57 // which has changed. firstColour and nColours specify which part of the
58 // colour map has changed. If nColours is 0, this means the rest of the
59 // colour map. The PixelBuffer previously passed to init() must have a
60 // valid ColourMap object. If the client also has a colour map, then the
61 // writer argument is used to send a SetColourMapEntries message to the
62 // client. If the client is true colour then instead we update the
63 // internal translation table - in this case the caller should also make
64 // sure that the client receives an update of the relevant parts of the
65 // framebuffer (the simplest thing to do is just update the whole
66 // framebuffer, though it is possible to be smarter than this).
67
68 void setColourMapEntries(int firstColour, int nColours,
69 SMsgWriter* writer=0);
70
71 // getImage() gets the given rectangle of data from the PixelBuffer,
72 // translates it into the client's pixel format and puts it in the buffer
73 // pointed to by the outPtr argument. The optional outStride argument can
74 // be used where padding is required between the output scanlines (the
75 // padding will be outStride-r.width() pixels).
76 void getImage(void* outPtr, const Rect& r, int outStride=0);
77
78 // translatePixels() translates the given number of pixels from inPtr,
79 // putting it into the buffer pointed to by outPtr. The pixels at inPtr
80 // should be in the same format as the PixelBuffer, and the translated
81 // pixels will be in the format previously given by the outPF argument to
82 // init(). Note that this call does not use the PixelBuffer's pixel data.
83 void translatePixels(void* inPtr, void* outPtr, int nPixels) const;
84
85 // setPixelBuffer() changes the pixel buffer to be used. The new pixel
86 // buffer MUST have the same pixel format as the old one - if not you
87 // should call init() instead.
88 void setPixelBuffer(PixelBuffer* pb_) { pb = pb_; }
89
90 // setOffset() sets an offset which is subtracted from the coordinates of
91 // the rectangle given to getImage().
92 void setOffset(const Point& offset_) { offset = offset_; }
93
94 private:
95 bool economic;
96 PixelBuffer* pb;
97 PixelFormat outPF;
98 rdr::U8* table;
99 transFnType transFn;
100 ColourCube* cube;
101 Point offset;
102 };
103}
104#endif