quantize static method
Future<QuantizerResult>
quantize(
- ImageProvider<
Object> imageProvider, - int count, {
- bool debug = false,
Implementation
static Future<QuantizerResult> quantize(
ImageProvider imageProvider,
int count, {
bool debug = false,
}) async {
final sw = Stopwatch()..start();
final byteData = await imageProviderToScaledRgba(imageProvider, 96);
monetDebug(
debug,
() => '[Extract] downscaled in ${sw.elapsedMilliseconds}ms',
);
if (byteData.lengthInBytes == 0) {
return Future<QuantizerResult>.value(
const QuantizerResult({}, lstarToCount: {}),
);
}
sw.reset();
final bytes = byteData.buffer.asUint32List();
monetDebug(debug, () => '[Extract] Uint32s in ${sw.elapsedMilliseconds}ms');
sw.reset();
final argbBytes = bytes
.map(rgbaToArgb)
.where((e) => alphaFromArgb(e) == 255)
.toList();
monetDebug(debug, () => '[Extract] ARGB in ${sw.elapsedMilliseconds}ms');
sw.reset();
final pool = await _getQuantizeWorkerPool();
monetDebug(
debug,
() => '[Extract] Worker pool in ${sw.elapsedMilliseconds}ms',
);
sw.reset();
final quantizerResult = await pool.quantize(argbBytes, count);
monetDebug(
debug,
() => '[Extract] Quantized in ${sw.elapsedMilliseconds}ms',
);
return Future<QuantizerResult>.value(quantizerResult);
}