Skip to content

Commit 4bf69ca

Browse files
committed
Restructure the TigerVNC 1.2 encoder so that it uses TigerVNC's pixel translation code instead of the built-in pixel translation code in the benchmark tools. Also fix an issue whereby the bits per pixel field in rfbScreen was being set to the BPP of the client, not the server. As a result of both of these changes, the -o option now works when using the TigerVNC 1.2 encoder with the CUT active.
git-svn-id: svn+ssh://svn.code.sf.net/p/turbovnc/code/vncbenchtools/trunk@2802 799e4f7b-5fd2-41f6-823c-2ecc41bc7f0b
1 parent 3f9a7d5 commit 4bf69ca

15 files changed

+1271
-107
lines changed

misc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void InitEverything (int color_depth)
128128

129129
image->width = 1280;
130130
image->height = 1024;
131-
image->bits_per_pixel = rfbClient.format.bitsPerPixel;
131+
image->bits_per_pixel = rfbServerFormat.bitsPerPixel;
132132
image->bytes_per_line = ((image->width * image->bits_per_pixel / 8) + 3) & (~3);
133133
image->data = (char *)malloc(image->width * image->bytes_per_line);
134134

tiger-1.2.cxx

+29-13
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@
1616
* USA.
1717
*/
1818

19+
#include <rdr/Exception.h>
20+
#include <rfb/ComparingUpdateTracker.h>
21+
#include <rdr/RFBOutStream.h>
22+
#include <rfb/TightEncoder.h>
1923
#include "rfb.h"
2024

2125
static int compressLevel = 1;
2226
static int qualityLevel = 8;
2327

24-
#include <rfb/PixelFormat.h>
25-
2628
using namespace rfb;
2729

2830
rfbClientPtr cl = NULL;
31+
rdr::RFBOutStream rfbos;
2932
static rdr::U8* imageBuf = NULL;
3033
static int imageBufSize = 0;
3134

@@ -46,13 +49,11 @@ rdr::U8* getImageBuf(int required, const PixelFormat& pf)
4649
return imageBuf;
4750
}
4851

49-
#include <rdr/Exception.h>
50-
#include <rfb/TightEncoder.h>
51-
#include <rfb/ComparingUpdateTracker.h>
52-
5352
static TightEncoder *te = NULL;
5453
static TransImageGetter image_getter;
5554

55+
PixelFormat clientPF;
56+
5657
Bool compareFB = FALSE;
5758

5859
static ComparingUpdateTracker *cut = NULL;
@@ -74,14 +75,27 @@ Bool rfbSendRectEncodingTight(rfbClientPtr _cl, int x, int y, int w, int h)
7475

