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; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 35 | class PixelBuffer; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 36 | |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 37 | class TransImageGetter : public ImageGetter, |
| 38 | public PixelTransformer { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 39 | public: |
| 40 | |
| 41 | TransImageGetter(bool econ=false); |
| 42 | virtual ~TransImageGetter(); |
| 43 | |
| 44 | // init() is called to initialise the translation tables. The PixelBuffer |
| 45 | // argument gives the source data and format details, outPF gives the |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 46 | // client's pixel format. |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 47 | |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 48 | void init(PixelBuffer* pb, const PixelFormat& outPF, SMsgWriter* writer=0); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 49 | |
| 50 | // getImage() gets the given rectangle of data from the PixelBuffer, |
| 51 | // translates it into the client's pixel format and puts it in the buffer |
| 52 | // pointed to by the outPtr argument. The optional outStride argument can |
| 53 | // be used where padding is required between the output scanlines (the |
| 54 | // padding will be outStride-r.width() pixels). |
| 55 | void getImage(void* outPtr, const Rect& r, int outStride=0); |
| 56 | |
Pierre Ossman | 945cdda | 2014-01-28 14:13:12 +0100 | [diff] [blame] | 57 | // getRawBufferR() gets the given rectangle of data directly from the |
Pierre Ossman | 4eb7420 | 2011-11-03 13:20:32 +0000 | [diff] [blame] | 58 | // underlying PixelBuffer, bypassing the translation logic. Only use |
| 59 | // this when doing something that's independent of the client's pixel |
| 60 | // format. |
Pierre Ossman | 945cdda | 2014-01-28 14:13:12 +0100 | [diff] [blame] | 61 | const rdr::U8 *getRawBufferR(const Rect &r, int *stride); |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 62 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 63 | // setPixelBuffer() changes the pixel buffer to be used. The new pixel |
| 64 | // buffer MUST have the same pixel format as the old one - if not you |
| 65 | // should call init() instead. |
| 66 | void setPixelBuffer(PixelBuffer* pb_) { pb = pb_; } |
| 67 | |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 68 | PixelBuffer *getPixelBuffer(void) { return pb; } |
| 69 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 70 | // setOffset() sets an offset which is subtracted from the coordinates of |
| 71 | // the rectangle given to getImage(). |
| 72 | void setOffset(const Point& offset_) { offset = offset_; } |
| 73 | |
| 74 | private: |
| 75 | bool economic; |
| 76 | PixelBuffer* pb; |
| 77 | PixelFormat outPF; |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 78 | SMsgWriter* writer; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 79 | rdr::U8* table; |
| 80 | transFnType transFn; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 81 | Point offset; |
| 82 | }; |
| 83 | } |
| 84 | #endif |