Bug #1160
closeddcmcjpls generates an invalid JPEG-LS bitstream with signed pixel data in cooked mode
100%
Description
The dcmcjpls generates an invalid JPEG-LS bitstream when compressing images that contain signed pixel data (i.e. PhotometricInterpretation=1) when the tool operates in the "cooked mode" (command line option --prefer-cooked), which is not the default, and the number of bits per sample (i.e. BitsStored) is not 8 or 16.
The issue is likely caused by the way DCMTK passes negative numbers to the JPEG-LS encoder: DCMTK extends the sign bit to the full 8-bit or 16-bit structure (i.e. represents a 13-bit number with the value -1 as 0xFFFF), whereas the CharLS library apparently requires the unused bits to be zeroed, i.e. a 13-bit number with value -1 to be passed as 0x1FFF.
Reported 2025-06-12 by Mathieu Malaterre <mathieu.malaterre@gmail.com>