Fix encoding bug

This commit is contained in:
Harrison Burt 2022-03-30 13:41:13 +01:00
parent 3a0e0ca0b5
commit 3601d9d515
2 changed files with 2 additions and 12 deletions

View File

@ -26,12 +26,10 @@ impl Pipeline for AheadOfTimePipeline {
fn on_upload(&self, kind: ImageKind, data: Vec<u8>) -> anyhow::Result<PipelineResult> {
let resized = processor::resizer::resize_image_to_presets(&self.presets, kind, data.into())?;
let mut to_store = vec![];
for to_encode in resized {
let encoded_images = processor::encoder::encode_following_config(
self.formats,
kind,
to_encode.img,
to_encode.sizing_id
)?;

View File

@ -13,7 +13,6 @@ pub struct EncodedImage {
pub fn encode_following_config(
cfg: ImageFormats,
kind: ImageKind,
img: DynamicImage,
sizing_id: u32,
) -> anyhow::Result<Vec<EncodedImage>> {
@ -29,7 +28,7 @@ pub fn encode_following_config(
let (tx, rx) = crossbeam::channel::bounded(4);
for variant in ImageKind::variants() {
if cfg.is_enabled(*variant) && (kind != *variant) {
if cfg.is_enabled(*variant) {
let tx_local = tx.clone();
let local = original_image.clone();
rayon::spawn(move || {
@ -49,16 +48,10 @@ pub fn encode_following_config(
processed.push(encoded);
}
let mut finished = processed
let finished = processed
.into_iter()
.collect::<Result<Vec<EncodedImage>, _>>()?;
finished.push(EncodedImage {
kind,
sizing_id,
buff: Bytes::from(original_image.as_ref().as_bytes().to_vec()),
});
Ok(finished)
}
@ -90,7 +83,6 @@ pub fn encode_to(webp_cfg: webp::WebPConfig, img: &DynamicImage, format: ImageFo
return Ok(Bytes::from(encoded?.to_vec()))
}
let mut buff = Cursor::new(Vec::new());
img.write_to(&mut buff, format)?;
Ok(Bytes::from(buff.into_inner()))