public IList <IStorageLocation> CreateMedia(DicomFile data) { if (null != MediaStorage) { string key = null; int framesCount = 1; List <IStorageLocation> locations = new List <IStorageLocation> ( ); if (StoreMultiFrames) { DicomPixelData pd; pd = DicomPixelData.CreateFrom(data); framesCount = pd.NumberOfFrames; } for (int frame = 1; frame <= framesCount; frame++) { var storeLocation = MediaStorage.GetLocation(new DicomMediaId(data.DataSet, frame, MediaType)); Upload(data, frame, storeLocation); locations.Add(storeLocation); } return(locations); } throw new InvalidOperationException("No MediaStorage service found"); }
protected override WadoResponse DoProcess(IWadoUriRequest request, string mimeType) { var dcmLocation = MediaStorage.GetLocation(MediaFactory.Create(request, new DicomMediaProperties { MediaType = MimeMediaTypes.DICOM, TransferSyntax = (request.ImageRequestInfo != null) ? request.ImageRequestInfo.TransferSyntax : "" })); if (!dcmLocation.Exists( )) { throw new ApplicationException("Object Not Found - return proper wado error "); } //if (string.Compare(mimeType, MimeMediaTypes.DICOM, true) == 0) { return(new WadoResponse(Location.GetReadStream( ), mimeType)); } }
public virtual IWadoRsResponse Process(IWadoUriRequest request, string mimeType) { Location = MediaStorage.GetLocation(MediaFactory.Create(request, GetMediaProperties(request, mimeType, GetTransferSyntax(request)))); if (Location != null && Location.Exists( )) { WadoResponse response = new WadoResponse(Location.GetReadStream( ), mimeType); return(response); } else { //TODO: in case mime not storedmethod to create on return(DoProcess(request, mimeType)); } }
//TODO: I should be able to replace this with the media readers now protected override WadoResponse DoProcess(IWadoUriRequest request, string mimeType) { var dcmLocation = MediaStorage.GetLocation(new DicomMediaId(request, MimeMediaTypes.DICOM)); //var dcmLocation = RetrieveService.RetrieveSopInstances ( request, mimeType ).FirstOrDefault(); if (!dcmLocation.Exists( )) { throw new ApplicationException("Object Not Found - return proper wado error "); } //if (string.Compare(mimeType, MimeMediaTypes.DICOM, true) == 0) { return(new WadoResponse(Location, mimeType)); } DicomFile file = new DicomFile( ); var frameIndex = request.ImageRequestInfo.FrameNumber - 1 ?? 0; frameIndex = Math.Max(frameIndex, 0); file.Load(dcmLocation.GetReadStream()); if (string.Compare(mimeType, MimeMediaTypes.Jpeg, true) == 0) { WadoResponse response = new WadoResponse(); if (file.TransferSyntax == TransferSyntax.JpegBaselineProcess1) { //ClearCanvas.Dicom.Codec.Jpeg.Jpeg8Codec codec = new ClearCanvas.Dicom.Codec.Jpeg.Jpeg8Codec (ClearCanvas.Dicom.Codec.Jpeg.JpegMode.Baseline, 0, 0 ) //codec.Encode () DicomCompressedPixelData pd = DicomPixelData.CreateFrom(file) as DicomCompressedPixelData; byte[] buffer = pd.GetFrameFragmentData(frameIndex); response.Content = new MemoryStream(buffer); response.MimeType = mimeType; return(response); } else { } } if (string.Compare(mimeType, MimeMediaTypes.UncompressedData) == 0) { WadoResponse response = null; DicomPixelData pd = null; byte[] buffer = null; response = new WadoResponse( ); pd = DicomPixelData.CreateFrom(file); buffer = pd.GetFrame(frameIndex); //********* TEST CODE*************** //System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap (pd.ImageWidth, pd.ImageHeight, System.Drawing.Imaging.PixelFormat.Format8bppIndexed ) ; //System.Drawing.Imaging.ColorPalette ncp = bitmap.Palette; // for (int i = 0; i < 256; i++) // ncp.Entries[i] = System.Drawing.Color.FromArgb(255, i, i, i); // bitmap.Palette = ncp; // System.Drawing.Imaging.BitmapData data = bitmap.LockBits (new System.Drawing.Rectangle ( 0,0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); //IntPtr ptr = data.Scan0 ; //System.Runtime.InteropServices.Marshal.Copy (buffer, 0, ptr, buffer.Length ) ; //string fileName = @"C:\Users\zalsafadi_p.SPX\Downloads\libwebp-master\Output\release-static\x86\bin\Samples\uncompressed.raw" ; //bitmap.UnlockBits (data); //bitmap.Save ( fileName); //File.WriteAllBytes(fileName, buffer) ; //********* TEST CODE*************** response.Content = new MemoryStream(buffer); response.MimeType = mimeType; return(response); } //if ( string.Compare(mimeType, MimeMediaTypes.WebP) == 0) //{ // WadoResponse response = new WadoResponse ( ) ; // byte[] buffer = File.ReadAllBytes(Location) ; // response.Content = new MemoryStream(buffer); // response.MimeType = mimeType ; // return response ; //} return(null); }