pack2Bit static method
Implementation
static Uint8List pack2Bit(Uint8List bpp2) {
int byteLength =
(bpp2.length + 3) ~/ 4; // Calculate the required number of bytes
Uint8List packed =
Uint8List(byteLength); // Create the Uint8List to hold packed bytes
for (int i = 0; i < bpp2.length; i++) {
int byteIndex = i ~/ 4;
int bitOffset = (3 - (i % 4)) * 2;
packed[byteIndex] |= (bpp2[i] & 0x03) << bitOffset;
}
return packed;
}