tmp
This commit is contained in:
parent
84099d4928
commit
c1ccad6229
41
src/main.rs
41
src/main.rs
@ -1,3 +1,4 @@
|
|||||||
|
use gtk::builders::ImageBuilder;
|
||||||
use gtk::gio::Cancellable;
|
use gtk::gio::Cancellable;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{Application, ApplicationWindow, Picture, Scale, Label, FileDialog};
|
use gtk::{Application, ApplicationWindow, Picture, Scale, Label, FileDialog};
|
||||||
@ -39,13 +40,13 @@ fn build_ui(app: &Application) {
|
|||||||
|
|
||||||
// Создание кнопки для открытия диалога выбора файла
|
// Создание кнопки для открытия диалога выбора файла
|
||||||
let button = Button::with_label("Select Image");
|
let button = Button::with_label("Select Image");
|
||||||
let picture = Picture::new();
|
// let picture = Picture::new();
|
||||||
picture.set_size_request(400, 400);
|
// picture.set_size_request(400, 400);
|
||||||
|
|
||||||
{
|
{
|
||||||
let window = window.clone();
|
let window = window.clone();
|
||||||
let selected_file = selected_file.clone();
|
let selected_file = selected_file.clone();
|
||||||
let picture = picture.clone();
|
// let picture = picture.clone();
|
||||||
button.connect_clicked(move |_| {
|
button.connect_clicked(move |_| {
|
||||||
// Создание FileDialog
|
// Создание FileDialog
|
||||||
let dialog = FileDialog::builder()
|
let dialog = FileDialog::builder()
|
||||||
@ -62,7 +63,7 @@ fn build_ui(app: &Application) {
|
|||||||
// Показ диалога и обработка результата
|
// Показ диалога и обработка результата
|
||||||
let window = window.clone();
|
let window = window.clone();
|
||||||
let selected_file = selected_file.clone();
|
let selected_file = selected_file.clone();
|
||||||
let picture = picture.clone();
|
// let picture = picture.clone();
|
||||||
dialog.open(Some(&window), None::<>k::gio::Cancellable>, move |result| {
|
dialog.open(Some(&window), None::<>k::gio::Cancellable>, move |result| {
|
||||||
if let Ok(file) = result {
|
if let Ok(file) = result {
|
||||||
// Получение выбранного файла
|
// Получение выбранного файла
|
||||||
@ -74,7 +75,7 @@ fn build_ui(app: &Application) {
|
|||||||
println!("Image loaded successfully: {}x{}", pixbuf.width(), pixbuf.height());
|
println!("Image loaded successfully: {}x{}", pixbuf.width(), pixbuf.height());
|
||||||
let _ = fs::copy(&path, "/tmp/modified.png");
|
let _ = fs::copy(&path, "/tmp/modified.png");
|
||||||
*selected_file.borrow_mut() = Some(file.clone());
|
*selected_file.borrow_mut() = Some(file.clone());
|
||||||
picture.set_pixbuf(Some(&pixbuf));
|
// picture.set_pixbuf(Some(&pixbuf));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
eprintln!("Failed to load image.");
|
eprintln!("Failed to load image.");
|
||||||
@ -90,11 +91,17 @@ fn build_ui(app: &Application) {
|
|||||||
button.set_visible(false);
|
button.set_visible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
let br_slider = Scale::with_range(Orientation::Horizontal, -128., 128., 1.);
|
let picture = Picture::for_filename("/tmp/modified.png");
|
||||||
|
let image = image::open("/tmp/modified.png")
|
||||||
|
.map(|img| img.to_rgb8())
|
||||||
|
.map_err(|e| eprintln!("Failed to load image: {}", e))
|
||||||
|
.ok().unwrap();
|
||||||
|
|
||||||
|
let br_slider = Scale::with_range(Orientation::Horizontal, -128., 128., 10.);
|
||||||
br_slider.set_value(0.);
|
br_slider.set_value(0.);
|
||||||
br_slider.set_hexpand(true);
|
br_slider.set_hexpand(true);
|
||||||
|
|
||||||
let br_text = Label::new(Some("Brightness: 0.00"));
|
let br_text = Label::new(Some("Brightness: +000"));
|
||||||
|
|
||||||
let br_container = GtkBox::new(Orientation::Horizontal, 5);
|
let br_container = GtkBox::new(Orientation::Horizontal, 5);
|
||||||
br_container.append(&br_text);
|
br_container.append(&br_text);
|
||||||
@ -102,8 +109,11 @@ fn build_ui(app: &Application) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
br_slider.clone().connect_change_value(move |_, _, _| {
|
br_slider.clone().connect_change_value(move |_, _, _| {
|
||||||
let value = br_slider.value();
|
let mut value = br_slider.value();
|
||||||
br_text.set_text(&format!("Brightness: {:.2}", value));
|
value = value.round();
|
||||||
|
br_slider.set_value(value);
|
||||||
|
br_text.set_text(&format!("Brightness: {:+04.0}", value));
|
||||||
|
edit_image(&mut image, value as i8);
|
||||||
|
|
||||||
// Продолжаем обработку события
|
// Продолжаем обработку события
|
||||||
Propagation::Proceed
|
Propagation::Proceed
|
||||||
@ -154,14 +164,11 @@ fn build_ui(app: &Application) {
|
|||||||
window.show();
|
window.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn edit_image(img: &mut RgbImage) {
|
fn edit_image(img: &mut RgbImage, brightness: i8) {
|
||||||
// for (x, y, pixel) in img.enumerate_pixels_mut() {
|
for (x, y, pixel) in img.enumerate_pixels_mut() {
|
||||||
// // Пример: инвертируем цвета
|
pixel[0] = (pixel[0] as i16 + brightness as i16) as u8;
|
||||||
// pixel[0] = 255 - pixel[0]; // Красный
|
}
|
||||||
// pixel[1] = 255 - pixel[1]; // Зеленый
|
}
|
||||||
// pixel[2] = 255 - pixel[2]; // Синий
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn update_image(picture: &Picture, img: &DynamicImage) {
|
// fn update_image(picture: &Picture, img: &DynamicImage) {
|
||||||
// img.save("tmp.png").unwrap();
|
// img.save("tmp.png").unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user