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