diff options
Diffstat (limited to 'source')
66 files changed, 0 insertions, 4490 deletions
diff --git a/source/benoit/benoit.rs b/source/benoit/benoit.rs deleted file mode 100644 index 55a1e44..0000000 --- a/source/benoit/benoit.rs +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -pub mod app; -pub mod colour_data; -pub mod complex; -pub mod configuration; -pub mod image; -pub mod fractal; -pub mod launcher; -pub mod palette; -pub mod render; -pub mod render_data; -pub mod script; -pub mod video; - -pub const VERSION: (u32, u32, u32) = ( - 0x2, // Major - 0x7, // Minor - 0x1, // Patch -); - -pub const PRECISION: u32 = 0x80; - -pub const BAILOUT_DISTANCE: f32 = 256.0; - -pub fn width_height_ratio(width: u32, height: u32) -> (f32, f32) { - return if width > height { - (1.0, height as f32 / width as f32) - } else { - (width as f32 / height as f32, 1.0) - }; -} diff --git a/source/benoit/benoit/app.rs b/source/benoit/benoit/app.rs deleted file mode 100644 index 3f487f7..0000000 --- a/source/benoit/benoit/app.rs +++ /dev/null @@ -1,61 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::complex::Complex; -use crate::benoit::fractal::Fractal; -use crate::benoit::palette::Palette; - -extern crate rug; - -use rug::Float; - -pub mod draw_feedback; -pub mod drop; -pub mod handle_keys; -pub mod new; -pub mod poll_events; -pub mod print_controls; -pub mod render; -pub mod run; - -pub struct App { - // Configuration: - fractal: Fractal, - - canvas_width: u32, - canvas_height: u32, - scale: u32, - - centre: Complex, - extra: Complex, - zoom: Float, - - max_iter_count: u32, - - palette: Palette, - colour_range: f32, - - // Flags: - do_render: bool, - do_textual_feedback: bool, -} diff --git a/source/benoit/benoit/app/draw_feedback.rs b/source/benoit/benoit/app/draw_feedback.rs deleted file mode 100644 index e21b343..0000000 --- a/source/benoit/benoit/app/draw_feedback.rs +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::app::App; -use crate::benoit::complex::Complex; -use crate::benoit::video::Video; - -extern crate rug; - -use rug::Float; - -impl App { - pub(super) fn draw_feedback(&self, video: &mut Video, prev_centre: &Complex, prev_zoom: &Float) { - if { - // Don't draw translation feedback if rendering a - // Julia set or if we haven't done any viewport - // translations. - - &self.centre.real != &prev_centre.real - || &self.centre.imag != &prev_centre.imag - || &self.zoom != prev_zoom - }{ - video.draw_translation_feedback(self.canvas_width, self.canvas_height, self.scale, prev_centre, prev_zoom, &self.centre, &self.zoom); - } - - if self.do_textual_feedback { video.draw_textual_feedback(&self.centre, &self.zoom, self.max_iter_count) }; - } -}
\ No newline at end of file diff --git a/source/benoit/benoit/app/drop.rs b/source/benoit/benoit/app/drop.rs deleted file mode 100644 index dfa6de1..0000000 --- a/source/benoit/benoit/app/drop.rs +++ /dev/null @@ -1,31 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::app::App; - -impl Drop for App { - fn drop(&mut self) { - eprintln!(); - eprintln!("Goodbye!"); - } -} diff --git a/source/benoit/benoit/app/handle_keys.rs b/source/benoit/benoit/app/handle_keys.rs deleted file mode 100644 index df35ea5..0000000 --- a/source/benoit/benoit/app/handle_keys.rs +++ /dev/null @@ -1,170 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::PRECISION; -use crate::benoit::app::App; -use crate::benoit::configuration::Configuration; - -extern crate rug; -extern crate sdl2; - -use rug::{Assign, Float}; -use sdl2::keyboard::{KeyboardState, Scancode}; - -impl App { - #[must_use] - pub(super) fn handle_keys(&mut self, scan_code: Scancode, state: KeyboardState) -> bool { - if scan_code == Scancode::C { self.do_render = true }; - - if state.is_scancode_pressed(Scancode::LShift) { return self.handle_shift_keys(scan_code) }; - - match scan_code { - Scancode::Escape => return true, - Scancode::F1 => self.do_textual_feedback = !self.do_textual_feedback, - Scancode::LAlt => self.cycle_fractal(-0x1), - Scancode::LCtrl => self.toggle_inverse(), - Scancode::Left => self.cycle_palette(-0x1), - Scancode::RAlt => self.cycle_fractal(0x1), - Scancode::Right => self.cycle_palette(0x1), - Scancode::Tab => self.toggle_julia(), - Scancode::X => self.reset_viewport(), - Scancode::Z => self.dump_info(), - _ => {}, - }; - - self.translate(scan_code); - - self.max_iter_count = match scan_code { - Scancode::F => self.max_iter_count * 0x2, - Scancode::R => (self.max_iter_count / 0x2).max(0x1), - _ => self.max_iter_count, - }; - - const COLOUR_RANGE_FACTOR: f32 = 1.0 + 1.0 / 16.0; - - self.colour_range = match scan_code { - Scancode::Up => self.colour_range * COLOUR_RANGE_FACTOR, - Scancode::Down => (self.colour_range / COLOUR_RANGE_FACTOR).max(Configuration::MIN_COLOUR_RANGE), - _ => self.colour_range, - }; - - return false; - } - - #[must_use] - fn handle_shift_keys(&mut self, scan_code: Scancode) -> bool { - let translate_ammount = Float::with_val(PRECISION, 4.0 / 64.0 / &self.zoom); - - match scan_code { - Scancode::A => self.extra.real -= &translate_ammount, - Scancode::D => self.extra.real += &translate_ammount, - _ => {}, - }; - - match scan_code { - Scancode::S => self.extra.imag -= &translate_ammount, - Scancode::W => self.extra.imag += &translate_ammount, - _ => {}, - }; - - return false; - } - - fn translate(&mut self, scan_code: Scancode) { - const ZOOM_FACTOR: f32 = 1.0 + 1.0 / 4.0; - - match scan_code { - Scancode::E => self.zoom *= ZOOM_FACTOR, - Scancode::Q => self.zoom /= ZOOM_FACTOR, - _ => {}, - }; - - let translate_ammount = Float::with_val(PRECISION, 4.0 / 16.0 / &self.zoom); - - match scan_code { - Scancode::A => self.centre.real -= &translate_ammount, - Scancode::D => self.centre.real += &translate_ammount, - _ => {}, - }; - - match scan_code { - Scancode::S => self.centre.imag -= &translate_ammount, - Scancode::W => self.centre.imag += &translate_ammount, - _ => {}, - }; - } - - fn cycle_fractal(&mut self, distance: i8) { - self.fractal.kind.cycle(distance); - - eprintln!("renderer the {}", self.fractal.kind.name()); - } - - fn toggle_inverse(&mut self) { - self.fractal.inverse = !self.fractal.inverse; - - match self.fractal.inverse { - false => eprintln!("reverting fractal"), - true => eprintln!("inverting fractals"), - }; - } - - fn toggle_julia(&mut self) { - self.fractal.julia = !self.fractal.julia; - - match self.fractal.julia { - false => eprintln!("disabled the julia set"), - true => eprintln!("enabled the julia set"), - }; - } - - fn cycle_palette(&mut self, direction: i8) { - self.palette.cycle(direction); - - eprintln!("using palette \"{}\"", self.palette.name()); - } - - fn reset_viewport(&mut self) { - self.centre.real.assign(Configuration::DEFAULT_CENTRE.0); - self.centre.imag.assign(Configuration::DEFAULT_CENTRE.1); - self.zoom.assign( Configuration::DEFAULT_ZOOM); - - self.extra.real.assign(Configuration::DEFAULT_EXTRA.0); - self.extra.imag.assign(Configuration::DEFAULT_EXTRA.1); - - self.max_iter_count = Configuration::DEFAULT_MAX_ITER_COUNT; - - self.colour_range = Configuration::DEFAULT_COLOUR_RANGE; - } - - fn dump_info(&self) { - eprintln!("info dump: the {}", self.fractal.name()); - eprintln!(" re(c): {}", self.centre.real); - eprintln!(" im(c): {}", self.centre.imag); - eprintln!(" re(w): {}", self.extra.real); - eprintln!(" im(w): {}", self.extra.imag); - eprintln!(" zoom: {}", self.zoom); - eprintln!(" max. iter count: {}", self.max_iter_count); - eprintln!(" col. range: {}", self.colour_range); - } -} diff --git a/source/benoit/benoit/app/new.rs b/source/benoit/benoit/app/new.rs deleted file mode 100644 index f19380a..0000000 --- a/source/benoit/benoit/app/new.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::PRECISION; -use crate::benoit::app::App; -use crate::benoit::complex::Complex; -use crate::benoit::configuration::Configuration; - -extern crate rug; - -use rug::Float; - -impl App { - #[must_use] - pub fn new(canvas_width: u32, canvas_height: u32) -> App { - return App { - fractal: Configuration::DEFAULT_FRACTAL, - - canvas_width: canvas_width, - canvas_height: canvas_height, - scale: 0x2, - - centre: Complex::new(Float::with_val(PRECISION, Configuration::DEFAULT_CENTRE.0), Float::with_val(PRECISION, Configuration::DEFAULT_CENTRE.1)), - extra: Complex::new(Float::with_val(PRECISION, Configuration::DEFAULT_EXTRA.0), Float::with_val(PRECISION, Configuration::DEFAULT_EXTRA.1)), - zoom: Float::with_val(PRECISION, Configuration::DEFAULT_ZOOM), - - max_iter_count: Configuration::DEFAULT_MAX_ITER_COUNT, - - palette: Configuration::DEFAULT_PALETTE, - colour_range: Configuration::DEFAULT_COLOUR_RANGE, - - do_render: true, - do_textual_feedback: false, - }; - } -} diff --git a/source/benoit/benoit/app/poll_events.rs b/source/benoit/benoit/app/poll_events.rs deleted file mode 100644 index df24b0e..0000000 --- a/source/benoit/benoit/app/poll_events.rs +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::app::App; - -extern crate sdl2; - -use sdl2::EventPump; -use sdl2::event::Event; - -impl App { - #[must_use] - pub(super) fn poll_events(&mut self, pump: &mut EventPump) -> bool { - loop { - let event = match pump.poll_event() { - Some(event) => event, - None => break, - }; - - let quit = match event { - Event::KeyDown { - timestamp: _, - window_id: _, - keycode: _, - scancode: scan_code, - keymod: _, - repeat: _, - } => { - let state = pump.keyboard_state(); - - self.handle_keys(scan_code.unwrap(), state) - }, - Event::Quit { .. } => true, - _ => false, - }; - - if quit { return true }; - } - - return false; - } -} diff --git a/source/benoit/benoit/app/print_controls.rs b/source/benoit/benoit/app/print_controls.rs deleted file mode 100644 index 99cab61..0000000 --- a/source/benoit/benoit/app/print_controls.rs +++ /dev/null @@ -1,65 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::app::App; - -impl App { - pub(super) fn print_controls() { - println!(""); - println!("controls:"); - println!("- \u{1B}[1mW\u{1B}[0m translate +Im"); - println!("- \u{1B}[1mA\u{1B}[0m translate -Re"); - println!("- \u{1B}[1mS\u{1B}[0m translate -Im"); - println!("- \u{1B}[1mD\u{1B}[0m translate +Re"); - println!(); - println!("- \u{1B}[1mQ\u{1B}[0m zoom out"); - println!("- \u{1B}[1mE\u{1B}[0m zoom in"); - println!(); - println!("- \u{1B}[1mR\u{1B}[0m decrease max. iteration count"); - println!("- \u{1B}[1mF\u{1B}[0m increase max. iteration count"); - println!(); - println!("- \u{1B}[1mLEFT ALT\u{1B}[0m cycle to previous fractal"); - println!("- \u{1B}[1mRIGHT ALT\u{1B}[0m cycle to next fractal"); - println!("- \u{1B}[1mTAB\u{1B}[0m toggle Julia"); - println!("- \u{1B}[1mLEFT CTRL\u{1B}[0m toggle inverse"); - println!(); - println!("- \u{1B}[1mLEFT\u{1B}[0m cycle to previous palette"); - println!("- \u{1B}[1mRIGHT\u{1B}[0m cycle to next palette"); - println!("- \u{1B}[1mUP\u{1B}[0m increase colour range"); - println!("- \u{1B}[1mDOWN\u{1B}[0m decrease colour range"); - println!(); - println!("- \u{1B}[1mF1\u{1B}[0m toggle textual feedback"); - println!("- \u{1B}[1mZ\u{1B}[0m print centre value (c)"); - println!(); - println!("- \u{1B}[1mC\u{1B}[0m render frame"); - println!(); - println!("Controls (holding \u{1B}[1mSHIFT\u{1B}[0m):"); - println!("- \u{1B}[1mW\u{1B}[0m perturbate/translate +Im"); - println!("- \u{1B}[1mA\u{1B}[0m perturbate/translate -Re"); - println!("- \u{1B}[1mS\u{1B}[0m perturbate/translate -Im"); - println!("- \u{1B}[1mD\u{1B}[0m perturbate/translate +Re"); - println!(); - println!("- \u{1B}[1mC\u{1B}[0m render frame"); - println!(); - } -}
\ No newline at end of file diff --git a/source/benoit/benoit/app/render.rs b/source/benoit/benoit/app/render.rs deleted file mode 100644 index 1ba6c01..0000000 --- a/source/benoit/benoit/app/render.rs +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::app::App; -use crate::benoit::render::Render; -use std::time::Instant; - -impl App { - pub(super) fn render(&self, render: &mut Render) -> Result<(), String> { - eprint!("rendering..."); - - let time_start = Instant::now(); - - render.render( - self.fractal, - &self.centre, - &self.zoom, - &self.extra, - self.max_iter_count, - )?; - - let render_time = time_start.elapsed(); - - eprintln!("\rrendered: {:.3}ms", render_time.as_micros() as f32 / 1000.0); - - return Ok(()); - } -}
\ No newline at end of file diff --git a/source/benoit/benoit/app/run.rs b/source/benoit/benoit/app/run.rs deleted file mode 100644 index 9652b8e..0000000 --- a/source/benoit/benoit/app/run.rs +++ /dev/null @@ -1,78 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::app::App; -use crate::benoit::image::Image; -use crate::benoit::render::Render; -use crate::benoit::video::Video; - -extern crate rug; - -use rug::Assign; -use std::time::Instant; - -impl App { - #[must_use] - pub fn run(mut self) -> Result<(), String> { - let mut video = Video::initialise(self.canvas_width, self.canvas_height, self.scale)?; - - App::print_controls(); - - let mut event_pump = match video.sdl.event_pump() { - Ok( pump) => pump, - Err(_) => return Err("unable to get event pump".to_string()), - }; - - let mut render = Render::allocate(self.canvas_width, self.canvas_height)?; - let mut image = Image::allocate( self.canvas_width, self.canvas_height)?; - - // Used for translation feedback: - let mut prev_centre = self.centre.clone(); - let mut prev_zoom = self.zoom.clone(); - - loop { - let start_frame = Instant::now(); - - if self.poll_events(&mut event_pump) { break }; - - if self.do_render { - self.render(&mut render)?; - - prev_centre.assign(&self.centre); - prev_zoom.assign( &self.zoom); - - self.do_render = false; - }; - - image.colour(&render, self.palette, self.max_iter_count, self.colour_range)?; - - video.draw_image(&image, self.scale); - self.draw_feedback(&mut video, &prev_centre, &prev_zoom); - video.update(); - - video.sync(&start_frame)?; - } - - return Ok(()); - } -}
\ No newline at end of file diff --git a/source/benoit/benoit/colour_data.rs b/source/benoit/benoit/colour_data.rs deleted file mode 100644 index 2c36672..0000000 --- a/source/benoit/benoit/colour_data.rs +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::palette::PaletteData; - -pub struct ColourData { - exponent: f32, - max_iter_count: u32, - colour_range: f32, - - palette_data: &'static PaletteData, -} - -impl ColourData { - #[must_use] - pub fn new( - exponent: f32, - max_iter_count: u32, - colour_range: f32, - palette_data: &'static PaletteData, - ) -> ColourData { - return ColourData { - exponent: exponent, - max_iter_count: max_iter_count, - colour_range: colour_range, - - palette_data: palette_data, - }; - } - - #[must_use] - pub fn consts(&self) -> (f32, u32, f32, &'static PaletteData) { - return (self.exponent, self.max_iter_count, self.colour_range, self.palette_data); - } -} diff --git a/source/benoit/benoit/complex.rs b/source/benoit/benoit/complex.rs deleted file mode 100644 index 204b586..0000000 --- a/source/benoit/benoit/complex.rs +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -extern crate rug; - -use rug::{Assign, Float}; - -#[derive(Clone)] -pub struct Complex { - pub real: Float, - pub imag: Float, -} - -impl Complex { - #[must_use] - pub fn new(real: Float, imag: Float) -> Complex { - return Complex { - real: real, - imag: imag, - }; - } - - pub fn assign(&mut self, other: &Self) { - self.real.assign(&other.real); - self.imag.assign(&other.imag); - } -} diff --git a/source/benoit/benoit/configuration.rs b/source/benoit/benoit/configuration.rs deleted file mode 100644 index 511a9aa..0000000 --- a/source/benoit/benoit/configuration.rs +++ /dev/null @@ -1,81 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::fractal::{Fractal, FractalKind}; -use crate::benoit::image::ImageFormat; -use crate::benoit::palette::Palette; - -extern crate rug; - -use rug::Float; - -pub mod default; -pub mod load; - -pub struct Configuration { - pub thread_count: u32, - - pub fractal: Fractal, - - pub canvas_width: u32, - pub canvas_height: u32, - pub palette: Palette, - - pub dump_path: String, - pub image_format: ImageFormat, - - pub start_frame: u32, - pub start_centre_real: Float, - pub start_centre_imag: Float, - pub start_extra_real: Float, - pub start_extra_imag: Float, - pub start_zoom: Float, - pub start_max_iter_count: u32, - pub start_colour_range: f32, - - pub stop_frame: u32, - pub stop_centre_real: Float, - pub stop_centre_imag: Float, - pub stop_extra_real: Float, - pub stop_extra_imag: Float, - pub stop_zoom: Float, - pub stop_max_iter_count: u32, - pub stop_colour_range: f32, -} - -impl Configuration { - pub const DEFAULT_FRACTAL: Fractal = Fractal { kind: FractalKind::Mandelbrot, inverse: false, julia: false }; - - pub const DEFAULT_CENTRE: (f64, f64) = (0.0, 0.0); - pub const DEFAULT_EXTRA: (f64, f64) = (0.0, 0.0); - pub const DEFAULT_ZOOM: f64 = 1.0; - - pub const DEFAULT_MAX_ITER_COUNT: u32 = 0x100; - - pub const DEFAULT_PALETTE: Palette = Palette::Fire; - pub const DEFAULT_COLOUR_RANGE: f32 = 64.0; - - pub const MIN_CANVAS_WIDTH: u32 = 0x2; - pub const MIN_MAX_ITER_COUNT: u32 = 0x1; - pub const MIN_COLOUR_RANGE: f32 = 2.0; -} diff --git a/source/benoit/benoit/configuration/default.rs b/source/benoit/benoit/configuration/default.rs deleted file mode 100644 index ecb6f58..0000000 --- a/source/benoit/benoit/configuration/default.rs +++ /dev/null @@ -1,66 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::PRECISION; -use crate::benoit::configuration::Configuration; -use crate::benoit::image::ImageFormat; - -extern crate rug; - -use rug::Float; - -impl Configuration { - #[must_use] - pub fn default() -> Configuration { - return Configuration { - thread_count: 0x0, // Automatic if null. - - fractal: Self::DEFAULT_FRACTAL, - - canvas_width: 0x100, - canvas_height: 0x100, - palette: Self::DEFAULT_PALETTE, - - dump_path: "./render".to_string(), - image_format: ImageFormat::Png, - - start_frame: 0x0, - start_centre_real: Float::with_val(PRECISION, Self::DEFAULT_CENTRE.0), - start_centre_imag: Float::with_val(PRECISION, Self::DEFAULT_CENTRE.1), - start_extra_real: Float::with_val(PRECISION, Self::DEFAULT_EXTRA.0), - start_extra_imag: Float::with_val(PRECISION, Self::DEFAULT_EXTRA.1), - start_zoom: Float::with_val(PRECISION, Self::DEFAULT_ZOOM), - start_max_iter_count: Self::DEFAULT_MAX_ITER_COUNT, - start_colour_range: Self::DEFAULT_COLOUR_RANGE, - - stop_frame: 0xF, - stop_centre_real: Float::with_val(PRECISION, Self::DEFAULT_CENTRE.0), - stop_centre_imag: Float::with_val(PRECISION, Self::DEFAULT_CENTRE.1), - stop_extra_real: Float::with_val(PRECISION, Self::DEFAULT_EXTRA.0), - stop_extra_imag: Float::with_val(PRECISION, Self::DEFAULT_EXTRA.1), - stop_zoom: Float::with_val(PRECISION, Self::DEFAULT_ZOOM), - stop_max_iter_count: Self::DEFAULT_MAX_ITER_COUNT, - stop_colour_range: Self::DEFAULT_COLOUR_RANGE, - }; - } -} diff --git a/source/benoit/benoit/configuration/load.rs b/source/benoit/benoit/configuration/load.rs deleted file mode 100644 index 4995163..0000000 --- a/source/benoit/benoit/configuration/load.rs +++ /dev/null @@ -1,170 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::PRECISION; -use crate::benoit::configuration::Configuration; -use crate::benoit::fractal::FractalKind; -use crate::benoit::image::ImageFormat; -use crate::benoit::palette::Palette; - -extern crate rug; -extern crate toml; - -use rug::Float; -use std::fs::read; -use std::str::FromStr; -use toml::{Table, Value}; - -impl Configuration { - #[must_use] - pub fn load(path: &str) -> Result<Configuration, String> { - eprintln!("loading configuration at \"{path}\""); - - let mut configuration = Configuration::default(); - - let configuration_text = match read(path) { - Ok( content) => String::from_utf8_lossy(&content).to_string(), - Err(_) => return Err("unable to read configuration file".to_string()), - }; - - let base_table = match Table::from_str(configuration_text.as_str()) { - Ok( table) => table, - Err(_) => return Err("unable to parse configuration".to_string()), - }; - - let start_table = get_table(&base_table, "start")?; - let stop_table = get_table(&base_table, "stop")?; - - get_integer(&mut configuration.thread_count, &base_table, "thread_count")?; - - get_boolean(&mut configuration.fractal.inverse, &base_table, "inverse")?; - get_boolean(&mut configuration.fractal.julia, &base_table, "julia")?; - - get_integer(&mut configuration.canvas_width, &base_table, "canvas_width")?; - get_integer(&mut configuration.canvas_height, &base_table, "canvas_height")?; - - if let Some(start_table) = start_table { - get_integer( &mut configuration.start_frame, &start_table, "frame")?; - get_bigfloat(&mut configuration.start_centre_real, &start_table, "real")?; - get_bigfloat(&mut configuration.start_centre_imag, &start_table, "imaginary")?; - get_bigfloat(&mut configuration.start_extra_real, &start_table, "extra_real")?; - get_bigfloat(&mut configuration.start_extra_imag, &start_table, "extra_imaginary")?; - get_bigfloat(&mut configuration.start_zoom, &start_table, "zoom")?; - get_integer( &mut configuration.start_max_iter_count, &start_table, "maximum_iteration_count")?; - get_float( &mut configuration.start_colour_range, &start_table, "colour_range")?; - } - - if let Some(stop_table) = stop_table { - get_integer( &mut configuration.stop_frame, &stop_table, "frame")?; - get_bigfloat(&mut configuration.stop_centre_real, &stop_table, "real")?; - get_bigfloat(&mut configuration.stop_centre_imag, &stop_table, "imaginary")?; - get_bigfloat(&mut configuration.stop_extra_real, &stop_table, "extra_real")?; - get_bigfloat(&mut configuration.stop_extra_imag, &stop_table, "extra_imaginary")?; - get_bigfloat(&mut configuration.stop_zoom, &stop_table, "zoom")?; - get_integer( &mut configuration.stop_max_iter_count, &stop_table, "maximum_iteration_count")?; - get_float( &mut configuration.stop_colour_range, &stop_table, "colour_range")?; - } - - // Strings: - if let Some(name) = get_string(&base_table, "fractal")? { - configuration.fractal.kind = FractalKind::from_str(name.as_str())?; - } - - if let Some(name) = get_string(&base_table, "palette")? { - configuration.palette = Palette::from_str(name.as_str())?; - } - - if let Some(path) = get_string(&base_table, "dump_path")? { - configuration.dump_path = path.clone(); - } - - if let Some(name) = get_string(&base_table, "image_format")? { - configuration.image_format = ImageFormat::from_str(name.as_str())?; - } - - return Ok(configuration); - } -} - -fn get_value<'a>(table: &'a Table, name: &str) -> Option<&'a Value> { - if !table.contains_key(name) { return None }; - - return Some(&table[name]); -} - -fn get_table<'a>(table: &'a Table, name: &str) -> Result<Option<&'a Table>, String> { - return match get_value(table, name) { - Some(Value::Table(table)) => Ok(Some(table)), - Some(_) => Err(format!("\"{name}\" should be a section")), - _ => Ok(None), - }; -} - -fn get_boolean(buffer: &mut bool, table: &Table, name: &str) -> Result<(), String> { - match get_value(table, name) { - Some(Value::Boolean(value)) => *buffer = *value, - Some(_) => return Err(format!("\"{name}\" should be a boolean")), - _ => {}, - }; - return Ok(()) -} - -fn get_integer(buffer: &mut u32, table: &Table, name: &str) -> Result<(), String> { - match get_value(table, name) { - Some(Value::Integer(value)) => *buffer = (*value) as u32, - Some(_) => return Err(format!("\"{name}\" should be an integer")), - _ => {}, - }; - return Ok(()) -} - -fn get_float(buffer: &mut f32, table: &Table, name: &str) -> Result<(), String> { - match get_value(table, name) { - Some(Value::Float(value)) => *buffer = (*value) as f32, - Some(_) => return Err(format!("\"{name}\" should be a float")), - _ => {}, - }; - return Ok(()) -} - -fn get_bigfloat(buffer: &mut Float, table: &Table, name: &str) -> Result<(), String> { - match get_value(table, name) { - Some(Value::String(string)) => { - *buffer = match Float::parse(string) { - Ok(value) => Float::with_val(PRECISION, value), - _ => return Err(format!("invalid format of \"{name}\"")), - } - }, - Some(_) => return Err(format!("\"{name}“ should be a quoted float")), - _ => {}, - }; - return Ok(()) -} - -fn get_string(table: &Table, name: &str) -> Result<Option<String>, String> { - return match get_value(table, name) { - Some(Value::String(value)) => Ok(Some(value.clone())), - Some(_) => Err(format!("\"{name}\" should be a string")), - _ => Ok(None), - }; -} diff --git a/source/benoit/benoit/fractal.rs b/source/benoit/benoit/fractal.rs deleted file mode 100644 index d47573d..0000000 --- a/source/benoit/benoit/fractal.rs +++ /dev/null @@ -1,115 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::complex::Complex; - -use std::mem::transmute; - -pub mod from_str; - -mod iterate; - -pub type IteratorFunction = fn(&mut Complex, &Complex); - -#[derive(Clone, Copy)] -#[repr(u8)] -pub enum FractalKind { - Mandelbrot, - Multibrot3, - Multibrot4, - BurningShip, - Tricorn, -} - -impl FractalKind { - pub fn name(self) -> &'static str { - return match self { - FractalKind::BurningShip => "burning ship", - FractalKind::Mandelbrot => "mandelbrot set", - FractalKind::Multibrot3 => "multibrot3 set", - FractalKind::Multibrot4 => "multibrot4 set", - FractalKind::Tricorn => "tricorn", - }; - } - - pub fn cycle(&mut self, direction: i8) { - let raw = *self as i16 + direction as i16; - - const NUM: isize = FractalKind::Tricorn as isize + 0x1; - let new: u8 = match raw as isize { - -0x1 => (NUM - 0x1) as u8, - NUM => 0x0, - _ => raw as u8, - }; - - *self = unsafe { transmute(new) }; - } -} - -#[derive(Clone, Copy)] -pub struct Fractal { - pub kind: FractalKind, - pub inverse: bool, - pub julia: bool, -} - -impl Fractal { - pub fn name(&self) -> String { - let kind = self.kind.name(); - - let extra = if self.inverse && !self.julia { - "inverse" - } else if !self.inverse && self.julia { - "julia" - } else if self.inverse && self.julia { - "inverse julia" - } else { - "normal" - }; - - let name = format!("{kind} ({extra})"); - return name; - } - - #[must_use] - pub fn exponent(&self) -> f32 { - return match self.kind { - FractalKind::BurningShip => 2.0, - FractalKind::Mandelbrot => 2.0, - FractalKind::Multibrot3 => 3.0, - FractalKind::Multibrot4 => 4.0, - FractalKind::Tricorn => 2.0, - }; - } - - #[must_use] - pub fn iterator(&self) -> IteratorFunction { - return match self.kind { - FractalKind::BurningShip => iterate::burning_ship, - FractalKind::Mandelbrot => iterate::mandelbrot, - FractalKind::Multibrot3 => iterate::multibrot3, - FractalKind::Multibrot4 => iterate::multibrot4, - FractalKind::Tricorn => iterate::tricorn, - }; - } -} diff --git a/source/benoit/benoit/fractal/from_str.rs b/source/benoit/benoit/fractal/from_str.rs deleted file mode 100644 index 05cf22e..0000000 --- a/source/benoit/benoit/fractal/from_str.rs +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::fractal::FractalKind; - -use std::str::FromStr; - -impl FromStr for FractalKind { - type Err = String; - - fn from_str(string: &str) -> Result<Self, Self::Err> { - use FractalKind::*; - - let kind = match string { - "burning_ship" => Some(BurningShip), - "mandelbrot" => Some(Mandelbrot), - "multibrot3" => Some(Multibrot3), - "multibrot4" => Some(Multibrot4), - "tricorn" => Some(Tricorn), - _ => None, - }; - - return match kind { - Some(kind) => Ok(kind), - _ => Err(format!("invalid fractal kind \"{string}\"")), - }; - } -} diff --git a/source/benoit/benoit/fractal/iterate.rs b/source/benoit/benoit/fractal/iterate.rs deleted file mode 100644 index 59c5a77..0000000 --- a/source/benoit/benoit/fractal/iterate.rs +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -pub mod burning_ship; -pub mod mandelbrot; -pub mod multibrot3; -pub mod multibrot4; -pub mod tricorn; - -pub use burning_ship::*; -pub use mandelbrot::*; -pub use multibrot3::*; -pub use multibrot4::*; -pub use tricorn::*; diff --git a/source/benoit/benoit/fractal/iterate/burning_ship.rs b/source/benoit/benoit/fractal/iterate/burning_ship.rs deleted file mode 100644 index dae3a12..0000000 --- a/source/benoit/benoit/fractal/iterate/burning_ship.rs +++ /dev/null @@ -1,44 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::complex::Complex; - -pub fn burning_ship(z: &mut Complex, c: &Complex) { - // The Burning Ship is different in that - during - // iteration - the real and imaginary parts of (z) - // are made absolute: - // - // z(n+1) = (abs(Re(z(n)))+i*abs(Im(z(n))))^2+c. - - z.real.abs_mut(); // abs(a) - let za_temporary = z.real.clone(); // abs(a) - - z.real.square_mut(); // abs(a)^2 - z.real -= &z.imag * &z.imag; // abs(a)^2-abs(b)^2 - z.real += &c.real; // abs(a)^2-abs(b)^2+Re(c) - - z.imag.abs_mut(); // abs(b) - z.imag *= &za_temporary; // abs(a) - z.imag *= 2.0; // 2*abs(a) - z.imag += &c.imag; // 2*abs(a)+Im(c) -} diff --git a/source/benoit/benoit/fractal/iterate/mandelbrot.rs b/source/benoit/benoit/fractal/iterate/mandelbrot.rs deleted file mode 100644 index 078cc18..0000000 --- a/source/benoit/benoit/fractal/iterate/mandelbrot.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::complex::Complex; - -pub fn mandelbrot(z: &mut Complex, c: &Complex) { - // The Mandelbrot Set (M) is defined as the set of - // values in the complex plane where the iterating - // function - // - // z(n+1) = z(n)^2+c - // - // stays bounded: I.e. the absolute value of (z) stays bounded: - // - // abs(z) = sqrt(Re(z)^2+Im(z)^2) <= 2^2 = 4. - - let za_temporary = z.real.clone(); // a - - // We can calculate the square of a complex number - // as: - // - // (a+bi)^2 - // = (a+bi)(a+bi) - // = a^2+abi+abi-b^2 - // = a^2-b^2+2abi. - - z.real.square_mut(); // a^2 - z.real -= &z.imag * &z.imag; // a^2-b^2 - z.real += &c.real; // a^2-b^2+Re(c) - - z.imag *= &za_temporary; // ab - z.imag *= 2.0; // 2ab - z.imag += &c.imag; // 2ab+Im(c) -} diff --git a/source/benoit/benoit/fractal/iterate/multibrot3.rs b/source/benoit/benoit/fractal/iterate/multibrot3.rs deleted file mode 100644 index da58a5e..0000000 --- a/source/benoit/benoit/fractal/iterate/multibrot3.rs +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::complex::Complex; - -use crate::benoit::PRECISION; - -extern crate rug; - -use rug::Float; - -pub fn multibrot3(z: &mut Complex, c: &Complex) { - let za_temporary = z.real.clone(); // a - - // (a+bi)^3 - // = (a+bi)(a+bi)(a+bi) - // = (a^2-b^2+2abi)(a+bi) - // = a^3+(a^2)bi-ab^2-(b^3)i+2(a^2)bi-2ab^2 - // = a^3+3(a^2)bi-3ab^2-(b^3)i - // - // <=> a = a^3-3ab^2 - // b = 3(a^2)b-b^3 - - let mut temporary0 = Float::with_val(PRECISION, &z.imag * &z.imag); // b^2 - - let temporary1 = Float::with_val(PRECISION, &temporary0 * &z.imag); // b^3 - - temporary0 *= &z.real; // ab^2 - temporary0 *= 0x3; // 3ab^2 - - z.real.square_mut(); // a^2 - - z.imag *= &z.real; // (a^2)b - - z.real *= &za_temporary; // a^3 - z.real -= &temporary0; // a^3-3ab^2 - z.real += &c.real; // a^3-3ab^2+Re(c) - - z.imag *= 3.0; // 3(a^2)b - z.imag -= &temporary1; // 3(a^2)b-b^3 - z.imag += &c.imag; // 3(a^2)b-b^3+Im(c) - -} diff --git a/source/benoit/benoit/fractal/iterate/multibrot4.rs b/source/benoit/benoit/fractal/iterate/multibrot4.rs deleted file mode 100644 index d040cf3..0000000 --- a/source/benoit/benoit/fractal/iterate/multibrot4.rs +++ /dev/null @@ -1,64 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::complex::Complex; - -use crate::benoit::PRECISION; - -extern crate rug; - -use rug::{Assign, Float}; - -pub fn multibrot4(z: &mut Complex, c: &Complex) { - // (a+bi)^4 - // = (a+bi)^2*(a+bi)^2 - // = (a^2-b^2+2abi)^2 - // = (a^2-b^2+2abi)(a^2-b^2+2abi) - // = a^4-(a^2)b^2+2(a^3)bi-(a^2)b^2+b^4-2a(b^3)i-4(a^2)b^2+2(a^3)bi-2a(b^3)i-4(a^2)b^2 - // = a^4-6(a^2)b^2+4(a^3)bi+b^4-4a(b^3)i - // - // <=> a = a^4-6(a^2)b^2+b^4 - // b = 4(a^3)bi-4a(b^3)i - - let temporary0 = Float::with_val(PRECISION, &z.real * &z.real); // a^2 - let temporary1 = Float::with_val(PRECISION, &z.imag * &z.imag); // b^2 - - let mut temporary2 = Float::with_val(PRECISION, &z.real * &z.imag); // ab - temporary2 *= 4.0; // 4ab - - z.real.assign(&temporary0); // a^2 - z.real /= 6.0; // a^2/6 - z.real -= &temporary1; // a^2/6-b^2 - z.real *= &temporary0; // a^4/6-(a^2)b^2 - z.real *= 6.0; // a^4-6(a^2)b^2 - - z.imag.assign(&temporary1); // b^2 - z.imag *= -1.0; // -b^2 - z.imag += &temporary0; // a^2-b^2 - z.imag *= temporary2; // 4(a^3)b-4ab^3 - - z.real += temporary1.square(); // a^4-6(a^2)b^2+b^4 - z.real += &c.real; // a^4-6(a^2)b^2+b^4+Re(c) - - z.imag += &c.imag; // 4(a^3)b-4ab^3+Im(c) -} diff --git a/source/benoit/benoit/fractal/iterate/tricorn.rs b/source/benoit/benoit/fractal/iterate/tricorn.rs deleted file mode 100644 index a64b3aa..0000000 --- a/source/benoit/benoit/fractal/iterate/tricorn.rs +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::complex::Complex; - -pub fn tricorn(z: &mut Complex, c: &Complex) { - // The Tricorn is only different from the - // Mandelbrot Set in that the conjugate of (z) is - // used instead of just (z): - // - // z(n+1) = (Re(z(n))-Im(z(n))i)^2+c. - - let za_temporary = z.real.clone(); // a - - z.real.square_mut(); // a^2 - z.real -= &z.imag * &z.imag; // a^2-b^2 - z.real += &c.real; // a^2 - - z.imag *= &za_temporary; // ab - // We can negate the value by multiplying with - // (-1). A multiplication can be saved, as - // - // a*2*(-1) = a*(-2). - // - // Thus, we may combine these two multiplications. - z.imag *= -2.0; // -2ab - z.imag += &c.imag; // -2ab+Im(c) -} diff --git a/source/benoit/benoit/image.rs b/source/benoit/benoit/image.rs deleted file mode 100644 index 6d43d7a..0000000 --- a/source/benoit/benoit/image.rs +++ /dev/null @@ -1,74 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use std::ops::{Index, IndexMut}; -use std::slice::from_raw_parts; - -pub mod allocate; -pub mod colour; -pub mod dump; -pub mod from_str; - -pub struct Image { - width: u32, - height: u32, - - data: Vec::<(u8, u8, u8)>, -} - -#[derive(Clone, Copy)] -pub enum ImageFormat { - Png, - Webp, -} - -impl Image { - #[must_use] - pub fn size(&self) -> (u32, u32) { - return (self.width, self.height); - } - - #[must_use] - pub fn raw<'a>(&'a self) -> &'a [u8] { - let data_pointer = self.data.as_ptr() as *const u8; - - let length = self.height as usize * self.width as usize * 0x3; - let slice = unsafe { from_raw_parts(data_pointer, length) }; - - return slice; - } -} - -impl Index<usize> for Image { - type Output = (u8, u8, u8); - - fn index<'a>(&'a self, index: usize) -> &'a Self::Output { - return &self.data[index]; - } -} - -impl IndexMut<usize> for Image { - fn index_mut<'a>(&'a mut self, index: usize) -> &'a mut Self::Output { - return &mut self.data[index]; - } -} diff --git a/source/benoit/benoit/image/allocate.rs b/source/benoit/benoit/image/allocate.rs deleted file mode 100644 index bfd5a46..0000000 --- a/source/benoit/benoit/image/allocate.rs +++ /dev/null @@ -1,44 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::configuration::Configuration; -use crate::benoit::image::Image; - -impl Image { - #[must_use] - pub fn allocate(width: u32, height: u32) -> Result<Image, String> { - if width < Configuration::MIN_CANVAS_WIDTH || height < Configuration::MIN_CANVAS_WIDTH { return Err(format!("width and height may not be more than {}", Configuration::MIN_CANVAS_WIDTH)) }; - - let (canvas_size, overflow) = (height as usize).overflowing_mul(width as usize); - if overflow { return Err("overflow when calculating canvas size".to_string()) }; - - let data: Vec::<(u8, u8, u8)> = vec![(0x0, 0x0, 0x0); canvas_size]; - - return Ok(Image { - width: width, - height: height, - - data: data, - }); - } -} diff --git a/source/benoit/benoit/image/colour.rs b/source/benoit/benoit/image/colour.rs deleted file mode 100644 index 3c3562e..0000000 --- a/source/benoit/benoit/image/colour.rs +++ /dev/null @@ -1,80 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::colour_data::ColourData; -use crate::benoit::configuration::Configuration; -use crate::benoit::image::Image; -use crate::benoit::palette::{Palette, PALETTE_DATA_LENGTH}; -use crate::benoit::render::Render; - -extern crate rayon; - -use rayon::prelude::*; - -impl Image { - pub fn colour(&mut self, render: &Render, palette: Palette, new_max_iter_count: u32, colour_range: f32) -> Result<(), String> { - if render.size() != self.size() { return Err(format!("size mismatch - {}*{} (render) vs. {}*{} (image)", render.size().0, render.size().1, self.size().0, self.size().1)) }; - - if new_max_iter_count < Configuration::MIN_MAX_ITER_COUNT { return Err(format!("maximum_iteration_count must be at least {}", Configuration::MIN_MAX_ITER_COUNT)) }; - if colour_range < Configuration::MIN_COLOUR_RANGE { return Err(format!("colour range may not be less than {}", Configuration::MIN_COLOUR_RANGE)) }; - - let (fractal, max_iter_count) = match render.info() { - Some(info) => info, - None => return Err("cannot colour before render".to_string()), - }; - - let data = ColourData::new( - fractal.exponent(), - max_iter_count.min(new_max_iter_count), - colour_range, - palette.data(), - ); - - self.data.par_iter_mut().enumerate().for_each(|(index, point)| { - let (iter_count, dist) = render[index]; - - *point = colour_point(&data, iter_count, dist); - }); - - return Ok(()); - } -} - -fn colour_point(data: &ColourData, iter_count: u32, dist: f32) -> (u8, u8, u8) { - let (exponent, max_iter_count, colour_range, palette_data) = data.consts(); - - let (red, green, blue) = if iter_count < max_iter_count { - let factor = (iter_count as f32 + 1.0 - dist.ln().log(exponent)) / colour_range; - - let index = (factor * PALETTE_DATA_LENGTH as f32).round() as usize % PALETTE_DATA_LENGTH; - palette_data[index] - } else { - (0.0, 0.0, 0.0) - }; - - let red = (red * 255.0).round() as u8; - let green = (green * 255.0).round() as u8; - let blue = (blue * 255.0).round() as u8; - - return (red, green, blue); -} diff --git a/source/benoit/benoit/image/dump.rs b/source/benoit/benoit/image/dump.rs deleted file mode 100644 index cd1f1ea..0000000 --- a/source/benoit/benoit/image/dump.rs +++ /dev/null @@ -1,76 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::image::{Image, ImageFormat}; - -extern crate png; -extern crate webp; - -use std::fs::{File, write}; -use std::io::BufWriter; - -impl Image { - pub fn dump(&self, path: &str, format: ImageFormat) -> Result<(), String> { - use ImageFormat::*; - - return match format { - Png => self.dump_png( path), - Webp => self.dump_webp(path), - }; - } - - fn dump_png(&self, path: &str) -> Result<(), String> { - let path = path.to_owned() + ".png"; - - let file = match File::create(path) { - Ok( file) => file, - Err(_) => return Err("unable to create file".to_string()), - }; - let file_buffer = BufWriter::new(file); - - let mut encoder = png::Encoder::new(file_buffer, self.width, self.height); - encoder.set_color(png::ColorType::Rgb); - encoder.set_depth(png::BitDepth::Eight); - encoder.set_compression(png::Compression::Fast); - encoder.set_srgb(png::SrgbRenderingIntent::Perceptual); - - let mut writer = match encoder.write_header() { - Ok( writer) => writer, - Err(_) => return Err("unable to write image header".to_string()), - }; - if writer.write_image_data(self.raw()).is_err() { return Err("unable to write image".to_string()) }; - - return Ok(()); - } - - fn dump_webp(&self, path: &str) -> Result<(), String> { - let path = path.to_owned() + ".webp"; - - let encoder = webp::Encoder::from_rgb(self.raw(), self.width, self.height); - let data = encoder.encode_lossless(); - - if write(path, &*data).is_err() { return Err("unable to write image".to_string()) }; - - return Ok(()); - } -} diff --git a/source/benoit/benoit/image/from_str.rs b/source/benoit/benoit/image/from_str.rs deleted file mode 100644 index c4a86b9..0000000 --- a/source/benoit/benoit/image/from_str.rs +++ /dev/null @@ -1,45 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::image::ImageFormat; - -use std::str::FromStr; - -impl FromStr for ImageFormat { - type Err = String; - - fn from_str(string: &str) -> Result<Self, Self::Err> { - use ImageFormat::*; - - let kind = match string { - "png" => Some(Png), - "webp" => Some(Webp), - _ => None, - }; - - return match kind { - Some(kind) => Ok(kind), - _ => Err(format!("invalid image format \"{string}\"")), - }; - } -} diff --git a/source/benoit/benoit/launcher.rs b/source/benoit/benoit/launcher.rs deleted file mode 100644 index f38b6c3..0000000 --- a/source/benoit/benoit/launcher.rs +++ /dev/null @@ -1,45 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::configuration::Configuration; - -pub mod parse_arguments; -pub mod print_help; -pub mod print_message; -pub mod run; -pub mod set_title; -pub mod setup; - -pub enum Mode { - App( u32, u32), - Script(Configuration), -} - -pub struct Launcher {} - -impl Launcher { - #[must_use] - pub fn new() -> Launcher { - return Launcher {}; - } -} diff --git a/source/benoit/benoit/launcher/parse_arguments.rs b/source/benoit/benoit/launcher/parse_arguments.rs deleted file mode 100644 index 75adee1..0000000 --- a/source/benoit/benoit/launcher/parse_arguments.rs +++ /dev/null @@ -1,83 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::configuration::Configuration; -use crate::benoit::launcher::{Launcher, Mode}; - -use std::env::args; -use std::str::FromStr; - -impl Launcher { - #[must_use] - pub(super) fn parse_arguments(&self) -> Result<Mode, String> { - let arguments = args(); - - let mut width: Option<u32> = None; - let mut height: Option<u32> = None; - let mut configuration: Option<Configuration> = None; - - let mut command: Option<String> = None; - - for argument in arguments.skip(0x1) { - match command { - Some(_) => { - match command.take().unwrap().as_str() { - "height" => height = Some(u32::from_str(argument.as_str()).unwrap()), - "width" => width = Some(u32::from_str(argument.as_str()).unwrap()), - "path" => configuration = Some(Configuration::load(argument.as_str())?), - _ => {}, - } - continue; - }, - _ => {}, - } - - // Check if command doesn't take a value. - match argument.as_str() { - "help" => Launcher::print_help(), - _ => command = Some(argument.clone()), - }; - } - - if command.is_some() { return Err(format!("missing value to command \"{}\"", command.unwrap())) }; - - return if configuration.is_some() { - if width.is_some() || height.is_some() { eprintln!("width and height will be overwritten in script mode") }; - - Ok(Mode::Script(configuration.unwrap())) - } else { - // If only one length is specified, the other is - // assumed equal. - - let width_val = if let Some(val) = width { val } - else if let Some(val) = height { val } - else { 0x100 }; - - let height_val = if let Some(val) = height { val } - else if let Some(val) = width { val } - else { 0xC0 }; - - Ok(Mode::App(width_val, height_val)) - }; - } -} diff --git a/source/benoit/benoit/launcher/print_help.rs b/source/benoit/benoit/launcher/print_help.rs deleted file mode 100644 index 13d6805..0000000 --- a/source/benoit/benoit/launcher/print_help.rs +++ /dev/null @@ -1,66 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::launcher::Launcher; - -use std::process::exit; - -impl Launcher { - pub(super) fn print_help() -> ! { - println!("Usage:"); - println!(" benoit [--help] [path]"); - println!(); - println!("Configuration:"); - println!(" thread_count 0..=4294967295"); - println!(); - println!(" fractal \"mandelbrot\"|\"multibrot3\"|\"multibrot4\"|\"burningship\"|\"tricorn\""); - println!(" inverse false|true"); - println!(" julia false|true"); - println!(); - println!(" canvas_width 2..=4294967295"); - println!(" canvas_height 2..=4294967295"); - println!(" start_frame 0..=4294967295"); - println!(" stop_frame start_frame..=4294967295"); - println!(" palette \"emerald\"|\"fire\"|\"greyscale\"|\"hsv\"|\"lch\"|\"ruby\"|\"sapphire\"|\"simple\"|\"twilight\""); - println!(); - println!(" dump_path"); - println!(" image_format \"png\"|\"webp\""); - println!(); - println!("Additionally, the following parameters may be set in the \"start\" and \"stop\" sections:"); - println!(); - println!(" real \"0.0\"\u{B1}"); - println!(" imaginary \"0.0\"\u{B1}"); - println!(" extra_real \"0.0\"\u{B1}"); - println!(" extra_imaginary \"0.0\"\u{B1}"); - println!(" zoom \"0.0\"<"); - println!(" maximum_iteration_count 1..=4294967295"); - println!(" colour_range 2.0+"); - println!(); - println!("If not animating (stop_frame equals zero), only the latter section is used."); - println!("Note that real, imaginary, extra_real, extra_imaginary, and zoom - if present - must be quoted floats."); - println!("When choosing image format, keep in mind that PNG is faster whilst WebP yields better compression. Both are, however, lossless."); - println!(); - - exit(0x0); - } -} diff --git a/source/benoit/benoit/launcher/print_message.rs b/source/benoit/benoit/launcher/print_message.rs deleted file mode 100644 index 5f9314e..0000000 --- a/source/benoit/benoit/launcher/print_message.rs +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::VERSION; -use crate::benoit::launcher::Launcher; - -impl Launcher { - pub(super) fn print_message() { - println!(); - println!(" \u{1B}[1mBENO\u{CE}T\u{1B}[0m {:X}.{:X}.{:X}", VERSION.0, VERSION.1, VERSION.2); - println!(" Copyright 2021, 2023 \u{1B}[1mGabriel Bj\u{F8}rnager Jensen\u{1B}[0m."); - println!(); - println!(" \u{1B}[3mLe p\u{E8}re cogita et c'est pourquoi il fut.\u{1B}[0m"); - println!(); - } -} diff --git a/source/benoit/benoit/launcher/run.rs b/source/benoit/benoit/launcher/run.rs deleted file mode 100644 index ca71143..0000000 --- a/source/benoit/benoit/launcher/run.rs +++ /dev/null @@ -1,57 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::app::App; -use crate::benoit::launcher::{Launcher, Mode}; -use crate::benoit::script::Script; - -impl Launcher { - #[must_use] - pub fn run(self) -> Result<(), String> { - Launcher::print_message(); - - let mode = self.parse_arguments()?; - - let thread_count = match &mode { - Mode::Script(configuration) => configuration.thread_count, - _ => 0x0, - }; - - self.setup(thread_count); - - return match mode { - Mode::App(width, height) => { - eprintln!("running in iteractive mode"); - - let app = App::new(width, height); - app.run() - }, - Mode::Script(configuration) => { - eprintln!("running in script mode"); - - let script = Script::configure(configuration); - script.run() - }, - }; - } -} diff --git a/source/benoit/benoit/launcher/set_title.rs b/source/benoit/benoit/launcher/set_title.rs deleted file mode 100644 index 8066369..0000000 --- a/source/benoit/benoit/launcher/set_title.rs +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::launcher::Launcher; - -#[cfg(windows)] -extern crate windows; - -#[cfg(windows)] -use windows::Win32::System::Console::SetConsoleTitleA; - -impl Launcher { - pub fn set_title(title: &str) { - #[cfg(unix)] - { eprint!("\u{1B}]0;{title}\u{07}") }; - - #[cfg(windows)] - unsafe { SetConsoleTitleA(title) }; - } -} diff --git a/source/benoit/benoit/launcher/setup.rs b/source/benoit/benoit/launcher/setup.rs deleted file mode 100644 index da360dd..0000000 --- a/source/benoit/benoit/launcher/setup.rs +++ /dev/null @@ -1,51 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::VERSION; -use crate::benoit::launcher::Launcher; -use crate::benoit::palette::fill_palettes; - -extern crate rayon; - -use rayon::ThreadPoolBuilder; -use std::thread::available_parallelism; - -impl Launcher { - pub(super) fn setup(&self, thread_count: u32) { - Launcher::set_title(format!("BENO\u{CE}T {:X}.{:X}.{:X}", VERSION.0, VERSION.1, VERSION.2).as_str()); - - fill_palettes(); - - let thread_count = if thread_count == 0x0 { - match available_parallelism() { - Ok(ammount) => ammount.get() as u32, - _ => 0x2, // We assume at least two threads. - } - } else { - thread_count - }; - - eprintln!("using {} threads", thread_count); - ThreadPoolBuilder::new().num_threads(thread_count as usize).build_global().unwrap(); - } -} diff --git a/source/benoit/benoit/palette.rs b/source/benoit/benoit/palette.rs deleted file mode 100644 index 8235bbc..0000000 --- a/source/benoit/benoit/palette.rs +++ /dev/null @@ -1,104 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -extern crate enum_iterator; - -use enum_iterator::Sequence; -use std::mem::transmute; - -pub mod from_str; - -mod data; -mod paint; - -pub use data::fill_palettes; - -pub const PALETTE_DATA_LENGTH: usize = 0x1000; -pub type PaletteData = [(f32, f32, f32); PALETTE_DATA_LENGTH]; - -#[derive(Clone, Copy, Sequence)] -#[repr(u8)] -pub enum Palette { - Simple, - Twilight, - Fire, - Greyscale, - Ruby, - Emerald, - Sapphire, - Hsv, - Lch, -} - -impl Palette { - pub const NUM: usize = Self::Lch as usize + 0x1; - - #[must_use] - pub fn name(self) -> &'static str { - return match self { - Palette::Emerald => "emerald", - Palette::Fire => "fire", - Palette::Greyscale => "greyscale", - Palette::Hsv => "hsv", - Palette::Lch => "lch", - Palette::Ruby => "ruby", - Palette::Sapphire => "sapphire", - Palette::Simple => "simple", - Palette::Twilight => "twilight", - }; - } - - #[must_use] - pub fn data(self) -> &'static PaletteData { - // This is safe as we return it as immutable. - return unsafe { &*self.mut_data() }; - } - - pub fn cycle(&mut self, direction: i8) { - let raw = *self as i16 + direction as i16; - - const NUM: isize = Palette::NUM as isize; - let new: u8 = match raw as isize { - -0x1 => (Self::NUM - 0x1) as u8, - NUM => 0x0, - _ => raw as u8, - }; - - *self = unsafe { transmute(new) }; - } - - #[must_use] - fn function(self) -> fn(f32) -> (f32, f32, f32) { - return match self { - Palette::Emerald => paint::emerald, - Palette::Fire => paint::fire, - Palette::Greyscale => paint::greyscale, - Palette::Hsv => paint::hsv, - Palette::Lch => paint::lch, - Palette::Ruby => paint::ruby, - Palette::Sapphire => paint::sapphire, - Palette::Simple => paint::simple, - Palette::Twilight => paint::twilight, - }; - } -} diff --git a/source/benoit/benoit/palette/data.rs b/source/benoit/benoit/palette/data.rs deleted file mode 100644 index fdb8fa9..0000000 --- a/source/benoit/benoit/palette/data.rs +++ /dev/null @@ -1,70 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::palette::{Palette, PALETTE_DATA_LENGTH, PaletteData}; - -extern crate enum_iterator; - -use enum_iterator::all; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::time::Instant; - -impl Palette { - #[must_use] - pub(super) unsafe fn mut_data(self) -> &'static mut PaletteData { - return &mut PALETTE_DATA[self as usize]; - } -} - -static mut PALETTE_DATA: [PaletteData; Palette::NUM] = [[(0.0, 0.0, 0.0); PALETTE_DATA_LENGTH]; Palette::NUM]; - -pub fn fill_palettes() { - static PALETTES_FILLED: AtomicBool = AtomicBool::new(false); - - match PALETTES_FILLED.compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed) { - Err(_) => panic!("palettes already filled"), - _ => {}, - }; - - // We would like to precalculate the palettes at - // compile-time, but Rust does not allow - // const floating-point arithmetic. - - eprint!("filling palettes..."); - let time = Instant::now(); - - for palette in all::<Palette>() { - let data = unsafe { palette.mut_data() }; - let function = palette.function(); - - for index in 0x0..PALETTE_DATA_LENGTH { - let factor = index as f32 / PALETTE_DATA_LENGTH as f32; - - let (red, green, blue) = function(factor); - - data[index as usize] = (red, green, blue); - } - } - - eprintln!(" {:.3}ms", time.elapsed().as_micros() as f32 / 1000.0); -} diff --git a/source/benoit/benoit/palette/from_str.rs b/source/benoit/benoit/palette/from_str.rs deleted file mode 100644 index 3576d74..0000000 --- a/source/benoit/benoit/palette/from_str.rs +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::palette::Palette; - -use std::str::FromStr; - -impl FromStr for Palette { - type Err = String; - - fn from_str(string: &str) -> Result<Self, Self::Err> { - use Palette::*; - - let kind = match string { - "emerald" => Some(Emerald), - "fire" => Some(Fire), - "greyscale" => Some(Greyscale), - "hsv" => Some(Hsv), - "lch" => Some(Lch), - "ruby" => Some(Ruby), - "sapphire" => Some(Sapphire), - "simple" => Some(Simple), - "twilight" => Some(Twilight), - _ => None, - }; - - return match kind { - Some(kind) => Ok(kind), - _ => Err(format!("invalid palette \"{string}\"")), - }; - } -} diff --git a/source/benoit/benoit/palette/paint.rs b/source/benoit/benoit/palette/paint.rs deleted file mode 100644 index 84ff005..0000000 --- a/source/benoit/benoit/palette/paint.rs +++ /dev/null @@ -1,42 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -pub mod emerald; -pub mod fire; -pub mod greyscale; -pub mod hsv; -pub mod lch; -pub mod ruby; -pub mod sapphire; -pub mod simple; -pub mod twilight; - -pub use emerald::*; -pub use fire::*; -pub use greyscale::*; -pub use hsv::*; -pub use lch::*; -pub use ruby::*; -pub use sapphire::*; -pub use simple::*; -pub use twilight::*; diff --git a/source/benoit/benoit/palette/paint/emerald.rs b/source/benoit/benoit/palette/paint/emerald.rs deleted file mode 100644 index 7244e6a..0000000 --- a/source/benoit/benoit/palette/paint/emerald.rs +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -pub fn emerald(factor: f32) -> (f32, f32, f32) { - let factor = factor % 1.0; - - let factor = (if factor >= 1.0 / 2.0 { - 1.0 - factor - } else { - factor - }) * 2.0; - - return (factor * factor, factor, factor * factor * factor); -} diff --git a/source/benoit/benoit/palette/paint/fire.rs b/source/benoit/benoit/palette/paint/fire.rs deleted file mode 100644 index 9895210..0000000 --- a/source/benoit/benoit/palette/paint/fire.rs +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -// Classic colour palette, fixed (and smoothed) -// from version ↋. - -pub fn fire(factor: f32) -> (f32, f32, f32) { - let factor = factor % 1.0; - - let (red, green, blue) = if factor <= 1.0 / 4.0 { - (factor * 4.0, 0.0, 0.0) - } else if factor <= 1.0 / 2.0 { - let factor = factor - (1.0 / 4.0); - - (1.0, factor * 4.0, 0.0) - } else if factor <= 3.0 / 4.0 { - let factor = factor - (1.0 / 2.0); - - (1.0, 1.0, factor * 4.0) - } else { - let factor = 1.0 - factor; - - (factor * 4.0, factor * 4.0, factor * 4.0) - }; - - return (red, green, blue); -} diff --git a/source/benoit/benoit/palette/paint/greyscale.rs b/source/benoit/benoit/palette/paint/greyscale.rs deleted file mode 100644 index 046f6b8..0000000 --- a/source/benoit/benoit/palette/paint/greyscale.rs +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -// Original palette function after the Rust- -// rewrite (version 10). - -pub fn greyscale(factor: f32) -> (f32, f32, f32) { - let factor = factor % 1.0; - - let factor = (if factor >= 1.0 / 2.0 { - 1.0 - factor - } else { - factor - }) * 2.0; - - return (factor, factor, factor); -} diff --git a/source/benoit/benoit/palette/paint/hsv.rs b/source/benoit/benoit/palette/paint/hsv.rs deleted file mode 100644 index a9a6d9e..0000000 --- a/source/benoit/benoit/palette/paint/hsv.rs +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -pub fn hsv(factor: f32) -> (f32, f32, f32) { - return hsv_to_rgb(factor, 7.0 / 8.0, 7.0 / 8.0); -} - -fn hsv_to_rgb(hue: f32, saturation: f32, value: f32) -> (f32, f32, f32) { - return if saturation <= 0.0 { - let value = value.min(1.0); - - (value, value, value) - } else { - let h = hue % 1.0 * 6.0; - let s = saturation.min(1.0); - let v = value.min(1.0); - - let f = h % 1.0; - let p = v * (1.0 - s); - let q = v * (1.0 - s * f); - let t = v * (1.0 - s * (1.0 - f)); - - match h.trunc() as u8 { - 0x0 => (v, t, p), - 0x1 => (q, v, p), - 0x2 => (p, v, t), - 0x3 => (p, q, v), - 0x4 => (t, p, v), - 0x5 => (v, p, q), - _ => unreachable!(), - } - }; -} diff --git a/source/benoit/benoit/palette/paint/lch.rs b/source/benoit/benoit/palette/paint/lch.rs deleted file mode 100644 index 51d2ac0..0000000 --- a/source/benoit/benoit/palette/paint/lch.rs +++ /dev/null @@ -1,102 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use std::f32::consts::PI; - -pub fn lch(factor: f32) -> (f32, f32, f32) { - // Convert turns to radians: - // 1 turn = 2pi radians - - let angle = factor * PI * 2.0; - - let (l, a, b) = lch_to_lab( 200.0 / 3.0, 1053.0 / 20.0, angle); - let (x, y, z) = lab_to_xyz( l, a, b); - let (r, g, b) = xyz_to_rgb( x, y, z); - let (r, g, b) = rgb_to_srgb(r, g, b); - - return (r, g, b); -} - -fn rgb_to_srgb(r: f32, g: f32, b: f32) -> (f32, f32, f32) { - fn srgb(value: f32) -> f32 { - return if value > 7827.0 / 25000000.0 { - 211.0 / 200.0 * value.powf(5.0 / 12.0) - 11.0 / 200.0 - } else { - 298.0 / 25.0 * value - }; - } - - let r = srgb(r); - let g = srgb(g); - let b = srgb(b); - - (r, g, b) -} - -fn xyz_to_rgb(x: f32, y: f32, z: f32) -> (f32, f32, f32) { - let m: [[f32; 0x3]; 0x3] = [ - [ - 12831.0 / 3959.0, -329.0 / 214.0, -1974.0 / 3959.0, - ], - [ - -851781.0 / 878810.0, 1648619.0 / 878810.0, 36519.0 / 878810.0, - ], - [ - 705.0 / 12673.0, -2585.0 / 12673.0, 705.0 / 667.0, - ], - ]; - - let r = m[0x0][0x0] * x + m[0x0][0x1] * y + m[0x0][0x2] * z; - let g = m[0x1][0x0] * x + m[0x1][0x1] * y + m[0x1][0x2] * z; - let b = m[0x2][0x0] * x + m[0x2][0x1] * y + m[0x2][0x2] * z; - - return (r, g, b); -} - -fn lab_to_xyz(l: f32, a: f32, b: f32) -> (f32, f32, f32) { - let kappa: f32 = 24389.0 / 27.0; - let epsilon: f32 = 216.0 / 24389.0; - - let f1 = (l + 16.0) / 116.0; - let f0 = a / 500.0 + f1; - let f2 = f1 - b / 200.0; - - let temporary = (l + 16.0) / 116.0; - - let mut x = f0 * f0 * f0; - let mut y = temporary * temporary * temporary; - let mut z = f2 * f2 * f2; - - if x <= epsilon { x = 1152.0 / 1195.0 * ((116.0 * f0 - 16.0) / kappa) }; - if l <= kappa * epsilon { y = l / kappa }; - if z <= epsilon { z = 986.0 / 1195.0 * ((116.0 * f2 - 16.0) / kappa) }; - - return (x, y, z); -} - -fn lch_to_lab(l: f32, c: f32, h: f32) -> (f32, f32, f32) { - let a = c * h.cos(); - let b = c * h.sin(); - - return (l, a, b); -} diff --git a/source/benoit/benoit/palette/paint/ruby.rs b/source/benoit/benoit/palette/paint/ruby.rs deleted file mode 100644 index 8f23a3e..0000000 --- a/source/benoit/benoit/palette/paint/ruby.rs +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -pub fn ruby(factor: f32) -> (f32, f32, f32) { - let factor = factor % 1.0; - - let factor = (if factor >= 1.0 / 2.0 { - 1.0 - factor - } else { - factor - }) * 2.0; - - return (factor, factor * factor * factor, factor * factor); -} diff --git a/source/benoit/benoit/palette/paint/sapphire.rs b/source/benoit/benoit/palette/paint/sapphire.rs deleted file mode 100644 index 9ae4b0c..0000000 --- a/source/benoit/benoit/palette/paint/sapphire.rs +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -pub fn sapphire(factor: f32) -> (f32, f32, f32) { - let factor = factor % 1.0; - - let factor = (if factor >= 1.0 / 2.0 { - 1.0 - factor - } else { - factor - }) * 2.0; - - return (factor * factor * factor, factor * factor, factor); -} diff --git a/source/benoit/benoit/palette/paint/simple.rs b/source/benoit/benoit/palette/paint/simple.rs deleted file mode 100644 index c2e013f..0000000 --- a/source/benoit/benoit/palette/paint/simple.rs +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -// Original colour palette from MandelbrotSDL. - -pub fn simple(factor: f32) -> (f32, f32, f32) { - let red = factor * 3.0 % 1.0; - let green = factor * 5.0 % 1.0; - let blue = factor * 7.0 % 1.0; - - return (red, green, blue); -} diff --git a/source/benoit/benoit/palette/paint/twilight.rs b/source/benoit/benoit/palette/paint/twilight.rs deleted file mode 100644 index 79931ae..0000000 --- a/source/benoit/benoit/palette/paint/twilight.rs +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -// Palette function from mandelbrotsdl, my first -// Mandelbrot renderer. - -pub fn twilight(factor: f32) -> (f32, f32, f32) { - let factor = factor % 1.0; - - let red = 9.0 * (1.0 - factor) * factor * factor * factor; - let green = 15.0 * (1.0 - factor) * (1.0 - factor) * factor * factor; - let blue = 8.5 * (1.0 - factor) * (1.0 - factor) * (1.0 - factor) * factor; - - return (red, green, blue); -} diff --git a/source/benoit/benoit/render.rs b/source/benoit/benoit/render.rs deleted file mode 100644 index 9bd3756..0000000 --- a/source/benoit/benoit/render.rs +++ /dev/null @@ -1,64 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::fractal::Fractal; - -pub mod allocate; -pub mod render; - -use std::ops::{Index, IndexMut}; - -pub struct Render { - width: u32, - height: u32, - - info: Option<(Fractal, u32)>, - - data: Vec::<(u32, f32)>, -} - -impl Render { - #[must_use] - pub fn size(&self) -> (u32, u32) { - return (self.width, self.height); - } - - #[must_use] - pub fn info(&self) -> Option<(Fractal, u32)> { - return self.info.clone(); - } -} - -impl Index<usize> for Render { - type Output = (u32, f32); - - fn index<'a>(&'a self, index: usize) -> &'a Self::Output { - return &self.data[index]; - } -} - -impl IndexMut<usize> for Render { - fn index_mut<'a>(&'a mut self, index: usize) -> &'a mut Self::Output { - return &mut self.data[index]; - } -} diff --git a/source/benoit/benoit/render/allocate.rs b/source/benoit/benoit/render/allocate.rs deleted file mode 100644 index 8e9143d..0000000 --- a/source/benoit/benoit/render/allocate.rs +++ /dev/null @@ -1,45 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::configuration::Configuration; -use crate::benoit::render::Render; - -impl Render { - pub fn allocate(width: u32, height: u32) -> Result<Render, String> { - if width < Configuration::MIN_CANVAS_WIDTH || height < Configuration::MIN_CANVAS_WIDTH { return Err(format!("width and height may not be more than {}", Configuration::MIN_CANVAS_WIDTH)) }; - - let (canvas_size, overflow) = (height as usize).overflowing_mul(width as usize); - if overflow { return Err("overflow when calculating canvas size".to_string()) }; - - let data: Vec<(u32, f32)> = vec![(0x0, 0.0); canvas_size]; - - return Ok(Render { - width: width, - height: height, - - info: None, - - data: data, - }); - } -} diff --git a/source/benoit/benoit/render/render.rs b/source/benoit/benoit/render/render.rs deleted file mode 100644 index 4d11d14..0000000 --- a/source/benoit/benoit/render/render.rs +++ /dev/null @@ -1,136 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::{BAILOUT_DISTANCE, PRECISION}; -use crate::benoit::complex::Complex; -use crate::benoit::configuration::Configuration; -use crate::benoit::fractal::{Fractal, IteratorFunction}; -use crate::benoit::render::Render; -use crate::benoit::render_data::RenderData; - -extern crate rayon; -extern crate rug; - -use rayon::prelude::*; -use rug::{Assign, Float}; -use rug::float::Special; - -impl Render { - pub fn render( - &mut self, - fractal: Fractal, - centre: &Complex, - zoom: &Float, - extra: &Complex, - max_iter_count: u32, - ) -> Result<(), String> { - if *zoom <= 0x0 { return Err("zoom may not be negative nor zero".to_string()) }; - if max_iter_count < Configuration::MIN_MAX_ITER_COUNT { return Err(format!("maximum_iteration_count must be at least {}", Configuration::MIN_MAX_ITER_COUNT)) }; - - let data = RenderData::new( - &mut self.data[..], - self.width, - self.height, - centre.clone(), - extra.clone(), - zoom.clone(), - max_iter_count, - fractal.inverse, - fractal.julia, - ); - - let iterator = fractal.iterator(); - - self.data.par_iter_mut().for_each(|point| { - let (x, y) = data.coordinate(point); - *point = render_point(&data, x, y, iterator); - }); - - self.info = Some((fractal, max_iter_count)); - - return Ok(()); - } -} - -fn render_point(data: &RenderData, x: u32, y: u32, iterator: IteratorFunction) -> (u32, f32) { - let (centre, extra, zoom, max_iter_count, inverse, julia) = data.input(); - - let (x_offset, y_offset, x_factor, y_factor) = data.consts(); - - let x_temporary = (x as f32 + x_offset) * x_factor; - let y_temporary = (y as f32 + y_offset) * y_factor; - - let mut z = { - let mut a = Float::with_val(PRECISION, x_temporary / zoom); - a += ¢re.real; - - let mut b = Float::with_val(PRECISION, y_temporary / zoom); - b -= ¢re.imag; - - Complex {real: a, imag: b} - }; - - if inverse { - let mut factor_inverse = Float::with_val(PRECISION, &z.real * &z.real); - factor_inverse += &z.imag * &z.imag; - factor_inverse.recip_mut(); - - z.real *= &factor_inverse; - z.imag *= factor_inverse; - } - - // We can optimise pertubation by adding w (extra) - // to c. - let c = match julia { - false => Complex { real: Float::with_val(PRECISION, &z.real + &extra.real), imag: Float::with_val(PRECISION, &z.imag + &extra.imag) }, - true => extra.clone(), - }; - - let mut z_prev = Complex { - real: Float::with_val(PRECISION, Special::Nan), - imag: Float::with_val(PRECISION, Special::Nan), - }; - - let mut iter_count: u32 = 0x1; - let mut square_dist = Float::with_val(PRECISION, Special::Nan); - while { - square_dist.assign(&z.real * &z.real + &z.imag * &z.imag); - // Having a larger escape radius gives better - // results with regard to smoothing. - - // Check if the value is periodic, i.e. its - // sequence repeats. - let periodic = z.real == z_prev.real && z.imag == z_prev.imag; - if periodic { iter_count = max_iter_count } - - square_dist <= BAILOUT_DISTANCE && iter_count < max_iter_count - } { - z_prev.assign(&z); - - iterator(&mut z, &c); - - iter_count += 0x1; - } - - return (iter_count, square_dist.to_f32()); -} diff --git a/source/benoit/benoit/render_data.rs b/source/benoit/benoit/render_data.rs deleted file mode 100644 index 2f13d4b..0000000 --- a/source/benoit/benoit/render_data.rs +++ /dev/null @@ -1,112 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::width_height_ratio; -use crate::benoit::complex::Complex; - -extern crate rug; - -use rug::Float; -use std::mem::size_of; -use std::num::NonZeroUsize; -use std::ptr::addr_of; - -pub struct RenderData { - canvas_width: u32, - - centre: Complex, - extra: Complex, - zoom: Float, - - max_iter_count: u32, - - inverse: bool, - julia: bool, - - x_offset: f32, - y_offset: f32, - - x_factor: f32, - y_factor: f32, - - buffer: NonZeroUsize, -} - -impl RenderData { - #[must_use] - pub fn new( - buffer: &[(u32, f32)], - canvas_width: u32, - canvas_height: u32, - centre: Complex, - extra: Complex, - zoom: Float, - max_iter_count: u32, - inverse: bool, - julia: bool, - ) -> RenderData { - let (width_ratio, height_ratio) = width_height_ratio(canvas_width, canvas_height); - - return RenderData { - canvas_width: canvas_width, - - centre: centre, - extra: extra, - zoom: zoom, - - max_iter_count: max_iter_count, - - inverse: inverse, - julia: julia, - - x_offset: canvas_width as f32 / -2.0, - y_offset: canvas_height as f32 / -2.0, - - x_factor: 4.0 / canvas_width as f32 * width_ratio, - y_factor: 4.0 / canvas_height as f32 * height_ratio, - - buffer: NonZeroUsize::new(buffer.as_ptr() as usize).unwrap(), - }; - } - - #[must_use] - pub fn input(&self) -> (&Complex, &Complex, &Float, u32, bool, bool) { - return (&self.centre, &self.extra, &self.zoom, self.max_iter_count, self.inverse, self.julia); - } - - #[must_use] - pub fn consts(&self) -> (f32, f32, f32, f32) { - return (self.x_offset, self.y_offset, self.x_factor, self.y_factor); - } - - #[must_use] - pub fn coordinate(&self, element: &(u32, f32)) -> (u32, u32) { - let element_addr = addr_of!(*element) as usize; - - let index = (element_addr - self.buffer.get()) / size_of::<(u32, f32)>(); - - let x = (index % self.canvas_width as usize) as u32; - let y = (index / self.canvas_width as usize) as u32; - return (x, y); - } -} diff --git a/source/benoit/benoit/script.rs b/source/benoit/benoit/script.rs deleted file mode 100644 index fd34ab2..0000000 --- a/source/benoit/benoit/script.rs +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::complex::Complex; -use crate::benoit::fractal::Fractal; -use crate::benoit::image::ImageFormat; -use crate::benoit::palette::Palette; - -extern crate rug; - -use rug::Float; - -pub mod animate; -pub mod configure; -pub mod dump_frame; -pub mod run; -pub mod still; - -pub struct Keyframe { - frame: u32, - centre: Complex, - extra: Complex, - zoom: Float, - max_iter_count: u32, - colour_range: f32, -} - -pub struct Script { - // Configuration: - fractal: Fractal, - - canvas_width: u32, - canvas_height: u32, - - palette: Palette, - - dump_path: String, - image_format: ImageFormat, - - start: Keyframe, - stop: Keyframe, -} diff --git a/source/benoit/benoit/script/animate.rs b/source/benoit/benoit/script/animate.rs deleted file mode 100644 index d30ac8c..0000000 --- a/source/benoit/benoit/script/animate.rs +++ /dev/null @@ -1,165 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::PRECISION; -use crate::benoit::image::Image; -use crate::benoit::render::Render; -use crate::benoit::script::Script; - -extern crate rug; - -use rug::Float; -use rug::ops::PowAssign; - -impl Script { - #[must_use] - pub(super) fn animate(&self) -> Result<(), String> { - // TO-DO: Proper animation for centre value when zooming. - - let frame_count = self.stop.frame - self.start.frame + 0x1; - assert!(frame_count >= 0x2); - - let mut render = Render::allocate(self.canvas_width, self.canvas_height)?; - let mut image = Image::allocate( self.canvas_width, self.canvas_height)?; - - // Variables: - let mut centre = self.start.centre.clone(); - let mut extra = self.start.extra.clone(); - let mut zoom = self.start.zoom.clone(); - let mut max_iter_count = self.start.max_iter_count as f32; - let mut colour_range = self.start.colour_range; - - // Steps & factors: - let centre_real_step = get_step_bigfloat(self.stop.frame, &self.start.centre.real, &self.stop.centre.real); - let centre_imag_step = get_step_bigfloat(self.stop.frame, &self.start.centre.imag, &self.stop.centre.imag); - let extra_real_step = get_step_bigfloat(self.stop.frame, &self.start.extra.real, &self.stop.extra.real); - let extra_imag_step = get_step_bigfloat(self.stop.frame, &self.start.extra.imag, &self.stop.extra.imag); - let zoom_factor = get_factor_bigfloat(self.stop.frame, &self.start.zoom, &self.stop.zoom); - let max_iter_count_step = get_step(self.stop.frame, self.start.max_iter_count as f32, self.stop.max_iter_count as f32); - let colour_range_step = get_step(self.stop.frame, self.start.colour_range, self.stop.colour_range); - - eprintln!(""); - eprintln!("animating {frame_count} frames: the {}", self.fractal.name()); - eprintln!(" re(c): {} \u{2192} {} (step: {centre_real_step})", self.start.centre.real, self.stop.centre.real); - eprintln!(" im(c): {} \u{2192} {} (step: {centre_imag_step})", self.start.centre.imag, self.stop.centre.imag); - eprintln!(" re(w): {} \u{2192} {} (step: {extra_real_step})", self.start.extra.real, self.stop.extra.real); - eprintln!(" im(w): {} \u{2192} {} (step: {extra_imag_step})", self.start.extra.imag, self.stop.extra.imag); - eprintln!(" zoom: {} \u{2192} {} (fac.: {zoom_factor})", self.start.zoom, self.stop.zoom); - eprintln!(" max. iter count: {} \u{2192} {} (step: {max_iter_count_step})", self.start.max_iter_count, self.stop.max_iter_count); - eprintln!(" col. range: {} \u{2192} {} (step: {colour_range_step})", self.start.colour_range, self.stop.colour_range); - eprintln!(""); - - for frame in 0x0..frame_count { - let frame_name = format!("frame{frame:010}"); - - Script::dump_frame( - self.dump_path.as_str(), - frame_name.as_str(), - &mut image, - &mut render, - self.fractal, - self.palette, - ¢re, - &extra, - &zoom, - max_iter_count.round() as u32, - colour_range, - self.image_format, - )?; - - centre.real += ¢re_real_step; - centre.imag += ¢re_imag_step; - extra.real += &extra_real_step; - extra.imag += &extra_imag_step; - zoom *= &zoom_factor; - max_iter_count += max_iter_count_step; - colour_range += colour_range_step; - } - - return Ok(()); - } -} - -#[must_use] -fn get_step(stop_x: u32, start_y: f32, stop_y: f32) -> f32 { - assert!(stop_x - START_X != 0x0); - - const START_X: u32 = 0x1; - - // a = (y1-y0)/(x1-x0) - return (stop_y - start_y) / (stop_x as f32 - START_X as f32); -} - -#[allow(dead_code)] -#[must_use] -fn get_factor(stop_x: u32, start_y: f32, stop_y: f32) -> f32 { - assert!(stop_x - START_X != 0x0); - - const START_X: u32 = 0x1; - - // a = (y1/y0)^(1/(x1-x0)) - return (stop_y / start_y).powf(1.0 / (stop_x as f32 - START_X as f32)); -} - -#[must_use] -fn get_step_bigfloat(stop_x: u32, start_y: &Float, stop_y: &Float) -> Float { - assert!(stop_x - START_X > 0x0); - - const START_X: u32 = 0x1; - - let numerator = Float::with_val(PRECISION, stop_y - start_y); - let denominator = stop_x - START_X; - - return numerator / denominator; -} - -#[must_use] -fn get_factor_bigfloat(stop_x: u32, start_y: &Float, stop_y: &Float) -> Float { - assert!(stop_x - START_X > 0x0); - if stop_y == start_y { return Float::with_val(PRECISION, 0x1) }; - - const START_X: u32 = 0x1; - - // To get the zoom factor, we first want the 'a' - // value of the growth function from (0) to - // (frame_count) on the x-dimension and from - // (zoom_start) to (stop_zoom) on the y-dimension: - // - // a = nroot(x1-x0,y1/y0), - // - // but this may be simplified for use with Rug - // because - // - // nroot(a,b) = b^(1/a), - // - // making the final equation - // - // (y1/y0)^(1/(x1-x0)) = (stop_zoom/zoom_start)^(1/(frame_count-1)). - - let exponent = 1.0 / (stop_x as f64 - START_X as f64); - - let mut factor = Float::with_val(PRECISION, stop_y / start_y); - factor.pow_assign(exponent); - - return factor; -} diff --git a/source/benoit/benoit/script/configure.rs b/source/benoit/benoit/script/configure.rs deleted file mode 100644 index be2e1cd..0000000 --- a/source/benoit/benoit/script/configure.rs +++ /dev/null @@ -1,60 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::complex::Complex; -use crate::benoit::configuration::Configuration; -use crate::benoit::script::{Keyframe, Script}; - -impl Script { - #[must_use] - pub fn configure(configuration: Configuration) -> Script { - return Script { - fractal: configuration.fractal, - - canvas_width: configuration.canvas_width, - canvas_height: configuration.canvas_height, - palette: configuration.palette, - - dump_path: configuration.dump_path, - image_format: configuration.image_format, - - start: Keyframe { - frame: configuration.start_frame, - centre: Complex::new(configuration.start_centre_real, configuration.start_centre_imag), - extra: Complex::new(configuration.start_extra_real, configuration.start_extra_imag), - zoom: configuration.start_zoom, - max_iter_count: configuration.start_max_iter_count, - colour_range: configuration.start_colour_range, - }, - - stop: Keyframe { - frame: configuration.stop_frame, - centre: Complex::new(configuration.stop_centre_real, configuration.stop_centre_imag), - extra: Complex::new(configuration.stop_extra_real, configuration.stop_extra_imag), - zoom: configuration.stop_zoom, - max_iter_count: configuration.stop_max_iter_count, - colour_range: configuration.stop_colour_range, - }, - }; - } -} diff --git a/source/benoit/benoit/script/dump_frame.rs b/source/benoit/benoit/script/dump_frame.rs deleted file mode 100644 index 86b62c6..0000000 --- a/source/benoit/benoit/script/dump_frame.rs +++ /dev/null @@ -1,84 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::complex::Complex; -use crate::benoit::fractal::Fractal; -use crate::benoit::image::{Image, ImageFormat}; -use crate::benoit::launcher::Launcher; -use crate::benoit::palette::Palette; -use crate::benoit::render::Render; -use crate::benoit::script::Script; - -extern crate rug; - -use rug::Float; -use std::time::Instant; - -impl Script { - pub(super) fn dump_frame( - dump_path: &str, - name: &str, - image: &mut Image, - render: &mut Render, - fractal: Fractal, - palette: Palette, - centre: &Complex, - extra: &Complex, - zoom: &Float, - max_iter_count: u32, - colour_range: f32, - image_format: ImageFormat, - ) -> Result<(), String> { - eprint!("\u{1B}[1m\u{1B}[94mX\u{1B}[0m \"{name}\" (2^{:.9}x): rendering...", zoom.to_f64().log2()); - Launcher::set_title("Rendering..."); - - let time_start = Instant::now(); - - render.render( - fractal, - centre, - zoom, - extra, - max_iter_count, - )?; - - let render_time = time_start.elapsed(); - eprint!(" {:.3}ms, colouring...", render_time.as_micros() as f32 / 1000.0); - Launcher::set_title("Colouring..."); - - image.colour(&render, palette, max_iter_count, colour_range)?; - - let colour_time = time_start.elapsed() - render_time; - eprint!(" {:.3}ms, dumping...", colour_time.as_micros() as f32 / 1000.0); - Launcher::set_title("Dumping..."); - - let path = format!("{dump_path}/{name}"); - image.dump(path.as_str(), image_format)?; - - let dump_time = time_start.elapsed() - colour_time - render_time; - eprintln!(" {:.3}ms\r\u{1B}[1m\u{1B}[92mO\u{1B}[0m", dump_time.as_micros() as f32 / 1000.0); - Launcher::set_title("Done, waiting..."); - - return Ok(()); - } -} diff --git a/source/benoit/benoit/script/run.rs b/source/benoit/benoit/script/run.rs deleted file mode 100644 index 5a0f4c7..0000000 --- a/source/benoit/benoit/script/run.rs +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::script::Script; - -impl Script { - #[must_use] - pub fn run(self) -> Result<(), String> { - return match self.stop.frame == 0x0 && self.start.frame == 0x0 { - false => self.animate(), - true => self.still(), - }; - } -} diff --git a/source/benoit/benoit/script/still.rs b/source/benoit/benoit/script/still.rs deleted file mode 100644 index 65177d9..0000000 --- a/source/benoit/benoit/script/still.rs +++ /dev/null @@ -1,69 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::image::Image; -use crate::benoit::render::Render; -use crate::benoit::script::Script; - -impl Script { - #[must_use] - pub(super) fn still(&self) -> Result<(), String> { - let frame_count = self.stop.frame - self.start.frame + 0x1; - assert!(frame_count == 0x1); - - let mut render = Render::allocate(self.canvas_width, self.canvas_height)?; - let mut image = Image::allocate( self.canvas_width, self.canvas_height)?; - - const FRAME_NAME: &str = "render"; - - eprintln!(""); - eprintln!("rendering still: the {}", self.fractal.name()); - eprintln!(" width: {}", self.canvas_width); - eprintln!(" height: {}", self.canvas_height); - eprintln!(" re(c): {}", self.stop.centre.real); - eprintln!(" im(c): {}", self.stop.centre.imag); - eprintln!(" re(w): {}", self.stop.extra.real); - eprintln!(" im(w): {}", self.stop.extra.imag); - eprintln!(" zoom: {}", self.stop.zoom); - eprintln!(" max. iter count: {}", self.stop.max_iter_count); - eprintln!(" col. range: {}", self.stop.colour_range); - eprintln!(""); - - Script::dump_frame( - self.dump_path.as_str(), - FRAME_NAME, - &mut image, - &mut render, - self.fractal, - self.palette, - &self.stop.centre, - &self.stop.extra, - &self.stop.zoom, - self.stop.max_iter_count, - self.stop.colour_range, - self.image_format, - )?; - - return Ok(()); - } -} diff --git a/source/benoit/benoit/video.rs b/source/benoit/benoit/video.rs deleted file mode 100644 index d0de33f..0000000 --- a/source/benoit/benoit/video.rs +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -extern crate sdl2; - -use sdl2::{Sdl, VideoSubsystem}; -use sdl2::render::WindowCanvas; - -pub mod draw_image; -pub mod draw_textual_feedback; -pub mod draw_translation_feedback; -pub mod initialise; -pub mod sync; -pub mod update; - -pub struct Video { - pub sdl: Sdl, - pub sdl_video: VideoSubsystem, - pub canvas: WindowCanvas, -} diff --git a/source/benoit/benoit/video/draw_image.rs b/source/benoit/benoit/video/draw_image.rs deleted file mode 100644 index 9554b3b..0000000 --- a/source/benoit/benoit/video/draw_image.rs +++ /dev/null @@ -1,58 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::image::Image; -use crate::benoit::video::Video; - -extern crate sdl2; - -use sdl2::pixels::Color; -use sdl2::rect::Rect; - -impl Video { - pub fn draw_image(&mut self, image: &Image, scale: u32) { - let (canvas_width, canvas_height) = image.size(); - let canvas_size = canvas_height as usize * canvas_width as usize; - - for pixel in 0x0..canvas_size { - let x = pixel as u32 % canvas_width; - let y = pixel as u32 / canvas_width; - - let colour = { - let (red, green, blue) = image[pixel as usize]; - - Color::RGB(red, green, blue) - }; - - let square = Rect::new( - (x * scale) as i32, - (y * scale) as i32, - scale, - scale, - ); - - self.canvas.set_draw_color(colour); - self.canvas.fill_rect(square).unwrap(); - } - } -} diff --git a/source/benoit/benoit/video/draw_textual_feedback.rs b/source/benoit/benoit/video/draw_textual_feedback.rs deleted file mode 100644 index 72c9d2a..0000000 --- a/source/benoit/benoit/video/draw_textual_feedback.rs +++ /dev/null @@ -1,329 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::complex::Complex; -use crate::benoit::video::Video; - -extern crate rug; -extern crate sdl2; - -use rug::Float; -use sdl2::pixels::Color; -use sdl2::rect::Rect; -use sdl2::render::WindowCanvas; - -impl Video { - pub fn draw_textual_feedback(&mut self, centre: &Complex, zoom: &Float, max_iter_count: u32) { - let real_text = format!("REAL: {:.18}", centre.real.to_f64()); - let imag_text = format!("IMAG: {:.18}", centre.imag.to_f64()); - let zoom_text = format!("ZOOM: 2^{:.9}", zoom.to_f64().log2()); - let iter_text = format!("ITER: {}", max_iter_count); - - let string = format!("{real_text}\n{imag_text}\n{zoom_text}\n{iter_text}"); - - let mut offset_x = 0x1; - let mut offset_y = 0x1; - for character in string.chars() { - if character == '\n' { - offset_x = 0x1; - offset_y += TEXTURE_HEIGHT; - continue; - } - - let character = convert_character(character); - - draw_character(&mut self.canvas, offset_x, offset_y, character); - - offset_x += TEXTURE_WIDTH; - } - } -} - -fn draw_character(canvas: &mut WindowCanvas, x: u32, y: u32, character: u8) { - let texture = &FONT[character as usize]; - - for pixel in 0x0..TEXTURE_SIZE { - let alpha = texture[pixel] as u8 * 0xFF; - - let texture_y = pixel as u32 / TEXTURE_WIDTH; - let texture_x = pixel as u32 - texture_y * TEXTURE_WIDTH; - - let square = Rect::new( - (x * CHARACTER_SCALE + texture_x * CHARACTER_SCALE) as i32, - (y * CHARACTER_SCALE + texture_y * CHARACTER_SCALE) as i32, - CHARACTER_SCALE, - CHARACTER_SCALE, - ); - - canvas.set_draw_color(Color::RGBA(0xFF, 0xFF, 0xFF, alpha)); - canvas.fill_rect(square).unwrap(); - } -} - -fn convert_character(input: char) -> u8 { - return match input { - ' ' => 0x00, - 'A' => 0x01, - 'E' => 0x02, - 'G' => 0x03, - 'I' => 0x04, - 'L' => 0x05, - 'M' => 0x06, - 'O' => 0x07, - 'R' => 0x08, - 'T' => 0x09, - 'Z' => 0x0A, - '0' => 0x0B, - '1' => 0x0C, - '2' => 0x0D, - '3' => 0x0E, - '4' => 0x0F, - '5' => 0x10, - '6' => 0x11, - '7' => 0x12, - '8' => 0x13, - '9' => 0x14, - '-' => 0x15, - '^' => 0x16, - '.' => 0x17, - ':' => 0x18, - _ => 0x19, - }; -} - -const CHARACTER_SCALE: u32 = 0x2; - -const TEXTURE_WIDTH: u32 = 0x6; -const TEXTURE_HEIGHT: u32 = 0x6; -const TEXTURE_SIZE: usize = TEXTURE_HEIGHT as usize * TEXTURE_WIDTH as usize; - -const FONT: [[bool; TEXTURE_SIZE]; 0x1A] = [ - [ - false, false, false, false, false, false, - false, false, false, false, false, false, - false, false, false, false, false, false, - false, false, false, false, false, false, - false, false, false, false, false, false, - false, false, false, false, false, false, - ], - [ - false, true, true, true, false, false, - true, true, true, true, true, false, - true, true, false, true, true, false, - true, true, true, true, true, false, - true, true, false, true, true, false, - false, false, false, false, false, false, - ], - [ - true, true, true, true, true, false, - true, true, false, false, false, false, - true, true, true, true, false, false, - true, true, false, false, false, false, - true, true, true, true, true, false, - false, false, false, false, false, false, - ], - [ - true, true, true, true, true, false, - true, true, false, false, false, false, - true, true, false, true, true, false, - true, true, false, false, true, false, - true, true, true, true, true, false, - false, false, false, false, false, false, - ], - [ - true, true, true, true, true, false, - false, false, true, false, false, false, - false, false, true, false, false, false, - false, false, true, false, false, false, - true, true, true, true, true, false, - false, false, false, false, false, false, - ], - [ - true, true, false, false, false, false, - true, true, false, false, false, false, - true, true, false, false, false, false, - true, true, false, false, false, false, - true, true, true, true, true, false, - false, false, false, false, false, false, - ], - [ - true, true, false, true, true, false, - true, true, true, true, true, false, - true, true, true, true, true, false, - true, true, false, true, true, false, - true, true, false, true, true, false, - false, false, false, false, false, false, - ], - [ - false, true, true, true, false, false, - true, true, false, true, true, false, - true, true, false, true, true, false, - true, true, false, true, true, false, - false, true, true, true, false, false, - false, false, false, false, false, false, - ], - [ - true, true, true, true, false, false, - true, true, false, true, true, false, - true, true, true, true, false, false, - true, true, false, true, true, false, - true, true, false, false, true, false, - false, false, false, false, false, false, - ], - [ - true, true, true, true, true, false, - false, false, true, false, false, false, - false, false, true, false, false, false, - false, false, true, false, false, false, - false, false, true, false, false, false, - false, false, false, false, false, false, - ], - [ - true, true, true, true, true, false, - false, false, true, true, true, false, - false, true, true, true, false, false, - true, true, true, false, false, false, - true, true, true, true, true, false, - false, false, false, false, false, false, - ], - [ - false, true, true, true, false, false, - true, true, false, true, true, false, - true, true, false, true, true, false, - true, true, false, true, true, false, - false, true, true, true, false, false, - false, false, false, false, false, false, - ], - [ - false, true, true, false, false, false, - true, true, true, false, false, false, - false, false, true, false, false, false, - false, false, true, false, false, false, - true, true, true, true, true, false, - false, false, false, false, false, false, - ], - [ - false, true, true, true, false, false, - true, false, false, true, true, false, - false, false, true, true, false, false, - false, true, true, false, false, false, - true, true, true, true, true, false, - false, false, false, false, false, false, - ], - [ - true, true, true, true, true, false, - true, false, false, true, true, false, - false, false, true, true, false, false, - false, false, false, true, true, false, - true, true, true, true, false, false, - false, false, false, false, false, false, - ], - [ - false, true, false, true, true, false, - true, true, false, true, true, false, - true, true, true, true, true, false, - false, false, false, true, true, false, - false, false, false, true, true, false, - false, false, false, false, false, false, - ], - [ - true, true, true, true, true, false, - true, true, false, false, false, false, - true, true, true, true, true, false, - false, false, false, true, true, false, - true, true, true, true, false, false, - false, false, false, false, false, false, - ], - [ - false, true, true, true, true, false, - true, true, false, false, false, false, - true, true, true, true, true, false, - true, true, false, true, true, false, - false, true, true, true, true, false, - false, false, false, false, false, false, - ], - [ - true, true, true, true, true, false, - false, false, false, true, true, false, - false, false, true, true, false, false, - false, true, true, false, false, false, - true, true, false, false, false, false, - false, false, false, false, false, false, - ], - [ - false, true, true, true, false, false, - true, true, false, true, true, false, - false, true, true, true, false, false, - true, true, false, true, true, false, - false, true, true, true, false, false, - false, false, false, false, false, false, - ], - [ - false, true, true, true, true, false, - true, true, false, true, true, false, - true, true, true, true, true, false, - false, false, false, true, true, false, - true, true, true, true, false, false, - false, false, false, false, false, false, - ], - [ - false, false, false, false, false, false, - false, false, false, false, false, false, - true, true, true, true, true, false, - false, false, false, false, false, false, - false, false, false, false, false, false, - false, false, false, false, false, false, - ], - [ - false, false, true, false, false, false, - false, true, true, true, false, false, - true, true, false, true, true, false, - false, false, false, false, false, false, - false, false, false, false, false, false, - false, false, false, false, false, false, - ], - [ - false, false, false, false, false, false, - false, false, false, false, false, false, - false, false, false, false, false, false, - true, false, false, false, false, false, - true, false, false, false, false, false, - false, false, false, false, false, false, - ], - [ - true, false, false, false, false, false, - false, false, false, false, false, false, - false, false, false, false, false, false, - false, false, false, false, false, false, - true, false, false, false, false, false, - false, false, false, false, false, false, - ], - [ - true, true, false, false, false, false, - false, true, false, false, false, false, - true, true, false, false, false, false, - false, false, false, false, false, false, - true, false, false, false, false, false, - false, false, false, false, false, false, - ], -]; diff --git a/source/benoit/benoit/video/draw_translation_feedback.rs b/source/benoit/benoit/video/draw_translation_feedback.rs deleted file mode 100644 index 05ac70e..0000000 --- a/source/benoit/benoit/video/draw_translation_feedback.rs +++ /dev/null @@ -1,96 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::{PRECISION, width_height_ratio}; -use crate::benoit::complex::Complex; -use crate::benoit::video::Video; - -extern crate rug; -extern crate sdl2; - -use rug::Float; -use sdl2::pixels::Color; -use sdl2::rect::Rect; - -impl Video { - pub fn draw_translation_feedback(&mut self, canvas_width: u32, canvas_height: u32, scale: u32, prev_centre: &Complex, prev_zoom: &Float, next_centre: &Complex, next_zoom: &Float) { - let (width_ratio, height_ratio) = width_height_ratio(canvas_width, canvas_height); - - let canvas_width = Float::with_val(PRECISION, canvas_width * scale); - let canvas_height = Float::with_val(PRECISION, canvas_height * scale); - - let viewport = { - let (offset_x, offset_y, width, height) = { - let zoom_ratio = Float::with_val(PRECISION, next_zoom / prev_zoom); - - let mut width = Float::with_val(PRECISION, 1.0 / &zoom_ratio); - let mut height = Float::with_val(PRECISION, 1.0 / &zoom_ratio); - - // Remember that cartesian coordinates have an - // inverted vertical axis compared to those of - // SDL's coordinate system. - - let mut offset_x = next_centre.real.clone(); - let mut offset_y = Float::with_val(PRECISION, -&next_centre.imag); - - offset_x -= &prev_centre.real; - offset_y += &prev_centre.imag; - - offset_x /= 4.0; - offset_y /= 4.0; - - offset_x *= prev_zoom; - offset_y *= prev_zoom; - - offset_x /= width_ratio; - offset_y /= height_ratio; - - let mut zoom_offset = Float::with_val(PRECISION, 1.0 - &width); - zoom_offset /= 2.0; - - offset_x += &zoom_offset; - offset_y += &zoom_offset; - - offset_x *= &canvas_width; - offset_y *= &canvas_height; - width *= &canvas_width; - height *= &canvas_height; - - (offset_x.to_f32().round() as i32, offset_y.to_f32().round() as i32, width.to_f32().round() as u32, height.to_f32().round() as u32) - }; - - Rect::new( - offset_x, - offset_y, - width, - height, - ) - }; - - self.canvas.set_draw_color(Color::RGBA(0x0, 0x0, 0x0, 0x7F)); - self.canvas.fill_rect(viewport).unwrap(); - - self.canvas.set_draw_color(Color::RGB(0xFF, 0xFF, 0xFF)); - self.canvas.draw_rect(viewport).unwrap(); - } -} diff --git a/source/benoit/benoit/video/initialise.rs b/source/benoit/benoit/video/initialise.rs deleted file mode 100644 index f78ee7a..0000000 --- a/source/benoit/benoit/video/initialise.rs +++ /dev/null @@ -1,76 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::VERSION; -use crate::benoit::video::Video; - -extern crate sdl2; - -use sdl2::pixels::Color; -use sdl2::render::BlendMode; - -impl Video { - #[must_use] - pub fn initialise(canvas_width: u32, canvas_height: u32, scale: u32) -> Result<Video, String> { - let sdl = match sdl2::init() { - Ok( sdl) => sdl, - Err(_) => return Err("unable to initialise sdl2".to_string()), - }; - - let sdl_video = match sdl.video() { - Ok( video) => video, - Err(_) => return Err("unable to initialise video".to_string()), - }; - - let window_title = format!("BENO\u{CE}T {:X}.{:X}.{:X}", VERSION.0, VERSION.1, VERSION.2); - - let mut window_builder = sdl_video.window(window_title.as_str(), canvas_width * scale, canvas_height * scale); - window_builder.position_centered(); - - let window = match window_builder.build() { - Ok( window) => window, - Err(_) => return Err("unable to open window".to_string()), - }; - - let mut canvas = match window.into_canvas().build() { - Ok( canvas) => canvas, - Err(_) => return Err("unable to build canvas".to_string()), - }; - - canvas.set_blend_mode(BlendMode::Blend); - - // We only want to scale the render, not the - // feedback, so we can't use SDL's scaling feature. - - let clear_colour = Color::RGB(0x00, 0x00, 0x00); - canvas.set_draw_color(clear_colour); - canvas.clear(); - canvas.present(); - - return Ok(Video { - sdl: sdl, - sdl_video: sdl_video, - canvas: canvas, - }); - } -} diff --git a/source/benoit/benoit/video/sync.rs b/source/benoit/benoit/video/sync.rs deleted file mode 100644 index 46112eb..0000000 --- a/source/benoit/benoit/video/sync.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::video::Video; - -use std::thread::sleep; -use std::time::{Duration, Instant}; - -impl Video { - pub fn sync(&self, start_frame: &Instant) -> Result<(), String> { - let frame_duration = { - let index = match self.canvas.window().display_index() { - Ok( index) => index, - Err(_) => return Err("unable to get display index".to_string()), - }; - - let mode = match self.sdl_video.current_display_mode(index) { - Ok( mode) => mode, - Err(_) => return Err("unable to get display mode".to_string()), - }; - - Duration::from_secs(0x1) / mode.refresh_rate as u32 - }; - - let remaining = match frame_duration.checked_sub(start_frame.elapsed()) { - Some(value) => value, - None => Duration::from_secs(0x0), - }; - - sleep(remaining); - - return Ok(()); - } -}
\ No newline at end of file diff --git a/source/benoit/benoit/video/update.rs b/source/benoit/benoit/video/update.rs deleted file mode 100644 index eab330a..0000000 --- a/source/benoit/benoit/video/update.rs +++ /dev/null @@ -1,30 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -use crate::benoit::video::Video; - -impl Video { - pub fn update(&mut self) { - self.canvas.present(); - } -} diff --git a/source/benoit/main.rs b/source/benoit/main.rs deleted file mode 100644 index 1264873..0000000 --- a/source/benoit/main.rs +++ /dev/null @@ -1,42 +0,0 @@ -/* - Copyright 2021, 2023 Gabriel Bjørnager Jensen. - - This file is part of Benoit. - - Benoit is free software: you can redistribute it - and/or modify it under the terms of the GNU - Affero General Public License as published by - the Free Software Foundation, either version 3 - of the License, or (at your option) any later - version. - - Benoit is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without - even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU - Affero General Public License along with Benoit. - If not, see <https://www.gnu.org/licenses/>. -*/ - -mod benoit; - -use crate::benoit::launcher::Launcher; - -use std::process::exit; - -fn main() { - let launcher = Launcher::new(); - let result = launcher.run(); - - if let Err(ref error) = result { eprintln!("error: {error}") }; - - let code: i32 = match result { - Ok( _) => 0x0, - Err(_) => 0x1, - }; - - exit(code); -} |