Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 2 | * Copyright 2014 Pierre Ossman for Cendio AB |
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 | */ |
| 19 | #include <rdr/OutStream.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 20 | #include <rfb/encodings.h> |
Pierre Ossman | 668468b | 2014-01-31 12:37:32 +0100 | [diff] [blame] | 21 | #include <rfb/SConnection.h> |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame] | 22 | #include <rfb/PixelBuffer.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 23 | #include <rfb/RawEncoder.h> |
| 24 | |
| 25 | using namespace rfb; |
| 26 | |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 27 | RawEncoder::RawEncoder(SConnection* conn) : |
Pierre Ossman | 4694d88 | 2018-09-20 10:49:40 +0200 | [diff] [blame] | 28 | Encoder(conn, encodingRaw, EncoderPlain) |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 29 | { |
| 30 | } |
| 31 | |
| 32 | RawEncoder::~RawEncoder() |
| 33 | { |
| 34 | } |
| 35 | |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 36 | bool RawEncoder::isSupported() |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 37 | { |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 38 | // Implicitly required; |
| 39 | return true; |
| 40 | } |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame] | 41 | |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 42 | void RawEncoder::writeRect(const PixelBuffer* pb, const Palette& palette) |
| 43 | { |
| 44 | const rdr::U8* buffer; |
| 45 | int stride; |
Pierre Ossman | 0c9bd4b | 2014-07-09 16:44:11 +0200 | [diff] [blame] | 46 | |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 47 | rdr::OutStream* os; |
| 48 | int h, line_bytes, stride_bytes; |
| 49 | |
| 50 | buffer = pb->getBuffer(pb->getRect(), &stride); |
| 51 | |
| 52 | os = conn->getOutStream(); |
| 53 | |
| 54 | h = pb->height(); |
| 55 | line_bytes = pb->width() * pb->getPF().bpp/8; |
| 56 | stride_bytes = stride * pb->getPF().bpp/8; |
| 57 | while (h--) { |
| 58 | os->writeBytes(buffer, line_bytes); |
| 59 | buffer += stride_bytes; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | void RawEncoder::writeSolidRect(int width, int height, |
| 64 | const PixelFormat& pf, |
| 65 | const rdr::U8* colour) |
| 66 | { |
| 67 | rdr::OutStream* os; |
| 68 | int pixels, pixel_size; |
| 69 | |
| 70 | os = conn->getOutStream(); |
| 71 | |
| 72 | pixels = width*height; |
| 73 | pixel_size = pf.bpp/8; |
| 74 | while (pixels--) |
| 75 | os->writeBytes(colour, pixel_size); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 76 | } |