7576
te->setCompressLevel(compressLevel);
7677
te->setQualityLevel(qualityLevel);
78+
79+
PixelFormat serverPF(rfbServerFormat.bitsPerPixel, rfbServerFormat.depth,
80+
rfbServerFormat.bigEndian==1, rfbServerFormat.trueColour==1,
81+
rfbServerFormat.redMax, rfbServerFormat.greenMax,
82+
rfbServerFormat.blueMax, rfbServerFormat.redShift,
83+
rfbServerFormat.greenShift, rfbServerFormat.blueShift);
84+
85+
PixelFormat cpf(cl->format.bitsPerPixel, cl->format.depth,
86+
cl->format.bigEndian==1, cl->format.trueColour==1, cl->format.redMax,
87+
cl->format.greenMax, cl->format.blueMax, cl->format.redShift,
88+
cl->format.greenShift, cl->format.blueShift);
89+
clientPF = cpf;
90+
91+
if (!fb) fb = new FullFramePixelBuffer(serverPF, rfbScreen.width,
92+
rfbScreen.height, (rdr::U8 *)rfbScreen.pfbMemory, NULL);
93+
94+
image_getter.init(fb, clientPF, NULL);
95+
96+
rfbos.setptr((rdr::U8 *)&updateBuf[ublen]);
97+
7798
if (compareFB) {
78-
PixelFormat spf(rfbServerFormat.bitsPerPixel, rfbServerFormat.depth,
79-
rfbServerFormat.bigEndian==1, rfbServerFormat.trueColour==1,
80-
rfbServerFormat.redMax, rfbServerFormat.greenMax,
81-
rfbServerFormat.blueMax, rfbServerFormat.redShift,
82-
rfbServerFormat.greenShift, rfbServerFormat.blueShift);
83-
if (!fb) fb = new FullFramePixelBuffer(spf, rfbScreen.width,
84-
rfbScreen.height, (rdr::U8 *)rfbScreen.pfbMemory, NULL);
8599
if (!cut) cut = new ComparingUpdateTracker(fb);
86100
rfb::Region changed;
87101
cut->compareRect(r, &changed);
@@ -93,6 +107,8 @@ Bool rfbSendRectEncodingTight(rfbClientPtr _cl, int x, int y, int w, int h)
93107
}
94108
}
95109
else te->writeRect(r, &image_getter, NULL);
110+
111+
ublen = rfbos.getptr() - (rdr::U8 *)updateBuf;
96112
}
97113
catch (rdr::Exception e) {
98114
fprintf(stderr, "ERROR: %s\n", e.str());

tiger-1.2/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ set(SOURCES
77
rfb/JpegDecompressor.cxx
88
rfb/PixelBuffer.cxx
99
rfb/PixelFormat.cxx
10+
rfb/PixelTransformer.cxx
1011
rfb/Region.cxx
1112
rfb/TightEncoder.cxx
13+
rfb/TransImageGetter.cxx
1214
Xregion/Region.c)
1315

1416
add_library(tigervnc ${SOURCES})

tiger-1.2/rdr/RFBOutStream.h

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* Copyright (C) 2014 D. R. Commander. All Rights Reserved.
2+
*
3+
* This is free software; you can redistribute it and/or modify
4+
* it under the terms of the GNU General Public License as published by
5+
* the Free Software Foundation; either version 2 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* This software is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this software; if not, write to the Free Software
15+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16+
* USA.
17+
*/
18+
19+
//
20+
// OutStream wrapper for the buffering code used by the TurboVNC benchmark
21+
//
22+
23+
#ifndef __RDR_RFBOUTSTREAM_H__
24+
#define __RDR_RFBOUTSTREAM_H__
25+
26+
#include <rdr/OutStream.h>
27+
#include <rdr/Exception.h>
28+
#include "rfb.h"
29+
30+
extern rfbClientPtr cl;
31+
32+
namespace rdr {
33+
34+
class RFBOutStream : public OutStream {
35+
36+
public:
37+
38+
RFBOutStream() {
39+
ptr = (rdr::U8 *)&updateBuf[ublen];
40+
end = (rdr::U8 *)&updateBuf[UPDATE_BUF_SIZE];
41+
}
42+
43+
virtual ~RFBOutStream() {
44+
}
45+
46+
void writeBytes(const void* data, int length) {
47+
ublen = ptr - (rdr::U8 *)updateBuf;
48+
49+
int portionLen = UPDATE_BUF_SIZE;
50+
int compressedLen = length;
51+
char *buf = (char *)data;
52+
for(int i = 0; i < compressedLen; i += portionLen) {
53+
if(i + portionLen > compressedLen) {
54+
portionLen = compressedLen - i;
55+
}
56+
if(ublen + portionLen > UPDATE_BUF_SIZE)
57+
if(!rfbSendUpdateBuf(cl))
58+
throw Exception("rfbSendUpdateBuf() failed");
59+
memcpy(&updateBuf[ublen], &buf[i], portionLen);
60+
ublen += portionLen;
61+
}
62+
63+
ptr = (rdr::U8 *)&updateBuf[ublen];
64+
}
65+
66+
int length() { return ublen; }
67+
68+
protected:
69+
70+
int overrun(int itemSize, int nItems) {
71+
ublen = ptr - (rdr::U8 *)updateBuf;
72+
73+
if(ublen + itemSize * nItems > UPDATE_BUF_SIZE)
74+
if(!rfbSendUpdateBuf(cl))
75+
throw Exception("rfbSendUpdateBuf() failed");
76+
77+
if(ublen + itemSize * nItems > UPDATE_BUF_SIZE)
78+
throw Exception("Not enough room in buffer");
79+
80+
ptr = (rdr::U8 *)&updateBuf[ublen];
81+
82+
return nItems;
83+
}
84+
85+
};
86+
87+
}
88+
89+
#endif

tiger-1.2/rfb/ColourCube.h

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2+
*
3+
* This is free software; you can redistribute it and/or modify
4+
* it under the terms of the GNU General Public License as published by
5+
* the Free Software Foundation; either version 2 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* This software is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this software; if not, write to the Free Software
15+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16+
* USA.
17+
*/
18+
//
19+
// ColourCube - structure to represent a colour cube. The colour cube consists
20+
// of its dimensions (nRed x nGreen x nBlue) and a table mapping an (r,g,b)
21+
// triple to a pixel value.
22+
//
23+
// A colour cube is used in two cases. The first is internally in a viewer
24+
// when it cannot use a trueColour format, nor can it have exclusive access to
25+
// a writable colour map. This is most notably the case for an X viewer
26+
// wishing to use a PseudoColor X server's default colormap.
27+
//
28+
// The second use is on the server side when a client has asked for a colour
29+
// map and the server is trueColour. Instead of setting an uneven trueColour
30+
// format like bgr233, it can set the client's colour map up with a 6x6x6
31+
// colour cube. For this use the colour cube table has a null mapping, which
32+
// makes it easy to perform the reverse lookup operation from pixel value to
33+
// r,g,b values.
34+
35+
#ifndef __RFB_COLOURCUBE_H__
36+
#define __RFB_COLOURCUBE_H__
37+
38+
#include <rfb/Pixel.h>
39+
#include <rfb/ColourMap.h>
40+
41+
namespace rfb {
42+
43+
class ColourCube : public ColourMap {
44+
public:
45+
ColourCube(int nr, int ng, int nb, Pixel* table_=0)
46+
: nRed(nr), nGreen(ng), nBlue(nb), table(table_), deleteTable(false)
47+
{
48+
if (!table) {
49+
table = new Pixel[size()];
50+
deleteTable = true;
51+
// set a null mapping by default
52+
for (int i = 0; i < size(); i++)
53+
table[i] = i;
54+
}
55+
}
56+
57+
ColourCube() : deleteTable(false) {}
58+
59+
virtual ~ColourCube() {
60+
if (deleteTable) delete [] table;
61+
}
62+
63+
void set(int r, int g, int b, Pixel p) {
64+
table[(r * nGreen + g) * nBlue + b] = p;
65+
}
66+
67+
Pixel lookup(int r, int g, int b) const {
68+
return table[(r * nGreen + g) * nBlue + b];
69+
}
70+
71+
int size() const { return nRed*nGreen*nBlue; }
72+
int redMult() const { return nGreen*nBlue; }
73+
int greenMult() const { return nBlue; }
74+
int blueMult() const { return 1; }
75+
76+
// ColourMap lookup() method. Note that this only works when the table has
77+
// the default null mapping.
78+
virtual void lookup(int i, int* r, int* g, int* b) {
79+
if (i >= size()) return;
80+
*b = i % nBlue;
81+
i /= nBlue;
82+
*g = i % nGreen;
83+
*r = i / nGreen;
84+
*r = (*r * 65535 + (nRed-1) / 2) / (nRed-1);
85+
*g = (*g * 65535 + (nGreen-1) / 2) / (nGreen-1);
86+
*b = (*b * 65535 + (nBlue-1) / 2) / (nBlue-1);
87+
}
88+
89+
int nRed;
90+
int nGreen;
91+
int nBlue;
92+
Pixel* table;
93+
bool deleteTable;
94+
};
95+
}
96+
#endif

tiger-1.2/rfb/ComparingUpdateTracker.cxx

+12-7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ ComparingUpdateTracker::~ComparingUpdateTracker()
3838

3939
void ComparingUpdateTracker::compareRect(const Rect& r, Region* newChanged)
4040
{
41+
if (!r.enclosed_by(fb->getRect())) {
42+
Rect safe;
43+
// Crop the rect and try again
44+
safe = r.intersect(fb->getRect());
45+
if (!safe.is_empty())
46+
compareRect(safe, newChanged);
47+
return;
48+
}
49+
4150
if (firstCompare) {
4251
// NB: We leave the change region untouched on this iteration,
4352
// since in effect the entire framebuffer has changed.
@@ -49,14 +58,10 @@ void ComparingUpdateTracker::compareRect(const Rect& r, Region* newChanged)
4958
oldFb.imageRect(pos, srcData, srcStride);
5059
}
5160
firstCompare = false;
52-
}
5361

54-
if (!r.enclosed_by(fb->getRect())) {
55-
Rect safe;
56-
// Crop the rect and try again
57-
safe = r.intersect(fb->getRect());
58-
if (!safe.is_empty())
59-
compareRect(safe, newChanged);
62+
Region temp;
63+
temp.reset(fb->getRect());
64+
newChanged->assign_union(temp);
6065
return;
6166
}
6267

0 commit comments

Comments
 (0)