blob: f415455492244f0013f5c25246089c03e990a8bb [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
Pierre Ossmana2739342011-03-08 16:53:07 +000018#include <assert.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000019#include <stdio.h>
20#include <stdlib.h>
Adam Tkac20e0d712008-11-14 14:48:21 +000021#include <string.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000022#include <rfb/PixelFormat.h>
23#include <rfb/Exception.h>
24#include <rfb/ConnParams.h>
25#include <rfb/SMsgWriter.h>
26#include <rfb/ColourMap.h>
27#include <rfb/TrueColourMap.h>
28#include <rfb/PixelBuffer.h>
29#include <rfb/ColourCube.h>
30#include <rfb/TransImageGetter.h>
31
32using namespace rfb;
33
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000034TransImageGetter::TransImageGetter(bool econ)
Pierre Ossmana2739342011-03-08 16:53:07 +000035 : PixelTransformer(econ), pb(0)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000036{
37}
38
39TransImageGetter::~TransImageGetter()
40{
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000041}
42
43void TransImageGetter::init(PixelBuffer* pb_, const PixelFormat& out,
Pierre Ossmana2739342011-03-08 16:53:07 +000044 SMsgWriter* writer_, ColourCube* cube_)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000045{
46 pb = pb_;
Pierre Ossmana2739342011-03-08 16:53:07 +000047 writer = writer_;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000048
Pierre Ossmana2739342011-03-08 16:53:07 +000049 PixelTransformer::init(pb->getPF(), pb->getColourMap(), out, cube_,
50 cmCallback, this);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000051}
52
Pierre Ossmana2739342011-03-08 16:53:07 +000053void TransImageGetter::setColourMapEntries(int firstCol, int nCols)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000054{
Pierre Ossmana2739342011-03-08 16:53:07 +000055 PixelTransformer::setColourMapEntries(firstCol, nCols);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000056}
57
58void TransImageGetter::getImage(void* outPtr, const Rect& r, int outStride)
59{
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000060 int inStride;
61 const rdr::U8* inPtr = pb->getPixelsR(r.translate(offset.negate()), &inStride);
62
63 if (!outStride) outStride = r.width();
64
Pierre Ossman49427152011-06-08 16:58:19 +000065 translateRect((void*)inPtr, inStride, Rect(0, 0, r.width(), r.height()),
66 outPtr, outStride, Point(0, 0));
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000067}
68
Pierre Ossmana2739342011-03-08 16:53:07 +000069void TransImageGetter::cmCallback(int firstColour, int nColours,
70 ColourMap* cm, void* data)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000071{
Pierre Ossmana2739342011-03-08 16:53:07 +000072 TransImageGetter *self;
73
74 assert(data);
75 self = (TransImageGetter*)data;
76
77 if (self->writer)
78 self->writer->writeSetColourMapEntries(firstColour, nColours, cm);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000079}
Pierre Ossmana2739342011-03-08 16:53:07 +000080