Move image encoding logic into a central EncodeManager class
This allows us to apply a lot more server logic
independently of which encoder is in use.
Most of this class are things moved over from the
Tight encoder.
diff --git a/common/rfb/RawEncoder.cxx b/common/rfb/RawEncoder.cxx
index e50ebc7..4090427 100644
--- a/common/rfb/RawEncoder.cxx
+++ b/common/rfb/RawEncoder.cxx
@@ -1,4 +1,5 @@
/* 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
@@ -17,14 +18,14 @@
*/
#include <rdr/OutStream.h>
#include <rfb/encodings.h>
-#include <rfb/SMsgWriter.h>
#include <rfb/SConnection.h>
#include <rfb/PixelBuffer.h>
#include <rfb/RawEncoder.h>
using namespace rfb;
-RawEncoder::RawEncoder(SConnection* conn) : Encoder(conn)
+RawEncoder::RawEncoder(SConnection* conn) :
+ Encoder(conn, encodingRaw, EncoderPlain, -1)
{
}
@@ -32,13 +33,44 @@
{
}
-void RawEncoder::writeRect(const Rect& r, PixelBuffer* pb)
+bool RawEncoder::isSupported()
{
- rdr::U8* buf = conn->writer()->getImageBuf(r.area());
+ // Implicitly required;
+ return true;
+}
- pb->getImage(conn->cp.pf(), buf, r);
+void RawEncoder::writeRect(const PixelBuffer* pb, const Palette& palette)
+{
+ const rdr::U8* buffer;
+ int stride;
- conn->writer()->startRect(r, encodingRaw);
- conn->getOutStream()->writeBytes(buf, r.area() * conn->cp.pf().bpp/8);
- conn->writer()->endRect();
+ rdr::OutStream* os;
+ int h, line_bytes, stride_bytes;
+
+ buffer = pb->getBuffer(pb->getRect(), &stride);
+
+ os = conn->getOutStream();
+
+ h = pb->height();
+ line_bytes = pb->width() * pb->getPF().bpp/8;
+ stride_bytes = stride * pb->getPF().bpp/8;
+ while (h--) {
+ os->writeBytes(buffer, line_bytes);
+ buffer += stride_bytes;
+ }
+}
+
+void RawEncoder::writeSolidRect(int width, int height,
+ const PixelFormat& pf,
+ const rdr::U8* colour)
+{
+ rdr::OutStream* os;
+ int pixels, pixel_size;
+
+ os = conn->getOutStream();
+
+ pixels = width*height;
+ pixel_size = pf.bpp/8;
+ while (pixels--)
+ os->writeBytes(colour, pixel_size);
}