Registering Custom Codec with DicomObjects.NET

Contents

DicomObjects.NET (only)

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(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 : DicomObjects.DicomCodecs.IDecompressor
 {    
	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;
	}

	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();
	}
 }

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;
	}

	int ICompressor.MaximumBits
	{
	  get
	  {
		throw new NotImplementedException();
	  }
	}

	bool ICompressor.NeedsPlanarConfigTransform
	{
	  get
	  {
		throw new NotImplementedException();
	  }
	}

	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)
	{
	  throw new NotImplementedException();
	}
 }


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.



We use cookies to give you the best possible experience on our website. By continuing to use this website, you agree with our use of cookies. for more information please click HERE