Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uc8151 Improvements DrawBitmap and DrawBuffer #680

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions uc8151/uc8151.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,31 @@ func (d *Device) DrawBitmap(x, y int16, bitmap pixel.Image[pixel.Monochrome]) er
return nil
}

// DrawBuffer copies the buffer directly to the screen at the given coordinates (no rotation taken into account). X coordinate and width need to be a multiple of 8.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(no rotation taken into account)

That seems is a possible issue, since most of the time with this screen we operate at 270 degrees rotation.

func (d *Device) DrawBuffer(x, y, width, height int16, buffer []uint8) error {
h, w := d.Size()
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
x >= w || (x+width) > w || y >= h || (y+height) > h {
return errors.New("rectangle coordinates outside display area")
}
width = width / 8
k := int32(width) * int32(height)
l := int32(len(buffer))
if k != l {
return errors.New("buffer length does not match with rectangle size")
}
x = x / 8
w = w / 8

for i := x; i < (x + width); i++ {
for j := y; j < (y + height); j++ {
d.buffer[i+j*w] = buffer[(i-x)+(j-y)*width]
}
}

return nil
}

// Display sends the buffer to the screen.
func (d *Device) Display() error {
if d.blocking {
Expand Down
Loading