mirror of
https://github.com/amitbet/vncproxy.git
synced 2025-07-04 01:46:36 +00:00
added tightpng encoding
This commit is contained in:
parent
076d8bb4cf
commit
ed0dc6839c
@ -1,8 +1,8 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,22 +18,9 @@ type Encoding interface {
|
|||||||
Read(*PixelFormat, *Rectangle, *RfbReadHelper) (Encoding, error)
|
Read(*PixelFormat, *Rectangle, *RfbReadHelper) (Encoding, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
EncodingRaw = 0
|
|
||||||
EncodingCopyRect = 1
|
|
||||||
EncodingRRE = 2
|
|
||||||
EncodingCoRRE = 4
|
|
||||||
EncodingHextile = 5
|
|
||||||
EncodingZlib = 6
|
|
||||||
EncodingTight = 7
|
|
||||||
EncodingZRLE = 16
|
|
||||||
)
|
|
||||||
|
|
||||||
// EncodingType represents a known VNC encoding type.
|
// EncodingType represents a known VNC encoding type.
|
||||||
type EncodingType int32
|
type EncodingType int32
|
||||||
|
|
||||||
//go:generate stringer -type=EncodingType
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
EncRaw EncodingType = 0
|
EncRaw EncodingType = 0
|
||||||
EncCopyRect EncodingType = 1
|
EncCopyRect EncodingType = 1
|
||||||
@ -80,6 +67,17 @@ const (
|
|||||||
EncFencePseudo EncodingType = -312
|
EncFencePseudo EncodingType = -312
|
||||||
EncContinuousUpdatesPseudo EncodingType = -313
|
EncContinuousUpdatesPseudo EncodingType = -313
|
||||||
EncClientRedirect EncodingType = -311
|
EncClientRedirect EncodingType = -311
|
||||||
|
EncTightPNGBase64 EncodingType = 21 + 0x574d5600
|
||||||
|
EncTightDiffComp EncodingType = 22 + 0x574d5600
|
||||||
|
EncVMWDefineCursor EncodingType = 100 + 0x574d5600
|
||||||
|
EncVMWCursorState EncodingType = 101 + 0x574d5600
|
||||||
|
EncVMWCursorPosition EncodingType = 102 + 0x574d5600
|
||||||
|
EncVMWTypematicInfo EncodingType = 103 + 0x574d5600
|
||||||
|
EncVMWLEDState EncodingType = 104 + 0x574d5600
|
||||||
|
EncVMWServerPush2 EncodingType = 123 + 0x574d5600
|
||||||
|
EncVMWServerCaps EncodingType = 122 + 0x574d5600
|
||||||
|
EncVMWFrameStamp EncodingType = 124 + 0x574d5600
|
||||||
|
EncOffscreenCopyRect EncodingType = 126 + 0x574d5600
|
||||||
)
|
)
|
||||||
|
|
||||||
// PixelFormat describes the way a pixel is formatted for a VNC connection.
|
// PixelFormat describes the way a pixel is formatted for a VNC connection.
|
||||||
@ -98,7 +96,7 @@ type PixelFormat struct {
|
|||||||
BlueShift uint8
|
BlueShift uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
func (format *PixelFormat) WriteTo(w io.Writer) ( error) {
|
func (format *PixelFormat) WriteTo(w io.Writer) error {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
||||||
// Byte 1
|
// Byte 1
|
||||||
|
@ -12,7 +12,8 @@ const (
|
|||||||
TightExplicitFilter = 0x04
|
TightExplicitFilter = 0x04
|
||||||
TightFill = 0x08
|
TightFill = 0x08
|
||||||
TightJpeg = 0x09
|
TightJpeg = 0x09
|
||||||
TightMaxSubencoding = 0x09
|
TightPNG = 0x10
|
||||||
|
|
||||||
TightFilterCopy = 0x00
|
TightFilterCopy = 0x00
|
||||||
TightFilterPalette = 0x01
|
TightFilterPalette = 0x01
|
||||||
TightFilterGradient = 0x02
|
TightFilterGradient = 0x02
|
||||||
@ -74,24 +75,15 @@ func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangl
|
|||||||
//conn := &DataSource{conn: conn.c, PixelFormat: conn.PixelFormat}
|
//conn := &DataSource{conn: conn.c, PixelFormat: conn.PixelFormat}
|
||||||
|
|
||||||
//var subencoding uint8
|
//var subencoding uint8
|
||||||
subencoding, err := r.ReadUint8()
|
compctl, err := r.ReadUint8()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("error in handling tight encoding: %v\n", err)
|
fmt.Printf("error in handling tight encoding: %v\n", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
fmt.Printf("bytesPixel= %d, subencoding= %d\n", bytesPixel, subencoding)
|
fmt.Printf("bytesPixel= %d, subencoding= %d\n", bytesPixel, compctl)
|
||||||
// if err := binary.Read(conn.c, binary.BigEndian, &subencoding); err != nil {
|
|
||||||
// return t, err
|
|
||||||
// }
|
|
||||||
|
|
||||||
//move it to position (remove zlib flush commands)
|
//move it to position (remove zlib flush commands)
|
||||||
compType := subencoding >> 4 & 0x0F
|
compType := compctl >> 4 & 0x0F
|
||||||
// for stream_id := 0; stream_id < 4; stream_id++ {
|
|
||||||
// // if ((comp_ctl & 1) != 0 && tightInflaters[stream_id] != null) {
|
|
||||||
// // tightInflaters[stream_id] = null;
|
|
||||||
// // }
|
|
||||||
// subencoding >>= 1
|
|
||||||
// }
|
|
||||||
|
|
||||||
fmt.Printf("afterSHL:%d\n", compType)
|
fmt.Printf("afterSHL:%d\n", compType)
|
||||||
switch compType {
|
switch compType {
|
||||||
@ -120,7 +112,7 @@ func (t *TightEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangl
|
|||||||
fmt.Println("Compression control byte is incorrect!")
|
fmt.Println("Compression control byte is incorrect!")
|
||||||
}
|
}
|
||||||
|
|
||||||
handleTightFilters(subencoding, pixelFmt, rect, r)
|
handleTightFilters(compctl, pixelFmt, rect, r)
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
encodings/enc-tightpng.go
Normal file
43
encodings/enc-tightpng.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package encodings
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"vncproxy/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TightPngEncoding struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*TightPngEncoding) Type() int32 { return int32(common.EncTightPng) }
|
||||||
|
|
||||||
|
func (t *TightPngEncoding) Read(pixelFmt *common.PixelFormat, rect *common.Rectangle, r *common.RfbReadHelper) (common.Encoding, error) {
|
||||||
|
bytesPixel := calcTightBytePerPixel(pixelFmt)
|
||||||
|
|
||||||
|
//var subencoding uint8
|
||||||
|
compctl, err := r.ReadUint8()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("error in handling tight encoding: %v\n", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fmt.Printf("bytesPixel= %d, subencoding= %d\n", bytesPixel, compctl)
|
||||||
|
|
||||||
|
//move it to position (remove zlib flush commands)
|
||||||
|
compType := compctl >> 4 & 0x0F
|
||||||
|
|
||||||
|
fmt.Printf("afterSHL:%d\n", compType)
|
||||||
|
switch compType {
|
||||||
|
case TightPNG:
|
||||||
|
len, err := r.ReadCompactLen()
|
||||||
|
_, err = r.ReadBytes(len)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return t, err
|
||||||
|
}
|
||||||
|
|
||||||
|
case TightFill:
|
||||||
|
r.ReadBytes(int(bytesPixel))
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unknown tight compression %d", compType)
|
||||||
|
}
|
||||||
|
return t, nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user