blob: 53cb170956230fedeb973c4e5df167ad88dc691a [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* 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 */
18#include <stdio.h>
19#include <rfb/Exception.h>
20#include <rfb/Encoder.h>
21#include <rfb/RawEncoder.h>
22#include <rfb/RREEncoder.h>
23#include <rfb/HextileEncoder.h>
24#include <rfb/ZRLEEncoder.h>
25#include <rfb/TightEncoder.h>
26
27using namespace rfb;
28
29Encoder::~Encoder()
30{
31}
32
33EncoderCreateFnType Encoder::createFns[encodingMax+1] = { 0 };
34
35bool Encoder::supported(unsigned int encoding)
36{
37 return encoding <= encodingMax && createFns[encoding];
38}
39
40Encoder* Encoder::createEncoder(unsigned int encoding, SMsgWriter* writer)
41{
42 if (encoding <= encodingMax && createFns[encoding])
43 return (*createFns[encoding])(writer);
44 return 0;
45}
46
47void Encoder::registerEncoder(unsigned int encoding,
48 EncoderCreateFnType createFn)
49{
50 if (encoding > encodingMax)
51 throw Exception("Encoder::registerEncoder: encoding out of range");
52
53 if (createFns[encoding])
54 fprintf(stderr,"Replacing existing encoder for encoding %s (%d)\n",
55 encodingName(encoding), encoding);
56 createFns[encoding] = createFn;
57}
58
59void Encoder::unregisterEncoder(unsigned int encoding)
60{
61 if (encoding > encodingMax)
62 throw Exception("Encoder::unregisterEncoder: encoding out of range");
63 createFns[encoding] = 0;
64}
65
66int EncoderInit::count = 0;
67
68EncoderInit::EncoderInit()
69{
70 if (count++ != 0) return;
71
72 Encoder::registerEncoder(encodingRaw, RawEncoder::create);
73 Encoder::registerEncoder(encodingRRE, RREEncoder::create);
74 Encoder::registerEncoder(encodingHextile, HextileEncoder::create);
75 Encoder::registerEncoder(encodingZRLE, ZRLEEncoder::create);
76 Encoder::registerEncoder(encodingTight, TightEncoder::create);
77}