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 |
| 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 | |
| 26 | namespace 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 | |
Pierre Ossman | 62ea8a2 | 2011-07-15 08:26:18 +0000 | [diff] [blame] | 57 | const PixelFormat &getInPF() const; |
| 58 | const ColourMap *getInColourMap() const; |
| 59 | |
| 60 | const PixelFormat &getOutPF() const; |
| 61 | const ColourCube *getOutColourCube() const; |
| 62 | |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 63 | // setColourMapEntries() is called when the colour map specified to init() |
| 64 | // has changed. firstColour and nColours specify which part of the |
| 65 | // colour map has changed. If nColours is 0, this means the rest of the |
| 66 | // colour map. If the target also has a colour map, then the callback or |
| 67 | // cube specified to init() will be used. If the target is true colour |
| 68 | // then instead we update the internal translation table - in this case |
| 69 | // the caller should also make sure that the target surface receives an |
| 70 | // update of the relevant parts (the simplest thing to do is just update |
| 71 | // the whole framebuffer, though it is possible to be smarter than this). |
| 72 | |
| 73 | void setColourMapEntries(int firstColour, int nColours); |
| 74 | |
| 75 | // translatePixels() translates the given number of pixels from inPtr, |
| 76 | // putting it into the buffer pointed to by outPtr. The pixels at inPtr |
| 77 | // should be in the format given by inPF to init(), and the translated |
| 78 | // pixels will be in the format given by the outPF argument to init(). |
| 79 | void translatePixels(void* inPtr, void* outPtr, int nPixels) const; |
| 80 | |
| 81 | // Similar to translatePixels() but handles an arbitrary region of |
| 82 | // two pixel buffers. |
| 83 | void translateRect(void* inPtr, int inStride, Rect inRect, |
| 84 | void* outPtr, int outStride, Point outCoord) const; |
| 85 | |
| 86 | private: |
| 87 | bool economic; |
| 88 | |
| 89 | PixelFormat inPF; |
| 90 | ColourMap* inCM; |
| 91 | |
| 92 | PixelFormat outPF; |
| 93 | setCMFnType cmCallback; |
| 94 | void *cbData; |
| 95 | ColourCube* cube; |
| 96 | |
| 97 | rdr::U8* table; |
| 98 | transFnType transFn; |
| 99 | }; |
| 100 | } |
| 101 | #endif |