Registering Custom Codec with DicomObjects.NET
Contents
- Create new Custom CodecFactory class
- Implement DicomObjects.DicomCodecs.IDecompressor
- Implement DicomObjects.DicomCodecs.ICompressor interface
- Registering your CodecFactory with DicomObjects.NET
DicomObjects.NET (only)
Create new Custom CodecFactory class
You need to create a new Class that derives from DicomObjects.DicomCodecs.CodecFactory. See the sample code below:
class MyCodecFactory : CodecFactory
{
static string TransferSyntax = "1.2.3.4.5";
public override bool CheckStart(Stream stream, 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[] SupportedTransferSyntaxes(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 : IDecompressor
{
public void Decompress(DicomObjects.DicomCodecs.DecompressionArguments args)
{
// Your own Decompression code here
}
public string DecompressedPhotmetricInterpretation(DicomDataSet parent)
{
return parent[Keyword.PhotometricInterpretation].Value.ToString();
}
public bool NeedsPlanarConfigTransform
{
get { return false; }
}
public object LockObject()
{
return this;
}
public PixelRequest BestRequest(float Zoom, RequestType Sync, DicomDataSet parent, int Frame)
{
throw new NotImplementedException();
}
public DecompressStatus DecompressState(PixelRequest Request)
{
throw new NotImplementedException();
}
public ProgressiveStatus DownloadStatus(PixelRequest Request)
{
throw new NotImplementedException();
}
public int CalculatedFrameCount()
{
throw new NotImplementedException();
}
public string DecompressedPhotometricInterpretation(DicomDataSet parent)
{
throw new NotImplementedException();
}
}
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;
}
public object Quality(string TransferSyntax, Dictionary<string, object> qmap, DicomDataSet dataset)
{
return null;
}
}
Registering your CodecFactory with DicomObjects.NET
Call the registerCodec method at the start of your application:
DicomObjects.DicomCodecs.CodecGlobal.RegisterCodec(new MyCodecFactory ());
You can download our sample project for registering and using a CharLS custom codec to handle Jpeg-LS (1.2.840.10008.1.2.4.80 and 1.2.840.10008.1.2.4.81) transfer syntaxes.