convertToRows static method
Implementation
static List<List<int>> convertToRows(ImageData img, bool halfTones) {
final List<List<int>> bitRows = [];
for (int x = 0; x < img.width; x++) {
final List<int> bits = [];
for (int y = img.height - 1; y >= 0; y--) {
final pixel = img.getPixel(x, y);
final brightness =
(0.299 * pixel.r + 0.587 * pixel.g + 0.114 * pixel.b);
if (!halfTones) {
bits.add(brightness < 128 ? 1 : 0);
continue;
}
// half-tones
bits.add(halfTonePixel(brightness.toInt(), x, y));
}
bitRows.add(bits);
}
// group into bytes
return bitRows;
}