DCMTK and Orthanc: Manipulating DICOM images in-memory

Hi!

Question: given I’ve got a DcmFileFormat instance I’ve fiddled with, how do I write it to a memory buffer?

Specifically, what I want to achieve is real-time anonimisation of instances when downloading study archives through “/studies/[study-id]/archive”. I’d like the resulting archive’s images to be stripped of certain tags, namely private tags. But not all of them.

I know there’s the DcmOutputBufferStream but I’m getting an error message that reads like so: I/O suspension or premature end of stream. I’m pretty new to DCMTK and I thought I only had to do this:

dcmFileFormat.transferInit();

E_TransferSyntax transferSyntax = metaInfo->getOriginalXfer();
E_EncodingType encodingType = EET_ExplicitLength;
newContentSize = dcmFileFormat.calcElementLength( transferSyntax, encodingType );
newContentPtr = (char*) malloc( sizeof( char ) * ( newContentSize ) );
DcmOutputBufferStream outputStream( newContentPtr, newContentSize );

Log( “Output buffer created.” );

OFCondition writeStatus = dcmFileFormat.write( outputStream, transferSyntax, encodingType, NULL );
dcmFileFormat.transferEnd();

The dcmFileFormat.write fails with the aforementioned error.

To achieve that, I’ve created a DicomImageFilter callback that’s triggered in the OrthancRestAchive during the visitor’s execution. So, when Orthanc is about to write the instance file into the zip, it calls a callback like this one:

ORTHANC_PLUGINS_API OrthancPluginErrorCode OrthancOverseer_FilterDicomTags(
const char* instanceId,
const char* oldContentPtr,
size_t oldContentSize,
char** newContentPtrPtr,
size_t* newContentSizePtr
)

PS: I’m most certainly changing the char*/size_t pairs into OrthancPluginMemoryBuffer as it should have been done from the start, please don’t mind that.

Point being I should be able to mess with the file and return a new version of it.

Now I can read the file into a DcmFileFormat through a DcmInputBufferStream but I’m missing something in the write process. And this is why I’m calling for help.

Thanks in advance! =)

Hello,

This question is related to DCMTK, not to Orthanc.

Please use the “OrthancPluginCreateDicom()” primitive in the Orthanc plugin SDK that can be used to create DICOM images:
http://sdk.orthanc-server.com/group__Toolbox.html#ga88726ae4c968c1151a01a8a770d7b90e

Sébastien-