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

Commit

Permalink
Tweak image greyscale conversion
Browse files Browse the repository at this point in the history
Instead of assuming everything that isn't exactly black to be white,
convert the image to greyscale and split at the middle of grey.
Anything darker than 50% grey is read as Black, while anything lighter
is read as White.
  • Loading branch information
zorchenhimer committed Jun 30, 2024
1 parent 5ca0284 commit 5934f09
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (p Printer) PrintImage8(img image.Image, density Density) error {
continue
}
c := color.GrayModel.Convert(img.At(x, y+i)).(color.Gray)
if c.Y == 0 {
if c.Y < 0x80 {
col |= 1
}
}
Expand Down Expand Up @@ -510,7 +510,7 @@ func (p Printer) PrintImage24(img image.Image, density Density) error {
}

c := color.GrayModel.Convert(img.At(x, (y+z*8)+i)).(color.Gray)
if c.Y == 0 {
if c.Y < 0x80 {
col |= 1
}
}
Expand Down

0 comments on commit 5934f09

Please sign in to comment.