Fix palettes. Remove unnecessary memory alloc for pixels.

pull/106/head
George Sexton 1 year ago
parent e455f8e488
commit 742e8e4240

@ -29,36 +29,36 @@ var _ draw.Image = &DevImpression{}
var ( var (
// For more: https://github.com/pimoroni/inky/issues/115#issuecomment-887453065 // For more: https://github.com/pimoroni/inky/issues/115#issuecomment-887453065
dsc = []color.NRGBA{ dsc = []color.NRGBA{
{0, 0, 0, 0}, // Black {0, 0, 0, 255}, // Black
{255, 255, 255, 255}, // White {255, 255, 255, 255}, // White
{0, 255, 0, 255}, // Green {0, 255, 0, 255}, // Green
{0, 0, 255, 255}, // Blue {0, 0, 255, 255}, // Blue
{255, 0, 0, 255}, // Red {255, 0, 0, 255}, // Red
{255, 255, 0, 255}, // Yellow {255, 255, 0, 255}, // Yellow
{255, 140, 0, 255}, // Orange {255, 140, 0, 255}, // Orange
{255, 255, 255, 255}, {255, 255, 255, 0}, // Clear
} }
sc = []color.NRGBA{ sc = []color.NRGBA{
{57, 48, 57, 0}, // Black {57, 48, 57, 255}, // Black
{255, 255, 255, 255}, // White {255, 255, 255, 255}, // White
{58, 91, 70, 255}, // Green {58, 91, 70, 255}, // Green
{61, 59, 94, 255}, // Blue {61, 59, 94, 255}, // Blue
{156, 72, 75, 255}, // Red {156, 72, 75, 255}, // Red
{208, 190, 71, 255}, // Yellow {208, 190, 71, 255}, // Yellow
{177, 106, 73, 255}, // Orange {177, 106, 73, 255}, // Orange
{255, 255, 255, 255}, {255, 255, 255, 0}, // Clear
} }
sc7 = []color.NRGBA{ sc7 = []color.NRGBA{
{0, 0, 0, 0}, // Black {0, 0, 0, 255}, // Black
{217, 242, 255, 255}, // White {217, 242, 255, 255}, // White
{3, 124, 76, 255}, // Green {3, 124, 76, 255}, // Green
{27, 46, 198, 255}, // Blue {27, 46, 198, 255}, // Blue
{245, 80, 34, 255}, // Red {245, 80, 34, 255}, // Red
{255, 255, 68, 255}, // Yellow {255, 255, 68, 255}, // Yellow
{239, 121, 44, 255}, // Orange {239, 121, 44, 255}, // Orange
{255, 255, 255, 255}, {255, 255, 255, 0}, // Clear
} }
) )
@ -224,10 +224,10 @@ func NewImpression(p spi.Port, dc gpio.PinOut, reset gpio.PinOut, busy gpio.PinI
} }
// blend recalculates the palette based on the saturation level. // blend recalculates the palette based on the saturation level.
func (d *DevImpression) blend() []color.Color { func (d *DevImpression) blend() color.Palette {
sat := float64(d.saturation / 100) sat := float64(d.saturation) / 100.0
pr := []color.Color{} pr := make([]color.Color, 0)
for i := 0; i < 7; i++ { for i := 0; i < 7; i++ {
var rs, gs, bs uint8 var rs, gs, bs uint8
if d.Dev.model == IMPRESSION73 { if d.Dev.model == IMPRESSION73 {
@ -295,7 +295,7 @@ func (d *DevImpression) Render() error {
merged := make([]uint8, len(d.Pix)/2) merged := make([]uint8, len(d.Pix)/2)
for i, offset := 0, 0; i < len(d.Pix)-1; i, offset = i+2, offset+1 { for i, offset := 0, 0; i < len(d.Pix)-1; i, offset = i+2, offset+1 {
merged[offset] = (d.Pix[i]<<4)&0xF0 | d.Pix[i+1]&0x0F merged[offset] = ((d.Pix[i] << 4) & 0xF0) | (d.Pix[i+1] & 0x0F)
} }
return d.update(merged) return d.update(merged)
@ -526,18 +526,16 @@ func (d *DevImpression) updateAC(pix []uint8) error {
} }
// TODO there has to be a better way to force the white colour to be used instead of clear... // TODO there has to be a better way to force the white colour to be used instead of clear...
buf := make([]byte, len(pix))
for i := range pix { for i := range pix {
buf[i] = pix[i] if pix[i]&0xF == 7 {
if buf[i]&0xF == 7 { pix[i] = (pix[i] & 0xF0) + 1
buf[i] = (buf[i] & 0xF0) + 1
} }
if buf[i]&0xF0 == 0x70 { if pix[i]&0xF0 == 0x70 {
buf[i] = (buf[i] & 0xF) + 0x10 pix[i] = (pix[i] & 0xF) + 0x10
} }
} }
if err := d.sendCommand(ac073TC1DTM, buf); err != nil { if err := d.sendCommand(ac073TC1DTM, pix); err != nil {
return err return err
} }
@ -626,6 +624,7 @@ func (d *DevImpression) Draw(r image.Rectangle, src image.Image, sp image.Point)
// Dither the image using FloydSteinberg dithering algorithm otherwise it won't look as good on the screen. // Dither the image using FloydSteinberg dithering algorithm otherwise it won't look as good on the screen.
draw.FloydSteinberg.Draw(d, r, src, image.Point{}) draw.FloydSteinberg.Draw(d, r, src, image.Point{})
return d.Render() return d.Render()
} }

Loading…
Cancel
Save