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); }
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 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()); context.Response.Headers.Add("BitsStored", pd.BitsStored.ToString()); context.Response.Headers.Add("DerivationDescription", pd.DerivationDescription); context.Response.Headers.Add("HighBit", pd.HighBit.ToString()); context.Response.Headers.Add("ImageHeight", pd.ImageHeight.ToString()); context.Response.Headers.Add("ImageWidth", pd.ImageWidth.ToString()); context.Response.Headers.Add("LossyImageCompression", pd.LossyImageCompression); context.Response.Headers.Add("LossyImageCompressionMethod", pd.LossyImageCompressionMethod); context.Response.Headers.Add("LossyImageCompressionRatio", pd.LossyImageCompressionRatio.ToString()); context.Response.Headers.Add("NumberOfFrames", pd.NumberOfFrames.ToString()); context.Response.Headers.Add("PhotometricInterpretation", pd.PhotometricInterpretation); context.Response.Headers.Add("PixelRepresentation", pd.PixelRepresentation.ToString()); context.Response.Headers.Add("PlanarConfiguration", pd.PlanarConfiguration.ToString()); context.Response.Headers.Add("SamplesPerPixel", pd.SamplesPerPixel.ToString()); } #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"); }