using System; using System.IO; using ClearCanvas.Common; using ClearCanvas.Desktop; using ClearCanvas.Desktop.Actions; using ClearCanvas.Dicom; using ClearCanvas.ImageViewer; using ClearCanvas.ImageViewer.BaseTools; using ClearCanvas.ImageViewer.StudyManagement; namespace Nullstack.ClearCanvas.ImageViewerTools.PixelDataRedux { [MenuAction("a", "global-menus/MenuDebug/SlayTheDragon", "PDDump")] [MenuAction("b", "global-menus/MenuDebug/Recompre", "Recompress")] [ExtensionOf(typeof (ImageViewerToolExtensionPoint))] public class PDReduxTool : ImageViewerTool { public void Recompress() { try { FileDialogCreationArgs args = new FileDialogCreationArgs(""); args.Filters.Add(new FileExtensionFilter("*.dcm", "DCM Images")); FileDialogResult fdr = base.Context.DesktopWindow.ShowSaveFileDialogBox(args); if (fdr.Action == DialogBoxAction.Ok) { if (base.SelectedImageSopProvider.ImageSop.DataSource is ILocalSopDataSource) { ILocalSopDataSource lds = (ILocalSopDataSource)base.SelectedImageSopProvider.ImageSop.DataSource; DicomFile dcf = new DicomFile(lds.Filename); dcf.Load(); dcf.ChangeTransferSyntax(TransferSyntax.JpegLosslessNonHierarchicalFirstOrderPredictionProcess14SelectionValue1); dcf.Save(fdr.FileName); } } } catch (Exception ex) { ExceptionHandler.Report(ex, base.Context.DesktopWindow); } } public void PDDump() { try { FileDialogCreationArgs args = new FileDialogCreationArgs(""); args.Filters.Add(new FileExtensionFilter("*.raw", "RAW Images")); FileDialogResult fdr = base.Context.DesktopWindow.ShowSaveFileDialogBox(args); if (fdr.Action == DialogBoxAction.Ok) { if (base.SelectedImageSopProvider.ImageSop.DataSource is ILocalSopDataSource) { ILocalSopDataSource lds = (ILocalSopDataSource) base.SelectedImageSopProvider.ImageSop.DataSource; DicomFile dcf = new DicomFile(lds.Filename); dcf.Load(); if (!dcf.TransferSyntax.Encapsulated) { DicomUncompressedPixelData dupd = new DicomUncompressedPixelData(dcf); byte[] fpd = dupd.GetFrame(0); File.WriteAllBytes(fdr.FileName, fpd); } else if (global::ClearCanvas.Dicom.Codec.DicomCodecRegistry.GetCodec(dcf.TransferSyntax) != null) { DicomCompressedPixelData dcpd = new DicomCompressedPixelData(dcf); string pi; byte[] fpd = dcpd.GetFrame(0, out pi); File.WriteAllBytes(fdr.FileName, fpd); } else { throw new NotSupportedException("Codec not found"); } } } } catch (Exception ex) { ExceptionHandler.Report(ex, base.Context.DesktopWindow); } } } }