Skip to content

Commit

Permalink
fix rgba8 image jpeg encode bug (#2169)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyan3060 committed Mar 23, 2024
1 parent fbd3f3e commit c193acb
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/codecs/jpeg/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -461,21 +461,11 @@ impl<W: Write> JpegEncoder<W> {
ImageBuffer::from_raw(width, height, image).unwrap();
self.encode_image(&image)
}
ExtendedColorType::La8 => {
let image: ImageBuffer<LumaA<_>, _> =
ImageBuffer::from_raw(width, height, image).unwrap();
self.encode_image(&image)
}
ExtendedColorType::Rgb8 => {
let image: ImageBuffer<Rgb<_>, _> =
ImageBuffer::from_raw(width, height, image).unwrap();
self.encode_image(&image)
}
ExtendedColorType::Rgba8 => {
let image: ImageBuffer<Rgba<_>, _> =
ImageBuffer::from_raw(width, height, image).unwrap();
self.encode_image(&image)
}
_ => Err(ImageError::Unsupported(
UnsupportedError::from_format_and_kind(
ImageFormat::Jpeg.into(),
Expand Down Expand Up @@ -577,7 +567,7 @@ impl<W: Write> JpegEncoder<W> {
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)
Expand Down

0 comments on commit c193acb

Please sign in to comment.