blob: 0e29f1dfcd5dc03ec7fafc3a5a772c02f0073fbf [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Pierre Ossman316a3242014-01-15 12:40:20 +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 */
Pierre Ossmanc0397262014-03-14 15:59:46 +010019
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000020#include <rfb/Encoder.h>
Pierre Ossmanc0397262014-03-14 15:59:46 +010021#include <rfb/PixelBuffer.h>
22#include <rfb/Palette.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000023
24using namespace rfb;
25
Pierre Ossmanc0397262014-03-14 15:59:46 +010026Encoder::Encoder(SConnection *conn_, int encoding_,
Pierre Ossmanbeab2b62018-09-20 10:52:15 +020027 enum EncoderFlags flags_,
28 unsigned int maxPaletteSize_, int losslessQuality_) :
Pierre Ossmanb1cd6ca2015-03-03 16:37:43 +010029 encoding(encoding_), flags(flags_),
Pierre Ossmanbeab2b62018-09-20 10:52:15 +020030 maxPaletteSize(maxPaletteSize_), losslessQuality(losslessQuality_),
31 conn(conn_)
Pierre Ossman4aba19e2014-01-29 16:42:48 +010032{
33}
34
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000035Encoder::~Encoder()
36{
37}
38
Pierre Ossmanc0397262014-03-14 15:59:46 +010039void Encoder::writeSolidRect(int width, int height,
40 const PixelFormat& pf, const rdr::U8* colour)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000041{
Pierre Ossmanc0397262014-03-14 15:59:46 +010042 ManagedPixelBuffer buffer(pf, width, height);
Pierre Ossmanc0397262014-03-14 15:59:46 +010043
44 Palette palette;
45 rdr::U32 palcol;
46
Pierre Ossman56f99d62015-06-05 12:57:02 +020047 buffer.fillRect(buffer.getRect(), colour);
Pierre Ossmanc0397262014-03-14 15:59:46 +010048
49 palcol = 0;
50 memcpy(&palcol, colour, pf.bpp/8);
51 palette.insert(palcol, 1);
52
53 writeRect(&buffer, palette);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000054}
55
Pierre Ossmanc0397262014-03-14 15:59:46 +010056void Encoder::writeSolidRect(const PixelBuffer* pb, const Palette& palette)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000057{
Pierre Ossmanc0397262014-03-14 15:59:46 +010058 rdr::U32 col32;
59 rdr::U16 col16;
60 rdr::U8 col8;
61
62 rdr::U8* buffer;
63
64 assert(palette.size() == 1);
65
66 // The Palette relies on implicit up and down conversion
67 switch (pb->getPF().bpp) {
68 case 32:
69 col32 = (rdr::U32)palette.getColour(0);
70 buffer = (rdr::U8*)&col32;
71 break;
72 case 16:
73 col16 = (rdr::U16)palette.getColour(0);
74 buffer = (rdr::U8*)&col16;
75 break;
Pierre Ossman316a3242014-01-15 12:40:20 +010076 default:
Pierre Ossmanc0397262014-03-14 15:59:46 +010077 col8 = (rdr::U8)palette.getColour(0);
78 buffer = (rdr::U8*)&col8;
79 break;
Pierre Ossman316a3242014-01-15 12:40:20 +010080 }
Pierre Ossmanc0397262014-03-14 15:59:46 +010081
82 writeSolidRect(pb->width(), pb->height(), pb->getPF(), buffer);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000083}