예제 #1
0
        /// <summary>
        /// Converts colour pixel data to ARGB.
        /// </summary>
        protected static byte[] ToArgb(IDicomAttributeProvider dicomAttributeProvider, byte[] pixelData, PhotometricInterpretation photometricInterpretation)
        {
            CodeClock clock = new CodeClock();

            clock.Start();

            int rows        = dicomAttributeProvider[DicomTags.Rows].GetInt32(0, 0);
            int columns     = dicomAttributeProvider[DicomTags.Columns].GetInt32(0, 0);
            int sizeInBytes = rows * columns * 4;

            byte[] argbPixelData = MemoryManager.Allocate <byte>(sizeInBytes);

            // Convert palette colour images to ARGB so we don't get interpolation artifacts
            // when rendering.
            if (photometricInterpretation == PhotometricInterpretation.PaletteColor)
            {
                int bitsAllocated       = dicomAttributeProvider[DicomTags.BitsAllocated].GetInt32(0, 0);
                int pixelRepresentation = dicomAttributeProvider[DicomTags.PixelRepresentation].GetInt32(0, 0);

                ColorSpaceConverter.ToArgb(
                    bitsAllocated,
                    pixelRepresentation != 0 ? true : false,
                    pixelData,
                    argbPixelData,
                    PaletteColorMap.Create(dicomAttributeProvider));
            }
            // Convert RGB and YBR variants to ARGB
            else
            {
                int planarConfiguration = dicomAttributeProvider[DicomTags.PlanarConfiguration].GetInt32(0, 0);

                ColorSpaceConverter.ToArgb(
                    photometricInterpretation,
                    planarConfiguration,
                    pixelData,
                    argbPixelData);
            }

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

            return(argbPixelData);
        }
예제 #2
0
 public PixelData GetPixelData()
 {
     if (!IsColor)
     {
         byte[] pixelData = PixelData ?? new byte[Rows * Columns * BitsAllocated / 8];
         return(new GrayscalePixelData(Rows, Columns, BitsAllocated, BitsStored,
                                       HighBit, PixelRepresentation != 0, pixelData));
     }
     else
     {
         if (PixelData == null)
         {
             return(new ColorPixelData(Rows, Columns, new byte[Rows * Columns * 4]));
         }
         else
         {
             byte[] original = PixelData;
             byte[] argb     = new byte[Rows * Columns * 4];
             ColorSpaceConverter.ToArgb(InternalPhotometricInterpretation, PlanarConfiguration, original, argb);
             return(new ColorPixelData(Rows, Columns, argb));
         }
     }
 }