I want to decompress a DICOM file using DCMTK like in this example http://support.dcmtk.org/docs/mod_dcmjpeg.html But my problem is that I don't want to load a file.
I have an array which inside there are the PixelData values Compressed. I have tried in this way but doesn't work.
DJDecoderRegistration::registerCodecs();
DJEncoderRegistration::registerCodecs();
DcmFileFormat fileformat;
DJ_RPLossless param_lossless;
DcmDataset *pDataset = fileformat.getDataset();
pDataset->chooseRepresentation(EXS_JPEGProcess14SV1, ¶m_lossless);
BYTE* pBufferImg = (BYTE*)pArray->ImgDicom.GetAt(0); //here I have my PixelData
//I put it into my dataset
pDataset->putAndInsertUint8Array(DCM_PixelData, pBufferImg, pArray->NumByteImg);
//decompress
OFCondition status = pDataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL); //status is OK
...
//add all the tags like Rows, Columuns, BitStored, etc
...
if (pDataset->canWriteXfer(EXS_LittleEndianExplicit))
{
fileformat.saveFile("test.dcm", EXS_LittleEndianExplicit);
}
DJDecoderRegistration::cleanup(); // deregister JPEG codecs
DJEncoderRegistration::cleanup();
The file test.dcm is created but I can't open it (free Dicom Viewr software crash) and the dimension is equal to the compressed file, so the decode procedure doesn't work... What is my error?
I have also tried:
DcmElement * dummyElem;
pDataset->findAndGetElement(DCM_PixelData, dummyElem);
Uint32 frameSize;
dummyElem->getUncompressedFrameSize(pDataset, frameSize);
BYTE* buf = new BYTE[frameSize];
OFString decompressedColorModel;
Uint32 startFragment = 0;
dummyElem->getUncompressedFrame(pDataset, 0, startFragment, buf, frameSize, decompressedColorModel);
pDataset->putAndInsertUint8Array(DCM_PixelData, (const Uint8*)buf, frameSize);
pDataset->removeAllButCurrentRepresentations();
//check if everything went well
if (pDataset->canWriteXfer(EXS_LittleEndianExplicit))
{
fileformat.saveFile("test.dcm", EXS_LittleEndianExplicit);
}
The getUncompressedFrame
return the error "Too many bytes requested"
If use frameSize - 1
instead of frameSize I have the error "Illegal call perhaps wrong parameter"... but why?!?
Illegal call
status – GiordiX