I am trying to compressed byte sequence in DICOM file. this code is working (still i need to refine). i am inserting DcmPixelItem in DcmPixelSequence. after dicom image is saved, i need to clean up heap objects. i am removing from pixelsequence but when i am try to delete DcmPixelItem objects. it crashing while calling DcmList::deleteAllElements(). there is not list available because of i delete it . is there something i am not doing correct in this code or what is right way delete DcmPixelItem and DcmPixelData objects. Is tehre any sequence i need to follow while deleting.
Code: Select all
auto pixelSequence = new DcmPixelSequence(DcmTag(DCM_PixelData, EVR_OB));
// add the table offset
auto offsetTable = new DcmPixelItem(DcmTag(DCM_Item, EVR_OB));
Status = pixelSequence->insert(offsetTable);
if (Status.bad())
{
return false;
}
auto pixelItem = new DcmPixelItem(DcmTag(DCM_Item, EVR_OB));
ptrdiff_t size;
ReadAllBytes(m_pVideoFileName.c_str(), &size);
if (m_pixels != NULL)
{
pixelItem->putUint8Array(OFreinterpret_cast(Uint8*, m_pixels), size);
Status = pixelSequence->insert(pixelItem);
if (Status.bad())
{
return false;
}
}
else
{
return false;
}
auto pixelData = new DcmPixelData(DCM_PixelData);
pixelData->putOriginalRepresentation(EXS_MPEG4HighProfileLevel4_1, NULL, pixelSequence);
Status = pDataSet->insert(pixelData, OFTrue);
if (Status.good())
{
pFileFormat.saveFile(m_pDicomFileName.c_str(), EXS_MPEG4HighProfileLevel4_1, EET_UndefinedLength, EGL_recalcGL);
}
else
{
return false;
}
if (pixelSequence != NULL)
{
pixelSequence->remove(pixelItem);
pixelSequence->remove(offsetTable);
}
Ashish