Allow cancelling/aborting image encoding (ImageChangeTransferSyntax::Change)
Cross-platform DICOM implementation
Brought to you by:
malat
Using compression for a large stack of slices can take a significant ammount of time. To allow the end user of a GDCM-based application to cancel saving a DICOM image stack there needs to be a way in the ImageChangeTransferSyntax::Change call stack to abort the encoding process somehow. For example, a crude implementation to support JPEG encoding:
std::atomic<bool> gdcm::g_JPEGCodecAbort{false};
// ...
bool JPEGCodec::Code(DataElement const &in, DataElement &out)
{
// ...
for(unsigned int dim = 0; dim < dims[2]; ++dim)
{
std::stringstream os;
const char *p = input + dim * image_len;
bool r = Internal->InternalCode(p, image_len, os);
if( !r || g_JPEGCodecAbort.load() )
{
return false;
}
// ...
}</bool>
Corresponding ITK issue that is blocked by this: https://github.com/InsightSoftwareConsortium/ITK/issues/560