blob: 5de75430af7645878025b243dda60531bb7e8cbd [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
Peter Åstrand98fe98c2010-02-10 07:43:02 +000035bool Encoder::supported(int encoding)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000036{
Adam Tkacea633a72010-07-21 14:12:18 +000037 return encoding >= 0 && encoding <= encodingMax && createFns[encoding];
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000038}
39
Peter Åstrand98fe98c2010-02-10 07:43:02 +000040Encoder* Encoder::createEncoder(int encoding, SMsgWriter* writer)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000041{
Adam Tkacea633a72010-07-21 14:12:18 +000042 if (supported(encoding))
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000043 return (*createFns[encoding])(writer);
44 return 0;
45}
46
Peter Åstrand98fe98c2010-02-10 07:43:02 +000047void Encoder::registerEncoder(int encoding,
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000048 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
Peter Åstrand98fe98c2010-02-10 07:43:02 +000059void Encoder::unregisterEncoder(int encoding)
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000060{
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}