fix basic errormap diffusion to look more-or-less correct
This commit is contained in:
parent
254167de4e
commit
088ba19e3c
13
quantizer.go
13
quantizer.go
@ -40,7 +40,7 @@ func naiveBW(_, _ int, c color.Color) color.Color {
|
||||
// randomNoise injects random noise into the quantization step
|
||||
func randomNoise(_, _ int, c color.Color) color.Color {
|
||||
l := luminence(c)
|
||||
if (l + rand.Float64() - 0.5) > 0.5 {
|
||||
if (l + (rand.Float64() - 0.5)) > 0.5 {
|
||||
return color.White
|
||||
}
|
||||
return color.Black
|
||||
@ -126,15 +126,14 @@ func simpleErrorDiffusion() quantizerFunction {
|
||||
errMap := make(map[coord]float64)
|
||||
return func(x int, y int, c color.Color) color.Color {
|
||||
l := luminence(c) + errMap[coord{x: x, y: y}]
|
||||
delete(errMap, coord{x: x, y: y}) // don't let the error map grow too big
|
||||
if l > 0.5 {
|
||||
errMap[coord{x: x + 1, y: y}] = (l - 1.0) / 2.0
|
||||
errMap[coord{x: x, y: y + 1}] = (l - 1.0) / 2.0
|
||||
delete(errMap, coord{x: x, y: y})
|
||||
errMap[coord{x: x + 1, y: y}] = errMap[coord{x: x + 1, y: y}] + ((l - 1.0) / 2.0)
|
||||
errMap[coord{x: x, y: y + 1}] = errMap[coord{x: x, y: y + 1}] + ((l - 1.0) / 2.0)
|
||||
return color.White
|
||||
}
|
||||
errMap[coord{x: x + 1, y: y}] = l / 2.0
|
||||
errMap[coord{x: x, y: y + 1}] = l / 2.0
|
||||
delete(errMap, coord{x: x, y: y})
|
||||
errMap[coord{x: x + 1, y: y}] = errMap[coord{x: x + 1, y: y}] + (l / 2.0)
|
||||
errMap[coord{x: x, y: y + 1}] = errMap[coord{x: x, y: y + 1}] + (l / 2.0)
|
||||
return color.Black
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user