@@ -530,7 +530,7 @@ OFCondition HtJ2kEncoderBase::losslessRawEncode(
530530 if (compressedSize > 0 ) compressionRatio = uncompressedSize / compressedSize;
531531
532532 // update photometric interpretation for color images
533- if (result.good () && samplesPerPixel > 1 ) {
533+ if (result.good () && photometricInterpretation == " RGB " ) {
534534 result = dataset->putAndInsertString (
535535 DCM_PhotometricInterpretation,
536536 djrp->useLosslessProcess () ? " YBR_RCT" : " YBR_ICT" );
@@ -562,7 +562,8 @@ OFCondition HtJ2kEncoderBase::compressRawFrame(
562562 ojph::codestream codestream;
563563 ojph::mem_outfile destinationBuffer;
564564
565- bool colorTransform = (samplesPerPixel > 1 );
565+ // Apply color transform only for RGB input
566+ bool colorTransform = (photometricInterpretation == " RGB" );
566567 codestream.set_planar (colorTransform == false );
567568 codestream.set_tilepart_divisions (true , false );
568569 codestream.request_tlm_marker (true );
@@ -813,7 +814,7 @@ OFCondition HtJ2kEncoderBase::RenderedEncode(
813814 if (result.good ())
814815 result = dataset->putAndInsertUint16 (DCM_HighBit, bitsPerSample - 1 );
815816 // update photometric interpretation for color images
816- if (result.good () && samplesPerPixel > 1 ) {
817+ if (result.good () && photometricInterpretation == " RGB " ) {
817818 result = dataset->putAndInsertString (
818819 DCM_PhotometricInterpretation,
819820 djrp->useLosslessProcess () ? " YBR_RCT" : " YBR_ICT" );
@@ -980,7 +981,8 @@ OFCondition HtJ2kEncoderBase::compressRenderedFrame(
980981 ojph::codestream codestream;
981982 ojph::mem_outfile destinationBuffer;
982983
983- bool colorTransform = (samplesPerPixel > 1 );
984+ // Apply color transform only for RGB input
985+ bool colorTransform = (photometricInterpretation == " RGB" );
984986 codestream.set_planar (colorTransform == false );
985987 codestream.set_tilepart_divisions (true , false );
986988 codestream.request_tlm_marker (true );
0 commit comments