blob: 05df1a98c899b075ef6a50d7f52b2f3001c12c9e [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>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000027#include <rfb/PixelBuffer.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000028#include <rfb/TransImageGetter.h>
29
30using namespace rfb;
31
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000032TransImageGetter::TransImageGetter(bool econ)
Pierre Ossmana2739342011-03-08 16:53:07 +000033 : PixelTransformer(econ), pb(0)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000034{
35}
36
37TransImageGetter::~TransImageGetter()
38{
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000039}
40
41void TransImageGetter::init(PixelBuffer* pb_, const PixelFormat& out,
Pierre Ossmanb6b4dc62014-01-20 15:05:21 +010042 SMsgWriter* writer_)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000043{
44 pb = pb_;
Pierre Ossmana2739342011-03-08 16:53:07 +000045 writer = writer_;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000046
Pierre Ossmanb6b4dc62014-01-20 15:05:21 +010047 PixelTransformer::init(pb->getPF(), out);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000048}
49
Pierre Ossman945cdda2014-01-28 14:13:12 +010050const rdr::U8 *TransImageGetter::getRawBufferR(const Rect &r, int *stride)
DRCffe09d62011-08-17 02:27:59 +000051{
52 if (!offset.equals(Point(0, 0)))
Pierre Ossman945cdda2014-01-28 14:13:12 +010053 return pb->getBuffer(r.translate(offset.negate()), stride);
DRCffe09d62011-08-17 02:27:59 +000054 else
Pierre Ossman945cdda2014-01-28 14:13:12 +010055 return pb->getBuffer(r, stride);
DRCffe09d62011-08-17 02:27:59 +000056}
57
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000058void TransImageGetter::getImage(void* outPtr, const Rect& r, int outStride)
59{
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000060 int inStride;
Pierre Ossman945cdda2014-01-28 14:13:12 +010061 const rdr::U8* inPtr = pb->getBuffer(r.translate(offset.negate()), &inStride);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000062
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}