1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 10:39:25 +02:00

Support variable bit depths. Fix color issues.

This commit is contained in:
Simo Kinnunen 2015-09-21 16:28:05 +09:00
parent 9d20484dcb
commit 977b8c198e
3 changed files with 41 additions and 10 deletions

View file

@ -1,5 +1,6 @@
var net = require('net')
var util = require('util')
var os = require('os')
var syrup = require('stf-syrup')
var Promise = require('bluebird')
@ -65,6 +66,9 @@ module.exports = syrup.serial()
, frameHeight: 0
, sentFrameTime: null
, updateRequests: 0
, frameConfig: {
format: jpeg.FORMAT_RGB
}
}
var pointerTranslator = new PointerTranslator()
@ -115,7 +119,9 @@ module.exports = syrup.serial()
return
}
var decoded = jpeg.decompressSync(connState.lastFrame)
var decoded = jpeg.decompressSync(
connState.lastFrame, connState.frameConfig)
conn.writeFramebufferUpdate([
{ xPosition: 0
, yPosition: 0
@ -150,6 +156,35 @@ module.exports = syrup.serial()
maybeSendFrame()
})
conn.on('formatchange', function(format) {
var same = os.endianness() == 'BE' == format.bigEndianFlag
switch (format.bitsPerPixel) {
case 8:
connState.frameConfig = {
format: jpeg.FORMAT_GRAY
}
break
case 24:
connState.frameConfig = {
format: ((format.redShift > format.blueShift) === same)
? jpeg.FORMAT_BGR
: jpeg.FORMAT_RGB
}
break
case 32:
connState.frameConfig = {
format: ((format.redShift > format.blueShift) === same)
? (format.blueShift === 0
? jpeg.FORMAT_BGRX
: jpeg.FORMAT_XBGR)
: (format.redShift === 0
? jpeg.FORMAT_RGBX
: jpeg.FORMAT_XRGB)
}
break
}
})
conn.on('pointer', function(event) {
pointerTranslator.push(event)
})

View file

@ -1,4 +1,5 @@
var util = require('util')
var os = require('os')
var EventEmitter = require('eventemitter3').EventEmitter
var debug = require('debug')('vnc:connection')
@ -26,7 +27,7 @@ function VncConnection(conn, options) {
this._serverPixelFormat = new PixelFormat({
bitsPerPixel: 24
, depth: 24
, bigEndianFlag: 0
, bigEndianFlag: os.endianness() == 'BE' ? 1 : 0
, trueColorFlag: 1
, redMax: 255
, greenMax: 255
@ -35,7 +36,6 @@ function VncConnection(conn, options) {
, greenShift: 8
, blueShift: 0
})
this._requireServerPixelFormat = true
this._serverName = this.options.name
this._clientVersion = null
@ -202,6 +202,7 @@ VncConnection.prototype._writeSecurityResult = function(result, reason) {
}
VncConnection.prototype._writeServerInit = function() {
debug('server pixel format', this._serverPixelFormat)
var chunk = new Buffer(2 + 2 + 16 + 4 + this._serverName.length)
chunk.writeUInt16BE(this._serverWidth, 0)
chunk.writeUInt16BE(this._serverHeight, 2)
@ -318,12 +319,7 @@ VncConnection.prototype._read = function() {
})
// [16b, 19b) padding
debug('client pixel format', this._clientPixelFormat)
if (this._requireServerPixelFormat &&
this._clientPixelFormat.bitsPerPixel <
this._serverPixelFormat.bitsPerPixel) {
this.end()
return
}
this.emit('formatchange', this._clientPixelFormat)
this._changeState(VncConnection.STATE_NEED_CLIENT_MESSAGE)
}
break