getPagePixmap method

Future<Image> getPagePixmap(
  1. Pointer<MuPdfInst> ctx,
  2. int pageNumber
)

Implementation

Future<Image> getPagePixmap(Pointer<MuPdfInst> ctx, int pageNumber) {
  Pointer<Pointer<Uint8>> raw = calloc<Pointer<Uint8>>();
  Pointer<Int32> _w = calloc<Int32>();
  Pointer<Int32> _h = calloc<Int32>();
  Pointer<Int32> _channel = calloc<Int32>();
  pdflib.getPagePixmap(ctx, pageNumber, raw, _w, _h, _channel);
  int w = _w.value;
  int h = _h.value;
  int channel = _channel.value;

  Uint8List rawPixel = raw.value.asTypedList(w * h * channel);
  var rgba = List<int>.filled(w * h * 4, 255);
  for (int i = 0; i < w * h; i++) {
    int ro = i * 3;
    int no = i * 4;
    rgba[no] = rawPixel[ro];
    rgba[no + 1] = rawPixel[ro + 1];
    rgba[no + 2] = rawPixel[ro + 2];
  }

  Uint8List rgbaList = Uint8List.fromList(rgba);

  Completer<Image> c = Completer<Image>();
  decodeImageFromPixels(rgbaList, w, h, PixelFormat.rgba8888, (Image img) {
    c.complete(img);
  });
  return c.future;
}