Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 2 | * Copyright (C) 2011 D. R. Commander. All Rights Reserved. |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 3 | * |
| 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 Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 19 | #include <assert.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
Adam Tkac | 20e0d71 | 2008-11-14 14:48:21 +0000 | [diff] [blame] | 22 | #include <string.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 23 | #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 | |
| 33 | using namespace rfb; |
| 34 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 35 | TransImageGetter::TransImageGetter(bool econ) |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 36 | : PixelTransformer(econ), pb(0) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 37 | { |
| 38 | } |
| 39 | |
| 40 | TransImageGetter::~TransImageGetter() |
| 41 | { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void TransImageGetter::init(PixelBuffer* pb_, const PixelFormat& out, |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 45 | SMsgWriter* writer_, ColourCube* cube_) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 46 | { |
| 47 | pb = pb_; |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 48 | writer = writer_; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 49 | |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 50 | PixelTransformer::init(pb->getPF(), pb->getColourMap(), out, cube_, |
| 51 | cmCallback, this); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 54 | void TransImageGetter::setColourMapEntries(int firstCol, int nCols) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 55 | { |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 56 | PixelTransformer::setColourMapEntries(firstCol, nCols); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Pierre Ossman | 945cdda | 2014-01-28 14:13:12 +0100 | [diff] [blame^] | 59 | const rdr::U8 *TransImageGetter::getRawBufferR(const Rect &r, int *stride) |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 60 | { |
| 61 | if (!offset.equals(Point(0, 0))) |
Pierre Ossman | 945cdda | 2014-01-28 14:13:12 +0100 | [diff] [blame^] | 62 | return pb->getBuffer(r.translate(offset.negate()), stride); |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 63 | else |
Pierre Ossman | 945cdda | 2014-01-28 14:13:12 +0100 | [diff] [blame^] | 64 | return pb->getBuffer(r, stride); |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 67 | void TransImageGetter::getImage(void* outPtr, const Rect& r, int outStride) |
| 68 | { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 69 | int inStride; |
Pierre Ossman | 945cdda | 2014-01-28 14:13:12 +0100 | [diff] [blame^] | 70 | const rdr::U8* inPtr = pb->getBuffer(r.translate(offset.negate()), &inStride); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 71 | |
| 72 | if (!outStride) outStride = r.width(); |
| 73 | |
Pierre Ossman | 4942715 | 2011-06-08 16:58:19 +0000 | [diff] [blame] | 74 | translateRect((void*)inPtr, inStride, Rect(0, 0, r.width(), r.height()), |
| 75 | outPtr, outStride, Point(0, 0)); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 78 | void TransImageGetter::cmCallback(int firstColour, int nColours, |
| 79 | ColourMap* cm, void* data) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 80 | { |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 81 | TransImageGetter *self; |
| 82 | |
| 83 | assert(data); |
| 84 | self = (TransImageGetter*)data; |
| 85 | |
| 86 | if (self->writer) |
| 87 | self->writer->writeSetColourMapEntries(firstColour, nColours, cm); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 88 | } |