Divide by max
This commit is contained in:
parent
021ba892f8
commit
862cf9215e
2 changed files with 25 additions and 5 deletions
|
@ -43,6 +43,7 @@ impl Image {
|
|||
|
||||
let width = parts[1].parse::<usize>()?;
|
||||
let height = parts[2].parse::<usize>()?;
|
||||
let max_value = parts[3].parse::<usize>()?;
|
||||
|
||||
let numbers = Gn::<()>::new_scoped(move |mut s| {
|
||||
macro_rules! gen_try {
|
||||
|
@ -77,7 +78,11 @@ impl Image {
|
|||
None => bail!("Not enough elements"),
|
||||
};
|
||||
|
||||
let color = Color::new(r?, g?, b?);
|
||||
let r = r? / max_value as f64;
|
||||
let g = g? / max_value as f64;
|
||||
let b = b? / max_value as f64;
|
||||
|
||||
let color = Color::new(r, g, b);
|
||||
data.push(color);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
use std::{fs::File, io::Read, path::Path};
|
||||
use std::{
|
||||
fs::File,
|
||||
io::Read,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use anyhow::Result;
|
||||
use itertools::Itertools;
|
||||
use nalgebra::Vector3;
|
||||
|
||||
use crate::{
|
||||
image::Color,
|
||||
image::{Color, Image},
|
||||
scene::{
|
||||
cylinder::Cylinder,
|
||||
data::{Attenuation, Light, LightKind, Material, Object},
|
||||
|
@ -21,11 +25,13 @@ use super::data::{DepthCueing, ObjectKind};
|
|||
impl Scene {
|
||||
/// Parse the input file into a scene
|
||||
pub fn from_input_file(path: impl AsRef<Path>) -> Result<Self> {
|
||||
let path = path.as_ref();
|
||||
|
||||
// Scope the read so the file is dropped and closed immediately after the
|
||||
// contents have been read to memory
|
||||
let contents = {
|
||||
let mut contents = String::new();
|
||||
let mut file = File::open(path.as_ref())?;
|
||||
let mut file = File::open(path)?;
|
||||
file.read_to_string(&mut contents)?;
|
||||
contents
|
||||
};
|
||||
|
@ -281,7 +287,16 @@ impl Scene {
|
|||
}
|
||||
}
|
||||
|
||||
"texture" => {}
|
||||
"texture" => {
|
||||
let input_parent = path.parent().unwrap().to_path_buf();
|
||||
let path = match parts.next() {
|
||||
Some(s) => input_parent.join(s),
|
||||
None => bail!("Did not provide path."),
|
||||
};
|
||||
|
||||
let image = Image::from_file(path)?;
|
||||
scene.textures.push(image);
|
||||
}
|
||||
|
||||
_ => bail!("Unknown keyword {keyword}"),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue