Skip to content
This repository was archived by the owner on Jul 8, 2024. It is now read-only.

Commit 102fdf2

Browse files
committed
Tweak PrintImage24
Removed the double loops in PrintImage24. Instead of converting the entire image before sending data to the printer, send each row as soon as it has been converted. PrintImage8 already did this.
1 parent 5934f09 commit 102fdf2

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

printer.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,13 @@ func (p Printer) PrintImage24(img image.Image, density Density) error {
492492
return fmt.Errorf(errMsg, err)
493493
}
494494

495-
imgBytes := [][]byte{}
495+
command := []byte{ESC, 0x2A, byte(density + 32), byte(imgRect.Max.X), byte(imgRect.Max.X >> 8)}
496496

497-
// First convert the image data to the 1-bit data format.
498497
// 24 dot density (meta row is 24 dots tall (3 bytes))
499498
for y := 0; y < imgRect.Max.Y; y += 24 {
500-
metaRow := []byte{}
501-
for x := 0; x < imgRect.Max.X; x++ {
499+
row := []byte{}
502500

501+
for x := 0; x < imgRect.Max.X; x++ {
503502
for z := 0; z < 3; z++ {
504503
col := byte(0)
505504
for i := 0; i < 8; i++ {
@@ -514,16 +513,10 @@ func (p Printer) PrintImage24(img image.Image, density Density) error {
514513
col |= 1
515514
}
516515
}
517-
metaRow = append(metaRow, col)
516+
row = append(row, col)
518517
}
519-
520518
}
521-
imgBytes = append(imgBytes, metaRow)
522-
}
523519

524-
// Next send the data to the printer.
525-
command := []byte{ESC, 0x2A, byte(density + 32), byte(imgRect.Max.X), byte(imgRect.Max.X >> 8)}
526-
for _, row := range imgBytes {
527520
err = p.SetLineSpacing(0)
528521
if err != nil {
529522
return fmt.Errorf(errMsg, err)

0 commit comments

Comments
 (0)