on DcmFileFormat::validateMetaInfo

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
gzhang
Posts: 50
Joined: Wed, 2015-09-02, 09:24

on DcmFileFormat::validateMetaInfo

#1 Post by gzhang »

Hi,
I am a bit confused with the DcmFileFormat::validateMetaInfo and DcmFileFormat::calcElementLength(). Using the following code, I load in a Dicom file, compress it, write it to a butter and then save the buffer through cstdio. Afterwards, when I try to read (dcmdjpeg.exe) the resulting file, it shows "I/O suspension or premature end of stream". However, if I comment out the validateMetaInfo() or save file by use of DcmFileFormat::saveFile(), everything seems fine. I guess the validateMetaInfo is somehow influencing the behavior of DcmFileFormat::calcElementLength(). How is that so?

Code: Select all

DcmFileFormat fileFormat;
fileFormat.loadFile("loadpath");

DJEncoderRegistration::registerCodecs();
DJ_RPLossless params;
fileFormat->chooseRepresentation(EXS_JPEGProcess14SV1, & params);

/* seems to create problems, regardless of the 2nd argument */
fileFormat->validateMetaInfo(EXS_JPEGProcess14SV1, ***);

if(fileFormat->canWriteXfer(EXS_JPEGProcess14SV1))
{
	unsigned len = fileFormat->calcElementLength(EXS_JPEGProcess14SV1, EET_UndefinedLength);
	char * buffer = new char[len];
	DcmOutputBufferStream  dcmOBStream(buffer, len);
	fileFormat->transferInit();
	OFCondition cond = fileFormat->write(dcmOBStream, EXS_JPEGProcess14SV1, EET_UndefinedLength, NULL);
	fileFormat->transferEnd();

	FILE * pFile;
	pFile = fopen("savepath", "wb");
	fwrite(buffer, sizeof(char), len, pFile)
}
DJEncoderRegistration::cleanup();        
If I would like to compress at the "DcmFileFormat" level instead of the "DcmDataset" level, what would be the correct way to perform "DcmFileFormat::chooseRepresentation()", "DcmFileFormat::calcElementLength()", and "DcmFileFormat::write()"? Thanks!

Jan Schlamelcher
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 318
Joined: Mon, 2014-03-03, 09:51
Location: Oldenburg, Germany

Re: on DcmFileFormat::validateMetaInfo

#2 Post by Jan Schlamelcher »

I'm not sure I understand your question entirely, but, you can ONLY compress the dataset, not the whole DICOM file. The DcmFileFormat consists of two components: the meta header and the actual file (data set). So I guess that what happens is that you "accidentally" also compress the meta header and not just the data set and the file therefore cannot be read since the meta header must always be uncompressed.

gzhang
Posts: 50
Joined: Wed, 2015-09-02, 09:24

Re: on DcmFileFormat::validateMetaInfo

#3 Post by gzhang »

Thanks for replying!

My problem was solved after correcting the 'length' given by DcmFileFormat::calcElementLength() with the one given by DcmOutputBufferStream::flushBuffer(). This, of course, is done after the writing finishes.

It seems the value given by DcmFileFormat::calcElementLength() may fall a few bits too large when associated with a change of transfer syntax. Luckily, 'too large' does not really hurts, as opposed to 'too small'. In the meanwhile, DcmFileFormat::validateMetaInfo() seems to be irrelevant because the meta header always gets to be somehow recreated and always says correctly in terms of the transfer syntax. I guess it may only be needed if people hope to update the UIDs.

In reply to your suggestion, yes, the meta header should always be in little-endian explicit.

Post Reply

Who is online

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