Skip to content

Commit

Permalink
Merge pull request #272 from Enet4/imp/lossless-bitdepth
Browse files Browse the repository at this point in the history
Admit more precision values in JPEG Lossless
  • Loading branch information
fintelia authored Oct 29, 2023
2 parents 4d38958 + 1e5b891 commit fcdb5f0
Show file tree
Hide file tree
Showing 30 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion benches/decoding_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() {
}));

c.bench_function("decode a 3072x2048 RGB Lossless JPEG", |b| b.iter(|| {
read_image(include_bytes!("../tests/reftest/images/lossless/jpeg_lossless_sel1-rgb.jpg"))
read_image(include_bytes!("../tests/reftest/images/lossless/1/jpeg_lossless_sel1-rgb.jpg"))
}));
c.final_summary();
}
6 changes: 3 additions & 3 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ impl<R: Read> Decoder<R> {
Some(ref frame) => {
let pixel_format = match frame.components.len() {
1 => match frame.precision {
8 => PixelFormat::L8,
16 => PixelFormat::L16,
2..=8 => PixelFormat::L8,
9..=16 => PixelFormat::L16,
_ => panic!(),
},
3 => PixelFormat::RGB24,
Expand Down Expand Up @@ -360,7 +360,7 @@ impl<R: Read> Decoder<R> {
frame.precision,
)));
}
if frame.precision != 8 && frame.precision != 16 {
if !(2..=16).contains(&frame.precision) {
return Err(Error::Unsupported(UnsupportedFeature::SamplePrecision(
frame.precision,
)));
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/reftest/images/lossless/1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# JPEG Lossless data set 1

The files starting with jpeg_lossless were taken from <https://github.com/rii-mango/JPEGLosslessDecoderJS>.
The image data bytes were extracted from the DICOM files.
The reference PNG files were created with the IJG library as distributed in the GDCM toolkit <https://github.com/malaterre/GDCM/tree/master/Utilities/gdcmjpeg>.
Binary file added tests/reftest/images/lossless/2/MR4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/reftest/images/lossless/2/MR4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions tests/reftest/images/lossless/2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# JPEG Lossless data set 2

The JPEG losssless files in this data set
were collected from the DICOM-WG04 compilation of public DICOM files in
<ftp://medical.nema.org/medical/dicom/DataSets/WG04> (revision 2004/08/26),
extracting the JPEG data from the files' pixel data.

The ground truth was collected from the respective reference (uncompressed) files
and converted to 16-bit PNG files.

## Description

- **MR4**: 512x512, 12 bit precision, non-hierarchical, selection value 1
- JPEG extracted from DICOM file `JPLL/MR4_JPLL`
- Ground truth converted from DICOM file `REF/MR4_UNC`
- **XA1**: 1024x1024, 10 bit precision, non-hierarchical, selection value 1
- JPEG extracted from DICOM file `JPLL/XA1_JPLL`
- Ground truth converted from DICOM file `REF/XA1_UNC`
Binary file added tests/reftest/images/lossless/2/XA1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/reftest/images/lossless/2/XA1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions tests/reftest/images/lossless/README.md

This file was deleted.

0 comments on commit fcdb5f0

Please sign in to comment.