mirror of
https://github.com/amitbet/vnc2video.git
synced 2025-09-25 04:16:04 +00:00
fixed tight palette filter
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
|||||||
"image/draw"
|
"image/draw"
|
||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
|
||||||
"vnc2video/logger"
|
"vnc2video/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,7 +36,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TightEncoding struct {
|
type TightEncoding struct {
|
||||||
Image image.Image
|
Image draw.Image
|
||||||
decoders []io.Reader
|
decoders []io.Reader
|
||||||
decoderBuffs []*bytes.Buffer
|
decoderBuffs []*bytes.Buffer
|
||||||
}
|
}
|
||||||
@@ -235,8 +234,7 @@ func (enc *TightEncoding) Read(c Conn, rect *Rectangle) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("problem while decoding jpeg:", err)
|
logger.Error("problem while decoding jpeg:", err)
|
||||||
}
|
}
|
||||||
dest := enc.Image.(draw.Image)
|
draw.Draw(enc.Image, enc.Image.Bounds(), img, image.Point{int(rect.X), int(rect.Y)}, draw.Src)
|
||||||
draw.Draw(dest, dest.Bounds(), img, image.Point{int(rect.X), int(rect.Y)}, draw.Src)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
@@ -336,28 +334,44 @@ func (enc *TightEncoding) handleTightFilters(compCtl uint8, pixelFmt *PixelForma
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (enc *TightEncoding) drawTightPalette(rect *Rectangle, palette color.Palette, tightBytes []byte) {
|
func (enc *TightEncoding) drawTightPalette(rect *Rectangle, palette color.Palette, tightBytes []byte) {
|
||||||
myImg := enc.Image.(draw.Image)
|
|
||||||
bytePos := 0
|
bytePos := 0
|
||||||
bitPos := 0
|
bitPos := uint8(7)
|
||||||
var palettePos int
|
var palettePos int
|
||||||
for i := 0; i < int(rect.Height); i++ {
|
logger.Debugf("drawTightPalette numbytes=%d", len(tightBytes))
|
||||||
for j := 0; j < int(rect.Width); j++ {
|
|
||||||
|
for y := 0; y < int(rect.Height); y++ {
|
||||||
|
for x := 0; x < int(rect.Width); x++ {
|
||||||
if len(palette) == 2 {
|
if len(palette) == 2 {
|
||||||
currByte := tightBytes[bytePos]
|
currByte := tightBytes[bytePos]
|
||||||
palettePos = int(currByte&byte(math.Pow(2.0, float64(bitPos)))) >> uint(bitPos)
|
mask := byte(1) << bitPos
|
||||||
//logger.Debugf("palletPos=%d, bitpos=%d, bytepos=%d", palettePos, bitPos, bytePos)
|
|
||||||
bytePos = bytePos + int((bitPos+1.0)/8.0)
|
palettePos = 0
|
||||||
bitPos = (bitPos + 1) % 8
|
if currByte&mask > 0 {
|
||||||
//logger.Debugf("next: bitpos=%d, bytepos=%d", bitPos, bytePos)
|
palettePos = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
//logger.Debugf("currByte=%d, bitpos=%d, bytepos=%d, palettepos=%d, mask=%d, totalBytes=%d", currByte, bitPos, bytePos, palettePos, mask, len(tightBytes))
|
||||||
|
|
||||||
|
if bitPos == 0 {
|
||||||
|
bytePos++
|
||||||
|
}
|
||||||
|
bitPos = ((bitPos - 1) + 8) % 8
|
||||||
} else {
|
} else {
|
||||||
palettePos = int(tightBytes[bytePos])
|
palettePos = int(tightBytes[bytePos])
|
||||||
bytePos++
|
bytePos++
|
||||||
}
|
}
|
||||||
myImg.Set(int(rect.X)+j, int(rect.Y)+i, palette[palettePos])
|
//palettePos = palettePos
|
||||||
|
enc.Image.Set(int(rect.X)+x, int(rect.Y)+y, palette[palettePos])
|
||||||
//logger.Debugf("(%d,%d): pos: %d col:%d", int(rect.X)+j, int(rect.Y)+i, palettePos, palette[palettePos])
|
//logger.Debugf("(%d,%d): pos: %d col:%d", int(rect.X)+j, int(rect.Y)+i, palettePos, palette[palettePos])
|
||||||
}
|
}
|
||||||
|
// if bitPos != 0 {
|
||||||
|
// bitPos = 7
|
||||||
|
// //bytePos++
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
func (enc *TightEncoding) decodeGradData(rect *Rectangle, buffer []byte) {
|
func (enc *TightEncoding) decodeGradData(rect *Rectangle, buffer []byte) {
|
||||||
|
|
||||||
@@ -367,7 +381,6 @@ func (enc *TightEncoding) decodeGradData(rect *Rectangle, buffer []byte) {
|
|||||||
thisRow := make([]byte, rect.Width*3+3) //new byte[w * 3];
|
thisRow := make([]byte, rect.Width*3+3) //new byte[w * 3];
|
||||||
|
|
||||||
bIdx := 0
|
bIdx := 0
|
||||||
dst := (enc.Image).(*image.RGBA) // enc.Image.(*image.RGBA)
|
|
||||||
|
|
||||||
for i := 0; i < int(rect.Height); i++ {
|
for i := 0; i < int(rect.Height); i++ {
|
||||||
for j := 3; j < int(rect.Width*3+3); j += 3 {
|
for j := 3; j < int(rect.Width*3+3); j += 3 {
|
||||||
@@ -412,7 +425,7 @@ func (enc *TightEncoding) decodeGradData(rect *Rectangle, buffer []byte) {
|
|||||||
|
|
||||||
for idx := 3; idx < (len(thisRow) - 3); idx += 3 {
|
for idx := 3; idx < (len(thisRow) - 3); idx += 3 {
|
||||||
myColor := color.RGBA{R: (thisRow[idx]), G: (thisRow[idx+1]), B: (thisRow[idx+2]), A: 1}
|
myColor := color.RGBA{R: (thisRow[idx]), G: (thisRow[idx+1]), B: (thisRow[idx+2]), A: 1}
|
||||||
dst.SetRGBA(idx/3+int(rect.X)-1, int(rect.Y)+i, myColor)
|
enc.Image.Set(idx/3+int(rect.X)-1, int(rect.Y)+i, myColor)
|
||||||
//logger.Debugf("putting pixel: idx=%d, pos=(%d,%d), col=%v", idx, idx/3+int(rect.X), int(rect.Y)+i, myColor)
|
//logger.Debugf("putting pixel: idx=%d, pos=(%d,%d), col=%v", idx, idx/3+int(rect.X), int(rect.Y)+i, myColor)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -647,14 +660,13 @@ func readTightLength(c Conn) (int, error) {
|
|||||||
*/
|
*/
|
||||||
func (enc *TightEncoding) drawTightBytes(bytes []byte, rect *Rectangle) {
|
func (enc *TightEncoding) drawTightBytes(bytes []byte, rect *Rectangle) {
|
||||||
bytesPos := 0
|
bytesPos := 0
|
||||||
myImg := (enc.Image).(draw.Image)
|
|
||||||
logger.Debugf("drawTightBytes: len(bytes)= %d, %v", len(bytes), rect)
|
logger.Debugf("drawTightBytes: len(bytes)= %d, %v", len(bytes), rect)
|
||||||
|
|
||||||
for ly := rect.Y; ly < rect.Y+rect.Height; ly++ {
|
for ly := rect.Y; ly < rect.Y+rect.Height; ly++ {
|
||||||
for lx := rect.X; lx < rect.X+rect.Width; lx++ {
|
for lx := rect.X; lx < rect.X+rect.Width; lx++ {
|
||||||
color := color.RGBA{R: bytes[bytesPos], G: bytes[bytesPos+1], B: bytes[bytesPos+2], A: 1}
|
color := color.RGBA{R: bytes[bytesPos], G: bytes[bytesPos+1], B: bytes[bytesPos+2], A: 1}
|
||||||
//logger.Debugf("drawTightBytes: setting pixel= (%d,%d): %v", int(lx), int(ly), color)
|
//logger.Debugf("drawTightBytes: setting pixel= (%d,%d): %v", int(lx), int(ly), color)
|
||||||
myImg.Set(int(lx), int(ly), color)
|
enc.Image.Set(int(lx), int(ly), color)
|
||||||
|
|
||||||
bytesPos += 3
|
bytesPos += 3
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user