Skip to content

Commit

Permalink
refactor: ignore test_images
Browse files Browse the repository at this point in the history
  • Loading branch information
cs50victor committed Jan 25, 2024
1 parent e6a8c76 commit a45e003
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
target/
Cargo.lock

**/test_images

# ggml binaries & other binaries in general
*.bin
# local splat files
Expand Down
37 changes: 22 additions & 15 deletions crates/bevy_frame_capture/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,35 +161,29 @@
// }
// }

// fn image_to_browser_base64(img: &ImageBuffer<Rgba<u8>, Vec<u8>>) -> Result<String> {
// let mut image_data: Vec<u8> = Vec::new();
// img.write_to(&mut Cursor::new(&mut image_data), ImageOutputFormat::Png)?;
// let res_base64 = general_purpose::STANDARD.encode(image_data);
// Ok(format!("data:image/png;base64,{}", res_base64))
// }

// pub fn white_img_placeholder(w: u32, h: u32) -> String {
// let img = RgbaImage::new(w, h);
// // img.iter_mut().for_each(|pixel| *pixel = 255);
// image_to_browser_base64(&img).unwrap()
// }




use std::path::PathBuf;
use std::{io::Cursor, path::PathBuf};

use base64::{engine::general_purpose, Engine};
use bevy::{
app::AppExit,
prelude::*,
render::{camera::RenderTarget, renderer::RenderDevice},
};
use image::{ImageBuffer, ImageOutputFormat, Rgba, RgbaImage};
use wgpu::{Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages};

use super::image_copy::ImageCopier;

#[derive(Component, Default)]
pub struct CaptureCamera;

#[derive(Resource)]
pub struct CurrImageBase64(pub String);

#[derive(Component, Deref, DerefMut)]
struct ImageToSave(Handle<Image>);
Expand All @@ -211,7 +205,7 @@
}

impl SceneController {
pub fn new(width: u32, height: u32, single_image: bool) -> SceneController {
pub fn new(width: u32, height: u32) -> SceneController {
SceneController {
state: SceneState::BuildScene,
name: String::from(""),
Expand Down Expand Up @@ -297,7 +291,6 @@
images_to_save: Query<&ImageToSave>,
mut images: ResMut<Assets<Image>>,
mut scene_controller: ResMut<SceneController>,
mut app_exit_writer: EventWriter<AppExit>,
) {
if let SceneState::Render(n) = scene_controller.state {
if n < 1 {
Expand All @@ -311,7 +304,7 @@

let images_dir =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test_images");
print!("Saving image to: {:?}\n", images_dir);
println!("Saving image to: {images_dir:?}");
std::fs::create_dir_all(&images_dir).unwrap();

let uuid = bevy::utils::Uuid::new_v4();
Expand All @@ -325,3 +318,17 @@
}
}
}

// useful utils
fn image_to_browser_base64(img: &ImageBuffer<Rgba<u8>, Vec<u8>>) -> anyhow::Result<String> {
let mut image_data: Vec<u8> = Vec::new();
img.write_to(&mut Cursor::new(&mut image_data), ImageOutputFormat::Png)?;
let res_base64 = general_purpose::STANDARD.encode(image_data);
Ok(format!("data:image/png;base64,{}", res_base64))
}

pub fn white_img_placeholder(w: u32, h: u32) -> String {
let img = RgbaImage::new(w, h);
// img.iter_mut().for_each(|pixel| *pixel = 255);
image_to_browser_base64(&img).unwrap()
}
1 change: 0 additions & 1 deletion crates/minimal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ fn headless_app() {
app.insert_resource(bevy_frame_capture::scene::SceneController::new(
config.width,
config.height,
true
));

app.insert_resource(ClearColor(Color::rgb_u8(0, 0, 0)));
Expand Down

0 comments on commit a45e003

Please sign in to comment.