mirror of
https://github.com/xzeldon/rdr2_screenshot_converter.git
synced 2025-07-13 22:54:35 +03:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
b24d6a934c
|
|||
2507c010c0
|
|||
5c69f3ad5d
|
|||
cd04c5d78b |
1751
Cargo.lock
generated
1751
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@ Convert and save photomode screenshots from Red Dead Redemption 2 to JPEG format
|
||||

|
||||
|
||||
## QuickStart
|
||||
Just [download](https://github.com/xzeldon/rdr2_screenshot_converter/releases/download/1.0.0/rdr2_screenshot_converter.exe) the executable file from releases and run it. It will automatically find your screenshots and save them.
|
||||
Just [download](https://github.com/xzeldon/rdr2_screenshot_converter/releases) the executable file from releases and run it. It will automatically find your screenshots and save them.
|
||||
|
||||
## Arguments
|
||||
You can define a path for saving screenshots. To do this, open a command prompt, specify the path to the executable file and the path to save the screenshots.
|
||||
|
@ -12,14 +12,8 @@ version = "1.1.0"
|
||||
[dependencies]
|
||||
colored = "2.0.0"
|
||||
core = {path = "../core"}
|
||||
ctrlc = {version = "3.0", features = ["termination"]}
|
||||
dirs = "4.0.0"
|
||||
serde = {version = "1.0", features = ["derive"]}
|
||||
serde_json = "1.0"
|
||||
|
||||
[target.'cfg(target_os="windows")'.dependencies.winapi]
|
||||
features = ["consoleapi", "errhandlingapi", "fileapi", "handleapi", "processenv"]
|
||||
version = "0.3"
|
||||
|
||||
[build-dependencies]
|
||||
embed-resource = "1.6"
|
||||
|
@ -1,8 +1,13 @@
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "gui"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
cli = {path = "../cli"}
|
||||
core = {path = "../core"}
|
||||
eframe = "0.16.0"
|
||||
image = "0.23.14"
|
||||
rfd = "0.6.4"
|
||||
|
59
gui/src/lib.rs
Normal file
59
gui/src/lib.rs
Normal file
@ -0,0 +1,59 @@
|
||||
use eframe::egui::{Separator, Ui};
|
||||
use eframe::epi::Image;
|
||||
use eframe::{egui, epi};
|
||||
|
||||
const PADDING: f32 = 5.0;
|
||||
|
||||
pub fn render_header(ui: &mut Ui) {
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.heading("RDR2Converter");
|
||||
});
|
||||
ui.add_space(PADDING);
|
||||
let sep = Separator::default().spacing(20.);
|
||||
ui.add(sep);
|
||||
}
|
||||
|
||||
pub fn decode_image(buffer: &[u8]) -> Option<epi::Image> {
|
||||
use image::GenericImageView;
|
||||
let image = image::load_from_memory(buffer).ok()?;
|
||||
let image_buffer = image.to_rgba8();
|
||||
let size = [image.width() as usize, image.height() as usize];
|
||||
let pixels = image_buffer.into_vec();
|
||||
Some(epi::Image::from_rgba_unmultiplied(size, &pixels))
|
||||
}
|
||||
|
||||
pub fn render_image(
|
||||
ui: &mut egui::Ui,
|
||||
frame: &epi::Frame,
|
||||
tex_mngr: &mut TextureManager,
|
||||
image: Option<epi::Image>,
|
||||
) {
|
||||
egui::ScrollArea::vertical()
|
||||
.auto_shrink([false; 2])
|
||||
.show(ui, |ui| {
|
||||
if let Some(image) = image {
|
||||
if let Some(texture_id) = tex_mngr.texture(frame, &image) {
|
||||
let mut size = egui::Vec2::new(image.size[0] as f32, image.size[1] as f32);
|
||||
size *= (ui.available_width() / size.x).min(1.0);
|
||||
ui.image(texture_id, size);
|
||||
} else {
|
||||
ui.monospace("ERROR");
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TextureManager {
|
||||
texture_id: Option<egui::TextureId>,
|
||||
}
|
||||
|
||||
impl TextureManager {
|
||||
pub fn texture(&mut self, frame: &epi::Frame, image: &Image) -> Option<egui::TextureId> {
|
||||
if let Some(texture_id) = self.texture_id.take() {
|
||||
frame.free_texture(texture_id);
|
||||
}
|
||||
self.texture_id = Some(frame.alloc_texture(image.clone()));
|
||||
self.texture_id
|
||||
}
|
||||
}
|
@ -1,3 +1,49 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
use core::buffer;
|
||||
use eframe::{
|
||||
egui::{CentralPanel, Vec2},
|
||||
epi::App,
|
||||
run_native, NativeOptions,
|
||||
};
|
||||
use gui::TextureManager;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Default)]
|
||||
struct RDR2Converter {
|
||||
pub tex_mngr: TextureManager,
|
||||
picked_path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl App for RDR2Converter {
|
||||
fn update(&mut self, ctx: &eframe::egui::CtxRef, frame: &eframe::epi::Frame) {
|
||||
CentralPanel::default().show(ctx, |ui| {
|
||||
gui::render_header(ui);
|
||||
|
||||
if ui.button("Open file...").clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().pick_file() {
|
||||
self.picked_path = Some(path);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: use threads and channels
|
||||
if let Some(picked_path) = &self.picked_path {
|
||||
let buf = buffer::read_file(&picked_path).unwrap();
|
||||
let pic = buffer::parse_buf(&buf, b"JPEG", b"JSON", 12);
|
||||
let image = gui::decode_image(&pic);
|
||||
gui::render_image(ui, frame, &mut self.tex_mngr, image);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
"RDR2Converter"
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let app = RDR2Converter::default();
|
||||
let mut win_option = NativeOptions::default();
|
||||
win_option.initial_window_size = Some(Vec2::new(540., 960.));
|
||||
run_native(Box::new(app), win_option);
|
||||
}
|
||||
|
Reference in New Issue
Block a user