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> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 27 | #include <rfb/PixelBuffer.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 28 | #include <rfb/TransImageGetter.h> |
| 29 | |
| 30 | using namespace rfb; |
| 31 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 32 | TransImageGetter::TransImageGetter(bool econ) |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 33 | : PixelTransformer(econ), pb(0) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 34 | { |
| 35 | } |
| 36 | |
| 37 | TransImageGetter::~TransImageGetter() |
| 38 | { |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void TransImageGetter::init(PixelBuffer* pb_, const PixelFormat& out, |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 42 | SMsgWriter* writer_) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 43 | { |
| 44 | pb = pb_; |
Pierre Ossman | a273934 | 2011-03-08 16:53:07 +0000 | [diff] [blame] | 45 | writer = writer_; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 46 | |
Pierre Ossman | b6b4dc6 | 2014-01-20 15:05:21 +0100 | [diff] [blame] | 47 | PixelTransformer::init(pb->getPF(), out); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Pierre Ossman | 945cdda | 2014-01-28 14:13:12 +0100 | [diff] [blame] | 50 | const rdr::U8 *TransImageGetter::getRawBufferR(const Rect &r, int *stride) |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 51 | { |
| 52 | if (!offset.equals(Point(0, 0))) |
Pierre Ossman | 945cdda | 2014-01-28 14:13:12 +0100 | [diff] [blame] | 53 | return pb->getBuffer(r.translate(offset.negate()), stride); |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 54 | else |
Pierre Ossman | 945cdda | 2014-01-28 14:13:12 +0100 | [diff] [blame] | 55 | return pb->getBuffer(r, stride); |
DRC | ffe09d6 | 2011-08-17 02:27:59 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 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; |
Pierre Ossman | 945cdda | 2014-01-28 14:13:12 +0100 | [diff] [blame] | 61 | const rdr::U8* inPtr = pb->getBuffer(r.translate(offset.negate()), &inStride); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 62 | |
| 63 | if (!outStride) outStride = r.width(); |
| 64 | |
Pierre Ossman | 4942715 | 2011-06-08 16:58:19 +0000 | [diff] [blame] | 65 | translateRect((void*)inPtr, inStride, Rect(0, 0, r.width(), r.height()), |
| 66 | outPtr, outStride, Point(0, 0)); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 67 | } |