blob: 8fde743b1a7a6c391d27be81dcf2f047f40d3d7e [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
DRCffe09d62011-08-17 02:27:59 +00002 * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00003 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
19//
20// TransImageGetter - class to perform translation between pixel formats,
21// implementing the ImageGetter interface.
22//
23
24#ifndef __RFB_TRANSIMAGEGETTER_H__
25#define __RFB_TRANSIMAGEGETTER_H__
26
27#include <rfb/Rect.h>
28#include <rfb/PixelFormat.h>
Pierre Ossmana2739342011-03-08 16:53:07 +000029#include <rfb/PixelTransformer.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000030#include <rfb/ImageGetter.h>
31
32namespace rfb {
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000033
34 class SMsgWriter;
35 class ColourMap;
36 class PixelBuffer;
37 class ColourCube;
38
Pierre Ossmana2739342011-03-08 16:53:07 +000039 class TransImageGetter : public ImageGetter,
40 public PixelTransformer {
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000041 public:
42
43 TransImageGetter(bool econ=false);
44 virtual ~TransImageGetter();
45
46 // init() is called to initialise the translation tables. The PixelBuffer
47 // argument gives the source data and format details, outPF gives the
48 // client's pixel format. If the client has a colour map, then the writer
49 // argument is used to send a SetColourMapEntries message to the client.
50
51 void init(PixelBuffer* pb, const PixelFormat& outPF, SMsgWriter* writer=0,
52 ColourCube* cube=0);
53
54 // setColourMapEntries() is called when the PixelBuffer has a colour map
55 // which has changed. firstColour and nColours specify which part of the
56 // colour map has changed. If nColours is 0, this means the rest of the
57 // colour map. The PixelBuffer previously passed to init() must have a
58 // valid ColourMap object. If the client also has a colour map, then the
59 // writer argument is used to send a SetColourMapEntries message to the
60 // client. If the client is true colour then instead we update the
61 // internal translation table - in this case the caller should also make
62 // sure that the client receives an update of the relevant parts of the
63 // framebuffer (the simplest thing to do is just update the whole
64 // framebuffer, though it is possible to be smarter than this).
65
Pierre Ossmana2739342011-03-08 16:53:07 +000066 void setColourMapEntries(int firstColour, int nColours);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000067
68 // getImage() gets the given rectangle of data from the PixelBuffer,
69 // translates it into the client's pixel format and puts it in the buffer
70 // pointed to by the outPtr argument. The optional outStride argument can
71 // be used where padding is required between the output scanlines (the
72 // padding will be outStride-r.width() pixels).
73 void getImage(void* outPtr, const Rect& r, int outStride=0);
74
DRCffe09d62011-08-17 02:27:59 +000075 rdr::U8 *getPixelsRW(const Rect &r, int *stride);
76
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000077 // setPixelBuffer() changes the pixel buffer to be used. The new pixel
78 // buffer MUST have the same pixel format as the old one - if not you
79 // should call init() instead.
80 void setPixelBuffer(PixelBuffer* pb_) { pb = pb_; }
81
DRCffe09d62011-08-17 02:27:59 +000082 PixelBuffer *getPixelBuffer(void) { return pb; }
83
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000084 // setOffset() sets an offset which is subtracted from the coordinates of
85 // the rectangle given to getImage().
86 void setOffset(const Point& offset_) { offset = offset_; }
87
88 private:
Pierre Ossmana2739342011-03-08 16:53:07 +000089 static void cmCallback(int firstColour, int nColours,
90 ColourMap* cm, void* data);
91
92 private:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000093 bool economic;
94 PixelBuffer* pb;
95 PixelFormat outPF;
Pierre Ossmana2739342011-03-08 16:53:07 +000096 SMsgWriter* writer;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000097 rdr::U8* table;
98 transFnType transFn;
99 ColourCube* cube;
100 Point offset;
101 };
102}
103#endif