using namespace rfb;
-rdr::MemOutStream* ZRLEEncoder::sharedMos = 0;
-int ZRLEEncoder::maxLen = 4097 * 1024; // enough for width 16384 32-bit pixels
-
IntParameter zlibLevel("ZlibLevel","Zlib compression level",-1);
#define EXTRA_ARGS ImageGetter* ig
}
ZRLEEncoder::ZRLEEncoder(SMsgWriter* writer_)
- : writer(writer_), zos(0,0,zlibLevel)
+ : writer(writer_), zos(0,0,zlibLevel), mos(129*1024)
{
- if (sharedMos)
- mos = sharedMos;
- else
- mos = new rdr::MemOutStream(129*1024);
}
ZRLEEncoder::~ZRLEEncoder()
{
- if (!sharedMos)
- delete mos;
}
bool ZRLEEncoder::writeRect(const Rect& r, TransImageGetter* ig, Rect* actual)
{
rdr::U8* imageBuf = writer->getImageBuf(64 * 64 * 4 + 4);
- mos->clear();
+ mos.clear();
bool wroteAll = true;
*actual = r;
switch (writer->bpp()) {
case 8:
- wroteAll = zrleEncode8(r, mos, &zos, imageBuf, maxLen, actual, ig);
+ wroteAll = zrleEncode8(r, &mos, &zos, imageBuf, actual, ig);
break;
case 16:
- wroteAll = zrleEncode16(r, mos, &zos, imageBuf, maxLen, actual, ig);
+ wroteAll = zrleEncode16(r, &mos, &zos, imageBuf, actual, ig);
break;
case 32:
{
if ((fitsInLS3Bytes && pf.isLittleEndian()) ||
(fitsInMS3Bytes && pf.isBigEndian()))
{
- wroteAll = zrleEncode24A(r, mos, &zos, imageBuf, maxLen, actual, ig);
+ wroteAll = zrleEncode24A(r, &mos, &zos, imageBuf, actual, ig);
}
else if ((fitsInLS3Bytes && pf.isBigEndian()) ||
(fitsInMS3Bytes && pf.isLittleEndian()))
{
- wroteAll = zrleEncode24B(r, mos, &zos, imageBuf, maxLen, actual, ig);
+ wroteAll = zrleEncode24B(r, &mos, &zos, imageBuf, actual, ig);
}
else
{
- wroteAll = zrleEncode32(r, mos, &zos, imageBuf, maxLen, actual, ig);
+ wroteAll = zrleEncode32(r, &mos, &zos, imageBuf, actual, ig);
}
break;
}
writer->startRect(*actual, encodingZRLE);
rdr::OutStream* os = writer->getOutStream();
- os->writeU32(mos->length());
- os->writeBytes(mos->data(), mos->length());
+ os->writeU32(mos.length());
+ os->writeBytes(mos.data(), mos.length());
writer->endRect();
return wroteAll;
}
virtual bool writeRect(const Rect& r, TransImageGetter* ig, Rect* actual);
virtual ~ZRLEEncoder();
- // setMaxLen() sets the maximum size in bytes of any ZRLE rectangle. This
- // can be used to stop the MemOutStream from growing too large. The value
- // must be large enough to allow for at least one row of ZRLE tiles. So
- // for example for a screen width of 2048 32-bit pixels this is 2K*4*64 =
- // 512Kbytes plus a bit of overhead (the overhead is about 1/16 of the
- // width, in this example about 128 bytes).
- static void setMaxLen(int m) { maxLen = m; }
-
- // setSharedMos() sets a MemOutStream to be shared amongst all
- // ZRLEEncoders. Should be called before any ZRLEEncoders are created.
- static void setSharedMos(rdr::MemOutStream* mos_) { sharedMos = mos_; }
-
private:
ZRLEEncoder(SMsgWriter* writer);
SMsgWriter* writer;
rdr::ZlibOutStream zos;
- rdr::MemOutStream* mos;
- static rdr::MemOutStream* sharedMos;
- static int maxLen;
+ rdr::MemOutStream mos;
};
}
#endif
void ZRLE_ENCODE_TILE (PIXEL_T* data, int w, int h, rdr::OutStream* os);
bool ZRLE_ENCODE (const Rect& r, rdr::OutStream* os,
- rdr::ZlibOutStream* zos, void* buf, int maxLen, Rect* actual
+ rdr::ZlibOutStream* zos, void* buf, Rect* actual
#ifdef EXTRA_ARGS
, EXTRA_ARGS
#endif
t.br.y = __rfbmin(r.br.y, t.tl.y + 64);
- if (os->length() + worstCaseLine > maxLen) {
+ // enough for width 16384 32-bit pixels
+ if (os->length() + worstCaseLine > 4097 * 1024) {
if (t.tl.y == r.tl.y)
throw Exception("ZRLE: not enough space for first line?");
actual->tl = r.tl;