mirror of
https://github.com/YuzuZensai/TrollSSH.git
synced 2026-09-13 17:19:03 +00:00
✨ feat: color frames, derive grayscale frames at render time
This commit is contained in:
+7
-7
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// .tsf container, little-endian: "TSFR" | version uint16 | fps float64 |
|
||||
// count uint32 | count × (length uint32, JPEG bytes).
|
||||
// count uint32 | count × (colorLen uint32, color JPEG).
|
||||
const (
|
||||
tsfMagic = "TSFR"
|
||||
tsfVersion = 1
|
||||
@@ -29,13 +29,13 @@ func writeTSF(output string, data *FramesContainer) error {
|
||||
var hdr [14]byte
|
||||
binary.LittleEndian.PutUint16(hdr[0:], tsfVersion)
|
||||
binary.LittleEndian.PutUint64(hdr[2:], math.Float64bits(data.FPS))
|
||||
binary.LittleEndian.PutUint32(hdr[10:], uint32(len(data.Frames)))
|
||||
binary.LittleEndian.PutUint32(hdr[10:], uint32(len(data.ColorFrames)))
|
||||
if _, err := w.Write(hdr[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var lenBuf [4]byte
|
||||
for _, frame := range data.Frames {
|
||||
for _, frame := range data.ColorFrames {
|
||||
binary.LittleEndian.PutUint32(lenBuf[:], uint32(len(frame)))
|
||||
if _, err := w.Write(lenBuf[:]); err != nil {
|
||||
return err
|
||||
@@ -66,7 +66,7 @@ func loadTSF(filename string) (*FramesContainer, error) {
|
||||
fps := math.Float64frombits(binary.LittleEndian.Uint64(raw[6:]))
|
||||
count := binary.LittleEndian.Uint32(raw[14:])
|
||||
|
||||
frames := make([][]byte, 0, count)
|
||||
colorFrames := make([][]byte, 0, count)
|
||||
off := 18
|
||||
for range count {
|
||||
if off+4 > len(raw) {
|
||||
@@ -77,15 +77,15 @@ func loadTSF(filename string) (*FramesContainer, error) {
|
||||
if off+n > len(raw) {
|
||||
return nil, invalid()
|
||||
}
|
||||
frames = append(frames, raw[off:off+n])
|
||||
colorFrames = append(colorFrames, raw[off:off+n])
|
||||
off += n
|
||||
}
|
||||
|
||||
if len(frames) == 0 || fps <= 0 {
|
||||
if len(colorFrames) == 0 || fps <= 0 {
|
||||
return nil, fmt.Errorf(
|
||||
"invalid frames file %q: expected non-empty frames and a positive fps",
|
||||
filename,
|
||||
)
|
||||
}
|
||||
return &FramesContainer{Frames: frames, FPS: fps}, nil
|
||||
return &FramesContainer{ColorFrames: colorFrames, FPS: fps}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user