Skip to content

Commit

Permalink
jpeg: Fix corruption with going from rgb to grayscale for progressive…
Browse files Browse the repository at this point in the history
… images

Signed-off-by: caleb <[email protected]>
  • Loading branch information
etemesi254 committed Oct 4, 2023
1 parent eed3523 commit 62969db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions zune-jpeg/src/mcu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ impl<T: ZReaderTrait> JpegDecoder<T> {
if self.is_interleaved
&& self.input_colorspace.num_components() > 1
&& self.options.jpeg_get_out_colorspace().num_components() == 1
&& (self.sub_sample_ratio == SampleRatios::V
|| self.sub_sample_ratio == SampleRatios::HV)
{
// For a specific set of images, e.g interleaved,
// when converting from YcbCr to grayscale, we need to
Expand All @@ -117,6 +119,7 @@ impl<T: ZReaderTrait> JpegDecoder<T> {
//
// set coeff to be 2 to ensure that we increment two rows
// for every mcu processed also
mcu_height *= self.v_max;
mcu_height /= self.h_max;
self.coeff = 2;
}
Expand Down
20 changes: 19 additions & 1 deletion zune-jpeg/src/mcu_prog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<T: ZReaderTrait> JpegDecoder<T> {
) -> Result<(), DecodeErrors> {
setup_component_params(self)?;

let mcu_height;
let mut mcu_height;

// memory location for decoded pixels for components
let mut block: [Vec<i16>; MAX_COMPONENTS] = [vec![], vec![], vec![], vec![]];
Expand All @@ -77,6 +77,24 @@ impl<T: ZReaderTrait> JpegDecoder<T> {
mcu_width = (self.info.width as usize + 7) / 8;
mcu_height = (self.info.height as usize + 7) / 8;
}
if self.is_interleaved
&& self.input_colorspace.num_components() > 1
&& self.options.jpeg_get_out_colorspace().num_components() == 1
&& (self.sub_sample_ratio == SampleRatios::V
|| self.sub_sample_ratio == SampleRatios::HV)
{
// For a specific set of images, e.g interleaved,
// when converting from YcbCr to grayscale, we need to
// take into account mcu height since the MCU decoding needs to take
// it into account for padding purposes and the post processor
// parses two rows per mcu width.
//
// set coeff to be 2 to ensure that we increment two rows
// for every mcu processed also
mcu_height *= self.v_max;
mcu_height /= self.h_max;
self.coeff = 2;
}

mcu_width *= 64;

Expand Down

0 comments on commit 62969db

Please sign in to comment.