Skip to content

Commit 4da1150

Browse files
committed
ili9341: st7735: st7789: add DrawBitmap method
This adds a new DrawBitmap method, which is meant to replace DrawRGBBitmap8.
1 parent 52c0dc8 commit 4da1150

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

ili9341/ili9341.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"tinygo.org/x/drivers"
10+
"tinygo.org/x/drivers/pixel"
1011
)
1112

1213
type Config struct {
@@ -173,6 +174,8 @@ func (d *Device) EnableTEOutput(on bool) {
173174
}
174175

175176
// DrawRGBBitmap copies an RGB bitmap to the internal buffer at given coordinates
177+
//
178+
// Deprecated: use DrawBitmap instead.
176179
func (d *Device) DrawRGBBitmap(x, y int16, data []uint16, w, h int16) error {
177180
k, i := d.Size()
178181
if x < 0 || y < 0 || w <= 0 || h <= 0 ||
@@ -187,6 +190,8 @@ func (d *Device) DrawRGBBitmap(x, y int16, data []uint16, w, h int16) error {
187190
}
188191

189192
// DrawRGBBitmap8 copies an RGB bitmap to the internal buffer at given coordinates
193+
//
194+
// Deprecated: use DrawBitmap instead.
190195
func (d *Device) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error {
191196
k, i := d.Size()
192197
if x < 0 || y < 0 || w <= 0 || h <= 0 ||
@@ -200,6 +205,13 @@ func (d *Device) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error {
200205
return nil
201206
}
202207

208+
// DrawBitmap copies the bitmap to the internal buffer on the screen at the
209+
// given coordinates. It returns once the image data has been sent completely.
210+
func (d *Device) DrawBitmap(x, y int16, bitmap pixel.Image[pixel.RGB565BE]) error {
211+
width, height := bitmap.Size()
212+
return d.DrawRGBBitmap8(x, y, bitmap.RawBuffer(), int16(width), int16(height))
213+
}
214+
203215
// FillRectangle fills a rectangle at given coordinates with a color
204216
func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
205217
k, i := d.Size()

st7735/st7735.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ func (d *DeviceOf[T]) FillRectangle(x, y, width, height int16, c color.RGBA) err
305305
}
306306

307307
// DrawRGBBitmap8 copies an RGB bitmap to the internal buffer at given coordinates
308+
//
309+
// Deprecated: use DrawBitmap instead.
308310
func (d *DeviceOf[T]) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error {
309311
k, i := d.Size()
310312
if x < 0 || y < 0 || w <= 0 || h <= 0 ||
@@ -316,6 +318,13 @@ func (d *DeviceOf[T]) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error
316318
return nil
317319
}
318320

321+
// DrawBitmap copies the bitmap to the internal buffer on the screen at the
322+
// given coordinates. It returns once the image data has been sent completely.
323+
func (d *DeviceOf[T]) DrawBitmap(x, y int16, bitmap pixel.Image[T]) error {
324+
width, height := bitmap.Size()
325+
return d.DrawRGBBitmap8(x, y, bitmap.RawBuffer(), int16(width), int16(height))
326+
}
327+
319328
// FillRectangle fills a rectangle at a given coordinates with a buffer
320329
func (d *DeviceOf[T]) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error {
321330
k, l := d.Size()

st7789/st7789.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ func (d *DeviceOf[T]) fillRectangle(x, y, width, height int16, c color.RGBA) err
382382
}
383383

384384
// DrawRGBBitmap8 copies an RGB bitmap to the internal buffer at given coordinates
385+
//
386+
// Deprecated: use DrawBitmap instead.
385387
func (d *DeviceOf[T]) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error {
386388
k, i := d.Size()
387389
if x < 0 || y < 0 || w <= 0 || h <= 0 ||
@@ -395,6 +397,13 @@ func (d *DeviceOf[T]) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error
395397
return nil
396398
}
397399

400+
// DrawBitmap copies the bitmap to the internal buffer on the screen at the
401+
// given coordinates. It returns once the image data has been sent completely.
402+
func (d *DeviceOf[T]) DrawBitmap(x, y int16, bitmap pixel.Image[T]) error {
403+
width, height := bitmap.Size()
404+
return d.DrawRGBBitmap8(x, y, bitmap.RawBuffer(), int16(width), int16(height))
405+
}
406+
398407
// FillRectangleWithBuffer fills buffer with a rectangle at a given coordinates.
399408
func (d *DeviceOf[T]) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error {
400409
i, j := d.Size()

0 commit comments

Comments
 (0)