Implementation
@override
FutureOr<Uint8List> get data async {
final (:byteColors, :width, :height) = await _imageInfo;
final List<int> pixels = [];
for (var h = 0; h < height; h++) {
for (var w = 0; w < width; w += 8) {
int value = 0;
for (var i = 0; i < 8; i++) {
final index = (h * width + w + i) * 4;
if (w + i < width) {
final red = byteColors[index];
final green = byteColors[index + 1];
final blue = byteColors[index + 2];
final alpha = byteColors[index + 3];
int pixel = red == 255 && green == 255 && blue == 255 || alpha == 0 ? 0 : 1;
value |= pixel << 7 - i;
}
}
pixels.add(value);
}
}
final xL = (width + 7) ~/ 8 & 255;
final xH = (width + 7) ~/ 8 >> 8 & 255;
final yL = height & 255;
final yH = height >> 8 & 255;
return Uint8List.fromList([29, 118, 48, 0, xL, xH, yL, yH] + pixels);
}