blob: a368b63a7dd1e7d986bf8ccddd2bbec349af7b65 [file] [log] [blame]
Pierre Ossmana2739342011-03-08 16:53:07 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 * Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
DRCffe09d62011-08-17 02:27:59 +00003 * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
Pierre Ossmana2739342011-03-08 16:53:07 +00004 *
5 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this software; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 * USA.
19 */
20
21#ifndef __RFB_PIXELTRANSFORMER_H__
22#define __RFB_PIXELTRANSFORMER_H__
23
DRCffe09d62011-08-17 02:27:59 +000024#include <stdlib.h>
Pierre Ossmana2739342011-03-08 16:53:07 +000025#include <rfb/Rect.h>
26#include <rfb/PixelFormat.h>
27
28namespace rfb {
29 typedef void (*transFnType)(void* table_,
30 const PixelFormat& inPF, void* inPtr,
31 int inStride,
32 const PixelFormat& outPF, void* outPtr,
33 int outStride, int width, int height);
34
35 class SMsgWriter;
36 class ColourMap;
37 class PixelBuffer;
38 class ColourCube;
39
40 typedef void (*setCMFnType)(int firstColour, int nColours, ColourMap* cm, void* data);
41
42 class PixelTransformer {
43 public:
44
45 PixelTransformer(bool econ=false);
46 virtual ~PixelTransformer();
47
48 // init() is called to initialise the translation tables. The inPF and
49 // inCM arguments give the source format details, outPF gives the
50 // target pixel format. If the target has a colour map, then the you
51 // must specify either a colour map callback or a colour cube to indicate
52 // how the target colour map should be handled. If both are specified
53 // then the cube will be used.
54
55 void init(const PixelFormat& inPF, ColourMap* inCM,
56 const PixelFormat& outPF, ColourCube* cube = NULL,
57 setCMFnType cmCallback = NULL, void *cbData = NULL);
58
Pierre Ossman62ea8a22011-07-15 08:26:18 +000059 const PixelFormat &getInPF() const;
60 const ColourMap *getInColourMap() const;
61
62 const PixelFormat &getOutPF() const;
63 const ColourCube *getOutColourCube() const;
64
Pierre Ossmana2739342011-03-08 16:53:07 +000065 // setColourMapEntries() is called when the colour map specified to init()
66 // has changed. firstColour and nColours specify which part of the
67 // colour map has changed. If nColours is 0, this means the rest of the
68 // colour map. If the target also has a colour map, then the callback or
69 // cube specified to init() will be used. If the target is true colour
70 // then instead we update the internal translation table - in this case
71 // the caller should also make sure that the target surface receives an
72 // update of the relevant parts (the simplest thing to do is just update
73 // the whole framebuffer, though it is possible to be smarter than this).
74
75 void setColourMapEntries(int firstColour, int nColours);
76
77 // translatePixels() translates the given number of pixels from inPtr,
78 // putting it into the buffer pointed to by outPtr. The pixels at inPtr
79 // should be in the format given by inPF to init(), and the translated
80 // pixels will be in the format given by the outPF argument to init().
81 void translatePixels(void* inPtr, void* outPtr, int nPixels) const;
82
83 // Similar to translatePixels() but handles an arbitrary region of
84 // two pixel buffers.
85 void translateRect(void* inPtr, int inStride, Rect inRect,
86 void* outPtr, int outStride, Point outCoord) const;
87
DRCffe09d62011-08-17 02:27:59 +000088 bool willTransform(void);
89
Pierre Ossmana2739342011-03-08 16:53:07 +000090 private:
91 bool economic;
92
93 PixelFormat inPF;
94 ColourMap* inCM;
95
96 PixelFormat outPF;
97 setCMFnType cmCallback;
98 void *cbData;
99 ColourCube* cube;
100
101 rdr::U8* table;
102 transFnType transFn;
103 };
104}
105#endif