fromPacked static method

UGrayImage fromPacked(
  1. Uint8List pixels,
  2. int width,
  3. int height, {
  4. bool bgra = true,
  5. int rowStride = 0,
})

Builds a grayscale image from packed 32-bit pixels.

Implementation

static UGrayImage fromPacked(Uint8List pixels, int width, int height, {bool bgra = true, int rowStride = 0}) {
  final int stride = rowStride == 0 ? width * 4 : rowStride;
  final Uint8List out = Uint8List(width * height);
  for (int y = 0; y < height; y++) {
    int src = y * stride;
    final int dst = y * width;
    for (int x = 0; x < width; x++) {
      final int b = bgra ? pixels[src] : pixels[src + 2];
      final int g = pixels[src + 1];
      final int r = bgra ? pixels[src + 2] : pixels[src];
      out[dst + x] = (r * 77 + g * 151 + b * 28) >> 8;
      src += 4;
    }
  }
  return UGrayImage(out, width, height);
}