protected virtual IImageMimeTypeProcessor GetMimeTypeProcessor(ImageStreamingContext context) { string responseContentType = context.ContentType; if (String.IsNullOrEmpty(responseContentType)) { if (context.IsMultiFrame) { responseContentType = "application/dicom"; } else { responseContentType = "image/jpeg"; if (!ClientAcceptable(context, responseContentType)) { responseContentType = "application/dicom"; } } } if (_processorMap.ContainsKey(context.ContentType)) { return((IImageMimeTypeProcessor)Activator.CreateInstance(_processorMap[context.ContentType])); } ImageMimeTypeProcessorExtensionPoint xp = new ImageMimeTypeProcessorExtensionPoint(); object[] plugins = xp.CreateExtensions(); bool found = false; foreach (IImageMimeTypeProcessor mimeTypeConverter in plugins) { if (mimeTypeConverter.OutputMimeType == responseContentType) { found = true; _processorMap.Add(context.ContentType, mimeTypeConverter.GetType()); if (ClientAcceptable(context, mimeTypeConverter.OutputMimeType)) { return(mimeTypeConverter); } } } if (found) { throw new WADOException(HttpStatusCode.NotAcceptable, String.Format("{0} is supported but is not acceptable by the client", responseContentType)); } else { throw new WADOException(HttpStatusCode.BadRequest, String.Format("The specified contentType '{0}' is not supported", responseContentType)); } }
public WADOResponse Process(WADORequestTypeHandlerContext context) { Platform.CheckForNullReference(context, "httpContext"); Platform.CheckForNullReference(context.ServerAE, "context.ServerAE"); Platform.CheckForNullReference(context.HttpContext, "context.HttpContext"); // Cache the query string for performance purpose. Every time Request.QueryString is called, .NET will rebuild the entire dictionary. NameValueCollection query = context.HttpContext.Request.QueryString; ServerPartition partition = ServerPartitionMonitor.Instance.GetPartition(context.ServerAE); if (partition == null) { throw new WADOException(HttpStatusCode.NotFound, String.Format(SR.FaultPartitionNotExists, context.ServerAE)); } if (!partition.Enabled) { throw new WADOException(HttpStatusCode.Forbidden, String.Format(SR.FaultPartitionDisabled, context.ServerAE)); } ImageStreamingContext streamingContext = new ImageStreamingContext(context.HttpContext); streamingContext.ServerAE = context.ServerAE; streamingContext.ContentType = query["ContentType"]; streamingContext.AcceptTypes = context.HttpContext.Request.AcceptTypes; streamingContext.StudyInstanceUid = query["studyuid"]; streamingContext.SeriesInstanceUid = query["seriesuid"]; streamingContext.ObjectUid = query["objectuid"]; string sessionId = context.HttpContext.Request.RemoteEndPoint.Address.ToString(); StudyStorageLoader storageLoader = new StudyStorageLoader(sessionId); storageLoader.CacheEnabled = ImageStreamingServerSettings.Default.EnableCache; storageLoader.CacheRetentionTime = ImageStreamingServerSettings.Default.CacheRetentionWindow; streamingContext.StorageLocation = storageLoader.Find(streamingContext.StudyInstanceUid, partition); // convert the dicom image into the appropriate mime type WADOResponse response = new WADOResponse(); IImageMimeTypeProcessor processor = GetMimeTypeProcessor(streamingContext); MimeTypeProcessorOutput output = processor.Process(streamingContext); response.Output = output.Output; response.ContentType = output.ContentType; response.IsLast = output.IsLast; return(response); }
protected static bool ClientAcceptable(ImageStreamingContext context, string contentType) { if (context.AcceptTypes == null) return false; foreach(string rawmime in context.AcceptTypes) { string mime = rawmime; if (rawmime.Contains(";")) mime = rawmime.Substring(0, rawmime.IndexOf(";")); if (mime=="*/*" || mime==contentType) return true; } return false; }
public MimeTypeProcessorOutput Process(ImageStreamingContext context) { var output = new MimeTypeProcessorOutput { ContentType = OutputMimeType }; var file = new DicomFile(context.ImagePath); file.Load(DicomReadOptions.StorePixelDataReferences); if (!file.SopClass.Equals(SopClass.EncapsulatedPdfStorage)) throw new WADOException(HttpStatusCode.NotImplemented, "image/pdf is not supported for this type of object: " + file.SopClass.Name); var iod = new EncapsulatedDocumentModuleIod(file.DataSet); output.Output = iod.EncapsulatedDocument; return output; }
public WADOResponse Process(WADORequestTypeHandlerContext context) { Platform.CheckForNullReference(context, "httpContext"); Platform.CheckForNullReference(context.ServerAE, "context.ServerAE"); Platform.CheckForNullReference(context.HttpContext, "context.HttpContext"); // Cache the query string for performance purpose. Every time Request.QueryString is called, .NET will rebuild the entire dictionary. NameValueCollection query = context.HttpContext.Request.QueryString; ServerPartition partition = ServerPartitionMonitor.Instance.GetPartition(context.ServerAE); if (partition== null) throw new WADOException(HttpStatusCode.NotFound, String.Format(SR.FaultPartitionNotExists, context.ServerAE)); if (!partition.Enabled) throw new WADOException(HttpStatusCode.Forbidden, String.Format(SR.FaultPartitionDisabled, context.ServerAE)); ImageStreamingContext streamingContext = new ImageStreamingContext(context.HttpContext); streamingContext.ServerAE = context.ServerAE; streamingContext.ContentType = query["ContentType"]; streamingContext.AcceptTypes = context.HttpContext.Request.AcceptTypes; streamingContext.StudyInstanceUid = query["studyuid"]; streamingContext.SeriesInstanceUid = query["seriesuid"]; streamingContext.ObjectUid = query["objectuid"]; string sessionId = context.HttpContext.Request.RemoteEndPoint.Address.ToString(); StudyStorageLoader storageLoader = new StudyStorageLoader(sessionId); storageLoader.CacheEnabled = ImageStreamingServerSettings.Default.EnableCache; storageLoader.CacheRetentionTime = ImageStreamingServerSettings.Default.CacheRetentionWindow; streamingContext.StorageLocation = storageLoader.Find(streamingContext.StudyInstanceUid, partition); // convert the dicom image into the appropriate mime type WADOResponse response = new WADOResponse(); IImageMimeTypeProcessor processor = GetMimeTypeProcessor(streamingContext); MimeTypeProcessorOutput output = processor.Process(streamingContext); response.Output = output.Output; response.ContentType = output.ContentType; response.IsLast = output.IsLast; return response; }
protected static bool ClientAcceptable(ImageStreamingContext context, string contentType) { if (context.AcceptTypes == null) { return(false); } foreach (string rawmime in context.AcceptTypes) { string mime = rawmime; if (rawmime.Contains(";")) { mime = rawmime.Substring(0, rawmime.IndexOf(";")); } if (mime == "*/*" || mime == contentType) { return(true); } } return(false); }
public MimeTypeProcessorOutput Process(ImageStreamingContext context) { uint stopTag; if (!uint.TryParse(context.Request.QueryString["stopTag"] ?? "", NumberStyles.HexNumber, null, out stopTag)) stopTag = DicomTags.PixelData; if (stopTag > DicomTags.PixelData) throw new WADOException(HttpStatusCode.BadRequest, "Stop tag must be less than PixelData tag."); MimeTypeProcessorOutput output = new MimeTypeProcessorOutput(); output.ContentType = OutputMimeType; DicomFile file = new DicomFile(context.ImagePath); file.Load(stopTag, DicomReadOptions.Default); output.ContentType = OutputMimeType; MemoryStream memStream = new MemoryStream(); file.Save(memStream, DicomWriteOptions.Default); output.Output = memStream.ToArray(); return output; }
protected virtual IImageMimeTypeProcessor GetMimeTypeProcessor(ImageStreamingContext context) { string responseContentType = context.ContentType; if (String.IsNullOrEmpty(responseContentType)) { if (context.IsMultiFrame) { responseContentType = "application/dicom"; } else { responseContentType = "image/jpeg"; if (!ClientAcceptable(context, responseContentType)) { responseContentType = "application/dicom"; } } } if (_processorMap.ContainsKey(responseContentType)) { Type processorType = _processorMap[responseContentType]; var processor = (IImageMimeTypeProcessor)Activator.CreateInstance(processorType); if (!ClientAcceptable(context, processor.OutputMimeType)) { Platform.Log(LogLevel.Warn, "Client requested for {0} but did not indicate in the request headers that it could support this mime-type (check HTTP-Accept)", context.ContentType); } return(processor); } throw new WADOException(HttpStatusCode.BadRequest, String.Format("The specified contentType '{0}' is not supported", responseContentType)); }
public MimeTypeProcessorOutput Process(ImageStreamingContext context) { MimeTypeProcessorOutput output = new MimeTypeProcessorOutput(); output.ContentType = OutputMimeType; using (FileStream stream = FileStreamOpener.OpenForRead(context.ImagePath, FileMode.Open)) { output.ContentType = OutputMimeType; byte[] buffer = new byte[stream.Length]; int offset = 0; int readBytes = 0; do { readBytes = stream.Read(buffer, offset, buffer.Length - offset); if (readBytes > 0) { offset += readBytes; } } while (readBytes > 0); output.Output = buffer; stream.Close(); } return output; }
public MimeTypeProcessorOutput Process(ImageStreamingContext context) { Platform.CheckForNullReference(context, "context"); DicomPixelData pd = context.PixelData; MimeTypeProcessorOutput output = new MimeTypeProcessorOutput(); int frame = context.FrameNumber; if (context.FrameNumber < 0) { throw new WADOException(HttpStatusCode.BadRequest, String.Format("Requested FrameNumber {0} cannot be negative.", frame)); } else if (frame >= pd.NumberOfFrames) { throw new WADOException(HttpStatusCode.BadRequest, String.Format("Requested FrameNumber {0} exceeds the number of frames in the image.", frame)); } output.ContentType = OutputMimeType; PixelDataLoader loader = new PixelDataLoader(context); output.Output = loader.ReadFrame(frame); output.IsLast = (pd.NumberOfFrames == frame + 1); // note: the transfer syntax of the returned pixel data may not be the same as that in the original image. // In the future, the clients may specify different transfer syntaxes which may mean the compressed image must be decompressed or vice versa. TransferSyntax transferSyntax = pd.TransferSyntax; output.IsCompressed = transferSyntax.LosslessCompressed || transferSyntax.LossyCompressed; #region Special Code // Note: this block of code inject special header fields to assist the clients handling the images // For eg, the if (output.IsLast) context.Response.Headers.Add("IsLast", "true"); if (output.IsCompressed) { // Fields that can be used by the web clients to decompress the compressed images streamed by the server. context.Response.Headers.Add("Compressed", "true"); context.Response.Headers.Add("TransferSyntaxUid", pd.TransferSyntax.UidString); context.Response.Headers.Add("BitsAllocated", pd.BitsAllocated.ToString(CultureInfo.InvariantCulture)); context.Response.Headers.Add("BitsStored", pd.BitsStored.ToString(CultureInfo.InvariantCulture)); context.Response.Headers.Add("DerivationDescription", pd.DerivationDescription); context.Response.Headers.Add("HighBit", pd.HighBit.ToString(CultureInfo.InvariantCulture)); context.Response.Headers.Add("ImageHeight", pd.ImageHeight.ToString(CultureInfo.InvariantCulture)); context.Response.Headers.Add("ImageWidth", pd.ImageWidth.ToString(CultureInfo.InvariantCulture)); context.Response.Headers.Add("LossyImageCompression", pd.LossyImageCompression); context.Response.Headers.Add("LossyImageCompressionMethod", pd.LossyImageCompressionMethod); context.Response.Headers.Add("LossyImageCompressionRatio", pd.LossyImageCompressionRatio.ToString(CultureInfo.InvariantCulture)); context.Response.Headers.Add("NumberOfFrames", pd.NumberOfFrames.ToString(CultureInfo.InvariantCulture)); context.Response.Headers.Add("PhotometricInterpretation", pd.PhotometricInterpretation); context.Response.Headers.Add("PixelRepresentation", pd.PixelRepresentation.ToString(CultureInfo.InvariantCulture)); context.Response.Headers.Add("PlanarConfiguration", pd.PlanarConfiguration.ToString(CultureInfo.InvariantCulture)); context.Response.Headers.Add("SamplesPerPixel", pd.SamplesPerPixel.ToString(CultureInfo.InvariantCulture)); } #endregion if (Platform.IsLogLevelEnabled(LogLevel.Debug)) { Platform.Log(LogLevel.Debug, "Streaming {0} pixel data: {1} x {2} x {3} , {4} bits [{5} KB] ({6})", output.IsCompressed ? "compressed" : "uncompressed", pd.ImageHeight, pd.ImageWidth, pd.SamplesPerPixel, pd.BitsStored, output.Output.Length/1024, pd.TransferSyntax.Name); } return output; }
public MimeTypeProcessorOutput Process(ImageStreamingContext context) { throw new WADOException( HttpStatusCode.NotImplemented, "image/jpeg is not supported. Please use a different ContentType"); }
protected virtual IImageMimeTypeProcessor GetMimeTypeProcessor(ImageStreamingContext context) { string responseContentType = context.ContentType; if (String.IsNullOrEmpty(responseContentType)) { if (context.IsMultiFrame) responseContentType = "application/dicom"; else { responseContentType = "image/jpeg"; if (!ClientAcceptable(context, responseContentType)) { responseContentType = "application/dicom"; } } } if (_processorMap.ContainsKey(context.ContentType)) { return (IImageMimeTypeProcessor) Activator.CreateInstance(_processorMap[context.ContentType]); } ImageMimeTypeProcessorExtensionPoint xp = new ImageMimeTypeProcessorExtensionPoint(); object[] plugins = xp.CreateExtensions(); bool found = false; foreach (IImageMimeTypeProcessor mimeTypeConverter in plugins) { if (mimeTypeConverter.OutputMimeType == responseContentType) { found = true; _processorMap.Add(context.ContentType, mimeTypeConverter.GetType()); if (ClientAcceptable(context, mimeTypeConverter.OutputMimeType)) { return mimeTypeConverter; } } } if (found) { throw new WADOException(HttpStatusCode.NotAcceptable, String.Format("{0} is supported but is not acceptable by the client", responseContentType)); } else { throw new WADOException(HttpStatusCode.BadRequest, String.Format("The specified contentType '{0}' is not supported", responseContentType)); } }
protected virtual IImageMimeTypeProcessor GetMimeTypeProcessor(ImageStreamingContext context) { string responseContentType = context.ContentType; if (String.IsNullOrEmpty(responseContentType)) { if (context.IsMultiFrame) responseContentType = "application/dicom"; else { responseContentType = "image/jpeg"; if (!ClientAcceptable(context, responseContentType)) { responseContentType = "application/dicom"; } } } if (_processorMap.ContainsKey(responseContentType)) { Type processorType = _processorMap[responseContentType]; var processor = (IImageMimeTypeProcessor)Activator.CreateInstance(processorType); if (!ClientAcceptable(context, processor.OutputMimeType)) { Platform.Log(LogLevel.Warn, "Client requested for {0} but did not indicate in the request headers that it could support this mime-type (check HTTP-Accept)", context.ContentType); } return processor; } throw new WADOException(HttpStatusCode.BadRequest, String.Format("The specified contentType '{0}' is not supported", responseContentType)); }
internal PixelDataLoader(ImageStreamingContext context) { _context = context; }
internal PixelDataLoader(ImageStreamingContext context) { _context = context; }