JNI wrapper over dcm2pnm: where does dcm2pnm.cc delete the DcmFileFormat instance?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
mattywix
Posts: 15
Joined: Wed, 2011-03-30, 15:31

JNI wrapper over dcm2pnm: where does dcm2pnm.cc delete the DcmFileFormat instance?

#1 Post by mattywix »

I have wrapped some of the apps with JNI so I can invoke from Java.
One of the methods I wrapped is main in dcm2pnm.
I then changed it to stream in memory instead of reading/writing files.

However I cannot see where the DcmFileFormat instance is deleted.
I tried to add a delete line but it crashed so I assume something had already deleted it, but what?

Does the following
delete di;
delete disp;
Somehow also delete the DcmFileFormat object?

Note I now have the following code to pass in a buffer instead of file:

Code: Select all

	DcmFileFormat *dfile = new DcmFileFormat();

	DcmInputBufferStream dcmInputBufferStream;
	dcmInputBufferStream.setBuffer(inputbuf.inputbuffer, inputbuf.length);
	dcmInputBufferStream.setEos();

	dfile->transferInit();

	OFCondition cond = dfile->read(dcmInputBufferStream, opt_transferSyntax,
			EGL_withoutGL, DCM_MaxReadLength);

	dfile->transferEnd();
Please advise how to safely delete this DcmFileFormat object and any copy it might make of the buffer data passed in.

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#2 Post by Jörg Riesmeier »

First of all, I don't think that wrapping "dcm2pnm" is a good idea. Since the main functionality is contained in the DicomImage class, why don't you just wrap this class?

Regarding your questing: Using the flag "CIF_TakeOverExternalDataset", the DicomImage instance takes over the responsibilty for deleting the dataset/fileformat passed to the constructor.

mattywix
Posts: 15
Joined: Wed, 2011-03-30, 15:31

#3 Post by mattywix »

Thanks for the prompt reply.

I wrapped the app instead of the class as it was an easy way to work out what was required to invoke the dcm2pnm conversion and what options might be set.

I have approached the dcm2xml in the same way.

Then I started stripping back what I didn't need.

Without a thorough knowledge of the DicomImage class lifecycle, this seemed to be an easier approach.

However I did have to write a new IJG destination manager and a new DiJPEGPlugin to call that new destination manager, and that meant casting my buffer object to (FILE *) to get IJG to hand it through to my destination manager when I invoke write

Code: Select all

result = di->writePluginFormat(&plugin, (FILE*)outputBuffer, frame);
In my case outputBuffer is a pointer to a C struct containing my output buffer details.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest