blob: bfd9c2fab105977a6884bb892da94ae1603e98e1 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
DRCffe09d62011-08-17 02:27:59 +00002 * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00003 *
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 Ossmana2739342011-03-08 16:53:07 +000029#include <rfb/PixelTransformer.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000030
31namespace rfb {
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000032
33 class SMsgWriter;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000034 class PixelBuffer;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000035
Pierre Ossman8b56a872014-02-12 13:23:30 +010036 class TransImageGetter : public PixelTransformer {
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000037 public:
38
39 TransImageGetter(bool econ=false);
40 virtual ~TransImageGetter();
41
42 // init() is called to initialise the translation tables. The PixelBuffer
43 // argument gives the source data and format details, outPF gives the
Pierre Ossmanb6b4dc62014-01-20 15:05:21 +010044 // client's pixel format.
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000045
Pierre Ossmanb6b4dc62014-01-20 15:05:21 +010046 void init(PixelBuffer* pb, const PixelFormat& outPF, SMsgWriter* writer=0);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000047
48 // getImage() gets the given rectangle of data from the PixelBuffer,
49 // translates it into the client's pixel format and puts it in the buffer
50 // pointed to by the outPtr argument. The optional outStride argument can
51 // be used where padding is required between the output scanlines (the
52 // padding will be outStride-r.width() pixels).
53 void getImage(void* outPtr, const Rect& r, int outStride=0);
54
Pierre Ossman945cdda2014-01-28 14:13:12 +010055 // getRawBufferR() gets the given rectangle of data directly from the
Pierre Ossman4eb74202011-11-03 13:20:32 +000056 // underlying PixelBuffer, bypassing the translation logic. Only use
57 // this when doing something that's independent of the client's pixel
58 // format.
Pierre Ossman945cdda2014-01-28 14:13:12 +010059 const rdr::U8 *getRawBufferR(const Rect &r, int *stride);
DRCffe09d62011-08-17 02:27:59 +000060
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000061 // setPixelBuffer() changes the pixel buffer to be used. The new pixel
62 // buffer MUST have the same pixel format as the old one - if not you
63 // should call init() instead.
64 void setPixelBuffer(PixelBuffer* pb_) { pb = pb_; }
65
DRCffe09d62011-08-17 02:27:59 +000066 PixelBuffer *getPixelBuffer(void) { return pb; }
67
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000068 // setOffset() sets an offset which is subtracted from the coordinates of
69 // the rectangle given to getImage().
70 void setOffset(const Point& offset_) { offset = offset_; }
71
72 private:
73 bool economic;
74 PixelBuffer* pb;
75 PixelFormat outPF;
Pierre Ossmana2739342011-03-08 16:53:07 +000076 SMsgWriter* writer;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000077 rdr::U8* table;
78 transFnType transFn;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000079 Point offset;
80 };
81}
82#endif