*nPixels = imageBufSize / (handler->cp.pf().bpp / 8);
return imageBuf;
}
-
-int CMsgReader::bpp()
-{
- return handler->cp.pf().bpp;
-}
rdr::InStream* getInStream() { return is; }
rdr::U8* getImageBuf(int required, int requested=0, int* nPixels=0);
- int bpp();
int imageBufIdealSize;
void writeFence(rdr::U32 flags, unsigned len, const char data[]);
- ConnParams* getConnParams() { return cp; }
- rdr::OutStream* getOutStream() { return os; }
-
// InputHandler implementation
virtual void keyEvent(rdr::U32 key, bool down);
* USA.
*/
#include <rdr/InStream.h>
-#include <rfb/CMsgReader.h>
+#include <rfb/CConnection.h>
#include <rfb/CMsgHandler.h>
#include <rfb/PixelBuffer.h>
#include <rfb/CopyRectDecoder.h>
using namespace rfb;
-CopyRectDecoder::CopyRectDecoder(CMsgReader* reader) : Decoder(reader)
+CopyRectDecoder::CopyRectDecoder(CConnection* conn) : Decoder(conn)
{
}
void CopyRectDecoder::readRect(const Rect& r, CMsgHandler* handler)
{
- int srcX = reader->getInStream()->readU16();
- int srcY = reader->getInStream()->readU16();
+ int srcX = conn->getInStream()->readU16();
+ int srcY = conn->getInStream()->readU16();
handler->copyRect(r, srcX, srcY);
}
class CopyRectDecoder : public Decoder {
public:
- CopyRectDecoder(CMsgReader* reader);
+ CopyRectDecoder(CConnection* conn);
virtual ~CopyRectDecoder();
virtual void readRect(const Rect& r, CMsgHandler* handler);
};
using namespace rfb;
-Decoder::Decoder(CMsgReader* reader_) : reader(reader_)
+Decoder::Decoder(CConnection* conn_) : conn(conn_)
{
}
}
}
-Decoder* Decoder::createDecoder(int encoding, CMsgReader* reader)
+Decoder* Decoder::createDecoder(int encoding, CConnection* conn)
{
switch (encoding) {
case encodingRaw:
- return new RawDecoder(reader);
+ return new RawDecoder(conn);
case encodingCopyRect:
- return new CopyRectDecoder(reader);
+ return new CopyRectDecoder(conn);
case encodingRRE:
- return new RREDecoder(reader);
+ return new RREDecoder(conn);
case encodingHextile:
- return new HextileDecoder(reader);
+ return new HextileDecoder(conn);
case encodingZRLE:
- return new ZRLEDecoder(reader);
+ return new ZRLEDecoder(conn);
case encodingTight:
- return new TightDecoder(reader);
+ return new TightDecoder(conn);
default:
return NULL;
}
#include <rfb/Rect.h>
namespace rfb {
- class CMsgReader;
+ class CConnection;
class CMsgHandler;
class Decoder {
public:
- Decoder(CMsgReader* reader);
+ Decoder(CConnection* conn);
virtual ~Decoder();
virtual void readRect(const Rect& r, CMsgHandler* handler)=0;
static bool supported(int encoding);
- static Decoder* createDecoder(int encoding, CMsgReader* reader);
+ static Decoder* createDecoder(int encoding, CConnection* conn);
protected:
- CMsgReader* reader;
+ CConnection* conn;
};
}
#include <rfb/HextileEncoder.h>
#include <rfb/ZRLEEncoder.h>
#include <rfb/TightEncoder.h>
-#include <rfb/SMsgWriter.h>
+#include <rfb/SConnection.h>
using namespace rfb;
-Encoder::Encoder(SMsgWriter* writer_) : writer(writer_)
+Encoder::Encoder(SConnection *conn_) : conn(conn_)
{
}
}
}
-Encoder* Encoder::createEncoder(int encoding, SMsgWriter* writer)
+Encoder* Encoder::createEncoder(int encoding, SConnection* conn)
{
switch (encoding) {
case encodingRaw:
- return new RawEncoder(writer);
+ return new RawEncoder(conn);
case encodingRRE:
- return new RREEncoder(writer);
+ return new RREEncoder(conn);
case encodingHextile:
- return new HextileEncoder(writer);
+ return new HextileEncoder(conn);
case encodingZRLE:
- return new ZRLEEncoder(writer);
+ return new ZRLEEncoder(conn);
case encodingTight:
- return new TightEncoder(writer);
+ return new TightEncoder(conn);
default:
return NULL;
}
#include <rfb/TransImageGetter.h>
namespace rfb {
- class SMsgWriter;
+ class SConnection;
class TransImageGetter;
class Encoder {
public:
- Encoder(SMsgWriter* writer);
+ Encoder(SConnection* conn);
virtual ~Encoder();
virtual void setCompressLevel(int level) {};
virtual void writeRect(const Rect& r, TransImageGetter* ig)=0;
static bool supported(int encoding);
- static Encoder* createEncoder(int encoding, SMsgWriter* writer);
+ static Encoder* createEncoder(int encoding, SConnection* conn);
protected:
- SMsgWriter* writer;
+ SConnection* conn;
};
}
* USA.
*/
#include <rfb/CMsgReader.h>
+#include <rfb/CConnection.h>
#include <rfb/CMsgHandler.h>
#include <rfb/HextileDecoder.h>
#include <rfb/hextileDecode.h>
#undef BPP
-HextileDecoder::HextileDecoder(CMsgReader* reader) : Decoder(reader)
+HextileDecoder::HextileDecoder(CConnection* conn) : Decoder(conn)
{
}
void HextileDecoder::readRect(const Rect& r, CMsgHandler* handler)
{
- rdr::InStream* is = reader->getInStream();
- rdr::U8* buf = reader->getImageBuf(16 * 16 * 4);
- switch (reader->bpp()) {
+ rdr::InStream* is = conn->getInStream();
+ rdr::U8* buf = conn->reader()->getImageBuf(16 * 16 * 4);
+ switch (conn->cp.pf().bpp) {
case 8: hextileDecode8 (r, is, (rdr::U8*) buf, handler); break;
case 16: hextileDecode16(r, is, (rdr::U16*)buf, handler); break;
case 32: hextileDecode32(r, is, (rdr::U32*)buf, handler); break;
class HextileDecoder : public Decoder {
public:
- HextileDecoder(CMsgReader* reader);
+ HextileDecoder(CConnection* conn);
virtual ~HextileDecoder();
virtual void readRect(const Rect& r, CMsgHandler* handler);
};
#include <rfb/TransImageGetter.h>
#include <rfb/encodings.h>
#include <rfb/SMsgWriter.h>
+#include <rfb/SConnection.h>
#include <rfb/HextileEncoder.h>
#include <rfb/Configuration.h>
#include <rfb/hextileEncodeBetter.h>
#undef BPP
-HextileEncoder::HextileEncoder(SMsgWriter* writer_) : Encoder(writer_)
+HextileEncoder::HextileEncoder(SConnection* conn) : Encoder(conn)
{
}
void HextileEncoder::writeRect(const Rect& r, TransImageGetter* ig)
{
- writer->startRect(r, encodingHextile);
- rdr::OutStream* os = writer->getOutStream();
- switch (writer->bpp()) {
+ conn->writer()->startRect(r, encodingHextile);
+ rdr::OutStream* os = conn->getOutStream();
+ switch (conn->cp.pf().bpp) {
case 8:
if (improvedHextile) {
hextileEncodeBetter8(r, os, ig);
}
break;
}
- writer->endRect();
+ conn->writer()->endRect();
}
class HextileEncoder : public Encoder {
public:
- HextileEncoder(SMsgWriter* writer);
+ HextileEncoder(SConnection* conn);
virtual ~HextileEncoder();
virtual void writeRect(const Rect& r, TransImageGetter* ig);
};
* USA.
*/
#include <rfb/CMsgReader.h>
+#include <rfb/CConnection.h>
#include <rfb/CMsgHandler.h>
#include <rfb/RREDecoder.h>
#include <rfb/rreDecode.h>
#undef BPP
-RREDecoder::RREDecoder(CMsgReader* reader) : Decoder(reader)
+RREDecoder::RREDecoder(CConnection* conn) : Decoder(conn)
{
}
void RREDecoder::readRect(const Rect& r, CMsgHandler* handler)
{
- rdr::InStream* is = reader->getInStream();
- switch (reader->bpp()) {
+ rdr::InStream* is = conn->getInStream();
+ switch (conn->cp.pf().bpp) {
case 8: rreDecode8 (r, is, handler); break;
case 16: rreDecode16(r, is, handler); break;
case 32: rreDecode32(r, is, handler); break;
class RREDecoder : public Decoder {
public:
- RREDecoder(CMsgReader* reader);
+ RREDecoder(CConnection* conn);
virtual ~RREDecoder();
virtual void readRect(const Rect& r, CMsgHandler* handler);
};
#include <rfb/TransImageGetter.h>
#include <rfb/encodings.h>
#include <rfb/SMsgWriter.h>
+#include <rfb/SConnection.h>
#include <rfb/RREEncoder.h>
using namespace rfb;
#include <rfb/rreEncode.h>
#undef BPP
-RREEncoder::RREEncoder(SMsgWriter* writer) : RawEncoder(writer)
+RREEncoder::RREEncoder(SConnection* conn) : RawEncoder(conn)
{
}
{
int w = r.width();
int h = r.height();
- rdr::U8* imageBuf = writer->getImageBuf(w*h);
+ rdr::U8* imageBuf = conn->writer()->getImageBuf(w*h);
ig->getImage(imageBuf, r);
mos.clear();
int nSubrects = -1;
- switch (writer->bpp()) {
+ switch (conn->cp.pf().bpp) {
case 8: nSubrects = rreEncode8(imageBuf, w, h, &mos); break;
case 16: nSubrects = rreEncode16(imageBuf, w, h, &mos); break;
case 32: nSubrects = rreEncode32(imageBuf, w, h, &mos); break;
return;
}
- writer->startRect(r, encodingRRE);
- rdr::OutStream* os = writer->getOutStream();
+ conn->writer()->startRect(r, encodingRRE);
+ rdr::OutStream* os = conn->getOutStream();
os->writeU32(nSubrects);
os->writeBytes(mos.data(), mos.length());
- writer->endRect();
+ conn->writer()->endRect();
}
class RREEncoder : public RawEncoder {
public:
- RREEncoder(SMsgWriter* writer);
+ RREEncoder(SConnection* conn);
virtual ~RREEncoder();
virtual void writeRect(const Rect& r, TransImageGetter* ig);
private:
*/
#include <rdr/InStream.h>
#include <rfb/CMsgReader.h>
+#include <rfb/CConnection.h>
#include <rfb/CMsgHandler.h>
#include <rfb/RawDecoder.h>
using namespace rfb;
-RawDecoder::RawDecoder(CMsgReader* reader) : Decoder(reader)
+RawDecoder::RawDecoder(CConnection* conn) : Decoder(conn)
{
}
int w = r.width();
int h = r.height();
int nPixels;
- rdr::U8* imageBuf = reader->getImageBuf(w, w*h, &nPixels);
- int bytesPerRow = w * (reader->bpp() / 8);
+ rdr::U8* imageBuf = conn->reader()->getImageBuf(w, w*h, &nPixels);
+ int bytesPerRow = w * (conn->cp.pf().bpp / 8);
while (h > 0) {
int nRows = nPixels / w;
if (nRows > h) nRows = h;
- reader->getInStream()->readBytes(imageBuf, nRows * bytesPerRow);
+ conn->getInStream()->readBytes(imageBuf, nRows * bytesPerRow);
handler->imageRect(Rect(x, y, x+w, y+nRows), imageBuf);
h -= nRows;
y += nRows;
class RawDecoder : public Decoder {
public:
- RawDecoder(CMsgReader* reader);
+ RawDecoder(CConnection* conn);
virtual ~RawDecoder();
virtual void readRect(const Rect& r, CMsgHandler* handler);
};
#include <rfb/TransImageGetter.h>
#include <rfb/encodings.h>
#include <rfb/SMsgWriter.h>
+#include <rfb/SConnection.h>
#include <rfb/RawEncoder.h>
using namespace rfb;
-RawEncoder::RawEncoder(SMsgWriter* writer) : Encoder(writer)
+RawEncoder::RawEncoder(SConnection* conn) : Encoder(conn)
{
}
int w = r.width();
int h = r.height();
int nPixels;
- rdr::U8* imageBuf = writer->getImageBuf(w, w*h, &nPixels);
- int bytesPerRow = w * (writer->bpp() / 8);
- writer->startRect(r, encodingRaw);
+ rdr::U8* imageBuf = conn->writer()->getImageBuf(w, w*h, &nPixels);
+ int bytesPerRow = w * (conn->cp.pf().bpp / 8);
+ conn->writer()->startRect(r, encodingRaw);
while (h > 0) {
int nRows = nPixels / w;
if (nRows > h) nRows = h;
ig->getImage(imageBuf, Rect(x, y, x+w, y+nRows));
- writer->getOutStream()->writeBytes(imageBuf, nRows * bytesPerRow);
+ conn->getOutStream()->writeBytes(imageBuf, nRows * bytesPerRow);
h -= nRows;
y += nRows;
}
- writer->endRect();
+ conn->writer()->endRect();
}
class RawEncoder : public Encoder {
public:
- RawEncoder(SMsgWriter* writer);
+ RawEncoder(SConnection* conn);
virtual ~RawEncoder();
virtual void writeRect(const Rect& r, TransImageGetter* ig);
};
currentEncoding = encoding;
lenBeforeRect = os->length();
if (encoding != encodingCopyRect)
- rawBytesEquivalent += 12 + r.width() * r.height() * (bpp()/8);
+ rawBytesEquivalent += 12 + r.width() * r.height() * (cp->pf().bpp/8);
os->writeS16(r.tl.x);
os->writeS16(r.tl.y);
return imageBuf;
}
-int SMsgWriter::bpp()
-{
- return cp->pf().bpp;
-}
-
void SMsgWriter::startMsg(int type)
{
os->writeU8(type);
void startRect(const Rect& r, int enc);
void endRect();
- ConnParams* getConnParams() { return cp; }
- rdr::OutStream* getOutStream() { return os; }
rdr::U8* getImageBuf(int required, int requested=0, int* nPixels=0);
- int bpp();
int getUpdatesSent() { return updatesSent; }
int getRectsSent(int encoding) { return rectsSent[encoding]; }
* USA.
*/
#include <rfb/CMsgReader.h>
+#include <rfb/CConnection.h>
#include <rfb/CMsgHandler.h>
#include <rfb/TightDecoder.h>
#include <rfb/tightDecode.h>
#undef BPP
-TightDecoder::TightDecoder(CMsgReader* reader) : Decoder(reader)
+TightDecoder::TightDecoder(CConnection* conn) : Decoder(conn)
{
}
void TightDecoder::readRect(const Rect& r, CMsgHandler* handler)
{
- is = reader->getInStream();
+ is = conn->getInStream();
this->handler = handler;
clientpf = handler->getPreferredPF();
serverpf = handler->cp.pf();
class TightDecoder : public Decoder {
public:
- TightDecoder(CMsgReader* reader);
+ TightDecoder(CConnection* conn);
virtual ~TightDecoder();
virtual void readRect(const Rect& r, CMsgHandler* handler);
#include <rfb/encodings.h>
#include <rfb/ConnParams.h>
#include <rfb/SMsgWriter.h>
+#include <rfb/SConnection.h>
#include <rfb/TightEncoder.h>
using namespace rfb;
#include <rfb/tightEncode.h>
#undef BPP
-TightEncoder::TightEncoder(SMsgWriter* writer) : Encoder(writer)
+TightEncoder::TightEncoder(SConnection* conn) : Encoder(conn)
{
setCompressLevel(defaultCompressLevel);
setQualityLevel(-1);
int TightEncoder::getNumRects(const Rect &r)
{
- ConnParams* cp = writer->getConnParams();
+ ConnParams* cp = &conn->cp;
const unsigned int w = r.width();
const unsigned int h = r.height();
{
ig = _ig;
serverpf = ig->getPixelBuffer()->getPF();
- ConnParams* cp = writer->getConnParams();
+ ConnParams* cp = &conn->cp;
clientpf = cp->pf();
// Shortcuts to rectangle coordinates and dimensions.
tightEncode32(r, &mos, forceSolid); break;
}
- writer->startRect(r, encodingTight);
- rdr::OutStream* os = writer->getOutStream();
+ conn->writer()->startRect(r, encodingTight);
+ rdr::OutStream* os = conn->getOutStream();
os->writeBytes(mos.data(), mos.length());
- writer->endRect();
+ conn->writer()->endRect();
}
void TightEncoder::writeCompact(rdr::OutStream* os, rdr::U32 value)
class TightEncoder : public Encoder {
public:
- TightEncoder(SMsgWriter* writer);
+ TightEncoder(SConnection* conn);
virtual ~TightEncoder();
virtual void setCompressLevel(int level);
encoding = cp.currentEncoding();
if (!encoders[encoding])
- encoders[encoding] = Encoder::createEncoder(encoding, writer());
+ encoders[encoding] = Encoder::createEncoder(encoding, this);
encoders[encoding]->setCompressLevel(cp.compressLevel);
encoders[encoding]->setQualityLevel(cp.qualityLevel);
* USA.
*/
#include <rfb/CMsgReader.h>
+#include <rfb/CConnection.h>
#include <rfb/CMsgHandler.h>
#include <rfb/ZRLEDecoder.h>
#undef CPIXEL
#undef BPP
-ZRLEDecoder::ZRLEDecoder(CMsgReader* reader) : Decoder(reader)
+ZRLEDecoder::ZRLEDecoder(CConnection* conn) : Decoder(conn)
{
}
void ZRLEDecoder::readRect(const Rect& r, CMsgHandler* handler)
{
- rdr::InStream* is = reader->getInStream();
- rdr::U8* buf = reader->getImageBuf(64 * 64 * 4);
- switch (reader->bpp()) {
+ rdr::InStream* is = conn->getInStream();
+ rdr::U8* buf = conn->reader()->getImageBuf(64 * 64 * 4);
+ switch (conn->cp.pf().bpp) {
case 8: zrleDecode8 (r, is, &zis, (rdr::U8*) buf, handler); break;
case 16: zrleDecode16(r, is, &zis, (rdr::U16*)buf, handler); break;
case 32:
class ZRLEDecoder : public Decoder {
public:
- ZRLEDecoder(CMsgReader* reader);
+ ZRLEDecoder(CConnection* conn);
virtual ~ZRLEDecoder();
virtual void readRect(const Rect& r, CMsgHandler* handler);
private:
#include <rfb/encodings.h>
#include <rfb/ConnParams.h>
#include <rfb/SMsgWriter.h>
+#include <rfb/SConnection.h>
#include <rfb/ZRLEEncoder.h>
#include <rfb/Configuration.h>
#undef CPIXEL
#undef BPP
-ZRLEEncoder::ZRLEEncoder(SMsgWriter* writer)
- : Encoder(writer), zos(0,0,zlibLevel), mos(129*1024)
+ZRLEEncoder::ZRLEEncoder(SConnection* conn)
+ : Encoder(conn), zos(0,0,zlibLevel), mos(129*1024)
{
}
void ZRLEEncoder::writeRect(const Rect& r, TransImageGetter* ig)
{
- rdr::U8* imageBuf = writer->getImageBuf(64 * 64 * 4 + 4);
+ rdr::U8* imageBuf = conn->writer()->getImageBuf(64 * 64 * 4 + 4);
mos.clear();
- switch (writer->bpp()) {
+ switch (conn->cp.pf().bpp) {
case 8:
zrleEncode8(r, &mos, &zos, imageBuf, ig);
break;
break;
case 32:
{
- const PixelFormat& pf = writer->getConnParams()->pf();
+ const PixelFormat& pf = conn->cp.pf();
Pixel maxPixel = pf.pixelFromRGB((rdr::U16)-1, (rdr::U16)-1, (rdr::U16)-1);
bool fitsInLS3Bytes = maxPixel < (1<<24);
}
}
- writer->startRect(r, encodingZRLE);
- rdr::OutStream* os = writer->getOutStream();
+ conn->writer()->startRect(r, encodingZRLE);
+ rdr::OutStream* os = conn->getOutStream();
os->writeU32(mos.length());
os->writeBytes(mos.data(), mos.length());
- writer->endRect();
+ conn->writer()->endRect();
}
class ZRLEEncoder : public Encoder {
public:
- ZRLEEncoder(SMsgWriter* writer);
+ ZRLEEncoder(SConnection* conn);
virtual ~ZRLEEncoder();
virtual void writeRect(const Rect& r, TransImageGetter* ig);
private:
PIXEL_T *buf;
int stride = r.width();
if (directDecode) buf = (PIXEL_T *)handler->getRawBufferRW(r, &stride);
- else buf = (PIXEL_T *)reader->getImageBuf(r.area());
+ else buf = (PIXEL_T *)conn->reader()->getImageBuf(r.area());
if (palSize == 0) {
// Truecolor data
// JPEG can read from the raw buffer, but for the other methods, we need
// to translate the raw pixels into an intermediate buffer.
if(palette.size() != 0 || jpegQuality == -1) {
- pixels = (PIXEL_T *)writer->getImageBuf(r.area());
+ pixels = (PIXEL_T *)conn->writer()->getImageBuf(r.area());
stride = r.width();
ig->getImage(pixels, r);
}
} else {
// Pixel translation will be required, so create an intermediate buffer,
// translate the raw pixels into it, and count its colors.
- pixels = (PIXEL_T *)writer->getImageBuf(r.area());
+ pixels = (PIXEL_T *)conn->writer()->getImageBuf(r.area());
stride = r.width();
ig->getImage(pixels, r);
}
if (!decoders[encoding]) {
- decoders[encoding] = Decoder::createDecoder(encoding, reader());
+ decoders[encoding] = Decoder::createDecoder(encoding, this);
if (!decoders[encoding]) {
fprintf(stderr, "Unknown rect encoding %d\n", encoding);
throw Exception("Unknown rect encoding");