We have no use for it, so let's keep things simple.
#include <stdio.h>
#include <rdr/OutStream.h>
#include <rfb/msgTypes.h>
+#include <rfb/encodings.h>
#include <rfb/PixelFormat.h>
#include <rfb/Rect.h>
#include <rfb/ConnParams.h>
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
+ * Copyright 2014 Pierre Ossman for Cendio AB
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* USA.
*/
#include <stdio.h>
-#include <rfb/Exception.h>
+#include <rfb/encodings.h>
#include <rfb/Decoder.h>
#include <rfb/RawDecoder.h>
#include <rfb/RREDecoder.h>
{
}
-DecoderCreateFnType Decoder::createFns[encodingMax+1] = { 0 };
-
bool Decoder::supported(int encoding)
{
- return encoding >= 0 && encoding <= encodingMax && createFns[encoding];
+ switch (encoding) {
+ case encodingRaw:
+ case encodingRRE:
+ case encodingHextile:
+ case encodingZRLE:
+ case encodingTight:
+ return true;
+ default:
+ return false;
+ }
}
Decoder* Decoder::createDecoder(int encoding, CMsgReader* reader)
{
- if (supported(encoding))
- return (*createFns[encoding])(reader);
- return 0;
-}
-
-void Decoder::registerDecoder(int encoding,
- DecoderCreateFnType createFn)
-{
- if (encoding > encodingMax)
- throw Exception("Decoder::registerDecoder: encoding out of range");
-
- if (createFns[encoding])
- fprintf(stderr,"Replacing existing decoder for encoding %s (%d)\n",
- encodingName(encoding), encoding);
- createFns[encoding] = createFn;
-}
-
-int DecoderInit::count = 0;
-
-DecoderInit::DecoderInit()
-{
- if (count++ != 0) return;
-
- Decoder::registerDecoder(encodingRaw, RawDecoder::create);
- Decoder::registerDecoder(encodingRRE, RREDecoder::create);
- Decoder::registerDecoder(encodingHextile, HextileDecoder::create);
- Decoder::registerDecoder(encodingZRLE, ZRLEDecoder::create);
- Decoder::registerDecoder(encodingTight, TightDecoder::create);
+ switch (encoding) {
+ case encodingRaw:
+ return new RawDecoder(reader);
+ case encodingRRE:
+ return new RREDecoder(reader);
+ case encodingHextile:
+ return new HextileDecoder(reader);
+ case encodingZRLE:
+ return new ZRLEDecoder(reader);
+ case encodingTight:
+ return new TightDecoder(reader);
+ default:
+ return NULL;
+ }
}
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
+ * Copyright 2014 Pierre Ossman for Cendio AB
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#define __RFB_DECODER_H__
#include <rfb/Rect.h>
-#include <rfb/encodings.h>
namespace rfb {
class CMsgReader;
class CMsgHandler;
- class Decoder;
- typedef Decoder* (*DecoderCreateFnType)(CMsgReader*);
class Decoder {
public:
static bool supported(int encoding);
static Decoder* createDecoder(int encoding, CMsgReader* reader);
- static void registerDecoder(int encoding,
- DecoderCreateFnType createFn);
- private:
- static DecoderCreateFnType createFns[encodingMax+1];
};
-
- class DecoderInit {
- static int count;
- public:
- DecoderInit();
- };
-
- static DecoderInit decoderInitObj;
}
#endif
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
+ * Copyright 2014 Pierre Ossman for Cendio AB
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* USA.
*/
#include <stdio.h>
+#include <rfb/encodings.h>
#include <rfb/Exception.h>
#include <rfb/Encoder.h>
#include <rfb/RawEncoder.h>
{
}
-EncoderCreateFnType Encoder::createFns[encodingMax+1] = { 0 };
-
bool Encoder::supported(int encoding)
{
- return encoding >= 0 && encoding <= encodingMax && createFns[encoding];
+ switch (encoding) {
+ case encodingRaw:
+ case encodingRRE:
+ case encodingHextile:
+ case encodingZRLE:
+ case encodingTight:
+ return true;
+ default:
+ return false;
+ }
}
Encoder* Encoder::createEncoder(int encoding, SMsgWriter* writer)
{
- if (supported(encoding))
- return (*createFns[encoding])(writer);
- return 0;
-}
-
-void Encoder::registerEncoder(int encoding,
- EncoderCreateFnType createFn)
-{
- if (encoding > encodingMax)
- throw Exception("Encoder::registerEncoder: encoding out of range");
-
- if (createFns[encoding])
- fprintf(stderr,"Replacing existing encoder for encoding %s (%d)\n",
- encodingName(encoding), encoding);
- createFns[encoding] = createFn;
-}
-
-void Encoder::unregisterEncoder(int encoding)
-{
- if (encoding > encodingMax)
- throw Exception("Encoder::unregisterEncoder: encoding out of range");
- createFns[encoding] = 0;
-}
-
-int EncoderInit::count = 0;
-
-EncoderInit::EncoderInit()
-{
- if (count++ != 0) return;
-
- Encoder::registerEncoder(encodingRaw, RawEncoder::create);
- Encoder::registerEncoder(encodingRRE, RREEncoder::create);
- Encoder::registerEncoder(encodingHextile, HextileEncoder::create);
- Encoder::registerEncoder(encodingZRLE, ZRLEEncoder::create);
- Encoder::registerEncoder(encodingTight, TightEncoder::create);
+ switch (encoding) {
+ case encodingRaw:
+ return new RawEncoder(writer);
+ case encodingRRE:
+ return new RREEncoder(writer);
+ case encodingHextile:
+ return new HextileEncoder(writer);
+ case encodingZRLE:
+ return new ZRLEEncoder(writer);
+ case encodingTight:
+ return new TightEncoder(writer);
+ default:
+ return NULL;
+ }
}
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
* Copyright (C) 2011 D. R. Commander. All Rights Reserved.
+ * Copyright 2014 Pierre Ossman for Cendio AB
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#define __RFB_ENCODER_H__
#include <rfb/Rect.h>
-#include <rfb/encodings.h>
+#include <rfb/TransImageGetter.h>
#include <rfb/JpegCompressor.h>
namespace rfb {
class SMsgWriter;
- class Encoder;
class TransImageGetter;
- typedef Encoder* (*EncoderCreateFnType)(SMsgWriter*);
class Encoder {
public:
static bool supported(int encoding);
static Encoder* createEncoder(int encoding, SMsgWriter* writer);
- static void registerEncoder(int encoding,
- EncoderCreateFnType createFn);
- static void unregisterEncoder(int encoding);
- private:
- static EncoderCreateFnType createFns[encodingMax+1];
};
-
- class EncoderInit {
- static int count;
- public:
- EncoderInit();
- };
-
- static EncoderInit encoderInitObj;
}
#endif
#include <rfb/hextileDecode.h>
#undef BPP
-Decoder* HextileDecoder::create(CMsgReader* reader)
-{
- return new HextileDecoder(reader);
-}
-
HextileDecoder::HextileDecoder(CMsgReader* reader_) : reader(reader_)
{
}
class HextileDecoder : public Decoder {
public:
- static Decoder* create(CMsgReader* reader);
- virtual void readRect(const Rect& r, CMsgHandler* handler);
+ HextileDecoder(CMsgReader* reader);
virtual ~HextileDecoder();
+ virtual void readRect(const Rect& r, CMsgHandler* handler);
private:
- HextileDecoder(CMsgReader* reader);
CMsgReader* reader;
};
}
#include <rfb/hextileEncodeBetter.h>
#undef BPP
-Encoder* HextileEncoder::create(SMsgWriter* writer)
-{
- return new HextileEncoder(writer);
-}
-
HextileEncoder::HextileEncoder(SMsgWriter* writer_) : writer(writer_)
{
}
class HextileEncoder : public Encoder {
public:
- static Encoder* create(SMsgWriter* writer);
- virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
+ HextileEncoder(SMsgWriter* writer);
virtual ~HextileEncoder();
+ virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
private:
- HextileEncoder(SMsgWriter* writer);
SMsgWriter* writer;
};
}
#include <rfb/rreDecode.h>
#undef BPP
-Decoder* RREDecoder::create(CMsgReader* reader)
-{
- return new RREDecoder(reader);
-}
-
RREDecoder::RREDecoder(CMsgReader* reader_) : reader(reader_)
{
}
class RREDecoder : public Decoder {
public:
- static Decoder* create(CMsgReader* reader);
- virtual void readRect(const Rect& r, CMsgHandler* handler);
+ RREDecoder(CMsgReader* reader);
virtual ~RREDecoder();
+ virtual void readRect(const Rect& r, CMsgHandler* handler);
private:
- RREDecoder(CMsgReader* reader);
CMsgReader* reader;
};
}
#include <rfb/rreEncode.h>
#undef BPP
-Encoder* RREEncoder::create(SMsgWriter* writer)
-{
- return new RREEncoder(writer);
-}
-
RREEncoder::RREEncoder(SMsgWriter* writer_) : writer(writer_)
{
}
class RREEncoder : public Encoder {
public:
- static Encoder* create(SMsgWriter* writer);
- virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
+ RREEncoder(SMsgWriter* writer);
virtual ~RREEncoder();
+ virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
private:
- RREEncoder(SMsgWriter* writer);
SMsgWriter* writer;
rdr::MemOutStream mos;
};
using namespace rfb;
-Decoder* RawDecoder::create(CMsgReader* reader)
-{
- return new RawDecoder(reader);
-}
-
RawDecoder::RawDecoder(CMsgReader* reader_) : reader(reader_)
{
}
class RawDecoder : public Decoder {
public:
- static Decoder* create(CMsgReader* reader);
- virtual void readRect(const Rect& r, CMsgHandler* handler);
+ RawDecoder(CMsgReader* reader);
virtual ~RawDecoder();
+ virtual void readRect(const Rect& r, CMsgHandler* handler);
private:
- RawDecoder(CMsgReader* reader);
CMsgReader* reader;
};
}
using namespace rfb;
-Encoder* RawEncoder::create(SMsgWriter* writer)
-{
- return new RawEncoder(writer);
-}
-
RawEncoder::RawEncoder(SMsgWriter* writer_) : writer(writer_)
{
}
class RawEncoder : public Encoder {
public:
- static Encoder* create(SMsgWriter* writer);
- virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
+ RawEncoder(SMsgWriter* writer);
virtual ~RawEncoder();
+ virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
private:
- RawEncoder(SMsgWriter* writer);
SMsgWriter* writer;
};
}
#include <rfb/tightDecode.h>
#undef BPP
-Decoder* TightDecoder::create(CMsgReader* reader)
-{
- return new TightDecoder(reader);
-}
-
TightDecoder::TightDecoder(CMsgReader* reader_) : reader(reader_)
{
}
class TightDecoder : public Decoder {
public:
- static Decoder* create(CMsgReader* reader);
- virtual void readRect(const Rect& r, CMsgHandler* handler);
+ TightDecoder(CMsgReader* reader);
virtual ~TightDecoder();
+ virtual void readRect(const Rect& r, CMsgHandler* handler);
private:
void tightDecode8(const Rect& r);
void directFillRect16(const Rect& r, Pixel pix);
void directFillRect32(const Rect& r, Pixel pix);
- TightDecoder(CMsgReader* reader);
-
CMsgReader* reader;
CMsgHandler* handler;
rdr::InStream* is;
#include <rfb/tightEncode.h>
#undef BPP
-Encoder* TightEncoder::create(SMsgWriter* writer)
-{
- return new TightEncoder(writer);
-}
-
TightEncoder::TightEncoder(SMsgWriter* writer_) : writer(writer_)
{
setCompressLevel(defaultCompressLevel);
class TightEncoder : public Encoder {
public:
- static Encoder* create(SMsgWriter* writer);
+ TightEncoder(SMsgWriter* writer);
+ virtual ~TightEncoder();
+
virtual void setCompressLevel(int level);
virtual void setQualityLevel(int level);
virtual void setFineQualityLevel(int quality, JPEG_SUBSAMP subsampling);
virtual int getNumRects(const Rect &r);
virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
- virtual ~TightEncoder();
private:
- TightEncoder(SMsgWriter* writer);
bool checkSolidTile(Rect& r, rdr::U32* colorPtr, bool needSameColor);
void extendSolidArea(const Rect& r, rdr::U32 colorValue, Rect& er);
void findBestSolidArea(Rect& r, rdr::U32 colorValue, Rect& bestr);
#undef CPIXEL
#undef BPP
-Decoder* ZRLEDecoder::create(CMsgReader* reader)
-{
- return new ZRLEDecoder(reader);
-}
-
ZRLEDecoder::ZRLEDecoder(CMsgReader* reader_) : reader(reader_)
{
}
class ZRLEDecoder : public Decoder {
public:
- static Decoder* create(CMsgReader* reader);
- virtual void readRect(const Rect& r, CMsgHandler* handler);
+ ZRLEDecoder(CMsgReader* reader);
virtual ~ZRLEDecoder();
+ virtual void readRect(const Rect& r, CMsgHandler* handler);
private:
- ZRLEDecoder(CMsgReader* reader);
CMsgReader* reader;
rdr::ZlibInStream zis;
};
#undef CPIXEL
#undef BPP
-Encoder* ZRLEEncoder::create(SMsgWriter* writer)
-{
- return new ZRLEEncoder(writer);
-}
-
ZRLEEncoder::ZRLEEncoder(SMsgWriter* writer_)
: writer(writer_), zos(0,0,zlibLevel), mos(129*1024)
{
class ZRLEEncoder : public Encoder {
public:
- static Encoder* create(SMsgWriter* writer);
- virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
+ ZRLEEncoder(SMsgWriter* writer);
virtual ~ZRLEEncoder();
-
+ virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
private:
- ZRLEEncoder(SMsgWriter* writer);
SMsgWriter* writer;
rdr::ZlibOutStream zos;
rdr::MemOutStream mos;