aboutsummaryrefslogtreecommitdiff
path: root/transcoder/src/image.rs
diff options
context:
space:
mode:
Diffstat (limited to 'transcoder/src/image.rs')
-rw-r--r--transcoder/src/image.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/transcoder/src/image.rs b/transcoder/src/image.rs
index 6943b2b..49f99bd 100644
--- a/transcoder/src/image.rs
+++ b/transcoder/src/image.rs
@@ -5,14 +5,17 @@
*/
use anyhow::{anyhow, Context, Result};
use image::imageops::FilterType;
-use jellycache::{cache, cache_read, CacheKey};
+use jellycache::{cache, cache_read, HashKey};
use log::{debug, info};
use rgb::FromSlice;
use std::io::Cursor;
-pub fn transcode(key: CacheKey, quality: f32, speed: u8, width: usize) -> Result<Vec<u8>> {
+pub fn transcode(key: &str, quality: u32, speed: u8, width: usize) -> Result<Vec<u8>> {
cache(
- CacheKey::new_image(("image-tc", key, width, quality as i32, speed)),
+ &format!(
+ "transcode/image/{}-W{width}-Q{quality}-S{speed}",
+ HashKey(key)
+ ),
move || {
let input = cache_read(key)?.ok_or(anyhow!("transcode cache key missing"))?;
info!("encoding image (speed={speed}, quality={quality}, width={width})");
@@ -53,7 +56,7 @@ pub fn transcode(key: CacheKey, quality: f32, speed: u8, width: usize) -> Result
let pixels = image.to_vec();
let encoded = ravif::Encoder::new()
.with_speed(speed.clamp(1, 10))
- .with_quality(quality.clamp(1., 100.))
+ .with_quality(quality.clamp(1, 100) as f32)
.encode_rgba(imgref::Img::new(
pixels.as_rgba(),
image.width() as usize,