Permalink
Browse files

now using Sync version again

  • Loading branch information...
1 parent 2cc9b80 commit 162bca6eba35db815f270f4d7e136ae5f374422f @pkrumins committed Aug 9, 2010
Showing with 30 additions and 35 deletions.
  1. +30 −35 lib/resources/fb/encoder.js
@@ -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';
@@ -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);
}
});

0 comments on commit 162bca6

Please sign in to comment.