constructHistogram method

void constructHistogram(
  1. Map<int, int> pixels
)

Implementation

void constructHistogram(Map<int, int> pixels) {
  weights = List.filled(totalSize, 0, growable: false);
  momentsR = List.filled(totalSize, 0, growable: false);
  momentsG = List.filled(totalSize, 0, growable: false);
  momentsB = List.filled(totalSize, 0, growable: false);
  moments = List.filled(totalSize, 0, growable: false);
  for (var entry in pixels.entries) {
    final pixel = entry.key;
    final count = entry.value;
    final red = ColorUtils.redFromArgb(pixel);
    final green = ColorUtils.greenFromArgb(pixel);
    final blue = ColorUtils.blueFromArgb(pixel);
    final bitsToRemove = 8 - indexBits;
    final iR = (red >> bitsToRemove) + 1;
    final iG = (green >> bitsToRemove) + 1;
    final iB = (blue >> bitsToRemove) + 1;
    final index = getIndex(iR, iG, iB);
    weights[index] += count;
    momentsR[index] += (red * count);
    momentsG[index] += (green * count);
    momentsB[index] += (blue * count);
    moments[index] +=
        (count * ((red * red) + (green * green) + (blue * blue)));
  }
}