Skip to content

Commit 8c5b4ba

Browse files
committed
Add --stop-on-last-frame command.
1 parent b44fac3 commit 8c5b4ba

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

exporter/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ pub struct Opt {
6060
#[clap(long = "skipframes", default_value = "0")]
6161
skipframes: u32,
6262

63+
/// Stops capturing frames once the root movie clip reaches its final frame.
64+
#[clap(long, action)]
65+
stop_on_last_frame: bool,
66+
6367
/// Don't show a progress bar
6468
#[clap(short, long, action)]
6569
silent: bool,
@@ -89,6 +93,7 @@ pub struct Opt {
8993
}
9094

9195
/// Captures a screenshot. The resulting image uses straight alpha
96+
#[allow(clippy::too_many_arguments)]
9297
fn take_screenshot(
9398
descriptors: Arc<Descriptors>,
9499
swf_path: &Path,
@@ -97,6 +102,7 @@ fn take_screenshot(
97102
progress: &Option<ProgressBar>,
98103
size: SizeOpt,
99104
force_play: bool,
105+
stop_on_last_frame: bool,
100106
) -> Result<Vec<RgbaImage>> {
101107
let movie = SwfMovie::from_path(swf_path, None).map_err(|e| anyhow!(e.to_string()))?;
102108

@@ -168,10 +174,23 @@ fn take_screenshot(
168174
if let Some(progress) = &progress {
169175
progress.inc(1);
170176
}
177+
178+
if stop_on_last_frame && is_root_movie_clip_at_end(&player) {
179+
break;
180+
}
171181
}
172182
Ok(result)
173183
}
174184

185+
fn is_root_movie_clip_at_end(player: &Arc<Mutex<Player>>) -> bool {
186+
player.lock().unwrap().mutate_with_update_context(|ctx| {
187+
ctx.stage
188+
.root_clip()
189+
.and_then(|root_clip| root_clip.as_movie_clip())
190+
.is_some_and(|movie_clip| movie_clip.current_frame() == movie_clip.total_frames())
191+
})
192+
}
193+
175194
fn force_root_clip_play(player: &Arc<Mutex<Player>>) {
176195
let mut player_guard = player.lock().unwrap();
177196

@@ -258,6 +277,7 @@ fn capture_single_swf(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()> {
258277
&progress,
259278
opt.size,
260279
opt.force_play,
280+
opt.stop_on_last_frame,
261281
)?;
262282

263283
if let Some(progress) = &progress {
@@ -352,6 +372,7 @@ fn capture_multiple_swfs(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()>
352372
&progress,
353373
opt.size,
354374
opt.force_play,
375+
opt.stop_on_last_frame,
355376
) {
356377
let mut relative_path = file
357378
.path()

0 commit comments

Comments
 (0)