Inheritance: DcmCodecParameters
示例#1
0
        public void Decode(DcmDataset dataset, DcmPixelData oldPixelData, DcmPixelData newPixelData, DcmCodecParameters parameters)
        {
            DcmRleCodecParameters rleParams = parameters as DcmRleCodecParameters;

            if (rleParams == null)
            {
                rleParams = GetDefaultParameters() as DcmRleCodecParameters;
            }

            int pixelCount       = oldPixelData.ImageWidth * oldPixelData.ImageHeight;
            int numberOfSegments = oldPixelData.BytesAllocated * oldPixelData.SamplesPerPixel;

            byte[] frameData = new byte[newPixelData.UncompressedFrameSize];

            for (int i = 0; i < oldPixelData.NumberOfFrames; i++)
            {
                IList <ByteBuffer> rleData = oldPixelData.GetFrameFragments(i);
                RLEDecoder         decoder = new RLEDecoder(rleData);

                if (decoder.NumberOfSegments != numberOfSegments)
                {
                    throw new DicomCodecException("Unexpected number of RLE segments!");
                }

                for (int s = 0; s < numberOfSegments; s++)
                {
                    int sample = s / newPixelData.BytesAllocated;
                    int sabyte = s % newPixelData.BytesAllocated;

                    int pos, offset;

                    if (newPixelData.PlanarConfiguration == 0)
                    {
                        pos    = sample * newPixelData.BytesAllocated;
                        offset = newPixelData.SamplesPerPixel * newPixelData.BytesAllocated;
                    }
                    else
                    {
                        pos    = sample * newPixelData.BytesAllocated * pixelCount;
                        offset = newPixelData.BytesAllocated;
                    }

                    if (rleParams.ReverseByteOrder)
                    {
                        pos += sabyte;
                    }
                    else
                    {
                        pos += newPixelData.BytesAllocated - sabyte - 1;
                    }

                    decoder.DecodeSegment(s, frameData, pos, offset);
                }

                newPixelData.AddFrame(frameData);
            }
        }
示例#2
0
        public void Encode(DcmDataset dataset, DcmPixelData oldPixelData, DcmPixelData newPixelData, DcmCodecParameters parameters)
        {
            DcmRleCodecParameters rleParams = parameters as DcmRleCodecParameters;

            if (rleParams == null)
            {
                rleParams = GetDefaultParameters() as DcmRleCodecParameters;
            }

            int pixelCount       = oldPixelData.ImageWidth * oldPixelData.ImageHeight;
            int numberOfSegments = oldPixelData.BytesAllocated * oldPixelData.SamplesPerPixel;

            for (int i = 0; i < oldPixelData.NumberOfFrames; i++)
            {
                RLEEncoder encoder   = new RLEEncoder();
                byte[]     frameData = oldPixelData.GetFrameDataU8(i);

                for (int s = 0; s < numberOfSegments; s++)
                {
                    encoder.NextSegment();

                    int sample = s / oldPixelData.BytesAllocated;
                    int sabyte = s % oldPixelData.BytesAllocated;

                    int pos;
                    int offset;

                    if (newPixelData.PlanarConfiguration == 0)
                    {
                        pos    = sample * oldPixelData.BytesAllocated;
                        offset = numberOfSegments;
                    }
                    else
                    {
                        pos    = sample * oldPixelData.BytesAllocated * pixelCount;
                        offset = oldPixelData.BytesAllocated;
                    }

                    if (rleParams.ReverseByteOrder)
                    {
                        pos += sabyte;
                    }
                    else
                    {
                        pos += oldPixelData.BytesAllocated - sabyte - 1;
                    }

                    for (int p = 0; p < pixelCount; p++)
                    {
                        if (pos >= frameData.Length)
                        {
                            throw new DicomCodecException("");
                        }
                        encoder.Encode(frameData[pos]);
                        pos += offset;
                    }
                    encoder.Flush();
                }

                encoder.MakeEvenLength();

                newPixelData.AddFrame(encoder.GetBuffer());
            }
        }