Commit 80af0519 authored by Urs Wolfer's avatar Urs Wolfer

Add 16 bpp color support, make low quality use 8bpp, medium 16 bpp and hight 32 bpp.

Patch by Patch by Wouter Van Meir <wouter.vanmeir pandora.be>, thanks.

svn path=/trunk/KDE/kdenetwork/krdc/; revision=1157496
parent 6620ed72
......@@ -17,10 +17,9 @@ Copy these files into a folder and run:
make
In order to try it out, type:
./krdc-vnc-qtonly vnc://:password@server:1 1 [8bit]
(the 2nd argument defines the quality as second argument (1-3, where 1 is
the best). Default is 2.
optionally use a 3rd argument "8bit" to use only 8bit color. This lowers network traffic.)
./krdc-vnc-qtonly vnc://:password@server:1 1
(the last argument defines the quality as second argument (1-3, where 1 is
the best). Default is 2.)
If you use these code in your project, make sure that QTONLY is defined (see
krdc-vnc-qtonly.pro).
......
......@@ -30,8 +30,7 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
if (QCoreApplication::arguments().count() < 2) {
qFatal("Please define an URL as argument. Example: vnc://:password@server:1\n"
"Optionally, you can define the quality as second argument (1-3, where 1 is the best). Default is 2.\n"
"Optionally, you can use 8bit as 3rd argument for 8bit color depth (default is 32)");
"Optionally, you can define the quality as second argument (1-3, where 1 is the best). Default is 2.");
return 1;
}
VncView vncView(0, QCoreApplication::arguments().at(1));
......
......@@ -32,17 +32,10 @@ static QString outputErrorMessageString;
QVector<QRgb> VncClientThread::m_colorTable;
rfbBool VncClientThread::newclient(rfbClient *cl)
void VncClientThread::setClientColorDepth(rfbClient* cl, VncClientThread::ColorDepth cd)
{
VncClientThread *t = (VncClientThread*)rfbClientGetClientData(cl, 0);
Q_ASSERT(t);
//8bit color hack for Intel(r) AMT KVM "classic vnc" = vnc server built in in Intel Vpro chipsets.
if (INTEL_AMT_KVM_STRING == cl->desktopName) {
kDebug(5011) << "Intel(R) AMT KVM: switching to 8 bit color depth (workaround, recent libvncserver needed)";
t->setUse8BitColors(true);
}
if (t->use8BitColors()) {
switch(cd) {
case bpp8:
if (m_colorTable.isEmpty()) {
m_colorTable.resize(256);
int r,g,b;
......@@ -63,7 +56,19 @@ rfbBool VncClientThread::newclient(rfbClient *cl)
cl->format.redMax = 7;
cl->format.greenMax = 7;
cl->format.blueMax = 3;
} else {
break;
case bpp16:
cl->format.depth = 16;
cl->format.bitsPerPixel = 16;
cl->format.redShift = 11;
cl->format.greenShift = 5;
cl->format.blueShift = 0;
cl->format.redMax = 0x1f;
cl->format.greenMax = 0x3f;
cl->format.blueMax = 0x1f;
break;
case bpp32:
default:
cl->format.depth = 24;
cl->format.bitsPerPixel = 32;
cl->format.redShift = 16;
......@@ -73,6 +78,19 @@ rfbBool VncClientThread::newclient(rfbClient *cl)
cl->format.greenMax = 0xff;
cl->format.blueMax = 0xff;
}
}
rfbBool VncClientThread::newclient(rfbClient *cl)
{
VncClientThread *t = (VncClientThread*)rfbClientGetClientData(cl, 0);
Q_ASSERT(t);
//8bit color hack for Intel(r) AMT KVM "classic vnc" = vnc server built in in Intel Vpro chipsets.
if (INTEL_AMT_KVM_STRING == cl->desktopName) {
kDebug(5011) << "Intel(R) AMT KVM: switching to 8 bit color depth (workaround, recent libvncserver needed)";
t->setColorDepth(bpp8);
}
setClientColorDepth(cl, t->colorDepth());
const int width = cl->width, height = cl->height, depth = cl->format.bitsPerPixel;
const int size = width * height * (depth / 8);
......@@ -113,11 +131,17 @@ void VncClientThread::updatefb(rfbClient* cl, int x, int y, int w, int h)
const int width = cl->width, height = cl->height;
QImage img;
if (t->use8BitColors()) {
switch(t->colorDepth()) {
case bpp8:
img = QImage(cl->frameBuffer, width, height, QImage::Format_Indexed8);
img.setColorTable(m_colorTable);
} else {
break;
case bpp16:
img = QImage(cl->frameBuffer, width, height, QImage::Format_RGB16);
break;
case bpp32:
img = QImage(cl->frameBuffer, width, height, QImage::Format_RGB32);
break;
}
if (img.isNull()) {
......@@ -191,8 +215,8 @@ void VncClientThread::outputHandler(const char *format, ...)
VncClientThread::VncClientThread(QObject *parent)
: QThread(parent)
, frameBuffer(0)
, m_stopped(false)
, cl(0)
, m_stopped(false)
{
QMutexLocker locker(&mutex);
......@@ -246,11 +270,23 @@ void VncClientThread::setPort(int port)
void VncClientThread::setQuality(RemoteView::Quality quality)
{
m_quality = quality;
//set color depth dependent on quality
switch(quality) {
case RemoteView::Low:
setColorDepth(bpp8);
break;
case RemoteView::High:
setColorDepth(bpp32);
break;
case RemoteView::Medium:
default:
setColorDepth(bpp16);
}
}
void VncClientThread::setUse8BitColors(bool use8BitColors)
void VncClientThread::setColorDepth(ColorDepth colorDepth)
{
m_use8BitColors= use8BitColors;
m_colorDepth= colorDepth;
}
RemoteView::Quality VncClientThread::quality() const
......@@ -258,9 +294,9 @@ RemoteView::Quality VncClientThread::quality() const
return m_quality;
}
bool VncClientThread::use8BitColors() const
VncClientThread::ColorDepth VncClientThread::colorDepth() const
{
return m_use8BitColors;
return m_colorDepth;
}
void VncClientThread::setImage(const QImage &img)
......@@ -308,6 +344,7 @@ void VncClientThread::run()
rfbClientErr = outputHandler;
//24bit color dept in 32 bits per pixel = default. Will change colordepth and bpp later if needed
cl = rfbGetClient(8, 3, 4);
setClientColorDepth(cl, this->colorDepth());
cl->MallocFrameBuffer = newclient;
cl->canHandleNewFBSize = true;
cl->GetPassword = passwdHandler;
......
......@@ -97,6 +97,14 @@ class VncClientThread: public QThread
Q_OBJECT
public:
Q_ENUMS(ColorDepth)
enum ColorDepth {
bpp32,
bpp16,
bpp8
};
explicit VncClientThread(QObject *parent = 0);
~VncClientThread();
const QImage image(int x = 0, int y = 0, int w = 0, int h = 0);
......@@ -107,7 +115,6 @@ public:
void setHost(const QString &host);
void setPort(int port);
void setQuality(RemoteView::Quality quality);
void setUse8BitColors(bool use8BitColors);
void setPassword(const QString &password) {
m_password = password;
}
......@@ -116,7 +123,7 @@ public:
}
RemoteView::Quality quality() const;
bool use8BitColors() const;
ColorDepth colorDepth() const;
uint8_t *frameBuffer;
signals:
......@@ -134,6 +141,8 @@ protected:
void run();
private:
static void setClientColorDepth(rfbClient *cl, ColorDepth cd);
void setColorDepth(ColorDepth colorDepth);
//these static methods are callback functions for libvncclient
static rfbBool newclient(rfbClient *cl);
static void updatefb(rfbClient *cl, int x, int y, int w, int h);
......@@ -148,7 +157,7 @@ private:
int m_port;
QMutex mutex;
RemoteView::Quality m_quality;
bool m_use8BitColors;
ColorDepth m_colorDepth;
QQueue<ClientEvent* > m_eventQueue;
//color table for 8bit indexed colors
static QVector<QRgb> m_colorTable;
......
......@@ -194,20 +194,14 @@ bool VncView::start()
vncThread.setHost(m_host);
vncThread.setPort(m_port);
RemoteView::Quality quality;
bool use8BitColors;
#ifdef QTONLY
quality = (RemoteView::Quality)((QCoreApplication::arguments().count() > 2) ?
QCoreApplication::arguments().at(2).toInt() : 2);
use8BitColors = ((QCoreApplication::arguments().count() > 3) ?
(QCoreApplication::arguments().at(3) == "8bit") : false);
#else
quality = m_hostPreferences->quality();
//don't use 8bit colors by default
use8BitColors = false;
#endif
vncThread.setQuality(quality);
vncThread.setUse8BitColors(use8BitColors);
// set local cursor on by default because low quality mostly means slow internet connection
if (quality == RemoteView::Low) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment