public void DecodeFrame(int frame, DicomCompressedPixelData oldPixelData, DicomUncompressedPixelData newPixelData, DicomCodecParameters parameters) { DicomRleCodecParameters rleParams = parameters as DicomRleCodecParameters ?? new DicomRleCodecParameters(); int pixelCount = oldPixelData.ImageWidth * oldPixelData.ImageHeight; int numberOfSegments = oldPixelData.BytesAllocated * oldPixelData.SamplesPerPixel; int segmentLength = (pixelCount & 1) == 1 ? pixelCount + 1 : pixelCount; byte[] segment = new byte[segmentLength]; byte[] frameData = new byte[oldPixelData.UncompressedFrameSize]; IList <DicomFragment> rleData = oldPixelData.GetFrameFragments(frame); RLEDecoder decoder = new RLEDecoder(rleData); if (decoder.NumberOfSegments != numberOfSegments) { throw new DicomCodecException("Unexpected number of RLE segments!"); } for (int s = 0; s < numberOfSegments; s++) { decoder.DecodeSegment(s, segment); int sample = s / oldPixelData.BytesAllocated; int sabyte = s % oldPixelData.BytesAllocated; int pos; int offset; if (newPixelData.PlanarConfiguration == 0) { pos = sample * oldPixelData.BytesAllocated; offset = oldPixelData.SamplesPerPixel * oldPixelData.BytesAllocated; } 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++) { frameData[pos] = segment[p]; pos += offset; } } newPixelData.AppendFrame(frameData); }
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); } }
public override void Decode( DicomPixelData oldPixelData, DicomPixelData newPixelData, DicomCodecParams parameters) { for (var frame = 0; frame < oldPixelData.NumberOfFrames; frame++) { var rleData = oldPixelData.GetFrame(frame); // Create new frame data of even length var frameSize = newPixelData.UncompressedFrameSize; if ((frameSize & 1) == 1) { ++frameSize; } var frameData = new MemoryByteBuffer(new byte[frameSize]); var pixelCount = oldPixelData.Width * oldPixelData.Height; var numberOfSegments = oldPixelData.BytesAllocated * oldPixelData.SamplesPerPixel; var decoder = new RLEDecoder(rleData); if (decoder.NumberOfSegments != numberOfSegments) { throw new InvalidOperationException("Unexpected number of RLE segments!"); } for (var s = 0; s < numberOfSegments; s++) { var sample = s / newPixelData.BytesAllocated; var sabyte = s % newPixelData.BytesAllocated; int pos, offset; if (newPixelData.PlanarConfiguration == PlanarConfiguration.Interleaved) { pos = sample * newPixelData.BytesAllocated; offset = newPixelData.SamplesPerPixel * newPixelData.BytesAllocated; } else { pos = sample * newPixelData.BytesAllocated * pixelCount; offset = newPixelData.BytesAllocated; } pos += newPixelData.BytesAllocated - sabyte - 1; decoder.DecodeSegment(s, frameData, pos, offset); } newPixelData.AddFrame(frameData); } }
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); } }
public void DecodeFrame(int frame, DicomCompressedPixelData oldPixelData, DicomUncompressedPixelData newPixelData, DicomCodecParameters parameters) { DicomRleCodecParameters rleParams = parameters as DicomRleCodecParameters; if (rleParams == null) throw new DicomCodecException("Unexpected RLE Codec parameters"); int pixelCount = oldPixelData.ImageWidth * oldPixelData.ImageHeight; int numberOfSegments = oldPixelData.BytesAllocated * oldPixelData.SamplesPerPixel; int segmentLength = (pixelCount & 1) == 1 ? pixelCount + 1 : pixelCount; byte[] segment = new byte[segmentLength]; byte[] frameData = new byte[oldPixelData.UncompressedFrameSize]; IList<DicomFragment> rleData = oldPixelData.GetFrameFragments(frame); RLEDecoder decoder = new RLEDecoder(rleData); if (decoder.NumberOfSegments != numberOfSegments) throw new DicomCodecException("Unexpected number of RLE segments!"); for (int s = 0; s < numberOfSegments; s++) { decoder.DecodeSegment(s, segment); int sample = s / oldPixelData.BytesAllocated; int sabyte = s % oldPixelData.BytesAllocated; int pos; int offset; if (newPixelData.PlanarConfiguration == 0) { pos = sample * oldPixelData.BytesAllocated; offset = oldPixelData.SamplesPerPixel * oldPixelData.BytesAllocated; } 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++) { frameData[pos] = segment[p]; pos += offset; } } newPixelData.AppendFrame(frameData); }