diff --git a/color_quant.go b/color_quant.go index f32e433..1724c87 100644 --- a/color_quant.go +++ b/color_quant.go @@ -48,15 +48,12 @@ func naivePalette(p color.Palette) quantizerFunction { // randomNoisePalette injects random noise into the quantization step func randomNoisePalette(p color.Palette) quantizerFunction { + r := len(p) return func(_, _ int, c color.Color) color.Color { - // the randomization here is tuned for the sixteen-color palette for now. // I think the proper theory here is probably "only try and randomize within one palette swatch in either direction". // it might be possible to instead permute the color selected _from the palette_ (i.e. modify the result of p.Index(c))... // ...but I think for that to work you'd need a proper "ordering" for the colors. - noise := rand.Intn(64) - 32 - if noise < 0 { - noise = 0 - } + noise := rand.Intn(256) / r rc := permuteColor(c, uint8(noise)) return p[p.Index(rc)] }