Skip to content

Commit d3232f9

Browse files
Updated photometric interpretation handling in encoder
1 parent 41e3cb2 commit d3232f9

5 files changed

Lines changed: 36 additions & 12 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ project(
88

99
set(DCMTKHTJ2K_VERSION_MAJOR 1)
1010
set(DCMTKHTJ2K_VERSION_MINOR 0)
11-
set(DCMTKHTJ2K_VERSION_BUILD 3)
11+
set(DCMTKHTJ2K_VERSION_BUILD 4)
1212
set(DCMTKHTJ2K_VERSION
1313
"${DCMTKHTJ2K_VERSION_MAJOR}.${DCMTKHTJ2K_VERSION_MINOR}.${DCMTKHTJ2K_VERSION_BUILD}"
1414
)

include/dcmtkhtj2k/djcodecd.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class DCMTKHTJ2K_EXPORT HtJ2kDecoderBase : public DcmCodec {
268268
* frame in the compressed pixel sequence. This method uses various
269269
* approaches to compute the number of fragments for a frame, including a
270270
* check of the offset table and checking the start of each fragment for JPEG
271-
* SOI markers.
271+
* SOC markers.
272272
* @param numberOfFrames total number of frames of the DICOM object
273273
* @param currentFrame index of current frame (0..numberOfFrames-1)
274274
* @param startItem index of fragment (pixel item) the frame starts with
@@ -285,8 +285,8 @@ class DCMTKHTJ2K_EXPORT HtJ2kDecoderBase : public DcmCodec {
285285
/** check whether the given buffer contains a HT-J2K start-of-image code
286286
* @param fragmentData pointer to 4 or more bytes of HT-J2K data
287287
* @returns true if the first four bytes of the code stream indicate that
288-
* this fragment is the start of a new HT-J2K image, i.e. starts with
289-
* an SOI marker followed by SOF, COM or APPn.
288+
* this fragment is the start of a new HT-J2K image,
289+
* i.e. codestream starts with SOC (FF4F), followed by SIZ (FF51).
290290
*/
291291
static OFBool isJ2KStartOfImage(Uint8 *fragmentData);
292292

libsrc/djcodece.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,13 @@ OFCondition HtJ2kEncoderBase::losslessRawEncode(
529529

530530
if (compressedSize > 0) compressionRatio = uncompressedSize / compressedSize;
531531

532+
// update photometric interpretation for color images
533+
if (result.good() && samplesPerPixel > 1) {
534+
result = dataset->putAndInsertString(
535+
DCM_PhotometricInterpretation,
536+
djrp->useLosslessProcess() ? "YBR_RCT" : "YBR_ICT");
537+
}
538+
532539
// byte swap pixel data back to local endian if necessary
533540
if (byteSwapped) {
534541
swapIfNecessary(gLocalByteOrder, EBO_LittleEndian,
@@ -708,6 +715,10 @@ OFCondition HtJ2kEncoderBase::RenderedEncode(
708715
dataset->findAndGetUint16(DCM_PixelRepresentation, pixelRepresentation);
709716
if (result.bad()) return result;
710717

718+
Uint16 samplesPerPixel = 0;
719+
result = dataset->findAndGetUint16(DCM_SamplesPerPixel, samplesPerPixel);
720+
if (result.bad()) return result;
721+
711722
DcmPixelSequence *pixelSequence = NULL;
712723
DcmPixelItem *offsetTable = NULL;
713724

@@ -762,9 +773,6 @@ OFCondition HtJ2kEncoderBase::RenderedEncode(
762773
unsigned long frameCount = dimage->getFrameCount();
763774

764775
// compute original image size in bytes, ignoring any padding bits.
765-
Uint16 samplesPerPixel = 0;
766-
if ((dataset->findAndGetUint16(DCM_SamplesPerPixel, samplesPerPixel)).bad())
767-
samplesPerPixel = 1;
768776
uncompressedSize = dimage->getWidth() * dimage->getHeight() *
769777
bitsPerSample * frameCount * samplesPerPixel / 8.0;
770778

@@ -804,6 +812,12 @@ OFCondition HtJ2kEncoderBase::RenderedEncode(
804812
result = dataset->putAndInsertUint16(DCM_BitsStored, bitsPerSample);
805813
if (result.good())
806814
result = dataset->putAndInsertUint16(DCM_HighBit, bitsPerSample - 1);
815+
// update photometric interpretation for color images
816+
if (result.good() && samplesPerPixel > 1) {
817+
result = dataset->putAndInsertString(
818+
DCM_PhotometricInterpretation,
819+
djrp->useLosslessProcess() ? "YBR_RCT" : "YBR_ICT");
820+
}
807821
}
808822

809823
if (compressedSize > 0) compressionRatio = uncompressedSize / compressedSize;

libsrc/djcparam.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ HtJ2kCodecParameter::HtJ2kCodecParameter(
2929
HTJ2K_PlanarConfiguration planarConfiguration, OFBool ignoreOffsetTble)
3030
: DcmCodecParameter(),
3131
jp2k_optionsEnabled_(OFFalse),
32-
jp2k_cblkwidth_(0),
33-
jp2k_cblkheight_(1),
32+
jp2k_decompositions_(5),
33+
jp2k_cblkwidth_(64),
34+
jp2k_cblkheight_(64),
35+
jp2k_progressionOrder_(EHTJ2KPO_default),
3436
fragmentSize_(0),
3537
createOffsetTable_(OFTrue),
3638
preferCookedEncoding_(OFTrue),
@@ -40,12 +42,12 @@ HtJ2kCodecParameter::HtJ2kCodecParameter(
4042
ignoreOffsetTable_(ignoreOffsetTble) {}
4143

4244
HtJ2kCodecParameter::HtJ2kCodecParameter(HtJ2kCodecParameter const &arg)
43-
: DcmCodecParameter(arg)
44-
45-
,
45+
: DcmCodecParameter(arg),
4646
jp2k_optionsEnabled_(arg.jp2k_optionsEnabled_),
47+
jp2k_decompositions_(arg.jp2k_decompositions_),
4748
jp2k_cblkwidth_(arg.jp2k_cblkwidth_),
4849
jp2k_cblkheight_(arg.jp2k_cblkheight_),
50+
jp2k_progressionOrder_(arg.jp2k_progressionOrder_),
4951
fragmentSize_(arg.fragmentSize_),
5052
createOffsetTable_(arg.createOffsetTable_),
5153
preferCookedEncoding_(arg.preferCookedEncoding_),

tests/test.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,14 @@ TEST(CodecTest, BasicColorCompressDecompressLossless) {
399399
.good());
400400
ASSERT_TRUE(readDataset->canWriteXfer(EXS_LittleEndianExplicit));
401401

402+
// Verify photometric interpretation is updated to YBR_RCT
403+
OFString photometricInterpretation;
404+
ASSERT_TRUE(readDataset
405+
->findAndGetOFString(DCM_PhotometricInterpretation,
406+
photometricInterpretation)
407+
.good());
408+
ASSERT_EQ(photometricInterpretation, "YBR_RCT");
409+
402410
Uint8 const *decoded = nullptr;
403411
unsigned long decodedCount = 0;
404412
ASSERT_TRUE(

0 commit comments

Comments
 (0)