Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor exr metadata module #108

Merged
merged 1 commit into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/exr_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
use exr::prelude::*;

/// Print the metadatas of a an EXR using a path as an input
pub fn read_meta(path: String) {
/// Print the metadatas of a an EXR using a path as an input, the output is
/// trying to the closer as `rvls -l` without the formating
pub fn read_meta(path: String) -> String {
let msg = format!("run path `{}` to generate the required file", &path);
let meta_data = MetaData::read_from_file(
&path,
false, // do not throw an error for invalid or missing attributes, skipping them instead
)
.expect(&msg);
// Iterate over the headers
let mut metadata: Vec<String> = Vec::new();
for (layer_index, image_layer) in meta_data.headers.iter().enumerate() {
println!(
metadata.push(format!(
"{} layer #{} size:{:?}; channels:{:?}",
&path, layer_index, image_layer.layer_size, image_layer.channels
);
));
}
// Join the headers
metadata.join(",")
}
#[test]
fn test_read_meta() {
let source = "./samples/big/RenderPass_Beauty_1_00000.exr".to_string();
let expect = "./samples/big/RenderPass_Beauty_1_00000.exr layer #0 size:Vec2(320, 143); channels:ChannelList { list: [ChannelDescription { name: exr::Text(\"A\"), sample_type: F16, quantize_linearly: false, sampling: Vec2(1, 1) }, ChannelDescription { name: exr::Text(\"B\"), sample_type: F16, quantize_linearly: false, sampling: Vec2(1, 1) }, ChannelDescription { name: exr::Text(\"G\"), sample_type: F16, quantize_linearly: false, sampling: Vec2(1, 1) }, ChannelDescription { name: exr::Text(\"Plane_Beauty.A\"), sample_type: F16, quantize_linearly: false, sampling: Vec2(1, 1) }, ChannelDescription { name: exr::Text(\"Plane_Beauty.B\"), sample_type: F16, quantize_linearly: false, sampling: Vec2(1, 1) }, ChannelDescription { name: exr::Text(\"Plane_Beauty.G\"), sample_type: F16, quantize_linearly: false, sampling: Vec2(1, 1) }, ChannelDescription { name: exr::Text(\"Plane_Beauty.R\"), sample_type: F16, quantize_linearly: false, sampling: Vec2(1, 1) }, ChannelDescription { name: exr::Text(\"R\"), sample_type: F16, quantize_linearly: false, sampling: Vec2(1, 1) }, ChannelDescription { name: exr::Text(\"Spheres_Beauty.A\"), sample_type: F16, quantize_linearly: false, sampling: Vec2(1, 1) }, ChannelDescription { name: exr::Text(\"Spheres_Beauty.B\"), sample_type: F16, quantize_linearly: false, sampling: Vec2(1, 1) }, ChannelDescription { name: exr::Text(\"Spheres_Beauty.G\"), sample_type: F16, quantize_linearly: false, sampling: Vec2(1, 1) }, ChannelDescription { name: exr::Text(\"Spheres_Beauty.R\"), sample_type: F16, quantize_linearly: false, sampling: Vec2(1, 1) }], bytes_per_pixel: 24, uniform_sample_type: Some(F16) }".to_string();
assert_eq!(expect, read_meta(source));
}
25 changes: 17 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,14 @@ fn create_frame_string(value: Vec<String>) -> String {
convert_vec_to_str(group_continuity)
}
#[test]
fn test_create_frame_string(){
let source: Vec<String> = vec!["001".to_string(), "005".to_string(), "003".to_string(),"002".to_string()];
let expected: String ="1-3,5".to_string();
fn test_create_frame_string() {
let source: Vec<String> = vec![
"001".to_string(),
"005".to_string(),
"003".to_string(),
"002".to_string(),
];
let expected: String = "1-3,5".to_string();
assert_eq!(expected, create_frame_string(source));
}
/// ## Basic listing of the library
Expand All @@ -224,11 +229,13 @@ pub fn basic_listing(frames: Vec<String>) -> Vec<String> {
}
/// This function is intented to check if a file is an exr to call exr module
/// and print the exr metadata of the file
fn get_exr_metada(re: &Regex, root_path: &String, path: &String){
fn get_exr_metada(re: &Regex, root_path: &String, path: &String) -> String {
if re.is_match(&path) {
let path = format!("{}{}", root_path, path);
read_meta(path);
};
read_meta(path)
} else {
"Not an exr".to_string()
}
}
/// ## Extended function of the Library
/// ### Description
Expand All @@ -244,17 +251,19 @@ pub fn extended_listing(root_path: String, frames: Vec<String>) -> Vec<String> {
let re: Regex = Regex::new(r".*.exr$").unwrap();
let frames_dict: HashMap<String, Vec<String>> = parse_result(frames);
let mut out_frames: Vec<String> = Vec::new();
let mut medata: Vec<String> = Vec::new();
for (key, value) in frames_dict {
if value[0] == "None" && value.len() == 1 {
get_exr_metada(&re, &root_path, &key);
medata.push(get_exr_metada(&re, &root_path, &key));
out_frames.push(key);
} else {
let to = value.first().unwrap();
let from = String::from_utf8(vec![b'*'; to.len()]).unwrap();
let new_path = &key.replace(&from, to);
get_exr_metada(&re, &root_path, &new_path);
medata.push(get_exr_metada(&re, &root_path, &new_path));
out_frames.push(format!("{}@{}", key, create_frame_string(value)));
}
}
out_frames.append(&mut medata);
out_frames
}