public static void RoundTripAndRender() { foreach (FileInfo fi in new DirectoryInfo("..\\CompressionSamples").GetFiles("*.dcm")) { Console.WriteLine("Compression Test -- Filename: " + fi.Name); DICOMData data = new DICOMData(); data.ParseFile(fi.FullName, true, new NullLogger()); TransferSyntax syntax = data.TransferSyntax; int compressedLength = (int)data[DICOMTags.PixelData].GetDataLength(false); data.Uncompress(); Image testImage = DICOMQuickRenderer.QuickRender(data, 0); Assert.IsNotNull(testImage); int uncompressedLength = (int)data[DICOMTags.PixelData].GetDataLength(false); Assert.IsTrue(uncompressedLength > compressedLength); if (CompressionWorker.SupportsCompression(syntax.Compression)) { data.ChangeTransferSyntax(syntax); int recompressedLength = (int)data[DICOMTags.PixelData].GetDataLength(false); Assert.IsTrue(recompressedLength < uncompressedLength); } //data.WriteFile(fi.FullName.Replace(".dcm", "_un.dcm")); } }
/// <summary> /// Checks to see if we support both the decompression (if any) and compression (if any) to perform the transfer syntax change requested. /// If either step is not available, then this will return false, but you may still be able to do a decompression. You can check that with /// the static methods on <see cref="DICOMSharp.Data.Compression.CompressionWorker"/>. /// </summary> /// <param name="newSyntax">The new transfer syntax you'd like to change to</param> /// <returns>Whether or not the complete change can be performed.</returns> public bool CanChangeTransferSyntax(TransferSyntax newSyntax) { if (!CompressionWorker.SupportsDecompression(this.TransferSyntax.Compression)) { return(false); } if (!CompressionWorker.SupportsCompression(newSyntax.Compression)) { return(false); } return(true); }