diff --git a/dcmdata/include/dcmtk/dcmdata/dccodec.h b/dcmdata/include/dcmtk/dcmdata/dccodec.h index 60b5de50f6..5d99148365 100644 --- a/dcmdata/include/dcmtk/dcmdata/dccodec.h +++ b/dcmdata/include/dcmtk/dcmdata/dccodec.h @@ -1,6 +1,6 @@ /* * - * Copyright (C) 1997-2018, OFFIS e.V. + * Copyright (C) 1997-2020, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by @@ -92,6 +92,10 @@ class DCMTK_DCMDATA_EXPORT DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition decode( @@ -99,7 +103,8 @@ class DCMTK_DCMDATA_EXPORT DcmCodec DcmPixelSequence * pixSeq, DcmPolymorphOBOW& uncompressedPixelData, const DcmCodecParameter * cp, - const DcmStack& objStack) const = 0; + const DcmStack & objStack, + OFBool& removeOldRep) const = 0; /** decompresses a single frame from the given pixel sequence and * stores the result in the given buffer. @@ -149,6 +154,10 @@ class DCMTK_DCMDATA_EXPORT DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -157,7 +166,8 @@ class DCMTK_DCMDATA_EXPORT DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & pixSeq, const DcmCodecParameter *cp, - DcmStack & objStack) const = 0; + DcmStack & objStack, + OFBool& removeOldRep) const = 0; /** transcodes (re-compresses) the given compressed DICOM image and stores * the result in the given toPixSeq element. @@ -171,6 +181,10 @@ class DCMTK_DCMDATA_EXPORT DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -180,7 +194,8 @@ class DCMTK_DCMDATA_EXPORT DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & toPixSeq, const DcmCodecParameter * cp, - DcmStack & objStack) const = 0; + DcmStack & objStack, + OFBool& removeOldRep) const = 0; /** checks if this codec is able to convert from the * given current transfer syntax to the given new @@ -345,6 +360,10 @@ class DCMTK_DCMDATA_EXPORT DcmCodecList * @param uncompressedPixelData uncompressed pixel data stored in this element * @param pixelStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ static OFCondition decode( @@ -352,7 +371,8 @@ class DCMTK_DCMDATA_EXPORT DcmCodecList const DcmRepresentationParameter * fromParam, DcmPixelSequence * fromPixSeq, DcmPolymorphOBOW& uncompressedPixelData, - DcmStack & pixelStack); + DcmStack & pixelStack, + OFBool& removeOldRep); /** looks for a codec that is able to decode from the given transfer syntax * and calls the decodeFrame() method of the codec. A read lock on the list of @@ -405,6 +425,10 @@ class DCMTK_DCMDATA_EXPORT DcmCodecList * allocated on heap) returned in this parameter upon success. * @param pixelStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ static OFCondition encode( @@ -414,7 +438,8 @@ class DCMTK_DCMDATA_EXPORT DcmCodecList const E_TransferSyntax toRepType, const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & pixSeq, - DcmStack & pixelStack); + DcmStack & pixelStack, + OFBool& removeOldRep); /** looks for a codec that is able to transcode (re-compresses) * from the given transfer syntax to the given transfer syntax @@ -431,6 +456,10 @@ class DCMTK_DCMDATA_EXPORT DcmCodecList * allocated on heap) returned in this parameter upon success. * @param pixelStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ static OFCondition encode( @@ -440,7 +469,8 @@ class DCMTK_DCMDATA_EXPORT DcmCodecList const E_TransferSyntax toRepType, const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & toPixSeq, - DcmStack & pixelStack); + DcmStack & pixelStack, + OFBool& removeOldRep); /** looks for a codec that claims to be able to convert * between the given transfer syntaxes. diff --git a/dcmdata/include/dcmtk/dcmdata/dcrleccd.h b/dcmdata/include/dcmtk/dcmdata/dcrleccd.h index 435c7bfb48..77155b3238 100644 --- a/dcmdata/include/dcmtk/dcmdata/dcrleccd.h +++ b/dcmdata/include/dcmtk/dcmdata/dcrleccd.h @@ -47,6 +47,10 @@ class DCMTK_DCMDATA_EXPORT DcmRLECodecDecoder: public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition decode( @@ -54,7 +58,8 @@ class DCMTK_DCMDATA_EXPORT DcmRLECodecDecoder: public DcmCodec DcmPixelSequence * pixSeq, DcmPolymorphOBOW& uncompressedPixelData, const DcmCodecParameter * cp, - const DcmStack& objStack) const; + const DcmStack & objStack, + OFBool& removeOldRep) const; /** decompresses a single frame from the given pixel sequence and * stores the result in the given buffer. @@ -104,6 +109,10 @@ class DCMTK_DCMDATA_EXPORT DcmRLECodecDecoder: public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -112,7 +121,8 @@ class DCMTK_DCMDATA_EXPORT DcmRLECodecDecoder: public DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & pixSeq, const DcmCodecParameter *cp, - DcmStack & objStack) const; + DcmStack & objStack, + OFBool& removeOldRep) const; /** transcodes (re-compresses) the given compressed DICOM image and stores * the result in the given toPixSeq element. @@ -126,6 +136,10 @@ class DCMTK_DCMDATA_EXPORT DcmRLECodecDecoder: public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -135,7 +149,8 @@ class DCMTK_DCMDATA_EXPORT DcmRLECodecDecoder: public DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & toPixSeq, const DcmCodecParameter * cp, - DcmStack & objStack) const; + DcmStack & objStack, + OFBool& removeOldRep) const; /** checks if this codec is able to convert from the * given current transfer syntax to the given new diff --git a/dcmdata/include/dcmtk/dcmdata/dcrlecce.h b/dcmdata/include/dcmtk/dcmdata/dcrlecce.h index 2b98324012..4e36cea1e3 100644 --- a/dcmdata/include/dcmtk/dcmdata/dcrlecce.h +++ b/dcmdata/include/dcmtk/dcmdata/dcrlecce.h @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2002-2011, OFFIS e.V. + * Copyright (C) 2002-2020, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by @@ -49,6 +49,10 @@ class DCMTK_DCMDATA_EXPORT DcmRLECodecEncoder: public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition decode( @@ -56,7 +60,8 @@ class DCMTK_DCMDATA_EXPORT DcmRLECodecEncoder: public DcmCodec DcmPixelSequence * pixSeq, DcmPolymorphOBOW& uncompressedPixelData, const DcmCodecParameter * cp, - const DcmStack& objStack) const; + const DcmStack & objStack, + OFBool& removeOldRep) const; /** decompresses a single frame from the given pixel sequence and * stores the result in the given buffer. @@ -106,6 +111,10 @@ class DCMTK_DCMDATA_EXPORT DcmRLECodecEncoder: public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -114,7 +123,8 @@ class DCMTK_DCMDATA_EXPORT DcmRLECodecEncoder: public DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & pixSeq, const DcmCodecParameter *cp, - DcmStack & objStack) const; + DcmStack & objStack, + OFBool& removeOldRep) const; /** transcodes (re-compresses) the given compressed DICOM image and stores * the result in the given toPixSeq element. @@ -128,6 +138,10 @@ class DCMTK_DCMDATA_EXPORT DcmRLECodecEncoder: public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -137,7 +151,8 @@ class DCMTK_DCMDATA_EXPORT DcmRLECodecEncoder: public DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & toPixSeq, const DcmCodecParameter * cp, - DcmStack & objStack) const; + DcmStack & objStack, + OFBool& removeOldRep) const; /** checks if this codec is able to convert from the * given current transfer syntax to the given new diff --git a/dcmdata/libsrc/dccodec.cc b/dcmdata/libsrc/dccodec.cc index bb32f38853..52d6a2a70f 100644 --- a/dcmdata/libsrc/dccodec.cc +++ b/dcmdata/libsrc/dccodec.cc @@ -1,6 +1,6 @@ /* * - * Copyright (C) 1997-2016, OFFIS e.V. + * Copyright (C) 1997-2020, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by @@ -434,7 +434,8 @@ OFCondition DcmCodecList::decode( const DcmRepresentationParameter * fromParam, DcmPixelSequence * fromPixSeq, DcmPolymorphOBOW& uncompressedPixelData, - DcmStack & pixelStack) + DcmStack & pixelStack, + OFBool& removeOldRep) { #ifdef WITH_THREADS if (! codecLock.initialized()) return EC_IllegalCall; // should never happen @@ -454,7 +455,7 @@ OFCondition DcmCodecList::decode( { if ((*first)->codec->canChangeCoding(fromXfer, EXS_LittleEndianExplicit)) { - result = (*first)->codec->decode(fromParam, fromPixSeq, uncompressedPixelData, (*first)->codecParameter, pixelStack); + result = (*first)->codec->decode(fromParam, fromPixSeq, uncompressedPixelData, (*first)->codecParameter, pixelStack, removeOldRep); first = last; } else ++first; } @@ -513,7 +514,8 @@ OFCondition DcmCodecList::encode( const E_TransferSyntax toRepType, const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & toPixSeq, - DcmStack & pixelStack) + DcmStack & pixelStack, + OFBool& removeOldRep) { toPixSeq = NULL; #ifdef WITH_THREADS @@ -535,7 +537,7 @@ OFCondition DcmCodecList::encode( { if (!toRepParam) toRepParam = (*first)->defaultRepParam; result = (*first)->codec->encode(fromRepType, fromParam, fromPixSeq, - toRepParam, toPixSeq, (*first)->codecParameter, pixelStack); + toRepParam, toPixSeq, (*first)->codecParameter, pixelStack, removeOldRep); first = last; } else ++first; } @@ -553,7 +555,8 @@ OFCondition DcmCodecList::encode( const E_TransferSyntax toRepType, const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & toPixSeq, - DcmStack & pixelStack) + DcmStack & pixelStack, + OFBool& removeOldRep) { toPixSeq = NULL; #ifdef WITH_THREADS @@ -575,7 +578,7 @@ OFCondition DcmCodecList::encode( { if (!toRepParam) toRepParam = (*first)->defaultRepParam; result = (*first)->codec->encode(pixelData, length, toRepParam, toPixSeq, - (*first)->codecParameter, pixelStack); + (*first)->codecParameter, pixelStack, removeOldRep); first = last; } else ++first; } diff --git a/dcmdata/libsrc/dcpixel.cc b/dcmdata/libsrc/dcpixel.cc index 16616352c8..48c29e038c 100644 --- a/dcmdata/libsrc/dcpixel.cc +++ b/dcmdata/libsrc/dcpixel.cc @@ -1,6 +1,6 @@ /* * - * Copyright (C) 1997-2019, OFFIS e.V. + * Copyright (C) 1997-2020, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by @@ -442,13 +442,20 @@ DcmPixelData::decode( DcmStack & pixelStack) { if (existUnencapsulated) return EC_Normal; - OFCondition l_error = DcmCodecList::decode(fromType, fromParam, fromPixSeq, *this, pixelStack); + OFBool removeOldPixelRepresentation = OFFalse; + OFCondition l_error = DcmCodecList::decode(fromType, fromParam, fromPixSeq, *this, pixelStack, removeOldPixelRepresentation); if (l_error.good()) { existUnencapsulated = OFTrue; current = repListEnd; setVR(EVR_OW); recalcVR(); + + // the codec has indicated that the image pixel module has been modified + // in a way that may affect the validity of the old representation of pixel data. + // Thus, we cannot just switch back to the old representation. + // Thus, remove old representation(s). + if (removeOldPixelRepresentation) removeAllButCurrentRepresentations(); } else { @@ -473,10 +480,11 @@ DcmPixelData::encode( if (toType.isEncapsulated()) { DcmPixelSequence * toPixSeq = NULL; + OFBool removeOldPixelRepresentation = OFFalse; if (fromType.isEncapsulated()) { l_error = DcmCodecList::encode(fromType.getXfer(), fromParam, fromPixSeq, - toType.getXfer(), toParam, toPixSeq, pixelStack); + toType.getXfer(), toParam, toPixSeq, pixelStack, removeOldPixelRepresentation); } else { @@ -486,7 +494,7 @@ DcmPixelData::encode( if (l_error == EC_Normal) { l_error = DcmCodecList::encode(fromType.getXfer(), pixelData, length, - toType.getXfer(), toParam, toPixSeq, pixelStack); + toType.getXfer(), toParam, toPixSeq, pixelStack, removeOldPixelRepresentation); } } @@ -495,6 +503,11 @@ DcmPixelData::encode( current = insertRepresentationEntry( new DcmRepresentationEntry(toType.getXfer(), toParam, toPixSeq)); recalcVR(); + // the codec has indicated that the image pixel module has been modified + // in a way that may affect the validity of the old representation of pixel data. + // Thus, we cannot just switch back to the old representation, but have + // to actually decode in this case. Thus, remove old representation(s). + if (removeOldPixelRepresentation) removeAllButCurrentRepresentations(); } else delete toPixSeq; // if it was possible to convert one encapsulated syntax into diff --git a/dcmdata/libsrc/dcrleccd.cc b/dcmdata/libsrc/dcrleccd.cc index 61fde6beb8..ffdd141162 100644 --- a/dcmdata/libsrc/dcrleccd.cc +++ b/dcmdata/libsrc/dcrleccd.cc @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2002-2019, OFFIS e.V. + * Copyright (C) 2002-2020, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by @@ -63,7 +63,8 @@ OFCondition DcmRLECodecDecoder::decode( DcmPixelSequence * pixSeq, DcmPolymorphOBOW& uncompressedPixelData, const DcmCodecParameter * cp, - const DcmStack& objStack) const + const DcmStack& objStack, + OFBool& /* removeOldRep */) const { OFCondition result = EC_Normal; @@ -704,7 +705,8 @@ OFCondition DcmRLECodecDecoder::encode( const DcmRepresentationParameter * /* toRepParam */, DcmPixelSequence * & /* pixSeq */, const DcmCodecParameter * /* cp */, - DcmStack & /* objStack */) const + DcmStack & /* objStack */, + OFBool& /* removeOldRep */) const { // we are a decoder only return EC_IllegalCall; @@ -718,7 +720,8 @@ OFCondition DcmRLECodecDecoder::encode( const DcmRepresentationParameter * /* toRepParam */, DcmPixelSequence * & /* toPixSeq */, const DcmCodecParameter * /* cp */, - DcmStack & /* objStack */) const + DcmStack & /* objStack */, + OFBool& /* removeOldRep */) const { // we don't support re-coding for now. return EC_IllegalCall; diff --git a/dcmdata/libsrc/dcrlecce.cc b/dcmdata/libsrc/dcrlecce.cc index 6d54eff030..30a5a64c85 100644 --- a/dcmdata/libsrc/dcrlecce.cc +++ b/dcmdata/libsrc/dcrlecce.cc @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2002-2016, OFFIS e.V. + * Copyright (C) 2002-2020, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by @@ -71,7 +71,8 @@ OFCondition DcmRLECodecEncoder::decode( DcmPixelSequence * /* pixSeq */, DcmPolymorphOBOW& /* uncompressedPixelData */, const DcmCodecParameter * /* cp */, - const DcmStack& /* objStack */) const + const DcmStack& /* objStack */, + OFBool& /* removeOldRep */ ) const { // we are an encoder only return EC_IllegalCall; @@ -101,7 +102,8 @@ OFCondition DcmRLECodecEncoder::encode( const DcmRepresentationParameter * /* toRepParam */, DcmPixelSequence * & /* toPixSeq */, const DcmCodecParameter * /* cp */, - DcmStack & /* objStack */) const + DcmStack& /* objStack */, + OFBool& /* removeOldRep */ ) const { // we don't support re-coding for now. return EC_IllegalCall; @@ -114,7 +116,8 @@ OFCondition DcmRLECodecEncoder::encode( const DcmRepresentationParameter * /* toRepParam */ , DcmPixelSequence * & pixSeq, const DcmCodecParameter *cp, - DcmStack & objStack) const + DcmStack& objStack, + OFBool& /* removeOldRep */ ) const { OFCondition result = EC_Normal; diff --git a/dcmjpeg/include/dcmtk/dcmjpeg/djcodecd.h b/dcmjpeg/include/dcmtk/dcmjpeg/djcodecd.h index 4a747ce900..7c31575d83 100644 --- a/dcmjpeg/include/dcmtk/dcmjpeg/djcodecd.h +++ b/dcmjpeg/include/dcmtk/dcmjpeg/djcodecd.h @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2001-2017, OFFIS e.V. + * Copyright (C) 2001-2020, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by @@ -61,6 +61,10 @@ class DCMTK_DCMJPEG_EXPORT DJCodecDecoder : public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition decode( @@ -68,7 +72,8 @@ class DCMTK_DCMJPEG_EXPORT DJCodecDecoder : public DcmCodec DcmPixelSequence * pixSeq, DcmPolymorphOBOW& uncompressedPixelData, const DcmCodecParameter * cp, - const DcmStack& objStack) const; + const DcmStack & objStack, + OFBool& removeOldRep) const; /** decompresses a single frame from the given pixel sequence and * stores the result in the given buffer. @@ -118,6 +123,10 @@ class DCMTK_DCMJPEG_EXPORT DJCodecDecoder : public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -126,7 +135,8 @@ class DCMTK_DCMJPEG_EXPORT DJCodecDecoder : public DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & pixSeq, const DcmCodecParameter *cp, - DcmStack & objStack) const; + DcmStack & objStack, + OFBool& removeOldRep) const; /** transcodes (re-compresses) the given compressed DICOM image and stores * the result in the given toPixSeq element. @@ -140,6 +150,10 @@ class DCMTK_DCMJPEG_EXPORT DJCodecDecoder : public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -149,7 +163,8 @@ class DCMTK_DCMJPEG_EXPORT DJCodecDecoder : public DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & toPixSeq, const DcmCodecParameter * cp, - DcmStack & objStack) const; + DcmStack & objStack, + OFBool& removeOldRep) const; /** checks if this codec is able to convert from the * given current transfer syntax to the given new diff --git a/dcmjpeg/include/dcmtk/dcmjpeg/djcodece.h b/dcmjpeg/include/dcmtk/dcmjpeg/djcodece.h index 9fda0226a4..b521bab1be 100644 --- a/dcmjpeg/include/dcmtk/dcmjpeg/djcodece.h +++ b/dcmjpeg/include/dcmtk/dcmjpeg/djcodece.h @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2001-2014, OFFIS e.V. + * Copyright (C) 2001-2020, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by @@ -65,6 +65,10 @@ class DCMTK_DCMJPEG_EXPORT DJCodecEncoder : public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition decode( @@ -72,7 +76,8 @@ class DCMTK_DCMJPEG_EXPORT DJCodecEncoder : public DcmCodec DcmPixelSequence * pixSeq, DcmPolymorphOBOW& uncompressedPixelData, const DcmCodecParameter * cp, - const DcmStack& objStack) const; + const DcmStack & objStack, + OFBool& removeOldRep) const; /** decompresses a single frame from the given pixel sequence and * stores the result in the given buffer. @@ -122,6 +127,10 @@ class DCMTK_DCMJPEG_EXPORT DJCodecEncoder : public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -130,7 +139,8 @@ class DCMTK_DCMJPEG_EXPORT DJCodecEncoder : public DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & pixSeq, const DcmCodecParameter *cp, - DcmStack & objStack) const; + DcmStack & objStack, + OFBool& removeOldRep) const; /** transcodes (re-compresses) the given compressed DICOM image and stores * the result in the given toPixSeq element. @@ -144,6 +154,10 @@ class DCMTK_DCMJPEG_EXPORT DJCodecEncoder : public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -153,7 +167,8 @@ class DCMTK_DCMJPEG_EXPORT DJCodecEncoder : public DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & toPixSeq, const DcmCodecParameter * cp, - DcmStack & objStack) const; + DcmStack & objStack, + OFBool& removeOldRep) const; /** checks if this codec is able to convert from the * given current transfer syntax to the given new diff --git a/dcmjpeg/libsrc/djcodecd.cc b/dcmjpeg/libsrc/djcodecd.cc index f7280d97d7..c13d4673ca 100644 --- a/dcmjpeg/libsrc/djcodecd.cc +++ b/dcmjpeg/libsrc/djcodecd.cc @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2001-2018, OFFIS e.V. + * Copyright (C) 2001-2020, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by @@ -65,9 +65,16 @@ OFCondition DJCodecDecoder::decode( DcmPixelSequence * pixSeq, DcmPolymorphOBOW& uncompressedPixelData, const DcmCodecParameter * cp, - const DcmStack& objStack) const + const DcmStack& objStack, + OFBool& removeOldRep) const { OFCondition result = EC_Normal; + + // this codec may modify the DICOM header such that the previous pixel + // representation is not valid anymore. Indicate this to the caller + // to trigger removal. + removeOldRep = OFTrue; + // assume we can cast the codec parameter to what we need const DJCodecParameter *djcp = OFreinterpret_cast(const DJCodecParameter*, cp); @@ -594,7 +601,8 @@ OFCondition DJCodecDecoder::encode( const DcmRepresentationParameter * /* toRepParam */, DcmPixelSequence * & /* pixSeq */, const DcmCodecParameter * /* cp */, - DcmStack & /* objStack */) const + DcmStack & /* objStack */, + OFBool& /* removeOldRep */) const { // we are a decoder only return EC_IllegalCall; @@ -608,7 +616,8 @@ OFCondition DJCodecDecoder::encode( const DcmRepresentationParameter * /* toRepParam */, DcmPixelSequence * & /* toPixSeq */, const DcmCodecParameter * /* cp */, - DcmStack & /* objStack */) const + DcmStack & /* objStack */, + OFBool& /* removeOldRep */) const { // we don't support re-coding for now return EC_IllegalCall; diff --git a/dcmjpeg/libsrc/djcodece.cc b/dcmjpeg/libsrc/djcodece.cc index f8668442f4..b052e0d52f 100644 --- a/dcmjpeg/libsrc/djcodece.cc +++ b/dcmjpeg/libsrc/djcodece.cc @@ -81,7 +81,8 @@ OFCondition DJCodecEncoder::decode( DcmPixelSequence * /* pixSeq */, DcmPolymorphOBOW& /* uncompressedPixelData */, const DcmCodecParameter * /* cp */, - const DcmStack& /* objStack */) const + const DcmStack& /* objStack */, + OFBool& /* removeOldRep */ ) const { // we are an encoder only return EC_IllegalCall; @@ -111,7 +112,8 @@ OFCondition DJCodecEncoder::encode( const DcmRepresentationParameter * /* toRepParam */, DcmPixelSequence * & /* toPixSeq */, const DcmCodecParameter * /* cp */, - DcmStack & /* objStack */) const + DcmStack & /* objStack */, + OFBool& /* removeOldRep */) const { // we don't support re-coding for now return EC_IllegalCall; @@ -124,9 +126,16 @@ OFCondition DJCodecEncoder::encode( const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & pixSeq, const DcmCodecParameter *cp, - DcmStack & objStack) const + DcmStack & objStack, + OFBool& removeOldRep) const { OFCondition result = EC_Normal; + + // this codec may modify the DICOM header such that the previous pixel + // representation is not valid anymore. Indicate this to the caller + // to trigger removal. + removeOldRep = OFTrue; + // assume we can cast the codec parameter to what we need const DJCodecParameter *djcp = OFreinterpret_cast(const DJCodecParameter*, cp); diff --git a/dcmjpls/include/dcmtk/dcmjpls/djcodecd.h b/dcmjpls/include/dcmtk/dcmjpls/djcodecd.h index 71c5de79f6..611d9b4d68 100644 --- a/dcmjpls/include/dcmtk/dcmjpls/djcodecd.h +++ b/dcmjpls/include/dcmtk/dcmjpls/djcodecd.h @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2007-2017, OFFIS e.V. + * Copyright (C) 2007-2020, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by @@ -54,6 +54,10 @@ class DCMTK_DCMJPLS_EXPORT DJLSDecoderBase: public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition decode( @@ -61,7 +65,8 @@ class DCMTK_DCMJPLS_EXPORT DJLSDecoderBase: public DcmCodec DcmPixelSequence * pixSeq, DcmPolymorphOBOW& uncompressedPixelData, const DcmCodecParameter * cp, - const DcmStack& objStack) const; + const DcmStack & objStack, + OFBool& removeOldRep) const; /** decompresses a single frame from the given pixel sequence and * stores the result in the given buffer. @@ -111,6 +116,10 @@ class DCMTK_DCMJPLS_EXPORT DJLSDecoderBase: public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -119,7 +128,8 @@ class DCMTK_DCMJPLS_EXPORT DJLSDecoderBase: public DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & pixSeq, const DcmCodecParameter *cp, - DcmStack & objStack) const; + DcmStack & objStack, + OFBool& removeOldRep) const; /** transcodes (re-compresses) the given compressed DICOM image and stores * the result in the given toPixSeq element. @@ -133,6 +143,10 @@ class DCMTK_DCMJPLS_EXPORT DJLSDecoderBase: public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -142,7 +156,8 @@ class DCMTK_DCMJPLS_EXPORT DJLSDecoderBase: public DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & toPixSeq, const DcmCodecParameter * cp, - DcmStack & objStack) const; + DcmStack & objStack, + OFBool& removeOldRep) const; /** checks if this codec is able to convert from the * given current transfer syntax to the given new diff --git a/dcmjpls/include/dcmtk/dcmjpls/djcodece.h b/dcmjpls/include/dcmtk/dcmjpls/djcodece.h index e2dbc4f8d2..01209c2551 100644 --- a/dcmjpls/include/dcmtk/dcmjpls/djcodece.h +++ b/dcmjpls/include/dcmtk/dcmjpls/djcodece.h @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2007-2019, OFFIS e.V. + * Copyright (C) 2007-2020, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by @@ -57,6 +57,10 @@ class DCMTK_DCMJPLS_EXPORT DJLSEncoderBase : public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition decode( @@ -64,7 +68,8 @@ class DCMTK_DCMJPLS_EXPORT DJLSEncoderBase : public DcmCodec DcmPixelSequence * pixSeq, DcmPolymorphOBOW& uncompressedPixelData, const DcmCodecParameter * cp, - const DcmStack& objStack) const; + const DcmStack & objStack, + OFBool& removeOldRep) const; /** decompresses a single frame from the given pixel sequence and * stores the result in the given buffer. @@ -114,6 +119,10 @@ class DCMTK_DCMJPLS_EXPORT DJLSEncoderBase : public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -122,7 +131,8 @@ class DCMTK_DCMJPLS_EXPORT DJLSEncoderBase : public DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & pixSeq, const DcmCodecParameter *cp, - DcmStack & objStack) const; + DcmStack & objStack, + OFBool& removeOldRep) const; /** transcodes (re-compresses) the given compressed DICOM image and stores * the result in the given toPixSeq element. @@ -136,6 +146,10 @@ class DCMTK_DCMJPLS_EXPORT DJLSEncoderBase : public DcmCodec * @param cp codec parameters for this codec * @param objStack stack pointing to the location of the pixel data * element in the current dataset. + * @param removeOldRep boolean flag that should be set to false before this method call + * and will be set to true if the codec modifies the DICOM dataset such + * that the pixel data of the original representation may not be usable + * anymore. * @return EC_Normal if successful, an error code otherwise. */ virtual OFCondition encode( @@ -145,7 +159,8 @@ class DCMTK_DCMJPLS_EXPORT DJLSEncoderBase : public DcmCodec const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & toPixSeq, const DcmCodecParameter * cp, - DcmStack & objStack) const; + DcmStack & objStack, + OFBool& removeOldRep) const; /** checks if this codec is able to convert from the * given current transfer syntax to the given new diff --git a/dcmjpls/libsrc/djcodecd.cc b/dcmjpls/libsrc/djcodecd.cc index 4b3b2390ea..fc0df5c7f2 100644 --- a/dcmjpls/libsrc/djcodecd.cc +++ b/dcmjpls/libsrc/djcodecd.cc @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2007-2019, OFFIS e.V. + * Copyright (C) 2007-2020, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by @@ -81,8 +81,16 @@ OFCondition DJLSDecoderBase::decode( DcmPixelSequence * pixSeq, DcmPolymorphOBOW& uncompressedPixelData, const DcmCodecParameter * cp, - const DcmStack& objStack) const + const DcmStack& objStack, + OFBool& removeOldRep) const { + + // this codec may modify the DICOM header such that the previous pixel + // representation is not valid anymore, e.g. in the case of color images + // where the planar configuration can change. Indicate this to the caller + // to trigger removal. + removeOldRep = OFTrue; + // retrieve pointer to dataset from parameter stack DcmStack localStack(objStack); (void)localStack.pop(); // pop pixel data element from stack @@ -470,7 +478,8 @@ OFCondition DJLSDecoderBase::encode( const DcmRepresentationParameter * /* toRepParam */, DcmPixelSequence * & /* pixSeq */, const DcmCodecParameter * /* cp */, - DcmStack & /* objStack */) const + DcmStack & /* objStack */, + OFBool& /* removeOldRep */) const { // we are a decoder only return EC_IllegalCall; @@ -484,7 +493,8 @@ OFCondition DJLSDecoderBase::encode( const DcmRepresentationParameter * /* toRepParam */, DcmPixelSequence * & /* toPixSeq */, const DcmCodecParameter * /* cp */, - DcmStack & /* objStack */) const + DcmStack & /* objStack */, + OFBool& /* removeOldRep */) const { // we don't support re-coding for now. return EC_IllegalCall; diff --git a/dcmjpls/libsrc/djcodece.cc b/dcmjpls/libsrc/djcodece.cc index e253acbd4a..5e82662783 100644 --- a/dcmjpls/libsrc/djcodece.cc +++ b/dcmjpls/libsrc/djcodece.cc @@ -108,7 +108,8 @@ OFCondition DJLSEncoderBase::decode( DcmPixelSequence * /* pixSeq */, DcmPolymorphOBOW& /* uncompressedPixelData */, const DcmCodecParameter * /* cp */, - const DcmStack& /* objStack */) const + const DcmStack& /* objStack */, + OFBool& /* removeOldRep */ ) const { // we are an encoder only return EC_IllegalCall; @@ -138,7 +139,8 @@ OFCondition DJLSEncoderBase::encode( const DcmRepresentationParameter * /* toRepParam */, DcmPixelSequence * & /* toPixSeq */, const DcmCodecParameter * /* cp */, - DcmStack & /* objStack */) const + DcmStack& /* objStack */, + OFBool& /* removeOldRep */ ) const { // we don't support re-coding for now. return EC_IllegalCall; @@ -150,11 +152,17 @@ OFCondition DJLSEncoderBase::encode( const DcmRepresentationParameter * toRepParam, DcmPixelSequence * & pixSeq, const DcmCodecParameter *cp, - DcmStack & objStack) const + DcmStack& objStack, + OFBool& removeOldRep) const { OFCondition result = EC_Normal; DJLSRepresentationParameter defRep; + // this codec may modify the DICOM header such that the previous pixel + // representation is not valid anymore. Indicate this to the caller + // to trigger removal. + removeOldRep = OFTrue; + // retrieve pointer to dataset from parameter stack DcmStack localStack(objStack); (void)localStack.pop(); // pop pixel data element from stack