Skip to content

Commit

Permalink
utk display: fix rendering
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Maslowski <[email protected]>
  • Loading branch information
orangecms committed Sep 17, 2024
1 parent e49e2ff commit b317dd0
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions pkg/visitors/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,19 @@ func (v *Display) Visit(f uefi.Firmware) error {

b := bytes.NewBuffer(f.Buf())
os.WriteFile(v.Name, f.Buf(), 0644)
numblocks := b.Len()/uefi.RegionBlockSize
// The display is 256 blocks x however many rows we need.
// So that's len(buf) / (256x1024)
squareSize := 2
wid := 256*squareSize
ht := squareSize*(numblocks/256)

numblocks := b.Len() / uefi.RegionBlockSize
// The display is blocksPerRow x however many rows we need.
blocksPerRow := 64
blocksPerCol := numblocks / blocksPerRow
// Add some padding from the window edges
padding := 20
squareSize := 5
width := 2*padding + blocksPerRow*squareSize
height := 2*padding + blocksPerCol*squareSize

// Initialize the draw context with a dynamically-sized window
d, err := draw.Init(nil, "", v.Name, fmt.Sprintf("%dx%d", wid+100, ht+20))
d, err := draw.Init(nil, "", v.Name, fmt.Sprintf("%dx%d", width, height))
if err != nil {
return fmt.Errorf("failed to initialize draw: %w", err)
}
Expand All @@ -79,12 +84,15 @@ func (v *Display) Visit(f uefi.Firmware) error {
red := d.AllocImageMix(draw.Red, draw.Opaque)

var buf [uefi.RegionBlockSize]byte
done:
for y := 0; y < ht; y++ {
for x := 0; x < wid; x++ {
done:
for y := 0; y < blocksPerCol; y++ {
for x := 0; x < blocksPerRow; x++ {
// Calculate the top-left corner of the square
pt := draw.Pt(20+x*squareSize, 20+y*squareSize)
px := padding + x*squareSize
py := padding + y*squareSize
pt := draw.Pt(px, py)
rect := draw.Rect(pt.X, pt.Y, pt.X+squareSize, pt.Y+squareSize)

n, err := b.Read(buf[:])
if err != nil && err != io.EOF {
return fmt.Errorf("reading buffer with non-eof error:%w", err)
Expand Down

0 comments on commit b317dd0

Please sign in to comment.