From c193acbf7b745b071f5617e269f0955ee97c25d3 Mon Sep 17 00:00:00 2001 From: yuanyan3060 <58114805+yuanyan3060@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:31:17 +0800 Subject: [PATCH] fix rgba8 image jpeg encode bug (#2169) --- src/codecs/jpeg/encoder.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/codecs/jpeg/encoder.rs b/src/codecs/jpeg/encoder.rs index ebf2532524..52390220a7 100644 --- a/src/codecs/jpeg/encoder.rs +++ b/src/codecs/jpeg/encoder.rs @@ -9,7 +9,7 @@ use crate::error::{ }; use crate::image::{ImageEncoder, ImageFormat}; use crate::utils::clamp; -use crate::{ExtendedColorType, GenericImageView, ImageBuffer, Luma, LumaA, Pixel, Rgb, Rgba}; +use crate::{ExtendedColorType, GenericImageView, ImageBuffer, Luma, Pixel, Rgb}; use super::entropy::build_huff_lut_const; use super::transform; @@ -461,21 +461,11 @@ impl JpegEncoder { ImageBuffer::from_raw(width, height, image).unwrap(); self.encode_image(&image) } - ExtendedColorType::La8 => { - let image: ImageBuffer, _> = - ImageBuffer::from_raw(width, height, image).unwrap(); - self.encode_image(&image) - } ExtendedColorType::Rgb8 => { let image: ImageBuffer, _> = ImageBuffer::from_raw(width, height, image).unwrap(); self.encode_image(&image) } - ExtendedColorType::Rgba8 => { - let image: ImageBuffer, _> = - ImageBuffer::from_raw(width, height, image).unwrap(); - self.encode_image(&image) - } _ => Err(ImageError::Unsupported( UnsupportedError::from_format_and_kind( ImageFormat::Jpeg.into(), @@ -577,7 +567,7 @@ impl JpegEncoder { build_scan_header(&mut buf, &self.components[..num_components]); self.writer.write_segment(SOS, &buf)?; - if let ExtendedColorType::Rgb8 = color_type { + if ExtendedColorType::Rgb8 == color_type || ExtendedColorType::Rgba8 == color_type { self.encode_rgb(image) } else { self.encode_gray(image)