Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* 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 Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame^] | 18 | #include <assert.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
Adam Tkac | 20e0d71 | 2008-11-14 14:48:21 +0000 | [diff] [blame] | 21 | #include <string.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 22 | #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 | |
| 32 | using namespace rfb; |
| 33 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 34 | TransImageGetter::TransImageGetter(bool econ) |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame^] | 35 | : PixelTransformer(econ), pb(0) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 36 | { |
| 37 | } |
| 38 | |
| 39 | TransImageGetter::~TransImageGetter() |
| 40 | { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void TransImageGetter::init(PixelBuffer* pb_, const PixelFormat& out, |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame^] | 44 | SMsgWriter* writer_, ColourCube* cube_) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 45 | { |
| 46 | pb = pb_; |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame^] | 47 | writer = writer_; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 48 | |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame^] | 49 | PixelTransformer::init(pb->getPF(), pb->getColourMap(), out, cube_, |
| 50 | cmCallback, this); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame^] | 53 | void TransImageGetter::setColourMapEntries(int firstCol, int nCols) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 54 | { |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame^] | 55 | PixelTransformer::setColourMapEntries(firstCol, nCols); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void TransImageGetter::getImage(void* outPtr, const Rect& r, int outStride) |
| 59 | { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 60 | int inStride; |
| 61 | const rdr::U8* inPtr = pb->getPixelsR(r.translate(offset.negate()), &inStride); |
| 62 | |
| 63 | if (!outStride) outStride = r.width(); |
| 64 | |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame^] | 65 | translateRect((void*)inPtr, inStride, r, outPtr, outStride, r.tl); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame^] | 68 | void TransImageGetter::cmCallback(int firstColour, int nColours, |
| 69 | ColourMap* cm, void* data) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 70 | { |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame^] | 71 | TransImageGetter *self; |
| 72 | |
| 73 | assert(data); |
| 74 | self = (TransImageGetter*)data; |
| 75 | |
| 76 | if (self->writer) |
| 77 | self->writer->writeSetColourMapEntries(firstColour, nColours, cm); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 78 | } |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame^] | 79 | |