Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 3 | * Copyright (C) 2011 D. R. Commander. All Rights Reserved. |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 4 | * |
| 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 | |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 24 | #include <stdlib.h> |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 25 | #include <rfb/Rect.h> |
| 26 | #include <rfb/PixelFormat.h> |
| 27 | |
| 28 | namespace rfb { |
| 29 | typedef void (*transFnType)(void* table_, |
Pierre Ossman | 654e3f9 | 2012-01-30 13:53:11 +0000 | [diff] [blame^] | 30 | const PixelFormat& inPF, const void* inPtr, |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 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 Ossman | 62ea8a2 | 2011-07-15 08:26:18 +0000 | [diff] [blame] | 59 | const PixelFormat &getInPF() const; |
| 60 | const ColourMap *getInColourMap() const; |
| 61 | |
| 62 | const PixelFormat &getOutPF() const; |
| 63 | const ColourCube *getOutColourCube() const; |
| 64 | |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 65 | // 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(). |
Pierre Ossman | 654e3f9 | 2012-01-30 13:53:11 +0000 | [diff] [blame^] | 81 | void translatePixels(const void* inPtr, void* outPtr, int nPixels) const; |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 82 | |
| 83 | // Similar to translatePixels() but handles an arbitrary region of |
| 84 | // two pixel buffers. |
Pierre Ossman | 654e3f9 | 2012-01-30 13:53:11 +0000 | [diff] [blame^] | 85 | void translateRect(const void* inPtr, int inStride, Rect inRect, |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 86 | void* outPtr, int outStride, Point outCoord) const; |
| 87 | |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 88 | bool willTransform(void); |
| 89 | |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 90 | 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 |