quantize function

Image quantize (
  1. Image src,
  2. {int numberOfColors: 256,
  3. QuantizeMethod method: QuantizeMethod.neuralNet}
)

Quantize the number of colors in image to 256.

Implementation

Image quantize(Image src,
    {int numberOfColors = 256,
    QuantizeMethod method = QuantizeMethod.neuralNet}) {
  if (method == QuantizeMethod.octree || numberOfColors < 4) {
    var oct = OctreeQuantizer(src, numberOfColors: numberOfColors);
    for (var i = 0, len = src.length; i < len; ++i) {
      src[i] = oct.getQuantizedColor(src[i]);
    }
    return src;
  }

  var quant = NeuralQuantizer(src, numberOfColors: numberOfColors);
  for (var i = 0, len = src.length; i < len; ++i) {
    src[i] = quant.getQuantizedColor(src[i]);
  }
  return src;
}