Skip to content

Commit

Permalink
[ts-registry] tweak JPEG-LS encoding logic for palette color images
Browse files Browse the repository at this point in the history
- retain photometric interpretation in that case
  and force lossless encoding
  • Loading branch information
Enet4 committed Oct 23, 2024
1 parent 69e3994 commit fd44db9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions transfer-syntax-registry/src/adapters/jpegls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@ impl PixelDataWriter for JpegLsAdapter {
};

// prefer lossless encoding by default
let quality = options.quality.map(|q| q.clamp(0, 100)).unwrap_or(100);
let mut quality = options.quality.map(|q| q.clamp(0, 100)).unwrap_or(100);

let pmi = src.photometric_interpretation();

if pmi == Some("PALETTE COLOR") {
// force lossless encoding of palette color samples
quality = 100;
}

// calculate the maximum acceptable error range
// based on the requested quality and bit depth
Expand Down Expand Up @@ -201,12 +208,10 @@ impl PixelDataWriter for JpegLsAdapter {
]
};

let pmi = src.photometric_interpretation();

if samples_per_pixel == 1 {
// set Photometric Interpretation to Monochrome2
// if it was neither of the expected monochromes
if pmi != Some("MONOCHROME1") && pmi != Some("MONOCHROME2") {
// set Photometric Interpretation to MONOCHROME2
// if it was neither of the expected 1-channel formats
if pmi != Some("MONOCHROME1") && pmi != Some("MONOCHROME2") && pmi != Some("PALETTE COLOR") {
changes.push(AttributeOp::new(
Tag(0x0028, 0x0004),
AttributeAction::SetStr("MONOCHROME2".into()),
Expand Down

0 comments on commit fd44db9

Please sign in to comment.