Compare commits
No commits in common. "b6b1b8eeed07a204a2f6282e97374cc263a6700c" and "f481105fd9dc6e3f66259c37dd69553dce715f95" have entirely different histories.
b6b1b8eeed
...
f481105fd9
11 changed files with 744 additions and 753 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "ext/htmlfilemerger"]
|
||||||
|
path = ext/htmlfilemerger
|
||||||
|
url = https://github.com/DarkTrick/htmlfilemerger.git
|
1284
Cargo.lock
generated
1284
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -8,7 +8,7 @@ anyhow = "1.0"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
simplelog = "0.12"
|
simplelog = "0.12"
|
||||||
wry = "0.34"
|
wry = "0.34"
|
||||||
native-dialog = "0.6"
|
native-dialog = "0.7"
|
||||||
rust-embed = "8"
|
rust-embed = "8"
|
||||||
directories = "5"
|
directories = "5"
|
||||||
clap = "4"
|
clap = "4"
|
||||||
|
|
File diff suppressed because one or more lines are too long
1
ext/htmlfilemerger
Submodule
1
ext/htmlfilemerger
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit cf3a34373ff48519d699e08f8a0abf7c83e432c2
|
63
html/index.html
Normal file
63
html/index.html
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Panorama viewer</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="../css/photo-sphere-viewer.min.css">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
html, body {
|
||||||
|
width: 100%; height: 100%; overflow: hidden; margin: 0; padding:
|
||||||
|
0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#photosphere {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.psv-button.custom-button {
|
||||||
|
font-size: 22px;
|
||||||
|
line-height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.demo-label {
|
||||||
|
color: white;
|
||||||
|
font-size: 20px;
|
||||||
|
font-family: Helvetica, sans-serif;
|
||||||
|
text-align: center;
|
||||||
|
padding: 5px;
|
||||||
|
border: 1px solid white;
|
||||||
|
background: rgba(0,0,0,0.4);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="photosphere"></div>
|
||||||
|
|
||||||
|
<script src="../js/three.min.js"></script>
|
||||||
|
<script src="../js/browser.min.js"></script>
|
||||||
|
<script src="../js/photo-sphere-viewer.min.js"></script>
|
||||||
|
|
||||||
|
<h1>Panorama</h1>>
|
||||||
|
<script>
|
||||||
|
var PSV = new PhotoSphereViewer.Viewer({
|
||||||
|
container: 'photosphere',
|
||||||
|
panorama: 'img',
|
||||||
|
caption: 'Panorama displayed with Photo Sphere Viewer V4.7.1',
|
||||||
|
defaultZoomLvl: 40,
|
||||||
|
minFov: 5,
|
||||||
|
maxFov: 75,
|
||||||
|
navbar: [
|
||||||
|
'autorotate',
|
||||||
|
'zoom',
|
||||||
|
'caption'
|
||||||
|
]
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
0
embed/js/browser.min.js → js/browser.min.js
vendored
0
embed/js/browser.min.js → js/browser.min.js
vendored
0
embed/js/three.min.js → js/three.min.js
vendored
0
embed/js/three.min.js → js/three.min.js
vendored
51
src/main.rs
51
src/main.rs
|
@ -1,6 +1,6 @@
|
||||||
#![windows_subsystem = "windows"]
|
#![windows_subsystem = "windows"]
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use clap::{Arg, Command};
|
use clap::{Arg, Command};
|
||||||
use fast_image_resize as fr;
|
use fast_image_resize as fr;
|
||||||
use image::{io::Reader as ImageReader, DynamicImage};
|
use image::{io::Reader as ImageReader, DynamicImage};
|
||||||
|
@ -68,33 +68,22 @@ fn main() -> Result<()> {
|
||||||
.ok_or_else(|| anyhow!("No file"))?
|
.ok_or_else(|| anyhow!("No file"))?
|
||||||
};
|
};
|
||||||
|
|
||||||
if !img_path.exists() {
|
|
||||||
MessageDialog::new()
|
|
||||||
.set_title("Image error")
|
|
||||||
.set_text(&format!("Image `{}` does not exist", img_path.display()))
|
|
||||||
.set_type(native_dialog::MessageType::Error)
|
|
||||||
.show_alert()?;
|
|
||||||
bail!("File `{}` does not exist !", img_path.display());
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("Open `{}`", img_path.display());
|
info!("Open `{}`", img_path.display());
|
||||||
let (width, height) = image::image_dimensions(&img_path)?;
|
let (width, height) = image::image_dimensions(&img_path)?;
|
||||||
const MAX_IMG_SIZE: u32 = 20_000_000;
|
const MAX_IMG_SIZE: u32 = 20_000_000;
|
||||||
info!("Image size {} * {}", width, height);
|
|
||||||
let img_data_path = if height * width > MAX_IMG_SIZE {
|
let img_data_path = if height * width > MAX_IMG_SIZE {
|
||||||
|
// @todo utilisation de rfd au lieu de message_dialog
|
||||||
// @todo Option pas de resize / taille en ligne de commande
|
// @todo Option pas de resize / taille en ligne de commande
|
||||||
// @todo Option pas de resize / taille dans une config (confy)
|
// @todo Option pas de resize / taille dans une config (confy)
|
||||||
// @todo Demande ensergistre l’action la première fois
|
// @todo Demande ensergistre l’action la première fois
|
||||||
// @todo Option always en ligne de commnade
|
// @todo Option always en ligne de commnade
|
||||||
// @todo Icon
|
// @todo Icon
|
||||||
// @todo no dialog with v0.7
|
|
||||||
let ratio = (height * width) as f64 / MAX_IMG_SIZE as f64;
|
let ratio = (height * width) as f64 / MAX_IMG_SIZE as f64;
|
||||||
let new_height = (height as f64 / ratio.sqrt()) as u32;
|
let new_height = (height as f64 / ratio.sqrt()) as u32;
|
||||||
let new_width = (width as f64 / ratio.sqrt()) as u32;
|
let new_width = (width as f64 / ratio.sqrt()) as u32;
|
||||||
|
|
||||||
if MessageDialog::new()
|
if MessageDialog::new()
|
||||||
.set_title("Resize")
|
.set_title("Resize")
|
||||||
.set_type(native_dialog::MessageType::Info)
|
|
||||||
.set_text(&format!(
|
.set_text(&format!(
|
||||||
"Resize the file to {} × {}",
|
"Resize the file to {} × {}",
|
||||||
new_width, new_height
|
new_width, new_height
|
||||||
|
@ -122,8 +111,9 @@ fn main() -> Result<()> {
|
||||||
img_path
|
img_path
|
||||||
};
|
};
|
||||||
|
|
||||||
info!("Run server");
|
info!("Generate HTML");
|
||||||
run_server(img_data_path);
|
let html = std::str::from_utf8(Embed::get("index.html").unwrap().data.as_ref())?.to_string();
|
||||||
|
run_server(html, img_data_path);
|
||||||
|
|
||||||
info!("Create webview");
|
info!("Create webview");
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
@ -153,7 +143,7 @@ fn main() -> Result<()> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_server(img_path: PathBuf) -> JoinHandle<()> {
|
fn run_server(html: String, img_path: PathBuf) -> JoinHandle<()> {
|
||||||
std::thread::spawn(|| {
|
std::thread::spawn(|| {
|
||||||
info!("Create runtime");
|
info!("Create runtime");
|
||||||
let async_runtime = tokio::runtime::Builder::new_current_thread()
|
let async_runtime = tokio::runtime::Builder::new_current_thread()
|
||||||
|
@ -161,38 +151,13 @@ fn run_server(img_path: PathBuf) -> JoinHandle<()> {
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
info!("Create response");
|
info!("Create response");
|
||||||
let index = warp::path("index.html").map(|| {
|
let hello = warp::path!("index.html").map(move || warp::reply::html(html.clone()));
|
||||||
info!("Request `index.html`");
|
|
||||||
let datas = get_file_data("index.html");
|
|
||||||
warp::reply::html(datas)
|
|
||||||
});
|
|
||||||
let css = warp::path!("css" / String).map(move |val: String| {
|
|
||||||
info!("Request css `{}`", &val);
|
|
||||||
let datas = get_file_data(&format!("css/{}", val));
|
|
||||||
warp::http::Response::builder().body(datas)
|
|
||||||
});
|
|
||||||
let js = warp::path!("js" / String).map(move |val: String| {
|
|
||||||
info!("Request js `{}`", &val);
|
|
||||||
let datas = get_file_data(&format!("js/{}", val));
|
|
||||||
warp::http::Response::builder().body(datas)
|
|
||||||
});
|
|
||||||
let img = warp::path!("img").map(move || std::fs::read(&img_path).unwrap());
|
let img = warp::path!("img").map(move || std::fs::read(&img_path).unwrap());
|
||||||
info!("Launch webserver");
|
info!("Launch webserver");
|
||||||
async_runtime
|
async_runtime.block_on(warp::serve(hello.or(img)).run(([127, 0, 0, 1], 62371)));
|
||||||
.block_on(warp::serve(img.or(index).or(css).or(js)).run(([127, 0, 0, 1], 62371)));
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_file_data(filename: &str) -> String {
|
|
||||||
if let Some(file) = Embed::get(filename) {
|
|
||||||
std::str::from_utf8(file.data.as_ref())
|
|
||||||
.unwrap_or("")
|
|
||||||
.to_string()
|
|
||||||
} else {
|
|
||||||
"".to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fast resize
|
/// Fast resize
|
||||||
pub fn fast_image_resize(
|
pub fn fast_image_resize(
|
||||||
img: &DynamicImage,
|
img: &DynamicImage,
|
||||||
|
|
Loading…
Reference in a new issue