rotateFlip static method

RgbaImage rotateFlip(
  1. RgbaImage src,
  2. int quarterTurns,
  3. bool flipH
)

Rotate clockwise by quarter turns, then optionally mirror horizontally.

Implementation

static RgbaImage rotateFlip(RgbaImage src, int quarterTurns, bool flipH) {
  final turns = ((quarterTurns % 4) + 4) % 4;
  if (turns == 0 && !flipH) return src;
  final dw = turns.isEven ? src.width : src.height;
  final dh = turns.isEven ? src.height : src.width;
  final input = calloc<Uint8>(src.bytes.length);
  final out = calloc<Uint8>(dw * dh * 4);
  try {
    input.asTypedList(src.bytes.length).setAll(0, src.bytes);
    _rotateFlip(input, src.width, src.height, turns, flipH ? 1 : 0, out);
    return RgbaImage(
      Uint8List.fromList(out.asTypedList(dw * dh * 4)),
      dw,
      dh,
    );
  } finally {
    calloc.free(input);
    calloc.free(out);
  }
}