pack4Bit static method

Uint8List pack4Bit(
  1. Uint8List bpp4
)

Implementation

static Uint8List pack4Bit(Uint8List bpp4) {
  int byteLength =
      (bpp4.length + 1) ~/ 2; // Calculate the required number of bytes
  Uint8List packed =
      Uint8List(byteLength); // Create the Uint8List to hold packed bytes

  for (int i = 0; i < bpp4.length; i++) {
    int byteIndex = i ~/ 2;
    int bitOffset = (1 - (i % 2)) * 4;
    packed[byteIndex] |= (bpp4[i] & 0x0F) << bitOffset;
  }

  return packed;
}