blob: 7942247a97d9b8821f8dbd06e18050f4e0360fd6 [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>
Pierre Ossmana2739342011-03-08 16:53:07 +000028#include <rfb/PixelTransformer.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000029#include <rfb/ImageGetter.h>
30
31namespace rfb {
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000032
33 class SMsgWriter;
34 class ColourMap;
35 class PixelBuffer;
36 class ColourCube;
37
Pierre Ossmana2739342011-03-08 16:53:07 +000038 class TransImageGetter : public ImageGetter,
39 public PixelTransformer {
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000040 public:
41
42 TransImageGetter(bool econ=false);
43 virtual ~TransImageGetter();
44
45 // init() is called to initialise the translation tables. The PixelBuffer
46 // argument gives the source data and format details, outPF gives the
47 // client's pixel format. If the client has a colour map, then the writer
48 // argument is used to send a SetColourMapEntries message to the client.
49
50 void init(PixelBuffer* pb, const PixelFormat& outPF, SMsgWriter* writer=0,
51 ColourCube* cube=0);
52
53 // setColourMapEntries() is called when the PixelBuffer has a colour map
54 // which has changed. firstColour and nColours specify which part of the
55 // colour map has changed. If nColours is 0, this means the rest of the
56 // colour map. The PixelBuffer previously passed to init() must have a
57 // valid ColourMap object. If the client also has a colour map, then the
58 // writer argument is used to send a SetColourMapEntries message to the
59 // client. If the client is true colour then instead we update the
60 // internal translation table - in this case the caller should also make
61 // sure that the client receives an update of the relevant parts of the
62 // framebuffer (the simplest thing to do is just update the whole
63 // framebuffer, though it is possible to be smarter than this).
64
Pierre Ossmana2739342011-03-08 16:53:07 +000065 void setColourMapEntries(int firstColour, int nColours);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000066
67 // getImage() gets the given rectangle of data from the PixelBuffer,
68 // translates it into the client's pixel format and puts it in the buffer
69 // pointed to by the outPtr argument. The optional outStride argument can
70 // be used where padding is required between the output scanlines (the
71 // padding will be outStride-r.width() pixels).
72 void getImage(void* outPtr, const Rect& r, int outStride=0);
73
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000074 // setPixelBuffer() changes the pixel buffer to be used. The new pixel
75 // buffer MUST have the same pixel format as the old one - if not you
76 // should call init() instead.
77 void setPixelBuffer(PixelBuffer* pb_) { pb = pb_; }
78
79 // setOffset() sets an offset which is subtracted from the coordinates of
80 // the rectangle given to getImage().
81 void setOffset(const Point& offset_) { offset = offset_; }
82
83 private:
Pierre Ossmana2739342011-03-08 16:53:07 +000084 static void cmCallback(int firstColour, int nColours,
85 ColourMap* cm, void* data);
86
87 private:
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000088 bool economic;
89 PixelBuffer* pb;
90 PixelFormat outPF;
Pierre Ossmana2739342011-03-08 16:53:07 +000091 SMsgWriter* writer;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000092 rdr::U8* table;
93 transFnType transFn;
94 ColourCube* cube;
95 Point offset;
96 };
97}
98#endif