quantize method

  1. @override
Future<QuantizerResult> quantize(
  1. Iterable<int> pixels,
  2. int maxColors, {
  3. bool returnInputPixelToClusterPixel = false,
})
override

Implementation

@override
Future<QuantizerResult> quantize(
  Iterable<int> pixels,
  int maxColors, {
  bool returnInputPixelToClusterPixel = false,
}) async {
  final wu = QuantizerWu();
  final wuResult = await wu.quantize(pixels, maxColors);
  final wsmeansResult = QuantizerWsmeans.quantize(
    pixels,
    maxColors,
    startingClusters: wuResult.argbToCount.keys.toList(),
    pointProvider: const PointProviderLab(),
    returnInputPixelToClusterPixel: returnInputPixelToClusterPixel,
  );
  // argbToCount: refined cluster centers from WSMeans
  // inputPixelToClusterPixel: each distinct input pixel -> its final cluster
  //               center, when requested. Lets callers reconstruct the
  //               palette-ized image without rerunning quantization.
  // lstarToCount: original input image's L* distribution (from Wu/Map),
  //               intentionally preserved for source image analysis
  return QuantizerResult(
    wsmeansResult.argbToCount,
    inputPixelToClusterPixel: wsmeansResult.inputPixelToClusterPixel,
    lstarToCount: wuResult.lstarToCount,
  );
}