in src/Microsoft.Health.Dicom.Core/Features/Retrieve/DicomDatasetExtensions.cs [37:121]
public static bool CanTranscodeDataset(this DicomDataset ds, DicomTransferSyntax toTransferSyntax)
{
EnsureArg.IsNotNull(ds, nameof(ds));
if (toTransferSyntax == null)
{
return true;
}
var fromTs = ds.InternalTransferSyntax;
if (!ds.TryGetSingleValue(DicomTag.BitsAllocated, out ushort bpp))
{
return false;
}
if (!ds.TryGetString(DicomTag.PhotometricInterpretation, out string photometricInterpretation))
{
return false;
}
if ((fromTs == DicomTransferSyntax.JPEG2000Lossless || fromTs == DicomTransferSyntax.JPEG2000Lossy) &&
(toTransferSyntax == DicomTransferSyntax.JPEG2000Lossless || toTransferSyntax == DicomTransferSyntax.JPEG2000Lossy) &&
((photometricInterpretation == PhotometricInterpretation.YbrIct.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrRct.Value)))
{
return false;
}
if ((fromTs == DicomTransferSyntax.DeflatedExplicitVRLittleEndian ||
fromTs == DicomTransferSyntax.ExplicitVRBigEndian ||
fromTs == DicomTransferSyntax.ExplicitVRLittleEndian ||
fromTs == DicomTransferSyntax.ImplicitVRLittleEndian ||
fromTs == DicomTransferSyntax.RLELossless) &&
(toTransferSyntax == DicomTransferSyntax.JPEG2000Lossless ||
toTransferSyntax == DicomTransferSyntax.JPEG2000Lossy ||
toTransferSyntax == DicomTransferSyntax.JPEGProcess1 ||
toTransferSyntax == DicomTransferSyntax.JPEGProcess2_4) &&
((photometricInterpretation == PhotometricInterpretation.Rgb.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrFull422.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrPartial422.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrPartial420.Value)))
{
return false;
}
if ((fromTs == DicomTransferSyntax.JPEG2000Lossless || fromTs == DicomTransferSyntax.JPEG2000Lossy) &&
((photometricInterpretation == PhotometricInterpretation.Rgb.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrFull422.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrPartial422.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrPartial420.Value)))
{
return false;
}
if ((fromTs == DicomTransferSyntax.JPEGProcess1 || fromTs == DicomTransferSyntax.JPEGProcess2_4) &&
((photometricInterpretation == PhotometricInterpretation.Rgb.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrFull.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrFull422.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrPartial422.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrPartial420.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrIct.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrRct.Value)))
{
return false;
}
// Bug in fo-dicom 4.0.1
if ((toTransferSyntax == DicomTransferSyntax.JPEGProcess1 || toTransferSyntax == DicomTransferSyntax.JPEGProcess2_4) &&
((photometricInterpretation == PhotometricInterpretation.Monochrome1.Value) ||
(photometricInterpretation == PhotometricInterpretation.Monochrome2.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrFull.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrIct.Value) ||
(photometricInterpretation == PhotometricInterpretation.YbrRct.Value)))
{
return false;
}
if (((bpp > 8) && SupportedTransferSyntaxesOver8Bit.Contains(toTransferSyntax) && SupportedTransferSyntaxesOver8Bit.Contains(fromTs)) ||
((bpp <= 8) && SupportedTransferSyntaxes8Bit.Contains(toTransferSyntax) && SupportedTransferSyntaxes8Bit.Contains(fromTs)))
{
return true;
}
return false;
}