Skip to content

Commit

Permalink
photoshoot: improve editorPreview quality
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Dec 19, 2024
1 parent 2b4acca commit 71f685f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 10 additions & 1 deletion bin/src/commands/photoshoot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use hemtt_common::{
config::ProjectConfig,
};
use hemtt_config::{Class, Config, Property, Value};
use image::codecs::jpeg::JpegEncoder;

use crate::{
context::{Context, PreservePrevious},
Expand Down Expand Up @@ -261,7 +262,15 @@ impl Action for Photoshoot {
.to_string(),
target.display()
);
image.save(target).expect("save");
let target = std::fs::File::create(target).expect("create");
JpegEncoder::new_with_quality(target, 90)
.encode(
&image,
image.width(),
image.height(),
image::ExtendedColorType::Rgb8,
)
.expect("encode");
}
vec![self.next_message()]
}
Expand Down
5 changes: 3 additions & 2 deletions bin/src/utils/photoshoot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Photoshoot {
&new.to_image(),
512,
512,
image::imageops::FilterType::Nearest,
image::imageops::FilterType::Lanczos3,
);
for pixel in new.pixels_mut() {
if is_background(*pixel) {
Expand All @@ -40,7 +40,8 @@ impl Photoshoot {
/// [`Error::Image`] if the image could not be loaded
pub fn preview(path: &Path) -> Result<ImageBuffer<Rgb<u8>, Vec<u8>>, Error> {
let new = image::open(path)?.into_rgb8();
let mut new = image::imageops::resize(&new, 455, 256, image::imageops::FilterType::Nearest);
let mut new =
image::imageops::resize(&new, 455, 256, image::imageops::FilterType::Lanczos3);
for pixel in new.pixels_mut() {
Self::gamma_rgb(pixel);
}
Expand Down

0 comments on commit 71f685f

Please sign in to comment.