blob: 3900d065b614d0bfefd3a24e7a3b440c0dd71321 [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 */
Pierre Ossmana2739342011-03-08 16:53:07 +000019#include <assert.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000020#include <stdio.h>
21#include <stdlib.h>
Adam Tkac20e0d712008-11-14 14:48:21 +000022#include <string.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000023#include <rfb/PixelFormat.h>
24#include <rfb/Exception.h>
25#include <rfb/ConnParams.h>
26#include <rfb/SMsgWriter.h>
27#include <rfb/ColourMap.h>
28#include <rfb/TrueColourMap.h>
29#include <rfb/PixelBuffer.h>
30#include <rfb/ColourCube.h>
31#include <rfb/TransImageGetter.h>
32
33using namespace rfb;
34
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000035TransImageGetter::TransImageGetter(bool econ)
Pierre Ossmana2739342011-03-08 16:53:07 +000036 : PixelTransformer(econ), pb(0)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000037{
38}
39
40TransImageGetter::~TransImageGetter()
41{
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000042}
43
44void TransImageGetter::init(PixelBuffer* pb_, const PixelFormat& out,
Pierre Ossmana2739342011-03-08 16:53:07 +000045 SMsgWriter* writer_, ColourCube* cube_)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000046{
47 pb = pb_;
Pierre Ossmana2739342011-03-08 16:53:07 +000048 writer = writer_;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000049
Pierre Ossmana2739342011-03-08 16:53:07 +000050 PixelTransformer::init(pb->getPF(), pb->getColourMap(), out, cube_,
51 cmCallback, this);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000052}
53
Pierre Ossmana2739342011-03-08 16:53:07 +000054void TransImageGetter::setColourMapEntries(int firstCol, int nCols)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000055{
Pierre Ossmana2739342011-03-08 16:53:07 +000056 PixelTransformer::setColourMapEntries(firstCol, nCols);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000057}
58
Pierre Ossman945cdda2014-01-28 14:13:12 +010059const rdr::U8 *TransImageGetter::getRawBufferR(const Rect &r, int *stride)
DRCffe09d62011-08-17 02:27:59 +000060{
61 if (!offset.equals(Point(0, 0)))
Pierre Ossman945cdda2014-01-28 14:13:12 +010062 return pb->getBuffer(r.translate(offset.negate()), stride);
DRCffe09d62011-08-17 02:27:59 +000063 else
Pierre Ossman945cdda2014-01-28 14:13:12 +010064 return pb->getBuffer(r, stride);
DRCffe09d62011-08-17 02:27:59 +000065}
66
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000067void TransImageGetter::getImage(void* outPtr, const Rect& r, int outStride)
68{
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000069 int inStride;
Pierre Ossman945cdda2014-01-28 14:13:12 +010070 const rdr::U8* inPtr = pb->getBuffer(r.translate(offset.negate()), &inStride);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000071
72 if (!outStride) outStride = r.width();
73
Pierre Ossman49427152011-06-08 16:58:19 +000074 translateRect((void*)inPtr, inStride, Rect(0, 0, r.width(), r.height()),
75 outPtr, outStride, Point(0, 0));
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000076}
77
Pierre Ossmana2739342011-03-08 16:53:07 +000078void TransImageGetter::cmCallback(int firstColour, int nColours,
79 ColourMap* cm, void* data)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000080{
Pierre Ossmana2739342011-03-08 16:53:07 +000081 TransImageGetter *self;
82
83 assert(data);
84 self = (TransImageGetter*)data;
85
86 if (self->writer)
87 self->writer->writeSetColourMapEntries(firstColour, nColours, cm);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000088}