createValueFromTempFile with padding byte

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
theonlylawislove
Posts: 34
Joined: Thu, 2014-07-17, 09:07

createValueFromTempFile with padding byte

#1 Post by theonlylawislove »

I have PixelData that cannot have a padded byte trimmed, but I can add an empty byte (0).

Previously, when calling "createValueFromTempFile", I would modify the fileLen passed to it using "if (fileLen & 1) fileLen--"".

I cannot do this because this last byte is important. I essentially need to do "if (fileLen & 1) fileLen++", but when saving the DCM file, I get "invalid stream".

How do I add a padding byte to the DCM file without modifying the original file?

theonlylawislove
Posts: 34
Joined: Thu, 2014-07-17, 09:07

Re: createValueFromTempFile with padding byte

#2 Post by theonlylawislove »

I have a hack solution, but I really hope there is a better one.

I overrode DcmInputFileStream/DcmInputFileStreamFactory/DcmFileProducer to implement my own DcmFileProducer. All methods are default, but I changed the "read" of the DcmFileProducer.

Code: Select all

offile_off_t PaddedDcmFileProducer::read(void *buf, offile_off_t buflen)
{
	offile_off_t result = 0;
	if (status_.good() && file_.open() && buf && buflen)
	{
		result = file_.fread(buf, 1, OFstatic_cast(size_t, buflen));
	}

	if (result < buflen)
	{
		if (size_ & 1) result++;
		((BYTE*)buf)[result - 1] = 0;
	}

	return result;
}
Thes adds the "0" byte at the end of the video. Is there another (better) solution?

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: createValueFromTempFile with padding byte

#3 Post by J. Riesmeier »

This specific problem is listed as Feature #296 in our (still internal) issue tracker. I've also added a link to this thread and set the "target version" to "next release" (whenever this will be).

I wrote this posting in order to tell you that the current limitation of createValueFromTempFile() is known to us - of course, as it is documented on API level - and will be solved in a future release of the DCMTK.

theonlylawislove
Posts: 34
Joined: Thu, 2014-07-17, 09:07

Re: createValueFromTempFile with padding byte

#4 Post by theonlylawislove »

Just curious, has this been implemented?

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: createValueFromTempFile with padding byte

#5 Post by J. Riesmeier »

Unfortunately, not. See the now public issue tracker (sorry for the German): http://support.dcmtk.org/redmine/issues/296

theonlylawislove
Posts: 34
Joined: Thu, 2014-07-17, 09:07

Re: createValueFromTempFile with padding byte

#6 Post by theonlylawislove »

Would you guys accept a PR? This seems like a trivial fix.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: createValueFromTempFile with padding byte

#7 Post by J. Riesmeier »

We will definitely check your proposal. Please send a patch with the proposed changes by email to bugs/at/dcmtk/dot/org or submit a PR at GitHub.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest