Added README; cleaned up the repo
This commit is contained in:
33 files changed
+270
-9330
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/color/palette"
|
||||
"image/draw"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -162,3 +163,56 @@ func (i imageView) Set(x, y int, c color.Color) {
|
||||
}
|
||||
i.Image.Set(x, y, c)
|
||||
}
|
||||
|
||||
func PaletteFor(model color.Model) color.Palette {
|
||||
var p color.Palette
|
||||
|
||||
switch model {
|
||||
case pixel.MonoModel:
|
||||
p = color.Palette{
|
||||
pixel.Off,
|
||||
pixel.On,
|
||||
}
|
||||
|
||||
case pixel.Gray2Model:
|
||||
p = color.Palette{
|
||||
pixel.Gray2{Y: 0},
|
||||
pixel.Gray2{Y: 1},
|
||||
pixel.Gray2{Y: 2},
|
||||
pixel.Gray2{Y: 3},
|
||||
}
|
||||
|
||||
case pixel.Gray4Model:
|
||||
p = color.Palette{
|
||||
pixel.Gray4{Y: 0x0}, pixel.Gray4{Y: 0x1}, pixel.Gray4{Y: 0x2}, pixel.Gray4{Y: 0x3},
|
||||
pixel.Gray4{Y: 0x4}, pixel.Gray4{Y: 0x5}, pixel.Gray4{Y: 0x6}, pixel.Gray4{Y: 0x7},
|
||||
pixel.Gray4{Y: 0x8}, pixel.Gray4{Y: 0x9}, pixel.Gray4{Y: 0xa}, pixel.Gray4{Y: 0xb},
|
||||
pixel.Gray4{Y: 0xc}, pixel.Gray4{Y: 0xd}, pixel.Gray4{Y: 0xe}, pixel.Gray4{Y: 0xf},
|
||||
}
|
||||
|
||||
default:
|
||||
// TODO(maze): implement color quantization
|
||||
return palette.Plan9
|
||||
}
|
||||
|
||||
// Convert to RGBA.
|
||||
for i, c := range p {
|
||||
r, g, b, _ := c.RGBA()
|
||||
p[i] = color.RGBA{R: uint8(r >> 8), G: uint8(g >> 8), B: uint8(b >> 8), A: 0xFF}
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func ImageToPaletted(dst *image.Paletted, src image.Image, palette color.Palette) *image.Paletted {
|
||||
if palette == nil {
|
||||
palette = PaletteFor(src.ColorModel())
|
||||
}
|
||||
|
||||
if dst == nil {
|
||||
dst = image.NewPaletted(src.Bounds(), palette)
|
||||
}
|
||||
|
||||
ImageCopy(dst, src)
|
||||
|
||||
return dst
|
||||
}
|
||||
+13
-36
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/BeatGlow/beatglow/app"
|
||||
"github.com/BeatGlow/beatglow/app/font"
|
||||
"github.com/BeatGlow/beatglow/app/widget"
|
||||
"github.com/BeatGlow/beatglow/config"
|
||||
"github.com/BeatGlow/beatglow/player"
|
||||
|
||||
_ "embed"
|
||||
@@ -31,6 +32,7 @@ const (
|
||||
|
||||
type playing struct {
|
||||
base
|
||||
settings *config.Settings
|
||||
phonesWidget *widget.Text
|
||||
formatRate bool
|
||||
formatText string
|
||||
@@ -53,6 +55,7 @@ func Playing(ctx app.Context) app.Layout {
|
||||
styles := app.StylesFor(ctx.Display().ColorModel())
|
||||
layout := &playing{
|
||||
base: base{name: "playing"},
|
||||
settings: ctx.Settings(),
|
||||
phonesWidget: widget.NewText(image.Pt(10, 12)),
|
||||
formatText: formatTextPlaceholder,
|
||||
formatWidget: widget.NewText(image.Pt(2+len(formatTextPlaceholder)*9, 12)),
|
||||
@@ -129,46 +132,20 @@ func Playing(ctx app.Context) app.Layout {
|
||||
return layout
|
||||
}
|
||||
|
||||
/*
|
||||
func (l *playing) log() *logrus.Entry {
|
||||
return logrus.WithField("layout", "playing")
|
||||
}
|
||||
|
||||
|
||||
func (playing) String() string {
|
||||
return "playing"
|
||||
}
|
||||
|
||||
func (l *playing) Hide(ctx app.Context) {
|
||||
log := l.log()
|
||||
log.Debug("hide")
|
||||
for _, widget := range l.Widgets() {
|
||||
log.WithField("widget", widget.String()).Debug("hide widget")
|
||||
_ = widget.Hide(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *playing) Show(ctx app.Context) {
|
||||
log := l.log()
|
||||
log.Debug("show")
|
||||
for _, widget := range l.Widgets() {
|
||||
log.WithField("widget", widget.String()).Debug("show widget")
|
||||
_ = widget.Show(ctx)
|
||||
channels := 2
|
||||
if l.settings.Spectrum.Mono {
|
||||
channels = 1
|
||||
}
|
||||
}
|
||||
|
||||
func (l *playing) Widgets() []app.Widget {
|
||||
return []app.Widget{
|
||||
l.phonesWidget,
|
||||
l.formatWidget,
|
||||
l.iconWidget,
|
||||
l.durationWidget,
|
||||
l.trackWidget,
|
||||
l.artWidget,
|
||||
l.spectrumWidget,
|
||||
}
|
||||
l.spectrumWidget.
|
||||
SetWaterfall(l.settings.Spectrum.Waterfall).
|
||||
SetChannels(channels).
|
||||
SetHold(int(l.settings.Spectrum.Hold)).
|
||||
SetRange(l.settings.Spectrum.MinFrequency, l.settings.Spectrum.MaxFrequency)
|
||||
|
||||
l.base.Show(ctx)
|
||||
}
|
||||
*/
|
||||
|
||||
func (l *playing) TrackChanged(ctx app.Context, track *player.Track) {
|
||||
if track == nil {
|
||||
|
||||
Reference in new issue
Block a user