blob: b12cf06f6f914466c4e2abe816ad35a17e7826ed [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Pierre Ossmanc0397262014-03-14 15:59:46 +01002 * Copyright 2014 Pierre Ossman for Cendio AB
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 */
19#include <rdr/OutStream.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000020#include <rfb/encodings.h>
Pierre Ossman668468b2014-01-31 12:37:32 +010021#include <rfb/SConnection.h>
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020022#include <rfb/PixelBuffer.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000023#include <rfb/RawEncoder.h>
24
25using namespace rfb;
26
Pierre Ossmanc0397262014-03-14 15:59:46 +010027RawEncoder::RawEncoder(SConnection* conn) :
Pierre Ossman4694d882018-09-20 10:49:40 +020028 Encoder(conn, encodingRaw, EncoderPlain)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000029{
30}
31
32RawEncoder::~RawEncoder()
33{
34}
35
Pierre Ossmanc0397262014-03-14 15:59:46 +010036bool RawEncoder::isSupported()
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000037{
Pierre Ossmanc0397262014-03-14 15:59:46 +010038 // Implicitly required;
39 return true;
40}
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020041
Pierre Ossmanc0397262014-03-14 15:59:46 +010042void RawEncoder::writeRect(const PixelBuffer* pb, const Palette& palette)
43{
44 const rdr::U8* buffer;
45 int stride;
Pierre Ossman0c9bd4b2014-07-09 16:44:11 +020046
Pierre Ossmanc0397262014-03-14 15:59:46 +010047 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
63void 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 Kaplinskya2adc8d2006-05-25 05:01:55 +000076}