dithering done :)
This commit is contained in:
@@ -18,16 +18,19 @@ func (_ grid) Bounds() image.Rectangle {
|
||||
}
|
||||
|
||||
func (g grid) At(x, y int) color.Color {
|
||||
step := int(64 / (g.Gray.Y / 4))
|
||||
if (y*8+x)%step == 0 {
|
||||
n := g.Gray.Y / 4
|
||||
if n == 0 {
|
||||
return color.Black
|
||||
}
|
||||
return color.White
|
||||
step := int(64 / n)
|
||||
if (y*8+x)%step == 0 {
|
||||
return color.White
|
||||
}
|
||||
return color.Black
|
||||
}
|
||||
|
||||
type uniformGrid struct {
|
||||
image.Image
|
||||
image.Rectangle
|
||||
}
|
||||
|
||||
func (g uniformGrid) ColorModel() color.Model {
|
||||
@@ -35,9 +38,23 @@ func (g uniformGrid) ColorModel() color.Model {
|
||||
}
|
||||
|
||||
func (g uniformGrid) Bounds() image.Rectangle {
|
||||
return g.Rectangle
|
||||
// just need to return something
|
||||
return g.Image.Bounds()
|
||||
}
|
||||
|
||||
func (g uniformGrid) At(x, y int) color.Color {
|
||||
return color.Color(nil)
|
||||
dx, dy := g.Image.Bounds().Dx(), g.Image.Bounds().Dy()
|
||||
return g.Image.At(x%dx, y%dy)
|
||||
}
|
||||
|
||||
type Dithering struct {
|
||||
image.Image
|
||||
}
|
||||
|
||||
func (d Dithering) ColorModel() color.Model { return color.GrayModel }
|
||||
func (d Dithering) Bounds() image.Rectangle { return d.Image.Bounds() }
|
||||
func (d Dithering) At(x, y int) color.Color {
|
||||
c := color.GrayModel.Convert(d.Image.At(x, y))
|
||||
return uniformGrid{grid{c.(color.Gray)}}.
|
||||
At(x, y)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user