@@ -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;
0 commit comments