Registering Custom Codec with DicomObjects.NET
Contents
- 1 Create new CodecFactory class
- 2 Implement DicomObjects.DicomCodecs.IDecompressor
- 3 Implement DicomObjects.DicomCodecs.ICompressor interface
- 4 Registering your CodecFactory with DicomObjects.NET
Create new CodecFactory class
You need to create a new Class that derives from DicomObjects.DicomCodecs.CodecFactory. See the sample code below:
public class MyCodecFactory : DicomObjects.DicomCodecs.CodecFactory
{
public override bool CheckStart(byte[] data, string TransferSyntax)
{
return true;
}
public override DicomObjects.DicomCodecs.ICompressor Compressor(string TransferSyntax)
{
return new MyEncoder();
}
public override DicomObjects.DicomCodecs.IDecompressor Decompressor(string TransferSyntax, System.IO.Stream Data, DicomDataSet DataSet, int Frame)
{
return new MyDecoder();
}
public override DicomObjects.DicomCodecs.IExporter Exporter(string Format)
{
throw new NotImplementedException();
}
public override DicomObjects.DicomCodecs.IImporter Importer(string Format)
{
throw new NotImplementedException();
}
public override string[] TransferSyntaxes(DicomObjects.DicomCodecs.CodecOperation Operation)
{
A list of Transfer Syntaxes your own codec will support
return new String[] { "1.2.840.10008.1.2.4.80" };
}
}
Implement DicomObjects.DicomCodecs.IDecompressor
internal class MyDecoder : DicomObjects.DicomCodecs.IDecompressor
{
public List<DicomObjects.DicomCodecs.PixelResolution> AvailableResolutions(DicomDataSet parent)
{
List<DicomObjects.DicomCodecs.PixelResolution> result = new List<DicomObjects.DicomCodecs.PixelResolution>();
result.Add(new DicomObjects.DicomCodecs.PixelResolution(parent));
return result;
}
public void Decompress(DicomObjects.DicomCodecs.DecompressionArguments args)
{
Your own Decompression code here
}
public string DecompressedPhotmetricInterpretation(DicomDataSet parent)
{
return parent[0x0028, 0x0004].ToString();
}
public bool NeedsPlanarConfigTransform
{
get { return false; }
}
public object LockObject()
{
return this;
}
}
Implement DicomObjects.DicomCodecs.ICompressor interface
internal class MyEncoder : DicomObjects.DicomCodecs.ICompressor
{
public void Compress(DicomObjects.DicomCodecs.CompressionArguments args)
{
Your own Compression code here
}
public int MaximumBits
{
return 16;
}
public bool NeedsPlanarConfigTransform
{
return false;
}
public void PrepareFunction(DicomObjects.DicomCodecs.ModificationArguments ModificationArguments)
{
Make any changes to the DicomDataSet which are required for compatibility with the compressed data, e.g. the BitDepth/Photometric Interpretation may need altering
}
public object LockObject()
{
return this;
}
}
Registering your CodecFactory with DicomObjects.NET
Call the registerCodec method at the start of your application:
DicomObjects.DicomCodecs.CodecGlobal.RegisterCodec(new MyCodecFactory ()); A complete working example (with a dummy compression/decompression) can be downloaded from HERE.
Â
Reviewed: