Skip to content

Commit

Permalink
now using Sync version again
Browse files Browse the repository at this point in the history
  • Loading branch information
pkrumins committed Aug 9, 2010
1 parent 2cc9b80 commit 162bca6
Showing 1 changed file with 30 additions and 35 deletions.
65 changes: 30 additions & 35 deletions lib/resources/fb/encoder.js
Expand Up @@ -15,8 +15,7 @@ Encoder.prototype = new EventEmitter;
function Encoder (rfb) {
if (!(this instanceof Encoder)) return new Encoder(rfb);
var self = this;
var imageStack = {};
var stackCounter = 0;
var imageStack = null;
var imageType = 'png';
var bufType = 'bgr';

Expand Down Expand Up @@ -70,56 +69,52 @@ function Encoder (rfb) {

rfb.on('startRects', function (nRects) {
if (nRects > 1) {
imageStack[stackCounter] = new PngLib.DynamicPngStack(bufType);
//imageStack[stackCounter] = new PngLib.DynamicPngStack(bufType);
imageStack = new PngLib.DynamicPngStack(bufType);
}
});

rfb.on('endRects', function (nRects) {
if (nRects > 1) {
imageStack[stackCounter].encode(function (image, dims) {
var imageBuf = new Buffer(image.length);
imageBuf.write(image, 'binary');
var image = imageStack.encodeSync();
var imageBuf = new Buffer(image.length);
imageBuf.write(image, 'binary');
var dims = imageStack.dimensions();

self.emit('screenUpdate', {
base64 : base64.encode(imageBuf),
type : imageType,
width : dims.width,
height : dims.height,
x : dims.x,
y : dims.y
});
self.emit('screenUpdate', {
base64 : base64.encode(imageBuf),
type : imageType,
width : dims.width,
height : dims.height,
x : dims.x,
y : dims.y
});
delete imageStack[stackCounter];
stackCounter++;
}
});

rfb.on('raw', function (rect) {
self.emit('raw', rect);
if (rect.nRects == 1) {
rfb.fbDims(function (dims) {
new PngLib.Png(rect.fb, rect.width, rect.height, bufType).encode(
function (image) {
var imageBuf = new Buffer(image.length);
imageBuf.write(image, 'binary');
var fullScreen = (rect.width == dims.width) &&
(rect.height == dims.height);

self.emit('screenUpdate', {
base64 : base64.encode(imageBuf),
type : imageType,
width : rect.width,
height : rect.height,
x : rect.x,
y : rect.y,
fullScreen : fullScreen
});
}
);
var image = new PngLib.Png(rect.fb, rect.width, rect.height, bufType).encodeSync();
var imageBuf = new Buffer(image.length);
imageBuf.write(image, 'binary');
var fullScreen = (rect.width == dims.width) &&
(rect.height == dims.height);

self.emit('screenUpdate', {
base64 : base64.encode(imageBuf),
type : imageType,
width : rect.width,
height : rect.height,
x : rect.x,
y : rect.y,
fullScreen : fullScreen
});
});
}
else {
imageStack[stackCounter].push(rect.fb, rect.x, rect.y, rect.width, rect.height);
imageStack.push(rect.fb, rect.x, rect.y, rect.width, rect.height);
}
});

Expand Down

0 comments on commit 162bca6

Please sign in to comment.