exporter: Support outputting to stdout

When using - as an output filename. Only supports single-frame output.
This commit is contained in:
Eva 2023-05-19 11:26:40 +02:00 committed by Aaron Hill
parent 2493194d2f
commit b10c9dc238
1 changed files with 33 additions and 12 deletions

View File

@ -12,6 +12,7 @@ use ruffle_render_wgpu::descriptors::Descriptors;
use ruffle_render_wgpu::target::TextureTarget; use ruffle_render_wgpu::target::TextureTarget;
use ruffle_render_wgpu::wgpu; use ruffle_render_wgpu::wgpu;
use std::fs::create_dir_all; use std::fs::create_dir_all;
use std::io::{self, Write};
use std::panic::catch_unwind; use std::panic::catch_unwind;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::Arc; use std::sync::Arc;
@ -238,7 +239,21 @@ fn capture_single_swf(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()> {
} }
if frames.len() == 1 { if frames.len() == 1 {
frames.get(0).unwrap().save(&output)?; let image = frames.get(0).unwrap();
if opt.output_path == Some(PathBuf::from("-")) {
let mut bytes: Vec<u8> = Vec::new();
image
.write_to(
&mut io::Cursor::new(&mut bytes),
image::ImageOutputFormat::Png,
)
.expect("Encoding failed");
io::stdout()
.write_all(bytes.as_slice())
.expect("Writing to stdout failed");
} else {
image.save(&output)?;
}
} else { } else {
for (frame, image) in frames.iter().enumerate() { for (frame, image) in frames.iter().enumerate() {
let mut path: PathBuf = (&output).into(); let mut path: PathBuf = (&output).into();
@ -248,24 +263,30 @@ fn capture_single_swf(descriptors: Arc<Descriptors>, opt: &Opt) -> Result<()> {
} }
let message = if frames.len() == 1 { let message = if frames.len() == 1 {
format!( if !opt.silent {
"Saved first frame of {} to {}", Some(format!(
opt.swf.to_string_lossy(), "Saved first frame of {} to {}",
output.to_string_lossy() opt.swf.to_string_lossy(),
) output.to_string_lossy()
))
} else {
None
}
} else { } else {
format!( Some(format!(
"Saved first {} frames of {} to {}", "Saved first {} frames of {} to {}",
frames.len(), frames.len(),
opt.swf.to_string_lossy(), opt.swf.to_string_lossy(),
output.to_string_lossy() output.to_string_lossy()
) ))
}; };
if let Some(progress) = progress { if let Some(message) = message {
progress.finish_with_message(message); if let Some(progress) = progress {
} else { progress.finish_with_message(message);
println!("{message}"); } else {
println!("{message}");
}
} }
Ok(()) Ok(())