protected override IJpegNativeCodec GetCodec(int bits, DicomJpegParams jparams)
 {
     if (bits <= 8) return new Jpeg8Codec(JpegMode.Lossless, jparams.Predictor, jparams.PointTransform);
     if (bits <= 12) return new Jpeg12Codec(JpegMode.Lossless, jparams.Predictor, jparams.PointTransform);
     if (bits <= 16) return new Jpeg16Codec(JpegMode.Lossless, jparams.Predictor, jparams.PointTransform);
     throw new DicomCodecException("Unable to create JPEG Process 14 codec for bits stored == {0}", bits);
 }
예제 #2
0
 protected override IJpegNativeCodec GetCodec(int bits, DicomJpegParams jparams)
 {
     if (bits == 8)
     {
         return(new Jpeg8Codec(JpegMode.Baseline, 0, 0));
     }
     throw new DicomCodecException("Unable to create JPEG Process 1 codec for bits stored == {0}", bits);
 }
		protected override IJpegNativeCodec GetCodec(int bits, DicomJpegParams jparams)
		{
			if (bits == 8)
			return new Jpeg8Codec(JpegMode.Sequential, 0, 0);
			if (bits <= 12)
				return new Jpeg12Codec(JpegMode.Sequential, 0, 0);
			throw new DicomCodecException("Unable to create JPEG Process 4 codec for bits stored == {0}", bits);
		}
예제 #4
0
파일: DicomImage.cs 프로젝트: vdrm/fo-dicom
        /// <summary>
        /// Loads the pixel data for specified frame and set the internal dataset
        ///
        /// </summary>
        /// <param name="dataset">dataset to load pixeldata from</param>
        /// <param name="frame">The frame number to create pixeldata for</param>
        private void Load(DicomDataset dataset, int frame)
        {
            Dataset = dataset;

            if (PixelData == null)
            {
                PixelData = DicomPixelData.Create(Dataset);
                PhotometricInterpretation = PixelData.PhotometricInterpretation;
            }

            if (Dataset.InternalTransferSyntax.IsEncapsulated)
            {
                // decompress single frame from source dataset
                DicomCodecParams cparams = null;
                if (Dataset.InternalTransferSyntax == DicomTransferSyntax.JPEGProcess1 || Dataset.InternalTransferSyntax == DicomTransferSyntax.JPEGProcess2_4)
                {
                    cparams = new DicomJpegParams {
                        ConvertColorspaceToRGB = true
                    };
                }

                var transcoder = new DicomTranscoder(Dataset.InternalTransferSyntax, DicomTransferSyntax.ExplicitVRLittleEndian);
                transcoder.InputCodecParams  = cparams;
                transcoder.OutputCodecParams = cparams;
                var buffer = transcoder.DecodeFrame(Dataset, frame);

                // clone the dataset because modifying the pixel data modifies the dataset
                var clone = Dataset.Clone();
                clone.InternalTransferSyntax = DicomTransferSyntax.ExplicitVRLittleEndian;

                var pixelData = DicomPixelData.Create(clone, true);
                pixelData.AddFrame(buffer);

                // temporary fix for JPEG compressed YBR images
                if ((Dataset.InternalTransferSyntax == DicomTransferSyntax.JPEGProcess1 || Dataset.InternalTransferSyntax == DicomTransferSyntax.JPEGProcess2_4) && pixelData.SamplesPerPixel == 3)
                {
                    pixelData.PhotometricInterpretation = PhotometricInterpretation.Rgb;
                }

                _pixelData = PixelDataFactory.Create(pixelData, 0);
            }
            else
            {
                // pull uncompressed frame from source pixel data
                _pixelData = PixelDataFactory.Create(PixelData, frame);
            }

            _pixelData.Rescale(_scale);

            _overlays = DicomOverlayData.FromDataset(Dataset).Where(x => x.Type == DicomOverlayType.Graphics && x.Data != null).ToArray();

            _currentFrame = frame;

            CreatePipeline();
        }
 protected override IJpegNativeCodec GetCodec(int bits, DicomJpegParams jparams)
 {
     if (bits <= 8)
     {
         return(new Jpeg8Codec(JpegMode.Lossless, 1, jparams.PointTransform));
     }
     if (bits <= 12)
     {
         return(new Jpeg12Codec(JpegMode.Lossless, 1, jparams.PointTransform));
     }
     if (bits <= 16)
     {
         return(new Jpeg16Codec(JpegMode.Lossless, 1, jparams.PointTransform));
     }
     throw new DicomCodecException("Unable to create JPEG Process 14 [SV1] codec for bits stored == {0}", bits);
 }