blob: b5ba8c0cac61b737d934e4104e1afdf55b0e4dc1 [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
3 *
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#ifndef __RFB_PIXELTRANSFORMER_H__
21#define __RFB_PIXELTRANSFORMER_H__
22
23#include <rfb/Rect.h>
24#include <rfb/PixelFormat.h>
25
26namespace rfb {
27 typedef void (*transFnType)(void* table_,
28 const PixelFormat& inPF, void* inPtr,
29 int inStride,
30 const PixelFormat& outPF, void* outPtr,
31 int outStride, int width, int height);
32
33 class SMsgWriter;
34 class ColourMap;
35 class PixelBuffer;
36 class ColourCube;
37
38 typedef void (*setCMFnType)(int firstColour, int nColours, ColourMap* cm, void* data);
39
40 class PixelTransformer {
41 public:
42
43 PixelTransformer(bool econ=false);
44 virtual ~PixelTransformer();
45
46 // init() is called to initialise the translation tables. The inPF and
47 // inCM arguments give the source format details, outPF gives the
48 // target pixel format. If the target has a colour map, then the you
49 // must specify either a colour map callback or a colour cube to indicate
50 // how the target colour map should be handled. If both are specified
51 // then the cube will be used.
52
53 void init(const PixelFormat& inPF, ColourMap* inCM,
54 const PixelFormat& outPF, ColourCube* cube = NULL,
55 setCMFnType cmCallback = NULL, void *cbData = NULL);
56
57 // setColourMapEntries() is called when the colour map specified to init()
58 // has changed. firstColour and nColours specify which part of the
59 // colour map has changed. If nColours is 0, this means the rest of the
60 // colour map. If the target also has a colour map, then the callback or
61 // cube specified to init() will be used. If the target is true colour
62 // then instead we update the internal translation table - in this case
63 // the caller should also make sure that the target surface receives an
64 // update of the relevant parts (the simplest thing to do is just update
65 // the whole framebuffer, though it is possible to be smarter than this).
66
67 void setColourMapEntries(int firstColour, int nColours);
68
69 // translatePixels() translates the given number of pixels from inPtr,
70 // putting it into the buffer pointed to by outPtr. The pixels at inPtr
71 // should be in the format given by inPF to init(), and the translated
72 // pixels will be in the format given by the outPF argument to init().
73 void translatePixels(void* inPtr, void* outPtr, int nPixels) const;
74
75 // Similar to translatePixels() but handles an arbitrary region of
76 // two pixel buffers.
77 void translateRect(void* inPtr, int inStride, Rect inRect,
78 void* outPtr, int outStride, Point outCoord) const;
79
80 private:
81 bool economic;
82
83 PixelFormat inPF;
84 ColourMap* inCM;
85
86 PixelFormat outPF;
87 setCMFnType cmCallback;
88 void *cbData;
89 ColourCube* cube;
90
91 rdr::U8* table;
92 transFnType transFn;
93 };
94}
95#endif