blob: ec3a2c87f7fcef425c97175d5397b63c4beb5a5f [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#include <rfb/ImageGetter.h>
31
32namespace rfb {
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000033
34 class SMsgWriter;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000035 class PixelBuffer;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000036
Pierre Ossmana2739342011-03-08 16:53:07 +000037 class TransImageGetter : public ImageGetter,
38 public PixelTransformer {
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000039 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 Ossmanb6b4dc62014-01-20 15:05:21 +010046 // client's pixel format.
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000047
Pierre Ossmanb6b4dc62014-01-20 15:05:21 +010048 void init(PixelBuffer* pb, const PixelFormat& outPF, SMsgWriter* writer=0);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000049
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 Ossman945cdda2014-01-28 14:13:12 +010057 // getRawBufferR() gets the given rectangle of data directly from the
Pierre Ossman4eb74202011-11-03 13:20:32 +000058 // underlying PixelBuffer, bypassing the translation logic. Only use
59 // this when doing something that's independent of the client's pixel
60 // format.
Pierre Ossman945cdda2014-01-28 14:13:12 +010061 const rdr::U8 *getRawBufferR(const Rect &r, int *stride);
DRCffe09d62011-08-17 02:27:59 +000062
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000063 // 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
DRCffe09d62011-08-17 02:27:59 +000068 PixelBuffer *getPixelBuffer(void) { return pb; }
69
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000070 // 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 Ossmana2739342011-03-08 16:53:07 +000078 SMsgWriter* writer;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000079 rdr::U8* table;
80 transFnType transFn;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000081 Point offset;
82 };
83}
84#endif