Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame^] | 2 | * Copyright (C) 2011 D. R. Commander. All Rights Reserved. |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 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 | // TransImageGetter - class to perform translation between pixel formats, |
| 21 | // implementing the ImageGetter interface. |
| 22 | // |
| 23 | |
| 24 | #ifndef __RFB_TRANSIMAGEGETTER_H__ |
| 25 | #define __RFB_TRANSIMAGEGETTER_H__ |
| 26 | |
| 27 | #include <rfb/Rect.h> |
| 28 | #include <rfb/PixelFormat.h> |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 29 | #include <rfb/PixelTransformer.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 30 | #include <rfb/ImageGetter.h> |
| 31 | |
| 32 | namespace rfb { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 33 | |
| 34 | class SMsgWriter; |
| 35 | class ColourMap; |
| 36 | class PixelBuffer; |
| 37 | class ColourCube; |
| 38 | |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 39 | class TransImageGetter : public ImageGetter, |
| 40 | public PixelTransformer { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 41 | public: |
| 42 | |
| 43 | TransImageGetter(bool econ=false); |
| 44 | virtual ~TransImageGetter(); |
| 45 | |
| 46 | // init() is called to initialise the translation tables. The PixelBuffer |
| 47 | // argument gives the source data and format details, outPF gives the |
| 48 | // client's pixel format. If the client has a colour map, then the writer |
| 49 | // argument is used to send a SetColourMapEntries message to the client. |
| 50 | |
| 51 | void init(PixelBuffer* pb, const PixelFormat& outPF, SMsgWriter* writer=0, |
| 52 | ColourCube* cube=0); |
| 53 | |
| 54 | // setColourMapEntries() is called when the PixelBuffer has a colour map |
| 55 | // which has changed. firstColour and nColours specify which part of the |
| 56 | // colour map has changed. If nColours is 0, this means the rest of the |
| 57 | // colour map. The PixelBuffer previously passed to init() must have a |
| 58 | // valid ColourMap object. If the client also has a colour map, then the |
| 59 | // writer argument is used to send a SetColourMapEntries message to the |
| 60 | // client. If the client is true colour then instead we update the |
| 61 | // internal translation table - in this case the caller should also make |
| 62 | // sure that the client receives an update of the relevant parts of the |
| 63 | // framebuffer (the simplest thing to do is just update the whole |
| 64 | // framebuffer, though it is possible to be smarter than this). |
| 65 | |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 66 | void setColourMapEntries(int firstColour, int nColours); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 67 | |
| 68 | // getImage() gets the given rectangle of data from the PixelBuffer, |
| 69 | // translates it into the client's pixel format and puts it in the buffer |
| 70 | // pointed to by the outPtr argument. The optional outStride argument can |
| 71 | // be used where padding is required between the output scanlines (the |
| 72 | // padding will be outStride-r.width() pixels). |
| 73 | void getImage(void* outPtr, const Rect& r, int outStride=0); |
| 74 | |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame^] | 75 | rdr::U8 *getPixelsRW(const Rect &r, int *stride); |
| 76 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 77 | // setPixelBuffer() changes the pixel buffer to be used. The new pixel |
| 78 | // buffer MUST have the same pixel format as the old one - if not you |
| 79 | // should call init() instead. |
| 80 | void setPixelBuffer(PixelBuffer* pb_) { pb = pb_; } |
| 81 | |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame^] | 82 | PixelBuffer *getPixelBuffer(void) { return pb; } |
| 83 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 84 | // setOffset() sets an offset which is subtracted from the coordinates of |
| 85 | // the rectangle given to getImage(). |
| 86 | void setOffset(const Point& offset_) { offset = offset_; } |
| 87 | |
| 88 | private: |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 89 | static void cmCallback(int firstColour, int nColours, |
| 90 | ColourMap* cm, void* data); |
| 91 | |
| 92 | private: |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 93 | bool economic; |
| 94 | PixelBuffer* pb; |
| 95 | PixelFormat outPF; |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 96 | SMsgWriter* writer; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 97 | rdr::U8* table; |
| 98 | transFnType transFn; |
| 99 | ColourCube* cube; |
| 100 | Point offset; |
| 101 | }; |
| 102 | } |
| 103 | #endif |