/// <summary>
            /// Called by the base class to create a new byte buffer containing normalized pixel data
            /// for this frame (8 or 16-bit grayscale, or 32-bit ARGB).
            /// </summary>
            /// <returns>A new byte buffer containing the normalized pixel data.</returns>
            protected override byte[] CreateNormalizedPixelData()
            {
                DicomMessageBase message = this.Parent.SourceMessage;

                CodeClock clock = new CodeClock();

                clock.Start();

                PhotometricInterpretation photometricInterpretation;

                byte[] rawPixelData = null;

                if (!message.TransferSyntax.Encapsulated)
                {
                    DicomUncompressedPixelData pixelData = new DicomUncompressedPixelData(message);
                    // DICOM library uses zero-based frame numbers
                    MemoryManager.Execute(delegate { rawPixelData = pixelData.GetFrame(_frameIndex); });

                    ExtractOverlayFrames(rawPixelData, pixelData.BitsAllocated);

                    photometricInterpretation = PhotometricInterpretation.FromCodeString(message.DataSet[DicomTags.PhotometricInterpretation]);
                }
                else if (DicomCodecRegistry.GetCodec(message.TransferSyntax) != null)
                {
                    DicomCompressedPixelData pixelData = new DicomCompressedPixelData(message);
                    string pi = null;

                    MemoryManager.Execute(delegate { rawPixelData = pixelData.GetFrame(_frameIndex, out pi); });

                    photometricInterpretation = PhotometricInterpretation.FromCodeString(pi);
                }
                else
                {
                    throw new DicomCodecException("Unsupported transfer syntax");
                }

                if (photometricInterpretation.IsColor)
                {
                    rawPixelData = ToArgb(message.DataSet, rawPixelData, photometricInterpretation);
                }
                else
                {
                    NormalizeGrayscalePixels(message.DataSet, rawPixelData);
                }

                clock.Stop();
                PerformanceReportBroker.PublishReport("DicomMessageSopDataSource", "CreateFrameNormalizedPixelData", clock.Seconds);

                return(rawPixelData);
            }
示例#2
0
        protected override void Upload(DicomFile dicomObject, int frame, IStorageLocation storeLocation)
        {
            var frameIndex = frame - 1;


            if (dicomObject.TransferSyntax == TransferSyntax.JpegBaselineProcess1)
            {
                DicomCompressedPixelData pd = DicomPixelData.CreateFrom(dicomObject) as DicomCompressedPixelData;


                byte[] buffer = pd.GetFrameFragmentData(frameIndex);

                storeLocation.Upload(buffer);
            }
            else if (false)   //TODO: handle compressed images properly!
            {
                DicomFile dcmJpeg = new DicomFile( );
                DicomUncompressedPixelData unCompressed = DicomPixelData.CreateFrom(dicomObject) as DicomUncompressedPixelData;
                DicomCompressedPixelData   compressed   = new DicomCompressedPixelData(unCompressed);


                //compressed.ImageWidth = unCompressed.ImageWidth;
                //compressed.ImageHeight = unCompressed.HighBit;
                compressed.BitsStored    = 8;
                compressed.BitsAllocated = 8;
                //compressed.HighBit = 7;
                compressed.SamplesPerPixel = 3;
                //compressed.PlanarConfiguration = 0;
                compressed.PhotometricInterpretation = "YBR_FULL_422";
                compressed.TransferSyntax            = TransferSyntax.JpegBaselineProcess1;

                byte[] imageBuffer = unCompressed.GetFrame(frameIndex);
                compressed.AddFrameFragment(imageBuffer);

                compressed.UpdateMessage(dcmJpeg);

                storeLocation.Upload(compressed.GetFrame(frameIndex));
                //ClearCanvas.Dicom.Codec.Jpeg.Jpeg8Codec codec = new ClearCanvas.Dicom.Codec.Jpeg.Jpeg8Codec (ClearCanvas.Dicom.Codec.Jpeg.JpegMode.Baseline, 0, 0 ) ;
                //ClearCanvas.Dicom.Codec.Jpeg.DicomJpegParameters jparam = new ClearCanvas.Dicom.Codec.Jpeg.DicomJpegParameters ( ) ;

                //jparam.
                //codec.
                //codec.Encode ( )
            }
        }
示例#3
0
        public byte[] GetPixelData()
        {
            if (_compressedPixelData != null)
            {
                try
                {
                    byte[] uncompressed = _compressedPixelData.GetFrame(0);

                    _pixelData           = uncompressed;
                    _compressedPixelData = null;
                }
                catch (Exception ex)
                {
                    throw new Exception(String.Format("Error occurred while decompressing the pixel data: {0}", ex.Message));
                }
            }

            return(_pixelData);
        }