Browse files

ensure frame buffers created by codecs have even length

  • Loading branch information...
1 parent 2c1e742 commit 116f930007ae13776021014cd42efe0e98d4f119 @rcd committed Jan 10, 2013
View
1 ChangeLog.md
@@ -1,5 +1,6 @@
#### v1.0.31
* Improved portability and fewer compiler warnings (Anders Gustafsson)
+* Ensure frame buffers created by codecs have even length
* Import DicomFileScanner from mDCM
* Miscellaneous improvements and fixes
View
2 DICOM [Native]/Dicom.Imaging.Codec.Jpeg.i
@@ -335,6 +335,7 @@ void JPEGCODEC::Encode(DicomPixelData^ oldPixelData, DicomPixelData^ newPixelDat
buffer = gcnew TempFileBuffer(MemoryBuffer->ToArray());
else
buffer = gcnew MemoryByteBuffer(MemoryBuffer->ToArray());
+ buffer = EvenLengthBuffer::Create(buffer);
newPixelData->AddFrame(buffer);
} finally {
MemoryBuffer = nullptr;
@@ -489,6 +490,7 @@ void JPEGCODEC::Decode(DicomPixelData^ oldPixelData, DicomPixelData^ newPixelDat
buffer = gcnew TempFileBuffer(frameArray->Data);
else
buffer = gcnew MemoryByteBuffer(frameArray->Data);
+ buffer = EvenLengthBuffer::Create(buffer);
if (newPixelData->PlanarConfiguration == PlanarConfiguration::Planar && newPixelData->SamplesPerPixel > 1) {
if (oldPixelData->SamplesPerPixel != 3 || oldPixelData->BitsStored > 8)
View
2 DICOM [Native]/Dicom.Imaging.Codec.Jpeg2000.cpp
@@ -210,6 +210,7 @@ void DicomJpeg2000NativeCodec::Encode(DicomPixelData^ oldPixelData, DicomPixelDa
buffer = gcnew TempFileBuffer(cbuf);
else
buffer = gcnew MemoryByteBuffer(cbuf);
+ buffer = EvenLengthBuffer::Create(buffer);
newPixelData->AddFrame(buffer);
} else
throw gcnew DicomCodecException("Unable to JPEG 2000 encode image");
@@ -351,6 +352,7 @@ void DicomJpeg2000NativeCodec::Decode(DicomPixelData^ oldPixelData, DicomPixelDa
buffer = gcnew TempFileBuffer(destArray->Data);
else
buffer = gcnew MemoryByteBuffer(destArray->Data);
+ buffer = EvenLengthBuffer::Create(buffer);
newPixelData->AddFrame(buffer);
}
finally {
View
2 DICOM [Native]/Dicom.Imaging.Codec.JpegLS.cpp
@@ -100,6 +100,7 @@ void DicomJpegLsNativeCodec::Encode(DicomPixelData^ oldPixelData, DicomPixelData
buffer = gcnew TempFileBuffer(jpegData);
else
buffer = gcnew MemoryByteBuffer(jpegData);
+ buffer = EvenLengthBuffer::Create(buffer);
newPixelData->AddFrame(buffer);
}
}
@@ -122,6 +123,7 @@ void DicomJpegLsNativeCodec::Decode(DicomPixelData^ oldPixelData, DicomPixelData
buffer = gcnew TempFileBuffer(frameData);
else
buffer = gcnew MemoryByteBuffer(frameData);
+ buffer = EvenLengthBuffer::Create(buffer);
newPixelData->AddFrame(buffer);
}
}
View
2 DICOM [Native]/Dicom.Imaging.Codec.Rle.cpp
@@ -213,6 +213,7 @@ void DicomRleNativeCodec::Encode(DicomPixelData^ oldPixelData, DicomPixelData^ n
buffer = gcnew TempFileBuffer(data);
else
buffer = gcnew MemoryByteBuffer(data);
+ buffer = EvenLengthBuffer::Create(buffer);
newPixelData->AddFrame(buffer);
}
}
@@ -363,6 +364,7 @@ void DicomRleNativeCodec::Decode(DicomPixelData^ oldPixelData, DicomPixelData^ n
buffer = gcnew TempFileBuffer(frameData);
else
buffer = gcnew MemoryByteBuffer(frameData);
+ buffer = EvenLengthBuffer::Create(buffer);
newPixelData->AddFrame(buffer);
}
}
View
4 DICOM/DICOM.csproj
@@ -67,9 +67,11 @@
<Compile Include="DicomDictionary.cs" />
<Compile Include="DicomDictionaryEntry.cs" />
<Compile Include="DicomDictionaryReader.cs" />
+ <Compile Include="DicomFileScanner.cs" />
<Compile Include="DicomMatchRules.cs" />
<Compile Include="DicomTransformRules.cs" />
<Compile Include="DicomUIDGenerator.cs" />
+ <Compile Include="IO\Buffer\EvenLengthBuffer.cs" />
<Compile Include="Media\DicomDirectory.cs" />
<Compile Include="Media\DicomDirectoryRecord.cs" />
<Compile Include="Media\DicomDirectoryRecordCollection.cs" />
@@ -264,7 +266,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_BuildVersioningStyle="None.None.Increment.YearDayOfYear" BuildVersion_UseGlobalSettings="True" />
+ <UserProperties BuildVersion_UseGlobalSettings="True" BuildVersion_BuildVersioningStyle="None.None.Increment.YearDayOfYear" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
View
45 DICOM/IO/Buffer/EvenLengthBuffer.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Dicom.IO.Buffer {
+ public class EvenLengthBuffer : IByteBuffer {
+ private EvenLengthBuffer(IByteBuffer buffer) {
+ Buffer = buffer;
+ }
+
+ public IByteBuffer Buffer {
+ get;
+ private set;
+ }
+
+ public bool IsMemory {
+ get { return true; }
+ }
+
+ public uint Size {
+ get { return Buffer.Size + 1; }
+ }
+
+ public byte[] Data {
+ get {
+ byte[] data = new byte[Size];
+ System.Buffer.BlockCopy(Buffer.Data, 0, data, 0, (int)Buffer.Size);
+ return data;
+ }
+ }
+
+ public byte[] GetByteRange(int offset, int count) {
+ byte[] data = new byte[count];
+ System.Buffer.BlockCopy(Buffer.Data, offset, data, 0, Math.Min((int)Buffer.Size, count));
+ return data;
+ }
+
+ public static IByteBuffer Create(IByteBuffer buffer) {
+ if ((buffer.Size & 1) == 1)
+ return new EvenLengthBuffer(buffer);
+ return buffer;
+ }
+ }
+}

0 comments on commit 116f930

Please sign in to comment.