reframeClip method

void reframeClip(
  1. int index, {
  2. required double subjectX,
  3. required double subjectY,
})

Frames clip index so the normalized subject point (subjectX, subjectY in 0..1 of the clip frame) sits at the canvas centre, filling the canvas. Used by AI auto-reframe.

Implementation

void reframeClip(int index, {required double subjectX, required double subjectY}) {
  if (index < 0 || index >= clips.length) return;
  final clip = clips[index];
  final canvas = aspectRatio.canvasSize(
    source: clips.first.resolution,
    shortSide: 1080,
  );
  final scale = math.max(
    canvas.width / clip.width,
    canvas.height / clip.height,
  );
  final w = clip.width * scale;
  final h = clip.height * scale;
  // Offset that moves the subject to the centre, limited so the scaled
  // frame still covers the whole canvas.
  final maxX = (w - canvas.width) / 2;
  final maxY = (h - canvas.height) / 2;
  final dx = (w * (0.5 - subjectX)).clamp(-maxX, maxX);
  final dy = (h * (0.5 - subjectY)).clamp(-maxY, maxY);
  clipController.updateClipFillMode(index, VideoFillMode.fill);
  clipController.updateClipCrop(
    index,
    scale: 1.0,
    x: dx / canvas.width,
    y: dy / canvas.height,
  );
  _saveState();
  notifyListeners();
}