-
Notifications
You must be signed in to change notification settings - Fork 6
/
wrasse.go
93 lines (78 loc) · 2.12 KB
/
wrasse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Copyright 2018 Johannes Donath <[email protected]>
* and other copyright owners as documented in the project's IP log.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sstv
import (
"github.com/go-audio/audio"
"image"
)
type WrasseMode uint8
const (
WrasseSC2180 WrasseMode = 55
)
const wrassePulseLength = .7344
const (
wrasseLineFrequency = 1200
wrasseLineLength = 5.5225
wrasseSyncFrequency = 1500
wrasseSyncLength = 0.5
)
// provides a Wrasse implementation
//
// this implementation encodes RGB images into 256 lines
type wrasseEncoder struct {
mode WrasseMode
format *audio.Format
}
// creates a new Wrasse compatible image encoder
func NewWrasse(mode WrasseMode, format *audio.Format) Encoder {
return &wrasseEncoder{
mode: mode,
format: format,
}
}
func (enc *wrasseEncoder) Vis() uint8 {
return uint8(enc.mode)
}
func (enc *wrasseEncoder) Resolution() image.Rectangle {
return image.Rect(0, 0, 320, 256)
}
func (enc *wrasseEncoder) Encode(img image.Image) *audio.FloatBuffer {
wr := newWriter(enc.format)
wr.writeHeader()
wr.writeVis(uint8(enc.mode))
size := img.Bounds().Size()
for y := 0; y < size.Y; y++ {
wr.write(wrasseLineFrequency, wrasseLineLength)
wr.write(wrasseSyncFrequency, wrasseSyncLength)
for i := 0; i < 3; i++ {
for x := 0; x < size.X; x++ {
r, g, b := convertRGB(img.At(x, y))
var val float64
switch i {
case 0:
val = g
case 1:
val = b
case 2:
val = r
}
wr.writeValue(val, wrassePulseLength)
}
}
}
return wr.buf
}