diff --git a/Modules/ThirdParty/GDCM/UpdateFromUpstream.sh b/Modules/ThirdParty/GDCM/UpdateFromUpstream.sh index 086231b3e90..48a33d42e72 100755 --- a/Modules/ThirdParty/GDCM/UpdateFromUpstream.sh +++ b/Modules/ThirdParty/GDCM/UpdateFromUpstream.sh @@ -33,7 +33,6 @@ readonly paths=" Utilities/gdcm_openjpeg.h Utilities/gdcmopenjpeg Utilities/gdcmrle - Utilities/gdcmutfcpp Utilities/gdcmuuid Utilities/gdcm_uuid.h Utilities/gdcm_zlib.h diff --git a/Modules/ThirdParty/GDCM/src/gdcm/CMakeLists.txt b/Modules/ThirdParty/GDCM/src/gdcm/CMakeLists.txt index 750824bab80..1b6695417eb 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/CMakeLists.txt +++ b/Modules/ThirdParty/GDCM/src/gdcm/CMakeLists.txt @@ -1,14 +1,7 @@ -cmake_minimum_required(VERSION 3.9.2 FATAL_ERROR) +set(GDCM_MAX_VALIDATED_CMAKE_VERSION "3.13.4") -set(GDCM_MAX_VALIDATED_CMAKE_VERSION "3.13.1") -if("${CMAKE_VERSION}" VERSION_LESS_EQUAL "${GDCM_MAX_VALIDATED_CMAKE_VERSION}") - # As of 2018-12-04 GDCM has been validated to build with cmake version 3.13.1 new policies. - # Set and use the newest cmake policies that are validated to work - set(GDCM_CMAKE_POLICY_VERSION "${CMAKE_VERSION}") -else() - set(GDCM_CMAKE_POLICY_VERSION "${GDCM_MAX_VALIDATED_CMAKE_VERSION}") -endif() -cmake_policy(VERSION ${GDCM_CMAKE_POLICY_VERSION}) +# Set minimum required version of CMake, and policy version +cmake_minimum_required(VERSION 3.9.2...${GDCM_MAX_VALIDATED_CMAKE_VERSION} FATAL_ERROR) # travis-ci wants 3.9.2 # GDCM version 3.0.0 will only support C++11 and greater if(CMAKE_CXX_STANDARD EQUAL "98" ) @@ -17,7 +10,7 @@ endif() #---------------------------------------------------------------------------- project(GDCM - VERSION 3.0.24 + VERSION 3.2.5 LANGUAGES CXX C ) ## NOTE: the "DESCRIPTION" feature of project() was introduced in cmake 3.10.0 @@ -125,20 +118,39 @@ if(BUILD_SHARED_LIBS) endif() #----------------------------------------------------------------------------- -if(NOT EXECUTABLE_OUTPUT_PATH) - set(EXECUTABLE_OUTPUT_PATH ${GDCM_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.") - mark_as_advanced(EXECUTABLE_OUTPUT_PATH) +# Compatibility with older usage of EXECUTABLE_OUTPUT_PATH and LIBRARY_OUTPUT_PATH. +# This should be removed in the future. +if(EXECUTABLE_OUTPUT_PATH) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) + message(WARNING "EXECUTABLE_OUTPUT_PATH is deprecated. Use CMAKE_RUNTIME_OUTPUT_DIRECTORY instead.") endif() -if(NOT LIBRARY_OUTPUT_PATH) - set(LIBRARY_OUTPUT_PATH ${GDCM_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.") - mark_as_advanced(LIBRARY_OUTPUT_PATH) +if(LIBRARY_OUTPUT_PATH) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}) + message(WARNING "LIBRARY_OUTPUT_PATH is deprecated. Use CMAKE_LIBRARY_OUTPUT_DIRECTORY and CMAKE_ARCHIVE_OUTPUT_DIRECTORY instead.") endif() -# TODO: The following should be used for CMake 3 and beyond, -# EXECUTABLE_OUTPUT_PATH and LIBRARY_OUTPUT_PATH are deprecated -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}) +if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) +endif() +if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) +endif() +if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) +endif() + +# Set for legacy internal usage of EXECUTABLE_OUTPUT_PATH and LIBRARY_OUTPUT_PATH +if (NOT EXECUTABLE_OUTPUT_PATH) + set(EXECUTABLE_OUTPUT_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) +endif() +if (NOT LIBRARY_OUTPUT_PATH) + if (BUILD_SHARED_LIBS) + set(LIBRARY_OUTPUT_PATH ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) + else() + set(LIBRARY_OUTPUT_PATH ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}) + endif() +endif() #----------------------------------------------------------------------------- # Adding GDCM_DATA_ROOT @@ -187,6 +199,10 @@ macro(CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE) endif() endmacro() +if(UNIX) + include(GNUInstallDirs) +endif() + #include(${GDCM_SOURCE_DIR}/CMake/gdcmPlatformCxxTests.cmake) # #GDCM_PLATFORM_CXX_TEST(GDCM_CXX_HAS_FUNCTION @@ -524,7 +540,7 @@ if(GDCM_STANDALONE) endif() if(NOT DEFINED GDCM_DEFAULT_JAVA_VERSION) # override with cmake -DGDCM_DEFAULT_JAVA_VERSION:STRING=1.5 if you dare - set(GDCM_DEFAULT_JAVA_VERSION 1.7) + set(GDCM_DEFAULT_JAVA_VERSION 1.8) endif() if(GDCM_WRAP_JAVA) set(GDCM_JAVA_SOURCE_VERSION "${GDCM_DEFAULT_JAVA_VERSION}" CACHE STRING "javac source version") @@ -696,23 +712,45 @@ if(GDCM_STANDALONE) ) # documented at https://vtk.org/doc/nightly/html/group__module.html - vtk_module_build( - MODULES ${vtkgdcm_modules} - INSTALL_EXPORT GDCM - ARCHIVE_DESTINATION "${GDCM_INSTALL_LIB_DIR}" - HEADERS_DESTINATION "${GDCM_INSTALL_INCLUDE_DIR}/vtk${vtk_version_suffix}" - CMAKE_DESTINATION "${GDCM_INSTALL_PACKAGE_DIR}" - LICENSE_DESTINATION "${GDCM_INSTALL_DATA_DIR}/vtkgdcm-${GDCM_SHORT_VERSION}" - HIERARCHY_DESTINATION "${GDCM_INSTALL_LIB_DIR}/vtk${vtk_version_suffix}/hierarchy/vtkgdcm" - LIBRARY_NAME_SUFFIX "${vtkgdcm_library_suffix}" - VERSION "${GDCM_VERSION}" - SOVERSION "1" - # TODO: these are probably not set as they should be - #USE_EXTERNAL "${GDCM_USE_EXTERNAL}" - #TEST_DATA_TARGET vtkgdcmData - #TEST_INPUT_DATA_DIRECTORY "${vtkgdcm_test_data_directory_input}" - #TEST_OUTPUT_DATA_DIRECTORY "${vtkgdcm_test_data_directory_output}" - ) + if(VTK_VERSION VERSION_LESS 9.3) + vtk_module_build( + MODULES ${vtkgdcm_modules} + INSTALL_EXPORT GDCM + ARCHIVE_DESTINATION "${GDCM_INSTALL_LIB_DIR}" + HEADERS_DESTINATION "${GDCM_INSTALL_INCLUDE_DIR}/vtk${vtk_version_suffix}" + CMAKE_DESTINATION "${GDCM_INSTALL_PACKAGE_DIR}" + LICENSE_DESTINATION "${GDCM_INSTALL_DATA_DIR}/vtkgdcm-${GDCM_SHORT_VERSION}" + #SPDX_DESTINATION "${GDCM_INSTALL_DATA_DIR}/vtkgdcm-${GDCM_SHORT_VERSION}" + HIERARCHY_DESTINATION "${GDCM_INSTALL_LIB_DIR}/vtk${vtk_version_suffix}/hierarchy/vtkgdcm" + LIBRARY_NAME_SUFFIX "${vtkgdcm_library_suffix}" + VERSION "${GDCM_VERSION}" + SOVERSION "1" + # TODO: these are probably not set as they should be + #USE_EXTERNAL "${GDCM_USE_EXTERNAL}" + #TEST_DATA_TARGET vtkgdcmData + #TEST_INPUT_DATA_DIRECTORY "${vtkgdcm_test_data_directory_input}" + #TEST_OUTPUT_DATA_DIRECTORY "${vtkgdcm_test_data_directory_output}" + ) + else() + vtk_module_build( + MODULES ${vtkgdcm_modules} + INSTALL_EXPORT GDCM + ARCHIVE_DESTINATION "${GDCM_INSTALL_LIB_DIR}" + HEADERS_DESTINATION "${GDCM_INSTALL_INCLUDE_DIR}/vtk${vtk_version_suffix}" + CMAKE_DESTINATION "${GDCM_INSTALL_PACKAGE_DIR}" + LICENSE_DESTINATION "${GDCM_INSTALL_DATA_DIR}/vtkgdcm-${GDCM_SHORT_VERSION}" + SPDX_DESTINATION "${GDCM_INSTALL_DATA_DIR}/vtkgdcm-${GDCM_SHORT_VERSION}" + HIERARCHY_DESTINATION "${GDCM_INSTALL_LIB_DIR}/vtk${vtk_version_suffix}/hierarchy/vtkgdcm" + LIBRARY_NAME_SUFFIX "${vtkgdcm_library_suffix}" + VERSION "${GDCM_VERSION}" + SOVERSION "1" + # TODO: these are probably not set as they should be + #USE_EXTERNAL "${GDCM_USE_EXTERNAL}" + #TEST_DATA_TARGET vtkgdcmData + #TEST_INPUT_DATA_DIRECTORY "${vtkgdcm_test_data_directory_input}" + #TEST_OUTPUT_DATA_DIRECTORY "${vtkgdcm_test_data_directory_output}" + ) + endif() if(VTKGDCM_WRAP_PYTHON) find_package(PythonInterp ${VTK_PYTHON_VERSION} QUIET) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmASN1.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmASN1.cxx index afab05e02e6..dbc1cf679d7 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmASN1.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmASN1.cxx @@ -73,7 +73,7 @@ bool ASN1::ParseDump(const char *array, size_t length) BIO *out=NULL; out=BIO_new(BIO_s_file()); - assert( out ); + gdcm_assert( out ); BIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT); if (!ASN1_parse_dump(out,(const unsigned char*)array,length,indent,dump) ) { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmBoxRegion.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmBoxRegion.cxx index b675a0d64fe..1c8372c5104 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmBoxRegion.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmBoxRegion.cxx @@ -67,7 +67,7 @@ Region *BoxRegion::Clone() const bool BoxRegion::Empty() const { - assert( 0 ); + gdcm_assert( 0 ); return false; } @@ -146,14 +146,14 @@ BoxRegion BoxRegion::BoundingBox(BoxRegion const & b1, BoxRegion const & b2 ) BoxRegion::BoxRegion(const BoxRegion& b) { - assert( b.Internals ); + gdcm_assert( b.Internals ); Internals = new BoxRegionInternals; *Internals = *b.Internals; } void BoxRegion::operator=(const BoxRegion& b) { - assert( b.Internals ); + gdcm_assert( b.Internals ); *Internals = *b.Internals; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmCAPICryptographicMessageSyntax.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmCAPICryptographicMessageSyntax.cxx index ff6d05f1129..4ab23985701 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmCAPICryptographicMessageSyntax.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmCAPICryptographicMessageSyntax.cxx @@ -313,7 +313,7 @@ bool CAPICryptographicMessageSyntax::Decrypt(char *output, size_t &outlen, const keyBlob.header.reserved = 0; keyBlob.header.aiKeyAlg = GetAlgIdByObjId(cekAlg->pszObjId); keyBlob.cbKeySize = cekLen; - assert(cekLen <= 32); + gdcm_assert(cekLen <= 32); memcpy(keyBlob.rgbKeyData, cek, cekLen); if (!CryptImportKey(hProv, (unsigned char*)&keyBlob, sizeof(keyBlob), 0, 0, &hCEK)) @@ -480,7 +480,7 @@ void CAPICryptographicMessageSyntax::ReverseBytes(unsigned char* data, DWORD len bool CAPICryptographicMessageSyntax::LoadFile(const char * filename, unsigned char* & buffer, DWORD & bufLen) { - assert( !buffer ); + gdcm_assert( !buffer ); FILE * f = fopen(filename, "rb"); if (f == NULL) { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmCommand.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmCommand.h index 8bd0583c7c2..1012ff5ac84 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmCommand.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmCommand.h @@ -115,7 +115,7 @@ class MemberCommand : public Command T* m_This; TMemberFunctionPointer m_MemberFunction; TConstMemberFunctionPointer m_ConstMemberFunction; - MemberCommand():m_MemberFunction(nullptr),m_ConstMemberFunction(nullptr) {} + MemberCommand():m_This(nullptr),m_MemberFunction(nullptr),m_ConstMemberFunction(nullptr) {} ~MemberCommand() override= default; }; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmCryptoFactory.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmCryptoFactory.cxx index 379fc59d8d6..2fe8c2035b0 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmCryptoFactory.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmCryptoFactory.cxx @@ -61,7 +61,7 @@ CryptoFactory* CryptoFactory::GetFactoryInstance(CryptoLib id) gdcmErrorMacro( "No crypto factory registered with id " << (int)id ); return nullptr; } - assert(it->second); + gdcm_assert(it->second); return it->second; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmDataEvent.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmDataEvent.h index b60603131be..bd783ed6e17 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmDataEvent.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmDataEvent.h @@ -29,7 +29,7 @@ class DataEvent : public AnyEvent typedef AnyEvent Superclass; DataEvent(const char *bytes = nullptr, size_t len = 0):Bytes(bytes),Length(len) {} ~DataEvent() override = default; - DataEvent(const Self&s) : AnyEvent(s){}; + DataEvent(const Self&s) : AnyEvent(s), Bytes(nullptr), Length(0) {} void operator=(const Self&) = delete; const char * GetEventName() const override { return "DataEvent"; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmDirectory.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmDirectory.cxx index cf87700de25..196dcf3a62d 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmDirectory.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmDirectory.cxx @@ -68,7 +68,7 @@ unsigned int Directory::Explore(FilenameType const &name, bool recursive) if ('\\' == dirName[dirName.size() - 1]) dirName = dirName.substr(0, dirName.size() - 1); if ('/' != dirName[dirName.size() - 1]) dirName.push_back('/'); - assert( '/' == dirName[dirName.size()-1] ); + gdcm_assert( '/' == dirName[dirName.size()-1] ); const std::wstring firstfile = dirName+L"*"; HANDLE hFile = FindFirstFileW(firstfile.c_str(), &fileData); @@ -106,7 +106,7 @@ unsigned int Directory::Explore(FilenameType const &name, bool recursive) #else std::string fileName; std::string dirName = name; - // assert( System::FileIsDirectory( dirName ) ); + // gdcm_assert( System::FileIsDirectory( dirName ) ); Directories.push_back(dirName); // Real POSIX implementation: scandir is a BSD extension only, and doesn't // work on debian for example @@ -127,7 +127,7 @@ unsigned int Directory::Explore(FilenameType const &name, bool recursive) struct stat buf; dirent *d; if ('/' != dirName[dirName.size()-1]) dirName.push_back('/'); - assert( '/' == dirName[dirName.size()-1] ); + gdcm_assert( '/' == dirName[dirName.size()-1] ); for (d = readdir(dir); d; d = readdir(dir)) { fileName = dirName + d->d_name; @@ -152,7 +152,7 @@ unsigned int Directory::Explore(FilenameType const &name, bool recursive) || strcmp( d->d_name, ".." ) == 0 || d->d_name[0] == '.' ) // discard any hidden dir continue; - assert( d->d_name[0] != '.' ); // hidden directory ?? + gdcm_assert( d->d_name[0] != '.' ); // hidden directory ?? if ( recursive ) { nFiles += Explore( fileName, recursive); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmDirectory.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmDirectory.h index dd59e2657d3..9effed0619f 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmDirectory.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmDirectory.h @@ -56,7 +56,7 @@ public : /// Set/Get the file names within the directory FilenamesType const &GetFilenames() const { - assert( !(Toplevel.empty()) && "Need to call Explore first" ); + gdcm_assert( !(Toplevel.empty()) && "Need to call Explore first" ); return Filenames; } /// Return the Directories traversed diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmException.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmException.h index da87572c4b3..dded053340d 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmException.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmException.h @@ -31,6 +31,8 @@ # endif #endif +#define gdcm_forced_assert(cond) assert(cond) + namespace gdcm { @@ -54,9 +56,9 @@ class Exception : public std::exception const unsigned int lineNumber, const char* const func) { - assert(desc != nullptr); - assert(file != nullptr); - assert(func != nullptr); + gdcm_forced_assert(desc != nullptr); + gdcm_forced_assert(file != nullptr); + gdcm_forced_assert(func != nullptr); std::ostringstream oswhat; oswhat << file << ":" << lineNumber << " (" << func << "):\n"; oswhat << desc; @@ -98,6 +100,17 @@ class Exception : public std::exception } // end namespace gdcm +// Always defined +#define gdcm_assert(cond) \ + if (!(cond)) throw gdcm::Exception("An invalid logic behavior occurred" #cond, __FILE__ , __LINE__) + +/* Asserts that should only exist in debug builds. */ +#ifndef NDEBUG // checks in debug builds and elision in release builds (like assert) +#define gdcm_debug_assert(cond) gdcm_assert(cond) +#else +#define gdcm_debug_assert(cond) ((void)0) +#endif + // Undo warning suppression. #if defined(__clang__) && defined(__has_warning) # if __has_warning("-Wdeprecated") diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmFilename.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmFilename.cxx index 5384510dbff..d0969e769e8 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmFilename.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmFilename.cxx @@ -17,6 +17,10 @@ #include // realpath #include +#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) +#include +#endif + namespace gdcm { @@ -48,7 +52,7 @@ const char *Filename::GetPath() const char *Filename::GetName() { std::string filename = FileName; - assert( !filename.empty() ); + gdcm_assert( !filename.empty() ); #if defined(_WIN32) std::string::size_type slash_pos = filename.find_last_of("/\\"); #else @@ -65,7 +69,7 @@ const char *Filename::GetName() const char *Filename::ToWindowsSlashes() { Conversion = FileName; - //assert( !Conversion.empty() ); + //gdcm_assert( !Conversion.empty() ); for (std::string::iterator it = Conversion.begin(); it != Conversion.end(); ++it ) { if( *it == '/' ) @@ -82,13 +86,13 @@ const char *Filename::ToUnixSlashes() { Conversion = FileName; //std::string::size_type s = Conversion.find("\\"); - //assert( s == std::string::npos ); - assert( !Conversion.empty() ); + //gdcm_assert( s == std::string::npos ); + gdcm_assert( !Conversion.empty() ); for (std::string::iterator it = Conversion.begin(); it != Conversion.end(); ++it ) { if( *it == '\\' ) { - assert( it+1 == Conversion.end() || *(it+1) != ' ' ); // is it an escaped space ? + gdcm_assert( it+1 == Conversion.end() || *(it+1) != ' ' ); // is it an escaped space ? *it = '/'; } } @@ -97,7 +101,6 @@ const char *Filename::ToUnixSlashes() } #if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) -#include inline void Realpath(const char *path, std::string & resolved_path) { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmFilenameGenerator.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmFilenameGenerator.cxx index d3b40f1128b..505be3f5867 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmFilenameGenerator.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmFilenameGenerator.cxx @@ -92,7 +92,7 @@ bool FilenameGenerator::Generate() for( SizeType i = 0; i < numfiles && success; ++i) { int res = snprintf( internal, internal_len, Pattern.c_str(), i ); - assert( res >= 0 ); + gdcm_assert( res >= 0 ); success = (SizeType)res < internal_len; if( Pattern.empty() ) { @@ -102,7 +102,7 @@ bool FilenameGenerator::Generate() { Filenames[i] = Prefix + internal; } - //assert( Filenames[i].size() == res ); // upon success only + //gdcm_assert( Filenames[i].size() == res ); // upon success only } delete[] internal; if( !success ) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmFilenameGenerator.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmFilenameGenerator.h index 83d1e652a43..f31644a13b7 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmFilenameGenerator.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmFilenameGenerator.h @@ -62,7 +62,7 @@ class GDCM_EXPORT FilenameGenerator const char * GetFilename(SizeType n) const; /// Return all filenames - FilenamesType const & GetFilenames() const { assert( !Pattern.empty() ); return Filenames; } + FilenamesType const & GetFilenames() const { gdcm_assert( !Pattern.empty() ); return Filenames; } private: FilenameType Pattern; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmObject.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmObject.h index 9c150e5c978..e721851c873 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmObject.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmObject.h @@ -55,7 +55,7 @@ class GDCM_EXPORT Object virtual ~Object() { // If your debugger reach here it means you are doing something silly // like using SmartPointer on object allocated on the stack (vs heap) - assert(ReferenceCount == 0); + gdcm_forced_assert(ReferenceCount == 0); } // http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.24 @@ -71,10 +71,10 @@ class GDCM_EXPORT Object // For the purpose of the invasive SmartPointer implementation void Register() { ReferenceCount++; - assert( ReferenceCount > 0 ); + gdcm_assert( ReferenceCount > 0 ); } void UnRegister() { - assert( ReferenceCount > 0 ); + gdcm_assert( ReferenceCount > 0 ); ReferenceCount--; if(!ReferenceCount) { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmOpenSSLCryptographicMessageSyntax.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmOpenSSLCryptographicMessageSyntax.cxx index ffc9a9a9e40..429f33db3ed 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmOpenSSLCryptographicMessageSyntax.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmOpenSSLCryptographicMessageSyntax.cxx @@ -56,7 +56,7 @@ CryptographicMessageSyntax::CipherTypes OpenSSLCryptographicMessageSyntax::GetCi bool OpenSSLCryptographicMessageSyntax::SetPassword(const char * pass, size_t passLen) { - assert(pass); + gdcm_assert(pass); if (password) { @@ -281,7 +281,7 @@ bool OpenSSLCryptographicMessageSyntax::ParseKeyFile( const char *keyfile) bool OpenSSLCryptographicMessageSyntax::ParseCertificateFile( const char *keyfile) { - assert( recips ); + gdcm_assert( recips ); ::X509 *x509 = NULL; ::BIO *in; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmOpenSSLP7CryptographicMessageSyntax.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmOpenSSLP7CryptographicMessageSyntax.cxx index 8e44d5041a2..daaca4014a8 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmOpenSSLP7CryptographicMessageSyntax.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmOpenSSLP7CryptographicMessageSyntax.cxx @@ -446,7 +446,7 @@ bool OpenSSLP7CryptographicMessageSyntax::ParseCertificateFile( const char *keyf { #ifdef GDCM_USE_SYSTEM_OPENSSL STACK_OF(X509) *recips = Internals->GetRecipients(); - assert( recips ); + gdcm_assert( recips ); ::X509 *x509 = NULL; ::BIO *in; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmProgressEvent.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmProgressEvent.h index a2164d668e5..cecbaccfd8d 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmProgressEvent.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmProgressEvent.h @@ -34,7 +34,7 @@ class ProgressEvent : public AnyEvent ProgressEvent(double p = 0):m_Progress(p) {} ~ProgressEvent() override = default; - ProgressEvent(const Self&s) : AnyEvent(s){}; + ProgressEvent(const Self&s) : AnyEvent(s), m_Progress(0.0) {} void operator=(const Self&) = delete; const char * GetEventName() const override { return "ProgressEvent"; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSmartPointer.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSmartPointer.h index 03f044f4921..0fa1c8892dc 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSmartPointer.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSmartPointer.h @@ -60,7 +60,7 @@ class SmartPointer ObjectType& operator * () const { - assert( Pointer ); + gdcm_assert( Pointer ); return *Pointer; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSubject.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSubject.cxx index df1191f9679..1f9c047e3ad 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSubject.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSubject.cxx @@ -50,7 +50,7 @@ class SubjectInternals void InvokeEvent( const Event & event, const Subject* self); Command *GetCommand(unsigned long tag); bool HasObserver(const Event & event) const; - bool PrintObservers(std::ostream& os, std::string indent) const; + bool PrintObservers(std::ostream& os, const std::string & indent) const; private: std::list m_Observers; unsigned long m_Count; @@ -188,7 +188,7 @@ HasObserver(const Event & event) const bool SubjectInternals:: -PrintObservers(std::ostream& os, std::string indent) const +PrintObservers(std::ostream& os, const std::string & indent) const { if(m_Observers.empty()) { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSwapCode.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSwapCode.cxx index 4d46f86351a..acbb20b2118 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSwapCode.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSwapCode.cxx @@ -47,9 +47,9 @@ int SwapCode::GetIndex(SwapCode const & sc) idx = 4; break; default: - assert(0 && "Should not happen" ); + gdcm_assert(0 && "Should not happen" ); } - assert( idx < 5 ); + gdcm_assert( idx < 5 ); return idx; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSwapper.txx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSwapper.txx index d63ccd5d799..6d057818874 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSwapper.txx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSwapper.txx @@ -148,7 +148,7 @@ namespace gdcm SwapperNoOp::SwapArray((uint32_t*)array,n); break; default: - assert(0); + gdcm_assert(0); } } @@ -160,7 +160,7 @@ namespace gdcm SwapperNoOp::SwapArray((uint64_t*)array,n); break; default: - assert(0); + gdcm_assert(0); } } @@ -224,7 +224,7 @@ namespace gdcm SwapperDoOp::SwapArray((uint32_t*)array,n); break; default: - assert(0); + gdcm_assert(0); } } @@ -236,7 +236,7 @@ namespace gdcm SwapperDoOp::SwapArray((uint64_t*)array,n); break; default: - assert(0); + gdcm_assert(0); } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSystem.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSystem.cxx index 5d31526d088..e4fe756a3c3 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSystem.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmSystem.cxx @@ -212,7 +212,7 @@ bool System::FileExists(const char* filename) } else { - //assert( !FileIsDirectory(filename) ); + //gdcm_assert( !FileIsDirectory(filename) ); return true; } } @@ -437,7 +437,7 @@ bool System::DeleteDirectory(const char *source) out = prefix + (out.c_str() + 2); } else { // regular C:\ style path: - assert(out[1] == ':'); + gdcm_assert(out[1] == ':'); const std::wstring prefix = LR"(\\?\)"; out = prefix + out.c_str(); } @@ -613,7 +613,7 @@ inline int getlastdigit(unsigned char *data, unsigned long size) data[i] = (unsigned char)(extended / 10); carry = extended % 10; } - assert( carry >= 0 && carry < 10 ); + gdcm_assert( carry >= 0 && carry < 10 ); return carry; } @@ -689,7 +689,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) (other than the declaration) is a bug. Thus, the following is purely of historic interest. */ - assert( tz == 0 ); + gdcm_assert( tz == 0 ); FILETIME ft; unsigned __int64 tmpres = 0; //static int tzflag; @@ -818,7 +818,7 @@ const char *System::GetTimezoneOffsetFromUTC() time_t t = time(nullptr); struct tm *tmp = localtime(&t); size_t l = strftime(outstr, sizeof(outstr), "%z", tmp); - assert( l == 5 ); (void)l; + gdcm_assert( l == 5 ); (void)l; buffer = outstr; return buffer.c_str(); } @@ -846,7 +846,7 @@ bool System::FormatDateTime(char date[22], time_t timep, long milliseconds) } // Format the date and time, down to a single second. size_t ret = strftime (tmp, sizeof (tmp), "%Y%m%d%H%M%S", ptm); - assert( ret == 14 ); + gdcm_assert( ret == 14 ); if( ret == 0 || ret >= maxsize ) { return false; @@ -911,7 +911,7 @@ bool System::GetCurrentDateTime(char date[22]) // "59"), SS = Second (range "00" - "60"). // FFFFFF = Fractional Second contains a fractional part of a second as small // as 1 millionth of a second (range 000000 - 999999). - assert( tv.tv_usec >= 0 && tv.tv_usec < 1000000 ); + gdcm_assert( tv.tv_usec >= 0 && tv.tv_usec < 1000000 ); milliseconds = tv.tv_usec; return FormatDateTime(date, timep, milliseconds); @@ -925,7 +925,7 @@ int System::StrNCaseCmp(const char *s1, const char *s2, size_t n) return _strnicmp(s1,s2,n); #else // default implementation #error - assert( n ); // TODO + gdcm_assert( n ); // TODO while (--n && *s1 && (tolower(*s1) == tolower(*s2))) { s1++; @@ -1042,16 +1042,16 @@ char *System::StrSep(char **sp, const char *sep) #endif } +#if defined(_WIN32) struct CharsetAliasType { const char *alias; const char *name; }; -#if defined(_WIN32) static const char *CharsetAliasToName(const char *alias) { - assert( alias ); + gdcm_assert( alias ); //gdcmDebugMacro( alias ); // http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756(v=vs.85).aspx // 1252 windows-1252 ANSI Latin 1; Western European (Windows) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmTerminal.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmTerminal.cxx index 118192d86a0..ad36173c1ad 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmTerminal.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmTerminal.cxx @@ -84,7 +84,7 @@ class ConsoleImp std::string textcolor() const { char command[16]; int n = snprintf(command, sizeof(command), "%c[%d;%d;%dm", 0x1B, attribute, fgcolor + 30, bgcolor + 40); - assert( n < 16 ); (void)n; + gdcm_assert( n < 16 ); (void)n; return command; } void set_attributes(int color) { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmTesting.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmTesting.cxx index 0460443bc64..ed42c99d3dc 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmTesting.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmTesting.cxx @@ -79,7 +79,7 @@ const char * const * Testing::GetMediaStorageDataFile(unsigned int file) { if( file < Testing::GetNumberOfMediaStorageDataFiles() ) return gdcmMediaStorageDataFiles[file]; // else return the {0x0, 0x0} sentinel: - assert( *gdcmMediaStorageDataFiles[ Testing::GetNumberOfMediaStorageDataFiles() ] == nullptr ); + gdcm_assert( *gdcmMediaStorageDataFiles[ Testing::GetNumberOfMediaStorageDataFiles() ] == nullptr ); return gdcmMediaStorageDataFiles[ Testing::GetNumberOfMediaStorageDataFiles() ]; } const char * Testing::GetMediaStorageFromFile(const char *filepath) @@ -99,7 +99,7 @@ const char * Testing::GetMediaStorageFromFile(const char *filepath) p = mediastorages[i][0]; } // \postcondition always valid (before sentinel) - assert( i <= GetNumberOfMediaStorageDataFiles() ); + gdcm_assert( i <= GetNumberOfMediaStorageDataFiles() ); return mediastorages[i][1]; } @@ -119,7 +119,7 @@ const char * const * Testing::GetMD5DataImage(unsigned int file) { if( file < Testing::GetNumberOfMD5DataImages() ) return gdcmMD5DataImages[file]; // else return the {0x0, 0x0} sentinel: - assert( *gdcmMD5DataImages[ Testing::GetNumberOfMD5DataImages() ] == nullptr ); + gdcm_assert( *gdcmMD5DataImages[ Testing::GetNumberOfMD5DataImages() ] == nullptr ); return gdcmMD5DataImages[ Testing::GetNumberOfMD5DataImages() ]; } @@ -141,7 +141,7 @@ const char * Testing::GetMD5FromFile(const char *filepath) p = md5s[i][1]; } // \postcondition always valid (before sentinel) - assert( i <= GetNumberOfMD5DataImages() ); + gdcm_assert( i <= GetNumberOfMD5DataImages() ); return md5s[i][0]; } @@ -471,7 +471,7 @@ int Testing::GetLossyFlagFromFile(const char *filename) std::cerr << "Error: No ref table for: " << filename << std::endl; return -1; } - assert( pfiles->filename ); // need to update ref table + gdcm_assert( pfiles->filename ); // need to update ref table return pfiles->lossyflag; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmTrace.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmTrace.cxx index 177f8400252..cec18f06f31 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmTrace.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/gdcmTrace.cxx @@ -36,7 +36,7 @@ void Trace::SetStreamToFile( const char *filename ) if( !filename ) return; if( UseStreamToFile ) { - assert( FileStream ); + gdcm_assert( FileStream ); FileStream->close(); FileStream = nullptr; UseStreamToFile = false; @@ -45,7 +45,7 @@ void Trace::SetStreamToFile( const char *filename ) if( !out ) return; out->open( filename ); if( !out->good() ) return; - assert( !FileStream && !UseStreamToFile ); + gdcm_assert( !FileStream && !UseStreamToFile ); FileStream = out; UseStreamToFile = true; DebugStream = FileStream; @@ -58,7 +58,7 @@ void Trace::SetStream(std::ostream &os) if( !os.good() ) return; if( UseStreamToFile ) { - assert( FileStream ); + gdcm_assert( FileStream ); FileStream->close(); FileStream = nullptr; UseStreamToFile = false; @@ -114,7 +114,7 @@ Trace::~Trace() { if( UseStreamToFile ) { - assert( FileStream ); + gdcm_forced_assert( FileStream ); FileStream->close(); FileStream = nullptr; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/zipstreamimpl.hpp b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/zipstreamimpl.hpp index 39781c56964..669981e118a 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/zipstreamimpl.hpp +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/Common/zipstreamimpl.hpp @@ -272,7 +272,7 @@ bool basic_zip_streambuf::zip_to_stream( { // copy to the beginning of the stream std::streamsize theDiff = written_byte_size-remainder; - //assert(theDiff > 0 && theDiff < std::numeric_limits::max()); + //gdcm_assert(theDiff > 0 && theDiff < std::numeric_limits::max()); memcpy(&_output_buffer[0], &_output_buffer[(unsigned int)theDiff], remainder); @@ -511,7 +511,7 @@ basic_unzip_streambuf::fill_input_buffer() // Ok so we reached the end of file, since we did not read no header // we have to explicitly tell zlib the compress stream ends, therefore // we add an extra \0 character...it may not always be needed... - assert( nbytesread < (std::streamsize)(_input_buffer.size() / sizeof(char_type)) ); + gdcm_assert( nbytesread < (std::streamsize)(_input_buffer.size() / sizeof(char_type)) ); _input_buffer[ (unsigned int)nbytesread ] = 0; ++nbytesread; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmCSAHeaderDict.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmCSAHeaderDict.h index 2bb32216329..41651afb78f 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmCSAHeaderDict.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmCSAHeaderDict.h @@ -40,7 +40,7 @@ class GDCM_EXPORT CSAHeaderDict //static CSAHeaderDictEntry GroupLengthCSAHeaderDictEntry; // = CSAHeaderDictEntry("Group Length",VR::UL,VM::VM1); CSAHeaderDict():CSAHeaderDictInternal() { - assert( CSAHeaderDictInternal.empty() ); + gdcm_assert( CSAHeaderDictInternal.empty() ); } CSAHeaderDict &operator=(const CSAHeaderDict &_val) = delete; CSAHeaderDict(const CSAHeaderDict &_val) = delete; @@ -57,7 +57,9 @@ class GDCM_EXPORT CSAHeaderDict MapCSAHeaderDictEntry::size_type s = CSAHeaderDictInternal.size(); #endif CSAHeaderDictInternal.insert( de ); - assert( s < CSAHeaderDictInternal.size() ); +#ifndef NDEBUG + gdcm_assert( s < CSAHeaderDictInternal.size() ); +#endif } const CSAHeaderDictEntry &GetCSAHeaderDictEntry(const char *name) const diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDefaultDicts.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDefaultDicts.cxx index cbd2562b1be..29fa7291ca8 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDefaultDicts.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDefaultDicts.cxx @@ -13882,7 +13882,7 @@ void Dict::LoadDefault() { Tag t(n.group, n.element); DictEntry e( n.name, n.keyword, n.vr, n.vm, n.ret ); - assert( DictEntry::CheckKeywordAgainstName(n.name, n.keyword) ); + gdcm_assert( DictEntry::CheckKeywordAgainstName(n.name, n.keyword) ); AddDictEntry( t, e ); n = DICOMV3DataDict[++i]; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDict.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDict.h index a51e17790a6..ca34d7ec705 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDict.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDict.h @@ -50,7 +50,7 @@ class GDCM_EXPORT Dict //static DictEntry GroupLengthDictEntry; // = DictEntry("Group Length",VR::UL,VM::VM1); Dict():DictInternal() { - assert( DictInternal.empty() ); + gdcm_assert( DictInternal.empty() ); } Dict &operator=(const Dict &_val) = delete; Dict(const Dict &_val) = delete; @@ -69,7 +69,9 @@ class GDCM_EXPORT Dict #endif DictInternal.insert( MapDictEntry::value_type(tag, de)); - assert( s < DictInternal.size() ); +#ifndef NDEBUG + gdcm_assert( s < DictInternal.size() ); +#endif } const DictEntry &GetDictEntry(const Tag &tag) const @@ -92,13 +94,13 @@ class GDCM_EXPORT Dict && tag != Tag(0x40,0xa125) ) { - assert( 0 && "Impossible" ); + gdcm_assert( 0 && "Impossible" ); } #endif it = DictInternal.find( Tag(0xffff,0xffff) ); return it->second; } - assert( DictInternal.count(tag) == 1 ); + gdcm_assert( DictInternal.count(tag) == 1 ); return it->second; } @@ -111,7 +113,7 @@ class GDCM_EXPORT Dict { return nullptr; } - assert( DictInternal.count(tag) == 1 ); + gdcm_assert( DictInternal.count(tag) == 1 ); return it->second.GetKeyword(); } @@ -145,7 +147,7 @@ class GDCM_EXPORT Dict it = DictInternal.find( tag ); return it->second; } - assert( DictInternal.count(tag) == 1 ); + gdcm_assert( DictInternal.count(tag) == 1 ); return it->second; } @@ -178,7 +180,7 @@ class GDCM_EXPORT Dict it = DictInternal.find( tag ); return it->second; } - assert( DictInternal.count(tag) == 1 ); + gdcm_assert( DictInternal.count(tag) == 1 ); return it->second; } @@ -234,23 +236,25 @@ class GDCM_EXPORT PrivateDict { MapDictEntry::iterator it = DictInternal.find(tag); - assert( it != DictInternal.end() ); + gdcm_assert( it != DictInternal.end() ); DictEntry &duplicate = it->second; - assert( de.GetVR() == VR::UN || duplicate.GetVR() == VR::UN ); - assert( de.GetVR() != duplicate.GetVR() ); + gdcm_assert( de.GetVR() == VR::UN || duplicate.GetVR() == VR::UN ); + gdcm_assert( de.GetVR() != duplicate.GetVR() ); if( duplicate.GetVR() == VR::UN ) { - assert( de.GetVR() != VR::UN ); + gdcm_assert( de.GetVR() != VR::UN ); duplicate.SetVR( de.GetVR() ); duplicate.SetVM( de.GetVM() ); - assert( GetDictEntry(tag).GetVR() != VR::UN ); - assert( GetDictEntry(tag).GetVR() == de.GetVR() ); - assert( GetDictEntry(tag).GetVM() == de.GetVM() ); + gdcm_assert( GetDictEntry(tag).GetVR() != VR::UN ); + gdcm_assert( GetDictEntry(tag).GetVR() == de.GetVR() ); + gdcm_assert( GetDictEntry(tag).GetVM() == de.GetVM() ); } return; } #endif - assert( s < DictInternal.size() /*&& std::cout << tag << "," << de << std::endl*/ ); +#ifndef NDEBUG + gdcm_assert( s < DictInternal.size() /*&& std::cout << tag << "," << de << std::endl*/ ); +#endif } /// Remove entry 'tag'. Return true on success (element was found /// and remove). return false if element was not found. @@ -258,7 +262,7 @@ class GDCM_EXPORT PrivateDict { MapDictEntry::size_type s = DictInternal.erase(tag); - assert( s == 1 || s == 0 ); + gdcm_assert( s == 1 || s == 0 ); return s == 1; } bool FindDictEntry(const PrivateTag &tag) const @@ -278,12 +282,12 @@ class GDCM_EXPORT PrivateDict DictInternal.find(tag); if (it == DictInternal.end()) { - //assert( 0 && "Impossible" ); + //gdcm_assert( 0 && "Impossible" ); it = DictInternal.find( PrivateTag(0xffff,0xffff,"GDCM Private Sentinel" ) ); assert (it != DictInternal.end()); return it->second; } - assert( DictInternal.count(tag) == 1 ); + gdcm_assert( DictInternal.count(tag) == 1 ); return it->second; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDictConverter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDictConverter.cxx index 9792abec61d..ba2c645c059 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDictConverter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDictConverter.cxx @@ -153,7 +153,7 @@ void DictConverter::Convert() } } else - assert(0); + gdcm_assert(0); } else if ( line[7] == 'x' && line[8] == 'x' ) { @@ -179,7 +179,7 @@ void DictConverter::Convert() } } else - assert(0); + gdcm_assert(0); } else { @@ -206,7 +206,7 @@ bool DictConverter::ReadVR(const char *raw, VR::VRType &type) ++i; std::string vm(raw, raw+i-1); type = VR::GetVRType(vm.c_str()); - assert( type != VR::VR_END ); + gdcm_assert( type != VR::VR_END ); return true; } @@ -214,9 +214,9 @@ bool DictConverter::ReadVM(const char *raw, VM::VMType &type) { char vm[8]; int r = sscanf(raw, "%s", vm); - assert( r == 1 ); + gdcm_assert( r == 1 ); type = VM::GetVMType(vm); - assert( type != VM::VM_END ); + gdcm_assert( type != VM::VM_END ); return true; } @@ -224,11 +224,11 @@ bool DictConverter::Readuint16(const char *raw, uint16_t &ov) { unsigned int v; int r = sscanf(raw, "%04x", &v); - assert( r == 1 && "Wrong Value read for uint16"); + gdcm_assert( r == 1 && "Wrong Value read for uint16"); char sv[4+1]; r = snprintf(sv, sizeof(sv), "%04x", v); - assert( r == 4 && "Wrong Value printed for uint16"); - assert( strncmp(raw, sv, 4) == 0 ); + gdcm_assert( r == 4 && "Wrong Value printed for uint16"); + gdcm_assert( strncmp(raw, sv, 4) == 0 ); ov = v; return true; } @@ -302,7 +302,7 @@ bool DictConverter::ConvertToXML(const char *raw, std::string &cxx) VR::VRType vr; VM::VMType vm; Readuint16(raw, group); - assert( !(group%2) ); + gdcm_assert( !(group%2) ); Readuint16(raw+5, element); ReadVR(raw+10, vr); int len = 11+strlen(VR::GetVRString(vr)); @@ -331,7 +331,7 @@ bool DictConverter::ConvertToCXX(const char *raw, std::string &cxx) VR::VRType vr; VM::VMType vm; Readuint16(raw, group); - //assert( !(group%2) ); + //gdcm_assert( !(group%2) ); // Readuint16(raw+5, element); ReadVR(raw+10, vr); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDicts.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDicts.cxx index 4bd3ff38e97..7b500f294b0 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDicts.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmDicts.cxx @@ -55,12 +55,12 @@ const DictEntry &Dicts::GetDictEntry(const Tag& tag, const char *owner) const } else if( tag.IsPublic() ) { - assert( owner == nullptr ); + gdcm_assert( owner == nullptr ); return PublicDict.GetDictEntry(tag); } else { - assert( tag.IsPrivate() ); + gdcm_assert( tag.IsPrivate() ); if( owner && *owner ) { size_t len = strlen(owner); (void)len; @@ -78,10 +78,10 @@ const DictEntry &Dicts::GetDictEntry(const Tag& tag, const char *owner) const } else if( tag.IsPrivateCreator() ) { - assert( !tag.IsIllegal() ); - assert( tag.GetElement() ); // Not a group length ! - assert( tag.IsPrivate() ); - assert( owner == nullptr ); + gdcm_assert( !tag.IsIllegal() ); + gdcm_assert( tag.GetElement() ); // Not a group length ! + gdcm_assert( tag.IsPrivate() ); + gdcm_assert( owner == nullptr ); static const DictEntry Dummy("Private Creator", "PrivateCreator", VR::LO, VM::VM1, false); return Dummy; } @@ -109,7 +109,7 @@ const char *Dicts::GetConstructorString(ConstructorType type) const Dict &Dicts::GetPublicDict() const { - //assert( PublicType < PublicDicts.size() ); + //gdcm_assert( PublicType < PublicDicts.size() ); return PublicDict; //[PublicType]; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmGlobal.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmGlobal.cxx index 04f423719a0..efa45038d12 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmGlobal.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmGlobal.cxx @@ -44,7 +44,7 @@ class GlobalInternal // - on some system where it make sense the path where the Resource should be located void LoadDefaultPaths() { - assert( ResourcePaths.empty() ); + gdcm_assert( ResourcePaths.empty() ); const char filename2[] = GDCM_CMAKE_INSTALL_PREFIX "/" GDCM_INSTALL_DATA_DIR "/XML/"; ResourcePaths.emplace_back(filename2 ); const char filename3[] = GDCM_CMAKE_INSTALL_PREFIX " " GDCM_API_VERSION "/" GDCM_INSTALL_DATA_DIR "/XML/"; @@ -76,14 +76,14 @@ Global::Global() { if(++GlobalCount == 1) { - assert( Internals == nullptr ); // paranoid + gdcm_assert( Internals == nullptr ); // paranoid Internals = new GlobalInternal; - assert( Internals->GlobalDicts.IsEmpty() ); + gdcm_assert( Internals->GlobalDicts.IsEmpty() ); // Fill in with default values now ! // at startup time is safer as later call might be from different thread // thus initialization of std::map would be all skrew up Internals->GlobalDicts.LoadDefaults(); - assert( Internals->GlobalDefs.IsEmpty() ); + gdcm_assert( Internals->GlobalDefs.IsEmpty() ); // Same goes for GlobalDefs: //Internals->GlobalDefs.LoadDefaults(); //Internals->LoadDefaultPaths(); @@ -102,7 +102,7 @@ Global::~Global() bool Global::LoadResourcesFiles() { - assert( Internals != nullptr ); // paranoid + gdcm_assert( Internals != nullptr ); // paranoid const char *filename = Locate( "Part3.xml" ); if( filename ) { @@ -171,19 +171,19 @@ const char *Global::Locate(const char *resfile) const Dicts const &Global::GetDicts() const { - assert( !Internals->GlobalDicts.IsEmpty() ); + gdcm_assert( !Internals->GlobalDicts.IsEmpty() ); return Internals->GlobalDicts; } Dicts &Global::GetDicts() { - assert( !Internals->GlobalDicts.IsEmpty() ); + gdcm_assert( !Internals->GlobalDicts.IsEmpty() ); return Internals->GlobalDicts; } Defs const &Global::GetDefs() const { - assert( !Internals->GlobalDefs.IsEmpty() ); + gdcm_assert( !Internals->GlobalDefs.IsEmpty() ); return Internals->GlobalDefs; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmGroupDict.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmGroupDict.cxx index 3083bbda6e1..9217b1993ea 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmGroupDict.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmGroupDict.cxx @@ -18,13 +18,13 @@ namespace gdcm std::string const &GroupDict::GetAbbreviation(uint16_t num) const { - assert(num < Abbreviations.size()); + gdcm_assert(num < Abbreviations.size()); return Abbreviations[num]; } std::string const &GroupDict::GetName(uint16_t num) const { - assert(num < Names.size()); + gdcm_assert(num < Names.size()); return Names[num]; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmGroupDict.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmGroupDict.h index a6e924e078a..e3dab4ec748 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmGroupDict.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmGroupDict.h @@ -41,7 +41,7 @@ class GDCM_EXPORT GroupDict size_t Size() const { - assert( Names.size() == Abbreviations.size() ); + gdcm_assert( Names.size() == Abbreviations.size() ); return Names.size(); } std::string const &GetAbbreviation(uint16_t num) const; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmPrivateDefaultDicts.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmPrivateDefaultDicts.cxx index 7e90d3c417b..92a7cdc4ce3 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmPrivateDefaultDicts.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmPrivateDefaultDicts.cxx @@ -38,6 +38,17 @@ using DICT_ENTRY = struct }; static const DICT_ENTRY DICOMV3DataDict [] = { + {0x0033,0x0001,"KONICA MINOLTA QA 1.4",VR::SQ,VM::VM1,"?Possibly PHI?",false }, + {0x0033,0x0004,"KONICA MINOLTA QA 1.4",VR::SS,VM::VM1,"?",false }, + {0x0033,0x0006,"KONICA MINOLTA QA 1.4",VR::SS,VM::VM1,"?",false }, + {0x0033,0x0008,"KONICA MINOLTA QA 1.4",VR::SS,VM::VM1,"?",false }, + {0x0033,0x0010,"KONICA MINOLTA QA 1.4",VR::SS,VM::VM1,"?",false }, + {0x0033,0x0011,"KONICA MINOLTA QA 1.4",VR::SS,VM::VM1,"?",false }, + {0x0033,0x0014,"KONICA MINOLTA QA 1.4",VR::SS,VM::VM1,"?",false }, + {0x0033,0x0016,"KONICA MINOLTA QA 1.4",VR::SS,VM::VM1,"?",false }, + {0x0049,0x0010,"AIR",VR::LO,VM::VM1,"?Possibly PHI?",false }, + {0x0049,0x0011,"AIR",VR::LO,VM::VM1,"?number?",false }, + {0x0049,0x0013,"AIR",VR::LT,VM::VM1,"?Long desc possibly PHI?",false }, {0x0021,0x0010,"SIEMENS MR FMRI",VR::SQ,VM::VM1,"?",false }, {0x0021,0x0011,"SIEMENS MR FMRI",VR::LO,VM::VM1,"?",false }, {0x0021,0x0012,"SIEMENS MR FMRI",VR::SQ,VM::VM1,"?",false }, @@ -1156,9 +1167,12 @@ static const DICT_ENTRY DICOMV3DataDict [] = { {0x2013,0x0007,"BioClinicaImagingSegmentGroup",VR::OB,VM::VM1,"Custom Storage Segment Blob #7",false}, {0x2013,0x0008,"BioClinicaImagingSegmentGroup",VR::OB,VM::VM1,"Custom Storage Segment Blob #8",false}, {0x2013,0x0009,"BioClinicaImagingSegmentGroup",VR::OB,VM::VM1,"Custom Storage Segment Blob #9",false}, - {0x7fe1,0x0001,"Bioclinica",VR::UT,VM::VM1,"??",false}, - {0x7fe1,0x0002,"Bioclinica",VR::LO,VM::VM1,"??",false}, - {0x7fe1,0x0003,"Bioclinica",VR::LO,VM::VM1,"??",false}, + {0x2213,0x0001,"Clario",VR::UT,VM::VM1,"AES tag",false}, + {0x2213,0x0002,"Clario",VR::LO,VM::VM1,"PX version",false}, + {0x2213,0x0003,"Clario",VR::LO,VM::VM1,"Mask Name",false}, + {0x7fe1,0x0001,"Bioclinica",VR::UT,VM::VM1,"AES tag",false}, + {0x7fe1,0x0002,"Bioclinica",VR::LO,VM::VM1,"PX version",false}, + {0x7fe1,0x0003,"Bioclinica",VR::LO,VM::VM1,"Mask Name",false}, {0x5533,0x0033,"Visus Change",VR::SQ,VM::VM1,"Visus Data Save Sequence",false}, {0x5533,0x0035,"Visus Change",VR::DA,VM::VM1,"Visus Data Save Date",false}, {0x5533,0x0037,"Visus Change",VR::LO,VM::VM1,"Visus Data Save Originator",false}, @@ -5871,25 +5885,25 @@ static const DICT_ENTRY DICOMV3DataDict [] = { {0x0033,0x0008,"MITRA OBJECT ATTRIBUTES 1.0",VR::LO,VM::VM1,"?",false }, {0x0033,0x000a,"MITRA OBJECT ATTRIBUTES 1.0",VR::LO,VM::VM1,"?",false }, // {0x0029,0x0000,"MITRA OBJECT DOCUMENT 1.0",VR::OB,VM::VM1,"?",false }, - {0x0033,0x0002,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Patient's Name",false }, - {0x0033,0x0004,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::CS,VM::VM1,"Study Description",false }, - {0x0033,0x0006,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Referring Physician's Name",false }, - {0x0033,0x0008,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Requesting Physician's Name",false }, - {0x0033,0x000a,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Performing Physician's Name",false }, - {0x0033,0x000c,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::LO,VM::VM1,"Reason for Study",false }, - {0x0033,0x000e,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::LT,VM::VM1,"Study Comments",false }, - {0x0033,0x0013,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Patient's Name Single Byte",false }, - {0x0033,0x0014,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Patient's Name Ideographic",false }, - {0x0033,0x0015,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Patient's Name Phonetic",false }, - {0x0033,0x0016,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Referring Physician's Name Single Byte",false }, - {0x0033,0x0017,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Referring Physician's Name Ideographic",false }, - {0x0033,0x0018,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Referring Physician's Name Phonetic",false }, - {0x0033,0x0019,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Requesting Physician's Name Single Byte",false }, - {0x0033,0x001a,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Requesting Physician's Name Ideographic",false }, - {0x0033,0x001b,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Requesting Physician's Name Phonetic",false }, - {0x0033,0x001c,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Performing Physician's Name Single Byte",false }, - {0x0033,0x001d,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Performing Physician's Name Ideographic",false }, - {0x0033,0x001e,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::PN,VM::VM1,"Performing Physician's Name Phonetic",false }, + {0x0033,0x0002,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Patient's Name",false }, + {0x0033,0x0004,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Study Description",false }, + {0x0033,0x0006,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Referring Physician's Name",false }, + {0x0033,0x0008,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Requesting Physician's Name",false }, + {0x0033,0x000a,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Performing Physician's Name",false }, + {0x0033,0x000c,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Reason for Study",false }, + {0x0033,0x000e,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Study Comments",false }, + {0x0033,0x0013,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Patient's Name Single Byte",false }, + {0x0033,0x0014,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Patient's Name Ideographic",false }, + {0x0033,0x0015,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Patient's Name Phonetic",false }, + {0x0033,0x0016,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Referring Physician's Name Single Byte",false }, + {0x0033,0x0017,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Referring Physician's Name Ideographic",false }, + {0x0033,0x0018,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Referring Physician's Name Phonetic",false }, + {0x0033,0x0019,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Requesting Physician's Name Single Byte",false }, + {0x0033,0x001a,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Requesting Physician's Name Ideographic",false }, + {0x0033,0x001b,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Requesting Physician's Name Phonetic",false }, + {0x0033,0x001c,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Performing Physician's Name Single Byte",false }, + {0x0033,0x001d,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Performing Physician's Name Ideographic",false }, + {0x0033,0x001e,"MITRA OBJECT UTF8 ATTRIBUTES 1.0",VR::UN,VM::VM1,"Performing Physician's Name Phonetic",false }, {0x0029,0x0000,"MITRA PRESENTATION 1.0",VR::CS,VM::VM1,"Mitra Rotation",false }, {0x0029,0x0001,"MITRA PRESENTATION 1.0",VR::LO,VM::VM1,"Mitra Window Width",false }, {0x0029,0x0002,"MITRA PRESENTATION 1.0",VR::LO,VM::VM1,"Mitra Window Centre",false }, @@ -10999,7 +11013,7 @@ static const DICT_ENTRY DICOMV3DataDict [] = { {0x0019,0x0078,"SVISION",VR::DS,VM::VM1,"Filter Thickness 1",false }, {0x0019,0x0079,"SVISION",VR::DS,VM::VM1,"Filter Thickness 2",false }, {0x0019,0x0080,"SVISION",VR::IS,VM::VM1,"Bucky Format",false }, - {0x0019,0x0081,"SVISION",VR::IS,VM::VM1,"Object Position",false }, + {0x0019,0x0081,"SVISION",VR::LO,VM::VM1,"Object Position",false }, {0x0019,0x0090,"SVISION",VR::LO,VM::VM1,"Desk Command",false }, {0x0019,0x0091,"SVISION",VR::IS,VM::VM1,"Central Beam X",false }, {0x0019,0x0092,"SVISION",VR::IS,VM::VM1,"Central Beam Y",false }, @@ -11994,7 +12008,7 @@ void Dict::LoadDefault() { if( n.group % 2 == 0 ) { - assert( n.owner == 0 ); + gdcm_assert( n.owner == 0 ); Tag t(n.group, n.element); DictEntry e( n.name, n.vr, n.vm, n.ret ); AddDictEntry( t, e ); @@ -12012,10 +12026,10 @@ void PrivateDict::LoadDefault() { // if( n.group % 2 != 0 ) { - assert( n.owner != nullptr ); - assert( n.name ); - assert( n.group % 2 != 0 || n.group == 0xffff ); - assert( n.element <= 0xff || n.element == 0xffff ); + gdcm_assert( n.owner != nullptr ); + gdcm_assert( n.name ); + gdcm_assert( n.group % 2 != 0 || n.group == 0xffff ); + gdcm_assert( n.element <= 0xff || n.element == 0xffff ); PrivateTag t(n.group, n.element,n.owner); DictEntry e( n.name, "", n.vr, n.vm, n.ret ); AddDictEntry( t, e ); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmSOPClassUIDToIOD.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmSOPClassUIDToIOD.cxx index 8644a8ab590..5a69ae425b5 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmSOPClassUIDToIOD.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmSOPClassUIDToIOD.cxx @@ -135,7 +135,7 @@ namespace gdcm unsigned int SOPClassUIDToIOD::GetNumberOfSOPClassToIOD() { static const unsigned int n = sizeof( SOPClassUIDToIODStrings ) / sizeof( *SOPClassUIDToIODStrings ); - assert( n > 0 ); + gdcm_assert( n > 0 ); return n - 1; } @@ -153,7 +153,7 @@ const char *SOPClassUIDToIOD::GetIOD(UIDs const & uid) // int ret = 0; // do { // is.read(buf, sizeof(buf)); -// size_t len = is.gcount(); +// std::streamsize len = is.gcount(); // done = len < sizeof(buf); // if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR) { // fprintf(stderr, @@ -188,7 +188,7 @@ SOPClassUIDToIOD::SOPClassUIDToIODType& SOPClassUIDToIOD::GetSOPClassUIDToIOD(un if( i < SOPClassUIDToIOD::GetNumberOfSOPClassToIOD() ) return SOPClassUIDToIODStrings[i]; // else return the {0x0, 0x0} sentinel: - assert( *SOPClassUIDToIODStrings[ SOPClassUIDToIOD::GetNumberOfSOPClassToIOD() ] == nullptr ); + gdcm_assert( *SOPClassUIDToIODStrings[ SOPClassUIDToIOD::GetNumberOfSOPClassToIOD() ] == nullptr ); return SOPClassUIDToIODStrings[ SOPClassUIDToIOD::GetNumberOfSOPClassToIOD() ]; } @@ -209,7 +209,7 @@ const char *SOPClassUIDToIOD::GetSOPClassUIDFromIOD(const char *iod) p = sopclassuidtoiods[i][1]; } // \postcondition always valid (before sentinel) - assert( i <= GetNumberOfSOPClassToIOD() ); + gdcm_assert( i <= GetNumberOfSOPClassToIOD() ); return sopclassuidtoiods[i][0]; } @@ -229,7 +229,7 @@ const char *SOPClassUIDToIOD::GetIODFromSOPClassUID(const char *sopclassuid) p = sopclassuidtoiods[i][0]; } // \postcondition always valid (before sentinel) - assert( i <= GetNumberOfSOPClassToIOD() ); + gdcm_assert( i <= GetNumberOfSOPClassToIOD() ); return sopclassuidtoiods[i][1]; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmUIDs.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmUIDs.cxx index c43e24d6af1..2a5308f1429 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmUIDs.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmUIDs.cxx @@ -511,8 +511,8 @@ const char * const * UIDs::GetTransferSyntaxString(unsigned int ts) { if( ts > 0 && ts <= UIDs::GetNumberOfTransferSyntaxStrings() ) return TransferSyntaxStrings[ts]; // else return the {0x0, 0x0} sentinel (begin or end) - assert( *TransferSyntaxStrings[ UIDs::GetNumberOfTransferSyntaxStrings() + 1 ] == nullptr ); - assert( *TransferSyntaxStrings[ 0 ] == nullptr ); + gdcm_assert( *TransferSyntaxStrings[ UIDs::GetNumberOfTransferSyntaxStrings() + 1 ] == nullptr ); + gdcm_assert( *TransferSyntaxStrings[ 0 ] == nullptr ); return TransferSyntaxStrings[ UIDs::GetNumberOfTransferSyntaxStrings() + 1 ]; } @@ -553,11 +553,11 @@ bool UIDs::SetFromUID(const char *str) if( p ) { TSField = TSType(i); - assert( TSField != (TSType)0 ); + gdcm_assert( TSField != (TSType)0 ); return true; } - assert( TSField == (TSType)0 ); + gdcm_assert( TSField == (TSType)0 ); return false; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmUIDs.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmUIDs.h index c440d909289..b56fa4e0e99 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmUIDs.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/gdcmUIDs.h @@ -991,6 +991,7 @@ Private_1_3_46_670589_33_1_4_1 const char *GetString() const; operator TSType () const { return TSField; } + UIDs() = default; private: TSType TSField; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/privatedicts.xml b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/privatedicts.xml index 473e943f3d0..cbed3235681 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/privatedicts.xml +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary/privatedicts.xml @@ -5140,25 +5140,25 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/CMakeLists.txt b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/CMakeLists.txt index b12a2b62bae..18a5fa4c98c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/CMakeLists.txt +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/CMakeLists.txt @@ -85,7 +85,7 @@ if(NOT GDCM_USE_SYSTEM_ZLIB) endif() add_library(gdcmDSED ${DSED_SRCS} ${DSED3_SRCS}) -#target_compile_features(gdcmDSED PUBLIC cxx_strong_enums) +target_compile_features(gdcmDSED PUBLIC cxx_strong_enums) target_link_libraries(gdcmDSED LINK_PUBLIC gdcmCommon) # zlib stuff are actually included (template) so we need to link them here. target_link_libraries(gdcmDSED LINK_PRIVATE ${GDCM_ZLIB_LIBRARIES}) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmAttribute.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmAttribute.h index 2829603aed4..bd2f04a1e3f 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmAttribute.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmAttribute.h @@ -125,7 +125,7 @@ class Attribute // copy: //ArrayType GetValue(unsigned int idx = 0) { - // assert( idx < GetNumberOfValues() ); + // gdcm_assert( idx < GetNumberOfValues() ); // return Internal[idx]; //} //ArrayType operator[] (unsigned int idx) { @@ -152,7 +152,7 @@ class Attribute } ArrayType &GetValue(unsigned int idx = 0) { - assert( idx < GetNumberOfValues() ); + gdcm_assert( idx < GetNumberOfValues() ); return Internal[idx]; } ArrayType & operator[] (unsigned int idx) { @@ -160,18 +160,18 @@ class Attribute } // const reference ArrayType const &GetValue(unsigned int idx = 0) const { - assert( idx < GetNumberOfValues() ); + gdcm_assert( idx < GetNumberOfValues() ); return Internal[idx]; } ArrayType const & operator[] (unsigned int idx) const { return GetValue(idx); } void SetValue(ArrayType v, unsigned int idx = 0) { - assert( idx < GetNumberOfValues() ); + gdcm_assert( idx < GetNumberOfValues() ); Internal[idx] = v; } void SetValues(const ArrayType* array, unsigned int numel = VMType ) { - assert( array && numel && numel == GetNumberOfValues() ); + gdcm_assert( array && numel && numel == GetNumberOfValues() ); // std::copy is smarted than a memcpy, and will call memcpy when POD type std::copy(array, array+numel, Internal); } @@ -187,7 +187,7 @@ class Attribute EncodingImplementation::Mode>::Write(Internal, GetNumberOfValues(),os); ret.SetVR( GetVR() ); - assert( ret.GetVR() != VR::SQ ); + gdcm_assert( ret.GetVR() != VR::SQ ); if( (VR::VRType)VRToEncoding::Mode == VR::VRASCII ) { if( GetVR() != VR::UI ) @@ -205,9 +205,9 @@ class Attribute void SetFromDataElement(DataElement const &de) { // This is kind of hackish but since I do not generate other element than the first one: 0x6000 I should be ok: - assert( Tag(Group,Element) == de.GetTag() || Group == 0x6000 || Group == 0x5000 ); - assert( GetVR() != VR::INVALID ); - assert( GetVR().Compatible( de.GetVR() ) || de.GetVR() == VR::INVALID ); // In case of VR::INVALID cannot use the & operator + gdcm_assert( Tag(Group,Element) == de.GetTag() || Group == 0x6000 || Group == 0x5000 ); + gdcm_assert( GetVR() != VR::INVALID ); + gdcm_assert( GetVR().Compatible( de.GetVR() ) || de.GetVR() == VR::INVALID ); // In case of VR::INVALID cannot use the & operator if( de.IsEmpty() ) return; const ByteValue *bv = de.GetByteValue(); #ifdef GDCM_WORDS_BIGENDIAN @@ -236,7 +236,7 @@ class Attribute protected: void SetByteValueNoSwap(const ByteValue *bv) { if( !bv ) return; // That would be bad... - assert( bv->GetPointer() && bv->GetLength() ); // [123]C element can be empty + gdcm_assert( bv->GetPointer() && bv->GetLength() ); // [123]C element can be empty //if( VRToEncoding::Mode == VR::VRBINARY ) // { // // always do a copy ! @@ -253,7 +253,7 @@ class Attribute } void SetByteValue(const ByteValue *bv) { if( !bv ) return; // That would be bad... - assert( bv->GetPointer() && bv->GetLength() ); // [123]C element can be empty + gdcm_assert( bv->GetPointer() && bv->GetLength() ); // [123]C element can be empty //if( VRToEncoding::Mode == VR::VRBINARY ) // { // // always do a copy ! @@ -274,7 +274,7 @@ class Attribute const uint16_t cref[] = { Group, Element }; uint16_t c[2]; _is.read((char*)&c, sizeof(c)); - assert( c[0] == cref[0] && c[1] == cref[1] ); + gdcm_assert( c[0] == cref[0] && c[1] == cref[1] ); char vr[2]; _is.read(vr, 2); // Check consistency ? const uint32_t lref = GetLength() * sizeof( typename VRToType::Type ); @@ -357,7 +357,7 @@ class Attribute } // copy: //ArrayType GetValue(unsigned int idx = 0) { - // assert( idx < GetNumberOfValues() ); + // gdcm_assert( idx < GetNumberOfValues() ); // return Internal[idx]; //} //ArrayType operator[] (unsigned int idx) { @@ -384,7 +384,7 @@ class Attribute } ArrayType &GetValue() { -// assert( idx < GetNumberOfValues() ); +// gdcm_assert( idx < GetNumberOfValues() ); return Internal; } // ArrayType & operator[] (unsigned int idx) { @@ -392,18 +392,18 @@ class Attribute // } // const reference ArrayType const &GetValue() const { - //assert( idx < GetNumberOfValues() ); + //gdcm_assert( idx < GetNumberOfValues() ); return Internal; } //ArrayType const & operator[] () const { // return GetValue(); //} void SetValue(ArrayType v) { -// assert( idx < GetNumberOfValues() ); +// gdcm_assert( idx < GetNumberOfValues() ); Internal = v; } /* void SetValues(const ArrayType* array, unsigned int numel = VMType ) { - assert( array && numel && numel == GetNumberOfValues() ); + gdcm_assert( array && numel && numel == GetNumberOfValues() ); // std::copy is smarted than a memcpy, and will call memcpy when POD type std::copy(array, array+numel, Internal); } @@ -422,7 +422,7 @@ class Attribute EncodingImplementation::Mode>::Write(&Internal, GetNumberOfValues(),os); ret.SetVR( GetVR() ); - assert( ret.GetVR() != VR::SQ ); + gdcm_assert( ret.GetVR() != VR::SQ ); if( (VR::VRType)VRToEncoding::Mode == VR::VRASCII ) { if( GetVR() != VR::UI ) @@ -440,9 +440,9 @@ class Attribute void SetFromDataElement(DataElement const &de) { // This is kind of hackish but since I do not generate other element than the first one: 0x6000 I should be ok: - assert( Tag(Group,Element) == de.GetTag() || Group == 0x6000 || Group == 0x5000 ); - assert( GetVR() != VR::INVALID ); - assert( GetVR().Compatible( de.GetVR() ) || de.GetVR() == VR::INVALID ); // In case of VR::INVALID cannot use the & operator + gdcm_assert( Tag(Group,Element) == de.GetTag() || Group == 0x6000 || Group == 0x5000 ); + gdcm_assert( GetVR() != VR::INVALID ); + gdcm_assert( GetVR().Compatible( de.GetVR() ) || de.GetVR() == VR::INVALID ); // In case of VR::INVALID cannot use the & operator if( de.IsEmpty() ) return; const ByteValue *bv = de.GetByteValue(); #ifdef GDCM_WORDS_BIGENDIAN @@ -471,7 +471,7 @@ class Attribute protected: void SetByteValueNoSwap(const ByteValue *bv) { if( !bv ) return; // That would be bad... - assert( bv->GetPointer() && bv->GetLength() ); // [123]C element can be empty + gdcm_assert( bv->GetPointer() && bv->GetLength() ); // [123]C element can be empty //if( VRToEncoding::Mode == VR::VRBINARY ) // { // // always do a copy ! @@ -488,7 +488,7 @@ class Attribute } void SetByteValue(const ByteValue *bv) { if( !bv ) return; // That would be bad... - assert( bv->GetPointer() && bv->GetLength() ); // [123]C element can be empty + gdcm_assert( bv->GetPointer() && bv->GetLength() ); // [123]C element can be empty //if( VRToEncoding::Mode == VR::VRBINARY ) // { // // always do a copy ! @@ -509,7 +509,7 @@ class Attribute const uint16_t cref[] = { Group, Element }; uint16_t c[2]; _is.read((char*)&c, sizeof(c)); - assert( c[0] == cref[0] && c[1] == cref[1] ); + gdcm_assert( c[0] == cref[0] && c[1] == cref[1] ); char vr[2]; _is.read(vr, 2); // Check consistency ? const uint32_t lref = GetLength() * sizeof( typename VRToType::Type ); @@ -598,7 +598,7 @@ class Attribute os << "," << Internal[i]; } ArrayType &GetValue(unsigned int idx = 0) { - assert( idx < GetNumberOfValues() ); + gdcm_assert( idx < GetNumberOfValues() ); return Internal[idx]; } ArrayType &operator[] (unsigned int idx) { @@ -606,14 +606,14 @@ class Attribute } // const reference ArrayType const &GetValue(unsigned int idx = 0) const { - assert( idx < GetNumberOfValues() ); + gdcm_assert( idx < GetNumberOfValues() ); return Internal[idx]; } ArrayType const & operator[] (unsigned int idx) const { return GetValue(idx); } void SetValue(unsigned int idx, ArrayType v) { - assert( idx < GetNumberOfValues() ); + gdcm_assert( idx < GetNumberOfValues() ); Internal[idx] = v; } void SetValue(ArrayType v) { SetValue(0, v); } @@ -628,7 +628,7 @@ class Attribute } Own = own; Length = numel; - assert( Internal == nullptr ); + gdcm_assert( Internal == nullptr ); if( own ) // make a copy: { Internal = new ArrayType[numel]; @@ -640,7 +640,7 @@ class Attribute Internal = const_cast(array); } // postcondition - assert( numel == GetNumberOfValues() ); + gdcm_assert( numel == GetNumberOfValues() ); } DataElement GetAsDataElement() const { @@ -662,17 +662,17 @@ class Attribute } } ret.SetVR( GetVR() ); - assert( ret.GetVR() != VR::SQ ); + gdcm_assert( ret.GetVR() != VR::SQ ); VL::Type osStrSize = (VL::Type) os.str().size(); ret.SetByteValue( os.str().c_str(), osStrSize); return ret; } void SetFromDataElement(DataElement const &de) { // This is kind of hackish but since I do not generate other element than the first one: 0x6000 I should be ok: - assert( GetTag() == de.GetTag() || GetTag().GetGroup() == 0x6000 + gdcm_assert( GetTag() == de.GetTag() || GetTag().GetGroup() == 0x6000 || GetTag().GetGroup() == 0x5000 ); - assert( GetVR().Compatible( de.GetVR() ) ); // In case of VR::INVALID cannot use the & operator - assert( !de.IsEmpty() ); + gdcm_assert( GetVR().Compatible( de.GetVR() ) ); // In case of VR::INVALID cannot use the & operator + gdcm_assert( !de.IsEmpty() ); const ByteValue *bv = de.GetByteValue(); SetByteValue(bv); } @@ -688,7 +688,7 @@ class Attribute } protected: void SetByteValue(const ByteValue *bv) { - assert( bv ); // FIXME + gdcm_assert( bv ); // FIXME std::stringstream ss; std::string s = std::string( bv->GetPointer(), bv->GetLength() ); Length = bv->GetLength(); // HACK FIXME @@ -787,7 +787,7 @@ class Attribute Internal[i] = sarray.substr(pos1, pos2-pos1); // Shouldn't we do the contrary, since we know how many separators // (and default behavior is to discard anything after the VM declared - assert( GetLength()-1 == i ); + gdcm_assert( GetLength()-1 == i ); } unsigned long GetLength() const { @@ -840,7 +840,7 @@ class Attribute if( len ) { if( len > Length ) { // perform realloc - assert( (len / size) * size == len ); + gdcm_assert( (len / size) * size == len ); ArrayType *internal = new ArrayType[len / size]; memcpy(internal, Internal, Length * size); delete[] Internal; @@ -862,13 +862,13 @@ class Attribute // TODO rewrite this stupid code: Length = len; //Internal = array; - assert(0); + gdcm_assert(0); } } // Implementation of Print is common to all Mode (ASCII/Binary) void Print(std::ostream &_os) const { - assert( Length ); - assert( Internal ); + gdcm_assert( Length ); + gdcm_assert( Internal ); _os << Internal[0]; // VM is at least guarantee to be one const unsigned long length = GetLength() < 25 ? GetLength() : 25; for(unsigned long i=1; iGetLength() == ValueLengthField ); + gdcm_assert( !ValueLengthField.IsUndefined() ); + gdcm_assert( !ValueField || ValueField->GetLength() == ValueLengthField ); return TagField.GetLength() + ValueLengthField.GetLength() + ValueLengthField; } @@ -46,10 +46,10 @@ class GDCM_EXPORT BasicOffsetTable : public Fragment const Tag itemStart(0xfffe, 0xe000); if( !TagField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } - //assert( TagField == itemStart ); + //gdcm_assert( TagField == itemStart ); if( TagField != itemStart ) { // Bug_Siemens_PrivateIconNoItem.dcm @@ -61,7 +61,7 @@ class GDCM_EXPORT BasicOffsetTable : public Fragment } if( !ValueLengthField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } // Self @@ -83,24 +83,24 @@ class GDCM_EXPORT BasicOffsetTable : public Fragment const Tag seqDelItem(0xfffe,0xe0dd); if( !TagField.Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } - assert( TagField == itemStart ); + gdcm_assert( TagField == itemStart ); if( !ValueLengthField.Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } if( ValueLengthField ) { // Self const ByteValue *bv = GetByteValue(); - assert( bv ); - assert( bv->GetLength() == ValueLengthField ); + gdcm_assert( bv ); + gdcm_assert( bv->GetLength() == ValueLengthField ); if( !bv->Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } } @@ -115,7 +115,7 @@ inline std::ostream &operator<<(std::ostream &os, const BasicOffsetTable &val) if( val.ValueField ) { const ByteValue *bv = val.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); os << *bv; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteBuffer.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteBuffer.h index bfe20cda4bb..73e5b96d37d 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteBuffer.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteBuffer.h @@ -82,7 +82,7 @@ class ByteBuffer Start = /*buffer =*/ newBuf; } } - assert( (int)Internal.capacity() >= len ); + gdcm_assert( (int)Internal.capacity() >= len ); return End; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteSwapFilter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteSwapFilter.cxx index 7b1508f7f83..7247423cff5 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteSwapFilter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteSwapFilter.cxx @@ -36,7 +36,7 @@ bool ByteSwapFilter::ByteSwap() { const DataElement &de = *it; VR const & vr = de.GetVR(); - //assert( vr & VR::VRASCII || vr & VR::VRBINARY ); + //gdcm_assert( vr & VR::VRASCII || vr & VR::VRBINARY ); ByteValue *bv = const_cast(de.GetByteValue()); gdcm::SmartPointer si = de.GetValueAsSQ(); if( de.IsEmpty() ) @@ -44,15 +44,15 @@ bool ByteSwapFilter::ByteSwap() } else if( bv && !si ) { - assert( !si ); + gdcm_assert( !si ); // ASCII do not need byte swap if( vr & VR::VRBINARY /*&& de.GetTag().IsPrivate()*/ ) { - //assert( de.GetTag().IsPrivate() ); + //gdcm_assert( de.GetTag().IsPrivate() ); switch(vr) { case VR::AT: - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); break; case VR::FL: // FIXME: Technically FL should not be byte-swapped... @@ -60,22 +60,22 @@ bool ByteSwapFilter::ByteSwap() SwapperDoOp::SwapArray((uint32_t*)bv->GetVoidPointer(), bv->GetLength() / sizeof(uint32_t) ); break; case VR::FD: - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); break; case VR::OB: // I think we are fine, unless this is one of those OB_OW thingy break; case VR::OF: - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); break; case VR::OW: - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); break; case VR::SL: SwapperDoOp::SwapArray((uint32_t*)bv->GetVoidPointer(), bv->GetLength() / sizeof(uint32_t) ); break; case VR::SQ: - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); break; case VR::SS: SwapperDoOp::SwapArray((uint16_t*)bv->GetVoidPointer(), bv->GetLength() / sizeof(uint16_t) ); @@ -84,16 +84,16 @@ bool ByteSwapFilter::ByteSwap() SwapperDoOp::SwapArray((uint32_t*)bv->GetVoidPointer(), bv->GetLength() / sizeof(uint32_t) ); break; case VR::UN: - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); break; case VR::US: SwapperDoOp::SwapArray((uint16_t*)bv->GetVoidPointer(), bv->GetLength() / sizeof(uint16_t) ); break; case VR::UT: - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); break; default: - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); } } } @@ -116,11 +116,11 @@ bool ByteSwapFilter::ByteSwap() else if( const SequenceOfFragments *sf = de.GetSequenceOfFragments() ) { (void)sf; - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); } else { - assert( 0 && "error" ); + gdcm_assert( 0 && "error" ); } } @@ -135,7 +135,6 @@ bool ByteSwapFilter::ByteSwap() de.SetTag( Tag( SwapperDoOp::Swap( tag.GetGroup() ), SwapperDoOp::Swap( tag.GetElement() ) ) ); copy.Insert( de ); - DS.Remove( de.GetTag() ); } DS = copy; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteValue.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteValue.cxx index 432cdde99e6..d253a84c0ed 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteValue.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteValue.cxx @@ -64,7 +64,7 @@ namespace gdcm_ns } // I cannot check IsPrintable some file contains \2 or \0 in a VR::LO element // See: acr_image_with_non_printable_in_0051_1010.acr - //assert( IsPrintable(length) ); + //gdcm_assert( IsPrintable(length) ); std::vector::const_iterator it = Internal.begin(); for(; it != Internal.begin()+length; ++it) { @@ -156,7 +156,7 @@ namespace gdcm_ns else { //in the rare case there are more ^ characters - assert("Name components exceeded"); + gdcm_assert("Name components exceeded"); } } else if ( c == '=' ) @@ -201,7 +201,7 @@ namespace gdcm_ns } else { - assert("Impossible - only 3 names allowed"); + gdcm_assert("Impossible - only 3 names allowed"); } count2=1; } @@ -325,7 +325,7 @@ namespace gdcm_ns Internal.insert( Internal.end(), bv.Internal.begin(), bv.Internal.end()); Length += bv.Length; // post condition - assert( Internal.size() % 2 == 0 && Internal.size() == Length ); + gdcm_assert( Internal.size() % 2 == 0 && Internal.size() == Length ); } } // end namespace gdcm_ns diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteValue.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteValue.h index de945161aae..51830c34ad8 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteValue.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmByteValue.h @@ -22,6 +22,7 @@ #include #include #include +#include namespace gdcm_ns { @@ -34,21 +35,24 @@ using namespace gdcm; class GDCM_EXPORT ByteValue : public Value { public: - ByteValue(const char* array = nullptr, VL const &vl = 0): - Internal(array, array+vl),Length(vl) { + ByteValue(const char* array = nullptr, VL const &vl = 0): Length(vl) { + VL bytes_count_to_copy = Length; if( vl.IsOdd() ) { gdcmDebugMacro( "Odd length" ); Internal.resize(vl+1); ++Length; } + Internal.resize(Length); + if( array ) + std::memcpy(Internal.data(), array, bytes_count_to_copy); } /// \warning casting to uint32_t ByteValue(std::vector &v):Internal(v),Length((uint32_t)v.size()) {} //ByteValue(std::ostringstream const &os) { // (void)os; - // assert(0); // TODO + // gdcm_assert(0); // TODO //} ~ByteValue() override { Internal.clear(); @@ -62,13 +66,13 @@ class GDCM_EXPORT ByteValue : public Value // Either from Element Number (== 0x0000) void PrintGroupLength(std::ostream &os) { - assert( Length == 2 ); + gdcm_assert( Length == 2 ); (void)os; } bool IsEmpty() const { #if 0 - if( Internal.empty() ) assert( Length == 0 ); + if( Internal.empty() ) gdcm_assert( Length == 0 ); return Internal.empty(); #else return Length == 0; @@ -128,8 +132,8 @@ class GDCM_EXPORT ByteValue : public Value bool GetBuffer(char *buffer, unsigned long length) const; bool WriteBuffer(std::ostream &os) const { if( Length ) { - //assert( Internal.size() <= Length ); - assert( !(Internal.size() % 2) ); + //gdcm_assert( Internal.size() <= Length ); + gdcm_assert( !(Internal.size() % 2) ); os.write(&Internal[0], Internal.size() ); } return true; @@ -146,7 +150,7 @@ class GDCM_EXPORT ByteValue : public Value if( readvalues ) { is.read(&Internal[0], Length); - assert( Internal.size() == Length || Internal.size() == Length + 1 ); + gdcm_assert( Internal.size() == Length || Internal.size() == Length + 1 ); TSwap::SwapArray((TType*)GetVoidPointer(), Internal.size() / sizeof(TType) ); } else @@ -165,7 +169,7 @@ class GDCM_EXPORT ByteValue : public Value template std::ostream const &Write(std::ostream &os) const { - assert( !(Internal.size() % 2) ); + gdcm_assert( !(Internal.size() % 2) ); if( !Internal.empty() ) { //os.write(&Internal[0], Internal.size()); std::vector copy = Internal; @@ -187,7 +191,7 @@ class GDCM_EXPORT ByteValue : public Value * UNICODE or character set... */ bool IsPrintable(VL length) const { - assert( length <= Length ); + gdcm_assert( length <= Length ); for(unsigned int i=0; iGetLength().IsUndefined() ); + gdcm_assert( ValueField->GetLength().IsUndefined() ); Value *p = ValueField; // If this is a SQ we need to compute it's proper length SequenceOfItems *sq = dynamic_cast(p); @@ -37,18 +37,18 @@ VL CP246ExplicitDataElement::GetLength() const SequenceOfFragments *sf = dynamic_cast(p); if( sf ) { - assert( VRField & VR::OB_OW ); + gdcm_assert( VRField & VR::OB_OW ); return TagField.GetLength() + VRField.GetLength() + ValueLengthField.GetLength() + sf->ComputeLength(); } - assert(0); + gdcm_assert(0); return 0; } else { // Each time VR::GetLength() is 2 then Value Length is coded in 2 // 4 then Value Length is coded in 4 - assert( !ValueField || ValueField->GetLength() == ValueLengthField ); + gdcm_assert( !ValueField || ValueField->GetLength() == ValueLengthField ); return TagField.GetLength() + 2*VRField.GetLength() + ValueLengthField; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmCP246ExplicitDataElement.txx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmCP246ExplicitDataElement.txx index a733c51bbd8..823283990dc 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmCP246ExplicitDataElement.txx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmCP246ExplicitDataElement.txx @@ -44,17 +44,17 @@ std::istream &CP246ExplicitDataElement::ReadPreValue(std::istream &is) { if( !is.eof() ) // FIXME This should not be needed { - assert(0 && "Should not happen" ); + gdcm_assert(0 && "Should not happen" ); } return is; } - assert( TagField != Tag(0xfffe,0xe0dd) ); + gdcm_assert( TagField != Tag(0xfffe,0xe0dd) ); const Tag itemDelItem(0xfffe,0xe00d); if( TagField == itemDelItem ) { if( !ValueLengthField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } if( ValueLengthField != 0 ) @@ -72,20 +72,20 @@ std::istream &CP246ExplicitDataElement::ReadPreValue(std::istream &is) { if( !VRField.Read(is) ) { - assert(0 && "Should not happen" ); + gdcm_assert(0 && "Should not happen" ); return is; } } catch( std::exception & ) { // gdcm-MR-PHILIPS-16-Multi-Seq.dcm - // assert( TagField == Tag(0xfffe, 0xe000) ); + // gdcm_assert( TagField == Tag(0xfffe, 0xe000) ); // -> For some reason VR is written as {44,0} well I guess this is a VR... // Technically there is a second bug, dcmtk assume other things when reading this tag, // so I need to change this tag too, if I ever want dcmtk to read this file. oh well // 0019004_Baseline_IMG1.dcm // -> VR is garbage also... - // assert( TagField == Tag(8348,0339) || TagField == Tag(b5e8,0338)) + // gdcm_assert( TagField == Tag(8348,0339) || TagField == Tag(b5e8,0338)) gdcmWarningMacro( "Assuming 16 bits VR for Tag=" << TagField << " in order to read a buggy DICOM file." ); VRField = VR::INVALID; @@ -95,7 +95,7 @@ std::istream &CP246ExplicitDataElement::ReadPreValue(std::istream &is) { if( !ValueLengthField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } } @@ -128,11 +128,11 @@ std::istream &CP246ExplicitDataElement::ReadValue(std::istream &is, bool readval //std::cerr << "exp cur tag=" << TagField << " VR=" << VRField << " VL=" << ValueLengthField << std::endl; // Read the Value - //assert( ValueField == 0 ); + //gdcm_assert( ValueField == 0 ); if( VRField == VR::SQ ) { // Check whether or not this is an undefined length sequence - assert( TagField != Tag(0x7fe0,0x0010) ); + gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new SequenceOfItems; } else if( ValueLengthField.IsUndefined() ) @@ -143,14 +143,14 @@ std::istream &CP246ExplicitDataElement::ReadValue(std::istream &is, bool readval // Enhanced_MR_Image_Storage_PixelSpacingNotIn_0028_0030.dcm (illegal) // vs // undefined_length_un_vr.dcm - assert( TagField != Tag(0x7fe0,0x0010) ); + gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new SequenceOfItems; ValueField->SetLength(ValueLengthField); // perform realloc try { if( !ValueIO::Read(is,*ValueField,readvalues) ) // non cp246 { - assert(0); + gdcm_assert(0); } } catch( std::exception &) @@ -167,14 +167,14 @@ std::istream &CP246ExplicitDataElement::ReadValue(std::istream &is, bool readval else { // Ok this is Pixel Data fragmented... - assert( TagField == Tag(0x7fe0,0x0010) ); - assert( VRField & VR::OB_OW ); + gdcm_assert( TagField == Tag(0x7fe0,0x0010) ); + gdcm_assert( VRField & VR::OB_OW ); ValueField = new SequenceOfFragments; } } else { - //assert( TagField != Tag(0x7fe0,0x0010) ); + //gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new ByteValue; } // We have the length we should be able to read the value @@ -191,12 +191,12 @@ std::istream &CP246ExplicitDataElement::ReadValue(std::istream &is, bool readval ) { gdcmWarningMacro( "ByteSwaping Private SQ: " << TagField ); - assert( VRField == VR::SQ ); + gdcm_assert( VRField == VR::SQ ); try { if( !ValueIO::Read(is,*ValueField,readvalues) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); } } catch( std::exception & ) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmCSAElement.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmCSAElement.h index 653f3ce4e3a..9c302dac3fa 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmCSAElement.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmCSAElement.h @@ -29,7 +29,7 @@ namespace gdcm class GDCM_EXPORT CSAElement { public: - CSAElement(unsigned int kf = 0):KeyField(kf) {} + CSAElement(unsigned int kf = 0):KeyField(kf),SyngoDTField(0),NoOfItemsField(0) {} friend std::ostream& operator<<(std::ostream &os, const CSAElement &val); @@ -61,7 +61,7 @@ class GDCM_EXPORT CSAElement Value const &GetValue() const { return *DataField; } Value &GetValue() { return *DataField; } void SetValue(Value const & vl) { - //assert( DataField == 0 ); + //gdcm_assert( DataField == 0 ); DataField = vl; } /// Check if CSA Element is empty @@ -131,7 +131,7 @@ inline std::ostream& operator<<(std::ostream &os, const CSAElement &val) { //val.DataField->Print( os << "'" ); const ByteValue * bv = dynamic_cast(&*val.DataField); - assert( bv ); + gdcm_assert( bv ); const char * p = bv->GetPointer(); std::string str(p, p + bv->GetLength() ); if( val.ValueMultiplicityField == VM::VM1 ) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmCSAHeader.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmCSAHeader.cxx index 3fe9075c03b..6eb3a4f6293 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmCSAHeader.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmCSAHeader.cxx @@ -911,16 +911,16 @@ bool check_mapping(uint32_t syngodt, const char *vr) static const unsigned int max = sizeof(mapping) / sizeof(equ); const equ *p = mapping; if( syngodt > mapping[max-1].syngodt ) return false; - assert( syngodt <= mapping[max-1].syngodt ); + gdcm_assert( syngodt <= mapping[max-1].syngodt ); while(p->syngodt < syngodt ) { //std::cout << "mapping:" << p->vr << std::endl; ++p; } - assert( p->syngodt == syngodt ); // or else need to update mapping + gdcm_assert( p->syngodt == syngodt ); // or else need to update mapping const char* lvr = p->vr; int check = strcmp(vr, lvr) == 0; - assert( check ); (void)check; + gdcm_assert( check ); (void)check; return true; } @@ -978,9 +978,9 @@ bool CSAHeader::LoadFromDataElement(DataElement const &de) gdcmDebugMacro( "found type" ); const ByteValue *bv = de.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); const char *p = bv->GetPointer(); - assert( p ); + gdcm_assert( p ); std::string s( bv->GetPointer(), bv->GetLength() ); std::stringstream ss; ss.str( s ); @@ -1035,10 +1035,10 @@ bool CSAHeader::LoadFromDataElement(DataElement const &de) { ds.InsertDataElement( xde ); // Cannot use Insert since Group = 0x0 (< 0x8) //VR refvr = GetVRFromDataSetFormatDict( xde.GetTag() ); - //assert( xde.GetVR() == refvr ); + //gdcm_assert( xde.GetVR() == refvr ); } //std::cout << ds << std::endl; - assert( ss.eof() ); + gdcm_assert( ss.eof() ); } catch(std::exception &) { @@ -1049,7 +1049,7 @@ bool CSAHeader::LoadFromDataElement(DataElement const &de) } else { - //assert(0); + //gdcm_assert(0); ss.seekg( 0, std::ios::beg ); // No magic number for this one: // SIEMENS_Sonata-16-MONO2-Value_Multiplicity.dcm @@ -1060,10 +1060,10 @@ bool CSAHeader::LoadFromDataElement(DataElement const &de) { // NEW FORMAT ! ss.read(signature, 4); - assert( strcmp( signature, "\4\3\2\1" ) == 0 ); + gdcm_assert( strcmp( signature, "\4\3\2\1" ) == 0 ); InternalType = SV10; } - assert( InternalType != UNKNOWN ); + gdcm_assert( InternalType != UNKNOWN ); gdcmDebugMacro( "Found Type: " << (int)InternalType ); uint32_t n; @@ -1077,7 +1077,7 @@ bool CSAHeader::LoadFromDataElement(DataElement const &de) gdcmErrorMacro( "Must be a new format. Giving up" ); return false; } - assert( unused == 77 ); // 'M' character... + gdcm_assert( unused == 77 ); // 'M' character... for(uint32_t i = 0; i < n; ++i) { @@ -1094,7 +1094,7 @@ bool CSAHeader::LoadFromDataElement(DataElement const &de) ss.read((char*)&vm, sizeof(vm)); SwapperNoOp::SwapArray(&vm,1); csael.SetVM( VM::GetVMTypeFromLength(vm,1) ); - //assert( csael.GetVM() != VM::VM0 ); + //gdcm_assert( csael.GetVM() != VM::VM0 ); //std::cout << "VM " << vm << ", "; char vr[4]; ss.read(vr, 4); @@ -1104,7 +1104,7 @@ bool CSAHeader::LoadFromDataElement(DataElement const &de) gdcmErrorMacro( "Garbage data. Stopping CSA parsing." ); return false; } - assert( /*vr[3] == 0 &&*/ vr[2] == 0 ); + gdcm_assert( /*vr[3] == 0 &&*/ vr[2] == 0 ); csael.SetVR( VR::GetVRTypeFromFile(vr) ); //std::cout << "VR " << vr << ", "; uint32_t syngodt; @@ -1122,13 +1122,13 @@ bool CSAHeader::LoadFromDataElement(DataElement const &de) ss.read((char*)&nitems, sizeof(nitems)); SwapperNoOp::SwapArray(&nitems,1); csael.SetNoOfItems( nitems ); - if( InternalType == SV10) { assert( nitems % 6 == 0 );} + if( InternalType == SV10) { gdcm_assert( nitems % 6 == 0 );} //std::cout << "NoOfItems " << nitems << ", "; uint32_t xx; ss.read((char*)&xx, sizeof(xx)); SwapperNoOp::SwapArray(&xx,1); //std::cout << "xx=" << xx<< std::endl; - assert( xx == 77 || xx == 205 ); + gdcm_assert( xx == 77 || xx == 205 ); //std::cout << "Data "; std::ostringstream os; @@ -1138,10 +1138,10 @@ bool CSAHeader::LoadFromDataElement(DataElement const &de) ss.read((char*)&item_xx, 4*sizeof(uint32_t)); SwapperNoOp::SwapArray(item_xx,4); if( item_xx[2] != 77 && item_xx[2] != 205 ) return false; - assert( item_xx[2] == 77 || item_xx[2] == 205 ); + gdcm_assert( item_xx[2] == 77 || item_xx[2] == 205 ); uint32_t len = item_xx[1]; // 2nd element if( item_xx[0] != item_xx[1] || item_xx[1] != item_xx[3] ) return false; - assert( item_xx[0] == item_xx[1] && item_xx[1] == item_xx[3] ); + gdcm_assert( item_xx[0] == item_xx[1] && item_xx[1] == item_xx[3] ); if( len ) { char *val = new char[len+1]; @@ -1164,7 +1164,7 @@ bool CSAHeader::LoadFromDataElement(DataElement const &de) for(uint32_t d= 0; d < dummy_len; ++d) { // dummy[d] is zero in the NEW format - //assert( dummy[d] == 0 ); + //gdcm_assert( dummy[d] == 0 ); //for the old format there appears to be some garbage: if( dummy[d] ) { @@ -1216,7 +1216,7 @@ const CSAElement &CSAHeader::GetCSAElementByName(const char *name) for(; it != InternalCSADataSet.end(); ++it) { const char *itname = it->GetName(); - assert( itname ); + gdcm_assert( itname ); if( strcmp(name, itname) == 0 ) { return *it; @@ -1234,7 +1234,7 @@ bool CSAHeader::FindCSAElementByName(const char *name) for(; it != InternalCSADataSet.end(); ++it) { const char *itname = it->GetName(); - assert( itname ); + gdcm_assert( itname ); if( strcmp(name, itname) == 0 ) { return true; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataElement.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataElement.cxx index 5012ed41154..1a9ed551985 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataElement.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataElement.cxx @@ -23,13 +23,13 @@ namespace gdcm_ns { void DataElement::SetVLToUndefined() { - assert( VRField == VR::SQ || VRField == VR::INVALID + gdcm_assert( VRField == VR::SQ || VRField == VR::INVALID || (VRField == VR::UN /*&& IsUndefinedLength()*/ ) ); SequenceOfItems *sqi = dynamic_cast(ValueField.GetPointer()); if( sqi ) { sqi->SetLengthToUndefined(); - assert( GetValueAsSQ()->IsUndefinedLength() ); + gdcm_assert( GetValueAsSQ()->IsUndefinedLength() ); } ValueLengthField.SetToUndefined(); } @@ -61,7 +61,7 @@ namespace gdcm_ns SequenceOfItems *sq = dynamic_cast(ValueField.GetPointer()); if( sq ) // all set ! { - //assert( GetVR() == VR::SQ ); + //gdcm_assert( GetVR() == VR::SQ ); SmartPointer sqi = sq; return sqi; } @@ -72,7 +72,7 @@ namespace gdcm_ns if( GetVR() == VR::INVALID ) { const ByteValue *bv = GetByteValue(); - assert( bv ); + gdcm_assert( bv ); SequenceOfItems *sqi = new SequenceOfItems; sqi->SetLength( bv->GetLength() ); std::string s( bv->GetPointer(), bv->GetLength() ); @@ -111,9 +111,9 @@ namespace gdcm_ns } else if ( GetVR() == VR::UN ) // cp 246, IVRLE SQ { - assert( GetVR() == VR::UN ); // cp 246, IVRLE SQ + gdcm_assert( GetVR() == VR::UN ); // cp 246, IVRLE SQ const ByteValue *bv = GetByteValue(); - assert( bv ); + gdcm_assert( bv ); SequenceOfItems *sqi = new SequenceOfItems; sqi->SetLength( bv->GetLength() ); std::string s( bv->GetPointer(), bv->GetLength() ); @@ -168,7 +168,7 @@ namespace gdcm_ns else if ( GetVR() & VR::OB_OW ) // pre-dicom 1993 ? { const ByteValue *bv = GetByteValue(); - assert( bv ); + gdcm_assert( bv ); SequenceOfItems *sqi = new SequenceOfItems; sqi->SetLength( bv->GetLength() ); std::string s( bv->GetPointer(), bv->GetLength() ); @@ -189,8 +189,8 @@ namespace gdcm_ns } else { - assert( GetVR().IsVRFile() ); - assert( GetByteValue() ); + gdcm_assert( GetVR().IsVRFile() ); + gdcm_assert( GetByteValue() ); return nullptr; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataElement.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataElement.h index b1ae738fb4e..1aea27ab94a 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataElement.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataElement.h @@ -98,7 +98,7 @@ class GDCM_EXPORT DataElement } /// \warning you need to set the ValueLengthField explicitly void SetValue(Value const & vl) { - //assert( ValueField == 0 ); + //gdcm_assert( ValueField == 0 ); ValueField = vl; ValueLengthField = vl.GetLength(); } @@ -108,7 +108,7 @@ class GDCM_EXPORT DataElement /// Make Data Element empty (no Value) void Empty() { ValueField = nullptr; ValueLengthField = 0; } - /// Clear Data Element (make Value empty and invalidate Tag & VR) + /// Clear Data Element (make Value empty and invalidate Tag + VR) void Clear() { TagField = 0; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataSet.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataSet.cxx index 657ff111e04..a234bc4dc0e 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataSet.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataSet.cxx @@ -28,7 +28,7 @@ std::string DataSet::GetPrivateCreator(const Tag &t) const if( t.IsPrivate() && !t.IsGroupLength() && !t.IsPrivateCreator() && !t.IsIllegal() ) { Tag pc = t.GetPrivateCreator(); - assert( pc.GetElement() ); + gdcm_assert( pc.GetElement() ); { const DataElement r(pc); ConstIterator it = DES.find(r); @@ -40,7 +40,7 @@ std::string DataSet::GetPrivateCreator(const Tag &t) const const DataElement &de = *it; if( de.IsEmpty() ) return ""; const ByteValue *bv = de.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); std::string owner = std::string(bv->GetPointer(),bv->GetLength()).c_str(); // There should not be any trailing space character... // TODO: tmp.erase(tmp.find_last_not_of(' ') + 1); @@ -49,7 +49,7 @@ std::string DataSet::GetPrivateCreator(const Tag &t) const // osirix/AbdominalCT/36382443 owner.erase(owner.size()-1,1); } - assert( owner.empty() || owner[owner.size()-1] != ' ' ); + gdcm_assert( owner.empty() || owner[owner.size()-1] != ' ' ); return owner; } } @@ -67,17 +67,17 @@ PrivateTag DataSet::GetPrivateTag(const Tag &t) const Tag DataSet::ComputeDataElement(const PrivateTag & t) const { //gdcmDebugMacro( "Entering ComputeDataElement" ); - //assert( t.IsPrivateCreator() ); // No this is wrong to do the assert: eg. (0x07a1,0x000a,"ELSCINT1") + //gdcm_assert( t.IsPrivateCreator() ); // No this is wrong to do the assert: eg. (0x07a1,0x000a,"ELSCINT1") // is valid because we have not yet done the mapping, so 0xa < 0x10 fails but might not later on const Tag start(t.GetGroup(), 0x0010 ); // First possible private creator (0x0 -> 0x9 are reserved...) const DataElement r(start); ConstIterator it = DES.lower_bound(r); const char *refowner = t.GetOwner(); - assert( refowner ); + gdcm_assert( refowner ); bool found = false; while( it != DES.end() && it->GetTag().GetGroup() == t.GetGroup() && it->GetTag().GetElement() < 0x100 ) { - //assert( it->GetTag().GetOwner() ); + //gdcm_assert( it->GetTag().GetOwner() ); const ByteValue * bv = it->GetByteValue(); if( bv ) { @@ -85,7 +85,7 @@ Tag DataSet::ComputeDataElement(const PrivateTag & t) const std::string tmp(bv->GetPointer(),bv->GetLength()); // trim trailing whitespaces: tmp.erase(tmp.find_last_not_of(' ') + 1); - assert( tmp.empty() || tmp[ tmp.size() - 1 ] != ' ' ); // FIXME + gdcm_assert( tmp.empty() || tmp[ tmp.size() - 1 ] != ' ' ); // FIXME if( System::StrCaseCmp( tmp.c_str(), refowner ) == 0 ) { // found ! @@ -135,7 +135,7 @@ MediaStorage DataSet::GetMediaStorage() const std::string ts; { const ByteValue *bv = de.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); if( bv->GetPointer() && bv->GetLength() ) { // Pad string with a \0 diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataSet.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataSet.h index 3ed85b2a973..33e0a4dc1c4 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataSet.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataSet.h @@ -69,7 +69,7 @@ class GDCM_EXPORT DataSet DataElementSet &GetDES() { return DES; } void Clear() { DES.clear(); - assert( DES.empty() ); + gdcm_assert( DES.empty() ); } SizeType Size() const { @@ -79,7 +79,7 @@ class GDCM_EXPORT DataSet void Print(std::ostream &os, std::string const &indent = "") const { // CT_Phillips_JPEG2K_Decompr_Problem.dcm has a SQ of length == 0 //int s = DES.size(); - //assert( s ); + //gdcm_assert( s ); //std::copy(DES.begin(), DES.end(), // std::ostream_iterator(os, "\n")); ConstIterator it = DES.begin(); @@ -92,15 +92,15 @@ class GDCM_EXPORT DataSet template unsigned int ComputeGroupLength(Tag const &tag) const { - assert( tag.GetElement() == 0x0 ); + gdcm_assert( tag.GetElement() == 0x0 ); const DataElement r(tag); ConstIterator it = DES.find(r); unsigned int res = 0; for( ++it; it != DES.end() && it->GetTag().GetGroup() == tag.GetGroup(); ++it) { - assert( it->GetTag().GetElement() != 0x0 ); - assert( it->GetTag().GetGroup() == tag.GetGroup() ); + gdcm_assert( it->GetTag().GetElement() != 0x0 ); + gdcm_assert( it->GetTag().GetGroup() == tag.GetGroup() ); res += it->GetLength(); } return res; @@ -109,13 +109,13 @@ class GDCM_EXPORT DataSet template VL GetLength() const { if( DES.empty() ) return 0; - assert( !DES.empty() ); + gdcm_assert( !DES.empty() ); VL ll = 0; - assert( ll == 0 ); + gdcm_assert( ll == 0 ); ConstIterator it = DES.begin(); for( ; it != DES.end(); ++it) { - assert( !(it->GetLength().IsUndefined()) ); + gdcm_assert( !(it->GetLength().IsUndefined()) ); if ( it->GetTag() != Tag(0xfffe,0xe00d) ) { ll += it->GetLength(); @@ -171,7 +171,7 @@ class GDCM_EXPORT DataSet /// Completely remove a dataelement from the dataset SizeType Remove(const Tag& tag) { DataElementSet::size_type count = DES.erase(tag); - assert( count == 0 || count == 1 ); + gdcm_assert( count == 0 || count == 1 ); return count; } @@ -283,7 +283,7 @@ class GDCM_EXPORT DataSet #else DES.insert(de); #endif - assert( de.IsEmpty() || de.GetVL() == de.GetValue().GetLength() ); + gdcm_assert( de.IsEmpty() || de.GetVL() == de.GetValue().GetLength() ); } protected: diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataSet.txx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataSet.txx index 45301ac5ea4..9fd0b071878 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataSet.txx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmDataSet.txx @@ -26,7 +26,7 @@ namespace gdcm_ns std::istream &DataSet::ReadNested(std::istream &is) { DataElement de; const Tag itemDelItem(0xfffe,0xe00d); - assert( de.GetTag() != itemDelItem ); // precondition before while loop + gdcm_assert( de.GetTag() != itemDelItem ); // precondition before while loop try { while( de.Read(is) && de.GetTag() != itemDelItem ) // Keep that order please ! @@ -51,7 +51,7 @@ namespace gdcm_ns throw pe; } } - assert( de.GetTag() == itemDelItem ); + gdcm_assert( de.GetTag() == itemDelItem ); return is; } @@ -79,14 +79,14 @@ namespace gdcm_ns } else { - assert( is.good() ); + gdcm_assert( is.good() ); if( de.GetTag() != t ) is.seekg( de.GetVL(), std::ios::cur ); } // tag was found, we can exit the loop: if ( t <= de.GetTag() ) { - assert( is.good() ); + gdcm_assert( is.good() ); break; } } @@ -106,14 +106,14 @@ namespace gdcm_ns } else { - assert( is.good() ); + gdcm_assert( is.good() ); if( de.GetTag() != t ) is.seekg( de.GetVL(), std::ios::cur ); } // tag was found, we can exit the loop: if ( t <= de.GetTag() ) { - assert( is.good() ); + gdcm_assert( is.good() ); break; } } @@ -171,7 +171,7 @@ namespace gdcm_ns } } } - assert( inputStream.good() ); + gdcm_assert( inputStream.good() ); return inputStream; } @@ -179,11 +179,11 @@ namespace gdcm_ns std::istream &DataSet::ReadSelectedPrivateTags(std::istream &inputStream, const std::set & selectedPTags, bool readvalues) { if ( ! (selectedPTags.empty() || inputStream.fail()) ) { - assert( selectedPTags.size() == 1 ); + gdcm_assert( selectedPTags.size() == 1 ); const PrivateTag refPTag = *(selectedPTags.rbegin()); PrivateTag nextPTag = refPTag; nextPTag.SetElement( (uint16_t)(nextPTag.GetElement() + 0x1) ); - assert( nextPTag.GetElement() & 0x00ff ); // no wrap please + gdcm_assert( nextPTag.GetElement() & 0x00ff ); // no wrap please Tag maxTag; maxTag.SetPrivateCreator( nextPTag ); DataElement dataElem; @@ -299,11 +299,11 @@ namespace gdcm_ns (void)length; if ( ! (selectedPTags.empty() || inputStream.fail()) ) { - assert( selectedPTags.size() == 1 ); + gdcm_assert( selectedPTags.size() == 1 ); const PrivateTag refPTag = *(selectedPTags.rbegin()); PrivateTag nextPTag = refPTag; nextPTag.SetElement( (uint16_t)(nextPTag.GetElement() + 0x1) ); - assert( nextPTag.GetElement() ); // no wrap please + gdcm_assert( nextPTag.GetElement() ); // no wrap please Tag maxTag; maxTag.SetPrivateCreator( nextPTag ); DataElement dataElem; @@ -367,16 +367,16 @@ namespace gdcm_ns { //std::cout << "Nested: " << de << std::endl; #ifndef GDCM_SUPPORT_BROKEN_IMPLEMENTATION - assert( de.GetTag() != Tag(0xfffe,0xe000) ); // We should not be reading the next item... + gdcm_assert( de.GetTag() != Tag(0xfffe,0xe000) ); // We should not be reading the next item... #endif InsertDataElement( de ); const VL oflen = de.GetLength(); l += oflen; const std::streampos curpos = is.tellg(); - //assert( (curpos - startpos) == l || (curpos - startpos) + 1 == l ); + //gdcm_assert( (curpos - startpos) == l || (curpos - startpos) + 1 == l ); //std::cout << "l:" << l << std::endl; - //assert( !de.GetVL().IsUndefined() ); + //gdcm_assert( !de.GetVL().IsUndefined() ); //std::cerr << "DEBUG: " << de.GetTag() << " "<< de.GetLength() << // "," << de.GetVL() << "," << l << std::endl; // Bug_Philips_ItemTag_3F3F @@ -415,7 +415,7 @@ namespace gdcm_ns { // gdcm-MR-PHILIPS-16-Multi-Seq.dcm // Long story short, I think Philips engineer inserted 0xfffe,0x0000 instead of an item start element - // assert( FindDataElement( Tag(0xfffe,0x0000) ) == false ); + // gdcm_assert( FindDataElement( Tag(0xfffe,0x0000) ) == false ); is.seekg(-6, std::ios::cur ); length = locallength = l; } @@ -465,15 +465,15 @@ namespace gdcm_ns } // seek back since we read the next item starter: int iteml = de.GetLength(); - //assert( de.GetTag().GetElement() ); + //gdcm_assert( de.GetTag().GetElement() ); if( !de.GetTag().GetElement() ) { - assert( iteml == 12 ); (void)iteml; + gdcm_assert( iteml == 12 ); (void)iteml; is.seekg( -12, std::ios::cur ); } else { - //assert( de.GetTag() == Tag(0xfffe,0xe000) ); + //gdcm_assert( de.GetTag() == Tag(0xfffe,0xe000) ); is.seekg( -4, std::ios::cur ); } // let's fix the length now: @@ -495,8 +495,8 @@ namespace gdcm_ns // technically we could only do this assert if the dataset did not contains // duplicate data elements so only do a <= instead: - //assert( l == locallength ); - assert( l <= locallength ); + //gdcm_assert( l == locallength ); + gdcm_assert( l <= locallength ); return is; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmElement.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmElement.h index 15fb3a117b6..e211d84b62f 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmElement.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmElement.h @@ -92,18 +92,18 @@ class Element return Internal; } const typename VRToType::Type &GetValue(unsigned int idx = 0) const { - assert( idx < VMToLength::Length ); + gdcm_assert( idx < VMToLength::Length ); return Internal[idx]; } typename VRToType::Type &GetValue(unsigned int idx = 0) { - assert( idx < VMToLength::Length ); + gdcm_assert( idx < VMToLength::Length ); return Internal[idx]; } typename VRToType::Type operator[] (unsigned int idx) const { return GetValue(idx); } void SetValue(typename VRToType::Type v, unsigned int idx = 0) { - assert( idx < VMToLength::Length ); + gdcm_assert( idx < VMToLength::Length ); Internal[idx] = v; } @@ -130,7 +130,7 @@ class Element EncodingImplementation::Mode>::Write(Internal, GetLength(),os); ret.SetVR( (VR::VRType)TVR ); - assert( ret.GetVR() != VR::SQ ); + gdcm_assert( ret.GetVR() != VR::SQ ); if( (VR::VRType)VRToEncoding::Mode == VR::VRASCII ) { if( GetVR() != VR::UI ) @@ -172,7 +172,7 @@ class Element protected: void SetNoSwap(Value const &v) { const ByteValue *bv = dynamic_cast(&v); - assert( bv ); // That would be bad... + gdcm_assert( bv ); // That would be bad... //memcpy(Internal, bv->GetPointer(), bv->GetLength()); std::stringstream ss; std::string s = std::string( bv->GetPointer(), bv->GetLength() ); @@ -203,18 +203,18 @@ template<> class EncodingImplementation { template // FIXME this should be VRToType::Type static inline void ReadComputeLength(T* data, unsigned int &length, std::istream &_is) { - assert( data ); - //assert( length ); // != 0 + gdcm_assert( data ); + //gdcm_assert( length ); // != 0 length = 0; - assert( _is ); + gdcm_assert( _is ); #if 0 char sep; while( _is >> data[length++] ) { // Get the separator in between the values - assert( _is ); + gdcm_assert( _is ); _is.get(sep); - assert( sep == '\\' || sep == ' ' ); // FIXME: Bad use of assert + gdcm_assert( sep == '\\' || sep == ' ' ); // FIXME: Bad use of assert if( sep == ' ' ) length--; // FIXME } #else @@ -227,19 +227,19 @@ template<> class EncodingImplementation { template // FIXME this should be VRToType::Type static inline void Read(T* data, unsigned long length, std::istream &_is) { - assert( data ); - assert( length ); // != 0 - assert( _is ); + gdcm_assert( data ); + gdcm_assert( length ); // != 0 + gdcm_assert( _is ); // FIXME BUG: what if >> operation fails ? // gdcmData/MR00010001.dcm / SpacingBetweenSlices _is >> std::ws >> data[0]; char sep; //std::cout << "GetLength: " << af->GetLength() << std::endl; for(unsigned long i=1; i> std::ws >> sep; //_is.get(sep); - //assert( sep == '\\' ); // FIXME: Bad use of assert + //gdcm_assert( sep == '\\' ); // FIXME: Bad use of assert _is >> std::ws >> data[i]; } } @@ -252,12 +252,12 @@ template<> class EncodingImplementation { template static inline void Write(const T* data, unsigned long length, std::ostream &_os) { - assert( data ); - assert( length ); - assert( _os ); + gdcm_assert( data ); + gdcm_assert( length ); + gdcm_assert( _os ); _os << data[0]; for(unsigned long i=1; i inline void EncodingImplementation::Write(const double* data, unsigned long length, std::ostream &_os) { - assert( data ); - assert( length ); - assert( _os ); + gdcm_assert( data ); + gdcm_assert( length ); + gdcm_assert( _os ); #ifdef VRDS16ILLEGAL _os << to_string(data[0]); #else @@ -432,7 +432,7 @@ template<> inline void EncodingImplementation::Write(const double* _os << buf; #endif for(unsigned long i=1; i class EncodingImplementation { static inline void ReadComputeLength(T* data, unsigned int &length, std::istream &_is) { const unsigned int type_size = sizeof(T); - assert( data ); // Can we read from pointer ? - //assert( length ); + gdcm_assert( data ); // Can we read from pointer ? + //gdcm_assert( length ); length /= type_size; - assert( _is ); // Is stream valid ? + gdcm_assert( _is ); // Is stream valid ? _is.read( reinterpret_cast(data+0), type_size); for(unsigned long i=1; i(data+i), type_size ); } } @@ -468,9 +468,9 @@ template<> class EncodingImplementation { static inline void ReadNoSwap(T* data, unsigned long length, std::istream &_is) { const unsigned int type_size = sizeof(T); - assert( data ); // Can we read from pointer ? - assert( length ); - assert( _is ); // Is stream valid ? + gdcm_assert( data ); // Can we read from pointer ? + gdcm_assert( length ); + gdcm_assert( _is ); // Is stream valid ? _is.read( reinterpret_cast(data+0), type_size); for(unsigned long i=1; i class EncodingImplementation { static inline void Read(T* data, unsigned long length, std::istream &_is) { const unsigned int type_size = sizeof(T); - assert( data ); // Can we read from pointer ? - assert( length ); - assert( _is ); // Is stream valid ? + gdcm_assert( data ); // Can we read from pointer ? + gdcm_assert( length ); + gdcm_assert( _is ); // Is stream valid ? _is.read( reinterpret_cast(data+0), type_size); for(unsigned long i=1; i class EncodingImplementation { static inline void Write(const T* data, unsigned long length, std::ostream &_os) { const unsigned int type_size = sizeof(T); - assert( data ); // Can we write into pointer ? - assert( length ); - assert( _os ); // Is stream valid ? + gdcm_assert( data ); // Can we write into pointer ? + gdcm_assert( length ); + gdcm_assert( _os ); // Is stream valid ? //ByteSwap::SwapRangeFromSwapCodeIntoSystem((T*)data, // _os.GetSwapCode(), length); T swappedData = SwapperNoOp::Swap(data[0]); _os.write( reinterpret_cast(&swappedData), type_size); for(unsigned long i=1; i(&swappedData), type_size ); } @@ -542,7 +542,7 @@ class Element Internal[i] = sarray.substr(pos1, pos2-pos1); // Shouldn't we do the contrary, since we know how many separators // (and default behavior is to discard anything after the VM declared - assert( GetLength()-1 == i ); + gdcm_assert( GetLength()-1 == i ); } unsigned long GetLength() const { @@ -601,9 +601,9 @@ class Element if( len ) { if( len > Length ) { // perform realloc - assert( (len / size) * size == len ); + gdcm_assert( (len / size) * size == len ); Type *internal = new Type[len / size]; - assert( Save == false ); + gdcm_assert( Save == false ); Save = true; // ???? if( Internal ) { @@ -623,15 +623,15 @@ class Element if( save ) { SetLength(len); // realloc memcpy(Internal, array, len/*/sizeof(Type)*/); - assert( Save == false ); + gdcm_assert( Save == false ); } else { // TODO rewrite this stupid code: - assert( Length == 0 ); - assert( Internal == nullptr ); - assert( Save == false ); + gdcm_assert( Length == 0 ); + gdcm_assert( Internal == nullptr ); + gdcm_assert( Save == false ); Length = len / sizeof(Type); - //assert( (len / sizeof(Type)) * sizeof(Type) == len ); + //gdcm_assert( (len / sizeof(Type)) * sizeof(Type) == len ); // MR00010001.dcm is a tough kid: 0019,105a is supposed to be VR::FL, VM::VM3 but // length is 14 bytes instead of 12 bytes. Simply consider value is total garbage. if( (len / sizeof(Type)) * sizeof(Type) != len ) { Internal = nullptr; Length = 0; } @@ -640,15 +640,15 @@ class Element Save = save; } void SetValue(typename VRToType::Type v, unsigned int idx = 0) { - assert( idx < Length ); + gdcm_assert( idx < Length ); Internal[idx] = v; } const typename VRToType::Type &GetValue(unsigned int idx = 0) const { - assert( idx < Length ); + gdcm_assert( idx < Length ); return Internal[idx]; } typename VRToType::Type &GetValue(unsigned int idx = 0) { - //assert( idx < Length ); + //gdcm_assert( idx < Length ); return Internal[idx]; } typename VRToType::Type operator[] (unsigned int idx) const { @@ -656,13 +656,13 @@ class Element } void Set(Value const &v) { const ByteValue *bv = dynamic_cast(&v); - assert( bv ); // That would be bad... + gdcm_assert( bv ); // That would be bad... if( (VR::VRType)(VRToEncoding::Mode) == VR::VRBINARY ) { const Type* array = (const Type*)bv->GetVoidPointer(); if( array ) { - assert( array ); // That would be bad... - assert( Internal == nullptr ); + gdcm_assert( array ); // That would be bad... + gdcm_assert( Internal == nullptr ); SetArray(array, bv->GetLength() ); } } else @@ -699,8 +699,8 @@ class Element // Implementation of Print is common to all Mode (ASCII/Binary) void Print(std::ostream &_os) const { - assert( Length ); - assert( Internal ); + gdcm_assert( Length ); + gdcm_assert( Internal ); _os << Internal[0]; // VM is at least guarantee to be one const unsigned long length = GetLength() < 25 ? GetLength() : 25; for(unsigned long i=1; i DataElement GetAsDataElement() const { DataElement ret; ret.SetVR( (VR::VRType)TVR ); - assert( ret.GetVR() != VR::SQ ); + gdcm_assert( ret.GetVR() != VR::SQ ); if( Internal ) { std::ostringstream os; @@ -761,13 +761,13 @@ class Element protected: void SetNoSwap(Value const &v) { const ByteValue *bv = dynamic_cast(&v); - assert( bv ); // That would be bad... + gdcm_assert( bv ); // That would be bad... if( (VR::VRType)(VRToEncoding::Mode) == VR::VRBINARY ) { const Type* array = (const Type*)bv->GetPointer(); if( array ) { - assert( array ); // That would be bad... - assert( Internal == nullptr ); + gdcm_assert( array ); // That would be bad... + gdcm_assert( Internal == nullptr ); SetArray(array, bv->GetLength() ); } } else diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitDataElement.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitDataElement.cxx index aa13d49a921..a06756bf394 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitDataElement.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitDataElement.cxx @@ -24,7 +24,7 @@ VL ExplicitDataElement::GetLength() const { if( ValueLengthField.IsUndefined() ) { - assert( ValueField->GetLength().IsUndefined() ); + gdcm_assert( ValueField->GetLength().IsUndefined() ); Value *p = ValueField; // If this is a SQ we need to compute it's proper length SequenceOfItems *sq = dynamic_cast(p); @@ -32,27 +32,27 @@ VL ExplicitDataElement::GetLength() const if( sq ) { const VL sqlen = sq->ComputeLength(); - assert( sqlen % 2 == 0 ); + gdcm_assert( sqlen % 2 == 0 ); return TagField.GetLength() + VRField.GetLength() + ValueLengthField.GetLength() + sqlen; } SequenceOfFragments *sf = dynamic_cast(p); if( sf ) { - assert( VRField & VR::OB_OW ); // VR::INVALID is not possible AFAIK... + gdcm_assert( VRField & VR::OB_OW ); // VR::INVALID is not possible AFAIK... const VL sflen = sf->ComputeLength(); - assert( sflen % 2 == 0 ); + gdcm_assert( sflen % 2 == 0 ); return TagField.GetLength() + VRField.GetLength() + ValueLengthField.GetLength() + sflen; } - assert(0); + gdcm_assert(0); return 0; } else { // Each time VR::GetLength() is 2 then Value Length is coded in 2 // 4 then Value Length is coded in 4 - assert( !ValueField || ValueField->GetLength() == ValueLengthField ); + gdcm_assert( !ValueField || ValueField->GetLength() == ValueLengthField ); const bool vr16bitsimpossible = (VRField & VR::VL16) && (ValueLengthField > (uint32_t)VL::GetVL16Max()); if( vr16bitsimpossible || VRField == VR::INVALID ) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitDataElement.txx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitDataElement.txx index 47633b9f042..2a307a6e47d 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitDataElement.txx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitDataElement.txx @@ -43,7 +43,7 @@ std::istream &ExplicitDataElement::ReadPreValue(std::istream &is) { if( !is.eof() ) // FIXME This should not be needed { - assert(0 && "Should not happen" ); + gdcm_assert(0 && "Should not happen" ); } return is; } @@ -53,13 +53,13 @@ std::istream &ExplicitDataElement::ReadPreValue(std::istream &is) pe.SetLastElement( *this ); throw pe; } - //assert( TagField != Tag(0xfeff,0xdde0) ); + //gdcm_assert( TagField != Tag(0xfeff,0xdde0) ); const Tag itemDelItem(0xfffe,0xe00d); if( TagField == itemDelItem ) { if( !ValueLengthField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } if( ValueLengthField ) @@ -78,7 +78,7 @@ std::istream &ExplicitDataElement::ReadPreValue(std::istream &is) #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION if( TagField == Tag(0x00ff, 0x4aa5) ) { - //assert(0 && "Should not happen" ); + //gdcm_assert(0 && "Should not happen" ); // gdcmDataExtra/gdcmBreakers/DigitexAlpha_no_7FE0.dcm is.seekg( -4, std::ios::cur ); TagField = Tag(0x7fe0,0x0010); @@ -101,7 +101,7 @@ std::istream &ExplicitDataElement::ReadPreValue(std::istream &is) { if( !VRField.Read(is) ) { - assert(0 && "Should not happen" ); + gdcm_assert(0 && "Should not happen" ); return is; } } @@ -109,13 +109,13 @@ std::istream &ExplicitDataElement::ReadPreValue(std::istream &is) { #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION // gdcm-MR-PHILIPS-16-Multi-Seq.dcm - // assert( TagField == Tag(0xfffe, 0xe000) ); + // gdcm_assert( TagField == Tag(0xfffe, 0xe000) ); // -> For some reason VR is written as {44,0} well I guess this is a VR... // Technically there is a second bug, dcmtk assume other things when reading this tag, // so I need to change this tag too, if I ever want dcmtk to read this file. oh well // 0019004_Baseline_IMG1.dcm // -> VR is garbage also... - // assert( TagField == Tag(8348,0339) || TagField == Tag(b5e8,0338)) + // gdcm_assert( TagField == Tag(8348,0339) || TagField == Tag(b5e8,0338)) //gdcmWarningMacro( "Assuming 16 bits VR for Tag=" << // TagField << " in order to read a buggy DICOM file." ); //VRField = VR::INVALID; @@ -132,7 +132,7 @@ std::istream &ExplicitDataElement::ReadPreValue(std::istream &is) { if( !ValueLengthField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } } @@ -141,7 +141,7 @@ std::istream &ExplicitDataElement::ReadPreValue(std::istream &is) // 16bits only if( !ValueLengthField.template Read16(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION @@ -188,11 +188,11 @@ std::istream &ExplicitDataElement::ReadValue(std::istream &is, bool readvalues) } // Read the Value - //assert( ValueField == 0 ); + //gdcm_assert( ValueField == 0 ); if( VRField == VR::SQ ) { // Check whether or not this is an undefined length sequence - assert( TagField != Tag(0x7fe0,0x0010) ); + gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new SequenceOfItems; } else if( ValueLengthField.IsUndefined() ) @@ -200,7 +200,12 @@ std::istream &ExplicitDataElement::ReadValue(std::istream &is, bool readvalues) if( TagField == Tag(0x7fe0,0x0010) ) { // Ok this is Pixel Data fragmented... - assert( VRField & VR::OB_OW || VRField == VR::UN ); + gdcm_assert( VRField & VR::OB_OW || VRField == VR::UN ); + ValueField = new SequenceOfFragments; + } + else if( TagField == Tag(0x7fe1,0x1060) && VRField == VR::OB ) + { + gdcmWarningMacro( "IllegalPrivatePixelSequence (7fe1,1060)" ); ValueField = new SequenceOfFragments; } else @@ -209,8 +214,8 @@ std::istream &ExplicitDataElement::ReadValue(std::istream &is, bool readvalues) // Enhanced_MR_Image_Storage_PixelSpacingNotIn_0028_0030.dcm (illegal) // vs // undefined_length_un_vr.dcm - assert( TagField != Tag(0x7fe0,0x0010) ); - assert( VRField == VR::UN ); + gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); + gdcm_assert( VRField == VR::UN ); ValueField = new SequenceOfItems; ValueField->SetLength(ValueLengthField); // perform realloc try @@ -218,7 +223,7 @@ std::istream &ExplicitDataElement::ReadValue(std::istream &is, bool readvalues) //if( !ValueIO::Read(is,*ValueField) ) // non cp246 if( !ValueIO::Read(is,*ValueField,readvalues) ) // cp246 compliant { - assert(0); + gdcm_assert(0); } } catch( std::exception &) @@ -235,7 +240,7 @@ std::istream &ExplicitDataElement::ReadValue(std::istream &is, bool readvalues) } else { - //assert( TagField != Tag(0x7fe0,0x0010) ); + //gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new ByteValue; } // We have the length we should be able to read the value @@ -254,17 +259,17 @@ std::istream &ExplicitDataElement::ReadValue(std::istream &is, bool readvalues) ) { gdcmWarningMacro( "ByteSwaping Private SQ: " << TagField ); - assert( VRField == VR::SQ ); - assert( TagField.IsPrivate() ); + gdcm_assert( VRField == VR::SQ ); + gdcm_assert( TagField.IsPrivate() ); try { if( !ValueIO::Read(is,*ValueField,readvalues) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); } Value* v = &*ValueField; SequenceOfItems *sq = dynamic_cast(v); - assert( sq ); + gdcm_assert( sq ); SequenceOfItems::Iterator it = sq->Begin(); for( ; it != sq->End(); ++it) { @@ -283,17 +288,17 @@ std::istream &ExplicitDataElement::ReadValue(std::istream &is, bool readvalues) #endif bool failed; - //assert( VRField != VR::UN ); + //gdcm_assert( VRField != VR::UN ); if( VRField & VR::VRASCII ) { - //assert( VRField.GetSize() == 1 ); + //gdcm_assert( VRField.GetSize() == 1 ); failed = !ValueIO::Read(is,*ValueField,readvalues); } else { - assert( VRField & VR::VRBINARY ); + gdcm_assert( VRField & VR::VRBINARY ); unsigned int vrsize = VRField.GetSize(); - assert( vrsize == 1 || vrsize == 2 || vrsize == 4 || vrsize == 8 ); + gdcm_assert( vrsize == 1 || vrsize == 2 || vrsize == 4 || vrsize == 8 ); if(VRField==VR::AT) vrsize = 2; switch(vrsize) { @@ -311,7 +316,7 @@ std::istream &ExplicitDataElement::ReadValue(std::istream &is, bool readvalues) break; default: failed = true; - assert(0); + gdcm_assert(0); } } if( failed ) @@ -339,7 +344,7 @@ std::istream &ExplicitDataElement::ReadValue(std::istream &is, bool readvalues) #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION if( SequenceOfItems *sqi = dynamic_cast(&GetValue()) ) { - assert( ValueField->GetLength() == ValueLengthField ); + gdcm_assert( ValueField->GetLength() == ValueLengthField ); // Recompute the total length: if( !ValueLengthField.IsUndefined() ) { @@ -354,9 +359,9 @@ std::istream &ExplicitDataElement::ReadValue(std::istream &is, bool readvalues) } else if( SequenceOfFragments *sqf = dynamic_cast(&GetValue()) ) { - assert( ValueField->GetLength() == ValueLengthField ); - assert( sqf->GetLength() == ValueLengthField ); (void)sqf; - assert( ValueLengthField.IsUndefined() ); + gdcm_assert( ValueField->GetLength() == ValueLengthField ); + gdcm_assert( sqf->GetLength() == ValueLengthField ); (void)sqf; + gdcm_assert( ValueLengthField.IsUndefined() ); } #endif @@ -378,14 +383,14 @@ const std::ostream &ExplicitDataElement::Write(std::ostream &os) const //if( TagField == Tag(0xfffe,0xe0dd) ) return os; if( !TagField.Write(os) ) { - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); return os; } const Tag itemDelItem(0xfffe,0xe00d); if( TagField == itemDelItem ) { - assert(0); - assert( ValueField == nullptr ); + gdcm_assert(0); + gdcm_assert( ValueField == nullptr ); #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION if( ValueLengthField != 0 ) { @@ -397,10 +402,10 @@ const std::ostream &ExplicitDataElement::Write(std::ostream &os) const } #endif // else - assert( ValueLengthField == 0 ); + gdcm_assert( ValueLengthField == 0 ); if( !ValueLengthField.Write(os) ) { - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); return os; } return os; @@ -437,7 +442,7 @@ const std::ostream &ExplicitDataElement::Write(std::ostream &os) const if( ValueField && dynamic_cast(&*ValueField) ) { VL vl = 0xFFFFFFFF; - assert( vl.IsUndefined() ); + gdcm_assert( vl.IsUndefined() ); vl.Write(os); } else @@ -446,17 +451,17 @@ const std::ostream &ExplicitDataElement::Write(std::ostream &os) const } else { - assert( VRField.IsVRFile() && VRField != VR::INVALID ); + gdcm_assert( VRField.IsVRFile() && VRField != VR::INVALID ); if( !VRField.Write(os) ) { - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); return os; } if( VRField & VR::VL32 ) { if( !ValueLengthField.Write(os) ) { - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); return os; } } @@ -465,7 +470,7 @@ const std::ostream &ExplicitDataElement::Write(std::ostream &os) const // 16bits only if( !ValueLengthField.template Write16(os) ) { - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); return os; } } @@ -481,12 +486,12 @@ const std::ostream &ExplicitDataElement::Write(std::ostream &os) const // check consistency in Length: if( GetByteValue() ) { - assert( ValueField->GetLength() == ValueLengthField ); + gdcm_assert( ValueField->GetLength() == ValueLengthField ); } //else if( GetSequenceOfItems() ) else if( const SequenceOfItems *sqi = dynamic_cast(&GetValue()) ) { - assert( ValueField->GetLength() == ValueLengthField ); + gdcm_assert( ValueField->GetLength() == ValueLengthField ); // Recompute the total length: if( !ValueLengthField.IsUndefined() ) { @@ -496,13 +501,13 @@ const std::ostream &ExplicitDataElement::Write(std::ostream &os) const } else if( GetSequenceOfFragments() ) { - assert( ValueField->GetLength() == ValueLengthField ); + gdcm_assert( ValueField->GetLength() == ValueLengthField ); } //#endif // We have the length we should be able to write the value if( VRField == VR::UN && ValueLengthField.IsUndefined() ) { - assert( TagField == Tag(0x7fe0,0x0010) || GetValueAsSQ() ); + gdcm_assert( TagField == Tag(0x7fe0,0x0010) || GetValueAsSQ() ); ValueIO::Write(os,*ValueField); } #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION @@ -533,9 +538,9 @@ const std::ostream &ExplicitDataElement::Write(std::ostream &os) const } else { - assert( VRField & VR::VRBINARY ); + gdcm_assert( VRField & VR::VRBINARY ); unsigned int vrsize = VRField.GetSize(); - assert( vrsize == 1 || vrsize == 2 || vrsize == 4 || vrsize == 8 ); + gdcm_assert( vrsize == 1 || vrsize == 2 || vrsize == 4 || vrsize == 8 ); if(VRField == VR::AT) vrsize = 2; switch(vrsize) { @@ -553,12 +558,12 @@ const std::ostream &ExplicitDataElement::Write(std::ostream &os) const break; default: failed = true; - assert(0); + gdcm_assert(0); } } if( failed ) { - assert( 0 && "Should not happen" ); + gdcm_assert( 0 && "Should not happen" ); } } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitImplicitDataElement.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitImplicitDataElement.cxx index e98a6904843..4141f746fd4 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitImplicitDataElement.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitImplicitDataElement.cxx @@ -24,7 +24,7 @@ VL ExplicitImplicitDataElement::GetLength() const { if( ValueLengthField.IsUndefined() ) { - assert( ValueField->GetLength().IsUndefined() ); + gdcm_assert( ValueField->GetLength().IsUndefined() ); Value *p = ValueField; // If this is a SQ we need to compute it's proper length SequenceOfItems *sq = dynamic_cast(p); @@ -37,18 +37,18 @@ VL ExplicitImplicitDataElement::GetLength() const SequenceOfFragments *sf = dynamic_cast(p); if( sf ) { - assert( VRField & (VR::OB | VR::OW) ); + gdcm_assert( VRField & (VR::OB | VR::OW) ); return TagField.GetLength() + VRField.GetLength() + ValueLengthField.GetLength() + sf->ComputeLength(); } - assert(0); + gdcm_assert(0); return 0; } else { // Each time VR::GetLength() is 2 then Value Length is coded in 2 // 4 then Value Length is coded in 4 - assert( !ValueField || ValueField->GetLength() == ValueLengthField ); + gdcm_assert( !ValueField || ValueField->GetLength() == ValueLengthField ); return TagField.GetLength() + 2*VRField.GetLength() + ValueLengthField; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitImplicitDataElement.txx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitImplicitDataElement.txx index 13142a37d3b..ea0eaafaedf 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitImplicitDataElement.txx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmExplicitImplicitDataElement.txx @@ -44,7 +44,7 @@ std::istream &ExplicitImplicitDataElement::ReadPreValue(std::istream &is) { if( !is.eof() ) // FIXME This should not be needed { - assert(0 && "Should not happen" ); + gdcm_assert(0 && "Should not happen" ); } return is; } @@ -54,7 +54,7 @@ std::istream &ExplicitImplicitDataElement::ReadPreValue(std::istream &is) pe.SetLastElement( *this ); throw pe; } - //assert( TagField != Tag(0xfeff,0xdde0) ); + //gdcm_assert( TagField != Tag(0xfeff,0xdde0) ); const Tag itemDelItem(0xfffe,0xe00d); if( TagField == itemDelItem ) { @@ -63,7 +63,7 @@ std::istream &ExplicitImplicitDataElement::ReadPreValue(std::istream &is) //throw pe; if( !ValueLengthField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } if( ValueLengthField ) @@ -80,7 +80,7 @@ std::istream &ExplicitImplicitDataElement::ReadPreValue(std::istream &is) #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION if( TagField == Tag(0x00ff, 0x4aa5) ) { - //assert(0 && "Should not happen" ); + //gdcm_assert(0 && "Should not happen" ); // gdcmDataExtra/gdcmBreakers/DigitexAlpha_no_7FE0.dcm is.seekg( -4, std::ios::cur ); TagField = Tag(0x7fe0,0x0010); @@ -103,7 +103,7 @@ std::istream &ExplicitImplicitDataElement::ReadPreValue(std::istream &is) { if( !VRField.Read(is) ) { - assert(0 && "Should not happen" ); + gdcm_assert(0 && "Should not happen" ); return is; } // Read Value Length @@ -111,7 +111,7 @@ std::istream &ExplicitImplicitDataElement::ReadPreValue(std::istream &is) { if( !ValueLengthField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } } @@ -120,7 +120,7 @@ std::istream &ExplicitImplicitDataElement::ReadPreValue(std::istream &is) // 16bits only if( !ValueLengthField.template Read16(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION @@ -145,11 +145,11 @@ std::istream &ExplicitImplicitDataElement::ReadPreValue(std::istream &is) const Tag itemStartItem(0xfffe,0xe000); if( TagField == itemStartItem ) return is; - //assert( TagField != Tag(0xfffe,0xe0dd) ); + //gdcm_assert( TagField != Tag(0xfffe,0xe0dd) ); // Read Value Length if( !ValueLengthField.Read(is) ) { - //assert(0 && "Should not happen"); + //gdcm_assert(0 && "Should not happen"); throw Exception("Impossible"); return is; } @@ -162,9 +162,9 @@ std::istream &ExplicitImplicitDataElement::ReadPreValue(std::istream &is) } else if( ValueLengthField.IsUndefined() ) { - //assert( de.GetVR() == VR::SQ ); + //gdcm_assert( de.GetVR() == VR::SQ ); // FIXME what if I am reading the pixel data... - //assert( TagField != Tag(0x7fe0,0x0010) ); + //gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); if( TagField != Tag(0x7fe0,0x0010) ) { ValueField = new SequenceOfItems; @@ -202,7 +202,7 @@ std::istream &ExplicitImplicitDataElement::ReadPreValue(std::istream &is) is.seekg(-4, std::ios::cur ); if( item == itemStart ) { - assert( TagField != Tag(0x7fe0,0x0010) ); + gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new SequenceOfItems; } #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION @@ -219,7 +219,7 @@ std::istream &ExplicitImplicitDataElement::ReadPreValue(std::istream &is) { if( !ValueIO::Read(is,*ValueField,true) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); } } catch( std::exception &ex2 ) @@ -237,7 +237,7 @@ std::istream &ExplicitImplicitDataElement::ReadPreValue(std::istream &is) ValueField->SetLength(ValueLengthField); // perform realloc if( !ValueIO::Read(is,*ValueField,true) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); } return is; } @@ -299,12 +299,12 @@ std::istream &ExplicitImplicitDataElement::ReadPreValue(std::istream &is) VL dummy = ValueField->GetLength(); if( ValueLengthField != dummy ) { - gdcmWarningMacro( "ValueLengthField was bogus" ); assert(0); + gdcmWarningMacro( "ValueLengthField was bogus" ); gdcm_assert(0); ValueLengthField = dummy; } #else - assert( ValueLengthField == ValueField->GetLength() ); - assert( VRField == VR::INVALID ); + gdcm_assert( ValueLengthField == ValueField->GetLength() ); + gdcm_assert( VRField == VR::INVALID ); #endif return is; @@ -349,11 +349,11 @@ std::istream &ExplicitImplicitDataElement::ReadValue(std::istream &is, bool read } // Read the Value - //assert( ValueField == 0 ); + //gdcm_assert( ValueField == 0 ); if( VRField == VR::SQ ) { // Check whether or not this is an undefined length sequence - assert( TagField != Tag(0x7fe0,0x0010) ); + gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new SequenceOfItems; } else if( ValueLengthField.IsUndefined() ) @@ -364,7 +364,7 @@ std::istream &ExplicitImplicitDataElement::ReadValue(std::istream &is, bool read // Enhanced_MR_Image_Storage_PixelSpacingNotIn_0028_0030.dcm (illegal) // vs // undefined_length_un_vr.dcm - assert( TagField != Tag(0x7fe0,0x0010) ); + gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new SequenceOfItems; ValueField->SetLength(ValueLengthField); // perform realloc try @@ -372,7 +372,7 @@ std::istream &ExplicitImplicitDataElement::ReadValue(std::istream &is, bool read //if( !ValueIO::Read(is,*ValueField) ) // non cp246 if( !ValueIO::Read(is,*ValueField,readvalues) ) // cp246 compliant { - assert(0); + gdcm_assert(0); } } catch( std::exception &) @@ -389,14 +389,14 @@ std::istream &ExplicitImplicitDataElement::ReadValue(std::istream &is, bool read else { // Ok this is Pixel Data fragmented... - assert( TagField == Tag(0x7fe0,0x0010) ); - assert( VRField & VR::OB_OW ); + gdcm_assert( TagField == Tag(0x7fe0,0x0010) ); + gdcm_assert( VRField & VR::OB_OW ); ValueField = new SequenceOfFragments; } } else { - //assert( TagField != Tag(0x7fe0,0x0010) ); + //gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new ByteValue; } // We have the length we should be able to read the value @@ -415,17 +415,17 @@ std::istream &ExplicitImplicitDataElement::ReadValue(std::istream &is, bool read ) { gdcmWarningMacro( "ByteSwaping Private SQ: " << TagField ); - assert( VRField == VR::SQ ); - assert( TagField.IsPrivate() ); + gdcm_assert( VRField == VR::SQ ); + gdcm_assert( TagField.IsPrivate() ); try { if( !ValueIO::Read(is,*ValueField,readvalues) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); } Value* v = &*ValueField; SequenceOfItems *sq = dynamic_cast(v); - assert( sq ); + gdcm_assert( sq ); SequenceOfItems::Iterator it = sq->Begin(); for( ; it != sq->End(); ++it) { @@ -444,17 +444,17 @@ std::istream &ExplicitImplicitDataElement::ReadValue(std::istream &is, bool read #endif bool failed; - //assert( VRField != VR::UN ); + //gdcm_assert( VRField != VR::UN ); if( VRField & VR::VRASCII ) { - //assert( VRField.GetSize() == 1 ); + //gdcm_assert( VRField.GetSize() == 1 ); failed = !ValueIO::Read(is,*ValueField,readvalues); } else { - assert( VRField & VR::VRBINARY ); + gdcm_assert( VRField & VR::VRBINARY ); unsigned int vrsize = VRField.GetSize(); - assert( vrsize == 1 || vrsize == 2 || vrsize == 4 || vrsize == 8 ); + gdcm_assert( vrsize == 1 || vrsize == 2 || vrsize == 4 || vrsize == 8 ); if(VRField==VR::AT) vrsize = 2; switch(vrsize) { @@ -472,7 +472,7 @@ std::istream &ExplicitImplicitDataElement::ReadValue(std::istream &is, bool read break; default: failed = true; - assert(0); + gdcm_assert(0); } } if( failed ) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFile.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFile.cxx index 8bfe42804df..ea65931c9bc 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFile.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFile.cxx @@ -22,13 +22,13 @@ File::~File() = default; std::istream &File::Read(std::istream &is) { - assert(0); + gdcm_assert(0); return is; } std::ostream const &File::Write(std::ostream &os) const { - assert(0); + gdcm_assert(0); return os; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFile.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFile.h index 52da3a69175..16d4eaada7e 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFile.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFile.h @@ -71,7 +71,7 @@ inline std::ostream& operator<<(std::ostream &os, const File &val) { os << val.GetHeader() << std::endl; //os << val.GetDataSet() << std::endl; // FIXME - assert(0); + gdcm_assert(0); return os; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFileMetaInformation.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFileMetaInformation.cxx index ad127026466..360775d11c0 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFileMetaInformation.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFileMetaInformation.cxx @@ -190,7 +190,7 @@ void FileMetaInformation::FillFromDataSet(DataSet const &ds) { const DataElement& sopclass = ds.GetDataElement( Tag(0x0008, 0x0016) ); DataElement mssopclass = GetDataElement( Tag(0x0002, 0x0002) ); - assert( !mssopclass.IsEmpty() ); + gdcm_assert( !mssopclass.IsEmpty() ); const ByteValue *bv = sopclass.GetByteValue(); if( bv ) { @@ -233,7 +233,7 @@ void FileMetaInformation::FillFromDataSet(DataSet const &ds) } else { - //assert(0); + //gdcm_assert(0); throw gdcm::Exception( "No 2,3 and 8,18 element sorry" ); } } @@ -248,26 +248,26 @@ void FileMetaInformation::FillFromDataSet(DataSet const &ds) if( !ds.FindDataElement( Tag(0x0008, 0x0018) ) || ds.GetDataElement( Tag(0x0008, 0x0018) ).IsEmpty() ) { throw gdcm::Exception( "No 8,18 element sorry" ); - //assert(0); + //gdcm_assert(0); } const DataElement& sopinst = ds.GetDataElement( Tag(0x0008, 0x0018) ); //const DataElement & foo = GetDataElement( Tag(0x0002, 0x0003) ); - assert( !GetDataElement( Tag(0x0002, 0x0003) ).IsEmpty() ); + gdcm_assert( !GetDataElement( Tag(0x0002, 0x0003) ).IsEmpty() ); DataElement mssopinst = GetDataElement( Tag(0x0002, 0x0003) ); const ByteValue *bv = sopinst.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); mssopinst.SetByteValue( bv->GetPointer(), bv->GetLength() ); Replace( mssopinst ); } } - //assert( !GetDataElement( Tag(0x0002,0x0003) ).IsEmpty() ); + //gdcm_assert( !GetDataElement( Tag(0x0002,0x0003) ).IsEmpty() ); // Transfer Syntax UID (0002,0010) -> ??? (computed at write time at most) if( FindDataElement( Tag(0x0002, 0x0010) ) && !GetDataElement( Tag(0x0002,0x0010) ).IsEmpty() ) { DataElement tsuid = GetDataElement( Tag(0x0002, 0x0010) ); const char * datasetts = DataSetTS.GetString(); const ByteValue * bv = tsuid.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); std::string currentts( bv->GetPointer(), bv->GetPointer() + bv->GetLength() ); if( strlen(currentts.c_str()) != strlen(datasetts) || strcmp( currentts.c_str(), datasetts ) != 0 ) @@ -316,7 +316,7 @@ void FileMetaInformation::FillFromDataSet(DataSet const &ds) // TODO: Need to check Implementation UID is actually a valid UID... //const DataElement& impuid = GetDataElement( Tag(0x0002, 0x0012) ); //const ByteValue *bv = impuid.GetByteValue(); - //assert( bv ); + //gdcm_assert( bv ); //std::string copy( bv->GetPointer(), bv->GetLength() ); //if( !UIDGenerator::IsValid( copy.c_str() ) ) // { @@ -351,11 +351,11 @@ void FileMetaInformation::FillFromDataSet(DataSet const &ds) Attribute<0x0002, 0x0000> filemetagrouplength; Remove( filemetagrouplength.GetTag() ); unsigned int glen = GetLength(); - assert( (glen % 2) == 0 ); + gdcm_assert( (glen % 2) == 0 ); filemetagrouplength.SetValue( glen ); Insert( filemetagrouplength.GetAsDataElement() ); - assert( !IsEmpty() ); + gdcm_assert( !IsEmpty() ); } // FIXME @@ -372,7 +372,7 @@ bool ReadExplicitDataElement(std::istream &is, ExplicitDataElement &de) Tag t; if( !t.template Read(is) ) { - assert(0 && "Should not happen" ); + gdcm_assert(0 && "Should not happen" ); return false; } //std::cout << "Tag: " << t << std::endl; @@ -384,8 +384,8 @@ bool ReadExplicitDataElement(std::istream &is, ExplicitDataElement &de) // which seems to be quite different than fseeking in reverse from // the current position... ??? //is.seekg( start, std::ios::beg ); - assert( (start - currentpos) <= 0); - assert( (int)(start - currentpos) == -4 ); + gdcm_assert( (start - currentpos) <= 0); + gdcm_assert( (int)(start - currentpos) == -4 ); is.seekg( (start - currentpos), std::ios::cur ); return false; } @@ -403,7 +403,7 @@ bool ReadExplicitDataElement(std::istream &is, ExplicitDataElement &de) { if( !vl.template Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return false; } } @@ -417,12 +417,12 @@ bool ReadExplicitDataElement(std::istream &is, ExplicitDataElement &de) ByteValue *bv = nullptr; if( vr == VR::SQ ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return false; } else if( vl.IsUndefined() ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return false; } else @@ -433,13 +433,13 @@ bool ReadExplicitDataElement(std::istream &is, ExplicitDataElement &de) bv->SetLength(vl); // perform realloc if( !bv->template Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return false; } //std::cout << "Value : "; //bv->Print( std::cout ); //std::cout << std::endl; - assert( bv->GetLength() == vl ); + gdcm_assert( bv->GetLength() == vl ); de.SetTag(t); de.SetVR(vr); @@ -449,7 +449,7 @@ bool ReadExplicitDataElement(std::istream &is, ExplicitDataElement &de) // if( vl == 0 ) // { -// assert( de.IsEmpty() ); +// gdcm_assert( de.IsEmpty() ); // } return true; @@ -464,7 +464,7 @@ bool ReadImplicitDataElement(std::istream &is, ImplicitDataElement &de) Tag t; if( !t.template Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return false; } //std::cout << "Tag: " << t << std::endl; @@ -478,13 +478,13 @@ bool ReadImplicitDataElement(std::istream &is, ImplicitDataElement &de) VL vl; if( !vl.template Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return false; } ByteValue *bv = nullptr; if( vl.IsUndefined() ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return false; } else @@ -495,7 +495,7 @@ bool ReadImplicitDataElement(std::istream &is, ImplicitDataElement &de) bv->SetLength(vl); // perform realloc if( !bv->template Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return false; } de.SetTag(t); @@ -588,7 +588,7 @@ std::istream &FileMetaInformation::Read(std::istream &is) std::istream &FileMetaInformation::ReadCompat(std::istream &is) { // \precondition - assert( is.good() ); + gdcm_assert( is.good() ); // First off save position in case we fail (no File Meta Information) // See PS 3.5, Data Element Structure With Explicit VR if( !IsEmpty() ) @@ -659,7 +659,7 @@ std::istream &FileMetaInformation::ReadCompat(std::istream &is) } else { - //assert( t.GetElement() == 0x0 ); + //gdcm_assert( t.GetElement() == 0x0 ); char vr_str[3]; VR::VRType vr = VR::VR_END; if( is.read(vr_str, 2) ) @@ -691,7 +691,7 @@ std::istream &FileMetaInformation::ReadCompat(std::istream &is) // something like IM-0001-0066.CommandTag00.dcm was crafted ide.ReadValue(is); ReadCompat(is); // this will read the next element - assert( DataSetTS == TransferSyntax::ImplicitVRLittleEndian ); + gdcm_assert( DataSetTS == TransferSyntax::ImplicitVRLittleEndian ); is.seekg(-12, std::ios::cur); // Seek back return is; } @@ -730,7 +730,7 @@ bool AddVRToDataElement(DataElement &de) template std::istream &FileMetaInformation::ReadCompatInternal(std::istream &is) { - //assert( t.GetGroup() == 0x0002 ); + //gdcm_assert( t.GetGroup() == 0x0002 ); // if( t.GetGroup() == 0x0002 ) { // Purposely not Re-use ReadVR since we can read VR_END @@ -821,7 +821,7 @@ std::istream &FileMetaInformation::ReadCompatInternal(std::istream &is) //void FileMetaInformation::SetTransferSyntaxType(TS const &ts) //{ -// //assert( DS == 0 ); +// //gdcm_assert( DS == 0 ); // //InternalTS = ts; //} @@ -835,7 +835,7 @@ void FileMetaInformation::ComputeDataSetTransferSyntax() const ByteValue *bv = de.GetByteValue(); if( !bv ) { - throw Exception( "Unknown Transfer syntax" ); + throw Exception( "NULL Transfer syntax" ); } // Pad string with a \0 ts = std::string(bv->GetPointer(), bv->GetLength()); @@ -871,7 +871,7 @@ std::string FileMetaInformation::GetMediaStorageAsString() const std::string ts; { const ByteValue *bv = de.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); if( bv->GetPointer() && bv->GetLength() ) { // Pad string with a \0 @@ -931,7 +931,7 @@ std::ostream &FileMetaInformation::Write(std::ostream &os) const } // else // { -// assert(0); +// gdcm_assert(0); // } #if 0 // At least make sure to have group length diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFragment.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFragment.cxx index 537a509014e..b9eab900a4f 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFragment.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFragment.cxx @@ -18,8 +18,8 @@ namespace gdcm_ns VL Fragment::GetLength() const { - assert( !ValueLengthField.IsUndefined() ); - assert( !ValueField || ValueField->GetLength() == ValueLengthField ); + gdcm_assert( !ValueLengthField.IsUndefined() ); + gdcm_assert( !ValueField || ValueField->GetLength() == ValueLengthField ); return TagField.GetLength() + ValueLengthField.GetLength() + ValueLengthField; } @@ -27,9 +27,9 @@ VL Fragment::GetLength() const VL Fragment::ComputeLength() const { const ByteValue *bv = GetByteValue(); - assert( bv ); - assert( !ValueLengthField.IsUndefined() ); - //assert( !ValueField || ValueField->GetLength() == ValueLengthField ); + gdcm_assert( bv ); + gdcm_assert( !ValueLengthField.IsUndefined() ); + //gdcm_assert( !ValueField || ValueField->GetLength() == ValueLengthField ); return TagField.GetLength() + ValueLengthField.GetLength() + bv->ComputeLength() /*ValueLengthField*/; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFragment.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFragment.h index 8c0fdceb939..d0fc2d22775 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFragment.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmFragment.h @@ -119,7 +119,7 @@ class GDCM_EXPORT Fragment : public DataElement while( cont ) { TagField.Read(is); - assert( is ); + gdcm_assert( is ); if( TagField != itemStart && TagField != seqDelItem ) { ++offset; @@ -136,7 +136,7 @@ class GDCM_EXPORT Fragment : public DataElement cont = false; } } - assert( TagField == itemStart || TagField == seqDelItem ); + gdcm_assert( TagField == itemStart || TagField == seqDelItem ); if( !ValueLengthField.Read(is) ) { return is; @@ -166,10 +166,10 @@ class GDCM_EXPORT Fragment : public DataElement const Tag seqDelItem(0xfffe,0xe0dd); if( !TagField.Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } - assert( TagField == itemStart + gdcm_assert( TagField == itemStart || TagField == seqDelItem ); const ByteValue *bv = GetByteValue(); // VL @@ -177,23 +177,23 @@ class GDCM_EXPORT Fragment : public DataElement // CompressedLossy.dcm if( IsEmpty() ) { - //assert( bv ); + //gdcm_assert( bv ); VL zero = 0; if( !zero.Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } } else { - assert( ValueLengthField ); - assert( !ValueLengthField.IsUndefined() ); + gdcm_assert( ValueLengthField ); + gdcm_assert( !ValueLengthField.IsUndefined() ); const VL actuallen = bv->ComputeLength(); - assert( actuallen == ValueLengthField || actuallen == ValueLengthField + 1 ); + gdcm_assert( actuallen == ValueLengthField || actuallen == ValueLengthField + 1 ); if( !actuallen.Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } } @@ -201,11 +201,11 @@ class GDCM_EXPORT Fragment : public DataElement if( ValueLengthField && bv ) { // Self - assert( bv ); - assert( bv->GetLength() == ValueLengthField ); + gdcm_assert( bv ); + gdcm_assert( bv->GetLength() == ValueLengthField ); if( !bv->Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmImplicitDataElement.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmImplicitDataElement.cxx index 0cf211deea6..35af38b12fc 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmImplicitDataElement.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmImplicitDataElement.cxx @@ -23,7 +23,7 @@ VL ImplicitDataElement::GetLength() const { if( ValueLengthField.IsUndefined() ) { - assert( ValueField->GetLength().IsUndefined() ); + gdcm_assert( ValueField->GetLength().IsUndefined() ); Value *p = ValueField; SequenceOfItems *sq = dynamic_cast(p); if( sq ) @@ -35,12 +35,12 @@ VL ImplicitDataElement::GetLength() const SequenceOfFragments *sf = dynamic_cast(p); if( sf ) { - //assert( VRField & VR::OB_OW ); // VR::INVALID is not possible AFAIK... + //gdcm_assert( VRField & VR::OB_OW ); // VR::INVALID is not possible AFAIK... return TagField.GetLength() /*+ VRField.GetLength()*/ + ValueLengthField.GetLength() + sf->ComputeLength(); } #endif - assert( !ValueLengthField.IsUndefined() ); + gdcm_assert( !ValueLengthField.IsUndefined() ); return ValueLengthField; } //else if( const SequenceOfItems *sqi = GetSequenceOfItems() ) @@ -52,7 +52,7 @@ VL ImplicitDataElement::GetLength() const } else { - assert( !ValueField || ValueField->GetLength() == ValueLengthField ); + gdcm_assert( !ValueField || ValueField->GetLength() == ValueLengthField ); return TagField.GetLength() + ValueLengthField.GetLength() + ValueLengthField; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmImplicitDataElement.txx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmImplicitDataElement.txx index b7dfade6cda..bca17f0fa43 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmImplicitDataElement.txx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmImplicitDataElement.txx @@ -41,17 +41,17 @@ std::istream &ImplicitDataElement::ReadPreValue(std::istream& is) if( !is ) { if( !is.eof() ) // FIXME This should not be needed - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } const Tag itemStartItem(0xfffe,0xe000); if( TagField == itemStartItem ) return is; - //assert( TagField != Tag(0xfffe,0xe0dd) ); + //gdcm_assert( TagField != Tag(0xfffe,0xe0dd) ); // Read Value Length if( !ValueLengthField.Read(is) ) { - //assert(0 && "Should not happen"); + //gdcm_assert(0 && "Should not happen"); throw Exception("Impossible ValueLengthField"); return is; } @@ -63,7 +63,7 @@ std::istream &ImplicitDataElement::ReadValue(std::istream &is, bool readvalues) { if( is.eof() ) return is; const Tag itemStartItem(0xfffe,0xe000); - assert( TagField != itemStartItem ); + gdcm_assert( TagField != itemStartItem ); /* * technically this should not be needed, but what if an implementor, forgot @@ -93,9 +93,9 @@ std::istream &ImplicitDataElement::ReadValue(std::istream &is, bool readvalues) } else if( ValueLengthField.IsUndefined() ) { - //assert( de.GetVR() == VR::SQ ); + //gdcm_assert( de.GetVR() == VR::SQ ); // FIXME what if I am reading the pixel data... - //assert( TagField != Tag(0x7fe0,0x0010) ); + //gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); if( TagField != Tag(0x7fe0,0x0010) ) { ValueField = new SequenceOfItems; @@ -133,7 +133,7 @@ std::istream &ImplicitDataElement::ReadValue(std::istream &is, bool readvalues) is.seekg(-4, std::ios::cur ); if( item == itemStart ) { - assert( TagField != Tag(0x7fe0,0x0010) ); + gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new SequenceOfItems; } #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION @@ -150,7 +150,7 @@ std::istream &ImplicitDataElement::ReadValue(std::istream &is, bool readvalues) { if( !ValueIO::Read(is,*ValueField,readvalues) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); } gdcmWarningMacro( "Illegal: Explicit SQ found in a file with " "TransferSyntax=Implicit for tag: " << TagField ); @@ -161,7 +161,7 @@ std::istream &ImplicitDataElement::ReadValue(std::istream &is, bool readvalues) std::streampos current = is.tellg(); std::streamoff diff = start - current; is.seekg( diff, std::ios::cur ); - assert( diff == -14 ); + gdcm_assert( diff == -14 ); ValueIO::Read(is,*ValueField,readvalues); } catch( std::exception & ) @@ -178,7 +178,7 @@ std::istream &ImplicitDataElement::ReadValue(std::istream &is, bool readvalues) ValueField->SetLength(ValueLengthField); // perform realloc if( !ValueIO::Read(is,*ValueField,readvalues) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); } return is; } @@ -222,14 +222,14 @@ std::istream &ImplicitDataElement::ReadValue(std::istream &is, bool readvalues) VR vrfield = GetVRFromTag( TagField ); if( vrfield & VR::VRASCII || vrfield == VR::INVALID ) { - //assert( VRField.GetSize() == 1 ); + //gdcm_assert( VRField.GetSize() == 1 ); failed = !ValueIO::Read(is,*ValueField,readvalues); } else { - assert( vrfield & VR::VRBINARY ); + gdcm_assert( vrfield & VR::VRBINARY ); unsigned int vrsize = vrfield.GetSize(); - assert( vrsize == 1 || vrsize == 2 || vrsize == 4 || vrsize == 8 ); + gdcm_assert( vrsize == 1 || vrsize == 2 || vrsize == 4 || vrsize == 8 ); if(vrfield==VR::AT) vrsize = 2; switch(vrsize) { @@ -247,7 +247,7 @@ std::istream &ImplicitDataElement::ReadValue(std::istream &is, bool readvalues) break; default: failed = true; - assert(0); + gdcm_assert(0); } } #else @@ -276,12 +276,12 @@ std::istream &ImplicitDataElement::ReadValue(std::istream &is, bool readvalues) VL dummy = ValueField->GetLength(); if( ValueLengthField != dummy ) { - gdcmWarningMacro( "ValueLengthField was bogus" ); assert(0); + gdcmWarningMacro( "ValueLengthField was bogus" ); gdcm_assert(0); ValueLengthField = dummy; } #else - assert( ValueLengthField == ValueField->GetLength() ); - assert( VRField == VR::INVALID ); + gdcm_assert( ValueLengthField == ValueField->GetLength() ); + gdcm_assert( VRField == VR::INVALID ); #endif return is; @@ -330,9 +330,9 @@ std::istream &ImplicitDataElement::ReadValueWithLength(std::istream& is, VL & le } else if( ValueLengthField.IsUndefined() ) { - //assert( de.GetVR() == VR::SQ ); + //gdcm_assert( de.GetVR() == VR::SQ ); // FIXME what if I am reading the pixel data... - //assert( TagField != Tag(0x7fe0,0x0010) ); + //gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); if( TagField != Tag(0x7fe0,0x0010) ) { ValueField = new SequenceOfItems; @@ -370,7 +370,7 @@ std::istream &ImplicitDataElement::ReadValueWithLength(std::istream& is, VL & le is.seekg(-4, std::ios::cur ); if( item == itemStart ) { - assert( TagField != Tag(0x7fe0,0x0010) ); + gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new SequenceOfItems; } #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION @@ -387,7 +387,7 @@ std::istream &ImplicitDataElement::ReadValueWithLength(std::istream& is, VL & le { if( !ValueIO::Read(is,*ValueField,readvalues) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); } gdcmWarningMacro( "Illegal: Explicit SQ found in a file with " "TransferSyntax=Implicit for tag: " << TagField ); @@ -398,7 +398,7 @@ std::istream &ImplicitDataElement::ReadValueWithLength(std::istream& is, VL & le std::streampos current = is.tellg(); std::streamoff diff = start - current;//could be bad, if the specific implementation does not support negative streamoff values. is.seekg( diff, std::ios::cur ); - assert( diff == -14 ); + gdcm_assert( diff == -14 ); ValueIO::Read(is,*ValueField,readvalues); } catch( std::exception & ) @@ -409,14 +409,14 @@ std::istream &ImplicitDataElement::ReadValueWithLength(std::istream& is, VL & le } else if ( item == itemPMSStart2 ) { - assert( 0 ); // FIXME: Sync Read/ReadWithLength + gdcm_assert( 0 ); // FIXME: Sync Read/ReadWithLength gdcmWarningMacro( "Illegal: SQ start with " << itemPMSStart2 << " instead of " << itemStart << " for tag: " << TagField ); ValueField = new SequenceOfItems; ValueField->SetLength(ValueLengthField); // perform realloc if( !ValueIO::Read(is,*ValueField,readvalues) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); } return is; } @@ -460,14 +460,14 @@ std::istream &ImplicitDataElement::ReadValueWithLength(std::istream& is, VL & le VR vrfield = GetVRFromTag( TagField ); if( vrfield & VR::VRASCII || vrfield == VR::INVALID ) { - //assert( VRField.GetSize() == 1 ); + //gdcm_assert( VRField.GetSize() == 1 ); failed = !ValueIO::Read(is,*ValueField,readvalues); } else { - assert( vrfield & VR::VRBINARY ); + gdcm_assert( vrfield & VR::VRBINARY ); unsigned int vrsize = vrfield.GetSize(); - assert( vrsize == 1 || vrsize == 2 || vrsize == 4 || vrsize == 8 ); + gdcm_assert( vrsize == 1 || vrsize == 2 || vrsize == 4 || vrsize == 8 ); if(vrfield==VR::AT) vrsize = 2; switch(vrsize) { @@ -485,7 +485,7 @@ std::istream &ImplicitDataElement::ReadValueWithLength(std::istream& is, VL & le break; default: failed = true; - assert(0); + gdcm_assert(0); } } #else @@ -519,8 +519,8 @@ std::istream &ImplicitDataElement::ReadValueWithLength(std::istream& is, VL & le ValueLengthField = dummy; } #else - assert( ValueLengthField == ValueField->GetLength() ); - assert( VRField == VR::INVALID ); + gdcm_assert( ValueLengthField == ValueField->GetLength() ); + gdcm_assert( VRField == VR::INVALID ); #endif return is; @@ -534,7 +534,7 @@ const std::ostream &ImplicitDataElement::Write(std::ostream &os) const // Write Tag if( !TagField.Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } // Write Value Length @@ -547,10 +547,10 @@ const std::ostream &ImplicitDataElement::Write(std::ostream &os) const // Hum, we might have to recompute the length: // See TestWriter2, where an explicit SQ is converted to implicit SQ VL len = sqi->template ComputeLength(); - //assert( len == ValueLengthField ); + //gdcm_assert( len == ValueLengthField ); if( !len.Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } } @@ -560,20 +560,20 @@ const std::ostream &ImplicitDataElement::Write(std::ostream &os) const if( TagField == Tag(0x7fe0,0x0010) && ValueLengthField.IsUndefined() ) throw Exception( "VL u/f Impossible" ); if( !ValueLengthField.Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } } // Write Value if( ValueLengthField ) { - assert( ValueField ); + gdcm_assert( ValueField ); gdcmAssertAlwaysMacro( ValueLengthField == ValueField->GetLength() ); - assert( TagField != Tag(0xfffe, 0xe00d) + gdcm_assert( TagField != Tag(0xfffe, 0xe00d) && TagField != Tag(0xfffe, 0xe0dd) ); if( !ValueIO::Write(os,*ValueField) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmItem.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmItem.h index 6638aa33e53..9d2673222b1 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmItem.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmItem.h @@ -61,7 +61,7 @@ class GDCM_EXPORT Item : public DataElement // Update the length if( !IsUndefinedLength() ) { - assert( 0 && "InsertDataElement" ); + gdcm_assert( 0 && "InsertDataElement" ); //ValueLengthField += de.GetLength(); } } @@ -99,7 +99,7 @@ class GDCM_EXPORT Item : public DataElement { DataSet &nested = NestedDataSet; nested.Clear(); - assert( nested.IsEmpty() ); + gdcm_assert( nested.IsEmpty() ); } if( !TagField.Read(is) ) { @@ -119,7 +119,7 @@ class GDCM_EXPORT Item : public DataElement if( !ValueLengthField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } // Self @@ -133,7 +133,7 @@ class GDCM_EXPORT Item : public DataElement } //else if( ValueLengthField == 0 ) // { - // //assert( TagField == Tag( 0xfffe, 0xe0dd) ); + // //gdcm_assert( TagField == Tag( 0xfffe, 0xe0dd) ); // if( TagField != Tag( 0xfffe, 0xe0dd) ) // { // gdcmErrorMacro( "SQ: " << TagField << " has a length of 0" ); @@ -143,7 +143,7 @@ class GDCM_EXPORT Item : public DataElement { DataSet &nested = NestedDataSet; nested.Clear(); - assert( nested.IsEmpty() ); + gdcm_assert( nested.IsEmpty() ); std::streampos start = is.tellg(); try { @@ -158,7 +158,7 @@ class GDCM_EXPORT Item : public DataElement // You have to byteswap the length but not the tag...sigh gdcmWarningMacro( "Attempt to read nested Item without byteswapping the Value Length." ); start -= is.tellg(); - assert( start < 0 ); + gdcm_assert( start < 0 ); is.seekg( start, std::ios::cur ); nested.Clear(); nested.template ReadNested(is); @@ -174,14 +174,14 @@ class GDCM_EXPORT Item : public DataElement } catch(...) { - assert(0); + gdcm_assert(0); } } else /* if( ValueLengthField.IsUndefined() ) */ { DataSet &nested = NestedDataSet; nested.Clear(); - assert( nested.IsEmpty() ); + gdcm_assert( nested.IsEmpty() ); nested.template ReadWithLength(is, ValueLengthField); ByteSwapFilter bsf(nested); bsf.ByteSwap(); @@ -200,11 +200,11 @@ class GDCM_EXPORT Item : public DataElement gdcmDebugMacro( "Invalid Item, found tag: " << TagField); throw Exception( "Not a valid Item" ); } - assert( TagField == Tag(0xfffe, 0xe000) || TagField == Tag(0xfffe, 0xe0dd) ); + gdcm_assert( TagField == Tag(0xfffe, 0xe000) || TagField == Tag(0xfffe, 0xe0dd) ); if( !ValueLengthField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } // Self @@ -220,15 +220,15 @@ class GDCM_EXPORT Item : public DataElement { DataSet &nested = NestedDataSet; nested.Clear(); - assert( nested.IsEmpty() ); + gdcm_assert( nested.IsEmpty() ); nested.template ReadNested(is); } else /* if( ValueLengthField.IsUndefined() ) */ { - assert( !ValueLengthField.IsUndefined() ); + gdcm_assert( !ValueLengthField.IsUndefined() ); DataSet &nested = NestedDataSet; nested.Clear(); - assert( nested.IsEmpty() ); + gdcm_assert( nested.IsEmpty() ); nested.template ReadWithLength(is, ValueLengthField); } @@ -252,12 +252,12 @@ class GDCM_EXPORT Item : public DataElement if( TagField == Tag(0xfffe, 0xe0dd) ) { gdcmWarningMacro( "SeqDelItem found in defined length Sequence" ); - assert( ValueLengthField == 0 ); - assert( NestedDataSet.Size() == 0 ); + gdcm_assert( ValueLengthField == 0 ); + gdcm_assert( NestedDataSet.Size() == 0 ); } if( !TagField.Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } } @@ -265,18 +265,18 @@ class GDCM_EXPORT Item : public DataElement { if( !ValueLengthField.Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } } else { const VL dummy = NestedDataSet.GetLength(); - assert( dummy % 2 == 0 ); - //assert( ValueLengthField == dummy ); + gdcm_assert( dummy % 2 == 0 ); + //gdcm_assert( ValueLengthField == dummy ); if( !dummy.Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmItem.txx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmItem.txx index d71357ec02d..4885b4283be 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmItem.txx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmItem.txx @@ -24,13 +24,13 @@ VL Item::GetLength() const { if( ValueLengthField.IsUndefined() ) { - assert( !NestedDataSet.GetLength().IsUndefined() ); + gdcm_assert( !NestedDataSet.GetLength().IsUndefined() ); // Item Start 4 // Item Length 4 // DataSet ? // Item End Delimitation 4 // Item End Length 4 - assert( NestedDataSet.GetLength() % 2 == 0 ); + gdcm_assert( NestedDataSet.GetLength() % 2 == 0 ); return TagField.GetLength() /* 4 */ + ValueLengthField.GetLength() /* 4 */ + NestedDataSet.GetLength() + 4 + 4; } @@ -45,7 +45,7 @@ VL Item::GetLength() const // initially read explicit dataset in which case the two length cannot // related to each other //gdcmAssertAlwaysMacro( ValueLengthField == nestedlen ); - assert( nestedlen % 2 == 0 ); + gdcm_assert( nestedlen % 2 == 0 ); return TagField.GetLength() /* 4 */ + ValueLengthField.GetLength() /* 4 */ //+ ValueLengthField; + nestedlen; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmMediaStorage.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmMediaStorage.cxx index dc63307cdd2..72200c6ef21 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmMediaStorage.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmMediaStorage.cxx @@ -178,13 +178,13 @@ MediaStorage::MSType MediaStorage::GetMSType(const char *str) } } - //assert(0); + //gdcm_assert(0); return MS_END; } const char* MediaStorage::GetMSString(MSType ms) { - assert( ms <= MS_END ); + gdcm_assert( ms <= MS_END ); return MSStrings[(int)ms]; } @@ -349,21 +349,21 @@ static const MSModalityType MSModalityTypes[] = { unsigned int MediaStorage::GetNumberOfMSType() { const unsigned int n = MS_END; - assert( n > 0 ); + gdcm_assert( n > 0 ); return n; } unsigned int MediaStorage::GetNumberOfMSString() { static const unsigned int n = sizeof( MSStrings ) / sizeof( *MSStrings ); - assert( n > 0 ); + gdcm_assert( n > 0 ); return n - 1; } unsigned int MediaStorage::GetNumberOfModality() { static const unsigned int n = sizeof( MSModalityTypes ) / sizeof( *MSModalityTypes ); - assert( n > 0 ); + gdcm_assert( n > 0 ); return n - 1; } @@ -371,7 +371,7 @@ const char *MediaStorage::GetModality() const { if (!MSModalityTypes[MSField].Modality) return nullptr; - assert( MSModalityTypes[MSField].Modality[0] != ' ' ); // FIXME + gdcm_assert( MSModalityTypes[MSField].Modality[0] != ' ' ); // FIXME return MSModalityTypes[MSField].Modality; } @@ -379,7 +379,7 @@ unsigned int MediaStorage::GetModalityDimension() const { if (!MSModalityTypes[MSField].Modality) return 0; - assert( MSModalityTypes[MSField].Dimension ); + gdcm_assert( MSModalityTypes[MSField].Dimension ); return MSModalityTypes[MSField].Dimension; } @@ -485,7 +485,7 @@ void MediaStorage::SetFromSourceImageSequence(DataSet const &ds) const DataElement& de = subds.GetDataElement( referencedSOPClassUIDTag ); const ByteValue *sopclassuid = de.GetByteValue(); // LEADTOOLS_FLOWERS-8-PAL-Uncompressed.dcm - //assert( sopclassuid ); + //gdcm_assert( sopclassuid ); if( sopclassuid ) { std::string sopclassuid_str( @@ -498,7 +498,7 @@ void MediaStorage::SetFromSourceImageSequence(DataSet const &ds) sopclassuid_str = sopclassuid_str.substr(0,pos); } MediaStorage ms = MediaStorage::GetMSType(sopclassuid_str.c_str()); - assert( ms != MS_END ); + gdcm_assert( ms != MS_END ); MSField = ms; } } @@ -608,7 +608,7 @@ bool MediaStorage::SetFromFile(File const &file) ms2.SetFromSourceImageSequence(ds); if( MSField != ms2 && ms2 != MediaStorage::MS_END ) { - assert( MediaStorage::IsImage( ms2 ) ); + gdcm_assert( MediaStorage::IsImage( ms2 ) ); gdcmWarningMacro( "Object is declared as SecondaryCaptureImageStorage but according" " to Source Image Sequence it was derived from " << ms2 << ". Using it instead" ); MSField = ms2; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmParseException.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmParseException.h index 4093dc53c86..5b99fefb8fa 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmParseException.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmParseException.h @@ -68,7 +68,7 @@ class ParseException : public Exception return strwhat.c_str(); } */ - void SetLastElement(DataElement& de) + void SetLastElement(const DataElement& de) { LastElement = de; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmPrivateTag.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmPrivateTag.cxx index 052b4f2cc81..4c64d83281c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmPrivateTag.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmPrivateTag.cxx @@ -60,12 +60,12 @@ namespace gdcm_ns { const char *s1 = Owner.c_str(); const char *s2 = _val.GetOwner(); - assert( s1 ); - assert( s2 ); + gdcm_assert( s1 ); + gdcm_assert( s2 ); if( *s1 ) - assert( s1[strlen(s1)-1] != ' ' ); + gdcm_assert( s1[strlen(s1)-1] != ' ' ); if( *s2 ) - assert( s2[strlen(s2)-1] != ' ' ); + gdcm_assert( s2[strlen(s2)-1] != ' ' ); bool res = strcmp(s1, s2) < 0; #ifdef DEBUG_DUPLICATE if( *s1 && *s2 && gdcm::System::StrCaseCmp(s1,s2) == 0 && strcmp(s1,s2) != 0 ) @@ -73,11 +73,11 @@ namespace gdcm_ns // FIXME: // Typically this should only happen with the "Philips MR Imaging DD 001" vs "PHILIPS MR IMAGING DD 001" // or "Philips Imaging DD 001" vr "PHILIPS IMAGING DD 001" - //assert( strcmp(Owner.c_str(), _val.GetOwner()) == 0 ); + //gdcm_assert( strcmp(Owner.c_str(), _val.GetOwner()) == 0 ); //return true; const bool res2 = gdcm::System::StrCaseCmp(s1,s2) < 0; res = res2; - assert( 0 ); + gdcm_assert( 0 ); } #endif return res; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmPrivateTag.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmPrivateTag.h index 84b6fea866c..b535ae702d8 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmPrivateTag.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmPrivateTag.h @@ -90,7 +90,7 @@ class GDCM_EXPORT PrivateTag : public Tag inline std::ostream& operator<<(std::ostream &os, const PrivateTag &val) { - //assert( !val.Owner.empty() ); + //gdcm_assert( !val.Owner.empty() ); os.setf( std::ios::right ); os << std::hex << '(' << std::setw( 4 ) << std::setfill( '0' ) << val[0] << ',' << std::setw( 2 ) << std::setfill( '0' ) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmReader.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmReader.cxx index 454b0bf6192..0875c70fc0c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmReader.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmReader.cxx @@ -85,7 +85,7 @@ bool Reader::ReadDataSet() TransferSyntax Reader::GuessTransferSyntax() { // Don't call this function if you have a meta file info - //assert( Header->GetTransferSyntaxType() == TransferSyntax::TS_END ); + //gdcm_assert( Header->GetTransferSyntaxType() == TransferSyntax::TS_END ); std::streampos start = Stream->tellg(); SwapCode sc = SwapCode::Unknown; TransferSyntax::NegociatedType nts = TransferSyntax::Unknown; @@ -103,7 +103,7 @@ TransferSyntax Reader::GuessTransferSyntax() sc = SwapCode::BigEndian; break; default: - assert(0); + gdcm_assert(0); } // Purposely not Re-use ReadVR since we can read VR_END char vr_str[3]; @@ -117,7 +117,7 @@ TransferSyntax Reader::GuessTransferSyntax() } else { - assert( !(VR::IsSwap(vr_str))); + gdcm_assert( !(VR::IsSwap(vr_str))); Stream->seekg(-2, std::ios::cur); // Seek back if( t.GetElement() == 0x0000 ) { @@ -140,7 +140,7 @@ TransferSyntax Reader::GuessTransferSyntax() gdcmWarningMacro( "Bad Big Endian" ); break; default: - assert(0); + gdcm_assert(0); } } nts = TransferSyntax::Implicit; @@ -149,14 +149,14 @@ TransferSyntax Reader::GuessTransferSyntax() else { gdcmWarningMacro( "Start with a private tag creator" ); - assert( t.GetGroup() > 0x0002 ); + gdcm_assert( t.GetGroup() > 0x0002 ); switch( t.GetElement() ) { case 0x0010: sc = SwapCode::LittleEndian; break; default: - assert(0); + gdcm_assert(0); } // Purposely not Re-use ReadVR since we can read VR_END char vr_str[3]; @@ -177,8 +177,8 @@ TransferSyntax Reader::GuessTransferSyntax() gdcmWarningMacro( "Very dangerous assertion needs some work" ); } } - assert( nts != TransferSyntax::Unknown ); - assert( sc != SwapCode::Unknown ); + gdcm_assert( nts != TransferSyntax::Unknown ); + gdcm_assert( sc != SwapCode::Unknown ); if( nts == TransferSyntax::Implicit ) { if( sc == SwapCode::BigEndian ) @@ -191,15 +191,15 @@ TransferSyntax Reader::GuessTransferSyntax() } else { - assert(0); + gdcm_assert(0); } } else { - assert(0); + gdcm_assert(0); } Stream->seekg( start, std::ios::beg ); - assert( ts != TransferSyntax::TS_END ); + gdcm_assert( ts != TransferSyntax::TS_END ); return ts; } @@ -227,7 +227,7 @@ namespace details static void Check(bool b, std::istream &stream) { (void)stream; - if( b ) assert( stream.eof() ); + if( b ) gdcm_assert( stream.eof() ); } }; @@ -362,7 +362,7 @@ bool Reader::InternalReadCommon(const T_Caller &caller) } catch( ... ) { - assert(0); + gdcm_assert(0); } bool hasmetaheader = false; @@ -374,7 +374,7 @@ bool Reader::InternalReadCommon(const T_Caller &caller) { F->GetHeader().Read( is ); hasmetaheader = true; - assert( !F->GetHeader().IsEmpty() ); + gdcm_assert( !F->GetHeader().IsEmpty() ); } catch( std::exception &ex ) { @@ -382,7 +382,7 @@ bool Reader::InternalReadCommon(const T_Caller &caller) gdcmWarningMacro(ex.what()); // Weird implicit meta header: is.seekg(128+4, std::ios::beg ); - assert( is.good() ); + gdcm_assert( is.good() ); try { F->GetHeader().ReadCompat(is); @@ -410,7 +410,7 @@ bool Reader::InternalReadCommon(const T_Caller &caller) catch( ... ) { // Ooops.. - assert(0); + gdcm_assert(0); } if( F->GetHeader().IsEmpty() ) { @@ -431,7 +431,7 @@ bool Reader::InternalReadCommon(const T_Caller &caller) zlib_stream::zip_istream gzis( is ); // FIXME: we also know in this case that we are dealing with Explicit: - assert( ts.GetNegociatedType() == TransferSyntax::Explicit ); + gdcm_assert( ts.GetNegociatedType() == TransferSyntax::Explicit ); //F->GetDataSet().ReadUpToTag(gzis,tag, skiptags); caller.template ReadCommon(gzis); // I need the following hack to read: srwithgraphdeflated.dcm @@ -475,14 +475,14 @@ bool Reader::InternalReadCommon(const T_Caller &caller) std::streampos start = is.tellg(); is.seekg( 0, std::ios::end); std::streampos end = is.tellg(); - assert( !is.eof() ); - assert( is.good() ); + gdcm_assert( !is.eof() ); + gdcm_assert( is.good() ); std::streamoff theOffset = end-start; assert (theOffset > 0 || (uint32_t)theOffset < std::numeric_limits::max()); VL l = (uint32_t)(theOffset); is.seekg( start, std::ios::beg ); - assert( is.good() ); - assert( !is.eof() ); + gdcm_assert( is.good() ); + gdcm_assert( !is.eof() ); caller.template ReadCommonWithLength(is,l); } } @@ -575,7 +575,7 @@ bool Reader::InternalReadCommon(const T_Caller &caller) // gdcmWarningMacro( "Attempt to read Philips with ByteSwap private sequence wrongly encoded"); F->GetDataSet().Clear(); // remove garbage from 1st attempt... - assert(0); // TODO FIXME + gdcm_assert(0); // TODO FIXME } else if( ex.GetLastElement().GetVR() == VR::INVALID ) { @@ -694,7 +694,7 @@ bool Reader::InternalReadCommon(const T_Caller &caller) success = false; } - //if( success ) assert( Stream->eof() ); + //if( success ) gdcm_assert( Stream->eof() ); caller.Check(success, *Stream ); } catch( Exception &ex ) @@ -782,14 +782,14 @@ bool Reader::CanRead() const if (bigendian) { t.Read(ss); - //assert( t.GetGroup() != 0x2 ); + //gdcm_assert( t.GetGroup() != 0x2 ); if( t.GetGroup() <= 0xff ) sc = SwapCode::BigEndian; } else { t.Read(ss); - //assert( t.GetGroup() != 0x2 ); + //gdcm_assert( t.GetGroup() != 0x2 ); if( t.GetGroup() <= 0xff ) sc = SwapCode::LittleEndian; } @@ -844,7 +844,7 @@ void Reader::SetFileName(const char *utf8path) if( Ifstream->is_open() ) { Stream = Ifstream; - assert( Stream && *Stream ); + gdcm_assert( Stream && *Stream ); } else { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmReader.strict.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmReader.strict.cxx index c6f64228a96..4a5b9cc5978 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmReader.strict.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmReader.strict.cxx @@ -28,7 +28,7 @@ namespace gdcm bool StrictReadUpToTag( const char * filename, Tag const & last, std::set const & skiptags ) { gdcmstrict::Reader reader; - assert( filename ); + gdcm_assert( filename ); reader.SetFileName( filename ); bool read = false; try diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfFragments.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfFragments.cxx index 943596bd6a5..28c2c792c2d 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfFragments.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfFragments.cxx @@ -27,7 +27,7 @@ void SequenceOfFragments::Clear() SequenceOfFragments::SizeType SequenceOfFragments::GetNumberOfFragments() const { // Do not count the last fragment - //assert( SequenceLengthField.IsUndefined() ); + //gdcm_assert( SequenceLengthField.IsUndefined() ); return Fragments.size(); } @@ -46,10 +46,10 @@ VL SequenceOfFragments::ComputeLength() const for(;it != Fragments.end(); ++it) { const VL fraglen = it->ComputeLength(); - assert( fraglen % 2 == 0 ); + gdcm_assert( fraglen % 2 == 0 ); length += fraglen; } - assert( SequenceLengthField.IsUndefined() ); + gdcm_assert( SequenceLengthField.IsUndefined() ); length += 8; // seq end delimiter (tag + vl) return length; } @@ -60,7 +60,7 @@ unsigned long SequenceOfFragments::ComputeByteLength() const FragmentVector::const_iterator it = Fragments.begin(); for(;it != Fragments.end(); ++it) { - assert( !it->GetVL().IsUndefined() ); + gdcm_assert( !it->GetVL().IsUndefined() ); r += it->GetVL(); } return r; @@ -81,7 +81,7 @@ bool SequenceOfFragments::GetFragBuffer(unsigned int fragNb, char *buffer, unsig const Fragment& SequenceOfFragments::GetFragment(SizeType num) const { - assert( num < Fragments.size() ); + gdcm_assert( num < Fragments.size() ); FragmentVector::const_iterator it = Fragments.begin(); const Fragment &frag = *(it+num); return frag; @@ -103,7 +103,7 @@ bool SequenceOfFragments::GetBuffer(char *buffer, unsigned long length) const if( total != length ) { //std::cerr << " DEBUG: " << total << " " << length << std::endl; - assert(0); + gdcm_assert(0); return false; } return true; @@ -117,7 +117,7 @@ bool SequenceOfFragments::WriteBuffer(std::ostream &os) const { const Fragment &frag = *it; const ByteValue *bv = frag.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); const VL len = frag.GetVL(); bv->WriteBuffer(os); total += len; @@ -125,7 +125,7 @@ bool SequenceOfFragments::WriteBuffer(std::ostream &os) const //if( total != length ) // { // //std::cerr << " DEBUG: " << total << " " << length << std::endl; - // assert(0); + // gdcm_assert(0); // return false; // } (void)total; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfFragments.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfFragments.h index 1bcd926c66c..5ee35f2ff76 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfFragments.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfFragments.h @@ -85,7 +85,7 @@ class GDCM_EXPORT SequenceOfFragments : public Value template std::istream& Read(std::istream &is, bool readvalues = true) { - assert( SequenceLengthField.IsUndefined() ); + gdcm_assert( SequenceLengthField.IsUndefined() ); ReadPreValue(is); return ReadValue(is, readvalues); } @@ -122,7 +122,7 @@ std::istream& ReadPreValue(std::istream &is) else { throw "Catch me if you can"; - //assert(0); + //gdcm_assert(0); } } #else @@ -145,7 +145,7 @@ std::istream& ReadValue(std::istream &is, bool /*readvalues*/) //gdcmDebugMacro( "Frag: " << frag ); Fragments.push_back( frag ); } - assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); + gdcm_assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); } catch(Exception &ex) { @@ -165,9 +165,9 @@ std::istream& ReadValue(std::istream &is, bool /*readvalues*/) // 2. GENESIS_SIGNA-JPEG-CorruptFrag.dcm else if ( frag.GetTag() == Tag(0xddff,0x00e0) ) { - assert( Fragments.size() == 1 ); + gdcm_assert( Fragments.size() == 1 ); const ByteValue *bv = Fragments[0].GetByteValue(); - assert( (unsigned char)bv->GetPointer()[ bv->GetLength() - 1 ] == 0xfe ); + gdcm_assert( (unsigned char)bv->GetPointer()[ bv->GetLength() - 1 ] == 0xfe ); // Yes this is an extra copy, this is a bug anyway, go fix YOUR code Fragments[0].SetByteValue( bv->GetPointer(), bv->GetLength() - 1 ); gdcmWarningMacro( "JPEG Fragment length was declared with an extra byte" @@ -184,20 +184,20 @@ std::istream& ReadValue(std::istream &is, bool /*readvalues*/) // backward. This appears to be working on a set of DICOM/WSI files from // LEICA gdcmWarningMacro( "Trying to fix the even-but-odd value length bug #1" ); - assert( Fragments.size() ); + gdcm_assert( Fragments.size() ); const size_t lastf = Fragments.size() - 1; const ByteValue *bv = Fragments[ lastf ].GetByteValue(); const char *a = bv->GetPointer(); gdcmAssertAlwaysMacro( (unsigned char)a[ bv->GetLength() - 1 ] == 0xfe ); Fragments[ lastf ].SetByteValue( bv->GetPointer(), bv->GetLength() - 1 ); is.seekg( -9, std::ios::cur ); - assert( is.good() ); + gdcm_assert( is.good() ); while( frag.ReadBacktrack(is) && frag.GetTag() != seqDelItem ) { gdcmDebugMacro( "Frag: " << frag ); Fragments.push_back( frag ); } - assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); + gdcm_assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); } // 4. LEICA/WSI (bis) else if ( frag.GetTag().GetGroup() == 0xe000 ) @@ -208,20 +208,20 @@ std::istream& ReadValue(std::istream &is, bool /*readvalues*/) // backward. This appears to be working on a set of DICOM/WSI files from // LEICA gdcmWarningMacro( "Trying to fix the even-but-odd value length bug #2" ); - assert( Fragments.size() ); + gdcm_assert( Fragments.size() ); const size_t lastf = Fragments.size() - 1; const ByteValue *bv = Fragments[ lastf ].GetByteValue(); const char *a = bv->GetPointer(); gdcmAssertAlwaysMacro( (unsigned char)a[ bv->GetLength() - 2 ] == 0xfe ); Fragments[ lastf ].SetByteValue( bv->GetPointer(), bv->GetLength() - 2 ); is.seekg( -10, std::ios::cur ); - assert( is.good() ); + gdcm_assert( is.good() ); while( frag.ReadBacktrack(is) && frag.GetTag() != seqDelItem ) { gdcmDebugMacro( "Frag: " << frag ); Fragments.push_back( frag ); } - assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); + gdcm_assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); } // 5. LEICA/WSI (ter) else if ( (frag.GetTag().GetGroup() & 0x00ff) == 0x00e0 @@ -233,20 +233,20 @@ std::istream& ReadValue(std::istream &is, bool /*readvalues*/) // backward. This appears to be working on a set of DICOM/WSI files from // LEICA gdcmWarningMacro( "Trying to fix the even-but-odd value length bug #3" ); - assert( Fragments.size() ); + gdcm_assert( Fragments.size() ); const size_t lastf = Fragments.size() - 1; const ByteValue *bv = Fragments[ lastf ].GetByteValue(); const char *a = bv->GetPointer(); gdcmAssertAlwaysMacro( bv->GetLength() >= 3 && (unsigned char)a[ bv->GetLength() - 3 ] == 0xfe ); Fragments[ lastf ].SetByteValue( bv->GetPointer(), bv->GetLength() - 3 ); is.seekg( -11, std::ios::cur ); - assert( is.good() ); + gdcm_assert( is.good() ); while( frag.ReadBacktrack(is) && frag.GetTag() != seqDelItem ) { gdcmDebugMacro( "Frag: " << frag ); Fragments.push_back( frag ); } - assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); + gdcm_assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); } else { @@ -267,7 +267,7 @@ std::ostream const &Write(std::ostream &os) const { if( !Table.Write(os) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return os; } for(ConstIterator it = Begin();it != End(); ++it) @@ -301,7 +301,7 @@ std::ostream const &Write(std::ostream &os) const { os << " " << *it << "\n"; } - assert( SequenceLengthField.IsUndefined() ); + gdcm_assert( SequenceLengthField.IsUndefined() ); { const Tag seqDelItem(0xfffe,0xe0dd); VL zero = 0; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfItems.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfItems.cxx index fa7996eb920..5f3181882fb 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfItems.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfItems.cxx @@ -21,7 +21,7 @@ void SequenceOfItems::AddItem(Item const &item) Items.push_back( item ); if( !SequenceLengthField.IsUndefined() ) { - assert(0); // TODO + gdcm_assert(0); // TODO } } @@ -36,7 +36,7 @@ Item & SequenceOfItems::AddNewUndefinedLengthItem() void SequenceOfItems::Clear() { Items.clear(); - assert( SequenceLengthField.IsUndefined() ); + gdcm_assert( SequenceLengthField.IsUndefined() ); } bool SequenceOfItems::RemoveItemByIndex( const SizeType position ) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfItems.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfItems.h index 56fa684cd98..7de89106055 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfItems.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfItems.h @@ -111,11 +111,11 @@ class GDCM_EXPORT SequenceOfItems : public Value while( item.Read(is) && item.GetTag() != seqDelItem ) { //gdcmDebugMacro( "Item: " << item ); - assert( item.GetTag() != seqDelItem ); + gdcm_assert( item.GetTag() != seqDelItem ); Items.push_back( item ); item.Clear(); } - //assert( item.GetTag() == seqDelItem && item.GetVL() == 0 ); + //gdcm_assert( item.GetTag() == seqDelItem && item.GetVL() == 0 ); } else { @@ -149,8 +149,8 @@ class GDCM_EXPORT SequenceOfItems : public Value if( item.GetTag() == seqDelItem ) { gdcmWarningMacro( "SeqDelItem found in defined length Sequence. Skipping" ); - assert( item.GetVL() == 0 ); - assert( item.GetNestedDataSet().Size() == 0 ); + gdcm_assert( item.GetVL() == 0 ); + gdcm_assert( item.GetNestedDataSet().Size() == 0 ); // we need to pay attention that the length of the Sequence of Items will be wrong // this way. Indeed by not adding this item we are changing the size of this sqi } @@ -169,7 +169,7 @@ class GDCM_EXPORT SequenceOfItems : public Value gdcmDebugMacro( "Found: Length of Item larger than expected" ); throw "Length of Item larger than expected"; } - assert( l <= SequenceLengthField ); + gdcm_assert( l <= SequenceLengthField ); //std::cerr << "sqi debug len: " << is.tellg() << " " << l << " " << SequenceLengthField << std::endl; #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION // MR_Philips_Intera_No_PrivateSequenceImplicitVR.dcm @@ -192,7 +192,7 @@ class GDCM_EXPORT SequenceOfItems : public Value } #endif } - assert( l == SequenceLengthField ); + gdcm_assert( l == SequenceLengthField ); } return is; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfItems.txx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfItems.txx index 3dc251e675d..a5b5c2994a6 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfItems.txx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmSequenceOfItems.txx @@ -32,7 +32,7 @@ VL SequenceOfItems::ComputeLength() const } // For defined length SQ, make sure computation is correct (compare // to original length) - //assert( SequenceLengthField.IsUndefined() + //gdcm_assert( SequenceLengthField.IsUndefined() // || length == SequenceLengthField ); return length; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmTag.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmTag.h index dc21df325d1..37159f12c75 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmTag.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmTag.h @@ -84,13 +84,13 @@ class GDCM_EXPORT Tag /// Returns the Group or Element of the given Tag, depending on id (0/1) const uint16_t &operator[](const unsigned int &_id) const { - assert(_id<2); + gdcm_assert(_id<2); return ElementTag.tags[_id]; } /// Returns the Group or Element of the given Tag, depending on id (0/1) uint16_t &operator[](const unsigned int &_id) { - assert(_id<2); + gdcm_assert(_id<2); return ElementTag.tags[_id]; } @@ -194,7 +194,7 @@ class GDCM_EXPORT Tag { // See PS 3.5 - 7.8.1 PRIVATE DATA ELEMENT TAGS // eg: 0x0123,0x0045 -> 0x0123,0x4567 - assert( t.IsPrivate() /*&& t.IsPrivateCreator()*/ ); + gdcm_assert( t.IsPrivate() /*&& t.IsPrivateCreator()*/ ); const uint16_t element = (uint16_t)(t.GetElement() << 8); const uint16_t base = (uint16_t)(GetElement() << 8); SetElement( (uint16_t)((base >> 8) + element) ); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmTransferSyntax.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmTransferSyntax.cxx index 57a3abceb47..e8e55ac1ed2 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmTransferSyntax.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmTransferSyntax.cxx @@ -81,9 +81,17 @@ static const char *TSStrings[] = { "1.2.840.10008.1.2.4.102", // MPEG-4 AVC/H.264 BD-compatible High Profile / Level 4.1 "1.2.840.10008.1.2.4.103", + // High-Throughput JPEG 2000 Image Compression (Lossless Only) + "1.2.840.10008.1.2.4.201", + // High-Throughput JPEG 2000 with RPCL Options Image Compression (Lossless Only) + "1.2.840.10008.1.2.4.202", + // High-Throughput JPEG 2000 Image Compression + "1.2.840.10008.1.2.4.203", + // Deflated Image Frame Compression + "1.2.840.10008.1.2.8.1", // Unknown - "Unknown Transfer Syntax", // Pretty sure we never use this case... - nullptr // Compilers have no obligation to finish by NULL, do it ourself + "Unknown Transfer Syntax", // Pretty sure we never use this case... until a new transfer syntax is added + nullptr // Compilers have no obligation to finish by NULL, do it ourselves }; TransferSyntax::TSType TransferSyntax::GetTSType(const char *cstr) @@ -112,14 +120,14 @@ TransferSyntax::TSType TransferSyntax::GetTSType(const char *cstr) const char* TransferSyntax::GetTSString(TSType ts) { - assert( ts <= TS_END ); + gdcm_assert( ts <= TS_END ); return TSStrings[(int)ts]; //return TransferSyntaxStrings[(int)ts]; } bool TransferSyntax::IsImplicit(TSType ts) const { - assert( ts != TS_END ); + gdcm_assert( ts != TS_END ); return ts == ImplicitVRLittleEndian || ts == ImplicitVRBigEndianACRNEMA || ts == ImplicitVRBigEndianPrivateGE @@ -162,7 +170,8 @@ bool TransferSyntax::IsLossy() const TSField == MPEG2MainProfile || TSField == MPEG2MainProfileHighLevel || TSField == MPEG4AVCH264HighProfileLevel4_1 || - TSField == MPEG4AVCH264BDcompatibleHighProfileLevel4_1 + TSField == MPEG4AVCH264BDcompatibleHighProfileLevel4_1 || + TSField == HTJ2K ) { return true; @@ -188,6 +197,7 @@ bool TransferSyntax::CanStoreLossy() const TSField == JPEGLSLossless || TSField == JPEG2000Lossless || TSField == JPEG2000Part2Lossless || + TSField == DeflatedImageFrameCompression || TSField == RLELossless ) { @@ -211,7 +221,8 @@ bool TransferSyntax::IsLossless() const TSField == MPEG2MainProfile || TSField == MPEG2MainProfileHighLevel || TSField == MPEG4AVCH264HighProfileLevel4_1 || - TSField == MPEG4AVCH264BDcompatibleHighProfileLevel4_1 + TSField == MPEG4AVCH264BDcompatibleHighProfileLevel4_1 || + TSField == HTJ2K ) { return false; @@ -222,7 +233,7 @@ bool TransferSyntax::IsLossless() const // By implementation those two functions form a partition bool TransferSyntax::IsExplicit(TSType ts) const { - assert( ts != TS_END ); + gdcm_assert( ts != TS_END ); return !IsImplicit(ts); } @@ -241,13 +252,13 @@ TransferSyntax::NegociatedType TransferSyntax::GetNegociatedType() const bool TransferSyntax::IsLittleEndian(TSType ts) const { - assert( ts != TS_END ); + gdcm_assert( ts != TS_END ); return !IsBigEndian(ts); } bool TransferSyntax::IsBigEndian(TSType ts) const { - assert( ts != TS_END ); + gdcm_assert( ts != TS_END ); return ts == ExplicitVRBigEndian // || ts == ImplicitVRBigEndianPrivateGE // Indeed this is LittleEndian || ts == ImplicitVRBigEndianACRNEMA; @@ -255,12 +266,12 @@ bool TransferSyntax::IsBigEndian(TSType ts) const SwapCode TransferSyntax::GetSwapCode() const { - assert( TSField != TS_END ); + gdcm_assert( TSField != TS_END ); if( IsBigEndian( TSField ) ) { return SwapCode::BigEndian; } - assert( IsLittleEndian( TSField ) ); + gdcm_assert( IsLittleEndian( TSField ) ); return SwapCode::LittleEndian; } @@ -300,6 +311,11 @@ bool TransferSyntax::IsEncapsulated() const case MPEG4AVCH264BDcompatibleHighProfileLevel4_1: //case ImplicitVRBigEndianACRNEMA: //case WeirdPapryus: + case HTJ2KLossless: + case HTJ2KRPCLLossless: + case HTJ2K: + case DeflatedImageFrameCompression: + ret = true; break; default: diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmTransferSyntax.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmTransferSyntax.h index 8be7a3e5dbc..6a5cece7bd1 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmTransferSyntax.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmTransferSyntax.h @@ -86,6 +86,10 @@ class GDCM_EXPORT TransferSyntax MPEG2MainProfileHighLevel, MPEG4AVCH264HighProfileLevel4_1, MPEG4AVCH264BDcompatibleHighProfileLevel4_1, + HTJ2KLossless, + HTJ2KRPCLLossless, + HTJ2K, + DeflatedImageFrameCompression, TS_END } TSType; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitDataElement.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitDataElement.cxx index 9e8519eb394..61bddf39f9f 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitDataElement.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitDataElement.cxx @@ -24,7 +24,7 @@ VL UNExplicitDataElement::GetLength() const { if( ValueLengthField.IsUndefined() ) { - assert( ValueField->GetLength().IsUndefined() ); + gdcm_assert( ValueField->GetLength().IsUndefined() ); Value *p = ValueField; // If this is a SQ we need to compute it's proper length SequenceOfItems *sq = dynamic_cast(p); @@ -37,18 +37,18 @@ VL UNExplicitDataElement::GetLength() const SequenceOfFragments *sf = dynamic_cast(p); if( sf ) { - assert( VRField & (VR::OB | VR::OW) ); + gdcm_assert( VRField & (VR::OB | VR::OW) ); return TagField.GetLength() + VRField.GetLength() + ValueLengthField.GetLength() + sf->ComputeLength(); } - assert(0); + gdcm_assert(0); return 0; } else { // Each time VR::GetLength() is 2 then Value Length is coded in 2 // 4 then Value Length is coded in 4 - assert( !ValueField || ValueField->GetLength() == ValueLengthField ); + gdcm_assert( !ValueField || ValueField->GetLength() == ValueLengthField ); return TagField.GetLength() + 2*VRField.GetLength() + ValueLengthField; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitDataElement.txx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitDataElement.txx index 22cc4638b4c..f14bbb36dc6 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitDataElement.txx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitDataElement.txx @@ -44,7 +44,7 @@ std::istream &UNExplicitDataElement::ReadPreValue(std::istream &is) { if( !is.eof() ) // FIXME This should not be needed { - assert(0 && "Should not happen" ); + gdcm_assert(0 && "Should not happen" ); } return is; } @@ -54,14 +54,14 @@ std::istream &UNExplicitDataElement::ReadPreValue(std::istream &is) pe.SetLastElement( *this ); throw pe; } - assert( TagField != Tag(0xfffe,0xe0dd) ); + gdcm_assert( TagField != Tag(0xfffe,0xe0dd) ); const Tag itemDelItem(0xfffe,0xe00d); if( TagField == itemDelItem ) { if( !ValueLengthField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } if( ValueLengthField != 0 ) @@ -80,7 +80,7 @@ std::istream &UNExplicitDataElement::ReadPreValue(std::istream &is) { if( !VRField.Read(is) ) { - assert(0 && "Should not happen" ); + gdcm_assert(0 && "Should not happen" ); return is; } } @@ -88,13 +88,13 @@ std::istream &UNExplicitDataElement::ReadPreValue(std::istream &is) { #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION // gdcm-MR-PHILIPS-16-Multi-Seq.dcm - // assert( TagField == Tag(0xfffe, 0xe000) ); + // gdcm_assert( TagField == Tag(0xfffe, 0xe000) ); // -> For some reason VR is written as {44,0} well I guess this is a VR... // Technically there is a second bug, dcmtk assume other things when reading this tag, // so I need to change this tag too, if I ever want dcmtk to read this file. oh well // 0019004_Baseline_IMG1.dcm // -> VR is garbage also... - // assert( TagField == Tag(8348,0339) || TagField == Tag(b5e8,0338)) + // gdcm_assert( TagField == Tag(8348,0339) || TagField == Tag(b5e8,0338)) //gdcmWarningMacro( "Assuming 16 bits VR for Tag=" << // TagField << " in order to read a buggy DICOM file." ); //VRField = VR::INVALID; @@ -117,7 +117,7 @@ std::istream &UNExplicitDataElement::ReadPreValue(std::istream &is) { if( !ValueLengthField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } } @@ -126,7 +126,7 @@ std::istream &UNExplicitDataElement::ReadPreValue(std::istream &is) // 16bits only if( !ValueLengthField.template Read16(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } } @@ -146,11 +146,11 @@ std::istream &UNExplicitDataElement::ReadValue(std::istream &is, bool readvalues //std::cerr << "exp cur tag=" << TagField << " VR=" << VRField << " VL=" << ValueLengthField << std::endl; // Read the Value - //assert( ValueField == 0 ); + //gdcm_assert( ValueField == 0 ); if( VRField == VR::SQ ) { // Check whether or not this is an undefined length sequence - assert( TagField != Tag(0x7fe0,0x0010) ); + gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new SequenceOfItems; } else if( ValueLengthField.IsUndefined() ) @@ -161,7 +161,7 @@ std::istream &UNExplicitDataElement::ReadValue(std::istream &is, bool readvalues // Enhanced_MR_Image_Storage_PixelSpacingNotIn_0028_0030.dcm (illegal) // vs // undefined_length_un_vr.dcm - assert( TagField != Tag(0x7fe0,0x0010) ); + gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new SequenceOfItems; ValueField->SetLength(ValueLengthField); // perform realloc try @@ -169,7 +169,7 @@ std::istream &UNExplicitDataElement::ReadValue(std::istream &is, bool readvalues //if( !ValueIO::Read(is,*ValueField) ) // non cp246 if( !ValueIO::Read(is,*ValueField,readvalues) ) // cp246 compliant { - assert(0); + gdcm_assert(0); } } catch( std::exception &) @@ -184,14 +184,14 @@ std::istream &UNExplicitDataElement::ReadValue(std::istream &is, bool readvalues else { // Ok this is Pixel Data fragmented... - assert( TagField == Tag(0x7fe0,0x0010) ); - assert( VRField & VR::OB_OW ); + gdcm_assert( TagField == Tag(0x7fe0,0x0010) ); + gdcm_assert( VRField & VR::OB_OW ); ValueField = new SequenceOfFragments; } } else { - //assert( TagField != Tag(0x7fe0,0x0010) ); + //gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new ByteValue; } // We have the length we should be able to read the value @@ -209,7 +209,7 @@ std::istream &UNExplicitDataElement::ReadValue(std::istream &is, bool readvalues //we really need to read item marker ) { - assert(0); // Could we possibly be so unlucky to have this mixture of bugs... + gdcm_assert(0); // Could we possibly be so unlucky to have this mixture of bugs... } if( !ValueIO::Read(is,*ValueField,readvalues) ) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitImplicitDataElement.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitImplicitDataElement.cxx index 43d5c2de5f4..8138247382e 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitImplicitDataElement.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitImplicitDataElement.cxx @@ -24,7 +24,7 @@ VL UNExplicitImplicitDataElement::GetLength() const { if( ValueLengthField.IsUndefined() ) { - assert( ValueField->GetLength().IsUndefined() ); + gdcm_assert( ValueField->GetLength().IsUndefined() ); Value *p = ValueField; // If this is a SQ we need to compute it's proper length SequenceOfItems *sq = dynamic_cast(p); @@ -37,18 +37,18 @@ VL UNExplicitImplicitDataElement::GetLength() const SequenceOfFragments *sf = dynamic_cast(p); if( sf ) { - assert( VRField & (VR::OB | VR::OW) ); + gdcm_assert( VRField & (VR::OB | VR::OW) ); return TagField.GetLength() + VRField.GetLength() + ValueLengthField.GetLength() + sf->ComputeLength(); } - assert(0); + gdcm_assert(0); return 0; } else { // Each time VR::GetLength() is 2 then Value Length is coded in 2 // 4 then Value Length is coded in 4 - assert( !ValueField || ValueField->GetLength() == ValueLengthField ); + gdcm_assert( !ValueField || ValueField->GetLength() == ValueLengthField ); return TagField.GetLength() + 2*VRField.GetLength() + ValueLengthField; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitImplicitDataElement.txx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitImplicitDataElement.txx index e1bc51e1495..69723799fa2 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitImplicitDataElement.txx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmUNExplicitImplicitDataElement.txx @@ -37,7 +37,7 @@ std::istream &UNExplicitImplicitDataElement::Read(std::istream &is) template std::istream &UNExplicitImplicitDataElement::ReadPreValue(std::istream &is) { - assert(0); + gdcm_assert(0); //DataElement &de = *this;//unused de, fires a warning on macos //de.template ReadPreValue( is ); return is; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVL.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVL.h index 764707b9b99..8b93dc08bb9 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVL.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVL.h @@ -91,7 +91,7 @@ class GDCM_EXPORT VL is.read((char*)(©), sizeof(uint16_t)); TSwap::SwapArray(©,1); ValueLength = copy; - assert( ValueLength <= 65535 /*UINT16_MAX*/ ); // ?? doh ! + gdcm_assert( ValueLength <= 65535 /*UINT16_MAX*/ ); // ?? doh ! return is; } @@ -110,7 +110,7 @@ class GDCM_EXPORT VL template const std::ostream &Write16(std::ostream &os) const { - assert( ValueLength <= 65535 /*UINT16_MAX*/ ); + gdcm_assert( ValueLength <= 65535 /*UINT16_MAX*/ ); uint16_t copy = (uint16_t)ValueLength; if( IsOdd() ) { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVM.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVM.cxx index 705bdc71e85..ba1f98d8cd0 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVM.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVM.cxx @@ -139,15 +139,15 @@ unsigned int VM::GetLength() const return 0; default: len = 0; - assert(0); + gdcm_assert(0); } - assert( len ); + gdcm_assert( len ); return len; } unsigned int VM::GetIndex(VMType vm) { - assert( vm <= VM_END ); + gdcm_assert( vm <= VM_END ); unsigned int l; switch(vm) { @@ -225,8 +225,8 @@ unsigned int VM::GetIndex(VMType vm) const char *VM::GetVMString(VMType vm) { unsigned int idx = GetIndex(vm); - assert( idx < sizeof(VMStrings) / sizeof(VMStrings[0]) ); - //assert( idx ); + gdcm_assert( idx < sizeof(VMStrings) / sizeof(VMStrings[0]) ); + //gdcm_assert( idx ); return VMStrings[idx]; } @@ -250,7 +250,7 @@ VM::VMType VM::GetVMType(const char *vm) bool VM::IsValid(int vm1, VMType vm2) { bool r = false; - assert( vm1 >= 0 ); // Still need to check Part 3 + gdcm_assert( vm1 >= 0 ); // Still need to check Part 3 // If you update the VMType, you need to update this code. Hopefully a compiler is // able to tell when a case is missing switch(vm2) @@ -313,7 +313,7 @@ bool VM::IsValid(int vm1, VMType vm2) r = (vm1 >= 3); break; default: - assert(0); // should not happen + gdcm_assert(0); // should not happen } return r; } @@ -382,7 +382,7 @@ size_t VM::GetNumberOfElementsFromArray(const char *array, size_t length) bool VM::Compatible(VM const &vm) const { // make sure that vm is a numeric value - //assert( vm.VMField <= VM256 ); + //gdcm_assert( vm.VMField <= VM256 ); if ( VMField == VM::VM0 ) return false; // nothing was found in the dict if ( vm == VM::VM0 ) return true; // the user was not able to compute the vm from the empty bytevalue // let's start with the easy case: @@ -431,7 +431,7 @@ bool VM::Compatible(VM const &vm) const } if( r ) { - assert( VMField & vm.VMField ); + gdcm_assert( VMField & vm.VMField ); } return r; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVM.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVM.h index 7001297465d..4c0b3e71648 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVM.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVM.h @@ -143,7 +143,7 @@ class GDCM_EXPORT VM //----------------------------------------------------------------------------- inline std::ostream& operator<<(std::ostream& _os, const VM &_val) { - assert( VM::GetVMString(_val) ); + gdcm_assert( VM::GetVMString(_val) ); _os << VM::GetVMString(_val); return _os; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR.cxx index a08b8402f04..5ddd2ceaedd 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR.cxx @@ -260,7 +260,7 @@ unsigned int VR::GetSizeof() const default: size = 0; } - assert( size ); + gdcm_assert( size ); return size; } @@ -268,7 +268,7 @@ unsigned int VR::GetIndex(VRType vr) { if( vr == VR::VL32 ) return 0; unsigned int l = 0; - assert( vr <= VR_END ); + gdcm_assert( vr <= VR_END ); switch(vr) { case INVALID: @@ -310,13 +310,13 @@ const char *VR::GetVRStringFromFile(VRType vr) { #if 1 static const int N = sizeof(VRValue) / sizeof(VRType); - assert( N == 35 ); + gdcm_assert( N == 35 ); static VRType *start = VRValue; static VRType *end = VRValue+N; const VRType *p = std::lower_bound(start, end, vr); - assert( *p == vr ); - assert( (p - start) == (long long)GetIndex(vr) ); + gdcm_assert( *p == vr ); + gdcm_assert( (p - start) == (long long)GetIndex(vr) ); return VRStrings[p-start]; #else const unsigned int idx = GetIndex(vr); @@ -345,7 +345,7 @@ VR::VRType VR::GetVRTypeFromFile(const char *vr) */ #if 0 static const int N = sizeof(VRValue) / sizeof(VRType); - assert( N == 35 ); + gdcm_assert( N == 35 ); static const char **start = VRStrings+1; static const char **end = VRStrings+N; //std::cerr << "VR=" << vr << std::endl; @@ -364,9 +364,9 @@ VR::VRType VR::GetVRTypeFromFile(const char *vr) } return VR::INVALID; } - assert( (*p)[0] == vr[0] && (*p)[1] == vr[1] ); + gdcm_assert( (*p)[0] == vr[0] && (*p)[1] == vr[1] ); VRType r = VRValue[p-start+1]; - assert( r == (VR::VRType)(1 << (p-start)) ); + gdcm_assert( r == (VR::VRType)(1 << (p-start)) ); #else // old version not optimized VRType r = VR::VR_END; for (int i = 1; VRStrings[i] != nullptr; i++) @@ -394,7 +394,7 @@ VR::VRType VR::GetVRTypeFromFile(const char *vr) } #endif // postcondition - assert( r != VR::INVALID + gdcm_assert( r != VR::INVALID && r != VR::OB_OW && r != VR::US_SS && r != VR::US_SS_OW @@ -429,10 +429,10 @@ VR::VRType VR::GetVRType(const char *vr) r = US_OW; break; case 39: - r = VR_END; assert(0); + r = VR_END; gdcm_assert(0); break; default: - assert( vr[2] == 0 ); + gdcm_assert( vr[2] == 0 ); r = (VR::VRType)(1LL << (i-1)); } break; // found one value, we can exit the for loop @@ -449,7 +449,7 @@ bool VR::IsValid(const char *vr) // Use lazy evaluation instead of strncmp if (ref[0] == vr[0] && ref[1] == vr[1] ) { - assert( i < 35 ); // FIXME + gdcm_assert( i < 35 ); // FIXME return true; } } @@ -458,19 +458,19 @@ bool VR::IsValid(const char *vr) bool VR::IsValid(const char *vr1, VRType vr2) { - assert( strlen(vr1) == 2 ); + gdcm_assert( strlen(vr1) == 2 ); VR::VRType vr = GetVRType(vr1); return ((vr & vr2) != 0 ? true : false); } bool VR::IsSwap(const char *vr) { - assert( vr[2] == '\0' ); + gdcm_assert( vr[2] == '\0' ); char vr_swap[3]; vr_swap[0] = vr[1]; vr_swap[1] = vr[0]; vr_swap[2] = '\0'; - assert( GetVRType(vr_swap) != SS ); + gdcm_assert( GetVRType(vr_swap) != SS ); return GetVRType(vr_swap) != VR_END; } @@ -516,20 +516,20 @@ VRTemplateCase(UV,rep) bool VR::IsASCII(VRType vr) { - //assert( vr != VR::INVALID ); + //gdcm_assert( vr != VR::INVALID ); switch(vr) { VRTemplate(VRASCII) default: // 1.3.12.2.1107.5.1.4.54035.30000005100516290423400005768-no-phi.dcm has a VR=RT - //assert(0); + //gdcm_assert(0); return false; } } bool VR::IsASCII2(VRType vr) { - assert( vr != VR::INVALID ); + gdcm_assert( vr != VR::INVALID ); return vr == AE || vr == AS || @@ -549,7 +549,7 @@ bool VR::IsASCII2(VRType vr) bool VR::IsBinary(VRType vr) { - //assert( vr != VR::INVALID ); + //gdcm_assert( vr != VR::INVALID ); switch(vr) { VRTemplate(VRBINARY) @@ -562,14 +562,14 @@ bool VR::IsBinary(VRType vr) return true; default: // 1.3.12.2.1107.5.1.4.54035.30000005100516290423400005768-no-phi.dcm has a VR=RT - //assert(0); + //gdcm_assert(0); return false; } } bool VR::IsBinary2(VRType vr) { - //assert( vr != OF ); + //gdcm_assert( vr != OF ); return vr == OB || vr == OW || diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR.h index 95bda498d09..dcc924105fd 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR.h @@ -158,7 +158,7 @@ class GDCM_EXPORT VR char vr[2]; is.read(vr, 2); VRField = GetVRTypeFromFile(vr); - assert( VRField != VR::VR_END ); + gdcm_assert( VRField != VR::VR_END ); if( VRField == VR::INVALID ) { // \0\2 Data/TheralysGDCM120Bug.dcm @@ -199,8 +199,8 @@ class GDCM_EXPORT VR //vrfield = VR::UN; } const char *vr = GetVRString(vrfield); - //assert( strlen( vr ) == 2 ); - assert( vr[0] && vr[1] && vr[2] == 0 ); + //gdcm_assert( strlen( vr ) == 2 ); + gdcm_assert( vr[0] && vr[1] && vr[2] == 0 ); os.write(vr, 2); // See PS 3.5, Data Element Structure With Explicit VR if( vrfield & VL32 ) @@ -369,7 +369,7 @@ inline unsigned int VR::GetSize() const case VR::VRALL: case VR::VR_END: default: - assert( 0 && "should not" ); + gdcm_assert( 0 && "should not" ); } return 0; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR16ExplicitDataElement.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR16ExplicitDataElement.cxx index f25f43e34c3..904552f9c5c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR16ExplicitDataElement.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR16ExplicitDataElement.cxx @@ -24,7 +24,7 @@ VL VR16ExplicitDataElement::GetLength() const { if( ValueLengthField.IsUndefined() ) { - assert( ValueField->GetLength().IsUndefined() ); + gdcm_assert( ValueField->GetLength().IsUndefined() ); Value *p = ValueField; // If this is a SQ we need to compute it's proper length SequenceOfItems *sq = dynamic_cast(p); @@ -37,18 +37,18 @@ VL VR16ExplicitDataElement::GetLength() const SequenceOfFragments *sf = dynamic_cast(p); if( sf ) { - assert( VRField & (VR::OB | VR::OW) ); + gdcm_assert( VRField & (VR::OB | VR::OW) ); return TagField.GetLength() + VRField.GetLength() + ValueLengthField.GetLength() + sf->ComputeLength(); } - assert(0); + gdcm_assert(0); return 0; } else { // Each time VR::GetLength() is 2 then Value Length is coded in 2 // 4 then Value Length is coded in 4 - assert( !ValueField || ValueField->GetLength() == ValueLengthField ); + gdcm_assert( !ValueField || ValueField->GetLength() == ValueLengthField ); return TagField.GetLength() + 2*VRField.GetLength() + ValueLengthField; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR16ExplicitDataElement.txx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR16ExplicitDataElement.txx index 39b4706545c..92a0b57245b 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR16ExplicitDataElement.txx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmVR16ExplicitDataElement.txx @@ -43,20 +43,20 @@ std::istream &VR16ExplicitDataElement::ReadPreValue(std::istream &is) { if( !is.eof() ) // FIXME This should not be needed { - assert(0 && "Should not happen" ); + gdcm_assert(0 && "Should not happen" ); } return is; } - assert( TagField != Tag(0xfffe,0xe0dd) ); - //assert( TagField != Tag(0xfeff,0xdde0) ); + gdcm_assert( TagField != Tag(0xfffe,0xe0dd) ); + //gdcm_assert( TagField != Tag(0xfeff,0xdde0) ); const Tag itemDelItem(0xfffe,0xe00d); const Tag itemStartItem(0xfffe,0x0000); - assert( TagField != itemStartItem ); + gdcm_assert( TagField != itemStartItem ); if( TagField == itemDelItem ) { if( !ValueLengthField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } if( ValueLengthField ) @@ -72,7 +72,7 @@ std::istream &VR16ExplicitDataElement::ReadPreValue(std::istream &is) #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION if( TagField == Tag(0x00ff, 0x4aa5) ) { - assert(0 && "Should not happen" ); + gdcm_assert(0 && "Should not happen" ); // char c; // is.read(&c, 1); // std::cerr << "Debug: " << c << std::endl; @@ -87,7 +87,7 @@ std::istream &VR16ExplicitDataElement::ReadPreValue(std::istream &is) { if( !VRField.Read(is) ) { - assert(0 && "Should not happen" ); + gdcm_assert(0 && "Should not happen" ); return is; } } @@ -107,14 +107,14 @@ std::istream &VR16ExplicitDataElement::ReadPreValue(std::istream &is) // so I need to change this tag too, if I ever want dcmtk to read this file. oh well // 0019004_Baseline_IMG1.dcm // -> VR is garbage also... - // assert( TagField == Tag(8348,0339) || TagField == Tag(b5e8,0338)) + // gdcm_assert( TagField == Tag(8348,0339) || TagField == Tag(b5e8,0338)) if( TagField == Tag(0x7fe0,0x0010) ) { OX_hack = true; VRField = VR::UN; // make it a fake 32bits for now... char dummy[2]; is.read(dummy,2); - assert( dummy[0] == 0 && dummy[1] == 0 ); + gdcm_assert( dummy[0] == 0 && dummy[1] == 0 ); gdcmWarningMacro( "Assuming 32 bits VR for Tag=" << TagField << " in order to read a buggy DICOM file." ); } @@ -129,7 +129,7 @@ std::istream &VR16ExplicitDataElement::ReadPreValue(std::istream &is) { if( !ValueLengthField.Read(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } if( OX_hack ) @@ -139,11 +139,11 @@ std::istream &VR16ExplicitDataElement::ReadPreValue(std::istream &is) } else { - assert( OX_hack == false ); + gdcm_assert( OX_hack == false ); // 16bits only if( !ValueLengthField.template Read16(is) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); return is; } #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION @@ -185,11 +185,11 @@ std::istream &VR16ExplicitDataElement::ReadValue(std::istream &is, bool readvalu } // Read the Value - //assert( ValueField == 0 ); + //gdcm_assert( ValueField == 0 ); if( VRField == VR::SQ ) { // Check whether or not this is an undefined length sequence - assert( TagField != Tag(0x7fe0,0x0010) ); + gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new SequenceOfItems; } else if( ValueLengthField.IsUndefined() ) @@ -200,7 +200,7 @@ std::istream &VR16ExplicitDataElement::ReadValue(std::istream &is, bool readvalu // Enhanced_MR_Image_Storage_PixelSpacingNotIn_0028_0030.dcm (illegal) // vs // undefined_length_un_vr.dcm - assert( TagField != Tag(0x7fe0,0x0010) ); + gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new SequenceOfItems; ValueField->SetLength(ValueLengthField); // perform realloc try @@ -208,7 +208,7 @@ std::istream &VR16ExplicitDataElement::ReadValue(std::istream &is, bool readvalu //if( !ValueIO::Read(is,*ValueField) ) // non cp246 if( !ValueIO::Read(is,*ValueField,readvalues) ) // cp246 compliant { - assert(0); + gdcm_assert(0); } } catch( std::exception &) @@ -232,14 +232,14 @@ std::istream &VR16ExplicitDataElement::ReadValue(std::istream &is, bool readvalu throw pe; } // Ok this is Pixel Data fragmented... - assert( TagField == Tag(0x7fe0,0x0010) ); - assert( VRField & VR::OB_OW ); + gdcm_assert( TagField == Tag(0x7fe0,0x0010) ); + gdcm_assert( VRField & VR::OB_OW ); ValueField = new SequenceOfFragments; } } else { - //assert( TagField != Tag(0x7fe0,0x0010) ); + //gdcm_assert( TagField != Tag(0x7fe0,0x0010) ); ValueField = new ByteValue; } // We have the length we should be able to read the value @@ -258,17 +258,17 @@ std::istream &VR16ExplicitDataElement::ReadValue(std::istream &is, bool readvalu ) { gdcmWarningMacro( "ByteSwaping Private SQ: " << TagField ); - assert( VRField == VR::SQ ); - assert( TagField.IsPrivate() ); + gdcm_assert( VRField == VR::SQ ); + gdcm_assert( TagField.IsPrivate() ); try { if( !ValueIO::Read(is,*ValueField,readvalues) ) { - assert(0 && "Should not happen"); + gdcm_assert(0 && "Should not happen"); } Value* v = &*ValueField; SequenceOfItems *sq = dynamic_cast(v); - assert( sq ); + gdcm_assert( sq ); SequenceOfItems::Iterator it = sq->Begin(); for( ; it != sq->End(); ++it) { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmValueIO.txx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmValueIO.txx index d5d2685f93d..b8336615970 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmValueIO.txx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmValueIO.txx @@ -42,7 +42,7 @@ namespace gdcm_ns } else { - assert( 0 && "error" ); + gdcm_assert( 0 && "error" ); } return is; } @@ -57,7 +57,7 @@ namespace gdcm_ns else if( const SequenceOfItems *si = dynamic_cast(v) ) { //VL dummy = si->ComputeLength(); - //assert( /*dummy.IsUndefined() ||*/ dummy == si->GetLength() ); + //gdcm_assert( /*dummy.IsUndefined() ||*/ dummy == si->GetLength() ); si->template Write(os); } else if( const SequenceOfFragments *sf = dynamic_cast(v) ) @@ -66,7 +66,7 @@ namespace gdcm_ns } else { - assert( 0 && "error" ); + gdcm_assert( 0 && "error" ); } return os; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmWriter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmWriter.cxx index 515f23ed9f6..dd4fd935ad4 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmWriter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition/gdcmWriter.cxx @@ -99,7 +99,7 @@ bool Writer::Write() //gzostream gzos(os.rdbuf()); try { zlib_stream::zip_ostream gzos( os ); - assert( ts.GetNegociatedType() == TransferSyntax::Explicit ); + gdcm_assert( ts.GetNegociatedType() == TransferSyntax::Explicit ); DS.Write(gzos); //gzos.flush(); } catch (...){ @@ -122,7 +122,7 @@ bool Writer::Write() } else { - assert( ts.GetNegociatedType() == TransferSyntax::Explicit ); + gdcm_assert( ts.GetNegociatedType() == TransferSyntax::Explicit ); DS.Write(os); } } @@ -134,7 +134,7 @@ bool Writer::Write() } else { - assert( ts.GetNegociatedType() == TransferSyntax::Explicit ); + gdcm_assert( ts.GetNegociatedType() == TransferSyntax::Explicit ); DS.Write(os); } } @@ -181,10 +181,7 @@ void Writer::SetFileName(const char *utf8path) #else Ofstream->open(utf8path, std::ios::out | std::ios::binary); #endif - assert(Ofstream->is_open()); - assert(!Ofstream->fail()); - } - //std::cerr << Stream.is_open() << std::endl; + } Stream = Ofstream; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmDefs.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmDefs.cxx index 93eb04d277a..428ce7351b3 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmDefs.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmDefs.cxx @@ -49,7 +49,7 @@ void Defs::LoadDefaults() void Defs::LoadFromFile(const char *filename) { - assert( filename ); + gdcm_assert( filename ); TableReader tr(*this); tr.SetFilename(filename); tr.Read(); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmIODEntry.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmIODEntry.cxx index fb53238ba5b..a5849dfed36 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmIODEntry.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmIODEntry.cxx @@ -20,7 +20,7 @@ namespace gdcm Usage::UsageType IODEntry::GetUsageType() const { - assert( !usage.empty() ); + gdcm_assert( !usage.empty() ); if( usage == "M" ) { return Usage::Mandatory; @@ -42,7 +42,7 @@ Usage::UsageType IODEntry::GetUsageType() const return Usage::Conditional; } //else - assert(0); // Keep me so that I can debug Part3.xml + gdcm_assert(0); // Keep me so that I can debug Part3.xml return Usage::Invalid; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmIODs.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmIODs.h index 8b559c23404..90b5e0ea43f 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmIODs.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmIODs.h @@ -46,8 +46,8 @@ class GDCM_EXPORT IODs { //return IODsInternal[name]; IODMapType::const_iterator it = IODsInternal.find( name ); - assert( it != IODsInternal.end() ); - assert( it->first == name ); + gdcm_assert( it != IODsInternal.end() ); + gdcm_assert( it->first == name ); return it->second; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmMacro.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmMacro.cxx index 0e4d14fbd95..11318e32242 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmMacro.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmMacro.cxx @@ -37,7 +37,7 @@ const MacroEntry& Macro::GetMacroEntry(const Tag &tag) const MapModuleEntry::const_iterator it = ModuleInternal.find(tag); if( it != ModuleInternal.end() ) { - assert( it->first == tag ); + gdcm_assert( it->first == tag ); return it->second; } // Not found anywhere :( diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmMacros.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmMacros.h index c24722128ef..21b3f66c050 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmMacros.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmMacros.h @@ -39,17 +39,17 @@ class GDCM_EXPORT Macros // A Module is inserted based on it's ref void AddMacro(const char *ref, const Macro & module ) { - assert( ref && *ref ); - assert( ModulesInternal.find( ref ) == ModulesInternal.end() ); + gdcm_assert( ref && *ref ); + gdcm_assert( ModulesInternal.find( ref ) == ModulesInternal.end() ); ModulesInternal.insert( ModuleMapType::value_type(ref, module)); } const Macro &GetMacro(const char *name) const { - assert( name && *name ); + gdcm_assert( name && *name ); ModuleMapType::const_iterator it = ModulesInternal.find( name ); - assert( it != ModulesInternal.end() ); - assert( it->first == name ); + gdcm_assert( it != ModulesInternal.end() ); + gdcm_assert( it->first == name ); return it->second; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmModule.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmModule.cxx index dba09266cac..f3120f172e9 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmModule.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmModule.cxx @@ -59,7 +59,7 @@ const ModuleEntry& Module::GetModuleEntryInMacros(Macros const ¯os, const Ta MapModuleEntry::const_iterator it = ModuleInternal.find(tag); if( it != ModuleInternal.end() ) { - assert( it->first == tag ); + gdcm_assert( it->first == tag ); return it->second; } // Need to search within Nested-Included Macro: diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmModules.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmModules.h index 2b8d4aed690..304a2c4c532 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmModules.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmModules.h @@ -39,17 +39,17 @@ class GDCM_EXPORT Modules // A Module is inserted based on it's ref void AddModule(const char *ref, const Module & module ) { - assert( ref && *ref ); - assert( ModulesInternal.find( ref ) == ModulesInternal.end() ); + gdcm_assert( ref && *ref ); + gdcm_assert( ModulesInternal.find( ref ) == ModulesInternal.end() ); ModulesInternal.insert( ModuleMapType::value_type(ref, module)); } const Module &GetModule(const char *name) const { - assert( name && *name ); + gdcm_assert( name && *name ); ModuleMapType::const_iterator it = ModulesInternal.find( name ); - assert( it != ModulesInternal.end() ); - assert( it->first == name ); + gdcm_assert( it != ModulesInternal.end() ); + gdcm_assert( it->first == name ); return it->second; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmTable.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmTable.h index 377bd0c1965..5f186cb5ab0 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmTable.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmTable.h @@ -43,7 +43,9 @@ class Table #endif TableInternal.insert( MapTableEntry::value_type(tag, te)); - assert( s < TableInternal.size() ); +#ifndef NDEBUG + gdcm_assert( s < TableInternal.size() ); +#endif } const TableEntry &GetTableEntry(const Tag &tag) const @@ -52,7 +54,7 @@ class Table TableInternal.find(tag); if (it == TableInternal.end()) { - assert( 0 && "Impossible" ); + gdcm_assert( 0 && "Impossible" ); return GetTableEntry(Tag(0,0)); } return it->second; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmTableReader.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmTableReader.cxx index 869ba183493..cdc13cadb96 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmTableReader.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmTableReader.cxx @@ -70,29 +70,29 @@ static void XMLCALL characterDataHandler(void* userData, const char* data, void TableReader::HandleMacroEntryDescription(const char **atts) { (void)atts; - assert( ParsingMacroEntryDescription == false ); + gdcm_assert( ParsingMacroEntryDescription == false ); ParsingMacroEntryDescription = true; - assert( *atts == nullptr ); - assert( Description.empty() ); + gdcm_assert( *atts == nullptr ); + gdcm_assert( Description.empty() ); } void TableReader::HandleModuleInclude(const char **atts) { const char *ref = *atts; - assert( strcmp(ref, "ref") == 0 ); + gdcm_assert( strcmp(ref, "ref") == 0 ); (void)ref; //removing warning const char *include = *(atts+1); CurrentModule.AddMacro( include ); - //assert( *(atts+2) == 0 ); // description ? + //gdcm_assert( *(atts+2) == 0 ); // description ? } void TableReader::HandleModuleEntryDescription(const char **atts) { (void)atts; - assert( ParsingModuleEntryDescription == false ); + gdcm_assert( ParsingModuleEntryDescription == false ); ParsingModuleEntryDescription = true; - assert( *atts == nullptr ); - assert( Description.empty() ); + gdcm_assert( *atts == nullptr ); + gdcm_assert( Description.empty() ); } void TableReader::HandleMacroEntry(const char **atts) @@ -111,8 +111,8 @@ void TableReader::HandleMacroEntry(const char **atts) unsigned int v; const char *raw = *(current+1); int r = sscanf(raw, "%04x", &v); - assert( r == 1 ); - assert( v <= 0xFFFF ); + gdcm_assert( r == 1 ); + gdcm_assert( v <= 0xFFFF ); (void)r; //removing warning tag.SetGroup( (uint16_t)v ); } @@ -121,8 +121,8 @@ void TableReader::HandleMacroEntry(const char **atts) unsigned int v; const char *raw = *(current+1); int r = sscanf(raw, "%04x", &v); - assert( r == 1 ); - assert( v <= 0xFFFF ); + gdcm_assert( r == 1 ); + gdcm_assert( v <= 0xFFFF ); (void)r; //removing warning tag.SetElement( (uint16_t)v ); } @@ -138,7 +138,7 @@ void TableReader::HandleMacroEntry(const char **atts) } else { - assert(0); + gdcm_assert(0); } ++current; ++current; @@ -161,8 +161,8 @@ void TableReader::HandleModuleEntry(const char **atts) unsigned int v; const char *raw = *(current+1); int r = sscanf(raw, "%04x", &v); - assert( r == 1 ); - assert( v <= 0xFFFF ); + gdcm_assert( r == 1 ); + gdcm_assert( v <= 0xFFFF ); (void)r; //removing warning tag.SetGroup( (uint16_t)v ); } @@ -171,8 +171,8 @@ void TableReader::HandleModuleEntry(const char **atts) unsigned int v; const char *raw = *(current+1); int r = sscanf(raw, "%04x", &v); - assert( r == 1 ); - assert( v <= 0xFFFF ); + gdcm_assert( r == 1 ); + gdcm_assert( v <= 0xFFFF ); (void)r; //removing warning tag.SetElement( (uint16_t)v ); } @@ -188,7 +188,7 @@ void TableReader::HandleModuleEntry(const char **atts) } else { - assert(0); + gdcm_assert(0); } ++current; ++current; @@ -230,7 +230,7 @@ void TableReader::HandleIODEntry(const char **atts) } else { - assert(0); + gdcm_assert(0); } ++current; ++current; @@ -270,7 +270,7 @@ void TableReader::HandleModule(const char **atts) } else { - assert(0); + gdcm_assert(0); } ++current; ++current; @@ -334,7 +334,7 @@ void TableReader::StartElement(const char *name, const char **atts) } else /*if( ParsingIODoEntry )*/ { - assert(0); + gdcm_assert(0); } } else if( strcmp(name, "section" ) == 0 ) @@ -400,7 +400,7 @@ void TableReader::StartElement(const char *name, const char **atts) } else { - assert(0); + gdcm_assert(0); } } @@ -467,13 +467,13 @@ void TableReader::EndElement(const char *name) else if( ParsingMacroEntry ) { ParsingMacroEntryDescription = false; - //assert( !Description.empty() ); + //gdcm_assert( !Description.empty() ); CurrentMacroEntry.SetDescription( Description.c_str() ); Description = ""; } else { - assert(0); + gdcm_assert(0); } } else if( strcmp(name, "mapping" ) == 0 ) @@ -543,12 +543,12 @@ void TableReader::EndElement(const char *name) } else { - assert(0); + gdcm_assert(0); } } else { - assert(0); + gdcm_assert(0); } } @@ -557,18 +557,18 @@ void TableReader::CharacterDataHandler(const char *data, int length) if( ParsingModuleEntryDescription ) { std::string name( data, length); - assert( (unsigned int)length == strlen( name.c_str() ) ); + gdcm_assert( (unsigned int)length == strlen( name.c_str() ) ); Description.append( name ); } else if( ParsingMacroEntryDescription ) { std::string name( data, length); - assert( (unsigned int)length == strlen( name.c_str() ) ); + gdcm_assert( (unsigned int)length == strlen( name.c_str() ) ); Description.append( name ); } else { - //assert(0); + //gdcm_assert(0); } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmXMLDictReader.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmXMLDictReader.cxx index aab3c113f10..c71a0612257 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmXMLDictReader.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmXMLDictReader.cxx @@ -26,10 +26,10 @@ XMLDictReader::XMLDictReader():ParsingDescription(false),Description() void XMLDictReader::HandleEntry(const char **atts) { - assert( !ParsingDescription ); + gdcm_assert( !ParsingDescription ); VR vr; VM vm; - assert( vm == VM::VM0 ); + gdcm_assert( vm == VM::VM0 ); std::string name; bool ret; @@ -51,25 +51,25 @@ void XMLDictReader::HandleEntry(const char **atts) while(*current /*&& current+1*/) { - assert( *(current + 1) ); + gdcm_assert( *(current + 1) ); if( group == *current ) { unsigned int v; const char *raw = *(current+1); int r = sscanf(raw, "%04x", &v); - assert( r == 1 ); - assert( v <= 0xFFFF ); + gdcm_assert( r == 1 ); + gdcm_assert( v <= 0xFFFF ); char sv[4+1]; r = snprintf(sv, sizeof(sv), "%04x", v); - assert( r == 4 ); + gdcm_assert( r == 4 ); if( strncmp(raw, sv, 4) == 0 ) // GroupXX { tag.SetGroup( v ); } else { - assert( (raw[0] == '5' && raw[1] == '0') || (raw[0] == '6' && raw[1] == '0') ); + gdcm_assert( (raw[0] == '5' && raw[1] == '0') || (raw[0] == '6' && raw[1] == '0') ); if( raw[0] == '5' ) tag.SetGroup( 0x5000 ); if( raw[0] == '6' ) tag.SetGroup( 0x6000 ); CurrentDE.SetGroupXX( true ); @@ -80,19 +80,19 @@ void XMLDictReader::HandleEntry(const char **atts) unsigned int v; const char *raw = *(current+1); int r = sscanf(raw, "%04x", &v); - assert( r == 1 ); - assert( v <= 0xFFFF ); + gdcm_assert( r == 1 ); + gdcm_assert( v <= 0xFFFF ); char sv[4+1]; r = snprintf(sv, sizeof(sv), "%04x", v); - assert( r == 4 ); + gdcm_assert( r == 4 ); if( strncmp(raw, sv, 4) == 0 ) { tag.SetElement( v ); } else { - assert( raw[0] == '3' && raw[1] == '1' ); + gdcm_assert( raw[0] == '3' && raw[1] == '1' ); tag.SetElement( 0x3100 ); CurrentDE.SetElementXX( true ); } @@ -100,14 +100,14 @@ void XMLDictReader::HandleEntry(const char **atts) else if( strvr == *current ) { vr = VR::GetVRTypeFromFile( *(current + 1) ); - //assert( vr != VR::INVALID ); + //gdcm_assert( vr != VR::INVALID ); } else if( strvm == *current ) { vm = VM::GetVMType( *(current + 1) ); - //assert( *(current+1) != '\0' ); - //assert( vm != VM::VM0 ); - //assert( vm != VM::VM_END ); + //gdcm_assert( *(current+1) != '\0' ); + //gdcm_assert( vm != VM::VM0 ); + //gdcm_assert( vm != VM::VM_END ); } else if( retired == *current ) { @@ -121,7 +121,7 @@ void XMLDictReader::HandleEntry(const char **atts) } else { - assert(0); + gdcm_assert(0); } } else if( version == *current ) @@ -134,7 +134,7 @@ void XMLDictReader::HandleEntry(const char **atts) } else { - assert(0); + gdcm_assert(0); } // goes on to the next attribute (need to skip value) ++current; @@ -146,9 +146,9 @@ void XMLDictReader::HandleEntry(const char **atts) void XMLDictReader::HandleDescription(const char **atts) { - assert( ParsingDescription ); - assert( *atts == NULL ); - assert( Description == "" ); + gdcm_assert( ParsingDescription ); + gdcm_assert( *atts == NULL ); + gdcm_assert( Description == "" ); #if 0 DictEntry &de = CurrentDE; @@ -156,7 +156,7 @@ void XMLDictReader::HandleDescription(const char **atts) std::string description; while(*current /*&& current+1*/) { - assert( *(current + 1) ); + gdcm_assert( *(current + 1) ); ++current; } // Done ! @@ -188,7 +188,7 @@ void XMLDictReader::StartElement(const char *name, const char **atts) else { std::cerr << name << std::endl; - assert(0); + gdcm_assert(0); } } @@ -204,7 +204,7 @@ void XMLDictReader::EndElement(const char *name) } else if( description == name ) { - assert( ParsingDescription ); + gdcm_assert( ParsingDescription ); ParsingDescription = false; // TODO: do something with description ?? @@ -215,7 +215,7 @@ void XMLDictReader::EndElement(const char *name) } else { - assert(0); + gdcm_assert(0); } } @@ -224,7 +224,7 @@ void XMLDictReader::CharacterDataHandler(const char *data, int length) if( ParsingDescription ) { std::string name( data, length); - assert( length == strlen( name.c_str() ) ); + gdcm_assert( length == strlen( name.c_str() ) ); Description.append( name ); } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmXMLPrivateDictReader.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmXMLPrivateDictReader.cxx index cb42c1d7f44..efbac376bb3 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmXMLPrivateDictReader.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition/gdcmXMLPrivateDictReader.cxx @@ -26,7 +26,7 @@ XMLPrivateDictReader::XMLPrivateDictReader():ParsingDescription(false),Descripti void XMLPrivateDictReader::HandleEntry(const char **atts) { - assert( !ParsingDescription ); + gdcm_assert( !ParsingDescription ); std::string name; std::string owner; VR vr; @@ -52,37 +52,37 @@ void XMLPrivateDictReader::HandleEntry(const char **atts) while(*current /*&& current+1*/) { - assert( *(current + 1) ); + gdcm_assert( *(current + 1) ); if( group == *current ) { unsigned int v; const char *raw = *(current+1); int r = sscanf(raw, "%04x", &v); - assert( r == 1 ); - assert( v <= 0xFFFF ); + gdcm_assert( r == 1 ); + gdcm_assert( v <= 0xFFFF ); char sv[4+1]; r = snprintf(sv, sizeof(sv), "%04x", v); - assert( r == 4 ); + gdcm_assert( r == 4 ); if( strncmp(raw, sv, 4) == 0 ) // GroupXX { tag.SetGroup( v ); } else { - assert( (raw[0] == '5' && raw[1] == '0') || (raw[0] == '6' && raw[1] == '0') || + gdcm_assert( (raw[0] == '5' && raw[1] == '0') || (raw[0] == '6' && raw[1] == '0') || (raw[0] == '7' && raw[1] == '0') ); if( raw[0] == '5' ) tag.SetGroup( 0x5000 ); else if( raw[0] == '6' ) tag.SetGroup( 0x6000 ); else if( raw[0] == '7' ) tag.SetGroup( 0x7000 ); - else assert(0); + else gdcm_assert(0); CurrentDE.SetGroupXX( true ); } } else if( element == *current ) { const char *raw = *(current+1); - assert( (raw[0] == 'x' && raw[1] == 'x' ) + gdcm_assert( (raw[0] == 'x' && raw[1] == 'x' ) || (raw[2] == 'x' && raw[3] == 'x') ); if (raw[2] == 'x' && raw[3] == 'x') { @@ -98,40 +98,40 @@ void XMLPrivateDictReader::HandleEntry(const char **atts) } else { - assert(0); // FIXME + gdcm_assert(0); // FIXME } } else { unsigned int v; int r = sscanf(raw+2, "%02x", &v); - assert( r == 1 ); - assert( v <= 0xFF ); + gdcm_assert( r == 1 ); + gdcm_assert( v <= 0xFF ); char sv[4+1]; r = snprintf(sv, sizeof(sv), "xx%02x", v); - assert( r == 4 ); + gdcm_assert( r == 4 ); if( strncmp(raw, sv, 4) == 0 ) { tag.SetElement( v ); } else { - assert(0); + gdcm_assert(0); } } } else if( strvr == *current ) { vr = VR::GetVRTypeFromFile( *(current + 1) ); - //assert( vr != VR::INVALID ); + //gdcm_assert( vr != VR::INVALID ); } else if( strvm == *current ) { vm = VM::GetVMType( *(current + 1) ); - //assert( *(current+1) != '\0' ); - //assert( vm != VM::VM0 ); - //assert( vm != VM::VM_END ); + //gdcm_assert( *(current+1) != '\0' ); + //gdcm_assert( vm != VM::VM0 ); + //gdcm_assert( vm != VM::VM_END ); } else if( retired == *current ) { @@ -145,7 +145,7 @@ void XMLPrivateDictReader::HandleEntry(const char **atts) } else { - assert(0); + gdcm_assert(0); } } else if( version == *current ) @@ -162,7 +162,7 @@ void XMLPrivateDictReader::HandleEntry(const char **atts) } else { - assert(0); + gdcm_assert(0); } // goes on to the next attribute (need to skip value) ++current; @@ -175,9 +175,9 @@ void XMLPrivateDictReader::HandleEntry(const char **atts) void XMLPrivateDictReader::HandleDescription(const char **atts) { - assert( ParsingDescription ); - assert( *atts == NULL ); - assert( Description == "" ); + gdcm_assert( ParsingDescription ); + gdcm_assert( *atts == NULL ); + gdcm_assert( Description == "" ); #if 0 DictEntry &de = CurrentDE; @@ -185,7 +185,7 @@ void XMLPrivateDictReader::HandleDescription(const char **atts) std::string description; while(*current /*&& current+1*/) { - assert( *(current + 1) ); + gdcm_assert( *(current + 1) ); ++current; } // Done ! @@ -217,7 +217,7 @@ void XMLPrivateDictReader::StartElement(const char *name, const char **atts) else { std::cerr << name << std::endl; - assert(0); + gdcm_assert(0); } } @@ -233,7 +233,7 @@ void XMLPrivateDictReader::EndElement(const char *name) } else if( description == name ) { - assert( ParsingDescription ); + gdcm_assert( ParsingDescription ); ParsingDescription = false; // TODO: do something with description ?? @@ -246,7 +246,7 @@ void XMLPrivateDictReader::EndElement(const char *name) } else { - assert(0); + gdcm_assert(0); } } @@ -255,7 +255,7 @@ void XMLPrivateDictReader::CharacterDataHandler(const char *data, int length) if( ParsingDescription ) { std::string name( data, length); - assert( length == strlen( name.c_str() ) ); + gdcm_assert( length == strlen( name.c_str() ) ); Description.append( name ); } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmAnonymizer.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmAnonymizer.cxx index 85982095c90..b337be1cb85 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmAnonymizer.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmAnonymizer.cxx @@ -210,7 +210,7 @@ bool Anonymizer::Replace( Tag const &t, const char *value, VL const & vl ) else { // Ok this is a public element - assert( t.IsPublic() || t.IsPrivateCreator() ); + gdcm_assert( t.IsPublic() || t.IsPrivateCreator() ); const DictEntry &dictentry = dicts.GetDictEntry(t); if ( dictentry.GetVR() == VR::INVALID || dictentry.GetVR() == VR::UN @@ -275,7 +275,7 @@ bool Anonymizer::Replace( Tag const &t, const char *value, VL const & vl ) else { // vr from dict seems to be ascii, so it seems reasonable to write a ByteValue here: - assert( dictentry.GetVR() & VR::VRASCII ); + gdcm_assert( dictentry.GetVR() & VR::VRASCII ); if( value ) { std::string padded( value, vl ); @@ -343,18 +343,18 @@ bool Anonymizer::Replace( PrivateTag const &pt, const char *value, VL const & vl needcreator = false; found = true; } else { - assert( start.GetElement() != 0xff ); + gdcm_assert( start.GetElement() != 0xff ); start.SetElement( start.GetElement() + 1 ); } } while ( !found ); - assert( start.GetGroup() == pt.GetGroup() ); + gdcm_assert( start.GetGroup() == pt.GetGroup() ); if(needcreator) { // add private creator: Element priv_creator; priv_creator.SetValue( pt.GetOwner() ); DataElement creator = priv_creator.GetAsDataElement(); - assert( start.GetElement() <= 0xff ); + gdcm_assert( start.GetElement() <= 0xff ); start.SetElement( start.GetElement() ); creator.SetTag( start ); ds.Insert(creator); @@ -365,14 +365,14 @@ bool Anonymizer::Replace( PrivateTag const &pt, const char *value, VL const & vl const DictEntry &dictentry = dicts.GetDictEntry(pt); DataElement fake; Tag privateLocation(pt); - assert( pt.GetElement() <= 0xff ); + gdcm_assert( pt.GetElement() <= 0xff ); privateLocation.SetElement( start.GetElement() << 8 | pt.GetElement() ); - assert( start == privateLocation.GetPrivateCreator() ); + gdcm_assert( start == privateLocation.GetPrivateCreator() ); fake.SetTag( privateLocation ); fake.SetVR( dictentry.GetVR() ); ds.Insert( fake ); - assert(ds.FindDataElement(pt)); + gdcm_assert(ds.FindDataElement(pt)); return Replace( privateLocation, value, vl ); } } @@ -701,7 +701,7 @@ bool Anonymizer::BasicApplicationLevelConfidentialityProfile1() } else { - assert( de == encryptedds.GetDataElement( de.GetTag() ) ); + gdcm_assert( de == encryptedds.GetDataElement( de.GetTag() ) ); } } } @@ -741,7 +741,7 @@ bool Anonymizer::BasicApplicationLevelConfidentialityProfile1() gdcmErrorMacro( "Problem with Encrypt" ); return false; } - assert( encrypted_len <= encrypted_len2 ); + gdcm_assert( encrypted_len <= encrypted_len2 ); (void)encrypted_len2;//warning removal { @@ -896,11 +896,11 @@ bool Anonymizer::CanEmptyTag(Tag const &tag, const IOD &iod) const const DataSet &ds = F->GetDataSet(); (void)ds; //Type told = defs.GetTypeFromTag(*F, tag); Type t = iod.GetTypeFromTag(defs, tag); - //assert( t == told ); + //gdcm_assert( t == told ); gdcmDebugMacro( "Type for tag=" << tag << " is " << t ); - //assert( t != Type::UNKNOWN ); + //gdcm_assert( t != Type::UNKNOWN ); if( t == Type::T1 || t == Type::T1C ) { @@ -940,7 +940,7 @@ generate a DICOMDIR // This is a Type 3 attribute but with VR=UI // - //assert( dicts.GetDictEntry(tag).GetVR() != VR::UI ); + //gdcm_assert( dicts.GetDictEntry(tag).GetVR() != VR::UI ); return !b; } @@ -956,7 +956,7 @@ void Anonymizer::ClearInternalUIDs() bool Anonymizer::BALCPProtect(DataSet &ds, Tag const & tag, IOD const & iod) { // \precondition - assert( ds.FindDataElement(tag) ); + gdcm_assert( ds.FindDataElement(tag) ); AnonymizeEvent ae; ae.SetTag( tag ); @@ -1010,7 +1010,7 @@ bool Anonymizer::BALCPProtect(DataSet &ds, Tag const & tag, IOD const & iod) TagValueKey tvk; tvk.first = tag; - assert( dummyMapNonUIDTags.count( tvk ) == 0 || dummyMapNonUIDTags.count( tvk ) == 1 ); + gdcm_assert( dummyMapNonUIDTags.count( tvk ) == 0 || dummyMapNonUIDTags.count( tvk ) == 1 ); if( dummyMapNonUIDTags.count( tvk ) == 0 ) { const char *ret = DummyValueGenerator::Generate( tvk.second.c_str() ); @@ -1068,7 +1068,7 @@ void Anonymizer::RecurseDataSet( DataSet & ds ) DataSet::ConstIterator it = ds.Begin(); for( ; it != ds.End(); /*++it*/ ) { - assert( it != ds.End() ); + gdcm_assert( it != ds.End() ); DataElement de = *it; ++it; //const SequenceOfItems *sqi = de.GetSequenceOfItems(); VR vr = DataSetHelper::ComputeVR(*F, ds, de.GetTag() ); @@ -1083,7 +1083,7 @@ void Anonymizer::RecurseDataSet( DataSet & ds ) // Legacy behavior has been to create CP-246 / undefined length SQ as VR:UN... if( de.GetVR() == VR::OB ) de.SetVR( VR::UN ); de.SetVLToUndefined(); - assert( sqi->IsUndefinedLength() ); + gdcm_assert( sqi->IsUndefinedLength() ); //de.GetVL().SetToUndefined(); //sqi->SetLengthToUndefined(); SequenceOfItems::SizeType n = sqi->GetNumberOfItems(); @@ -1179,7 +1179,7 @@ bool Anonymizer::BasicApplicationLevelConfidentialityProfile2() gdcmDebugMacro( "Could not decrypt" ); return false; } - assert( encrypted_len <= encrypted_len2 ); + gdcm_assert( encrypted_len <= encrypted_len2 ); (void)encrypted_len2;//warning removal std::stringstream ss; @@ -1205,7 +1205,7 @@ bool Anonymizer::BasicApplicationLevelConfidentialityProfile2() //std::cout << des << std::endl; //std::cout << dummy << std::endl; //std::cout << ss.tellg() << std::endl; - assert( (size_t)ss.tellg() <= encrypted_len ); + gdcm_assert( (size_t)ss.tellg() <= encrypted_len ); // TODO: check that for i = ss.tellg() to encrypted_len, ss[i] == 0 delete[] buf; delete[] orig; @@ -1214,11 +1214,11 @@ bool Anonymizer::BasicApplicationLevelConfidentialityProfile2() // of the Modified Attributes Sequence (0400,0550) of the decoded dataset // into the main dataset, replacing dummy value Attributes that may be // present in the main dataset. - //assert( dummy.GetVR() == VR::SQ ); + //gdcm_assert( dummy.GetVR() == VR::SQ ); { //const SequenceOfItems *sqi = dummy.GetSequenceOfItems(); SmartPointer sqi = dummy.GetValueAsSQ(); - assert( sqi && sqi->GetNumberOfItems() == 1 ); + gdcm_assert( sqi && sqi->GetNumberOfItems() == 1 ); Item const & item2 = sqi->GetItem( 1 ); const DataSet &nds2 = item2.GetNestedDataSet(); DataSet::ConstIterator it = nds2.Begin(); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmApplicationEntity.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmApplicationEntity.h index dbd079de725..407b96554fc 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmApplicationEntity.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmApplicationEntity.h @@ -50,11 +50,11 @@ class GDCM_EXPORT ApplicationEntity } void SetBlob(const std::vector& v) { (void)v; - assert(0); //TODO + gdcm_assert(0); //TODO } void Print(std::ostream &os) const { (void)os; - assert(0); //TODO + gdcm_assert(0); //TODO } }; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmBitmap.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmBitmap.cxx index f92a1132306..fb051011904 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmBitmap.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmBitmap.cxx @@ -63,16 +63,16 @@ Bitmap::~Bitmap() = default; */ unsigned int Bitmap::GetNumberOfDimensions() const { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); return NumberOfDimensions; } void Bitmap::SetNumberOfDimensions(unsigned int dim) { NumberOfDimensions = dim; - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); Dimensions.resize( 3 /*NumberOfDimensions*/ ); // fill with 0 - assert( NumberOfDimensions == 2 || NumberOfDimensions == 3 ); + gdcm_assert( NumberOfDimensions == 2 || NumberOfDimensions == 3 ); if( NumberOfDimensions == 2 ) { Dimensions[2] = 1; @@ -82,25 +82,25 @@ void Bitmap::SetNumberOfDimensions(unsigned int dim) const unsigned int *Bitmap::GetDimensions() const { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); return Dimensions.data(); } unsigned int Bitmap::GetDimension(unsigned int idx) const { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); return Dimensions[idx]; } void Bitmap::SetDimensions(const unsigned int *dims) { - assert( NumberOfDimensions ); - //assert( Dimensions.empty() ); + gdcm_assert( NumberOfDimensions ); + //gdcm_assert( Dimensions.empty() ); #if 0 Dimensions = std::vector(dims, dims+NumberOfDimensions); #else - assert( Dimensions.size() == 3 ); + gdcm_assert( Dimensions.size() == 3 ); Dimensions[0] = dims[0]; Dimensions[1] = dims[1]; if( NumberOfDimensions == 2 ) @@ -112,13 +112,13 @@ void Bitmap::SetDimensions(const unsigned int *dims) void Bitmap::SetDimension(unsigned int idx, unsigned int dim) { - //assert( dim ); - assert( NumberOfDimensions ); - assert( idx < NumberOfDimensions ); + //gdcm_assert( dim ); + gdcm_assert( NumberOfDimensions ); + gdcm_assert( idx < NumberOfDimensions ); Dimensions.resize( 3 /*NumberOfDimensions*/ ); // Can dim be 0 ?? // -> no ! - //assert( dim ); // PhilipsLosslessRice.dcm + //gdcm_assert( dim ); // PhilipsLosslessRice.dcm Dimensions[idx] = dim; if( NumberOfDimensions == 2 ) { @@ -145,7 +145,7 @@ unsigned int Bitmap::GetPlanarConfiguration() const void Bitmap::SetPlanarConfiguration(unsigned int pc) { // precondition - assert( pc == 0 || pc == 1 ); + gdcm_assert( pc == 0 || pc == 1 ); PlanarConfiguration = pc; if( pc ) { @@ -181,7 +181,7 @@ void Bitmap::SetPlanarConfiguration(unsigned int pc) } } // \postcondition - assert( PlanarConfiguration == 0 || PlanarConfiguration == 1 ); + gdcm_assert( PlanarConfiguration == 0 || PlanarConfiguration == 1 ); } @@ -225,9 +225,9 @@ bool Bitmap::GetBuffer(char *buffer) const buffer = 0; return false; } - assert( bv ); + gdcm_assert( bv ); RAWCodec codec; - //assert( GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME2 ); + //gdcm_assert( GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME2 ); //codec.SetPhotometricInterpretation( GetPhotometricInterpretation() ); if( GetPhotometricInterpretation() != PhotometricInterpretation::MONOCHROME2 ) { @@ -238,9 +238,9 @@ bool Bitmap::GetBuffer(char *buffer) const codec.SetPlanarConfiguration( 0 ); DataElement out; bool r = codec.Decode(PixelData, out); - assert( r ); + gdcm_assert( r ); const ByteValue *outbv = out.GetByteValue(); - assert( outbv ); + gdcm_assert( outbv ); //unsigned long check = outbv->GetLength(); // FIXME memcpy(buffer, outbv->GetPointer(), outbv->GetLength() ); // FIXME return r; @@ -249,14 +249,14 @@ bool Bitmap::GetBuffer(char *buffer) const unsigned long Bitmap::GetBufferLength() const { - //assert( !IsEncapsulated() ); + //gdcm_assert( !IsEncapsulated() ); if( PF == PixelFormat::UNKNOWN ) return 0; - assert( NumberOfDimensions ); - //assert( NumberOfDimensions == Dimensions.size() ); + gdcm_assert( NumberOfDimensions ); + //gdcm_assert( NumberOfDimensions == Dimensions.size() ); if( NumberOfDimensions != Dimensions.size() ) { - assert( Dimensions[2] == 1 ); + gdcm_assert( Dimensions[2] == 1 ); } unsigned long len = 0; unsigned int mul = 1; @@ -274,23 +274,23 @@ unsigned long Bitmap::GetBufferLength() const #if 1 mul *= PF.GetPixelSize(); #else - assert( PF.GetSamplesPerPixel() == 1 ); + gdcm_assert( PF.GetSamplesPerPixel() == 1 ); unsigned int save = mul; save *= 12; save /= 8; - assert( save * 8 / 12 == mul ); + gdcm_assert( save * 8 / 12 == mul ); mul = save; #endif } else if( PF == PixelFormat::SINGLEBIT ) { - assert( PF.GetSamplesPerPixel() == 1 ); + gdcm_assert( PF.GetSamplesPerPixel() == 1 ); const size_t bytesPerRow = Dimensions[0] / 8 + (Dimensions[0] % 8 != 0 ? 1 : 0); size_t save = bytesPerRow * Dimensions[1]; if( NumberOfDimensions > 2 ) save *= Dimensions[2]; if(Dimensions[0] % 8 == 0 ) - assert( save * 8 == mul ); + gdcm_assert( save * 8 == mul ); mul = (unsigned int)save; } else if( PF.GetBitsAllocated() % 8 != 0 ) @@ -299,12 +299,12 @@ unsigned long Bitmap::GetBufferLength() const // BitsAllocated :14 // BitsStored :14 // HighBit :13 - assert( PF.GetSamplesPerPixel() == 1 ); + gdcm_assert( PF.GetSamplesPerPixel() == 1 ); const ByteValue *bv = PixelData.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); unsigned int ref = bv->GetLength() / mul; if( !GetTransferSyntax().IsEncapsulated() ) - assert( bv->GetLength() % mul == 0 ); + gdcm_assert( bv->GetLength() % mul == 0 ); mul *= ref; } else @@ -313,7 +313,7 @@ unsigned long Bitmap::GetBufferLength() const } len = mul; - //assert( len != 0 ); + //gdcm_assert( len != 0 ); return len; } @@ -358,7 +358,7 @@ bool Bitmap::TryRAWCodec(char *buffer, bool &lossyflag) const } if( !r ) return false; //const ByteValue *outbv = out.GetByteValue(); - //assert( outbv ); + //gdcm_assert( outbv ); if( len != bv->GetLength() ) { // SIEMENS_GBS_III-16-ACR_NEMA_1.acr @@ -375,12 +375,23 @@ bool Bitmap::TryRAWCodec(char *buffer, bool &lossyflag) const Bitmap *i = (Bitmap*)this; i->SetPixelFormat( codec.GetPixelFormat() ); } +#else + const PixelFormat pf = GetPixelFormat(); // PixelFormat::UINT8; + const PixelFormat & cpf = codec.GetPixelFormat(); + if( cpf.GetBitsAllocated() == 16 && pf.GetBitsAllocated() == 12 ) + { + Bitmap *i = const_cast(this); + gdcmWarningMacro( "Mismatch Bits Allocated. correcting." ); + i->GetPixelFormat().SetBitsAllocated( cpf.GetBitsAllocated() ); + i->GetPixelFormat().SetBitsStored( pf.GetBitsStored() ); + i->GetPixelFormat().SetHighBit( pf.GetHighBit() ); + } #endif unsigned long check; // = outbv->GetLength(); // FIXME check = len; // DermaColorLossLess.dcm - assert( check == len || check == len + 1 ); + gdcm_assert( check == len || check == len + 1 ); (void)check;// removing warning //if(buffer) memcpy(buffer, outbv->GetPointer(), outbv->GetLength() ); // FIXME return r; @@ -410,7 +421,7 @@ bool Bitmap::TryJPEGCodec(char *buffer, bool &lossyflag) const bool b = codec.GetHeaderInfo( ss, ts2 ); //bool b = codec.GetHeaderInfo( bv2.GetPointer(), bv2.GetLength() , ts2 ); if(!b) return false; - assert( b ); + gdcm_assert(b); lossyflag = codec.IsLossy(); // we need to know the actual pixeltype after ::Read #if 0 @@ -525,7 +536,7 @@ bool Bitmap::TryJPEGCodec(char *buffer, bool &lossyflag) const // i->SetPhotometricInterpretation( PhotometricInterpretation::RGB ); // } const ByteValue *outbv = out.GetByteValue(); - assert( outbv ); + gdcm_assert( outbv ); unsigned long check = outbv->GetLength(); // FIXME (void)check; // DermaColorLossLess.dcm has a len of 63531, but DICOM will give us: 63532 ... @@ -534,11 +545,11 @@ bool Bitmap::TryJPEGCodec(char *buffer, bool &lossyflag) const gdcmErrorMacro( "Impossible length: " << len << " should be (max): " << outbv->GetLength() ); return false; } - assert( len <= outbv->GetLength() ); + gdcm_assert( len <= outbv->GetLength() ); if(buffer) memcpy(buffer, outbv->GetPointer(), len /*outbv->GetLength()*/ ); // FIXME lossyflag = codec.IsLossy(); - //assert( codec.IsLossy() == ts.IsLossy() ); + //gdcm_assert( codec.IsLossy() == ts.IsLossy() ); return true; } @@ -574,11 +585,11 @@ bool Bitmap::TryJPEGCodec2(std::ostream &os) const //i->SetPhotometricInterpretation( codec.GetPhotometricInterpretation() ); } const ByteValue *outbv = out.GetByteValue(); - assert( outbv ); + gdcm_assert( outbv ); unsigned long check = outbv->GetLength(); // FIXME (void)check; // DermaColorLossLess.dcm has a len of 63531, but DICOM will give us: 63532 ... - assert( outbv->GetLength() < len ); (void)len; + gdcm_assert( outbv->GetLength() < len ); (void)len; //memcpy(buffer, outbv->GetPointer(), outbv->GetLength() ); os.write( outbv->GetPointer(), outbv->GetLength() ); @@ -606,21 +617,21 @@ bool Bitmap::TryPVRGCodec(char *buffer, bool &lossyflag) const bool r = codec.Decode(PixelData, out); if(!r) return false; codec.SetLossyFlag( ts.IsLossy() ); - assert( r ); + gdcm_assert( r ); if ( GetPlanarConfiguration() != codec.GetPlanarConfiguration() ) { Bitmap *i = const_cast(this); i->PlanarConfiguration = codec.GetPlanarConfiguration(); } const ByteValue *outbv = out.GetByteValue(); - assert( outbv ); + gdcm_assert( outbv ); unsigned long check = outbv->GetLength(); // FIXME (void)check; - assert( len <= outbv->GetLength() ); + gdcm_assert( len <= outbv->GetLength() ); if(buffer) memcpy(buffer, outbv->GetPointer(), len /*outbv->GetLength()*/ ); // FIXME lossyflag = codec.IsLossy(); - //assert( codec.IsLossy() == ts.IsLossy() ); + //gdcm_assert( codec.IsLossy() == ts.IsLossy() ); return r; } @@ -646,15 +657,15 @@ bool Bitmap::TryKAKADUCodec(char *buffer, bool &lossyflag) const bool r = codec.Decode(PixelData, out); if( !r ) return false; const ByteValue *outbv = out.GetByteValue(); - assert( outbv ); + gdcm_assert( outbv ); unsigned long check = outbv->GetLength(); // FIXME (void)check; - assert( len <= outbv->GetLength() ); + gdcm_assert( len <= outbv->GetLength() ); // DermaColorLossLess.dcm has a len of 63531, but DICOM will give us: 63532 ... - assert( len <= outbv->GetLength() ); + gdcm_assert( len <= outbv->GetLength() ); if(buffer) memcpy(buffer, outbv->GetPointer(), len /*outbv->GetLength()*/ ); // FIXME - //assert( codec.IsLossy() == ts.IsLossy() ); + //gdcm_assert( codec.IsLossy() == ts.IsLossy() ); lossyflag = codec.IsLossy(); if( codec.IsLossy() != ts.IsLossy() ) { @@ -720,15 +731,15 @@ bool Bitmap::TryJPEGLSCodec(char *buffer, bool &lossyflag) const bool r = codec.Decode(PixelData, out); if( !r ) return false; const ByteValue *outbv = out.GetByteValue(); - assert( outbv ); + gdcm_assert( outbv ); unsigned long check = outbv->GetLength(); // FIXME (void)check; - assert( len <= outbv->GetLength() ); + gdcm_assert( len <= outbv->GetLength() ); // DermaColorLossLess.dcm has a len of 63531, but DICOM will give us: 63532 ... - assert( len <= outbv->GetLength() ); + gdcm_assert( len <= outbv->GetLength() ); memcpy(buffer, outbv->GetPointer(), len /*outbv->GetLength()*/ ); // FIXME - //assert( codec.IsLossy() == ts.IsLossy() ); + //gdcm_assert( codec.IsLossy() == ts.IsLossy() ); lossyflag = codec.IsLossy(); if( codec.IsLossy() != ts.IsLossy() ) { @@ -877,19 +888,19 @@ bool Bitmap::TryJPEG2000Codec(char *buffer, bool &lossyflag) const DataElement out; bool r = codec.Decode(PixelData, out); if(!r) return false; - assert( r ); + gdcm_assert( r ); const ByteValue *outbv = out.GetByteValue(); - assert( outbv ); + gdcm_assert( outbv ); unsigned long check = outbv->GetLength(); // FIXME (void)check; - assert( len <= outbv->GetLength() ); + gdcm_assert( len <= outbv->GetLength() ); memcpy(buffer, outbv->GetPointer(), len /*outbv->GetLength()*/ ); // FIXME lossyflag = codec.IsLossy(); if( codec.IsLossy() && !ts.IsLossy() ) { - assert( codec.IsLossy() ); - assert( !ts.IsLossy() ); + gdcm_assert( codec.IsLossy() ); + gdcm_assert( !ts.IsLossy() ); gdcmErrorMacro( "EVIL file, it is declared as lossless but is in fact lossy." ); } #if 0 @@ -942,9 +953,9 @@ bool Bitmap::TryJPEG2000Codec2(std::ostream &os) const codec.SetNeedOverlayCleanup( AreOverlaysInPixelData() || UnusedBitsPresentInPixelData() ); DataElement out; bool r = codec.Code(PixelData, out); - assert( r ); + gdcm_assert( r ); const ByteValue *outbv = out.GetByteValue(); - assert( outbv ); + gdcm_assert( outbv ); unsigned long check = outbv->GetLength(); // FIXME (void)check; //memcpy(buffer, outbv->GetPointer(), outbv->GetLength() ); // FIXME @@ -962,8 +973,8 @@ bool Bitmap::TryRLECodec(char *buffer, bool &lossyflag ) const RLECodec codec; if( codec.CanDecode( ts ) ) { - //assert( sf->GetNumberOfFragments() == 1 ); - //assert( sf->GetNumberOfFragments() == GetDimensions(2) ); + //gdcm_assert( sf->GetNumberOfFragments() == 1 ); + //gdcm_assert( sf->GetNumberOfFragments() == GetDimensions(2) ); codec.SetDimensions( GetDimensions() ); codec.SetNumberOfDimensions( GetNumberOfDimensions() ); codec.SetPlanarConfiguration( GetPlanarConfiguration() ); @@ -978,7 +989,7 @@ bool Bitmap::TryRLECodec(char *buffer, bool &lossyflag ) const const ByteValue *outbv = out.GetByteValue(); //unsigned long check = outbv->GetLength(); // FIXME // DermaColorLossLess.dcm has a len of 63531, but DICOM will give us: 63532 ... - assert( len <= outbv->GetLength() ); + gdcm_assert( len <= outbv->GetLength() ); if(buffer) memcpy(buffer, outbv->GetPointer(), len /*outbv->GetLength()*/ ); // FIXME lossyflag = false; return true; @@ -1046,11 +1057,11 @@ bool Bitmap::IsTransferSyntaxCompatible( TransferSyntax const & ts ) const void Bitmap::Print(std::ostream &os) const { Object::Print(os); - //assert( NumberOfDimensions ); + //gdcm_assert( NumberOfDimensions ); if( !IsEmpty() ) { os << "NumberOfDimensions: " << NumberOfDimensions << "\n"; - assert( !Dimensions.empty() ); + gdcm_assert( !Dimensions.empty() ); os << "Dimensions: ("; std::vector::const_iterator it = Dimensions.begin(); os << *it; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmBitmapToBitmapFilter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmBitmapToBitmapFilter.cxx index d0f8d06293a..7c20da7b2a2 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmBitmapToBitmapFilter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmBitmapToBitmapFilter.cxx @@ -44,7 +44,7 @@ void BitmapToBitmapFilter::SetInput(const Bitmap& image) else { Output = nullptr; - assert( 0 ); + gdcm_assert( 0 ); } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmCleaner.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmCleaner.cxx index 0d0ffe28b09..0b81d6af829 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmCleaner.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmCleaner.cxx @@ -523,6 +523,7 @@ typedef std::set DataElementSet; typedef DataElementSet::const_iterator ConstIterator; struct Cleaner::impl { + std::set coded_entry_datas; std::set preserve_dpaths; std::set empty_dpaths; std::set remove_dpaths; @@ -545,7 +546,13 @@ struct Cleaner::impl { AllIllegal(true), WhenScrubFails(false) {} - enum ACTION { NONE, EMPTY, REMOVE, SCRUB }; + // CODE_MEANING: + // In general, there are no Code Sequence Attributes in this table, since it + // is usually safe to assume that coded sequence entries, including private + // codes, do not contain identifying information. Exceptions are codes for + // providers and staff. + // https://dicom.nema.org/medical/dicom/current/output/chtml/part15/chapter_E.html#para_d0913a6e-9386-42b2-b2b3-e87c84cdb304 + enum ACTION { NONE, EMPTY, REMOVE, SCRUB, CODE_MEANING }; enum ACTION ComputeAction(File const &file, DataSet &ds, const DataElement &de, VR const &ref_dict_vr, const std::string &tag_path); @@ -659,6 +666,11 @@ struct Cleaner::impl { bool Scrub(VR const & /*vr*/) { return false; } + bool ReplaceCodeMeaning(CodedEntryData const &ced) { + coded_entry_datas.insert(ced); + return true; + } + bool Preserve(DPath const &dpath) { preserve_dpaths.insert(dpath); return true; @@ -684,13 +696,13 @@ static VR ComputeDictVR(File &file, DataSet &ds, DataElement const &de) { } else { const PrivateTag pt = ds.GetPrivateTag(tag); const char *owner = pt.GetOwner(); - assert(owner); + gdcm_assert(owner); compute_dict_vr = *owner != 0; } if (compute_dict_vr) dict_vr = DataSetHelper::ComputeVR(file, ds, tag); if (de.GetVR() == VR::SQ) { - assert(dict_vr != VR::UN); + gdcm_assert(dict_vr != VR::UN); if (!dict_vr.Compatible(de.GetVR())) { gdcmErrorMacro("Impossible. Dict states VR is: " << dict_vr << " which is impossible for SQ"); @@ -699,11 +711,15 @@ static VR ComputeDictVR(File &file, DataSet &ds, DataElement const &de) { } if (dict_vr != VR::SQ) { if (de.GetVL().IsUndefined()) { - Tag pixelData(0x7fe0, 0x0010); - assert(dict_vr == VR::OB); - if (tag != pixelData) { - gdcmErrorMacro("Impossible happen: " << de); - return VR::SQ; + if (dict_vr == VR::UN) { + // implicit dataset, where SQ is undefined length + } else { + const Tag pixelData(0x7fe0, 0x0010); + gdcm_assert(dict_vr == VR::OB); + if (tag != pixelData) { + gdcmErrorMacro("Impossible happen: " << de); + return VR::SQ; + } } } } @@ -812,7 +828,7 @@ static inline int bs_memcmp(const void *s1, const void *s2, size_t n) { size_t i; const unsigned char *us1 = (const unsigned char *)s1; const unsigned char *us2 = (const unsigned char *)s2; - assert(n % 2 == 0); + gdcm_assert(n % 2 == 0); for (i = 0; i < n; i += 2, us1 += 2, us2 += 2) { if (*us1 < *(us2 + 1)) { @@ -1096,7 +1112,29 @@ Cleaner::impl::ACTION Cleaner::impl::ComputeAction( } if (tag.IsPublic()) { + // CodeMeaning + if (tag == gdcm::Tag(0x0008, 0x0104)) { + Attribute<0x0008, 0x0100> codeValue{}; + codeValue.SetFromDataSet(ds); + Attribute<0x0008, 0x0102> codingSchemeDesignator{}; + codingSchemeDesignator.SetFromDataSet(ds); + Attribute<0x0008, 0x0103> codingSchemeVersion{}; + codingSchemeVersion.SetFromDataSet(ds); + const std::string codeValueStr = codeValue.GetValue().Trim(); + const std::string codingSchemeDesignatorStr = codingSchemeDesignator.GetValue().Trim(); + const std::string codingSchemeVersionStr = codingSchemeVersion.GetValue().Trim(); + { + CodedEntryData ced; + ced = std::make_tuple(codeValueStr, codingSchemeDesignatorStr, + codingSchemeVersionStr); + if( coded_entry_datas.find(ced) != coded_entry_datas.end() ) + return Cleaner::impl::CODE_MEANING; + } + + return Cleaner::impl::NONE; + } const DPath dpath = ConstructDPath(tag_path, ds, tag); + // Preserve if (IsDPathInSet(preserve_dpaths, dpath)) return Cleaner::impl::NONE; // Scrub @@ -1107,9 +1145,9 @@ Cleaner::impl::ACTION Cleaner::impl::ComputeAction( // Empty if (empty_tags.find(tag) != empty_tags.end() || IsDPathInSet(empty_dpaths, dpath)) { - assert(!tag.IsGroupLength()); - assert(!tag.IsPrivateCreator()); - assert(ds.FindDataElement(tag)); + gdcm_assert(!tag.IsGroupLength()); + gdcm_assert(!tag.IsPrivateCreator()); + gdcm_assert(ds.FindDataElement(tag)); return Cleaner::impl::EMPTY; } // Remove @@ -1122,7 +1160,7 @@ Cleaner::impl::ACTION Cleaner::impl::ComputeAction( if (tag.IsPrivate() && !tag.IsPrivateCreator() && !tag.IsGroupLength()) { const PrivateTag pt = ds.GetPrivateTag(tag); const char *owner = pt.GetOwner(); - assert(owner); + gdcm_assert(owner); if (*owner == 0 && AllMissingPrivateCreator) { return Cleaner::impl::REMOVE; } @@ -1150,7 +1188,7 @@ Cleaner::impl::ACTION Cleaner::impl::ComputeAction( // VR cleanup if (!empty_vrs.empty() || !remove_vrs.empty()) { VR vr = de.GetVR(); - assert(ref_dict_vr != VR::INVALID); + gdcm_assert(ref_dict_vr != VR::INVALID); // be careful with vr handling since we must always prefer the one from // the dict in case of attribute written as 'OB' but dict states 'PN': if (ref_dict_vr != VR::UN /*&& ref_dict_vr != VR::INVALID*/) { @@ -1161,7 +1199,7 @@ Cleaner::impl::ACTION Cleaner::impl::ComputeAction( vr = ref_dict_vr; } if (vr != ref_dict_vr) { - // assert(vr == VR::OB || vr == VR::OW); + // gdcm_assert(vr == VR::OB || vr == VR::OW); vr = ref_dict_vr; } } @@ -1283,6 +1321,18 @@ bool Cleaner::impl::ProcessDataSet(Subject &subject, File &file, DataSet &ds, return false; } subject.InvokeEvent(ae); + } else if (action == Cleaner::impl::CODE_MEANING) { + // Cannot simply 'empty' public data element in this case: + // Code Meaning (0008, 0104) 1 Text that conveys the meaning of the Coded Entry. + // https://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_8.8.html#table_8.8-1a + // Action Code 'Z' states: + // replace with a zero length value, or a non - zero length value that may be a dummy value and consistent with the VR + DataElement clean(de.GetTag()); + clean.SetVR(de.GetVR()); + static const char clean_str[] = "ALTERED CODE MEANING"; // len=20 + clean.SetByteValue(clean_str, static_cast(strlen(clean_str))); + ds.Replace(clean); + subject.InvokeEvent(ae); } else { gdcmErrorMacro("Missing handling of action: " << action); return false; @@ -1310,6 +1360,10 @@ bool Cleaner::Scrub(PrivateTag const &pt) { return pimpl->Scrub(pt); } bool Cleaner::Scrub(DPath const &dpath) { return pimpl->Scrub(dpath); } bool Cleaner::Scrub(VR const &vr) { return pimpl->Scrub(vr); } +bool Cleaner::ReplaceCodeMeaning(Cleaner::CodedEntryData const &ced) { + return pimpl->ReplaceCodeMeaning(ced); +} + bool Cleaner::Preserve(DPath const &dpath) { return pimpl->Preserve(dpath); } void Cleaner::RemoveAllMissingPrivateCreator(bool remove) { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmCleaner.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmCleaner.h index bf2ad54430b..c42278fc014 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmCleaner.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmCleaner.h @@ -49,6 +49,14 @@ class GDCM_EXPORT Cleaner : public Subject { bool Scrub(DPath const &dpath); bool Scrub(VR const &vr); + // 8 Encoding of Coded Entry Data + // https://dicom.nema.org/medical/dicom/current/output/chtml/part03/chapter_8.html + typedef std::tuple CodedEntryData; + + /// Coded Entry Data + bool ReplaceCodeMeaning(CodedEntryData const &ced); + + /// Preserve bool Preserve(DPath const &dpath); /// Should I remove all private tag for which no private creator is found. diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmCurve.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmCurve.cxx index a8d9f7c1c07..64c6433d858 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmCurve.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmCurve.cxx @@ -153,13 +153,13 @@ unsigned int Curve::GetNumberOfCurves(DataSet const & ds) void Curve::Update(const DataElement & de) { - assert( de.GetTag().IsPublic() ); + gdcm_assert( de.GetTag().IsPublic() ); const ByteValue* bv = de.GetByteValue(); if( !bv ) return; // Discard any empty element (will default to another value) - assert( bv->GetPointer() && bv->GetLength() ); + gdcm_assert( bv->GetPointer() && bv->GetLength() ); std::string s( bv->GetPointer(), bv->GetLength() ); // What if a \0 can be found before the end of string... - //assert( strlen( s.c_str() ) == s.size() ); + //gdcm_assert( strlen( s.c_str() ) == s.size() ); // First thing check consistency: if( !GetGroup() ) @@ -168,7 +168,7 @@ void Curve::Update(const DataElement & de) } else // check consistency { - assert( GetGroup() == de.GetTag().GetGroup() ); // programmer error + gdcm_assert( GetGroup() == de.GetTag().GetGroup() ); // programmer error } //std::cerr << "Tag: " << de.GetTag() << std::endl; @@ -258,7 +258,7 @@ void Curve::Update(const DataElement & de) } else { - assert( 0 && "should not happen: Unknown curve tag" ); + gdcm_assert( 0 && "should not happen: Unknown curve tag" ); } } @@ -345,15 +345,15 @@ void Curve::SetCurve(const char *array, unsigned int length) if( !array || length == 0 ) return; Internal->Data.resize( length ); std::copy(array, array+length, Internal->Data.begin()); - //assert( 8 * length == (unsigned int)Internal->Rows * Internal->Columns ); - //assert( Internal->Data.size() == length ); + //gdcm_assert( 8 * length == (unsigned int)Internal->Rows * Internal->Columns ); + //gdcm_assert( Internal->Data.size() == length ); } void Curve::Decode(std::istream &is, std::ostream &os) { (void)is; (void)os; - assert(0); + gdcm_assert(0); } /* @@ -408,7 +408,7 @@ The data points of this dimension will be absent from Curve Data (50xx,3000). */ double Curve::ComputeValueFromStartAndStep(unsigned int idx) const { - assert( !Internal->CurveDataDescriptor.empty() ); + gdcm_assert( !Internal->CurveDataDescriptor.empty() ); const double res = Internal->CoordinateStartValue + Internal->CoordinateStepValue * idx; return res; @@ -416,49 +416,49 @@ double Curve::ComputeValueFromStartAndStep(unsigned int idx) const void Curve::GetAsPoints(float *array) const { - assert( getsizeofrep(Internal->DataValueRepresentation) ); + gdcm_assert( getsizeofrep(Internal->DataValueRepresentation) ); if( Internal->CurveDataDescriptor.empty() ) { - assert( Internal->Data.size() == (uint32_t)Internal->NumberOfPoints * + gdcm_assert( Internal->Data.size() == (uint32_t)Internal->NumberOfPoints * Internal->Dimensions * getsizeofrep( Internal->DataValueRepresentation) ); } else { - assert( Internal->Data.size() == (uint32_t)Internal->NumberOfPoints * + gdcm_assert( Internal->Data.size() == (uint32_t)Internal->NumberOfPoints * 1 * getsizeofrep( Internal->DataValueRepresentation) ); } - assert( Internal->Dimensions == 1 || Internal->Dimensions == 2 ); + gdcm_assert( Internal->Dimensions == 1 || Internal->Dimensions == 2 ); const int mult = Internal->Dimensions; int genidx = -1; if( !Internal->CurveDataDescriptor.empty() ) { - assert( Internal->CurveDataDescriptor.size() == Internal->Dimensions ); - assert( Internal->CurveDataDescriptor.size() == 2 ); // FIXME + gdcm_assert( Internal->CurveDataDescriptor.size() == Internal->Dimensions ); + gdcm_assert( Internal->CurveDataDescriptor.size() == 2 ); // FIXME if( Internal->CurveDataDescriptor[0] == 0 ) { - assert( Internal->CurveDataDescriptor[1] == 1 ); + gdcm_assert( Internal->CurveDataDescriptor[1] == 1 ); genidx = 0; } else if( Internal->CurveDataDescriptor[1] == 0 ) { - assert( Internal->CurveDataDescriptor[0] == 1 ); + gdcm_assert( Internal->CurveDataDescriptor[0] == 1 ); genidx = 1; } else { - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); } } const char * beg = Internal->Data.data(); const char * end = beg + Internal->Data.size(); if( genidx == -1 ) { - assert( end == beg + 2 * Internal->NumberOfPoints ); (void)beg;(void)end; + gdcm_assert( end == beg + 2 * Internal->NumberOfPoints ); (void)beg;(void)end; } else { - assert( end == beg + mult * Internal->NumberOfPoints ); (void)beg;(void)end; + gdcm_assert( end == beg + mult * Internal->NumberOfPoints ); (void)beg;(void)end; } @@ -554,7 +554,7 @@ void Curve::GetAsPoints(float *array) const } else { - assert( 0 ); + gdcm_assert( 0 ); } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDICOMDIRGenerator.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDICOMDIRGenerator.cxx index 09e6dd61d63..3d3e0305de0 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDICOMDIRGenerator.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDICOMDIRGenerator.cxx @@ -87,7 +87,7 @@ static const char *GetLowerLevelDirectoryRecord(const char *input) { return nullptr; } - assert( 0 ); + gdcm_assert( 0 ); //std::cerr << "COULD NOT FIND:" << input << std::endl; return nullptr; } @@ -113,13 +113,13 @@ DICOMDIRGenerator::MyPair DICOMDIRGenerator::GetReferenceValueForDirectoryType(s directoryrecordtype.Set( ds ); const char *input = directoryrecordtype.GetValue(); - assert( input ); + gdcm_assert( input ); if( strcmp( input, "PATIENT " ) == 0 ) { Attribute<0x10,0x20> patientid; patientid.Set( ds ); - assert( patientid.GetValue() ); + gdcm_assert( patientid.GetValue() ); ret.first = patientid.GetValue(); ret.second = patientid.GetTag(); } @@ -127,7 +127,7 @@ DICOMDIRGenerator::MyPair DICOMDIRGenerator::GetReferenceValueForDirectoryType(s { Attribute <0x20,0xd> studyuid; studyuid.Set( ds ); - assert( studyuid.GetValue() ); + gdcm_assert( studyuid.GetValue() ); ret.first = studyuid.GetValue(); ret.second = studyuid.GetTag(); } @@ -135,7 +135,7 @@ DICOMDIRGenerator::MyPair DICOMDIRGenerator::GetReferenceValueForDirectoryType(s { Attribute <0x20,0xe> seriesuid; seriesuid.Set( ds ); - assert( seriesuid.GetValue() ); + gdcm_assert( seriesuid.GetValue() ); ret.first = seriesuid.GetValue(); ret.second = seriesuid.GetTag(); } @@ -143,13 +143,13 @@ DICOMDIRGenerator::MyPair DICOMDIRGenerator::GetReferenceValueForDirectoryType(s { Attribute <0x04,0x1511> sopuid; sopuid.Set( ds ); - assert( sopuid.GetValue() ); + gdcm_assert( sopuid.GetValue() ); ret.first = sopuid.GetValue(); ret.second = Tag(0x8,0x18); // watch out ! } else { - assert( 0 ); + gdcm_assert( 0 ); } return ret; } @@ -175,15 +175,15 @@ static Tag GetParentTag(Tag const &t) } else { - assert( 0 ); + gdcm_assert( 0 ); } return ret; } bool DICOMDIRGenerator::SeriesBelongToStudy(const char *seriesuid, const char *studyuid) { - assert( seriesuid ); - assert( studyuid ); + gdcm_assert( seriesuid ); + gdcm_assert( studyuid ); const Scanner &scanner = GetScanner(); Scanner::TagToValue const &ttv = scanner.GetMappingFromTagToValue(Tag(0x20,0xe), seriesuid); @@ -203,8 +203,8 @@ bool DICOMDIRGenerator::SeriesBelongToStudy(const char *seriesuid, const char *s bool DICOMDIRGenerator::ImageBelongToSeries(const char *sopuid, const char *seriesuid, Tag const &t1, Tag const &t2) { - assert( seriesuid ); - assert( sopuid ); + gdcm_assert( seriesuid ); + gdcm_assert( sopuid ); const Scanner &scanner = GetScanner(); Scanner::TagToValue const &ttv = scanner.GetMappingFromTagToValue(t1, sopuid); @@ -223,8 +223,8 @@ bool DICOMDIRGenerator::ImageBelongToSeries(const char *sopuid, const char *seri bool DICOMDIRGenerator::ImageBelongToSameSeries(const char *sopuid1, const char *sopuid2, Tag const &t) { - assert( sopuid1 ); - assert( sopuid2 ); + gdcm_assert( sopuid1 ); + gdcm_assert( sopuid2 ); const Scanner &scanner = GetScanner(); Scanner::TagToValue const &ttv1 = scanner.GetMappingFromTagToValue(t, sopuid1); @@ -246,8 +246,8 @@ bool DICOMDIRGenerator::ImageBelongToSameSeries(const char *sopuid1, const char { seriesuid2 = ttv2.find(tseriesuid)->second; } - assert( seriesuid1 ); - assert( seriesuid2 ); + gdcm_assert( seriesuid1 ); + gdcm_assert( seriesuid2 ); b = strcmp( seriesuid1, seriesuid2) == 0; return b; @@ -278,7 +278,7 @@ size_t DICOMDIRGenerator::FindLowerLevelDirectoryRecord( size_t item1, const cha refval1.first.c_str(), refval2.second, refval1.second); if( b ) return i; } - //assert( strncmp( lowerdirectorytype, directoryrecordtype.GetValue(), strlen( lowerdirectorytype ) ) != 0 ); + //gdcm_assert( strncmp( lowerdirectorytype, directoryrecordtype.GetValue(), strlen( lowerdirectorytype ) ) != 0 ); } // Not found @@ -313,7 +313,7 @@ size_t DICOMDIRGenerator::FindNextDirectoryRecord( size_t item1, const char *dir bool b = ImageBelongToSameSeries(refval1.first.c_str(), refval2.first.c_str(), refval1.second); if( b ) return i; } - //assert( strncmp( directorytype, directoryrecordtype.GetValue(), strlen( directorytype ) ) != 0 ); + //gdcm_assert( strncmp( directorytype, directoryrecordtype.GetValue(), strlen( directorytype ) ) != 0 ); } // Not found @@ -359,7 +359,7 @@ void SingleDataElementInserter(DataSet &ds, Scanner const & scanner) Scanner::ValuesType patientsnames = scanner.GetValues( patientsname.GetTag() ); #ifndef NDEBUG const unsigned int npatient = patientsnames.size(); - assert( npatient == 1 ); + gdcm_assert( npatient == 1 ); #endif Scanner::ValuesType::const_iterator it = patientsnames.begin(); @@ -682,7 +682,7 @@ bool DICOMDIRGenerator::AddImageDirectoryRecord() std::string::size_type l = relative.find( rd ); if( l != std::string::npos ) { - assert( l == 0 ); // FIXME + gdcm_assert( l == 0 ); // FIXME relative.replace( l, strlen_rd, "" ); fn = relative.c_str() + 1; } @@ -719,7 +719,7 @@ bool DICOMDIRGenerator::AddImageDirectoryRecord() Attribute<0x8,0x8> imagetype; //Scanner::ValuesType imagetypes = scanner.GetValues( imagetype.GetTag() ); //Scanner::ValuesType::const_iterator it = imagetypes.begin(); - //assert( imagetypes.size() == 1 ); + //gdcm_assert( imagetypes.size() == 1 ); //imagetype.SetNumberOfValues( 1 ); //imagetype.SetValue( it->c_str() ); //ds.Replace( imagetype.GetAsDataElement() ); @@ -861,7 +861,7 @@ bool DICOMDIRGenerator::Generate() std::string::size_type l = relative.find( rd ); if( l != std::string::npos ) { - assert( l == 0 ); // FIXME + gdcm_assert( l == 0 ); // FIXME relative.replace( l, strlen_rd, "" ); f = relative.c_str() + 1; } @@ -1046,7 +1046,7 @@ SequenceOfItems *DICOMDIRGenerator::GetDirectoryRecordSequence() const char *DICOMDIRGenerator::ComputeFileID(const char *input) { - assert( 0 ); (void)input; + gdcm_assert( 0 ); (void)input; return nullptr; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDPath.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDPath.cxx index 0666a741b7f..4b7d617be57 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDPath.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDPath.cxx @@ -48,7 +48,7 @@ static inline std::string tostring(uint16_t const val, int const width = 4) { static std::vector tag2strings(gdcm::Tag const &tag) { std::vector ret; - assert(tag.IsPublic() || tag.IsPrivateCreator() || tag.IsGroupLength()); + gdcm_assert(tag.IsPublic() || tag.IsPrivateCreator() || tag.IsGroupLength()); ret.push_back(tostring(tag.GetGroup())); ret.push_back(tostring(tag.GetElement())); return ret; @@ -86,7 +86,7 @@ static std::vector split_from_slash_separated( comps.push_back(sub); } else { #if 0 - assert(!comps.empty()); + gdcm_assert(!comps.empty()); std::string &last = comps.back(); last.push_back(separator); last.append(sub); @@ -122,7 +122,7 @@ bool DPath::ConstructFromString(const char *spath) { std::ostringstream os; std::vector::const_iterator it = comps.begin(); unsigned int index = 0; - assert(comps.size() >= 2); + gdcm_assert(comps.size() >= 2); // check root if (!it->empty()) return false; ++it; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDataSetHelper.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDataSetHelper.cxx index aebe1b8662b..c7969cc13ca 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDataSetHelper.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDataSetHelper.cxx @@ -143,7 +143,7 @@ VR DataSetHelper::ComputeVR(File const &file, DataSet const &ds, const Tag& tag) // In case of SAX parser, we would have had to process Pixel Representation already: Attribute<0x0028,0x0103> at; const Tag &pixelrep = at.GetTag(); - assert( pixelrep < t ); + gdcm_assert( pixelrep < t ); const DataSet &rootds = file.GetDataSet(); // FIXME // PhilipsWith15Overlays.dcm has a Private SQ with public elements such as @@ -153,7 +153,7 @@ VR DataSetHelper::ComputeVR(File const &file, DataSet const &ds, const Tag& tag) // FIXME: // gdcmDataExtra/gdcmSampleData/ImagesPapyrus/TestImages/wristb.pap // It's the contrary: root dataset does not have a Pixel Representation, but each SQ do... - //assert( rootds.FindDataElement( pixelrep ) || ds.FindDataElement( pixelrep ) ); + //gdcm_assert( rootds.FindDataElement( pixelrep ) || ds.FindDataElement( pixelrep ) ); if( ds.FindDataElement( pixelrep ) ) { at.SetFromDataElement( ds.GetDataElement( pixelrep ) ); @@ -168,7 +168,7 @@ VR DataSetHelper::ComputeVR(File const &file, DataSet const &ds, const Tag& tag) gdcmWarningMacro( "Unhandled" ); // Typical to PDF encapsulated with some illegal attribute vr = VR::INVALID; } - //assert( at.GetValue() == 0 || at.GetValue() == 1 ); + //gdcm_assert( at.GetValue() == 0 || at.GetValue() == 1 ); if( at.GetValue() == 1 ) { vr = VR::SS; @@ -197,14 +197,14 @@ VR DataSetHelper::ComputeVR(File const &file, DataSet const &ds, const Tag& tag) Tag bitsallocated(0x0028,0x0100); Tag channelminval(0x5400,0x0110); Tag channelmaxval(0x5400,0x0112); - //assert( ds.FindDataElement( pixeldata ) ); + //gdcm_assert( ds.FindDataElement( pixeldata ) ); int v = -1; if( waveformdata == t || waveformpaddingvalue == t ) { Tag waveformbitsallocated(0x5400,0x1004); // For Waveform Data: // (5400,1004) US 16 # 2,1 Waveform Bits Allocated - assert( ds.FindDataElement( waveformbitsallocated ) ); + gdcm_assert( ds.FindDataElement( waveformbitsallocated ) ); Attribute<0x5400,0x1004> at; at.SetFromDataElement( ds.GetDataElement( waveformbitsallocated ) ); v = at.GetValue(); @@ -213,7 +213,7 @@ VR DataSetHelper::ComputeVR(File const &file, DataSet const &ds, const Tag& tag) { // For Pixel Data: // if( !ds.FindDataElement( bitsallocated ) ) return VR::UN; - Attribute<0x0028,0x0100> at; + // Attribute<0x0028,0x0100> at; // at.SetFromDataElement( ds.GetDataElement( bitsallocated ) ); } (void)v; @@ -230,7 +230,7 @@ VR DataSetHelper::ComputeVR(File const &file, DataSet const &ds, const Tag& tag) } else if( waveformdata == t || waveformpaddingvalue == t ) { - //assert( v == 8 || v == 16 ); + //gdcm_assert( v == 8 || v == 16 ); vr = VR::OW; } else if ( t.IsGroupXX(audiodata) ) @@ -282,16 +282,16 @@ VR DataSetHelper::ComputeVR(File const &file, DataSet const &ds, const Tag& tag) // TODO need to treat US_SS_OW too // \postcondition: - assert( vr.IsVRFile() ); - assert( vr != VR::INVALID ); + gdcm_assert( vr.IsVRFile() ); + gdcm_assert( vr != VR::INVALID ); if( tag.IsGroupLength() ) { - assert( vr == VR::UL ); + gdcm_assert( vr == VR::UL ); } if( tag.IsPrivateCreator() ) { - assert( vr == VR::LO ); + gdcm_assert( vr == VR::LO ); } return vr; } @@ -301,7 +301,7 @@ VR DataSetHelper::ComputeVR(File const &file, DataSet const &ds, const Tag& tag) SequenceOfItems* DataSetHelper::ComputeSQFromByteValue(File const & file, DataSet const &ds, const Tag &tag) { const TransferSyntax &ts = file.GetHeader().GetDataSetTransferSyntax(); - assert( ts != TransferSyntax::DeflatedExplicitVRLittleEndian ); + gdcm_assert( ts != TransferSyntax::DeflatedExplicitVRLittleEndian ); const DataElement &de = ds.GetDataElement( tag ); if( de.IsEmpty() ) { @@ -319,15 +319,15 @@ SequenceOfItems* DataSetHelper::ComputeSQFromByteValue(File const & file, DataSe { if( ts.GetSwapCode() == SwapCode::BigEndian ) { - assert(0); + gdcm_assert(0); } else { if( ts.GetNegociatedType() == TransferSyntax::Implicit ) { - assert( de.GetVR() == VR::INVALID ); + gdcm_assert( de.GetVR() == VR::INVALID ); const ByteValue *bv = de.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); SequenceOfItems *sqi = new SequenceOfItems; sqi->SetLength( bv->GetLength() ); std::stringstream ss; @@ -337,9 +337,9 @@ SequenceOfItems* DataSetHelper::ComputeSQFromByteValue(File const & file, DataSe } else { - assert( de.GetVR() == VR::UN ); // cp 246, IVRLE SQ + gdcm_assert( de.GetVR() == VR::UN ); // cp 246, IVRLE SQ const ByteValue *bv = de.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); SequenceOfItems *sqi = new SequenceOfItems; sqi->SetLength( bv->GetLength() ); std::stringstream ss; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDictPrinter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDictPrinter.cxx index 5ec8cab61c8..6804f11e6f9 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDictPrinter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDictPrinter.cxx @@ -51,7 +51,7 @@ VM GuessVMType(DataElement const &de) } else { - assert( VR::IsASCII( vr ) || vr == VR::INVALID ); + gdcm_assert( VR::IsASCII( vr ) || vr == VR::INVALID ); switch(vr) { case VR::INVALID: @@ -75,7 +75,7 @@ VM GuessVMType(DataElement const &de) vm = VM::VM1; // why not ? if(!de.IsEmpty()) { - assert( bv && "not bv" ); + gdcm_assert( bv && "not bv" ); const char *array = bv->GetPointer(); size_t c = VM::GetNumberOfElementsFromArray(array, vl); vm = VM::GetVMTypeFromLength( c, 1 ); @@ -84,7 +84,7 @@ VM GuessVMType(DataElement const &de) break; default: vm = VM::VM0; - assert( 0 ); // Impossible happen ! (someone added new VR and forgot this switch) + gdcm_assert( 0 ); // Impossible happen ! (someone added new VR and forgot this switch) } } @@ -406,7 +406,7 @@ std::string GetVersion(std::string const &owner) // { // // HEY ! // std::cerr << "OWNER= \"" << p->owner << "\"" << std::endl; -// assert(0); +// gdcm_assert(0); // } //#endif //if( owner == p->owner ) @@ -449,7 +449,7 @@ void DictPrinter::PrintDataElement2(std::ostream& os, const DataSet &ds, const D const DictEntry &entry = dicts.GetDictEntry(t,owner); dict_vr = entry.GetVR(); - assert(t.GetElement() >= 0x0100 ); + gdcm_assert(t.GetElement() >= 0x0100 ); //owner = GetOwner(ds,de); //version = GetVersion(owner); @@ -475,7 +475,7 @@ void DictPrinter::PrintDataElement2(std::ostream& os, const DataSet &ds, const D os << "vr=\"" << pvr << "\" vm=\"" << vm << "\" "; if( t.IsPrivate() ) { - assert( owner && *owner ); + gdcm_assert( owner && *owner ); os << R"(name="?" owner=")" << owner << "\"/>\n"; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDirectionCosines.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDirectionCosines.cxx index 119a7b4a839..87a4beacc69 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDirectionCosines.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDirectionCosines.cxx @@ -73,7 +73,7 @@ bool DirectionCosines::IsValid() const void DirectionCosines::Cross(double z[3]) const { - //assert( Dot() == 0 ); + //gdcm_assert( Dot() == 0 ); const double *x = Values; const double *y = x+3; double Zx = x[1]*y[2] - x[2]*y[1]; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDirectoryHelper.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDirectoryHelper.cxx index 84f67ac24b9..0e1a11dc348 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDirectoryHelper.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmDirectoryHelper.cxx @@ -171,19 +171,87 @@ std::vector DirectoryHelper::LoadImageFromFiles(const std::string& inDi std::string DirectoryHelper::RetrieveSOPInstanceUIDFromZPosition(double inZPos, const std::vector& inDS) { - std::vector::const_iterator itor; - Tag thePosition(0x0020, 0x0032); - Tag theSOPInstanceUID(0x0008, 0x0018); - Tag theSpacingBetweenSlice(0x0018, 0x0088); - double interSlice = 0.01; - if (inDS.begin() != inDS.end() && inDS.begin()->FindDataElement(theSpacingBetweenSlice)) + std::string blank;//return only if there's a problem + + //Find z spacing + const Tag tipp(0x0020,0x0032); // Image Position (Patient) + const Tag tiop(0x0020,0x0037); // Image Orientation (Patient) + double normal[3]; + + //Compute the normal + if (inDS.begin() != inDS.end() && inDS.begin()->FindDataElement(tiop)) { - DataElement tmpDe = inDS.begin()->GetDataElement(theSpacingBetweenSlice); - Attribute<0x0018,0x0088> tmpAt; + DataElement tmpDe = inDS.begin()->GetDataElement(tiop); + Attribute<0x0020,0x0037> tmpAt; tmpAt.SetFromDataElement(tmpDe); - interSlice = fabs(tmpAt.GetValue())/2.0; + if (tmpAt.GetNumberOfValues() == 6) + { + normal[0] = tmpAt.GetValue(1)*tmpAt.GetValue(5) - tmpAt.GetValue(2)*tmpAt.GetValue(4); + normal[1] = tmpAt.GetValue(2)*tmpAt.GetValue(3) - tmpAt.GetValue(0)*tmpAt.GetValue(5); + normal[2] = tmpAt.GetValue(0)*tmpAt.GetValue(4) - tmpAt.GetValue(1)*tmpAt.GetValue(3); + } + else + { + gdcmDebugMacro( "No 6 values in tiop: " << tmpAt.GetNumberOfValues() ); + return blank; + } } - std::string blank;//return only if there's a problem + else + { + gdcmDebugMacro( "No tiop available in the first slice" ); + return blank; + } + + //Compute dist for the first 2 slices + double dist1 = 0; + std::vector::const_iterator itor = inDS.begin(); + if (itor != inDS.end() && itor->FindDataElement(tipp)) + { + DataElement tmpDe = itor->GetDataElement(tipp); + Attribute<0x0020,0x0032> tmpAt; + tmpAt.SetFromDataElement(tmpDe); + if (tmpAt.GetNumberOfValues() == 3) + { + for (int i = 0; i < 3; ++i) dist1 += normal[i]*tmpAt.GetValue(i); + } + else + { + gdcmDebugMacro( "No 3 values in tipp for the first slice: " << tmpAt.GetNumberOfValues() ); + return blank; + } + } + else + { + gdcmDebugMacro( "No tipp available in the first slice" ); + return blank; + } + double dist2 = 0; + itor++; + if (itor != inDS.end() && itor->FindDataElement(tipp)) + { + DataElement tmpDe = itor->GetDataElement(tipp); + Attribute<0x0020,0x0032> tmpAt; + tmpAt.SetFromDataElement(tmpDe); + if (tmpAt.GetNumberOfValues() == 3) + { + for (int i = 0; i < 3; ++i) dist2 += normal[i]*tmpAt.GetValue(i); + } + else + { + gdcmDebugMacro( "No 3 values in tipp for the first slice: " << tmpAt.GetNumberOfValues() ); + return blank; + } + } + else + { + gdcmDebugMacro( "No tipp available in the first slice" ); + return blank; + } + double interSlice = fabs(dist2 - dist1)/2.0; + + //Find the SOPInstanceUID + Tag thePosition(0x0020, 0x0032); + Tag theSOPInstanceUID(0x0008, 0x0018); for (itor = inDS.begin(); itor != inDS.end(); itor++) { if (itor->FindDataElement(thePosition)) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmEquipmentManufacturer.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmEquipmentManufacturer.cxx index 2ada1f9f1fc..6ffc0bbb5fb 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmEquipmentManufacturer.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmEquipmentManufacturer.cxx @@ -19,9 +19,9 @@ namespace gdcm { // FIXME: fuji and hitachi are the same now -static const char* TypeStrings[] = {"UNKNOWN", "FUJI", "GEMS", "HITACHI", - "KODAK", "MARCONI", "PMS", "SIEMENS", - "TOSHIBA", "AGFA", "SAMSUNG", "UIH"}; +static const char* TypeStrings[] = {"UNKNOWN", "AGFA", "FUJI", "GEMS", + "HITACHI", "KODAK", "MARCONI", "PMS", + "SAMSUNG", "SIEMENS", "TOSHIBA", "UIH"}; const char* EquipmentManufacturer::TypeToString(Type type) { return TypeStrings[type]; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmEquipmentManufacturer.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmEquipmentManufacturer.h index 2b6c78641d8..1c1194f98e7 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmEquipmentManufacturer.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmEquipmentManufacturer.h @@ -29,16 +29,16 @@ class GDCM_EXPORT EquipmentManufacturer { public: typedef enum { UNKNOWN = 0, + AGFA, FUJI, GEMS, HITACHI, KODAK, MARCONI, PMS, + SAMSUNG, SIEMENS, TOSHIBA, - AGFA, - SAMSUNG, UIH } Type; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileAnonymizer.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileAnonymizer.cxx index 3038cb19901..eb5e0dc97cb 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileAnonymizer.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileAnonymizer.cxx @@ -146,9 +146,9 @@ bool FileAnonymizer::ComputeReplaceTagPosition() will try very hard to decode it as SQ...which obviously will fail Instead do not support SQ at all here and document it should not be used for SQ */ - assert( !Internals->InputFilename.empty() ); + gdcm_assert( !Internals->InputFilename.empty() ); const char *filename = Internals->InputFilename.c_str(); - assert( filename ); + gdcm_assert( filename ); const bool inplace = file_exist(Internals->OutputFilename.c_str()); std::map::reverse_iterator rit = Internals->ReplaceTags.rbegin(); @@ -184,9 +184,9 @@ bool FileAnonymizer::ComputeReplaceTagPosition() pe.IsTagFound = true; pe.DE.SetVL( de.GetVL() ); // Length is not used, unless to check undefined flag pe.DE.SetVR( de.GetVR() ); - assert( pe.DE.GetVL().IsUndefined() == de.GetVL().IsUndefined() ); - assert( pe.DE.GetVR() == de.GetVR() ); - assert( pe.DE.GetTag() == de.GetTag() ); + gdcm_assert( pe.DE.GetVL().IsUndefined() == de.GetVL().IsUndefined() ); + gdcm_assert( pe.DE.GetVR() == de.GetVR() ); + gdcm_assert( pe.DE.GetTag() == de.GetTag() ); if( de.GetVL().IsUndefined() ) { // This is a SQ @@ -200,15 +200,15 @@ bool FileAnonymizer::ComputeReplaceTagPosition() gdcmErrorMacro( "inplace mode requires same length attribute" ); // TODO we could allow smaller size (and pad with space...) return false; } - assert( !de.GetVL().IsUndefined() ); + gdcm_assert( !de.GetVL().IsUndefined() ); pe.BeginPos -= de.GetVL(); pe.BeginPos -= 2 * de.GetVR().GetLength(); // (VR+) VL pe.BeginPos -= 4; // Tag - assert( (int)pe.EndPos == + gdcm_assert( (int)pe.EndPos == (int)pe.BeginPos + (int)de.GetVL() + 2 * de.GetVR().GetLength() + 4 ); } pe.DE.SetByteValue( valuereplace.c_str(), (uint32_t)valuereplace.size() ); - assert( pe.DE.GetVL() == valuereplace.size() ); + gdcm_assert( pe.DE.GetVL() == valuereplace.size() ); } else { @@ -221,7 +221,7 @@ bool FileAnonymizer::ComputeReplaceTagPosition() //FIXME, for some public element we could do something nicer than VR:UN pe.DE.SetVR( VR::UN ); pe.DE.SetByteValue( valuereplace.c_str(), (uint32_t)valuereplace.size() ); - assert( pe.DE.GetVL() == valuereplace.size() ); + gdcm_assert( pe.DE.GetVL() == valuereplace.size() ); } // We need to push_back outside of if() since Action:Replace @@ -235,9 +235,9 @@ bool FileAnonymizer::ComputeReplaceTagPosition() bool FileAnonymizer::ComputeRemoveTagPosition() { - assert( !Internals->InputFilename.empty() ); + gdcm_assert( !Internals->InputFilename.empty() ); const char *filename = Internals->InputFilename.c_str(); - assert( filename ); + gdcm_assert( filename ); const bool inplace = file_exist(Internals->OutputFilename.c_str()); if( inplace && !Internals->RemoveTags.empty()) { @@ -277,9 +277,9 @@ bool FileAnonymizer::ComputeRemoveTagPosition() pe.IsTagFound = true; pe.DE.SetVL( de.GetVL() ); // Length is not used, unless to check undefined flag pe.DE.SetVR( de.GetVR() ); - assert( pe.DE.GetVL().IsUndefined() == de.GetVL().IsUndefined() ); - assert( pe.DE.GetVR() == de.GetVR() ); - assert( pe.DE.GetTag() == de.GetTag() ); + gdcm_assert( pe.DE.GetVL().IsUndefined() == de.GetVL().IsUndefined() ); + gdcm_assert( pe.DE.GetVR() == de.GetVR() ); + gdcm_assert( pe.DE.GetTag() == de.GetTag() ); if( de.GetVL().IsUndefined() ) { // This is a SQ @@ -292,16 +292,16 @@ bool FileAnonymizer::ComputeRemoveTagPosition() { vl = de.GetLength(); } - assert( pe.BeginPos > vl ); + gdcm_assert( pe.BeginPos > vl ); pe.BeginPos -= vl; } else { - assert( !de.GetVL().IsUndefined() ); + gdcm_assert( !de.GetVL().IsUndefined() ); pe.BeginPos -= de.GetVL(); pe.BeginPos -= 2 * de.GetVR().GetLength(); // (VR+) VL pe.BeginPos -= 4; // Tag - assert( (int)pe.EndPos == + gdcm_assert( (int)pe.EndPos == (int)pe.BeginPos + (int)de.GetVL() + 2 * de.GetVR().GetLength() + 4 ); } Internals->PositionEmptyArray.push_back( pe ); @@ -320,9 +320,9 @@ bool FileAnonymizer::ComputeRemoveTagPosition() bool FileAnonymizer::ComputeEmptyTagPosition() { // FIXME we sometime empty, attributes that are already empty... - assert( !Internals->InputFilename.empty() ); + gdcm_assert( !Internals->InputFilename.empty() ); const char *filename = Internals->InputFilename.c_str(); - assert( filename ); + gdcm_assert( filename ); const bool inplace = file_exist(Internals->OutputFilename.c_str()); if( inplace && !Internals->EmptyTags.empty()) { @@ -362,9 +362,9 @@ bool FileAnonymizer::ComputeEmptyTagPosition() pe.IsTagFound = true; pe.DE.SetVL( de.GetVL() ); // Length is not used, unless to check undefined flag pe.DE.SetVR( de.GetVR() ); - assert( pe.DE.GetVL().IsUndefined() == de.GetVL().IsUndefined() ); - assert( pe.DE.GetVR() == de.GetVR() ); - assert( pe.DE.GetTag() == de.GetTag() ); + gdcm_assert( pe.DE.GetVL().IsUndefined() == de.GetVL().IsUndefined() ); + gdcm_assert( pe.DE.GetVR() == de.GetVR() ); + gdcm_assert( pe.DE.GetTag() == de.GetTag() ); if( de.GetVL().IsUndefined() ) { // This is a SQ @@ -377,7 +377,7 @@ bool FileAnonymizer::ComputeEmptyTagPosition() { vl = de.GetLength(); } - assert( pe.BeginPos > vl ); + gdcm_assert( pe.BeginPos > vl ); pe.BeginPos -= vl; pe.BeginPos += 4; // Tag if( ts.GetNegociatedType() == TransferSyntax::Implicit ) @@ -391,7 +391,7 @@ bool FileAnonymizer::ComputeEmptyTagPosition() } else { - assert( !de.GetVL().IsUndefined() ); + gdcm_assert( !de.GetVL().IsUndefined() ); pe.BeginPos -= de.GetVL(); if( ts.GetNegociatedType() == TransferSyntax::Implicit ) { @@ -400,7 +400,7 @@ bool FileAnonymizer::ComputeEmptyTagPosition() else { pe.BeginPos -= de.GetVR().GetLength(); - assert( (int)pe.EndPos == + gdcm_assert( (int)pe.EndPos == (int)pe.BeginPos + (int)de.GetVL() + de.GetVR().GetLength() ); } } @@ -489,7 +489,7 @@ bool FileAnonymizer::Write() } if( action == EMPTY ) { - assert( !inplace ); + gdcm_assert( !inplace ); // Create a 0 Value Length (VR+Tag was copied in previous loop) for( int i = 0; i < vrlen; ++i) { @@ -523,11 +523,11 @@ bool FileAnonymizer::Write() } } // Skip the Value - assert( is.good() ); + gdcm_assert( is.good() ); is.seekg( pe.EndPos ); - assert( is.good() ); + gdcm_assert( is.good() ); prev = is.tellg(); - assert( prev == pe.EndPos ); + gdcm_assert( prev == pe.EndPos ); } else { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileChangeTransferSyntax.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileChangeTransferSyntax.cxx index cfd62a65d4f..94dee12c309 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileChangeTransferSyntax.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileChangeTransferSyntax.cxx @@ -124,7 +124,7 @@ bool FileChangeTransferSyntax::Change() Internals->Progress = 0; bool b = Internals->IC->StartEncode(os); - assert( b ); + gdcm_assert(b); size_t len = 0; // actual size compressed: if( Internals->IC->IsRowEncoder() ) { @@ -145,7 +145,7 @@ bool FileChangeTransferSyntax::Change() for( unsigned int y = 0; y < dims[1]; ++y ) { is.read( data, datalen ); - assert( is.good() ); + gdcm_assert( is.good() ); b = Internals->IC->CleanupUnusedBits(data, datalen); if( !b ) return false; b = Internals->IC->AppendRowEncode(os, data, datalen); @@ -189,7 +189,7 @@ bool FileChangeTransferSyntax::Change() std::streampos start = os.tellp(); { is.read( data, datalen ); - assert( is.good() ); + gdcm_assert( is.good() ); b = Internals->IC->CleanupUnusedBits(data, datalen); if( !b ) return false; b = Internals->IC->AppendFrameEncode(os, data, datalen); @@ -221,7 +221,7 @@ bool FileChangeTransferSyntax::Change() return false; } b = Internals->IC->StopEncode(os); - assert( b ); + gdcm_assert(b); const Tag seqDelItem(0xfffe,0xe0dd); seqDelItem.Write(os); @@ -295,7 +295,7 @@ void FileChangeTransferSyntax::SetTransferSyntax( TransferSyntax const & ts ) Internals->IC = codecs[i]->Clone(); } } - assert( Internals->TS ); + gdcm_assert( Internals->TS ); } ImageCodec * FileChangeTransferSyntax::GetCodec() @@ -454,6 +454,7 @@ bool FileChangeTransferSyntax::InitializeCopy() ISO_14495_1 = JPEG-LS Near-lossless Compression ISO_15444_1 = JPEG 2000 Irreversible Compression ISO_13818_2 = MPEG2 Compression + ISO_15444_15 = High-Throughput JPEG 2000 Irreversible Compression */ Attribute<0x0028,0x2114> at3; const TransferSyntax ts_orig = Internals->TS; @@ -467,6 +468,14 @@ bool FileChangeTransferSyntax::InitializeCopy() static const CSComp newvalues2[] = {"ISO_14495_1"}; at3.SetValues( newvalues2, 1 ); } + else if ( + ts_orig == TransferSyntax::HTJ2KLossless || + ts_orig == TransferSyntax::HTJ2KRPCLLossless || + ts_orig == TransferSyntax::HTJ2K ) + { + static const CSComp newvalues2[] = {"ISO_15444_15"}; + at3.SetValues( newvalues2, 1 ); + } else if ( ts_orig == TransferSyntax::JPEGBaselineProcess1 || ts_orig == TransferSyntax::JPEGExtendedProcess2_4 || diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileDecompressLookupTable.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileDecompressLookupTable.cxx index 54b51ea4655..6900d74eca4 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileDecompressLookupTable.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileDecompressLookupTable.cxx @@ -28,8 +28,8 @@ bool FileDecompressLookupTable::Change() if ( pi == PhotometricInterpretation::PALETTE_COLOR ) { const LookupTable &lut = PixelData->GetLUT(); - assert( lut.Initialized() ); -// assert( (pf.GetBitsAllocated() == 8 && pf.GetPixelRepresentation() == 0) + gdcm_assert( lut.Initialized() ); +// gdcm_assert( (pf.GetBitsAllocated() == 8 && pf.GetPixelRepresentation() == 0) // || (pf.GetBitsAllocated() == 16 && pf.GetPixelRepresentation() == 0) ); // lut descriptor: // (0028,1101) US 256\0\16 # 6, 3 RedPaletteColorLookupTableDescriptor diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileExplicitFilter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileExplicitFilter.cxx index 726f43a6e7b..e094e1e5e31 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileExplicitFilter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileExplicitFilter.cxx @@ -92,10 +92,10 @@ bool FileExplicitFilter::ProcessDataSet(DataSet &ds, Dicts const & dicts) const DictEntry &entry = dicts.GetDictEntry(t,owner); const VR &vr = entry.GetVR(); - //assert( de.GetVR() == VR::INVALID ); + //gdcm_assert( de.GetVR() == VR::INVALID ); VR cvr = DataSetHelper::ComputeVR(*F,ds, t); VR oldvr = de.GetVR(); - if( cvr == VR::SQ ) { assert( oldvr == VR::SQ || oldvr == VR::UN || oldvr == VR::INVALID || oldvr == VR::OB ); } + if( cvr == VR::SQ ) { gdcm_assert( oldvr == VR::SQ || oldvr == VR::UN || oldvr == VR::INVALID || oldvr == VR::OB ); } //SequenceOfItems *sqi = de.GetSequenceOfItems(); //SequenceOfItems *sqi = dynamic_cast(&de.GetValue()); SmartPointer sqi = nullptr; @@ -115,15 +115,15 @@ bool FileExplicitFilter::ProcessDataSet(DataSet &ds, Dicts const & dicts) if( de.GetByteValue() && !sqi ) { // all set - //assert( cvr != VR::SQ /*&& cvr != VR::UN*/ ); - assert( cvr != VR::INVALID ); + //gdcm_assert( cvr != VR::SQ /*&& cvr != VR::UN*/ ); + gdcm_assert( cvr != VR::INVALID ); if( cvr != VR::UN ) { // about to change , make some paranoid test: - //assert( cvr.Compatible( oldvr ) ); // LT != LO but there are somewhat compatible + //gdcm_assert( cvr.Compatible( oldvr ) ); // LT != LO but there are somewhat compatible if( cvr & VR::VRASCII ) { - //assert( oldvr & VR::VRASCII || oldvr == VR::INVALID || oldvr == VR::UN ); + //gdcm_assert( oldvr & VR::VRASCII || oldvr == VR::INVALID || oldvr == VR::UN ); // gdcm-JPEG-Extended.dcm has a couple of VR::OB private field // is this a good idea to change them to an ASCII when we know this might not work ? if( !(oldvr & VR::VRASCII || oldvr == VR::INVALID || oldvr == VR::UN || oldvr == VR::OB) ) @@ -143,7 +143,7 @@ bool FileExplicitFilter::ProcessDataSet(DataSet &ds, Dicts const & dicts) } else { - assert( 0 ); // programmer error + gdcm_assert( 0 ); // programmer error } // let's do one more check we are going to make this attribute explicit VR, there is @@ -157,7 +157,7 @@ bool FileExplicitFilter::ProcessDataSet(DataSet &ds, Dicts const & dicts) } else if( sqi ) { - assert( cvr == VR::SQ || cvr == VR::UN ); + gdcm_assert( cvr == VR::SQ || cvr == VR::UN ); de.SetVR( VR::SQ ); if( de.GetByteValue() ) { @@ -165,7 +165,7 @@ bool FileExplicitFilter::ProcessDataSet(DataSet &ds, Dicts const & dicts) //de.SetVL( sqi->ComputeLength() ); } de.SetVLToUndefined(); - assert( sqi->GetLength().IsUndefined() ); + gdcm_assert( sqi->GetLength().IsUndefined() ); // recursive SequenceOfItems::ItemVector::iterator sit = sqi->Items.begin(); for(; sit != sqi->Items.end(); ++sit) @@ -181,7 +181,7 @@ bool FileExplicitFilter::ProcessDataSet(DataSet &ds, Dicts const & dicts) } else if( de.GetSequenceOfFragments() ) { - assert( cvr & VR::OB ); + gdcm_assert( cvr & VR::OB ); } else { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileStreamer.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileStreamer.cxx index c35cc716dba..c5a4d455b5f 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileStreamer.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmFileStreamer.cxx @@ -105,7 +105,7 @@ static bool prepare_file( FILE * pFile, const off64_t offset, const off64_t insl char buffer[BUFFERSIZE]; struct stat sb; - assert( pFile ); + gdcm_assert( pFile ); int fd = fileno( pFile ); if (fstat(fd, &sb) == 0) { @@ -126,7 +126,7 @@ static bool prepare_file( FILE * pFile, const off64_t offset, const off64_t insl { return false; } - assert( wr_off < rd_off ); + gdcm_assert( wr_off < rd_off ); if( FSeeko(pFile, wr_off, SEEK_SET) ) { return false; @@ -138,7 +138,7 @@ static bool prepare_file( FILE * pFile, const off64_t offset, const off64_t insl bytes_to_move -= bytes_this_time; read_start_offset += bytes_this_time; } - assert( read_start_offset == sb.st_size ); + gdcm_assert( read_start_offset == sb.st_size ); if( !FTruncate( fd, sb.st_size + inslen ) ) { return false; @@ -147,7 +147,7 @@ static bool prepare_file( FILE * pFile, const off64_t offset, const off64_t insl else { #if 0 - assert(sb.st_size >= offset); + gdcm_assert(sb.st_size >= offset); #endif if (sb.st_size > offset) { @@ -157,7 +157,7 @@ static bool prepare_file( FILE * pFile, const off64_t offset, const off64_t insl { const size_t bytes_this_time = static_cast(std::min((off64_t)BUFFERSIZE, bytes_to_move)); const off64_t rd_off = read_end_offset - bytes_this_time; - assert( (off64_t)rd_off >= offset ); + gdcm_assert( (off64_t)rd_off >= offset ); const off64_t wr_off = rd_off + inslen; if( FSeeko(pFile, rd_off, SEEK_SET) ) { @@ -178,7 +178,7 @@ static bool prepare_file( FILE * pFile, const off64_t offset, const off64_t insl bytes_to_move -= bytes_this_time; read_end_offset = rd_off; } - assert( read_end_offset == offset ); + gdcm_assert( read_end_offset == offset ); } } // easy case when sb.st_size == offset ... @@ -269,7 +269,7 @@ class FileStreamerInternals { Self->InvokeEvent( StartEvent() ); const char *outfilename = OutFilename.c_str(); - assert( outfilename ); + gdcm_assert( outfilename ); actualde = 0; { std::ifstream is( outfilename, std::ios::binary ); @@ -305,7 +305,7 @@ class FileStreamerInternals { // if you trigger this assertion, this means we have been allocating // memory for an element when not needed. - assert( (de.GetByteValue() && de.GetByteValue()->GetPointer() == nullptr) || de.GetSequenceOfFragments() ); + gdcm_assert( (de.GetByteValue() && de.GetByteValue()->GetPointer() == nullptr) || de.GetSequenceOfFragments() ); } actualde = de.GetVL() + 2 * de.GetVR().GetLength() + 4; thepos -= actualde; @@ -315,9 +315,9 @@ class FileStreamerInternals // no attribute found, easy case ! } } - assert( pFile == nullptr ); + gdcm_assert( pFile == nullptr ); pFile = fopen(outfilename, "r+b"); - assert( pFile ); + gdcm_assert( pFile ); CurrentDataLenth = 0; return true; } @@ -330,11 +330,11 @@ class FileStreamerInternals if( TS.GetNegociatedType() == TransferSyntax::Explicit ) dicomlen += 4; off64_t newlen = len; - assert( (size_t)newlen == len ); + gdcm_assert( (size_t)newlen == len ); newlen += dicomlen; newlen -= actualde; off64_t plength = newlen; - assert( ReservedDataLength >= 0 ); + gdcm_assert( ReservedDataLength >= 0 ); if( ReservedDataLength ) { if( (newlen + ReservedDataLength) >= (off64_t)len ) @@ -346,7 +346,7 @@ class FileStreamerInternals plength = newlen + ReservedDataLength - len; } ReservedDataLength -= len; - assert( ReservedDataLength >= 0 ); + gdcm_assert( ReservedDataLength >= 0 ); } //if( !prepare_file( pFile, (off64_t)thepos + actualde, newlen ) ) if( !prepare_file( pFile, (off64_t)thepos + actualde, plength ) ) @@ -357,14 +357,14 @@ class FileStreamerInternals const Tag tag = t; const VL vl = 0; // will be updated later (UpdateDataElement) const size_t ddsize = WriteHelper( thepos, tag, vl ); - assert( ddsize == dicomlen ); (void)ddsize; + gdcm_assert( ddsize == dicomlen ); (void)ddsize; thepos += dicomlen; } else { - assert( pFile ); + gdcm_assert( pFile ); const off64_t curpos = FTello(pFile); - assert( curpos == thepos ); + gdcm_assert( curpos == thepos ); if( ReservedDataLength >= (off64_t)len ) { // simply update remaining reserved buffer: @@ -373,7 +373,7 @@ class FileStreamerInternals else { const off64_t plength = len - ReservedDataLength; - assert( plength >= 0 ); + gdcm_assert( plength >= 0 ); if( !prepare_file( pFile, (off64_t)curpos, plength) ) { return false; @@ -383,18 +383,18 @@ class FileStreamerInternals FSeeko(pFile, curpos, SEEK_SET); } - assert( ReservedDataLength >= 0 ); + gdcm_assert( ReservedDataLength >= 0 ); fwrite(data, 1, len, pFile); thepos += len; CurrentDataLenth += len; - assert( CurrentDataLenth < std::numeric_limits::max() ); + gdcm_assert( CurrentDataLenth < std::numeric_limits::max() ); return true; } bool StopDataElement( const Tag & t ) { // Update DataElement: const size_t currentdatalenth = CurrentDataLenth; - assert( ReservedDataLength >= 0); + gdcm_assert( ReservedDataLength >= 0); //const off64_t refpos = FTello(pFile); if( !UpdateDataElement( t ) ) { @@ -409,7 +409,7 @@ class FileStreamerInternals } ReservedDataLength = 0; } - assert( ReservedDataLength == 0); + gdcm_assert( ReservedDataLength == 0); fclose(pFile); pFile = nullptr; // Do some extra work: @@ -488,7 +488,7 @@ class FileStreamerInternals // mechanism we can simply append const char *outfilename = OutFilename.c_str(); DataElement private_creator = ori_pt.GetAsDataElement(); - assert( outfilename ); + gdcm_assert( outfilename ); Tag curtag = ori_pt; { bool cont = false; @@ -534,7 +534,7 @@ class FileStreamerInternals std::string dicomdata; { std::stringstream ss; - assert( private_creator.GetTag().IsPrivateCreator() ); + gdcm_assert( private_creator.GetTag().IsPrivateCreator() ); if( TS.GetSwapCode() == SwapCode::BigEndian ) { if( TS.GetNegociatedType() == TransferSyntax::Explicit ) @@ -565,7 +565,7 @@ class FileStreamerInternals { std::set tagset; Tag prev = private_creator.GetTag(); - //assert( prev.GetElement() ); + //gdcm_assert( prev.GetElement() ); prev.SetElement( (uint16_t)(prev.GetElement() - 0x1) ); tagset.insert( prev ); @@ -583,9 +583,9 @@ class FileStreamerInternals } const size_t pclen = dicomdata.size(); - assert( pFile == nullptr ); + gdcm_assert( pFile == nullptr ); pFile = fopen(outfilename, "r+b"); - assert( pFile ); + gdcm_assert( pFile ); if( !prepare_file( pFile, (off64_t)thepcpos, pclen ) ) { @@ -621,22 +621,22 @@ class FileStreamerInternals { Self->InvokeEvent( IterationEvent() ); const size_t len_this_time = std::min(MaxSizeDE - CurrentDataLenth, len_to_move); - assert( len_this_time % 2 == 0 ); + gdcm_assert( len_this_time % 2 == 0 ); if( !AppendToDataElement( CurrentGroupTag, data, len_this_time ) ) { return false; } - assert( CurrentDataLenth <= MaxSizeDE ); + gdcm_assert( CurrentDataLenth <= MaxSizeDE ); len_to_move -= len_this_time; if( CurrentDataLenth == MaxSizeDE ) { // flush - assert( CurrentDataLenth % 2 == 0 ); + gdcm_assert( CurrentDataLenth % 2 == 0 ); if( !UpdateDataElement( CurrentGroupTag ) ) { return false; } - assert( CurrentDataLenth == 0 ); + gdcm_assert( CurrentDataLenth == 0 ); CurrentGroupTag.SetElement( (uint16_t)(CurrentGroupTag.GetElement() + 1) ); const int lowbits = CurrentGroupTag.GetElement() & 0x00ff; if( lowbits == 0 ) @@ -701,10 +701,10 @@ class FileStreamerInternals FSeeko(pFile, curpos, SEEK_SET); int ret = fputc(0, pFile); // Set to NULL padding ? thepos += 1; - assert( ret != EOF ); (void)ret; + gdcm_assert( ret != EOF ); (void)ret; CurrentDataLenth += 1; } - assert( CurrentDataLenth % 2 == 0 ); + gdcm_assert( CurrentDataLenth % 2 == 0 ); off64_t vlpos = thepos; vlpos -= CurrentDataLenth; vlpos -= 4; // VL @@ -801,8 +801,8 @@ bool FileStreamer::InitializeCopy() } else { - assert( filename ); - assert( outfilename ); + gdcm_assert( filename ); + gdcm_assert( outfilename ); std::ifstream is( filename, std::ios::binary ); if( !is.good() ) return false; if( strcmp( filename, outfilename ) != 0 ) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIPPSorter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIPPSorter.cxx index d811c5975ae..4c02ca03900 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIPPSorter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIPPSorter.cxx @@ -255,7 +255,7 @@ bool IPPSorter::Sort(std::vector const & filenames) } } } - assert( !sorted.empty() ); + gdcm_assert( !sorted.empty() ); { SortedFilenames::const_iterator it2 = sorted.begin(); double prev = it2->first; @@ -307,7 +307,7 @@ bool IPPSorter::Sort(std::vector const & filenames) } gdcmDebugMacro( os.str() ); } - assert( spacingisgood == false || (ComputeZSpacing ? (ZSpacing > ZTolerance && ZTolerance > 0) : ZTolerance > 0) ); + gdcm_assert( spacingisgood == false || (ComputeZSpacing ? (ZSpacing > ZTolerance && ZTolerance > 0) : ZTolerance > 0) ); } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIconImage.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIconImage.cxx index 7623a92ee12..41edeac76a2 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIconImage.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIconImage.cxx @@ -53,7 +53,7 @@ IconImage::~IconImage() {} void IconImage::SetDimension(unsigned int idx, unsigned int dim) { - assert( idx < NumberOfDimensions ); + gdcm_assert( idx < NumberOfDimensions ); Dimensions.resize( NumberOfDimensions ); // Can dim be 0 ?? Dimensions[idx] = dim; @@ -97,9 +97,9 @@ bool IconImage::GetBuffer(char *buffer) const buffer = 0; return false; } - assert( bv ); + gdcm_assert( bv ); RAWCodec codec; - //assert( GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME2 ); + //gdcm_assert( GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME2 ); //codec.SetPhotometricInterpretation( GetPhotometricInterpretation() ); if( GetPhotometricInterpretation() != PhotometricInterpretation::MONOCHROME2 ) { @@ -110,9 +110,9 @@ bool IconImage::GetBuffer(char *buffer) const codec.SetPlanarConfiguration( 0 ); DataElement out; bool r = codec.Decode(PixelData, out); - assert( r ); + gdcm_assert( r ); const ByteValue *outbv = out.GetByteValue(); - assert( outbv ); + gdcm_assert( outbv ); //unsigned long check = outbv->GetLength(); // FIXME memcpy(buffer, outbv->GetPointer(), outbv->GetLength() ); // FIXME return r; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIconImageFilter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIconImageFilter.cxx index 2b7211b25ae..482a9e9a741 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIconImageFilter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIconImageFilter.cxx @@ -100,7 +100,7 @@ void IconImageFilter::ExtractIconImages() pixeldata.SetPixelFormat( pf ); // D 0028|0004 [CS] [Photometric Interpretation] [MONOCHROME2 ] const Tag tphotometricinterpretation(0x0028, 0x0004); - assert( ds.FindDataElement( tphotometricinterpretation ) ); + gdcm_assert( ds.FindDataElement( tphotometricinterpretation ) ); const ByteValue *photometricinterpretation = ds.GetDataElement( tphotometricinterpretation ).GetByteValue(); std::string photometricinterpretation_str( @@ -109,7 +109,7 @@ void IconImageFilter::ExtractIconImages() PhotometricInterpretation pi( PhotometricInterpretation::GetPIType( photometricinterpretation_str.c_str())); - assert( pi != PhotometricInterpretation::UNKNOWN); + gdcm_assert( pi != PhotometricInterpretation::UNKNOWN); pixeldata.SetPhotometricInterpretation( pi ); // @@ -151,29 +151,29 @@ void IconImageFilter::ExtractIconImages() if( ds.FindDataElement( tlut ) ) { const ByteValue *lut_raw = ds.GetDataElement( tlut ).GetByteValue(); - assert( lut_raw ); + gdcm_assert( lut_raw ); // LookupTableType::RED == 0 lut->SetLUT( LookupTable::LookupTableType(i), (const unsigned char*)lut_raw->GetPointer(), lut_raw->GetLength() ); - //assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); + //gdcm_assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); //unsigned long check = // (el_us3.GetValue(0) ? el_us3.GetValue(0) : 65536) // * el_us3.GetValue(2) / 8; - //assert( check == lut_raw->GetLength() ); (void)check; + //gdcm_assert( check == lut_raw->GetLength() ); (void)check; } else if( ds.FindDataElement( seglut ) ) { const ByteValue *lut_raw = ds.GetDataElement( seglut ).GetByteValue(); - assert( lut_raw ); + gdcm_assert( lut_raw ); lut->SetLUT( LookupTable::LookupTableType(i), (const unsigned char*)lut_raw->GetPointer(), lut_raw->GetLength() ); - //assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); + //gdcm_assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); //unsigned long check = // (el_us3.GetValue(0) ? el_us3.GetValue(0) : 65536) // * el_us3.GetValue(2) / 8; - //assert( check == lut_raw->GetLength() ); (void)check; + //gdcm_assert( check == lut_raw->GetLength() ); (void)check; } else { @@ -216,7 +216,7 @@ void IconImageFilter::ExtractIconImages() //const SequenceOfItems* sq = iconimagesq.GetSequenceOfItems(); SmartPointer sq = iconimagesq.GetValueAsSQ(); // Is SQ empty ? - assert( sq ); + gdcm_assert( sq ); if( !sq ) return; SmartPointer< IconImage > si1 = new IconImage; IconImage &pixeldata = *si1; @@ -279,7 +279,7 @@ void IconImageFilter::ExtractIconImages() pixeldata.SetPixelFormat( pf1 ); // D 0028|0004 [CS] [Photometric Interpretation] [MONOCHROME2 ] const Tag tphotometricinterpretation(0x0028, 0x0004); - assert( ds.FindDataElement( tphotometricinterpretation ) ); + gdcm_assert( ds.FindDataElement( tphotometricinterpretation ) ); const ByteValue *photometricinterpretation = ds.GetDataElement( tphotometricinterpretation ).GetByteValue(); std::string photometricinterpretation_str( photometricinterpretation->GetPointer(), @@ -287,10 +287,10 @@ void IconImageFilter::ExtractIconImages() PhotometricInterpretation pi( PhotometricInterpretation::GetPIType( photometricinterpretation_str.c_str())); - assert( pi != PhotometricInterpretation::UNKNOWN); + gdcm_assert( pi != PhotometricInterpretation::UNKNOWN); pixeldata.SetPhotometricInterpretation( pi ); const Tag tpixeldata = Tag(0x7fe0, 0x0010); - assert( ds.FindDataElement( tpixeldata ) ); + gdcm_assert( ds.FindDataElement( tpixeldata ) ); { const DataElement& de = ds.GetDataElement( tpixeldata ); #if 0 @@ -319,7 +319,7 @@ void IconImageFilter::ExtractIconImages() #if 1 std::istringstream is; const ByteValue *bv = de.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); is.str( std::string( bv->GetPointer(), bv->GetLength() ) ); TransferSyntax jpegts; JPEGCodec jpeg; @@ -327,7 +327,7 @@ void IconImageFilter::ExtractIconImages() bool b = jpeg.GetHeaderInfo( is, jpegts ); if( !b ) { - assert( 0 ); + gdcm_assert( 0 ); } //jpeg.GetPixelFormat().Print (std::cout); pixeldata.SetPixelFormat( jpeg.GetPixelFormat() ); @@ -353,7 +353,7 @@ void IconImageFilter::ExtractIconImages() //const SequenceOfItems* sq = iconimagesq.GetSequenceOfItems(); SmartPointer sq = iconimagesq.GetValueAsSQ(); // Is SQ empty ? - assert( sq ); + gdcm_assert( sq ); if( !sq ) return; SmartPointer< IconImage > si1 = new IconImage; @@ -417,7 +417,7 @@ void IconImageFilter::ExtractIconImages() pixeldata.SetPixelFormat( pf ); // D 0028|0004 [CS] [Photometric Interpretation] [MONOCHROME2 ] const Tag tphotometricinterpretation(0x0028, 0x0004); - assert( ds.FindDataElement( tphotometricinterpretation ) ); + gdcm_assert( ds.FindDataElement( tphotometricinterpretation ) ); const ByteValue *photometricinterpretation = ds.GetDataElement( tphotometricinterpretation ).GetByteValue(); std::string photometricinterpretation_str( photometricinterpretation->GetPointer(), @@ -425,11 +425,11 @@ void IconImageFilter::ExtractIconImages() PhotometricInterpretation pi( PhotometricInterpretation::GetPIType( photometricinterpretation_str.c_str())); - assert( pi != PhotometricInterpretation::UNKNOWN); + gdcm_assert( pi != PhotometricInterpretation::UNKNOWN); pixeldata.SetPhotometricInterpretation( pi ); //const Tag tpixeldata = Tag(0x7fe0, 0x0010); const PrivateTag tpixeldata(0x6003,0x0011,"GEMS_Ultrasound_ImageGroup_001"); - assert( ds.FindDataElement( tpixeldata ) ); + gdcm_assert( ds.FindDataElement( tpixeldata ) ); { const DataElement& de = ds.GetDataElement( tpixeldata ); pixeldata.SetDataElement( de ); @@ -519,7 +519,7 @@ void IconImageFilter::ExtractVeproIconImages() dims[0] = data.Width; dims[1] = data.Height; - assert( dims[0] * dims[1] == len - sizeof(data) - offset ); + gdcm_assert( dims[0] * dims[1] == len - sizeof(data) - offset ); DataElement pd; pd.SetByteValue( raw + offset, (uint32_t)(len - sizeof(data) - offset) ); @@ -555,7 +555,7 @@ unsigned int IconImageFilter::GetNumberOfIconImages() const IconImage& IconImageFilter::GetIconImage( unsigned int i ) const { - assert( i < Internals->icons.size() ); + gdcm_assert( i < Internals->icons.size() ); return *Internals->icons[i]; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIconImageGenerator.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIconImageGenerator.cxx index 496979d04c4..78455c878c7 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIconImageGenerator.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmIconImageGenerator.cxx @@ -140,7 +140,7 @@ Retrieved from: http://en.literateprograms.org/Median_cut_algorithm_(C_Plus_Plus Block::Block(Point* pts, std::ptrdiff_t ptslen) { - assert( ptslen > 0 ); + gdcm_assert( ptslen > 0 ); this->points = pts; this->pointsLength = (int)ptslen; for(int i=0; i < NUM_DIMENSIONS; i++) @@ -207,16 +207,16 @@ Retrieved from: http://en.literateprograms.org/Median_cut_algorithm_(C_Plus_Plus std::list medianCut(DataElement const &PixelData, int numPoints, unsigned int desiredSize, std::vector & outputimage ) { - assert( numPoints > 0 ); + gdcm_assert( numPoints > 0 ); //Point* Points = (Point*)malloc(sizeof(Point) * numPoints); Point* Points = new Point[numPoints]; - assert( Points ); + gdcm_assert( Points ); const ByteValue *bv = PixelData.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); const unsigned char *inbuffer = (const unsigned char*)bv->GetPointer(); - assert( inbuffer ); + gdcm_assert( inbuffer ); size_t bvlen = bv->GetLength(); (void)bvlen; - assert( bvlen == (size_t) numPoints * 3 ); // only 8bits RGB please + gdcm_assert( bvlen == (size_t) numPoints * 3 ); // only 8bits RGB please for(int i = 0; i < numPoints; i++) { #if 0 @@ -289,19 +289,19 @@ Retrieved from: http://en.literateprograms.org/Median_cut_algorithm_(C_Plus_Plus //int index = std::distance(s.begin(), it.first); size_t index = result.size(); - assert( index <= 256 ); + gdcm_assert( index <= 256 ); for(int i = 0; i < numPoints; i++) { const unsigned char *currentcolor = inbuffer + 3 * i; for(size_t j = 0; j < (size_t)block.numPoints(); j++) { - assert( currentcolor < inbuffer + bvlen ); - assert( currentcolor + 3 <= inbuffer + bvlen ); + gdcm_assert( currentcolor < inbuffer + bvlen ); + gdcm_assert( currentcolor + 3 <= inbuffer + bvlen ); if( std::equal( currentcolor, currentcolor + 3, points[j].x ) ) { - //assert( outputimage[i] == 0 ); - assert( index > 0 ); + //gdcm_assert( outputimage[i] == 0 ); + gdcm_assert( index > 0 ); outputimage[i] = (unsigned char)(index - 1); } } @@ -317,7 +317,7 @@ Retrieved from: http://en.literateprograms.org/Median_cut_algorithm_(C_Plus_Plus // Create LUT with a maximum number of color equal to \param maxcolor void IconImageGenerator::BuildLUT( Bitmap & bitmap, unsigned int maxcolor ) { - assert( Internals->ConvertRGBToPaletteColor ); + gdcm_assert( Internals->ConvertRGBToPaletteColor ); using namespace quantization; const unsigned int *dims = bitmap.GetDimensions(); unsigned int numPoints = dims[0]*dims[1]; @@ -349,7 +349,7 @@ void IconImageGenerator::BuildLUT( Bitmap & bitmap, unsigned int maxcolor ) } bitmap.GetDataElement().SetByteValue( (char*)indeximage.data(), (uint32_t)indeximage.size() ); - assert( lut.Initialized() ); + gdcm_assert( lut.Initialized() ); } void IconImageGenerator::SetOutsideValuePixel(double v) @@ -381,9 +381,9 @@ void IconImageGenerator::SetPixelMinMax(double min, double max) template void ComputeMinMax( const TPixelType *p, size_t npixels , double & min, double &max, double discardvalue) { - assert( npixels ); + gdcm_assert( npixels ); const TPixelType discard = (TPixelType)discardvalue; - assert( (double)discard == discardvalue ); + gdcm_assert( (double)discard == discardvalue ); TPixelType lmin = std::numeric_limits< TPixelType>::max(); TPixelType lmax = std::numeric_limits< TPixelType>::min(); for( size_t i = 0; i < npixels; ++i ) @@ -397,8 +397,8 @@ void ComputeMinMax( const TPixelType *p, size_t npixels , double & min, double & lmax = p[i]; } } - //assert( lmin != std::numeric_limits< TPixelType>::max() ); - //assert( lmax != std::numeric_limits< TPixelType>::min() ); + //gdcm_assert( lmin != std::numeric_limits< TPixelType>::max() ); + //gdcm_assert( lmax != std::numeric_limits< TPixelType>::min() ); // what if lmin == lmax == 0 for example: // let's fake a slightly different min/max found: @@ -407,7 +407,7 @@ void ComputeMinMax( const TPixelType *p, size_t npixels , double & min, double & if( lmax == std::numeric_limits::max() ) { lmin--; - assert( lmin + 1 > lmin ); + gdcm_assert( lmin + 1 > lmin ); } else { @@ -422,7 +422,7 @@ void ComputeMinMax( const TPixelType *p, size_t npixels , double & min, double & template void ComputeMinMax( const TPixelType *p, size_t npixels , double & min, double &max) { - assert( npixels ); + gdcm_assert( npixels ); TPixelType lmin = std::numeric_limits< TPixelType>::max(); TPixelType lmax = std::numeric_limits< TPixelType>::min(); for( size_t i = 0; i < npixels; ++i ) @@ -436,8 +436,8 @@ void ComputeMinMax( const TPixelType *p, size_t npixels , double & min, double & lmax = p[i]; } } - //assert( lmin != std::numeric_limits< TPixelType>::max() ); - //assert( lmax != std::numeric_limits< TPixelType>::min() ); + //gdcm_assert( lmin != std::numeric_limits< TPixelType>::max() ); + //gdcm_assert( lmax != std::numeric_limits< TPixelType>::min() ); // what if lmin == lmax == 0 for example: // let's fake a slightly different min/max found: @@ -446,7 +446,7 @@ void ComputeMinMax( const TPixelType *p, size_t npixels , double & min, double & if( lmax == std::numeric_limits::max() ) { lmin--; - assert( lmin + 1 > lmin ); + gdcm_assert( lmin + 1 > lmin ); } else { @@ -521,7 +521,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall else { I->SetPhotometricInterpretation( P->GetPhotometricInterpretation() ); - assert( I->GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME1 + gdcm_assert( I->GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME1 || I->GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME2 || I->GetPhotometricInterpretation() == PhotometricInterpretation::PALETTE_COLOR ); if( !Internals->ConvertRGBToPaletteColor @@ -531,7 +531,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall } } - assert( I->GetPlanarConfiguration() == 0 ); + gdcm_assert( I->GetPlanarConfiguration() == 0 ); // FIXME we should not retrieve the whole image, ideally we only need a // single 2D frame @@ -540,7 +540,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall if( P->GetNumberOfDimensions() == 3 ) { const unsigned int *dims = P->GetDimensions(); - assert( framelen % dims[2] == 0 ); + gdcm_assert( framelen % dims[2] == 0 ); framelen /= dims[2]; } vbuffer.resize( P->GetBufferLength() ); @@ -573,8 +573,8 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall for(unsigned int i = 0; i < Internals->dims[1]; ++i ) for(unsigned int j = 0; j < Internals->dims[0]; ++j ) { - assert( (i * Internals->dims[0] + j) * ps < I->GetBufferLength() ); - assert( (i * imgdims[0] * stepj + j * stepi) * ps < framelen /*P->GetBufferLength()*/ ); + gdcm_assert( (i * Internals->dims[0] + j) * ps < I->GetBufferLength() ); + gdcm_assert( (i * imgdims[0] * stepj + j * stepi) * ps < framelen /*P->GetBufferLength()*/ ); memcpy(iconb + (i * Internals->dims[0] + j) * ps, imgb + (i * imgdims[0] * stepj + j * stepi) * ps, ps ); } @@ -588,7 +588,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall if( I->GetPixelFormat().GetBitsAllocated() == 16 ) { - //assert( I->GetPixelFormat().GetPixelRepresentation() == 0 ); + //gdcm_assert( I->GetPixelFormat().GetPixelRepresentation() == 0 ); std::string s = ss.str(); Rescaler r; r.SetPixelFormat( I->GetPixelFormat() ); @@ -605,8 +605,8 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall r.SetIntercept( 0 - step ); // paranoid self check: - assert( r.GetIntercept() + r.GetSlope() * min == 0. ); - assert( r.GetIntercept() + r.GetSlope() * max == 255. ); + gdcm_assert( r.GetIntercept() + r.GetSlope() * min == 0. ); + gdcm_assert( r.GetIntercept() + r.GetSlope() * max == 255. ); r.SetTargetPixelType( PixelFormat::UINT8 ); r.SetUseTargetPixelType(true); @@ -615,7 +615,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall v8.resize( Internals->dims[0] * Internals->dims[1] * 3 ); if( !r.Rescale(v8.data(),s.data(),s.size()) ) { - assert( 0 ); // should not happen in real life + gdcm_assert( 0 ); // should not happen in real life gdcmErrorMacro( "Problem in the rescaler" ); return false; } @@ -644,7 +644,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall } else { - assert( I->GetPixelFormat() == PixelFormat::UINT8 ); + gdcm_assert( I->GetPixelFormat() == PixelFormat::UINT8 ); std::string s = ss.str(); if( Internals->ConvertRGBToPaletteColor ) { @@ -675,7 +675,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall if( P->GetPhotometricInterpretation() == PhotometricInterpretation::YBR_FULL || P->GetPhotometricInterpretation() == PhotometricInterpretation::YBR_FULL_422 ) { - assert( I->GetPixelFormat() == PixelFormat::UINT8 ); + gdcm_assert( I->GetPixelFormat() == PixelFormat::UINT8 ); if( P->GetPlanarConfiguration() == 0 ) { unsigned char *ybr = (unsigned char*)tempvbuf.data(); @@ -712,7 +712,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall d.write( &tempvbuf[0], tempvbuf.size() ); d.close(); #endif - assert( ybr_out == ybr_end ); + gdcm_assert( ybr_out == ybr_end ); } else // ( P->GetPlanarConfiguration() == 1 ) { @@ -720,7 +720,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall unsigned char *ybr = (unsigned char*)tempvbufybr.data(); unsigned char *ybr_end = ybr + vbuffer2.size(); - assert( vbuffer2.size() % 3 == 0 ); + gdcm_assert( vbuffer2.size() % 3 == 0 ); size_t ybrl = vbuffer2.size() / 3; unsigned char *ybra = ybr + 0 * ybrl; unsigned char *ybrb = ybr + 1 * ybrl; @@ -754,21 +754,21 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall *ybr_out = (unsigned char)G; ++ybr_out; *ybr_out = (unsigned char)B; ++ybr_out; } - assert( ybra + 2 * ybrl == ybr_end ); (void)ybr_end; - assert( ybrb + 1 * ybrl == ybr_end ); - assert( ybrc + 0 * ybrl == ybr_end ); + gdcm_assert( ybra + 2 * ybrl == ybr_end ); (void)ybr_end; + gdcm_assert( ybrb + 1 * ybrl == ybr_end ); + gdcm_assert( ybrc + 0 * ybrl == ybr_end ); } } else { if( P->GetPlanarConfiguration() == 1 ) { - assert( I->GetPixelFormat() == PixelFormat::UINT8 ); + gdcm_assert( I->GetPixelFormat() == PixelFormat::UINT8 ); std::string tempvbufrgb = tempvbuf; unsigned char *rgb = (unsigned char*)tempvbufrgb.data(); unsigned char *rgb_end = rgb + vbuffer2.size(); - assert( vbuffer2.size() % 3 == 0 ); + gdcm_assert( vbuffer2.size() % 3 == 0 ); size_t rgbl = vbuffer2.size() / 3; unsigned char *rgba = rgb + 0 * rgbl; unsigned char *rgbb = rgb + 1 * rgbl; @@ -786,9 +786,9 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall *rgb_out = b; ++rgb_out; *rgb_out = c; ++rgb_out; } - assert( rgba + 2 * rgbl == rgb_end ); (void)rgb_end; - assert( rgbb + 1 * rgbl == rgb_end ); - assert( rgbc + 0 * rgbl == rgb_end ); + gdcm_assert( rgba + 2 * rgbl == rgb_end ); (void)rgb_end; + gdcm_assert( rgbb + 1 * rgbl == rgb_end ); + gdcm_assert( rgbc + 0 * rgbl == rgb_end ); } } @@ -813,8 +813,8 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall } else { - assert( I->GetPixelFormat() == PixelFormat::UINT16 ); - assert( I->GetPixelFormat().GetPixelRepresentation() == 0 ); + gdcm_assert( I->GetPixelFormat() == PixelFormat::UINT16 ); + gdcm_assert( I->GetPixelFormat().GetPixelRepresentation() == 0 ); std::string s = is.str(); Rescaler r; r.SetPixelFormat( I->GetPixelFormat() ); @@ -831,8 +831,8 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall r.SetIntercept( 0 - step ); // paranoid self check: - assert( r.GetIntercept() + r.GetSlope() * min == 0. ); - assert( r.GetIntercept() + r.GetSlope() * max == 255. ); + gdcm_assert( r.GetIntercept() + r.GetSlope() * min == 0. ); + gdcm_assert( r.GetIntercept() + r.GetSlope() * max == 255. ); r.SetTargetPixelType( PixelFormat::UINT8 ); r.SetUseTargetPixelType(true); @@ -841,7 +841,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall v8.resize( Internals->dims[0] * Internals->dims[1] * 3 ); if( !r.Rescale(v8.data(),s.data(),s.size()) ) { - assert( 0 ); // should not happen in real life + gdcm_assert( 0 ); // should not happen in real life gdcmErrorMacro( "Problem in the rescaler" ); return false; } @@ -889,7 +889,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall void *p = vbuffer2.data(); size_t len = vbuffer2.size(); const PixelFormat &pf = I->GetPixelFormat(); - assert( pf.GetSamplesPerPixel() == 1 ); + gdcm_assert( pf.GetSamplesPerPixel() == 1 ); if( Internals->UseOutsideValuePixel ) { const double d = Internals->OutsideValuePixel; @@ -908,7 +908,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall ComputeMinMax( (const int16_t*)p, len / sizeof( int16_t ), min, max, d); break; default: - assert( 0 ); // should not happen + gdcm_assert( 0 ); // should not happen break; } // ok we have found the min value, we should now be able to replace all value 'd' with this min now: @@ -927,7 +927,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall std::replace( (int16_t*)p, (int16_t*)p + len / sizeof( int16_t ), (int16_t)d, (int16_t)min); break; default: - assert( 0 ); // should not happen + gdcm_assert( 0 ); // should not happen break; } } @@ -946,7 +946,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall ComputeMinMax( (const int16_t*)p, len / sizeof( int16_t ), min, max); break; default: - assert( 0 ); // should not happen + gdcm_assert( 0 ); // should not happen break; } } @@ -955,8 +955,8 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall r.SetIntercept( 0 - step ); // paranoid self check: - assert( (int)(0.5 + r.GetIntercept() + r.GetSlope() * min) == 0 ); - assert( (int)(0.5 + r.GetIntercept() + r.GetSlope() * max) == 255 ); + gdcm_assert( (int)(0.5 + r.GetIntercept() + r.GetSlope() * min) == 0 ); + gdcm_assert( (int)(0.5 + r.GetIntercept() + r.GetSlope() * max) == 255 ); r.SetTargetPixelType( PixelFormat::UINT8 ); r.SetUseTargetPixelType(true); @@ -965,7 +965,7 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall v8.resize( Internals->dims[0] * Internals->dims[1] ); if( !r.Rescale(v8.data(),vbuffer2.data(),vbuffer2.size()) ) { - assert( 0 ); // should not happen in real life + gdcm_assert( 0 ); // should not happen in real life gdcmErrorMacro( "Problem in the rescaler" ); return false; } @@ -979,16 +979,16 @@ f. If a Palette Color lookup Table is used, an 8 Bit Allocated (0028,0100) shall if( !Internals->ConvertRGBToPaletteColor && I->GetPhotometricInterpretation() == PhotometricInterpretation::RGB ) { - assert( I->GetPixelFormat().GetSamplesPerPixel() == 3 ); + gdcm_assert( I->GetPixelFormat().GetSamplesPerPixel() == 3 ); } else { - assert( I->GetPixelFormat().GetSamplesPerPixel() == 1 ); + gdcm_assert( I->GetPixelFormat().GetSamplesPerPixel() == 1 ); } - assert( I->GetPixelFormat().GetBitsAllocated() == 8 ); - assert( I->GetPixelFormat().GetBitsStored() == 8 ); - assert( I->GetPixelFormat().GetHighBit() == 7 ); - assert( I->GetPixelFormat().GetPixelRepresentation() == 0 ); + gdcm_assert( I->GetPixelFormat().GetBitsAllocated() == 8 ); + gdcm_assert( I->GetPixelFormat().GetBitsStored() == 8 ); + gdcm_assert( I->GetPixelFormat().GetHighBit() == 7 ); + gdcm_assert( I->GetPixelFormat().GetPixelRepresentation() == 0 ); return true; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImage.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImage.cxx index e1e03efb617..b06adfc0388 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImage.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImage.cxx @@ -27,37 +27,37 @@ namespace gdcm const double *Image::GetSpacing() const { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); return Spacing.data(); } double Image::GetSpacing(unsigned int idx) const { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); //if( idx < Spacing.size() ) { return Spacing[idx]; } - //assert( 0 && "Should not happen" ); + //gdcm_assert( 0 && "Should not happen" ); //return 1; // FIXME ??? } void Image::SetSpacing(const double *spacing) { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); Spacing.assign(spacing, spacing+NumberOfDimensions); } void Image::SetSpacing(unsigned int idx, double spacing) { - //assert( spacing > 1.e3 ); + //gdcm_assert( spacing > 1.e3 ); Spacing.resize( 3 /*idx + 1*/ ); Spacing[idx] = spacing; } const double *Image::GetOrigin() const { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); if( !Origin.empty() ) return Origin.data(); return nullptr; @@ -65,7 +65,7 @@ const double *Image::GetOrigin() const double Image::GetOrigin(unsigned int idx) const { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); if( idx < Origin.size() ) { return Origin[idx]; @@ -75,7 +75,7 @@ double Image::GetOrigin(unsigned int idx) const void Image::SetOrigin(const float *ori) { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); Origin.resize( NumberOfDimensions ); for(unsigned int i = 0; i < NumberOfDimensions; ++i) { @@ -85,7 +85,7 @@ void Image::SetOrigin(const float *ori) void Image::SetOrigin(const double *ori) { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); Origin.assign(ori, ori+NumberOfDimensions); } @@ -97,14 +97,14 @@ void Image::SetOrigin(unsigned int idx, double ori) const double *Image::GetDirectionCosines() const { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); if( !DirectionCosines.empty() ) return DirectionCosines.data(); return nullptr; } double Image::GetDirectionCosines(unsigned int idx) const { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); if( idx < DirectionCosines.size() ) { return DirectionCosines[idx]; @@ -114,7 +114,7 @@ double Image::GetDirectionCosines(unsigned int idx) const void Image::SetDirectionCosines(const float *dircos) { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); DirectionCosines.resize( 6 ); for(int i = 0; i < 6; ++i) { @@ -124,7 +124,7 @@ void Image::SetDirectionCosines(const float *dircos) void Image::SetDirectionCosines(const double *dircos) { - assert( NumberOfDimensions ); + gdcm_assert( NumberOfDimensions ); DirectionCosines.assign(dircos, dircos+6); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageApplyLookupTable.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageApplyLookupTable.cxx index 22030526bd6..827d44007f3 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageApplyLookupTable.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageApplyLookupTable.cxx @@ -80,7 +80,7 @@ bool ImageApplyLookupTable::Apply() lut.Decode8(v2.data(), v2.size(), v.data(), v.size()); else lut.Decode(v2.data(), v2.size(), v.data(), v.size()); - assert( v2.size() < (size_t)std::numeric_limits::max() ); + gdcm_assert( v2.size() < (size_t)std::numeric_limits::max() ); if( pimpl->rgb8 ) de.SetByteValue( v2.data(), (uint32_t)v2.size() / 2); else @@ -93,14 +93,14 @@ bool ImageApplyLookupTable::Apply() Output->GetPixelFormat().SetBitsAllocated(8); Output->SetPlanarConfiguration( 0 ); // FIXME OT-PAL-8-face.dcm has a PlanarConfiguration while being PALETTE COLOR... const TransferSyntax &ts = image.GetTransferSyntax(); - //assert( ts == TransferSyntax::RLELossless ); + //gdcm_assert( ts == TransferSyntax::RLELossless ); if( ts.IsExplicit() ) { Output->SetTransferSyntax( TransferSyntax::ExplicitVRLittleEndian ); } else { - assert( ts.IsImplicit() ); + gdcm_assert( ts.IsImplicit() ); Output->SetTransferSyntax( TransferSyntax::ImplicitVRLittleEndian ); } // I do not have access to the DataSet: diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePhotometricInterpretation.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePhotometricInterpretation.cxx index 53b0dc44102..aff4a693085 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePhotometricInterpretation.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePhotometricInterpretation.cxx @@ -77,14 +77,14 @@ bool ImageChangePhotometricInterpretation::ChangeMonochrome() //Output->GetPixelFormat().SetSamplesPerPixel( 3 ); //Output->SetPlanarConfiguration( 0 ); // FIXME OT-PAL-8-face.dcm has a PlanarConfiguration while being PALETTE COLOR... //const TransferSyntax &ts = image.GetTransferSyntax(); - ////assert( ts == TransferSyntax::RLELossless ); + ////gdcm_assert( ts == TransferSyntax::RLELossless ); //if( ts.IsExplicit() ) // { // Output->SetTransferSyntax( TransferSyntax::ExplicitVRLittleEndian ); // } //else // { - // assert( ts.IsImplicit() ); + // gdcm_assert( ts.IsImplicit() ); // Output->SetTransferSyntax( TransferSyntax::ImplicitVRLittleEndian ); // } @@ -101,7 +101,7 @@ bool ImageChangePhotometricInterpretation::ChangeYBR2RGB() // mistake. just like Largest Image Pixel Value and other would be wrong const Bitmap &image = *Input; PhotometricInterpretation pi = image.GetPhotometricInterpretation(); - //assert( pi == PhotometricInterpretation::MONOCHROME1 || pi == PhotometricInterpretation::MONOCHROME2 ); + //gdcm_assert( pi == PhotometricInterpretation::MONOCHROME1 || pi == PhotometricInterpretation::MONOCHROME2 ); if( pi == PI ) { return true; @@ -153,14 +153,14 @@ bool ImageChangePhotometricInterpretation::ChangeYBR2RGB() //Output->GetPixelFormat().SetSamplesPerPixel( 3 ); //Output->SetPlanarConfiguration( 0 ); // FIXME OT-PAL-8-face.dcm has a PlanarConfiguration while being PALETTE COLOR... //const TransferSyntax &ts = image.GetTransferSyntax(); - ////assert( ts == TransferSyntax::RLELossless ); + ////gdcm_assert( ts == TransferSyntax::RLELossless ); //if( ts.IsExplicit() ) // { // Output->SetTransferSyntax( TransferSyntax::ExplicitVRLittleEndian ); // } //else // { - // assert( ts.IsImplicit() ); + // gdcm_assert( ts.IsImplicit() ); // Output->SetTransferSyntax( TransferSyntax::ImplicitVRLittleEndian ); // } @@ -178,7 +178,7 @@ bool ImageChangePhotometricInterpretation::ChangeRGB2YBR() // mistake. just like Largest Image Pixel Value and other would be wrong const Bitmap &image = *Input; PhotometricInterpretation pi = image.GetPhotometricInterpretation(); - //assert( pi == PhotometricInterpretation::MONOCHROME1 || pi == PhotometricInterpretation::MONOCHROME2 ); + //gdcm_assert( pi == PhotometricInterpretation::MONOCHROME1 || pi == PhotometricInterpretation::MONOCHROME2 ); if( pi == PI ) { return true; @@ -230,14 +230,14 @@ bool ImageChangePhotometricInterpretation::ChangeRGB2YBR() //Output->GetPixelFormat().SetSamplesPerPixel( 3 ); //Output->SetPlanarConfiguration( 0 ); // FIXME OT-PAL-8-face.dcm has a PlanarConfiguration while being PALETTE COLOR... //const TransferSyntax &ts = image.GetTransferSyntax(); - ////assert( ts == TransferSyntax::RLELossless ); + ////gdcm_assert( ts == TransferSyntax::RLELossless ); //if( ts.IsExplicit() ) // { // Output->SetTransferSyntax( TransferSyntax::ExplicitVRLittleEndian ); // } //else // { - // assert( ts.IsImplicit() ); + // gdcm_assert( ts.IsImplicit() ); // Output->SetTransferSyntax( TransferSyntax::ImplicitVRLittleEndian ); // } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePhotometricInterpretation.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePhotometricInterpretation.h index 4aad33fe268..6ca6bbe84f2 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePhotometricInterpretation.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePhotometricInterpretation.h @@ -64,7 +64,7 @@ static inline int Round(T x) template static inline T Clamp(int v) { - assert( std::numeric_limits::min() == 0 ); + gdcm_assert( std::numeric_limits::min() == 0 ); return v < 0 ? 0 : (v > std::numeric_limits::max() ? std::numeric_limits::max() : v); } @@ -79,7 +79,7 @@ void ImageChangePhotometricInterpretation::RGB2YBR(T ybr[3], const T rgb[3], uns const double R = rgb[0]; const double G = rgb[1]; const double B = rgb[2]; - assert( storedbits <= sizeof(T) * 8 ); + gdcm_assert( storedbits <= sizeof(T) * 8 ); const int halffullscale = 1 << (storedbits - 1); const int Y = Round( 0.299 * R + 0.587 * G + 0.114 * B ); const int CB = Round((-0.299 * R - 0.587 * G + 0.886 * B)/1.772 + halffullscale); @@ -95,7 +95,7 @@ void ImageChangePhotometricInterpretation::YBR2RGB(T rgb[3], const T ybr[3], uns const double Y = ybr[0]; const double Cb = ybr[1]; const double Cr = ybr[2]; - assert( storedbits <= sizeof(T) * 8 ); + gdcm_assert( storedbits <= sizeof(T) * 8 ); const int halffullscale = 1 << (storedbits - 1); const int R = Round(Y + 1.402 * (Cr-halffullscale) ); const int G = Round(Y -( 0.114 * 1.772 * (Cb-halffullscale) + 0.299 * 1.402 * (Cr-halffullscale))/0.587); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePlanarConfiguration.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePlanarConfiguration.cxx index b3fdbc61bcd..42718da4730 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePlanarConfiguration.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePlanarConfiguration.cxx @@ -35,7 +35,7 @@ bool ImageChangePlanarConfiguration::Change() { return true; } - assert( Input->GetPhotometricInterpretation() == PhotometricInterpretation::YBR_FULL + gdcm_assert( Input->GetPhotometricInterpretation() == PhotometricInterpretation::YBR_FULL || Input->GetPhotometricInterpretation() == PhotometricInterpretation::YBR_FULL_422 || Input->GetPhotometricInterpretation() == PhotometricInterpretation::YBR_PARTIAL_422 || Input->GetPhotometricInterpretation() == PhotometricInterpretation::YBR_RCT @@ -52,11 +52,11 @@ bool ImageChangePlanarConfiguration::Change() char *p = new char[len]; image.GetBuffer( p ); - assert( len % 3 == 0 ); + gdcm_assert( len % 3 == 0 ); PixelFormat pf = Input->GetPixelFormat(); const size_t ps = pf.GetPixelSize(); const size_t framesize = dims[0] * dims[1] * ps; - assert( framesize * dims[2] == len ); + gdcm_assert( framesize * dims[2] == len ); char *copy = new char[len]; size_t size = framesize / 3; @@ -82,7 +82,7 @@ bool ImageChangePlanarConfiguration::Change() } else // User requested to do PlanarConfiguration == 1 { - assert( PlanarConfiguration == 1 ); + gdcm_assert( PlanarConfiguration == 1 ); for(unsigned int z = 0; z < dims[2]; ++z) { const void *frame = p + z * framesize; @@ -110,7 +110,7 @@ bool ImageChangePlanarConfiguration::Change() Output->SetPlanarConfiguration( PlanarConfiguration ); if( Input->GetTransferSyntax().IsImplicit() ) { - assert( Output->GetTransferSyntax().IsImplicit() ); + gdcm_assert( Output->GetTransferSyntax().IsImplicit() ); } else if( Input->GetTransferSyntax() == TransferSyntax::ExplicitVRBigEndian ) { @@ -120,8 +120,8 @@ bool ImageChangePlanarConfiguration::Change() { Output->SetTransferSyntax( TransferSyntax::ExplicitVRLittleEndian ); } - //assert( Output->GetTransferSyntax().IsRaw() ); - assert( Output->GetPhotometricInterpretation() == Input->GetPhotometricInterpretation() ); + //gdcm_assert( Output->GetTransferSyntax().IsRaw() ); + gdcm_assert( Output->GetPhotometricInterpretation() == Input->GetPhotometricInterpretation() ); return true; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePlanarConfiguration.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePlanarConfiguration.h index 8bf6f1c43a0..412b4d97a00 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePlanarConfiguration.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangePlanarConfiguration.h @@ -66,7 +66,7 @@ size_t ImageChangePlanarConfiguration::RGBPlanesToRGBPixels(T *out, const T *r, *pout++ = *b++; } - assert( (size_t)(pout - out) == 3 * s ); + gdcm_assert( (size_t)(pout - out) == 3 * s ); return pout - out; } @@ -80,7 +80,7 @@ size_t ImageChangePlanarConfiguration::RGBPixelsToRGBPlanes(T *r, T *g, T *b, co *g++ = *prgb++; *b++ = *prgb++; } - assert( (size_t)(prgb - rgb) == 3 * s ); + gdcm_assert( (size_t)(prgb - rgb) == 3 * s ); return prgb - rgb; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangeTransferSyntax.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangeTransferSyntax.cxx index 9457c5e9baa..0a3d3460f9c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangeTransferSyntax.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageChangeTransferSyntax.cxx @@ -30,7 +30,7 @@ namespace gdcm bool ImageChangeTransferSyntax::TryRAWCodecIcon(const DataElement &pixelde) { unsigned long len = Input->GetIconImage().GetBufferLength(); - //assert( len == pixelde.GetByteValue()->GetLength() ); + //gdcm_assert( len == pixelde.GetByteValue()->GetLength() ); const TransferSyntax &ts = GetTransferSyntax(); RAWCodec codec; @@ -71,7 +71,7 @@ void UpdatePhotometricInterpretation( Bitmap const &input, Bitmap &output ) { output.SetPhotometricInterpretation( PhotometricInterpretation::YBR_FULL ); } - assert( output.GetPhotometricInterpretation() == PhotometricInterpretation::RGB + gdcm_assert( output.GetPhotometricInterpretation() == PhotometricInterpretation::RGB || output.GetPhotometricInterpretation() == PhotometricInterpretation::YBR_FULL || output.GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME1 || output.GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME2 @@ -82,7 +82,7 @@ void UpdatePhotometricInterpretation( Bitmap const &input, Bitmap &output ) bool ImageChangeTransferSyntax::TryRAWCodec(const DataElement &pixelde, Bitmap const &input, Bitmap &output) { unsigned long len = input.GetBufferLength(); (void)len; - //assert( len == pixelde.GetByteValue()->GetLength() ); + //gdcm_assert( len == pixelde.GetByteValue()->GetLength() ); const TransferSyntax &ts = GetTransferSyntax(); RAWCodec codec; @@ -112,7 +112,7 @@ bool ImageChangeTransferSyntax::TryRAWCodec(const DataElement &pixelde, Bitmap c bool ImageChangeTransferSyntax::TryRLECodec(const DataElement &pixelde, Bitmap const &input, Bitmap &output) { unsigned long len = input.GetBufferLength(); (void)len; - //assert( len == pixelde.GetByteValue()->GetLength() ); + //gdcm_assert( len == pixelde.GetByteValue()->GetLength() ); const TransferSyntax &ts = GetTransferSyntax(); RLECodec codec; @@ -151,7 +151,7 @@ bool ImageChangeTransferSyntax::TryRLECodec(const DataElement &pixelde, Bitmap c bool ImageChangeTransferSyntax::TryJPEGCodec(const DataElement &pixelde, Bitmap const &input, Bitmap &output) { unsigned long len = input.GetBufferLength(); (void)len; - //assert( len == pixelde.GetByteValue()->GetLength() ); + //gdcm_assert( len == pixelde.GetByteValue()->GetLength() ); const TransferSyntax &ts = GetTransferSyntax(); JPEGCodec jpgcodec; @@ -160,7 +160,7 @@ bool ImageChangeTransferSyntax::TryJPEGCodec(const DataElement &pixelde, Bitmap // that can be both lossy and lossless: if( ts.IsLossy() ) { - //assert( !ts.IsLossless() ); // I cannot do since since Try* functions are called with all TS, I could be receiving a JPEGLS TS... + //gdcm_assert( !ts.IsLossless() ); // I cannot do since since Try* functions are called with all TS, I could be receiving a JPEGLS TS... jpgcodec.SetLossless( false ); } @@ -224,7 +224,7 @@ bool ImageChangeTransferSyntax::TryJPEGCodec(const DataElement &pixelde, Bitmap // HACK //Image *i = (Image*)this; //i->SetPhotometricInterpretation( codec.GetPhotometricInterpretation() ); - assert(0); + gdcm_assert(0); } return true; } @@ -234,7 +234,7 @@ bool ImageChangeTransferSyntax::TryJPEGCodec(const DataElement &pixelde, Bitmap bool ImageChangeTransferSyntax::TryJPEGLSCodec(const DataElement &pixelde, Bitmap const &input, Bitmap &output) { unsigned long len = input.GetBufferLength(); (void)len; - //assert( len == pixelde.GetByteValue()->GetLength() ); + //gdcm_assert( len == pixelde.GetByteValue()->GetLength() ); const TransferSyntax &ts = GetTransferSyntax(); JPEGLSCodec jlscodec; @@ -259,7 +259,7 @@ bool ImageChangeTransferSyntax::TryJPEGLSCodec(const DataElement &pixelde, Bitma if( input.AreOverlaysInPixelData() || input.UnusedBitsPresentInPixelData() ) { ByteValue *bv = const_cast(pixelde.GetByteValue()); - assert( bv ); + gdcm_assert( bv ); gdcm::DataElement tmp; tmp.SetByteValue( bv->GetPointer(), bv->GetLength()); bv = const_cast(tmp.GetByteValue()); @@ -294,7 +294,7 @@ bool ImageChangeTransferSyntax::TryJPEGLSCodec(const DataElement &pixelde, Bitma bool ImageChangeTransferSyntax::TryJPEG2000Codec(const DataElement &pixelde, Bitmap const &input, Bitmap &output) { unsigned long len = input.GetBufferLength(); (void)len; - //assert( len == pixelde.GetByteValue()->GetLength() ); + //gdcm_assert( len == pixelde.GetByteValue()->GetLength() ); const TransferSyntax &ts = GetTransferSyntax(); JPEG2000Codec j2kcodec; @@ -332,13 +332,13 @@ bool ImageChangeTransferSyntax::TryJPEG2000Codec(const DataElement &pixelde, Bit } else { - assert( ts == TransferSyntax::JPEG2000 ); + gdcm_assert( ts == TransferSyntax::JPEG2000 ); output.SetPhotometricInterpretation( PhotometricInterpretation::YBR_ICT ); } } else { - assert( input.GetPhotometricInterpretation().IsSameColorSpace( PhotometricInterpretation::YBR_FULL ) ); + gdcm_assert( input.GetPhotometricInterpretation().IsSameColorSpace( PhotometricInterpretation::YBR_FULL ) ); if( ts == TransferSyntax::JPEG2000Lossless ) { output.SetPhotometricInterpretation( PhotometricInterpretation::YBR_FULL ); @@ -348,7 +348,7 @@ bool ImageChangeTransferSyntax::TryJPEG2000Codec(const DataElement &pixelde, Bit } else { - assert( ts == TransferSyntax::JPEG2000 ); + gdcm_assert( ts == TransferSyntax::JPEG2000 ); //output.SetPhotometricInterpretation( PhotometricInterpretation::YBR_ICT ); // FIXME: technically when doing lossy we could be standard compliant and first convert to // RGB THEN compress to YBR_ICT. For now produce improper j2k image @@ -358,7 +358,7 @@ bool ImageChangeTransferSyntax::TryJPEG2000Codec(const DataElement &pixelde, Bit } else { - assert( input.GetPixelFormat().GetSamplesPerPixel() == 1 ); + gdcm_assert( input.GetPixelFormat().GetSamplesPerPixel() == 1 ); } if( !r ) return false; @@ -435,7 +435,7 @@ bool ImageChangeTransferSyntax::Change() Output->SetTransferSyntax( TS ); if( !success ) { - //assert(0); + //gdcm_assert(0); return false; } @@ -446,7 +446,7 @@ bool ImageChangeTransferSyntax::Change() { Bitmap &outbitmap = *Output; Pixmap *outpixmap = dynamic_cast( &outbitmap ); - assert( outpixmap != nullptr ); + gdcm_assert( outpixmap != nullptr ); if( !pixmap->GetIconImage().IsEmpty() ) { // same goes for icon @@ -469,16 +469,16 @@ bool ImageChangeTransferSyntax::Change() outpixmap->GetIconImage().SetTransferSyntax( TS ); if( !success ) { - //assert(0); + //gdcm_assert(0); return false; } - assert( outpixmap->GetIconImage().GetTransferSyntax() == TS ); + gdcm_assert( outpixmap->GetIconImage().GetTransferSyntax() == TS ); } } //Output->ComputeLossyFlag(); - assert( Output->GetTransferSyntax() == TS ); - //if( TS.IsLossy() ) assert( Output->IsLossy() ); + gdcm_assert( Output->GetTransferSyntax() == TS ); + //if( TS.IsLossy() ) gdcm_assert( Output->IsLossy() ); return success; } @@ -492,7 +492,7 @@ bool ImageChangeTransferSyntax::Change() Output->SetTransferSyntax( TS ); if( !success ) { - //assert(0); + //gdcm_assert(0); return false; } @@ -514,16 +514,16 @@ bool ImageChangeTransferSyntax::Change() outpixmap->GetIconImage().SetTransferSyntax( TS ); if( !success ) { - //assert(0); + //gdcm_assert(0); return false; } - assert( outpixmap->GetIconImage().GetTransferSyntax() == TS ); + gdcm_assert( outpixmap->GetIconImage().GetTransferSyntax() == TS ); } } //Output->ComputeLossyFlag(); - assert( Output->GetTransferSyntax() == TS ); + gdcm_assert( Output->GetTransferSyntax() == TS ); return success; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageCodec.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageCodec.cxx index 2c25a90f9ba..5cf2c02642a 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageCodec.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageCodec.cxx @@ -53,7 +53,7 @@ ImageCodec::~ImageCodec() bool ImageCodec::GetHeaderInfo(std::istream &, TransferSyntax &) { // This function should really be virtual pure. - assert( 0 ); + gdcm_assert( 0 ); return false; } @@ -98,17 +98,17 @@ bool ImageCodec::DoByteSwap(std::istream &is, std::ostream &os) { // FIXME: Do some stupid work: std::streampos start = is.tellg(); - assert( 0 - start == 0 ); + gdcm_assert( 0 - start == 0 ); is.seekg( 0, std::ios::end); size_t buf_size = (size_t)is.tellg(); - //assert(buf_size < INT_MAX); + //gdcm_assert(buf_size < INT_MAX); char *dummy_buffer = new char[(unsigned int)buf_size]; is.seekg(start, std::ios::beg); is.read( dummy_buffer, buf_size); is.seekg(start, std::ios::beg); // reset //SwapCode sc = is.GetSwapCode(); - assert( !(buf_size % 2) ); + gdcm_assert( !(buf_size % 2) ); #ifdef GDCM_WORDS_BIGENDIAN if( PF.GetBitsAllocated() == 16 ) { @@ -117,7 +117,7 @@ bool ImageCodec::DoByteSwap(std::istream &is, std::ostream &os) } #else // GE_DLX-8-MONO2-PrivateSyntax.dcm is 8bits - // assert( PF.GetBitsAllocated() == 16 ); + // gdcm_assert( PF.GetBitsAllocated() == 16 ); if ( PF.GetBitsAllocated() == 16 ) { ByteSwap::SwapRangeFromSwapCodeIntoSystem((uint16_t*) @@ -133,10 +133,10 @@ bool ImageCodec::DoYBR(std::istream &is, std::ostream &os) { // FIXME: Do some stupid work: std::streampos start = is.tellg(); - assert( 0 - start == 0 ); + gdcm_assert( 0 - start == 0 ); is.seekg( 0, std::ios::end); size_t buf_size = (size_t)is.tellg(); - //assert(buf_size < INT_MAX); + //gdcm_assert(buf_size < INT_MAX); char *dummy_buffer = new char[(unsigned int)buf_size]; is.seekg(start, std::ios::beg); is.read( dummy_buffer, buf_size); @@ -145,12 +145,12 @@ bool ImageCodec::DoYBR(std::istream &is, std::ostream &os) // Code is coming from: // http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf - assert( !(buf_size % 3) ); + gdcm_assert( !(buf_size % 3) ); unsigned long size = (unsigned long)buf_size/3; - //assert(buf_size < INT_MAX); + //gdcm_assert(buf_size < INT_MAX); unsigned char *copy = new unsigned char[ (unsigned int)buf_size ]; memmove( copy, dummy_buffer, (size_t)buf_size); -assert(0); // Do not use this code ! +gdcm_assert(0); // Do not use this code ! // FIXME FIXME FIXME // The following is bogus: we are doing two operation at once: // Planar configuration AND YBR... doh ! @@ -194,7 +194,7 @@ bool ImageCodec::DoYBRFull422(std::istream &is, std::ostream &os) { // FIXME: Do some stupid work: std::streampos start = is.tellg(); - assert( 0 - start == 0 ); + gdcm_assert( 0 - start == 0 ); is.seekg( 0, std::ios::end); const size_t buf_size = (size_t)is.tellg(); const size_t rgb_buf_size = buf_size * 3 / 2; @@ -203,8 +203,8 @@ bool ImageCodec::DoYBRFull422(std::istream &is, std::ostream &os) is.read( (char*)dummy_buffer, buf_size); is.seekg(start, std::ios::beg); // reset - assert( !(rgb_buf_size % 3) ); - assert( !(buf_size % 2) ); + gdcm_assert( !(rgb_buf_size % 3) ); + gdcm_assert( !(buf_size % 2) ); unsigned char *copy = new unsigned char[ rgb_buf_size ]; const size_t size = buf_size/4; @@ -251,10 +251,10 @@ bool ImageCodec::DoPlanarConfiguration(std::istream &is, std::ostream &os) { // FIXME: Do some stupid work: std::streampos start = is.tellg(); - assert( 0 - start == 0 ); + gdcm_assert( 0 - start == 0 ); is.seekg( 0, std::ios::end); size_t buf_size = (size_t)is.tellg(); - //assert(buf_size < INT_MAX); + //gdcm_assert(buf_size < INT_MAX); char *dummy_buffer = new char[(unsigned int)buf_size]; is.seekg(start, std::ios::beg); is.read( dummy_buffer, buf_size); @@ -262,8 +262,8 @@ bool ImageCodec::DoPlanarConfiguration(std::istream &is, std::ostream &os) //SwapCode sc = is.GetSwapCode(); // US-RGB-8-epicard.dcm - //assert( image.GetNumberOfDimensions() == 3 ); - assert( buf_size % 3 == 0 ); + //gdcm_assert( image.GetNumberOfDimensions() == 3 ); + gdcm_assert( buf_size % 3 == 0 ); unsigned long size = (unsigned long)buf_size/3; char *copy = new char[ (unsigned int)buf_size ]; //memmove( copy, dummy_buffer, buf_size); @@ -290,10 +290,10 @@ bool ImageCodec::DoSimpleCopy(std::istream &is, std::ostream &os) { #if 1 std::streampos start = is.tellg(); - assert( 0 - start == 0 ); + gdcm_assert( 0 - start == 0 ); is.seekg( 0, std::ios::end); size_t buf_size = (size_t)is.tellg(); - //assert(buf_size < INT_MAX); + //gdcm_assert(buf_size < INT_MAX); char *dummy_buffer = new char[(unsigned int)buf_size]; is.seekg(start, std::ios::beg); is.read( dummy_buffer, buf_size); @@ -313,17 +313,17 @@ bool ImageCodec::DoPaddedCompositePixelCode(std::istream &is, std::ostream &os) { // FIXME: Do some stupid work: std::streampos start = is.tellg(); - assert( 0 - start == 0 ); + gdcm_assert( 0 - start == 0 ); is.seekg( 0, std::ios::end); size_t buf_size = (size_t)is.tellg(); - //assert(buf_size < INT_MAX); + //gdcm_assert(buf_size < INT_MAX); char *dummy_buffer = new char[(unsigned int)buf_size]; is.seekg(start, std::ios::beg); is.read( dummy_buffer, buf_size); is.seekg(start, std::ios::beg); // reset //SwapCode sc = is.GetSwapCode(); - assert( !(buf_size % 2) ); + gdcm_assert( !(buf_size % 2) ); bool ret = true; if( GetPixelFormat().GetBitsAllocated() == 16 ) { @@ -340,7 +340,7 @@ bool ImageCodec::DoPaddedCompositePixelCode(std::istream &is, std::ostream &os) } else if( GetPixelFormat().GetBitsAllocated() == 32 ) { - assert( !(buf_size % 4) ); + gdcm_assert( !(buf_size % 4) ); for(size_t i = 0; i < buf_size/4; ++i) { #ifdef GDCM_WORDS_BIGENDIAN @@ -379,7 +379,7 @@ bool ImageCodec::DoInvertMonochrome(std::istream &is, std::ostream &os) } else if ( PF.GetBitsAllocated() == 16 ) { - assert( PF.GetBitsStored() != 12 ); + gdcm_assert( PF.GetBitsStored() != 12 ); uint16_t smask16 = 65535; uint16_t c; while( is.read((char*)&c,2) ) @@ -421,9 +421,9 @@ bool ImageCodec::DoInvertMonochrome(std::istream &is, std::ostream &os) << " results will be truncated. Use at own risk"); c = mask; } - assert( c <= mask ); + gdcm_assert( c <= mask ); c = (uint16_t)(mask - c); - assert( c <= mask ); + gdcm_assert( c <= mask ); os.write((char*)&c, 2); } } @@ -432,21 +432,11 @@ bool ImageCodec::DoInvertMonochrome(std::istream &is, std::ostream &os) return true; } -struct ApplyMask -{ - uint16_t operator()(uint16_t c) const { - return (uint16_t)((c >> (BitsStored - HighBit - 1)) & pmask); - } - unsigned short BitsStored; - unsigned short HighBit; - uint16_t pmask; -}; - bool ImageCodec::CleanupUnusedBits(char * data8, size_t datalen) { if( !NeedOverlayCleanup ) return true; void * data = data8; - assert( PF.GetBitsAllocated() > 8 ); + gdcm_assert( PF.GetBitsAllocated() > 8 ); if( PF.GetBitsAllocated() == 16 ) { // pmask : to mask the 'unused bits' (may contain overlays) @@ -491,9 +481,46 @@ bool ImageCodec::CleanupUnusedBits(char * data8, size_t datalen) } } } + else if (PF.GetBitsAllocated() == 32) { + // pmask : to mask the 'unused bits' (may contain overlays) + uint32_t pmask = 0xffffffff; + pmask = (uint32_t)(pmask >> (PF.GetBitsAllocated() - PF.GetBitsStored())); + + if (PF.GetPixelRepresentation()) { + // smask : to check the 'sign' when BitsStored != BitsAllocated + uint32_t smask = 0x00000001; + smask = (uint32_t)(smask << (32 - (PF.GetBitsAllocated() - + PF.GetBitsStored() + 1))); + // nmask : to propagate sign bit on negative values + int32_t nmask = (int32_t)0x80000000; + nmask = + (int32_t)(nmask >> (PF.GetBitsAllocated() - PF.GetBitsStored() - 1)); + + uint32_t *start = (uint32_t *)data; + for (uint32_t *p = start; p != start + datalen / 4; ++p) { + uint32_t c = *p; + c = (uint32_t)(c >> (PF.GetBitsStored() - PF.GetHighBit() - 1)); + if (c & smask) { + c = (uint32_t)(c | nmask); + } else { + c = c & pmask; + } + *p = c; + } + } else // Pixel are unsigned + { + uint32_t *start = (uint32_t *)data; + for (uint32_t *p = start; p != start + datalen / 4; ++p) { + uint32_t c = *p; + c = (uint32_t)((c >> (PF.GetBitsStored() - PF.GetHighBit() - 1)) & + pmask); + *p = c; + } + } + } else { - assert(0); // TODO + gdcm_assert(0); // TODO return false; } return true; @@ -502,7 +529,7 @@ bool ImageCodec::CleanupUnusedBits(char * data8, size_t datalen) // Cleanup the unused bits bool ImageCodec::DoOverlayCleanup(std::istream &is, std::ostream &os) { - assert( PF.GetBitsAllocated() > 8 ); + gdcm_assert( PF.GetBitsAllocated() > 8 ); if( PF.GetBitsAllocated() == 16 ) { // pmask : to mask the 'unused bits' (may contain overlays) @@ -536,11 +563,10 @@ bool ImageCodec::DoOverlayCleanup(std::istream &is, std::ostream &os) } else // Pixel are unsigned { -#if 1 // On Windows, is.read and os.write are expensive operations. // If we called it for each value then conversion would be extremely slow. - // Therefore we read/mask/write 1000 values at once. - const unsigned int bufferSize = 1000; + // Therefore we read/mask/write 1024 values at once. + const unsigned int bufferSize = 1024; std::vector buffer(bufferSize); while (is) { @@ -553,29 +579,56 @@ bool ImageCodec::DoOverlayCleanup(std::istream &is, std::ostream &os) } os.write((char *)buffer.data(), bytesRead); } -#else - //std::ostreambuf_iterator end_of_stream_iterator; - //std::ostreambuf_iterator out_iter(os.rdbuf()); - //while( out_iter != end_of_stream_iterator ) - // { - // *out_iter = - // (*out_iter >> (PF.GetBitsStored() - PF.GetHighBit() - 1)) & pmask; - // } - std::istreambuf_iterator it_in(is); - std::istreambuf_iterator eos; - std::ostreambuf_iterator it_out(os); - ApplyMask am; - am.BitsStored = PF.GetBitsStored(); - am.HighBit = PF.GetHighBit(); - am.pmask = pmask; - - std::transform(it_in, eos, it_out, am); -#endif } } + else if (PF.GetBitsAllocated() == 32) { + // pmask : to mask the 'unused bits' (may contain overlays) + uint16_t pmask = 0xffff; + pmask = (uint16_t)(pmask >> (PF.GetBitsAllocated() - PF.GetBitsStored())); + + if (PF.GetPixelRepresentation()) { + // smask : to check the 'sign' when BitsStored != BitsAllocated + uint16_t smask = 0x0001; + smask = (uint16_t)(smask << (16 - (PF.GetBitsAllocated() - + PF.GetBitsStored() + 1))); + // nmask : to propagate sign bit on negative values + int16_t nmask = (int16_t)0x8000; + nmask = + (int16_t)(nmask >> (PF.GetBitsAllocated() - PF.GetBitsStored() - 1)); + + uint16_t c; + while (is.read((char *)&c, 2)) { + c = (uint16_t)(c >> (PF.GetBitsStored() - PF.GetHighBit() - 1)); + if (c & smask) { + c = (uint16_t)(c | nmask); + } else { + c = c & pmask; + } + os.write((char *)&c, 2); + } + } else // Pixel are unsigned + { + // On Windows, is.read and os.write are expensive operations. + // If we called it for each value then conversion would be extremely slow. + // Therefore we read/mask/write 1024 values at once. + const unsigned int bufferSize = 1024; + std::vector buffer(bufferSize); + while (is) { + is.read((char *)buffer.data(), bufferSize * sizeof(uint16_t)); + std::streamsize bytesRead = is.gcount(); + std::vector::iterator validBufferEnd = + buffer.begin() + bytesRead / sizeof(uint16_t); + for (std::vector::iterator it = buffer.begin(); + it != validBufferEnd; ++it) { + *it = ((*it >> (PF.GetBitsStored() - PF.GetHighBit() - 1)) & pmask); + } + os.write((char *)buffer.data(), bytesRead); + } + } + } else { - assert(0); // TODO + gdcm_assert(0); // TODO return false; } return true; @@ -588,8 +641,8 @@ bool ImageCodec::Decode(DataElement const &, DataElement &) bool ImageCodec::DecodeByStreams(std::istream &is, std::ostream &os) { - assert( PlanarConfiguration == 0 || PlanarConfiguration == 1); - assert( PI != PhotometricInterpretation::UNKNOWN ); + gdcm_assert( PlanarConfiguration == 0 || PlanarConfiguration == 1); + gdcm_assert( PI != PhotometricInterpretation::UNKNOWN ); std::stringstream bs_os; // ByteSwap std::stringstream pcpc_os; // Padded Composite Pixel Code //std::stringstream pi_os; // PhotometricInterpretation @@ -640,7 +693,7 @@ bool ImageCodec::DecodeByStreams(std::istream &is, std::ostream &os) } break; case PhotometricInterpretation::PALETTE_COLOR: - //assert( LUT ); + //gdcm_assert( LUT ); // Nothing needs to be done break; case PhotometricInterpretation::YBR_FULL_422: @@ -698,7 +751,7 @@ bool ImageCodec::DecodeByStreams(std::istream &is, std::ostream &os) } else { - assert( PF.GetBitsAllocated() == PF.GetBitsStored() ); + gdcm_assert( PF.GetBitsAllocated() == PF.GetBitsStored() ); copySuccess = DoSimpleCopy(*cur_is, os); } @@ -720,7 +773,7 @@ void ImageCodec::SetDimensions(const unsigned int d[3]) void ImageCodec::SetDimensions(const std::vector & d) { size_t theSize = d.size(); - assert(theSize<= 3); + gdcm_assert(theSize<= 3); for (size_t i = 0; i < 3; i++) { if (i < theSize) @@ -732,7 +785,7 @@ void ImageCodec::SetDimensions(const std::vector & d) bool ImageCodec::StartEncode( std::ostream & ) { - assert(0); + gdcm_assert(0); return false; } bool ImageCodec::IsRowEncoder() @@ -745,19 +798,19 @@ bool ImageCodec::IsFrameEncoder() } bool ImageCodec::AppendRowEncode( std::ostream & , const char * , size_t ) { - assert(0); + gdcm_assert(0); return false; } // TODO: technically the frame encoder could use the row encoder when present // this could reduce code duplication bool ImageCodec::AppendFrameEncode( std::ostream & , const char * , size_t ) { - assert(0); + gdcm_assert(0); return false; } bool ImageCodec::StopEncode( std::ostream & ) { - assert(0); + gdcm_assert(0); return false; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageCodec.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageCodec.h index f58217735ce..2c29535c826 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageCodec.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageCodec.h @@ -55,7 +55,7 @@ class GDCM_EXPORT ImageCodec : public Codec } void SetPlanarConfiguration(unsigned int pc) { - assert( pc == 0 || pc == 1 ); + gdcm_assert( pc == 0 || pc == 1 ); PlanarConfiguration = pc; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageFragmentSplitter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageFragmentSplitter.cxx index 79f50321a6c..ae39d1d6259 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageFragmentSplitter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageFragmentSplitter.cxx @@ -43,7 +43,7 @@ bool ImageFragmentSplitter::Split() return false; } - //assert( sqf->GetNumberOfFragments() == 1 ); + //gdcm_assert( sqf->GetNumberOfFragments() == 1 ); // WARNING do not keep the same Basic Offset Table... const Fragment& frag = sqf->GetFragment(0); @@ -77,7 +77,7 @@ bool ImageFragmentSplitter::Split() { Fragment splitfrag; splitfrag.SetByteValue( p + nfrags * FragmentSizeMax, (uint32_t)lastfrag ); - assert( nfrags * FragmentSizeMax + lastfrag == len ); + gdcm_assert( nfrags * FragmentSizeMax + lastfrag == len ); sq->AddFragment( splitfrag ); } Output->GetDataElement().SetValue( *sq ); @@ -107,7 +107,7 @@ void ImageFragmentSplitter::SetFragmentSizeMax(unsigned int fragsize) FragmentSizeMax = 2; } // \postcondition: - assert( FragmentSizeMax >= 2 && (FragmentSizeMax % 2) == 0 ); + gdcm_assert( FragmentSizeMax >= 2 && (FragmentSizeMax % 2) == 0 ); } } // end namespace gdcm diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageHelper.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageHelper.cxx index ab1e1a853ee..59e95357b2c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageHelper.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageHelper.cxx @@ -53,6 +53,7 @@ bool ImageHelper::SecondaryCaptureImagePlaneModule = false; static bool GetOriginValueFromSequence(const DataSet& ds, const Tag& tfgs, std::vector &ori) { + ori.clear(); if( !ds.FindDataElement( tfgs ) ) return false; //const SequenceOfItems * sqi = ds.GetDataElement( tfgs ).GetSequenceOfItems(); SmartPointer sqi = ds.GetDataElement( tfgs ).GetValueAsSQ(); @@ -73,7 +74,7 @@ static bool GetOriginValueFromSequence(const DataSet& ds, const Tag& tfgs, std:: const Tag tps(0x0020,0x0032); if( !subds2.FindDataElement(tps) ) return false; const DataElement &de = subds2.GetDataElement( tps ); - //assert( bv ); + //gdcm_assert( bv ); Attribute<0x0020,0x0032> at; at.SetFromDataElement( de ); //at.Print( std::cout ); @@ -88,6 +89,7 @@ static bool GetOriginValueFromSequence(const DataSet& ds, const Tag& tfgs, std:: static bool GetDirectionCosinesValueFromSequence(const DataSet& ds, const Tag& tfgs, std::vector &dircos) { + dircos.clear(); if( !ds.FindDataElement( tfgs ) ) return false; //const SequenceOfItems * sqi = ds.GetDataElement( tfgs ).GetSequenceOfItems(); SmartPointer sqi = ds.GetDataElement( tfgs ).GetValueAsSQ(); @@ -101,7 +103,7 @@ static bool GetDirectionCosinesValueFromSequence(const DataSet& ds, const Tag& t //const SequenceOfItems * sqi2 = subds.GetDataElement( tpms ).GetSequenceOfItems(); SmartPointer sqi2 = subds.GetDataElement( tpms ).GetValueAsSQ(); if( !(sqi2 && sqi2->GetNumberOfItems()) ) return false; - assert( sqi2 && sqi2->GetNumberOfItems() ); + gdcm_assert( sqi2 && sqi2->GetNumberOfItems() ); // Take it from the first item const Item &item2 = sqi2->GetItem(1); const DataSet & subds2 = item2.GetNestedDataSet(); @@ -109,7 +111,7 @@ static bool GetDirectionCosinesValueFromSequence(const DataSet& ds, const Tag& t const Tag tps(0x0020,0x0037); if( !subds2.FindDataElement(tps) ) return false; const DataElement &de = subds2.GetDataElement( tps ); - //assert( bv ); + //gdcm_assert( bv ); Attribute<0x0020,0x0037> at; at.SetFromDataElement( de ); dircos.push_back( at.GetValue(0) ); @@ -124,6 +126,7 @@ static bool GetDirectionCosinesValueFromSequence(const DataSet& ds, const Tag& t static bool GetInterceptSlopeValueFromSequence(const DataSet& ds, const Tag& tfgs, std::vector &intslope) { + intslope.clear(); if( !ds.FindDataElement( tfgs ) ) return false; //const SequenceOfItems * sqi = ds.GetDataElement( tfgs ).GetSequenceOfItems(); SmartPointer sqi = ds.GetDataElement( tfgs ).GetValueAsSQ(); @@ -136,33 +139,37 @@ static bool GetInterceptSlopeValueFromSequence(const DataSet& ds, const Tag& tfg if( !subds.FindDataElement(tpms) ) return false; //const SequenceOfItems * sqi2 = subds.GetDataElement( tpms ).GetSequenceOfItems(); SmartPointer sqi2 = subds.GetDataElement( tpms ).GetValueAsSQ(); - assert( sqi2 ); + gdcm_assert( sqi2 ); const Item &item2 = sqi2->GetItem(1); const DataSet & subds2 = item2.GetNestedDataSet(); + double intercept; { // (0028,1052) DS [0] # 2,1 Rescale Intercept const Tag tps(0x0028,0x1052); if( !subds2.FindDataElement(tps) ) return false; const DataElement &de = subds2.GetDataElement( tps ); - //assert( bv ); + //gdcm_assert( bv ); Attribute<0x0028,0x1052> at; at.SetFromDataElement( de ); //at.Print( std::cout ); - intslope.push_back( at.GetValue() ); + intercept = at.GetValue(); } + double slope; { // (0028,1053) DS [5.65470085470085] # 16,1 Rescale Slope const Tag tps(0x0028,0x1053); if( !subds2.FindDataElement(tps) ) return false; const DataElement &de = subds2.GetDataElement( tps ); - //assert( bv ); + //gdcm_assert( bv ); Attribute<0x0028,0x1053> at; at.SetFromDataElement( de ); //at.Print( std::cout ); - intslope.push_back( at.GetValue() ); + slope = at.GetValue(); } + intslope.push_back( intercept ); + intslope.push_back( slope ); - assert( intslope.size() == 2 ); + gdcm_assert( intslope.size() == 2 ); return true; } @@ -196,14 +203,14 @@ static bool ComputeZSpacingFromIPP(const DataSet &ds, double &zspacing) cosines[5] = 0; } } - assert( b1 && cosines.size() == 6 ); // yeah we really need that + gdcm_assert( b1 && cosines.size() == 6 ); // yeah we really need that const Tag tfgs(0x5200,0x9230); if( !ds.FindDataElement( tfgs ) ) return false; //const SequenceOfItems * sqi = ds.GetDataElement( tfgs ).GetSequenceOfItems(); SmartPointer sqi = ds.GetDataElement( tfgs ).GetValueAsSQ(); if( !sqi ) return false; - assert( sqi ); + gdcm_assert( sqi ); double normal[3]; DirectionCosines dc( cosines.data() ); dc.Cross( normal ); @@ -214,6 +221,7 @@ static bool ComputeZSpacingFromIPP(const DataSet &ds, double &zspacing) if( nitems > 1 ) { std::vector dircos_subds2; dircos_subds2.resize(6); std::vector distances; + std::set unique_distances; for(SequenceOfItems::SizeType i0 = 1; i0 <= nitems; ++i0) { const Item &item = sqi->GetItem(i0); @@ -223,13 +231,13 @@ static bool ComputeZSpacingFromIPP(const DataSet &ds, double &zspacing) if( !subds.FindDataElement(tpms) ) return false; //const SequenceOfItems * sqi2 = subds.GetDataElement( tpms ).GetSequenceOfItems(); SmartPointer sqi2 = subds.GetDataElement( tpms ).GetValueAsSQ(); - assert( sqi2 ); + gdcm_assert( sqi2 ); const Item &item2 = sqi2->GetItem(1); const DataSet & subds2 = item2.GetNestedDataSet(); // Check Image Orientation (Patient) if( ImageHelper::GetDirectionCosinesFromDataSet(subds2, dircos_subds2) ) { - assert( dircos_subds2 == cosines ); + gdcm_assert( dircos_subds2 == cosines ); } // (0020,0032) DS [-82.5\-82.5\1153.75] # 20, 3 ImagePositionPatient const Tag tps(0x0020,0x0032); @@ -240,8 +248,22 @@ static bool ComputeZSpacingFromIPP(const DataSet &ds, double &zspacing) double dist = 0; for (int i = 0; i < 3; ++i) dist += normal[i]*ipp[i]; distances.push_back( dist ); + unique_distances.insert(dist); } - assert( distances.size() == nitems ); + gdcm_assert( distances.size() == nitems ); + if( unique_distances.size() != distances.size() ) + { + if( distances.size() % distances.size() == 0 ) + { + // same order ? + if( distances[0] == *unique_distances.begin() ) + { + distances.assign(unique_distances.begin(), unique_distances.end()); + nitems = unique_distances.size(); + } + } + } + double meanspacing = 0; double prev = distances[0]; for(unsigned int i = 1; i < nitems; ++i) @@ -257,7 +279,7 @@ static bool ComputeZSpacingFromIPP(const DataSet &ds, double &zspacing) if( meanspacing == 0.0 ) { // Could be a time series. Assume time spacing of 1. for now: - gdcmDebugMacro( "Assuming time series for Z-spacing" ); + gdcmWarningMacro( "Assuming time series for Z-spacing" ); meanspacing = 1.0; timeseries = true; } @@ -265,7 +287,7 @@ static bool ComputeZSpacingFromIPP(const DataSet &ds, double &zspacing) zspacing = meanspacing; if( nitems > 1 ) - assert( zspacing != 0.0 ); // technically this should not happen + gdcm_assert( zspacing != 0.0 ); // technically this should not happen if( !timeseries ) { @@ -278,7 +300,8 @@ static bool ComputeZSpacingFromIPP(const DataSet &ds, double &zspacing) if( fabs(current - zspacing) > ZTolerance ) { // For now simply gives up - gdcmErrorMacro( "This Enhanced Multiframe is not supported for now. Sorry" ); + gdcmDebugMacro( "This Enhanced Multiframe is not supported for now: " << i << " gives " << fabs(current - zspacing) ); + zspacing = 1.0; return false; } prev = distances[i]; @@ -299,7 +322,7 @@ static bool ComputeZSpacingFromIPP(const DataSet &ds, double &zspacing) if( !subds.FindDataElement(tpms) ) return true; //const SequenceOfItems * sqi2 = subds.GetDataElement( tpms ).GetSequenceOfItems(); SmartPointer sqi2 = subds.GetDataElement( tpms ).GetValueAsSQ(); - assert( sqi2 ); + gdcm_assert( sqi2 ); const Item &item2 = sqi2->GetItem(1); const DataSet & subds2 = item2.GetNestedDataSet(); // @@ -323,7 +346,7 @@ static bool GetSpacingValueFromSequence(const DataSet& ds, const Tag& tfgs, std: // //const Tag tfgs(0x5200,0x9229); //const Tag tfgs(0x5200,0x9230); - //assert( ds.FindDataElement( tfgs ) ); + //gdcm_assert( ds.FindDataElement( tfgs ) ); if( !ds.FindDataElement( tfgs ) ) return false; //const SequenceOfItems * sqi = ds.GetDataElement( tfgs ).GetSequenceOfItems(); SmartPointer sqi = ds.GetDataElement( tfgs ).GetValueAsSQ(); @@ -336,14 +359,14 @@ static bool GetSpacingValueFromSequence(const DataSet& ds, const Tag& tfgs, std: if( !subds.FindDataElement(tpms) ) return false; //const SequenceOfItems * sqi2 = subds.GetDataElement( tpms ).GetSequenceOfItems(); SmartPointer sqi2 = subds.GetDataElement( tpms ).GetValueAsSQ(); - assert( sqi2 ); + gdcm_assert( sqi2 ); const Item &item2 = sqi2->GetItem(1); const DataSet & subds2 = item2.GetNestedDataSet(); // const Tag tps(0x0028,0x0030); if( !subds2.FindDataElement(tps) ) return false; const DataElement &de = subds2.GetDataElement( tps ); - //assert( bv ); + //gdcm_assert( bv ); Attribute<0x0028,0x0030> at; at.SetFromDataElement( de ); //at.Print( std::cout ); @@ -382,7 +405,7 @@ static SmartPointer InsertOrReplaceSQ( DataSet & ds, const Tag DataElement de( tag ); de.SetVR( VR::SQ ); de.SetValue( *sqi ); - assert( de.GetVL().IsUndefined() ); + gdcm_assert( de.GetVL().IsUndefined() ); de.SetVLToUndefined(); ds.Insert( de ); } @@ -424,7 +447,7 @@ static bool GetUltraSoundSpacingValueFromSequence(const DataSet& ds, std::vector //const SequenceOfItems * sqi = ds.GetDataElement( tsqusreg ).GetSequenceOfItems(); SmartPointer sqi = ds.GetDataElement( tsqusreg ).GetValueAsSQ(); if( !sqi ) return false; - assert( sqi ); + gdcm_assert( sqi ); // Get first item: const Item &item = sqi->GetItem(1); const DataSet & subds = item.GetNestedDataSet(); @@ -434,10 +457,10 @@ static bool GetUltraSoundSpacingValueFromSequence(const DataSet& ds, std::vector Attribute<0x0018,0x602e> at2; const DataElement &de1 = subds.GetDataElement( at1.GetTag() ); at1.SetFromDataElement( de1 ); - assert( at1.GetNumberOfValues() == 1 ); + gdcm_assert( at1.GetNumberOfValues() == 1 ); const DataElement &de2 = subds.GetDataElement( at2.GetTag() ); at2.SetFromDataElement( de2 ); - assert( at2.GetNumberOfValues() == 1 ); + gdcm_assert( at2.GetNumberOfValues() == 1 ); sp.push_back( at1.GetValue() ); sp.push_back( at2.GetValue() ); @@ -542,7 +565,7 @@ std::vector ImageHelper::GetOriginValue(File const & f) if( GetOriginValueFromSequence(ds,t1, ori) || GetOriginValueFromSequence(ds, t2, ori) ) { - assert( ori.size() == 3 ); + gdcm_assert( ori.size() == 3 ); return ori; } ori.resize( 3 ); @@ -561,7 +584,7 @@ std::vector ImageHelper::GetOriginValue(File const & f) const Item &item = sqi->GetItem(1); const DataSet & subds = item.GetNestedDataSet(); const Tag timagepositionpatient(0x0020, 0x0032); - assert( subds.FindDataElement( timagepositionpatient ) ); + gdcm_assert( subds.FindDataElement( timagepositionpatient ) ); Attribute<0x0020,0x0032> at = {{0,0,0}}; // default value if empty at.SetFromDataSet( subds ); ori.resize( at.GetNumberOfValues() ); @@ -596,7 +619,7 @@ std::vector ImageHelper::GetOriginValue(File const & f) ori[1] = 0; ori[2] = 0; } - assert( ori.size() == 3 ); + gdcm_assert( ori.size() == 3 ); return ori; } @@ -675,7 +698,7 @@ std::vector ImageHelper::GetDirectionCosinesValue(File const & f) if( GetDirectionCosinesValueFromSequence(ds,t1, dircos) || GetDirectionCosinesValueFromSequence(ds, t2, dircos) ) { - assert( dircos.size() == 6 ); + gdcm_assert( dircos.size() == 6 ); return dircos; } else @@ -742,7 +765,7 @@ std::vector ImageHelper::GetDirectionCosinesValue(File const & f) dircos[5] = 0; } - assert( dircos.size() == 6 ); + gdcm_assert( dircos.size() == 6 ); return dircos; } @@ -953,7 +976,9 @@ void ImageHelper::SetDimensionsValue(File& f, const Pixmap & img) MediaStorage ms; ms.SetFromFile(f); DataSet& ds = f.GetDataSet(); - assert( MediaStorage::IsImage( ms ) ); + if (!MediaStorage::IsImage(ms)) { + gdcmWarningMacro("Wrong SOP Class"); + } { Attribute<0x0028,0x0010> rows; rows.SetValue( (uint16_t)dims[1] ); @@ -982,7 +1007,7 @@ void ImageHelper::SetDimensionsValue(File& f, const Pixmap & img) { // Only include Multi-Frame when required (not Conditional): if( ms == MediaStorage::XRayAngiographicImageStorage // A.14.3 XA Image IOD Module Table: Multi-frame C.7.6.6 C - Required if pixel data is Multi - frame Cine data - ) + ) { ds.Remove(numframes.GetTag()); } @@ -1024,7 +1049,7 @@ void ImageHelper::SetDimensionsValue(File& f, const Pixmap & img) { const DataElement &de = ds.GetDataElement( tfgs ); SmartPointer sqi = de.GetValueAsSQ(); - assert( sqi ); + gdcm_assert( sqi ); sqi->SetNumberOfItems( dims[2] ); { // Simple mechanism to avoid recomputation of Sequence Length: make @@ -1040,6 +1065,18 @@ void ImageHelper::SetDimensionsValue(File& f, const Pixmap & img) } +// We need special care to handle VR:FD -> VR:DS conversion +static double fd2ds(const double d) +{ + Element in = {{ 0 }}; + in.SetValue( d ); + std::stringstream ss; + in.Write( ss ); + Element out = {{ 0 }}; + out.Read( ss ); + return out.GetValue(); +} + std::vector ImageHelper::GetRescaleInterceptSlopeValue(File const & f) { std::vector interceptslope; @@ -1066,7 +1103,7 @@ std::vector ImageHelper::GetRescaleInterceptSlopeValue(File const & f) if( GetInterceptSlopeValueFromSequence(ds,t1, interceptslope) || GetInterceptSlopeValueFromSequence(ds,t2, interceptslope) ) { - assert( interceptslope.size() == 2 ); + gdcm_assert( interceptslope.size() == 2 ); return interceptslope; } @@ -1197,12 +1234,42 @@ std::vector ImageHelper::GetRescaleInterceptSlopeValue(File const & f) { if(dummy[0] != 0 || dummy[1] != 1) { // SIEMENS is sending MFSPLIT with Modality LUT - // Case is: MAGNETOM Prisma / syngo MR XA30A with MFSPLIT + // Case is: MAGNETOM Prisma / syngo MR XA30A with MFSPLIT interceptslope[0] = dummy[0]; interceptslope[1] = dummy[1]; gdcmDebugMacro( "Forcing Modality LUT used for MR Image Storage: [" << dummy[0] << "," << dummy[1] << "]" ); } } + else + { + // (0008,1090) LO [Gyroscan Intera ] # 16,1 Manufacturer's Model Name + // (0018,1020) LO [NT 8.1.1\MOD Conversion Tool V1.0 ] # 34,1-n Software Version(s) + const Tag trwvms(0x0040,0x9096); // Real World Value Mapping Sequence + if( ds.FindDataElement( trwvms ) ) + { + SmartPointer sqi = ds.GetDataElement( trwvms ).GetValueAsSQ(); + if( sqi ) + { + const Tag trwvlutd(0x0040,0x9212); // Real World Value LUT Data + if( ds.FindDataElement( trwvlutd ) ) + { + gdcmAssertAlwaysMacro(0); // Not supported ! + } + // don't know how to handle multiples: + gdcmAssertAlwaysMacro( sqi->GetNumberOfItems() == 1 ); + const Item &item = sqi->GetItem(1); + const DataSet & subds = item.GetNestedDataSet(); + //const Tag trwvi(0x0040,0x9224); // Real World Value Intercept + //const Tag trwvs(0x0040,0x9225); // Real World Value Slope + Attribute<0x0040,0x9224> at1 = {0}; + at1.SetFromDataSet( subds ); + Attribute<0x0040,0x9225> at2 = {1}; + at2.SetFromDataSet( subds ); + interceptslope[0] = fd2ds(at1.GetValue()); + interceptslope[1] = fd2ds(at2.GetValue()); + } + } + } } #endif } @@ -1224,7 +1291,7 @@ std::vector ImageHelper::GetRescaleInterceptSlopeValue(File const & f) } // \post condition slope can never be 0: - assert( interceptslope[1] != 0. ); + gdcm_assert( interceptslope[1] != 0. ); return interceptslope; } @@ -1307,7 +1374,7 @@ Tag ImageHelper::GetSpacingTagFromMediaStorage(MediaStorage const &ms) case MediaStorage::UltrasoundMultiFrameImageStorage: // gdcmData/US-MONO2-8-8x-execho.dcm // this should be handled somewhere else - //assert(0); + //gdcm_assert(0); gdcmWarningMacro( "FIXME" ); t = Tag(0xffff,0xffff); break; @@ -1446,7 +1513,7 @@ std::vector ImageHelper::GetSpacingValue(File const & f) if( GetSpacingValueFromSequence(ds,t1, sp) || GetSpacingValueFromSequence(ds, t2, sp) ) { - assert( sp.size() == 3 ); + gdcm_assert( sp.size() == 3 ); return sp; } // Else. @@ -1507,7 +1574,7 @@ std::vector ImageHelper::GetSpacingValue(File const & f) const Dicts &dicts = g.GetDicts(); const DictEntry &entry = dicts.GetDictEntry(de.GetTag()); const VR & vr = entry.GetVR(); - assert( vr.Compatible( de.GetVR() ) ); + gdcm_assert( vr.Compatible( de.GetVR() ) ); switch(vr) { case VR::DS: @@ -1515,7 +1582,7 @@ std::vector ImageHelper::GetSpacingValue(File const & f) Element el; std::stringstream ss; const ByteValue *bv = de.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); std::string s = std::string( bv->GetPointer(), bv->GetLength() ); ss.str( s ); // Stupid file: CT-MONO2-8-abdo.dcm @@ -1526,7 +1593,7 @@ std::vector ImageHelper::GetSpacingValue(File const & f) if( found != std::string::npos ) { el.Read( ss ); - assert( el.GetLength() == 2 ); + gdcm_assert( el.GetLength() == 2 ); for(unsigned int i = 0; i < el.GetLength(); ++i) { if( el.GetValue(i) ) @@ -1552,7 +1619,7 @@ std::vector ImageHelper::GetSpacingValue(File const & f) sp.push_back( singleval ); sp.push_back( singleval ); } - assert( sp.size() == (unsigned int)entry.GetVM() ); + gdcm_assert( sp.size() == (unsigned int)entry.GetVM() ); } break; case VR::IS: @@ -1560,7 +1627,7 @@ std::vector ImageHelper::GetSpacingValue(File const & f) Element el; std::stringstream ss; const ByteValue *bv = de.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); std::string s = std::string( bv->GetPointer(), bv->GetLength() ); ss.str( s ); el.SetLength( entry.GetVM().GetLength() * entry.GetVR().GetSizeof() ); @@ -1576,11 +1643,11 @@ std::vector ImageHelper::GetSpacingValue(File const & f) } } std::swap( sp[0], sp[1]); - assert( sp.size() == (unsigned int)entry.GetVM() ); + gdcm_assert( sp.size() == (unsigned int)entry.GetVM() ); } break; default: - assert(0); + gdcm_assert(0); break; } } @@ -1589,7 +1656,7 @@ std::vector ImageHelper::GetSpacingValue(File const & f) sp.push_back( 1.0 ); sp.push_back( 1.0 ); } - assert( sp.size() == 2 ); + gdcm_assert( sp.size() == 2 ); // Make sure multiframe: std::vector dims = ImageHelper::GetDimensionsValue( f ); @@ -1608,7 +1675,7 @@ std::vector ImageHelper::GetSpacingValue(File const & f) const Dicts &dicts = g.GetDicts(); const DictEntry &entry = dicts.GetDictEntry(de.GetTag()); const VR & vr = entry.GetVR(); - assert( de.GetVR() == vr || de.GetVR() == VR::INVALID || de.GetVR() == VR::UN ); + gdcm_assert( de.GetVR() == vr || de.GetVR() == VR::INVALID || de.GetVR() == VR::UN ); if( entry.GetVM() == VM::VM1 ) { switch(vr) @@ -1618,7 +1685,7 @@ std::vector ImageHelper::GetSpacingValue(File const & f) Element el; std::stringstream ss; const ByteValue *bv = de.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); std::string s = std::string( bv->GetPointer(), bv->GetLength() ); ss.str( s ); el.SetLength( entry.GetVM().GetLength() * entry.GetVR().GetSizeof() ); @@ -1628,18 +1695,18 @@ std::vector ImageHelper::GetSpacingValue(File const & f) const double value = el.GetValue(i); sp.push_back( value ); } - //assert( sp.size() == entry.GetVM() ); + //gdcm_assert( sp.size() == entry.GetVM() ); } break; default: - assert(0); + gdcm_assert(0); break; } } else { - assert( entry.GetVM() == VM::VM2_n ); - assert( vr == VR::DS ); + gdcm_assert( entry.GetVM() == VM::VM2_n ); + gdcm_assert( vr == VR::DS ); Attribute<0x28,0x8> numberoframes; const DataElement& de1 = ds.GetDataElement( numberoframes.GetTag() ); numberoframes.SetFromDataElement( de1 ); @@ -1658,7 +1725,7 @@ std::vector ImageHelper::GetSpacingValue(File const & f) const DataElement& de = ds.GetDataElement( Tag(0x0028,0x0009) ); Attribute<0x0028,0x0009,VR::AT,VM::VM1> at; at.SetFromDataElement( de ); - assert( ds.FindDataElement( at.GetTag() ) ); + gdcm_assert( ds.FindDataElement( at.GetTag() ) ); if( ds.FindDataElement( at.GetValue() ) ) { /* @@ -1678,13 +1745,9 @@ std::vector ImageHelper::GetSpacingValue(File const & f) { if( at2.GetValue() != 0. ) { - gdcmErrorMacro( "Number of Frame should be equal to 0" ); - sp.push_back( 0.0 ); - } - else - { - sp.push_back( 1.0 ); + gdcmErrorMacro( "Frame time for a single frame image should equal to 0, but found "<< at.GetValue() << ". Default to 1.0."); } + sp.push_back( 1.0 ); } } else @@ -1705,11 +1768,11 @@ std::vector ImageHelper::GetSpacingValue(File const & f) sp.push_back( 1.0 ); } - assert( sp.size() == 3 ); - assert( sp[0] != 0. ); - assert( sp[1] != 0. ); + gdcm_assert( sp.size() == 3 ); + gdcm_assert( sp[0] != 0. ); + gdcm_assert( sp[1] != 0. ); //if( ms != MediaStorage::MRImageStorage ) - // assert( sp[2] != 0. ); + // gdcm_assert( sp[2] != 0. ); return sp; } @@ -1717,7 +1780,9 @@ void ImageHelper::SetSpacingValue(DataSet & ds, const std::vector & spac { MediaStorage ms; ms.SetFromDataSet(ds); - assert( MediaStorage::IsImage( ms ) ); + if (!MediaStorage::IsImage(ms)) { + gdcmWarningMacro("Wrong SOP Class"); + } if( ms == MediaStorage::SecondaryCaptureImageStorage ) { Tag pixelspacing(0x0028,0x0030); @@ -1728,7 +1793,7 @@ void ImageHelper::SetSpacingValue(DataSet & ds, const std::vector & spac //ds.Remove( spacingbetweenslice ); //return; } - assert( spacing.size() == 3 ); + gdcm_assert( spacing.size() == 3 ); if( ms == MediaStorage::EnhancedCTImageStorage || ms == MediaStorage::EnhancedMRImageStorage @@ -1839,21 +1904,21 @@ void ImageHelper::SetSpacingValue(DataSet & ds, const std::vector & spac const DictEntry &entry = dicts.GetDictEntry(de.GetTag()); const VR & vr = entry.GetVR(); const VM & vm = entry.GetVM(); (void)vm; - assert( de.GetVR() == vr || de.GetVR() == VR::INVALID ); + gdcm_assert( de.GetVR() == vr || de.GetVR() == VR::INVALID ); switch(vr) { case VR::DS: { Element el; el.SetLength( entry.GetVM().GetLength() * vr.GetSizeof() ); - assert( entry.GetVM() == VM::VM2 ); + gdcm_assert( entry.GetVM() == VM::VM2 ); for( unsigned int i = 0; i < entry.GetVM().GetLength(); ++i) { el.SetValue( spacing[i], i ); } el.SetValue( spacing[1], 0 ); el.SetValue( spacing[0], 1 ); - //assert( el.GetValue(0) == spacing[0] && el.GetValue(1) == spacing[1] ); + //gdcm_assert( el.GetValue(0) == spacing[0] && el.GetValue(1) == spacing[1] ); std::stringstream os; el.Write( os ); de.SetVR( VR::DS ); @@ -1867,12 +1932,12 @@ void ImageHelper::SetSpacingValue(DataSet & ds, const std::vector & spac { Element el; el.SetLength( entry.GetVM().GetLength() * vr.GetSizeof() ); - assert( entry.GetVM() == VM::VM2 ); + gdcm_assert( entry.GetVM() == VM::VM2 ); for( unsigned int i = 0; i < entry.GetVM().GetLength(); ++i) { el.SetValue( (int)spacing[i], i ); } - //assert( el.GetValue(0) == spacing[0] && el.GetValue(1) == spacing[1] ); + //gdcm_assert( el.GetValue(0) == spacing[0] && el.GetValue(1) == spacing[1] ); std::stringstream os; el.Write( os ); de.SetVR( VR::IS ); @@ -1883,7 +1948,7 @@ void ImageHelper::SetSpacingValue(DataSet & ds, const std::vector & spac } break; default: - assert(0); + gdcm_assert(0); } } } @@ -1897,11 +1962,11 @@ void ImageHelper::SetSpacingValue(DataSet & ds, const std::vector & spac const DictEntry &entry = dicts.GetDictEntry(de.GetTag()); const VR & vr = entry.GetVR(); const VM & vm = entry.GetVM(); (void)vm; - assert( de.GetVR() == vr || de.GetVR() == VR::INVALID ); + gdcm_assert( de.GetVR() == vr || de.GetVR() == VR::INVALID ); if( entry.GetVM() == VM::VM2_n ) { - assert( vr == VR::DS ); - assert( de.GetTag() == Tag(0x3004,0x000c) ); + gdcm_assert( vr == VR::DS ); + gdcm_assert( de.GetTag() == Tag(0x3004,0x000c) ); Attribute<0x28,0x8> numberoframes; // Make we are multiframes: if( ds.FindDataElement( numberoframes.GetTag() ) ) @@ -1911,15 +1976,15 @@ void ImageHelper::SetSpacingValue(DataSet & ds, const std::vector & spac Element el; el.SetLength( numberoframes.GetValue() * vr.GetSizeof() ); - assert( entry.GetVM() == VM::VM2_n ); + gdcm_assert( entry.GetVM() == VM::VM2_n ); double spacing_start = 0; - assert( 0 < numberoframes.GetValue() ); + gdcm_assert( 0 < numberoframes.GetValue() ); for( int i = 0; i < numberoframes.GetValue(); ++i) { el.SetValue( spacing_start, i ); spacing_start += spacing[2]; } - //assert( el.GetValue(0) == spacing[0] && el.GetValue(1) == spacing[1] ); + //gdcm_assert( el.GetValue(0) == spacing[0] && el.GetValue(1) == spacing[1] ); std::stringstream os; el.Write( os ); de.SetVR( VR::DS ); @@ -1937,12 +2002,12 @@ void ImageHelper::SetSpacingValue(DataSet & ds, const std::vector & spac { Element el; el.SetLength( entry.GetVM().GetLength() * vr.GetSizeof() ); - assert( entry.GetVM() == VM::VM1 ); + gdcm_assert( entry.GetVM() == VM::VM1 ); for( unsigned int i = 0; i < entry.GetVM().GetLength(); ++i) { el.SetValue( spacing[i+2], i ); } - //assert( el.GetValue(0) == spacing[0] && el.GetValue(1) == spacing[1] ); + //gdcm_assert( el.GetValue(0) == spacing[0] && el.GetValue(1) == spacing[1] ); std::stringstream os; el.Write( os ); de.SetVR( VR::DS ); @@ -1953,7 +2018,7 @@ void ImageHelper::SetSpacingValue(DataSet & ds, const std::vector & spac } break; default: - assert(0); + gdcm_assert(0); } } } @@ -1995,10 +2060,13 @@ static void SetDataElementInSQAsItemNumber(DataSet & ds, DataElement const & de, void ImageHelper::SetOriginValue(DataSet & ds, const Image & image) { const double *origin = image.GetOrigin(); - //assert( origin.size() == 3 ); + //gdcm_assert( origin.size() == 3 ); MediaStorage ms; ms.SetFromDataSet(ds); - assert( MediaStorage::IsImage( ms ) ); + if (!MediaStorage::IsImage(ms)) { + gdcmWarningMacro("Wrong SOP Class"); + } + if( ms == MediaStorage::SecondaryCaptureImageStorage && !ImageHelper::SecondaryCaptureImagePlaneModule ) { @@ -2099,7 +2167,7 @@ void ImageHelper::SetOriginValue(DataSet & ds, const Image & image) if( ds.FindDataElement( tfgs0 ) ) { SmartPointer sqi = ds.GetDataElement( tfgs0 ).GetValueAsSQ(); - assert( sqi ); + gdcm_assert( sqi ); SequenceOfItems::SizeType nitems = sqi->GetNumberOfItems(); for(SequenceOfItems::SizeType i0 = 1; i0 <= nitems; ++i0) { @@ -2150,7 +2218,9 @@ void ImageHelper::SetDirectionCosinesValue(DataSet & ds, const std::vector iop = {{1,0,0,0,1,0}}; // default value - assert( dircos.size() == 6 ); + gdcm_assert( dircos.size() == 6 ); DirectionCosines dc( dircos.data() ); if( !dc.IsValid() ) { @@ -2266,7 +2336,7 @@ void ImageHelper::SetDirectionCosinesValue(DataSet & ds, const std::vector sqi = ds.GetDataElement( tfgs ).GetValueAsSQ(); - assert( sqi ); + gdcm_assert( sqi ); SequenceOfItems::SizeType nitems = sqi->GetNumberOfItems(); for(SequenceOfItems::SizeType i0 = 1; i0 <= nitems; ++i0) { @@ -2296,7 +2366,9 @@ void ImageHelper::SetRescaleInterceptSlopeValue(File & f, const Image & img) MediaStorage ms; // SetFromFile is required here, SetFromDataSet is not enough for all cases ms.SetFromFile(f); - assert( MediaStorage::IsImage( ms ) ); + if (!MediaStorage::IsImage(ms)) { + gdcmWarningMacro("Wrong SOP Class"); + } DataSet &ds = f.GetDataSet(); // FIXME Hardcoded @@ -2391,7 +2463,7 @@ void ImageHelper::SetRescaleInterceptSlopeValue(File & f, const Image & img) if( ds.FindDataElement( tfgs ) ) { SmartPointer sqi = ds.GetDataElement( tfgs ).GetValueAsSQ(); - assert( sqi ); + gdcm_assert( sqi ); SequenceOfItems::SizeType nitems = sqi->GetNumberOfItems(); for(SequenceOfItems::SizeType i0 = 1; i0 <= nitems; ++i0) { @@ -2535,23 +2607,23 @@ bool ImageHelper::GetRealWorldValueMappingContent(File const & f, RealWorldValue if( ms == MediaStorage::MRImageStorage || ms == MediaStorage::NuclearMedicineImageStorage ) { - const Tag trwvms(0x0040,0x9096); // Real World Value Mapping Sequence - if( ds.FindDataElement( trwvms ) ) - { - SmartPointer sqi0 = ds.GetDataElement( trwvms ).GetValueAsSQ(); - if( sqi0 ) - { - const Tag trwvlutd(0x0040,0x9212); // Real World Value LUT Data - if( ds.FindDataElement( trwvlutd ) ) - { - gdcmAssertAlwaysMacro(0); // Not supported ! - } - // don't know how to handle multiples: - gdcmAssertAlwaysMacro( sqi0->GetNumberOfItems() == 1 ); - const Item &item0 = sqi0->GetItem(1); - const DataSet & subds0 = item0.GetNestedDataSet(); - //const Tag trwvi(0x0040,0x9224); // Real World Value Intercept - //const Tag trwvs(0x0040,0x9225); // Real World Value Slope + const Tag trwvms(0x0040,0x9096); // Real World Value Mapping Sequence + if( ds.FindDataElement( trwvms ) ) + { + SmartPointer sqi0 = ds.GetDataElement( trwvms ).GetValueAsSQ(); + if( sqi0 ) + { + const Tag trwvlutd(0x0040,0x9212); // Real World Value LUT Data + if( ds.FindDataElement( trwvlutd ) ) + { + gdcmAssertAlwaysMacro(0); // Not supported ! + } + // don't know how to handle multiples: + gdcmAssertAlwaysMacro( sqi0->GetNumberOfItems() == 1 ); + const Item &item0 = sqi0->GetItem(1); + const DataSet & subds0 = item0.GetNestedDataSet(); + //const Tag trwvi(0x0040,0x9224); // Real World Value Intercept + //const Tag trwvs(0x0040,0x9225); // Real World Value Slope { Attribute<0x0040,0x9224> at1 = {0}; at1.SetFromDataSet( subds0 ); @@ -2560,26 +2632,26 @@ bool ImageHelper::GetRealWorldValueMappingContent(File const & f, RealWorldValue ret.RealWorldValueIntercept = at1.GetValue(); ret.RealWorldValueSlope = at2.GetValue(); } - const Tag tmucs(0x0040,0x08ea); // Measurement Units Code Sequence - if( subds0.FindDataElement( tmucs ) ) - { - SmartPointer sqi = subds0.GetDataElement( tmucs ).GetValueAsSQ(); - if( sqi ) - { - gdcmAssertAlwaysMacro( sqi->GetNumberOfItems() == 1 ); - const Item &item = sqi->GetItem(1); - const DataSet & subds = item.GetNestedDataSet(); - Attribute<0x0008,0x0100> at1; - at1.SetFromDataSet( subds ); - Attribute<0x0008,0x0104> at2; - at2.SetFromDataSet( subds ); - ret.CodeValue = at1.GetValue().Trim(); - ret.CodeMeaning = at2.GetValue().Trim(); - } - } - } - return true; - } + const Tag tmucs(0x0040,0x08ea); // Measurement Units Code Sequence + if( subds0.FindDataElement( tmucs ) ) + { + SmartPointer sqi = subds0.GetDataElement( tmucs ).GetValueAsSQ(); + if( sqi ) + { + gdcmAssertAlwaysMacro( sqi->GetNumberOfItems() == 1 ); + const Item &item = sqi->GetItem(1); + const DataSet & subds = item.GetNestedDataSet(); + Attribute<0x0008,0x0100> at1; + at1.SetFromDataSet( subds ); + Attribute<0x0008,0x0104> at2; + at2.SetFromDataSet( subds ); + ret.CodeValue = at1.GetValue().Trim(); + ret.CodeMeaning = at2.GetValue().Trim(); + } + } + } + return true; + } } return false; } @@ -2810,7 +2882,7 @@ SmartPointer ImageHelper::GetLUT(File const& f) // LookupTableType::RED == 0 lut->SetLUT( LookupTable::LookupTableType(i), (const unsigned char*)lut_raw->GetPointer(), lut_raw->GetLength() ); - //assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); + //gdcm_assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); } else { @@ -2820,7 +2892,7 @@ SmartPointer ImageHelper::GetLUT(File const& f) unsigned long check = (el_us3.GetValue(0) ? el_us3.GetValue(0) : 65536) * el_us3.GetValue(2) / 8; - assert( !lut->Initialized() || check == lut_raw->GetLength() ); (void)check; + gdcm_assert( !lut->Initialized() || check == lut_raw->GetLength() ); (void)check; } else if( ds.FindDataElement( seglut ) ) { @@ -2829,7 +2901,7 @@ SmartPointer ImageHelper::GetLUT(File const& f) { lut->SetLUT( LookupTable::LookupTableType(i), (const unsigned char*)lut_raw->GetPointer(), lut_raw->GetLength() ); - //assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); + //gdcm_assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); } else { @@ -2839,11 +2911,11 @@ SmartPointer ImageHelper::GetLUT(File const& f) //unsigned long check = // (el_us3.GetValue(0) ? el_us3.GetValue(0) : 65536) // * el_us3.GetValue(2) / 8; - //assert( check == lut_raw->GetLength() ); (void)check; + //gdcm_assert( check == lut_raw->GetLength() ); (void)check; } else { - assert(0); + gdcm_assert(0); } } if( ! lut->Initialized() ) { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageReader.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageReader.cxx index cd945aa959f..bc8e1aae6fb 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageReader.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageReader.cxx @@ -67,7 +67,7 @@ bool ImageReader::ReadImage(MediaStorage const &ms) // FIXME: Only SC is allowed not to have spacing: if( !spacing.empty() ) { - assert( spacing.size() >= pixeldata.GetNumberOfDimensions() ); // In MR, you can have a Z spacing, but store a 2D image + gdcm_assert( spacing.size() >= pixeldata.GetNumberOfDimensions() ); // In MR, you can have a Z spacing, but store a 2D image pixeldata.SetSpacing( spacing.data() ); if( spacing.size() > pixeldata.GetNumberOfDimensions() ) // FIXME HACK { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageRegionReader.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageRegionReader.cxx index 250967e32b2..bc8ff458649 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageRegionReader.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageRegionReader.cxx @@ -41,7 +41,7 @@ class ImageRegionReaderInternals { delete TheRegion; TheRegion = r.Clone(); - assert( TheRegion ); + gdcm_assert( TheRegion ); Modified = true; } Region *GetRegion() const @@ -144,7 +144,7 @@ bool ImageRegionReader::ReadInformation() return false; } std::streampos fileoffset = GetStreamPtr()->tellg(); - assert( fileoffset != std::streampos(-1) ); + gdcm_assert( fileoffset != std::streampos(-1) ); Internals->SetFileOffset( fileoffset ); const File &file = GetFile(); @@ -153,7 +153,7 @@ bool ImageRegionReader::ReadInformation() MediaStorage ms; ms.SetFromFile(file); - assert( ms != MediaStorage::VLWholeSlideMicroscopyImageStorage ); + gdcm_assert( ms != MediaStorage::VLWholeSlideMicroscopyImageStorage ); if( !MediaStorage::IsImage( ms ) ) { gdcmDebugMacro( "Not an image recognized. Giving up"); @@ -173,7 +173,7 @@ bool ImageRegionReader::ReadInformation() // FIXME: Only SC is allowed not to have spacing: if( !spacing.empty() ) { - assert( spacing.size() >= pixeldata.GetNumberOfDimensions() ); // In MR, you can have a Z spacing, but store a 2D image + gdcm_assert( spacing.size() >= pixeldata.GetNumberOfDimensions() ); // In MR, you can have a Z spacing, but store a 2D image pixeldata.SetSpacing( spacing.data() ); if( spacing.size() > pixeldata.GetNumberOfDimensions() ) // FIXME HACK { @@ -252,8 +252,8 @@ bool ImageRegionReader::ReadRAWIntoBuffer(char *buffer, size_t buflen) unsigned int ymax = boundingbox.GetYMax(); unsigned int zmin = boundingbox.GetZMin(); unsigned int zmax = boundingbox.GetZMax(); - assert( xmax >= xmin ); - assert( ymax >= ymin ); + gdcm_assert( xmax >= xmin ); + gdcm_assert( ymax >= ymin ); unsigned int rowsize = xmax - xmin + 1; unsigned int colsize = ymax - ymin + 1; unsigned int bytesPerPixel = pixelInfo.GetPixelSize(); @@ -281,8 +281,8 @@ bool ImageRegionReader::ReadRAWIntoBuffer(char *buffer, size_t buflen) } #if 0 const char * check = &(buffer[((z-zmin)*rowsize*colsize + (y-ymin)*rowsize)*bytesPerPixel]); - assert( check >= buffer && check < buffer + buflen ); - assert( check + rowsize*bytesPerPixel <= buffer + buflen ); + gdcm_assert( check >= buffer && check < buffer + buflen ); + gdcm_assert( check + rowsize*bytesPerPixel <= buffer + buflen ); #endif memcpy(&(buffer[((z-zmin)*rowsize*colsize + (y-ymin)*rowsize)*bytesPerPixel]), tmpBuffer2, rowsize*bytesPerPixel); @@ -326,8 +326,8 @@ bool ImageRegionReader::ReadRLEIntoBuffer(char *buffer, size_t buflen) unsigned int zmin = boundingbox.GetZMin(); unsigned int zmax = boundingbox.GetZMax(); - assert( xmax >= xmin ); - assert( ymax >= ymin ); + gdcm_assert( xmax >= xmin ); + gdcm_assert( ymax >= ymin ); bool ret = theCodec.DecodeExtent( buffer, @@ -375,8 +375,8 @@ bool ImageRegionReader::ReadJPEG2000IntoBuffer(char *buffer, size_t buflen) unsigned int zmin = boundingbox.GetZMin(); unsigned int zmax = boundingbox.GetZMax(); - assert( xmax >= xmin ); - assert( ymax >= ymin ); + gdcm_assert( xmax >= xmin ); + gdcm_assert( ymax >= ymin ); bool ret = theCodec.DecodeExtent( buffer, @@ -425,8 +425,8 @@ bool ImageRegionReader::ReadJPEGIntoBuffer(char *buffer, size_t buflen) unsigned int zmin = boundingbox.GetZMin(); unsigned int zmax = boundingbox.GetZMax(); - assert( xmax >= xmin ); - assert( ymax >= ymin ); + gdcm_assert( xmax >= xmin ); + gdcm_assert( ymax >= ymin ); bool ret = theCodec.DecodeExtent( buffer, @@ -474,8 +474,8 @@ bool ImageRegionReader::ReadJPEGLSIntoBuffer(char *buffer, size_t buflen) unsigned int zmin = boundingbox.GetZMin(); unsigned int zmax = boundingbox.GetZMax(); - assert( xmax >= xmin ); - assert( ymax >= ymin ); + gdcm_assert( xmax >= xmin ); + gdcm_assert( ymax >= ymin ); bool ret = theCodec.DecodeExtent( buffer, @@ -502,7 +502,7 @@ bool ImageRegionReader::ReadIntoBuffer(char *buffer, size_t buflen) gdcmDebugMacro( "buffer cannot be smaller than computed buffer length" ); return false; } - assert( Internals->GetFileOffset() != std::streampos(-1) ); + gdcm_assert( Internals->GetFileOffset() != std::streampos(-1) ); gdcmDebugMacro( "Using FileOffset: " << Internals->GetFileOffset() ); std::istream* theStream = GetStreamPtr(); theStream->seekg( Internals->GetFileOffset() ); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageWriter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageWriter.cxx index 0ee790670e2..aa9b0efc19c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageWriter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmImageWriter.cxx @@ -77,7 +77,7 @@ bool ImageWriter::Write() const MediaStorage ms = ComputeTargetMediaStorage(); if( !PrepareWrite( ms ) ) return false; - //assert( Stream.is_open() ); + //gdcm_assert( Stream.is_open() ); File& file = GetFile(); DataSet& ds = file.GetDataSet(); @@ -121,7 +121,7 @@ bool ImageWriter::Write() char date[22]; const size_t datelen = 8; int res = System::GetCurrentDateTime(date); - assert( res ); + gdcm_assert( res ); (void)res;//warning removal if( !ds.FindDataElement( Tag(0x0008,0x0020) ) ) { @@ -177,7 +177,7 @@ bool ImageWriter::Write() ds.Insert( de ); } - assert( ms != MediaStorage::MS_END ); + gdcm_assert( ms != MediaStorage::MS_END ); // Patient Orientation if( ms == MediaStorage::SecondaryCaptureImageStorage && !ds.FindDataElement( Tag(0x0020,0x0020) ) ) @@ -204,18 +204,18 @@ bool ImageWriter::Write() if( bv ) { modality2 = std::string( bv->GetPointer(), bv->GetLength() ); - //assert( modality2.find( ' ' ) == std::string::npos ); // no space ... + //gdcm_assert( modality2.find( ' ' ) == std::string::npos ); // no space ... } else { // remove empty Modality, and set a new one... ds.Remove( Tag(0x0008, 0x0060 ) ); // Modality is Type 1 ! - assert( ms != MediaStorage::MS_END ); + gdcm_assert( ms != MediaStorage::MS_END ); } /* if( modality2 != ms.GetModality() ) { - assert( std::string(ms.GetModality()).find( ' ' ) == std::string::npos ); // no space ... + gdcm_assert( std::string(ms.GetModality()).find( ' ' ) == std::string::npos ); // no space ... DataElement de( Tag(0x0008, 0x0060 ) ); de.SetByteValue( ms.GetModality(), strlen(ms.GetModality()) ); de.SetVR( Attribute<0x0008, 0x0060>::GetVR() ); @@ -246,8 +246,12 @@ bool ImageWriter::Write() // Do the Rescale Intercept & Slope if( pi == PhotometricInterpretation::MONOCHROME1 || pi == PhotometricInterpretation::MONOCHROME2 ) { - assert( pf.GetSamplesPerPixel() == 1 ); - ImageHelper::SetRescaleInterceptSlopeValue(GetFile(), pixeldata); + gdcm_assert( pf.GetSamplesPerPixel() == 1 ); + try { + ImageHelper::SetRescaleInterceptSlopeValue(GetFile(), pixeldata); + } catch( const char * ) { + return false; + } if( ms == MediaStorage::RTDoseStorage && pixeldata.GetIntercept() != 0 ) { return false; @@ -282,8 +286,8 @@ bool ImageWriter::Write() if ( pi == PhotometricInterpretation::PALETTE_COLOR ) { const LookupTable &lut = PixelData->GetLUT(); - assert( lut.Initialized() ); -// assert( (pf.GetBitsAllocated() == 8 && pf.GetPixelRepresentation() == 0) + gdcm_assert( lut.Initialized() ); +// gdcm_assert( (pf.GetBitsAllocated() == 8 && pf.GetPixelRepresentation() == 0) // || (pf.GetBitsAllocated() == 16 && pf.GetPixelRepresentation() == 0) ); // lut descriptor: // (0028,1101) US 256\0\16 # 6, 3 RedPaletteColorLookupTableDescriptor @@ -415,7 +419,7 @@ Attribute<0x0028,0x0004> piat; ImageHelper::SetOriginValue(ds, pixeldata); } - assert( Stream ); + gdcm_assert( Stream ); if( !Writer::Write() ) { return false; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEG2000Codec.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEG2000Codec.cxx index 10e0a756bae..e82217d3d79 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEG2000Codec.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEG2000Codec.cxx @@ -209,7 +209,7 @@ static bool parsejp2_imp( const char * const stream, const size_t file_size, boo if( len32 == 1 ) /* 64bits ? */ { bool b = read64(&cur, &cur_size, &len64); - assert( b ); (void)b; + gdcm_assert(b); (void)b; len64 -= 8; } if( marker == JP2C ) @@ -219,7 +219,7 @@ static bool parsejp2_imp( const char * const stream, const size_t file_size, boo { len64 = (size_t)(file_size - start + 8); } - assert( len64 >= 8 ); + gdcm_assert( len64 >= 8 ); return parsej2k_imp( cur, (size_t)(len64 - 8), lossless, mct ); } const size_t lenmarker = (size_t)(len64 - 8); @@ -293,11 +293,11 @@ OPJ_SIZE_T opj_read_from_memory(void * p_buffer, OPJ_SIZE_T p_nb_bytes, myfile* else { l_nb_read = (OPJ_SIZE_T)(p_file->mem + p_file->len - p_file->cur); - assert( l_nb_read < p_nb_bytes ); + gdcm_assert( l_nb_read < p_nb_bytes ); } memcpy(p_buffer,p_file->cur,l_nb_read); p_file->cur += l_nb_read; - assert( p_file->cur <= p_file->mem + p_file->len ); + gdcm_assert( p_file->cur <= p_file->mem + p_file->len ); //std::cout << "l_nb_read: " << l_nb_read << std::endl; return l_nb_read ? l_nb_read : ((OPJ_SIZE_T)-1); } @@ -313,12 +313,12 @@ OPJ_SIZE_T opj_write_from_memory (void * p_buffer, OPJ_SIZE_T p_nb_bytes, myfile //else // { // l_nb_write = p_file->mem + p_file->len - p_file->cur; - // assert( l_nb_write < p_nb_bytes ); + // gdcm_assert( l_nb_write < p_nb_bytes ); // } memcpy(p_file->cur,p_buffer,l_nb_write); p_file->cur += l_nb_write; p_file->len += l_nb_write; - //assert( p_file->cur < p_file->mem + p_file->len ); + //gdcm_assert( p_file->cur < p_file->mem + p_file->len ); return l_nb_write; //return p_nb_bytes; } @@ -346,7 +346,7 @@ OPJ_BOOL opj_seek_from_memory (OPJ_OFF_T p_nb_bytes, myfile * p_file) // return false; // } //return true; - assert( p_nb_bytes >= 0 ); + gdcm_assert( p_nb_bytes >= 0 ); if( (size_t)p_nb_bytes <= p_file->len ) { p_file->cur = p_file->mem + p_nb_bytes; @@ -376,7 +376,7 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_memory_stream (myfile* p_mem,OPJ_SI opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_memory); opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_memory); opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_memory); - opj_stream_set_user_data_length(l_stream, p_mem->len /* p_size*/); /* important to avoid an assert() */ + opj_stream_set_user_data_length(l_stream, p_mem->len /* p_size*/); /* important to avoid an gdcm_assert() */ return l_stream; } @@ -493,7 +493,10 @@ bool JPEG2000Codec::CanDecode(TransferSyntax const &ts) const return ts == TransferSyntax::JPEG2000Lossless || ts == TransferSyntax::JPEG2000 || ts == TransferSyntax::JPEG2000Part2Lossless - || ts == TransferSyntax::JPEG2000Part2; + || ts == TransferSyntax::JPEG2000Part2 + || ts == TransferSyntax::HTJ2KLossless + || ts == TransferSyntax::HTJ2KRPCLLossless + || ts == TransferSyntax::HTJ2K; } bool JPEG2000Codec::CanCode(TransferSyntax const &ts) const @@ -525,7 +528,7 @@ bool JPEG2000Codec::Decode(DataElement const &in, DataElement &out) if ( j2kbv ) { gdcmWarningMacro( "Pixel Data is not encapsulated correctly. Continuing anyway" ); - assert( !sf ); + gdcm_assert( !sf ); std::stringstream is; size_t j2kbv_len = j2kbv->GetLength(); char *mybuffer = new char[j2kbv_len]; @@ -588,10 +591,10 @@ bool JPEG2000Codec::Decode(DataElement const &in, DataElement &out) delete[] mybuffer; bool r = DecodeByStreams(is, os); if(!r) return false; - assert( r == true ); + gdcm_assert( r == true ); } std::string str = os.str(); - assert( !str.empty() ); + gdcm_assert( !str.empty() ); out.SetByteValue( str.data(), (uint32_t)str.size() ); return true; @@ -661,16 +664,16 @@ std::pair JPEG2000Codec::DecodeByStreamsCommon(char *dummy_buffe // gdcmData/MAROTECH_CT_JP2Lossy.dcm gdcmWarningMacro( "J2K start like JPEG-2000 compressed image data instead of codestream" ); parameters.decod_format = JP2_CFMT; - assert(parameters.decod_format == JP2_CFMT); + gdcm_assert(parameters.decod_format == JP2_CFMT); } else { /* JPEG-2000 codestream */ parameters.decod_format = J2K_CFMT; - assert(parameters.decod_format == J2K_CFMT); + gdcm_assert(parameters.decod_format == J2K_CFMT); } parameters.cod_format = PGX_DFMT; - assert(parameters.cod_format == PGX_DFMT); + gdcm_assert(parameters.cod_format == PGX_DFMT); /* get a decoder handle */ switch(parameters.decod_format) @@ -760,17 +763,17 @@ std::pair JPEG2000Codec::DecodeByStreamsCommon(char *dummy_buffe { if( image->color_space == CLRSPC_GRAY ) { - assert( this->GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME2 + gdcm_assert( this->GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME2 || this->GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME1 || this->GetPhotometricInterpretation() == PhotometricInterpretation::PALETTE_COLOR ); } else if( image->color_space == CLRSPC_SRGB ) { - assert( this->GetPhotometricInterpretation() == PhotometricInterpretation::RGB ); + gdcm_assert( this->GetPhotometricInterpretation() == PhotometricInterpretation::RGB ); } else { - assert(0); + gdcm_assert(0); } } #endif @@ -789,8 +792,8 @@ std::pair JPEG2000Codec::DecodeByStreamsCommon(char *dummy_buffe } LossyFlag = !reversible; - assert( image->numcomps == this->GetPixelFormat().GetSamplesPerPixel() ); - assert( image->numcomps == this->GetPhotometricInterpretation().GetSamplesPerPixel() ); + gdcm_assert( image->numcomps == this->GetPixelFormat().GetSamplesPerPixel() ); + gdcm_assert( image->numcomps == this->GetPhotometricInterpretation().GetSamplesPerPixel() ); if( this->GetPhotometricInterpretation() == PhotometricInterpretation::RGB || this->GetPhotometricInterpretation() == PhotometricInterpretation::YBR_FULL ) { @@ -812,7 +815,7 @@ std::pair JPEG2000Codec::DecodeByStreamsCommon(char *dummy_buffe // Copy buffer unsigned long len = Dimensions[0]*Dimensions[1] * (PF.GetBitsAllocated() / 8) * image->numcomps; char *raw = new char[len]; - //assert( len == fsrc->len ); + //gdcm_assert( len == fsrc->len ); for (unsigned int compno = 0; compno < (unsigned int)image->numcomps; compno++) { opj_image_comp_t *comp = &image->comps[compno]; @@ -822,7 +825,7 @@ std::pair JPEG2000Codec::DecodeByStreamsCommon(char *dummy_buffe //int h = image.comps[compno].h; int hr = int_ceildivpow2(image->comps[compno].h, image->comps[compno].factor); - //assert( wr * hr * 1 * image->numcomps * (comp->prec/8) == len ); + //gdcm_assert( wr * hr * 1 * image->numcomps * (comp->prec/8) == len ); // ELSCINT1_JP2vsJ2K.dcm // -> prec = 12, bpp = 0, sgnd = 0 @@ -838,10 +841,10 @@ std::pair JPEG2000Codec::DecodeByStreamsCommon(char *dummy_buffe PF.SetPixelRepresentation( (uint16_t)comp->sgnd ); } #ifndef GDCM_SUPPORT_BROKEN_IMPLEMENTATION - assert( comp->prec == PF.GetBitsStored()); // D_CLUNIE_RG3_JPLY.dcm - assert( comp->prec - 1 == PF.GetHighBit()); + gdcm_assert( comp->prec == PF.GetBitsStored()); // D_CLUNIE_RG3_JPLY.dcm + gdcm_assert( comp->prec - 1 == PF.GetHighBit()); #endif - //assert( comp->prec >= PF.GetBitsStored()); + //gdcm_assert( comp->prec >= PF.GetBitsStored()); if( comp->prec != PF.GetBitsStored() ) { if( comp->prec <= 8 ) @@ -853,8 +856,8 @@ std::pair JPEG2000Codec::DecodeByStreamsCommon(char *dummy_buffe PF.SetBitsStored( (unsigned short)comp->prec ); PF.SetHighBit( (unsigned short)(comp->prec - 1) ); // ?? } - assert( PF.IsValid() ); - assert( comp->prec <= 32 ); + gdcm_assert( PF.IsValid() ); + gdcm_assert( comp->prec <= 32 ); if (comp->prec <= 8) { @@ -1061,7 +1064,7 @@ opj_image_t* rawtoimage(const char *inputbuffer8, opj_cparameters_t *parameters, opj_image_t * image = nullptr; const void * inputbuffer = inputbuffer8; - assert( sample_pixel == 1 || sample_pixel == 3 ); + gdcm_assert( sample_pixel == 1 || sample_pixel == 3 ); if( sample_pixel == 1 ) { numcomps = 1; @@ -1078,9 +1081,9 @@ opj_image_t* rawtoimage(const char *inputbuffer8, opj_cparameters_t *parameters, gdcmDebugMacro( "BitsAllocated is not % 8" ); return nullptr; } - assert( bitsallocated % 8 == 0 ); + gdcm_assert( bitsallocated % 8 == 0 ); // eg. fragment_size == 63532 and 181 * 117 * 3 * 8 == 63531 ... - assert( ((fragment_size + 1)/2 ) * 2 == (((size_t)image_height * image_width * numcomps * (bitsallocated/8) + 1)/ 2 )* 2 ); + gdcm_assert( ((fragment_size + 1)/2 ) * 2 == (((size_t)image_height * image_width * numcomps * (bitsallocated/8) + 1)/ 2 )* 2 ); int subsampling_dx = parameters->subsampling_dx; int subsampling_dy = parameters->subsampling_dy; @@ -1090,7 +1093,7 @@ opj_image_t* rawtoimage(const char *inputbuffer8, opj_cparameters_t *parameters, /* initialize image components */ memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t)); - //assert( bitsallocated == 8 ); + //gdcm_assert( bitsallocated == 8 ); for(int i = 0; i < numcomps; i++) { cmptparm[i].prec = bitsstored; cmptparm[i].prec = bitsallocated; // FIXME @@ -1115,7 +1118,7 @@ opj_image_t* rawtoimage(const char *inputbuffer8, opj_cparameters_t *parameters, /* set image data */ - //assert( fragment_size == numcomps*w*h*(bitsallocated/8) ); + //gdcm_assert( fragment_size == numcomps*w*h*(bitsallocated/8) ); if (bitsallocated <= 8) { if( sign ) @@ -1389,12 +1392,12 @@ bool JPEG2000Codec::Code(DataElement const &in, DataElement &out) if( !b ) return false; Fragment frag; - assert( cbyteCompressed <= rgbyteCompressed.size() ); // default alloc would be bogus + gdcm_assert( cbyteCompressed <= rgbyteCompressed.size() ); // default alloc would be bogus frag.SetByteValue( rgbyteCompressed.data(), (uint32_t)cbyteCompressed ); sq->AddFragment( frag ); } - assert( sq->GetNumberOfFragments() == dims[2] ); + gdcm_assert( sq->GetNumberOfFragments() == dims[2] ); out.SetValue( *sq ); return true; @@ -1420,6 +1423,8 @@ bool JPEG2000Codec::GetHeaderInfo(const char * dummy_buffer, size_t buf_size, Tr opj_stream_t *cio = nullptr; opj_image_t *image = nullptr; const unsigned char *src = (const unsigned char*)dummy_buffer; + if(!src) + return false ; size_t file_length = buf_size; /* set decoding parameters to default values */ @@ -1432,16 +1437,16 @@ bool JPEG2000Codec::GetHeaderInfo(const char * dummy_buffer, size_t buf_size, Tr // gdcmData/ELSCINT1_JP2vsJ2K.dcm gdcmWarningMacro( "J2K start like JPEG-2000 compressed image data instead of codestream" ); parameters.decod_format = JP2_CFMT; - assert(parameters.decod_format == JP2_CFMT); + gdcm_assert(parameters.decod_format == JP2_CFMT); } else { /* JPEG-2000 codestream */ parameters.decod_format = J2K_CFMT; - assert(parameters.decod_format == J2K_CFMT); + gdcm_assert(parameters.decod_format == J2K_CFMT); } parameters.cod_format = PGX_DFMT; - assert(parameters.cod_format == PGX_DFMT); + gdcm_assert(parameters.cod_format == PGX_DFMT); /* get a decoder handle */ switch(parameters.decod_format ) @@ -1503,9 +1508,9 @@ bool JPEG2000Codec::GetHeaderInfo(const char * dummy_buffer, size_t buf_size, Tr int mct = 0; #if 0 reversible = opj_get_reversible(dinfo, ¶meters ); - assert( reversible == 0 || reversible == 1 ); + gdcm_assert( reversible == 0 || reversible == 1 ); // FIXME - assert( mct == 0 || mct == 1 ); + gdcm_assert( mct == 0 || mct == 1 ); #else bool b = false; bool lossless = false; @@ -1566,13 +1571,13 @@ bool JPEG2000Codec::GetHeaderInfo(const char * dummy_buffer, size_t buf_size, Tr // color space info: // - gdcmData/MAROTECH_CT_JP2Lossy.dcm // - gdcmData/D_CLUNIE_CT1_J2KI.dcm -> color_space = 32767 - //assert( image->color_space == 0 || image->color_space == CLRSPC_GRAY ); + //gdcm_assert( image->color_space == 0 || image->color_space == CLRSPC_GRAY ); PI = PhotometricInterpretation::MONOCHROME2; this->PF.SetSamplesPerPixel( 1 ); } else if( image->numcomps == 3 ) { - //assert( image->color_space == 0 ); + //gdcm_assert( image->color_space == 0 ); //PI = PhotometricInterpretation::RGB; /* 8.2.4 JPEG 2000 IMAGE COMPRESSION @@ -1623,7 +1628,7 @@ bool JPEG2000Codec::GetHeaderInfo(const char * dummy_buffer, size_t buf_size, Tr return false; } - assert( PI != PhotometricInterpretation::UNKNOWN ); + gdcm_assert( PI != PhotometricInterpretation::UNKNOWN ); bool bmct = false; if( bmct ) @@ -1659,15 +1664,15 @@ bool JPEG2000Codec::GetHeaderInfo(const char * dummy_buffer, size_t buf_size, Tr } } - //assert( ts.IsLossy() == this->GetPhotometricInterpretation().IsLossy() ); - //assert( ts.IsLossless() == this->GetPhotometricInterpretation().IsLossless() ); + //gdcm_assert( ts.IsLossy() == this->GetPhotometricInterpretation().IsLossy() ); + //gdcm_assert( ts.IsLossless() == this->GetPhotometricInterpretation().IsLossless() ); if( this->GetPhotometricInterpretation().IsLossy() ) { - assert( ts.IsLossy() ); + gdcm_assert( ts.IsLossy() ); } if( ts.IsLossless() && !ts.IsLossy() ) { - assert( this->GetPhotometricInterpretation().IsLossless() ); + gdcm_assert( this->GetPhotometricInterpretation().IsLossless() ); } /* close the byte stream */ @@ -1699,9 +1704,9 @@ bool JPEG2000Codec::DecodeExtent( const unsigned int * dimensions = this->GetDimensions(); // retrieve pixel format *after* DecodeByStreamsCommon ! const PixelFormat pf = this->GetPixelFormat(); // make a copy ! - assert( pf.GetBitsAllocated() % 8 == 0 ); - assert( pf != PixelFormat::SINGLEBIT ); - assert( pf != PixelFormat::UINT12 && pf != PixelFormat::INT12 ); + gdcm_assert( pf.GetBitsAllocated() % 8 == 0 ); + gdcm_assert( pf != PixelFormat::SINGLEBIT ); + gdcm_assert( pf != PixelFormat::UINT12 && pf != PixelFormat::INT12 ); if( NumberOfDimensions == 2 ) { @@ -1724,9 +1729,9 @@ bool JPEG2000Codec::DecodeExtent( // read J2K is.read( &vdummybuffer[oldlen], fraglen ); } - assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); - assert( zmin == zmax ); - assert( zmin == 0 ); + gdcm_assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); + gdcm_assert( zmin == zmax ); + gdcm_assert( zmin == 0 ); std::pair raw_len = this->DecodeByStreamsCommon(dummy_buffer, buf_size); if( !raw_len.first || !raw_len.second ) return false; @@ -1772,14 +1777,14 @@ bool JPEG2000Codec::DecodeExtent( while( frag.ReadPreValue(is) && frag.GetTag() != seqDelItem ) { //std::streamoff relstart = is.tellg(); - //assert( relstart - thestart == 8 ); + //gdcm_assert( relstart - thestart == 8 ); std::streamoff off = frag.GetVL(); offsets.push_back( (size_t)off ); is.seekg( off, std::ios::cur ); ++numfrags; } - assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); - assert( numfrags == offsets.size() ); + gdcm_assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); + gdcm_assert( numfrags == offsets.size() ); if( numfrags != Dimensions[2] ) { gdcmErrorMacro( "Not handled" ); @@ -1859,7 +1864,7 @@ bool JPEG2000Codec::AppendFrameEncode( std::ostream & out, const char * data, si { const unsigned int * dimensions = this->GetDimensions(); const PixelFormat & pf = this->GetPixelFormat(); - assert( datalen == dimensions[0] * dimensions[1] * pf.GetPixelSize() ); (void)pf; + gdcm_assert( datalen == dimensions[0] * dimensions[1] * pf.GetPixelSize() ); (void)pf; std::vector rgbyteCompressed; rgbyteCompressed.resize(dimensions[0] * dimensions[1] * 4); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEGBITSCodec.hxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEGBITSCodec.hxx index 5a08842681b..0313fd2aacc 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEGBITSCodec.hxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEGBITSCodec.hxx @@ -130,7 +130,7 @@ fill_input_buffer (j_decompress_ptr cinfo) } std::streamsize gcount = src->infile->gcount(); - assert(gcount < INT_MAX); + gdcm_assert(gcount < INT_MAX); nbytes = (size_t)gcount; if (gcount <= 0) { @@ -341,8 +341,8 @@ bool JPEGBITSCodec::GetHeaderInfo(std::istream &is, TransferSyntax &ts) if ( jerr.pub.msg_code == JERR_BAD_PRECISION /* 18 */ ) { this->BitSample = jerr.pub.msg_parm.i[0]; - assert( this->BitSample == 1 || this->BitSample == 8 || this->BitSample == 12 || this->BitSample == 16 ); - assert( this->BitSample == cinfo.data_precision ); + gdcm_assert( this->BitSample == 1 || this->BitSample == 8 || this->BitSample == 12 || this->BitSample == 16 ); + gdcm_assert( this->BitSample == cinfo.data_precision ); } jpeg_destroy_decompress(&cinfo); // TODO: www.dcm4che.org/jira/secure/attachment/10185/ct-implicit-little.dcm @@ -383,7 +383,7 @@ bool JPEGBITSCodec::GetHeaderInfo(std::istream &is, TransferSyntax &ts) } else { - assert( 0 ); + gdcm_assert( 0 ); } } this->Dimensions[1] = cinfo.image_height; /* Number of rows in image */ @@ -413,11 +413,11 @@ bool JPEGBITSCodec::GetHeaderInfo(std::istream &is, TransferSyntax &ts) } else { - assert( 0 ); + gdcm_assert( 0 ); } this->PF.SetPixelRepresentation( (uint16_t)prep ); this->PF.SetBitsStored( (uint16_t)precision ); - assert( (precision - 1) >= 0 ); + gdcm_assert( (precision - 1) >= 0 ); this->PF.SetHighBit( (uint16_t)(precision - 1) ); this->PlanarConfiguration = 0; @@ -444,24 +444,24 @@ bool JPEGBITSCodec::GetHeaderInfo(std::istream &is, TransferSyntax &ts) } else { - assert( 0 ); + gdcm_assert( 0 ); } } else if( cinfo.jpeg_color_space == JCS_GRAYSCALE ) { - assert( cinfo.num_components == 1 ); + gdcm_assert( cinfo.num_components == 1 ); PI = PhotometricInterpretation::MONOCHROME2; this->PF.SetSamplesPerPixel( 1 ); } else if( cinfo.jpeg_color_space == JCS_RGB ) { - assert( cinfo.num_components == 3 ); + gdcm_assert( cinfo.num_components == 3 ); PI = PhotometricInterpretation::RGB; this->PF.SetSamplesPerPixel( 3 ); } else if( cinfo.jpeg_color_space == JCS_YCbCr ) { - assert( cinfo.num_components == 3 ); + gdcm_assert( cinfo.num_components == 3 ); PI = PhotometricInterpretation::YBR_FULL_422; if( cinfo.process == JPROC_LOSSLESS ) PI = PhotometricInterpretation::RGB; // wotsit ? @@ -470,20 +470,20 @@ bool JPEGBITSCodec::GetHeaderInfo(std::istream &is, TransferSyntax &ts) } else if( cinfo.jpeg_color_space == JCS_CMYK ) { - assert( cinfo.num_components == 4 ); + gdcm_assert( cinfo.num_components == 4 ); PI = PhotometricInterpretation::CMYK; this->PF.SetSamplesPerPixel( 4 ); } else if( cinfo.jpeg_color_space == JCS_YCCK ) { - assert( cinfo.num_components == 4 ); + gdcm_assert( cinfo.num_components == 4 ); gdcmWarningMacro( "JCS_YCCK is not handled. Setting to CMYK for now." ); PI = PhotometricInterpretation::CMYK; // non-sense...oh well this->PF.SetSamplesPerPixel( 4 ); } else { - assert( 0 ); //TODO + gdcm_assert( 0 ); //TODO } } if( cinfo.process == JPROC_LOSSLESS ) @@ -519,13 +519,13 @@ bool JPEGBITSCodec::GetHeaderInfo(std::istream &is, TransferSyntax &ts) } else { - assert(0); // TODO + gdcm_assert(0); // TODO return false; } } else { - assert(0); // TODO + gdcm_assert(0); // TODO return false; } if( cinfo.process == JPROC_LOSSLESS ) @@ -573,7 +573,7 @@ UINT16 Y_density } break; case JCS_RGB: - assert( GetPhotometricInterpretation() == PhotometricInterpretation::RGB ); + gdcm_assert( GetPhotometricInterpretation() == PhotometricInterpretation::RGB ); break; case JCS_YCbCr: if( GetPhotometricInterpretation() != PhotometricInterpretation::YBR_FULL && @@ -597,11 +597,11 @@ UINT16 Y_density } break; default: - assert(0); + gdcm_assert(0); return false; } - //assert( cinfo.data_precision == BITS_IN_JSAMPLE ); - //assert( cinfo.data_precision == this->BitSample ); + //gdcm_assert( cinfo.data_precision == BITS_IN_JSAMPLE ); + //gdcm_assert( cinfo.data_precision == this->BitSample ); /* Step 4: set parameters for decompression */ /* no op */ @@ -731,7 +731,7 @@ bool JPEGBITSCodec::DecodeByStreams(std::istream &is, std::ostream &os) if ( jerr.pub.msg_code == JERR_BAD_PRECISION /* 18 */ ) { this->BitSample = jerr.pub.msg_parm.i[0]; - //assert( this->BitSample == 8 || this->BitSample == 12 || this->BitSample == 16 ); + //gdcm_assert( this->BitSample == 8 || this->BitSample == 12 || this->BitSample == 16 ); } jpeg_destroy_decompress(&cinfo); // TODO: www.dcm4che.org/jira/secure/attachment/10185/ct-implicit-little.dcm @@ -773,13 +773,13 @@ bool JPEGBITSCodec::DecodeByStreams(std::istream &is, std::ostream &os) // LJPEG_BuginGDCM12.dcm gdcmDebugMacro( "JWRN_MUST_DOWNSCALE" ); this->BitSample = jerr.pub.msg_parm.i[0]; - assert( cinfo.data_precision == this->BitSample ); + gdcm_assert( cinfo.data_precision == this->BitSample ); jpeg_destroy_decompress(&cinfo); return false; } else { - assert( 0 ); + gdcm_assert( 0 ); } } // Let's check the color space: @@ -806,8 +806,8 @@ bool JPEGBITSCodec::DecodeByStreams(std::istream &is, std::ostream &os) */ return false; } - assert( cinfo.image_width == dims[0] ); - assert( cinfo.image_height == dims[1] ); + gdcm_assert( cinfo.image_width == dims[0] ); + gdcm_assert( cinfo.image_height == dims[1] ); switch ( cinfo.jpeg_color_space ) { @@ -823,7 +823,7 @@ bool JPEGBITSCodec::DecodeByStreams(std::istream &is, std::ostream &os) } break; case JCS_RGB: - //assert( GetPhotometricInterpretation() == PhotometricInterpretation::RGB ); + //gdcm_assert( GetPhotometricInterpretation() == PhotometricInterpretation::RGB ); if ( cinfo.process == JPROC_LOSSLESS ) { cinfo.jpeg_color_space = JCS_UNKNOWN; @@ -866,7 +866,7 @@ bool JPEGBITSCodec::DecodeByStreams(std::istream &is, std::ostream &os) } break; case JCS_CMYK: - assert( GetPhotometricInterpretation() == PhotometricInterpretation::CMYK ); + gdcm_assert( GetPhotometricInterpretation() == PhotometricInterpretation::CMYK ); if ( cinfo.process == JPROC_LOSSLESS ) { cinfo.jpeg_color_space = JCS_UNKNOWN; @@ -881,11 +881,11 @@ bool JPEGBITSCodec::DecodeByStreams(std::istream &is, std::ostream &os) } break; default: - assert(0); + gdcm_assert(0); return false; } - //assert( cinfo.data_precision == BITS_IN_JSAMPLE ); - //assert( cinfo.data_precision == this->BitSample ); + //gdcm_assert( cinfo.data_precision == BITS_IN_JSAMPLE ); + //gdcm_assert( cinfo.data_precision == this->BitSample ); /* Step 4: set parameters for decompression */ /* no op */ @@ -1168,6 +1168,13 @@ bool JPEGBITSCodec::InternalCode(const char* input, unsigned long len, std::ostr int image_height = dims[1]; /* Number of rows in image */ int image_width = dims[0]; /* Number of columns in image */ + // Check if provided buffer correspond to image parameters for current frame + size_t expected_frame_size = (size_t)image_width * image_height * + this->GetPixelFormat().GetPixelSize(); + if (len != expected_frame_size) { + gdcmErrorMacro("Frame size don't match"); + return false; + } /* This struct contains the JPEG compression parameters and pointers to * working space (which is allocated as needed by the JPEG library). * It is possible to have several such structures, representing multiple @@ -1264,7 +1271,7 @@ bool JPEGBITSCodec::InternalCode(const char* input, unsigned long len, std::ostr // { // cinfo.in_color_space = JCS_UNKNOWN; // } - //assert( cinfo.image_height * cinfo.image_width * cinfo.input_components * sizeof(JSAMPLE) == len ); + //gdcm_assert( cinfo.image_height * cinfo.image_width * cinfo.input_components * sizeof(JSAMPLE) == len ); /* Now use the library's routine to set default compression parameters. * (You must set at least cinfo.in_color_space before calling this, @@ -1290,7 +1297,7 @@ bool JPEGBITSCodec::InternalCode(const char* input, unsigned long len, std::ostr */ if( !LossyFlag ) { - assert( Quality == 100 ); + gdcm_assert( Quality == 100 ); } jpeg_set_quality(&cinfo, Quality, TRUE /* limit to baseline-JPEG values */); @@ -1339,7 +1346,7 @@ bool JPEGBITSCodec::InternalCode(const char* input, unsigned long len, std::ostr row_pointer[0] = tempbuffer; int offset = image_height * image_width; while (cinfo.next_scanline < cinfo.image_height) { - assert( row_stride % 3 == 0 ); + gdcm_assert( row_stride % 3 == 0 ); JSAMPLE* ptempbuffer = tempbuffer; JSAMPLE* red = image_buffer + cinfo.next_scanline * row_stride / 3; JSAMPLE* green = image_buffer + cinfo.next_scanline * row_stride / 3 + offset; @@ -1486,7 +1493,7 @@ bool JPEGBITSCodec::EncodeBuffer(std::ostream &os, const char *data, size_t data // { // cinfo.in_color_space = JCS_UNKNOWN; // } - //assert( cinfo.image_height * cinfo.image_width * cinfo.input_components * sizeof(JSAMPLE) == len ); + //gdcm_assert( cinfo.image_height * cinfo.image_width * cinfo.input_components * sizeof(JSAMPLE) == len ); /* Now use the library's routine to set default compression parameters. * (You must set at least cinfo.in_color_space before calling this, @@ -1518,7 +1525,7 @@ bool JPEGBITSCodec::EncodeBuffer(std::ostream &os, const char *data, size_t data */ if( !LossyFlag ) { - assert( Quality == 100 ); + gdcm_assert( Quality == 100 ); } if( Internals->StateSuspension == 0 ) { @@ -1559,8 +1566,8 @@ bool JPEGBITSCodec::EncodeBuffer(std::ostream &os, const char *data, size_t data if ( Internals->StateSuspension == 1 ) { - assert( this->GetPlanarConfiguration() == 0 ); - assert( row_stride * sizeof(JSAMPLE) == datalen ); + gdcm_assert( this->GetPlanarConfiguration() == 0 ); + gdcm_assert( row_stride * sizeof(JSAMPLE) == datalen ); { //while (cinfo.next_scanline < cinfo.image_height) { /* jpeg_write_scanlines expects an array of pointers to scanlines. @@ -1569,8 +1576,8 @@ bool JPEGBITSCodec::EncodeBuffer(std::ostream &os, const char *data, size_t data */ row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride * 0]; const JDIMENSION nscanline = jpeg_write_scanlines(&cinfo, row_pointer, 1); - assert( nscanline == 1 ); (void)nscanline; - assert(cinfo.next_scanline <= cinfo.image_height); + gdcm_assert( nscanline == 1 ); (void)nscanline; + gdcm_assert(cinfo.next_scanline <= cinfo.image_height); //} } if(cinfo.next_scanline == cinfo.image_height) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEGCodec.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEGCodec.cxx index 467e1ff64f4..3bc63bcf2d6 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEGCodec.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEGCodec.cxx @@ -146,7 +146,7 @@ Interchange Format shall be used (the table specification shall be included). */ bool JPEGCodec::Decode(DataElement const &in, DataElement &out) { - assert( Internal ); + gdcm_assert( Internal ); out = in; // Fragments... const SequenceOfFragments *sf0 = in.GetSequenceOfFragments(); @@ -164,7 +164,7 @@ bool JPEGCodec::Decode(DataElement const &in, DataElement &out) size_t bv_len = bv.GetLength(); char *mybuffer = new char[bv_len]; bool b = bv.GetBuffer(mybuffer, bv.GetLength()); - assert( b ); (void)b; + gdcm_assert(b); (void)b; is.write(mybuffer, bv.GetLength()); delete[] mybuffer; bool r = DecodeByStreams(is, os); @@ -180,10 +180,9 @@ bool JPEGCodec::Decode(DataElement const &in, DataElement &out) // Ok so we are decoding a multiple frame jpeg DICOM file: // if we are lucky, we might be trying to decode some sort of broken multi-frame // DICOM file. In this case check that we have read all Fragment properly: - if( i >= this->GetDimensions()[2] ) + if( i >= this->GetDimensions()[2] && nfrags == this->GetNumberOfDimensions() ) { // JPEGInvalidSecondFrag.dcm - assert( nfrags == this->GetNumberOfDimensions() ); (void)nfrags; // sentinel gdcmWarningMacro( "Invalid JPEG Fragment found at pos #" << i + 1 << ". Skipping it" ); } else @@ -198,7 +197,7 @@ bool JPEGCodec::Decode(DataElement const &in, DataElement &out) size_t jpegbv_len = jpegbv->GetLength(); char *mybuffer0 = new char[jpegbv_len]; bool b0 = jpegbv->GetBuffer(mybuffer0, jpegbv->GetLength()); - assert( b0 ); (void)b0; + gdcm_assert( b0 ); (void)b0; is0.write(mybuffer0, jpegbv->GetLength()); delete[] mybuffer0; bool r = DecodeByStreams(is0, os); @@ -224,7 +223,7 @@ bool JPEGCodec::Decode(DataElement const &in, DataElement &out) size_t bv_len = bv.GetLength(); char *mybuffer = new char[bv_len]; bool b = bv.GetBuffer(mybuffer, bv.GetLength()); - assert( b ); (void)b; + gdcm_assert(b); (void)b; is.write(mybuffer, bv.GetLength()); delete[] mybuffer; bool r2 = DecodeByStreams(is, os); @@ -236,7 +235,7 @@ bool JPEGCodec::Decode(DataElement const &in, DataElement &out) } } - //assert( pos == len ); + //gdcm_assert( pos == len ); const size_t sizeOfOs = (size_t)os.tellp(); os.seekp( 0, std::ios::beg ); ByteValue * bv = new ByteValue; @@ -251,12 +250,12 @@ void JPEGCodec::ComputeOffsetTable(bool b) { (void)b; // Not implemented - assert(0); + gdcm_assert(0); } bool JPEGCodec::GetHeaderInfo( std::istream & is, TransferSyntax &ts ) { - assert( Internal ); + gdcm_assert( Internal ); if ( !Internal->GetHeaderInfo(is, ts) ) { // let's check if this is one of those buggy lossless JPEG @@ -268,7 +267,7 @@ bool JPEGCodec::GetHeaderInfo( std::istream & is, TransferSyntax &ts ) " but JPEG header says it's: " << Internal->BitSample ); if( this->BitSample < Internal->BitSample ) { - //assert(0); // Outside buffer will be too small + //gdcm_assert(0); // Outside buffer will be too small } is.seekg(0, std::ios::beg); SetupJPEGBitCodec( Internal->BitSample ); @@ -285,7 +284,7 @@ bool JPEGCodec::GetHeaderInfo( std::istream & is, TransferSyntax &ts ) } else { - //assert(0); // FATAL ERROR + //gdcm_assert(0); // FATAL ERROR gdcmErrorMacro( "Do not support this JPEG Type" ); return false; } @@ -342,7 +341,7 @@ bool JPEGCodec::Code(DataElement const &in, DataElement &out) } std::string str = os.str(); - assert( !str.empty() ); + gdcm_assert( !str.empty() ); Fragment frag; //frag.SetTag( itemStart ); VL::Type strSize = (VL::Type)str.size(); @@ -351,7 +350,7 @@ bool JPEGCodec::Code(DataElement const &in, DataElement &out) } //unsigned int n = sq->GetNumberOfFragments(); - assert( sq->GetNumberOfFragments() == dims[2] ); + gdcm_assert( sq->GetNumberOfFragments() == dims[2] ); out.SetValue( *sq ); return true; @@ -373,7 +372,7 @@ bool JPEGCodec::DecodeByStreams(std::istream &is, std::ostream &os) " but JPEG header says it's: " << Internal->BitSample ); if( this->BitSample < Internal->BitSample ) { - //assert(0); // Outside buffer will be too small + //gdcm_assert(0); // Outside buffer will be too small } is.seekg(0, std::ios::beg); SetupJPEGBitCodec( Internal->BitSample ); @@ -457,9 +456,9 @@ bool JPEGCodec::DecodeExtent( const unsigned int * dimensions = this->GetDimensions(); const PixelFormat & pf = this->GetPixelFormat(); - //assert( pf.GetBitsAllocated() % 8 == 0 ); - assert( pf != PixelFormat::SINGLEBIT ); - //assert( pf != PixelFormat::UINT12 && pf != PixelFormat::INT12 ); + //gdcm_assert( pf.GetBitsAllocated() % 8 == 0 ); + gdcm_assert( pf != PixelFormat::SINGLEBIT ); + //gdcm_assert( pf != PixelFormat::UINT12 && pf != PixelFormat::INT12 ); if( NumberOfDimensions == 2 ) { @@ -484,7 +483,7 @@ bool JPEGCodec::DecodeExtent( // read J2K is.read( &vdummybuffer[oldlen], fraglen ); } - assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); + gdcm_assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); } catch(Exception &ex) { @@ -504,12 +503,12 @@ bool JPEGCodec::DecodeExtent( // 2. GENESIS_SIGNA-JPEG-CorruptFrag.dcm else if ( frag.GetTag() == Tag(0xddff,0x00e0) ) { - assert( nfrags == 1 ); + gdcm_assert( nfrags == 1 ); const ByteValue *bv = frag.GetByteValue(); - assert( (unsigned char)bv->GetPointer()[ bv->GetLength() - 1 ] == 0xfe ); + gdcm_assert( (unsigned char)bv->GetPointer()[ bv->GetLength() - 1 ] == 0xfe ); // Yes this is an extra copy, this is a bug anyway, go fix YOUR code frag.SetByteValue( bv->GetPointer(), bv->GetLength() - 1 ); - assert( 0 ); + gdcm_assert( 0 ); gdcmWarningMacro( "JPEG Fragment length was declared with an extra byte" " at the end: stripped !" ); is.clear(); // clear the error bit @@ -524,21 +523,21 @@ bool JPEGCodec::DecodeExtent( #endif /* GDCM_SUPPORT_BROKEN_IMPLEMENTATION */ } - assert( zmin == zmax ); - assert( zmin == 0 ); + gdcm_assert( zmin == zmax ); + gdcm_assert( zmin == 0 ); std::stringstream iis; iis.write( vdummybuffer.data(), vdummybuffer.size() ); std::stringstream os; bool b = DecodeByStreams(iis,os); if(!b) return false; - assert( b ); + gdcm_assert(b); const unsigned int rowsize = xmax - xmin + 1; const unsigned int colsize = ymax - ymin + 1; const unsigned int bytesPerPixel = pf.GetPixelSize(); os.seekg(0, std::ios::beg ); - assert( os.good() ); + gdcm_assert( os.good() ); std::istream *theStream = &os; std::vector buffer1; buffer1.resize( rowsize*bytesPerPixel ); @@ -569,14 +568,14 @@ bool JPEGCodec::DecodeExtent( while( frag.ReadPreValue(is) && frag.GetTag() != seqDelItem ) { //std::streamoff relstart = is.tellg(); - //assert( relstart - thestart == 8 ); + //gdcm_assert( relstart - thestart == 8 ); const std::streamoff off = frag.GetVL(); offsets.push_back( (size_t)off ); is.seekg( off, std::ios::cur ); ++numfrags; } - assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); - assert( numfrags == offsets.size() ); + gdcm_assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); + gdcm_assert( numfrags == offsets.size() ); if( numfrags != Dimensions[2] ) { gdcmErrorMacro( "Not handled" ); @@ -595,12 +594,12 @@ bool JPEGCodec::DecodeExtent( std::stringstream os; const bool b = DecodeByStreams(is, os); (void)b; - assert( b ); + gdcm_assert(b); /* free the memory containing the code-stream */ //delete[] dummy_buffer; os.seekg(0, std::ios::beg ); - assert( os.good() ); + gdcm_assert( os.good() ); std::istream *theStream = &os; unsigned int rowsize = xmax - xmin + 1; @@ -629,7 +628,7 @@ bool JPEGCodec::DecodeExtent( bool JPEGCodec::IsStateSuspension() const { - assert( 0 ); + gdcm_assert( 0 ); return false; } @@ -638,10 +637,10 @@ ImageCodec * JPEGCodec::Clone() const JPEGCodec *copy = new JPEGCodec; ImageCodec &ic = *copy; ic = *this; - assert( copy->PF == PF ); + gdcm_assert( copy->PF == PF ); //copy->SetupJPEGBitCodec( BitSample ); copy->SetPixelFormat( GetPixelFormat() ); - assert( copy->BitSample == BitSample || BitSample == 0 ); + gdcm_assert( copy->BitSample == BitSample || BitSample == 0 ); //copy->Lossless = Lossless; copy->Quality = Quality; @@ -651,7 +650,7 @@ ImageCodec * JPEGCodec::Clone() const bool JPEGCodec::EncodeBuffer( std::ostream & out, const char *inbuffer, size_t inlen) { - assert( Internal ); + gdcm_assert( Internal ); return Internal->EncodeBuffer(out, inbuffer, inlen); } @@ -665,7 +664,7 @@ bool JPEGCodec::IsRowEncoder() } bool JPEGCodec::IsFrameEncoder() { - assert(0); + gdcm_assert(0); return false; } bool JPEGCodec::AppendRowEncode( std::ostream & os, const char * data, size_t datalen) @@ -676,7 +675,7 @@ bool JPEGCodec::AppendRowEncode( std::ostream & os, const char * data, size_t da // this could reduce code duplication bool JPEGCodec::AppendFrameEncode( std::ostream & , const char * , size_t ) { - assert(0); + gdcm_assert(0); return false; } bool JPEGCodec::StopEncode( std::ostream & ) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEGLSCodec.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEGLSCodec.cxx index 38d2f6d65f7..3e992dc415b 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEGLSCodec.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJPEGLSCodec.cxx @@ -56,7 +56,7 @@ bool JPEGLSCodec::GetHeaderInfo(std::istream &is, TransferSyntax &ts) using namespace charls; is.seekg( 0, std::ios::end); size_t buf_size = (size_t)is.tellg(); - //assert(buf_size < INT_MAX); + //gdcm_assert(buf_size < INT_MAX); char *dummy_buffer = new char[(unsigned int)buf_size]; is.seekg(0, std::ios::beg); is.read( dummy_buffer, buf_size); @@ -78,15 +78,15 @@ bool JPEGLSCodec::GetHeaderInfo(std::istream &is, TransferSyntax &ts) } else if( metadata.bitsPerSample <= 16 ) { - assert( metadata.bitsPerSample > 8 ); + gdcm_assert( metadata.bitsPerSample > 8 ); this->PF = PixelFormat( PixelFormat::UINT16 ); } else { - assert(0); + gdcm_assert(0); } this->PF.SetBitsStored( (uint16_t)metadata.bitsPerSample ); - assert( this->PF.IsValid() ); + gdcm_assert( this->PF.IsValid() ); // switch( metadata.bitspersample ) // { // case 8: @@ -100,7 +100,7 @@ bool JPEGLSCodec::GetHeaderInfo(std::istream &is, TransferSyntax &ts) // this->PF = PixelFormat( PixelFormat::UINT16 ); // break; // default: -// assert(0); +// gdcm_assert(0); // } if( metadata.components == 1 ) { @@ -113,7 +113,7 @@ bool JPEGLSCodec::GetHeaderInfo(std::istream &is, TransferSyntax &ts) PlanarConfiguration = 0; // CP-1843 this->PF.SetSamplesPerPixel( 3 ); } - else assert(0); + else gdcm_assert(0); // allowedlossyerror == 0 => Lossless LossyFlag = metadata.allowedLossyError != 0; @@ -155,9 +155,9 @@ template static void ConvPlanar(std::vector &input) { size_t buf_size = input.size(); - assert( buf_size % sizeof(T) == 0 ); + gdcm_assert( buf_size % sizeof(T) == 0 ); size_t npixels = buf_size / sizeof( T ); - assert( npixels % 3 == 0 ); + gdcm_assert( npixels % 3 == 0 ); size_t size = npixels / 3; T* buffer = (T*)input.data(); @@ -211,7 +211,7 @@ bool JPEGLSCodec::DecodeByStreamsCommon(const char *buffer, size_t totalLen, std else if(nBytes == 2 ) ConvPlanar(rgbyteOut); else - assert(0); + gdcm_assert(0); } } @@ -271,7 +271,7 @@ bool JPEGLSCodec::Decode(DataElement const &in, DataElement &out) totalLen--; } // what if 0xd9 is never found ? - assert( totalLen > 0 && pbyteCompressed[totalLen-1] == 0xd9 ); + gdcm_assert( totalLen > 0 && pbyteCompressed[totalLen-1] == 0xd9 ); size_t cbyteCompressed = totalLen; @@ -299,10 +299,10 @@ bool JPEGLSCodec::Decode(DataElement const &in, DataElement &out) os.write( (const char*)rgbyteOut.data(), rgbyteOut.size() ); if(!r) return false; - assert( r == true ); + gdcm_assert( r == true ); } std::string str = os.str(); - assert( !str.empty() ); + gdcm_assert( !str.empty() ); out.SetByteValue( str.data(), (uint32_t)str.size() ); return true; @@ -397,7 +397,7 @@ bool JPEGLSCodec::CodeFrameIntoBuffer(char * outdata, size_t outlen, size_t & co return false; } - assert( complen < outlen ); + gdcm_assert( complen < outlen ); return true; #endif @@ -440,7 +440,7 @@ bool JPEGLSCodec::Code(DataElement const &in, DataElement &out) sq->AddFragment( frag ); } - assert( sq->GetNumberOfFragments() == dims[2] ); + gdcm_assert( sq->GetNumberOfFragments() == dims[2] ); out.SetValue( *sq ); return true; @@ -473,9 +473,9 @@ bool JPEGLSCodec::DecodeExtent( const unsigned int * dimensions = this->GetDimensions(); const PixelFormat & pf = this->GetPixelFormat(); - assert( pf.GetBitsAllocated() % 8 == 0 ); - assert( pf != PixelFormat::SINGLEBIT ); - assert( pf != PixelFormat::UINT12 && pf != PixelFormat::INT12 ); + gdcm_assert( pf.GetBitsAllocated() % 8 == 0 ); + gdcm_assert( pf != PixelFormat::SINGLEBIT ); + gdcm_assert( pf != PixelFormat::UINT12 && pf != PixelFormat::INT12 ); if( NumberOfDimensions == 2 ) { @@ -496,9 +496,9 @@ bool JPEGLSCodec::DecodeExtent( // read J2K is.read( &vdummybuffer[oldlen], fraglen ); } - assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); - assert( zmin == zmax ); - assert( zmin == 0 ); + gdcm_assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); + gdcm_assert( zmin == zmax ); + gdcm_assert( zmin == 0 ); std::vector outv; bool b = DecodeByStreamsCommon(dummy_buffer, buf_size, outv); @@ -536,14 +536,14 @@ bool JPEGLSCodec::DecodeExtent( while( frag.ReadPreValue(is) && frag.GetTag() != seqDelItem ) { //std::streamoff relstart = is.tellg(); - //assert( relstart - thestart == 8 ); + //gdcm_assert( relstart - thestart == 8 ); std::streamoff off = frag.GetVL(); offsets.push_back( (size_t)off ); is.seekg( off, std::ios::cur ); ++numfrags; } - assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); - assert( numfrags == offsets.size() ); + gdcm_assert( frag.GetTag() == seqDelItem && frag.GetVL() == 0 ); + gdcm_assert( numfrags == offsets.size() ); if( numfrags != Dimensions[2] ) { gdcmErrorMacro( "Not handled" ); @@ -620,7 +620,7 @@ bool JPEGLSCodec::AppendFrameEncode( std::ostream & out, const char * data, size { const unsigned int * dimensions = this->GetDimensions(); const PixelFormat & pf = this->GetPixelFormat(); (void)pf; - assert( datalen == dimensions[0] * dimensions[1] * pf.GetPixelSize() ); + gdcm_assert( datalen == dimensions[0] * dimensions[1] * pf.GetPixelSize() ); std::vector rgbyteCompressed; rgbyteCompressed.resize(dimensions[0] * dimensions[1] * 4); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJSON.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJSON.cxx index a4e6f188762..96f26936686 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJSON.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmJSON.cxx @@ -78,7 +78,7 @@ static inline void wstrim(std::string& str) static inline bool CanContainBackslash( const VR::VRType vrtype ) { - assert( VR::IsASCII( vrtype ) ); + gdcm_assert( VR::IsASCII( vrtype ) ); // PS 3.5-2011 / Table 6.2-1 DICOM VALUE REPRESENTATIONS switch( vrtype ) { @@ -110,7 +110,7 @@ static inline bool CanContainBackslash( const VR::VRType vrtype ) //case VR::UN: // binary //case VR::US: // binary //case VR::UT: // VM1 - assert( !(vrtype & VR::VR_VM1) ); + gdcm_assert( !(vrtype & VR::VR_VM1) ); return true; default: ; @@ -179,7 +179,7 @@ static void DataElementToJSONArray( const VR::VRType vr, const DataElement & de, return; } // else - assert( !de.IsEmpty() ); + gdcm_assert( !de.IsEmpty() ); const bool checkbackslash = CanContainBackslash( vr ); const ByteValue * bv = de.GetByteValue(); const char * value = bv->GetPointer(); @@ -199,7 +199,7 @@ static void DataElementToJSONArray( const VR::VRType vr, const DataElement & de, { len--; } - assert( str1 ); + gdcm_assert( str1 ); std::stringstream ss; static const char *Keys[] = { "Alphabetic", @@ -208,21 +208,21 @@ static void DataElementToJSONArray( const VR::VRType vr, const DataElement & de, }; while (1) { - assert( str1 && (size_t)(str1 - value) <= len ); + gdcm_assert( str1 && (size_t)(str1 - value) <= len ); const char * sep = strchr(str1, '\\'); const size_t llen = (sep != NULL) ? (sep - str1) : (value + len - str1); const std::string component(str1, llen); const char *str2 = component.c_str(); - assert( str2 ); + gdcm_assert( str2 ); const size_t len2 = component.size(); - assert( len2 == llen ); + gdcm_assert( len2 == llen ); int idx = 0; json_object *my_object_comp = json_object_new_object(); while (1) { - assert( str2 && (size_t)(str2 - component.c_str() ) <= len2 ); + gdcm_assert( str2 && (size_t)(str2 - component.c_str() ) <= len2 ); const char * sep2 = strchr(str2, '='); const size_t llen2 = (sep2 != NULL) ? (sep2 - str2) : (component.c_str() + len2 - str2); const std::string group(str2, llen2); @@ -236,19 +236,19 @@ static void DataElementToJSONArray( const VR::VRType vr, const DataElement & de, json_object_array_add(my_array, my_object_comp); if (sep == NULL) break; str1 = sep + 1; - assert( checkbackslash ); + gdcm_assert( checkbackslash ); } } else if( vr == VR::DS || vr == VR::IS ) { const char *str1 = value; - assert( str1 ); + gdcm_assert( str1 ); VRToType::Type vris; VRToType::Type vrds; while (1) { std::stringstream ss; - assert( str1 && (size_t)(str1 - value) <= len ); + gdcm_assert( str1 && (size_t)(str1 - value) <= len ); const char * sep = strchr(str1, '\\'); const size_t llen = (sep != NULL) ? (sep - str1) : (value + len - str1); // This is complex, IS/DS should not be stored as string anymore @@ -265,20 +265,20 @@ static void DataElementToJSONArray( const VR::VRType vr, const DataElement & de, json_object_array_add(my_array, json_object_new_double(vrds)); break; default: - assert( 0 ); // programmer error + gdcm_assert( 0 ); // programmer error } if (sep == NULL) break; str1 = sep + 1; - assert( checkbackslash ); + gdcm_assert( checkbackslash ); } } else if( checkbackslash ) { const char *str1 = value; - assert( str1 ); + gdcm_assert( str1 ); while (1) { - assert( str1 && (size_t)(str1 - value) <= len ); + gdcm_assert( str1 && (size_t)(str1 - value) <= len ); const char * sep = strchr(str1, '\\'); const size_t llen = (sep != NULL) ? (sep - str1) : (value + len - str1); json_object_array_add(my_array, json_object_new_string_len(str1, llen)); @@ -324,7 +324,7 @@ static void ProcessNestedDataSet( const DataSet & ds, json_object *my_object, co else if( isprivatecreator ) vr = VR::LO; // always prefer VR::LO (over invalid/UN) else if( vr == VR::INVALID ) vr = VR::UN; const char * vr_str = VR::GetVRString(vr); - assert( VR::GetVRTypeFromFile(vr_str) != VR::INVALID ); + gdcm_assert( VR::GetVRTypeFromFile(vr_str) != VR::INVALID ); json_object *my_object_cur; my_object_cur = json_object_new_object(); @@ -363,11 +363,11 @@ static void ProcessNestedDataSet( const DataSet & ds, json_object *my_object, co else if( const SequenceOfFragments *sqf = de.GetSequenceOfFragments() ) { json_object_array_add(my_array, NULL ); // FIXME - assert( 0 ); + gdcm_assert( 0 ); } else { - assert( de.IsEmpty() ); + gdcm_assert( de.IsEmpty() ); //json_object_array_add(my_array, NULL ); // F.2.5 req ? } //json_object_object_add(my_object_cur, "Sequence", my_array ); @@ -481,29 +481,29 @@ static void ProcessNestedDataSet( const DataSet & ds, json_object *my_object, co case VR::OB: case VR::OW: { - assert( !de.IsUndefinedLength() ); // handled before + gdcm_assert( !de.IsUndefinedLength() ); // handled before const ByteValue * bv = de.GetByteValue(); wheretostore = "InlineBinary"; if( bv ) { const char *src = bv->GetPointer(); const size_t len = bv->GetLength(); - assert( len % 2 == 0 ); + gdcm_assert( len % 2 == 0 ); const size_t len64 = Base64::GetEncodeLength(src, len); buffer.resize( len64 ); const size_t ret = Base64::Encode( &buffer[0], len64, src, len ); - assert( ret != 0 ); + gdcm_assert( ret != 0 ); json_object_array_add(my_array, json_object_new_string_len(&buffer[0], len64)); } } break; default: - assert( 0 ); // programmer error + gdcm_assert( 0 ); // programmer error } json_object_object_add(my_object_cur, wheretostore, my_array ); } //const char *keyword = entry.GetKeyword(); - //assert( keyword && *keyword ); + //gdcm_assert( keyword && *keyword ); //if( preferkeyword && keyword && *keyword && !t.IsPrivateCreator() ) // { // json_object_object_add(my_object, keyword, my_object_cur ); @@ -552,14 +552,14 @@ bool JSON::Code(DataSet const & ds, std::ostream & os) static inline bool CheckTagKeywordConsistency( const char *name, const Tag & thetag ) { // Can be keyword or tag - assert( name ); + gdcm_assert( name ); // start with easy one: // only test first string character: bool istag = *name >= '0' && *name <= '9'; // should be relatively efficient if( istag ) { - assert( strlen(name) == 8 ); + gdcm_assert( strlen(name) == 8 ); Tag t; t.ReadFromContinuousString( name ); return t == thetag; @@ -575,7 +575,7 @@ static inline bool CheckTagKeywordConsistency( const char *name, const Tag & the return true; } // else - assert( strcmp( name, keyword ) == 0 ); + gdcm_assert( strcmp( name, keyword ) == 0 ); return strcmp( name, keyword ) == 0; } #endif @@ -585,7 +585,7 @@ static inline bool CheckTagKeywordConsistency( const char *name, const Tag & the static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElement & de ) { json_type jtype = json_object_get_type( obj ); - assert( jtype == json_type_object ); + gdcm_assert( jtype == json_type_object ); json_object * jvr = json_object_object_get_old(obj, "VR"); const char * vr_str = json_object_get_string ( jvr ); @@ -595,23 +595,23 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem { json_object * jprivatecreator = json_object_object_get_old(obj, "PrivateCreator"); pc_str = json_object_get_string ( jprivatecreator ); - assert( pc_str ); + gdcm_assert( pc_str ); } VR::VRType vrtype = VR::GetVRTypeFromFile( vr_str ); - assert( vrtype != VR::INVALID ); - assert( vrtype != VR::VR_END ); + gdcm_assert( vrtype != VR::INVALID ); + gdcm_assert( vrtype != VR::VR_END ); de.SetVR( vrtype ); if( vrtype == VR::SQ ) { json_object * jvalue = json_object_object_get_old(obj, "Value"); json_type jvaluetype = json_object_get_type( jvalue ); - assert( jvaluetype != json_type_null && jvaluetype == json_type_array ); + gdcm_assert( jvaluetype != json_type_null && jvaluetype == json_type_array ); #ifndef NDEBUG json_object * jseq = json_object_object_get_old(obj, "Sequence"); json_type jsqtype = json_object_get_type( jseq ); - assert( jsqtype == json_type_null ); + gdcm_assert( jsqtype == json_type_null ); #endif if( jvaluetype == json_type_array ) { @@ -624,7 +624,7 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem { json_object * jitem = json_object_array_get_idx ( jvalue, itemidx ); json_type jitemtype = json_object_get_type( jitem ); - assert( jitemtype == json_type_object ); + gdcm_assert( jitemtype == json_type_object ); //const char * dummy = json_object_to_json_string ( jitem ); // Create an item @@ -641,7 +641,7 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem while (!json_object_iter_equal(&it, &itEnd)) { const char *name = json_object_iter_peek_name(&it); - assert( name ); + gdcm_assert( name ); json_object * value = json_object_iter_peek_value (&it); DataElement lde; ProcessJSONElement( name, value, lde ); @@ -669,14 +669,14 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem #ifndef NDEBUG json_object * jpn = json_object_object_get_old(obj, "PersonName"); json_type jpntype = json_object_get_type( jpn ); - assert( jpntype == json_type_null ); + gdcm_assert( jpntype == json_type_null ); #endif json_type jvaluetype = json_object_get_type( jvalue ); //const char * dummy = json_object_to_json_string ( jvalue ); - assert( jvaluetype == json_type_null || jvaluetype == json_type_array ); + gdcm_assert( jvaluetype == json_type_null || jvaluetype == json_type_array ); if( jvaluetype == json_type_array ) { - //assert( vrtype != VR::PN ); + //gdcm_assert( vrtype != VR::PN ); const int valuelen = json_object_array_length ( jvalue ); std::string str; for( int validx = 0; validx < valuelen; ++validx ) @@ -686,7 +686,7 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem json_type valuetype = json_object_get_type( value ); if( value ) { - assert( valuetype != json_type_null ); + gdcm_assert( valuetype != json_type_null ); std::string value_str; std::stringstream ss; VRToType::Type vris; @@ -728,8 +728,8 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem else { // We have a [ null ] array, so at most there is a single item: - assert( valuelen == 1 ); - assert( valuetype == json_type_null ); + gdcm_assert( valuelen == 1 ); + gdcm_assert( valuetype == json_type_null ); } } if( str.size() % 2 ) @@ -744,7 +744,7 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem #ifndef NDEBUG else if( jpntype == json_type_array ) { - assert( 0 ); + gdcm_assert( 0 ); } #endif } @@ -755,7 +755,7 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem json_object * jvalue = json_object_object_get_old(obj, "Value"); json_type jvaluetype = json_object_get_type( jvalue ); //const char * dummy = json_object_to_json_string ( jvalue ); - assert( jvaluetype == json_type_array || jvaluetype == json_type_null ); + gdcm_assert( jvaluetype == json_type_array || jvaluetype == json_type_null ); if( jvaluetype == json_type_array ) { DataElement locde; @@ -770,7 +770,7 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem for( int validx = 0; validx < valuelen; ++validx ) { json_object * value = json_object_array_get_idx ( jvalue, validx ); - assert( json_object_get_type( value ) == json_type_double ); + gdcm_assert( json_object_get_type( value ) == json_type_double ); const double v = json_object_get_double ( value ); el.SetValue(v, validx); } @@ -784,7 +784,7 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem for( int validx = 0; validx < valuelen; ++validx ) { json_object * value = json_object_array_get_idx ( jvalue, validx ); - assert( json_object_get_type( value ) == json_type_double ); + gdcm_assert( json_object_get_type( value ) == json_type_double ); const double v = json_object_get_double ( value ); el.SetValue(v, validx); } @@ -798,7 +798,7 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem for( int validx = 0; validx < valuelen; ++validx ) { json_object * value = json_object_array_get_idx ( jvalue, validx ); - assert( json_object_get_type( value ) == json_type_int ); + gdcm_assert( json_object_get_type( value ) == json_type_int ); const int v = json_object_get_int( value ); el.SetValue(v, validx); } @@ -812,7 +812,7 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem for( int validx = 0; validx < valuelen; ++validx ) { json_object * value = json_object_array_get_idx ( jvalue, validx ); - assert( json_object_get_type( value ) == json_type_int ); + gdcm_assert( json_object_get_type( value ) == json_type_int ); const int v = json_object_get_int( value ); el.SetValue(v, validx); } @@ -826,7 +826,7 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem for( int validx = 0; validx < valuelen; ++validx ) { json_object * value = json_object_array_get_idx ( jvalue, validx ); - assert( json_object_get_type( value ) == json_type_int ); + gdcm_assert( json_object_get_type( value ) == json_type_int ); const int v = json_object_get_int( value ); el.SetValue(v, validx); } @@ -840,7 +840,7 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem for( int validx = 0; validx < valuelen; ++validx ) { json_object * value = json_object_array_get_idx ( jvalue, validx ); - assert( json_object_get_type( value ) == json_type_int ); + gdcm_assert( json_object_get_type( value ) == json_type_int ); const int v = json_object_get_int( value ); el.SetValue(v, validx); } @@ -854,7 +854,7 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem for( int validx = 0; validx < valuelen; ++validx ) { json_object * value = json_object_array_get_idx ( jvalue, validx ); - assert( json_object_get_type( value ) == json_type_string ); + gdcm_assert( json_object_get_type( value ) == json_type_string ); const char *atstr = json_object_get_string( value ); Tag t; t.ReadFromContinuousString( atstr ); @@ -864,7 +864,7 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem } break; default: - assert( 0 ); + gdcm_assert( 0 ); } if( !locde.IsEmpty() ) de.SetValue( locde.GetValue() ); @@ -882,43 +882,43 @@ static void ProcessJSONElement( const char *tag_str, json_object * obj, DataElem case VR::OF: case VR::OW: { - assert( valuelen == 1 || valuelen == 0 ); + gdcm_assert( valuelen == 1 || valuelen == 0 ); if( valuelen ) { json_object * value = json_object_array_get_idx ( jvaluebin, 0 ); json_type valuetype = json_object_get_type( value ); if( value ) { - assert( valuetype != json_type_null ); + gdcm_assert( valuetype != json_type_null ); const char * value_str = json_object_get_string ( value ); - assert( value_str ); + gdcm_assert( value_str ); const size_t len64 = strlen( value_str ); const size_t len = Base64::GetDecodeLength( value_str, len64 ); std::vector buffer; buffer.resize( len ); const size_t ret = Base64::Decode( &buffer[0], len, value_str, len64 ); - assert( ret != 0 ); + gdcm_assert( ret != 0 ); locde.SetByteValue( &buffer[0], len ); } else { // We have a [ null ] array, so at most there is a single item: - assert( valuelen == 1 ); - assert( valuetype == json_type_null ); + gdcm_assert( valuelen == 1 ); + gdcm_assert( valuetype == json_type_null ); } } } break; default: - assert( 0 ); + gdcm_assert( 0 ); } if( !locde.IsEmpty() ) de.SetValue( locde.GetValue() ); } else { - assert( jvaluebintype == json_type_null && jvaluetype == json_type_null ); + gdcm_assert( jvaluebintype == json_type_null && jvaluetype == json_type_null ); } } } @@ -949,7 +949,7 @@ bool JSON::Decode(std::istream & is, DataSet & ds) { fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); // Handle errors, as appropriate for your application. - assert( 0 ); + gdcm_assert( 0 ); } if (tok->char_offset < stringlen) // XXX shouldn't access internal fields { @@ -979,7 +979,7 @@ bool JSON::Decode(std::istream & is, DataSet & ds) while (!json_object_iter_equal(&it, &itEnd)) { const char *name = json_object_iter_peek_name(&it); - assert( name ); + gdcm_assert( name ); json_object * value = json_object_iter_peek_value (&it); DataElement de; ProcessJSONElement( name, value, de ); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmKAKADUCodec.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmKAKADUCodec.cxx index 47907c1f79b..d4e1ba3cd3b 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmKAKADUCodec.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmKAKADUCodec.cxx @@ -155,9 +155,9 @@ bool KAKADUCodec::Decode(DataElement const &in, DataElement &out) std::ofstream outfile(input.c_str(), std::ios::binary); const Fragment &frag = sf->GetFragment(i); - assert( !frag.IsEmpty() ); + gdcm_assert( !frag.IsEmpty() ); const ByteValue *bv = frag.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); //sf->WriteBuffer(outfile); bv->WriteBuffer( outfile ); outfile.close(); // flush ! @@ -203,7 +203,7 @@ bool KAKADUCodec::Decode(DataElement const &in, DataElement &out) free(tempoutput); } std::string str = os.str(); - assert( str.size() ); + gdcm_assert( str.size() ); out.SetTag( Tag(0x7fe0,0x0010) ); out.SetByteValue( &str[0], str.size() ); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmLookupTable.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmLookupTable.cxx index 2c566923b4b..5ae040e218d 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmLookupTable.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmLookupTable.cxx @@ -93,9 +93,9 @@ void LookupTable::InitializeLUT(LookupTableType type, unsigned short length, { return; } - assert( type >= RED && type <= BLUE ); - assert( subscript == 0 ); - assert( bitsize == 8 || bitsize == 16 ); + gdcm_assert( type >= RED && type <= BLUE ); + gdcm_assert( subscript == 0 ); + gdcm_assert( bitsize == 8 || bitsize == 16 ); if( length == 0 ) { Internal->Length[type] = 65536; @@ -142,11 +142,11 @@ void LookupTable::SetLUT(LookupTableType type, const unsigned char *array, { const unsigned int mult = Internal->BitSize[type]/8; const unsigned int mult2 = length / Internal->Length[type]; - assert( Internal->Length[type] * mult2 == length ); + gdcm_assert( Internal->Length[type] * mult2 == length ); if( Internal->Length[type]*mult == length || Internal->Length[type]*mult + 1 == length ) { - assert( mult2 == 1 || mult2 == 2 ); + gdcm_assert( mult2 == 1 || mult2 == 2 ); unsigned int offset = 0; if( mult == 2 ) { @@ -154,32 +154,32 @@ void LookupTable::SetLUT(LookupTableType type, const unsigned char *array, } for( unsigned int i = 0; i < Internal->Length[type]; ++i) { - assert( i*mult+offset < length ); - assert( 3*i+type < Internal->RGB.size() ); + gdcm_assert( i*mult+offset < length ); + gdcm_assert( 3*i+type < Internal->RGB.size() ); Internal->RGB[3*i+type] = array[i*mult+offset]; } } else { unsigned int offset = 0; - assert( mult2 == 2 ); + gdcm_assert( mult2 == 2 ); for( unsigned int i = 0; i < Internal->Length[type]; ++i) { - assert( i*mult2+offset < length ); - assert( 3*i+type < Internal->RGB.size() ); + gdcm_assert( i*mult2+offset < length ); + gdcm_assert( 3*i+type < Internal->RGB.size() ); Internal->RGB[3*i+type] = array[i*mult2+offset]; } } } else if( BitSample == 16 ) { - assert( Internal->Length[type]*(BitSample/8) == length ); + gdcm_assert( Internal->Length[type]*(BitSample/8) == length ); uint16_t *uchar16 = (uint16_t*)(void*)Internal->RGB.data(); const uint16_t *array16 = (const uint16_t*)(const void*)array; for( unsigned int i = 0; i < Internal->Length[type]; ++i) { - assert( 2*i < length ); - assert( 2*(3*i+type) < Internal->RGB.size() ); + gdcm_assert( 2*i < length ); + gdcm_assert( 2*(3*i+type) < Internal->RGB.size() ); uchar16[3*i+type] = array16[i]; } } @@ -198,8 +198,8 @@ void LookupTable::GetLUT(LookupTableType type, unsigned char *array, unsigned in } for( unsigned int i = 0; i < Internal->Length[type]; ++i) { - assert( i*mult+offset < length ); - assert( 3*i+type < Internal->RGB.size() ); + gdcm_assert( i*mult+offset < length ); + gdcm_assert( 3*i+type < Internal->RGB.size() ); array[i*mult+offset] = Internal->RGB[3*i+type]; } } @@ -210,8 +210,8 @@ void LookupTable::GetLUT(LookupTableType type, unsigned char *array, unsigned in uint16_t *array16 = (uint16_t*)(void*)array; for( unsigned int i = 0; i < Internal->Length[type]; ++i) { - assert( 2*i < length ); - assert( 2*(3*i+type) < Internal->RGB.size() ); + gdcm_assert( 2*i < length ); + gdcm_assert( 2*(3*i+type) < Internal->RGB.size() ); array16[i] = uchar16[3*i+type]; } } @@ -220,7 +220,7 @@ void LookupTable::GetLUT(LookupTableType type, unsigned char *array, unsigned in void LookupTable::GetLUTDescriptor(LookupTableType type, unsigned short &length, unsigned short &subscript, unsigned short &bitsize) const { - assert( type >= RED && type <= BLUE ); + gdcm_assert( type >= RED && type <= BLUE ); if( Internal->Length[type] == 65536 ) { length = 0; @@ -233,8 +233,8 @@ void LookupTable::GetLUTDescriptor(LookupTableType type, unsigned short &length, bitsize = Internal->BitSize[type]; // postcondition - assert( subscript == 0 ); - assert( bitsize == 8 || bitsize == 16 ); + gdcm_assert( subscript == 0 ); + gdcm_assert( bitsize == 8 || bitsize == 16 ); } void LookupTable::InitializeRedLUT(unsigned short length, @@ -324,15 +324,15 @@ void LookupTable::Encode(std::istream &is, std::ostream &os) U8 u; u.rgb[3] = 0; is.read( (char*)u.rgb, 3); - assert( u.rgb[3] == 0 ); - //assert( u.rgb[0] == u.rgb[1] && u.rgb[1] == u.rgb[2] ); + gdcm_assert( u.rgb[3] == 0 ); + //gdcm_assert( u.rgb[0] == u.rgb[1] && u.rgb[1] == u.rgb[2] ); std::pair it = s.insert( u ); if( it.second ) ++count; int d = std::distance(s.begin(), it.first); //std::cout << count << " Index: " << d << " -> "; printrgb( u.rgb ); std::cout << "\n"; - //assert( s.size() < 256 ); - assert( d < s.size() ); - //assert( d < 256 && d >= 0 ); + //gdcm_assert( s.size() < 256 ); + gdcm_assert( d < s.size() ); + //gdcm_assert( d < 256 && d >= 0 ); } // now generate output image @@ -344,13 +344,13 @@ void LookupTable::Encode(std::istream &is, std::ostream &os) U8 u; u.rgb[3] = 0; is.read( (char*)u.rgb, 3); - assert( u.rgb[3] == 0 ); - //assert( u.rgb[0] == u.rgb[1] && u.rgb[1] == u.rgb[2] ); + gdcm_assert( u.rgb[3] == 0 ); + //gdcm_assert( u.rgb[0] == u.rgb[1] && u.rgb[1] == u.rgb[2] ); std::pair it = s.insert( u ); int d = std::distance(s.begin(), it.first); //std::cout << "Index: " << d << " -> "; printrgb( u.rgb ); std::cout << "\n"; - assert( d < s.size() ); - //assert( d < 256 && d >= 0 ); + gdcm_assert( d < s.size() ); + //gdcm_assert( d < 256 && d >= 0 ); os.put( d ); } @@ -362,11 +362,11 @@ void LookupTable::Encode(std::istream &is, std::ostream &os) InitializeGreenLUT(ncolor, 0, 8); InitializeBlueLUT(ncolor, 0, 8); //int i = Internal->RGB.size(); - //assert( Internal->RGB.size() == 5 ); + //gdcm_assert( Internal->RGB.size() == 5 ); int idx = 0; for( RGBColorIndexer::const_iterator it = s.begin(); it != s.end() && idx < 256; ++it, ++idx ) { - assert( idx == std::distance( s.begin(), it ) ); + gdcm_assert( idx == std::distance( s.begin(), it ) ); //std::cout << "Index: " << idx << " -> "; printrgb( it->rgb ); std::cout << "\n"; Internal->RGB[3*idx+RED] = it->rgb[RED]; Internal->RGB[3*idx+GREEN] = it->rgb[GREEN]; @@ -378,9 +378,9 @@ void LookupTable::Encode(std::istream &is, std::ostream &os) U8 u; u.rgb[3] = 0; is.read( (char*)u.rgb, 3); - assert( u.rgb[3] == 0 ); + gdcm_assert( u.rgb[3] == 0 ); int d = 0; - assert( d < 256 && d >= 0 ); + gdcm_assert( d < 256 && d >= 0 ); os.put( (char)d ); } #endif @@ -396,13 +396,13 @@ void LookupTable::Encode(std::istream &is, std::ostream &os) U16 u; u.rgb[3] = 0; is.read( (char*)u.rgb, 3*2); - assert( u.rgb[3] == 0 ); - //assert( u.rgb[0] == u.rgb[1] && u.rgb[1] == u.rgb[2] ); + gdcm_assert( u.rgb[3] == 0 ); + //gdcm_assert( u.rgb[0] == u.rgb[1] && u.rgb[1] == u.rgb[2] ); std::pair it = s.insert( u ); int d = std::distance(s.begin(), it.first); //std::cout << "Index: " << d << " -> "; printrgb( u.rgb ); std::cout << "\n"; - assert( d < s.size() ); - assert( d < 65536 && d >= 0 ); + gdcm_assert( d < s.size() ); + gdcm_assert( d < 65536 && d >= 0 ); } // now generate output image @@ -414,13 +414,13 @@ void LookupTable::Encode(std::istream &is, std::ostream &os) U16 u; u.rgb[3] = 0; is.read( (char*)u.rgb, 3*2); - assert( u.rgb[3] == 0 ); - //assert( u.rgb[0] == u.rgb[1] && u.rgb[1] == u.rgb[2] ); + gdcm_assert( u.rgb[3] == 0 ); + //gdcm_assert( u.rgb[0] == u.rgb[1] && u.rgb[1] == u.rgb[2] ); std::pair it = s.insert( u ); unsigned short d = std::distance(s.begin(), it.first); //std::cout << "Index: " << d << " -> "; printrgb( u.rgb ); std::cout << "\n"; - assert( d < s.size() ); - assert( d < 65536 && d >= 0 ); + gdcm_assert( d < s.size() ); + gdcm_assert( d < 65536 && d >= 0 ); os.write( (const char*)&d , 2 ); } @@ -430,12 +430,12 @@ void LookupTable::Encode(std::istream &is, std::ostream &os) InitializeGreenLUT(ncolor, 0, 16); InitializeBlueLUT(ncolor, 0, 16); //int i = Internal->RGB.size(); - //assert( Internal->RGB.size() == 5 ); + //gdcm_assert( Internal->RGB.size() == 5 ); int idx = 0; uint16_t *rgb16 = (uint16_t*)&Internal->RGB[0]; for( RGBColorIndexer::const_iterator it = s.begin(); it != s.end(); ++it, ++idx ) { - assert( idx == std::distance( s.begin(), it ) ); + gdcm_assert( idx == std::distance( s.begin(), it ) ); //std::cout << "Index: " << idx << " -> "; printrgb( it->rgb ); std::cout << "\n"; rgb16[3*idx+RED] = it->rgb[RED]; rgb16[3*idx+GREEN] = it->rgb[GREEN]; @@ -447,9 +447,9 @@ void LookupTable::Encode(std::istream &is, std::ostream &os) U16 u; u.rgb[3] = 0; is.read( (char*)u.rgb, 3*2); - assert( u.rgb[3] == 0 ); + gdcm_assert( u.rgb[3] == 0 ); int d = 0; - assert( d < 65536 && d >= 0 ); + gdcm_assert( d < 65536 && d >= 0 ); os.write( (const char*)&d , 2 ); } #endif @@ -458,7 +458,7 @@ void LookupTable::Encode(std::istream &is, std::ostream &os) void LookupTable::Decode(std::istream &is, std::ostream &os) const { - assert( Initialized() ); + gdcm_assert( Initialized() ); if ( BitSample == 8 ) { unsigned char idx; @@ -469,9 +469,9 @@ void LookupTable::Decode(std::istream &is, std::ostream &os) const if( is.eof() || !is.good() ) break; if( IncompleteLUT ) { - assert( idx < Internal->Length[RED] ); - assert( idx < Internal->Length[GREEN] ); - assert( idx < Internal->Length[BLUE] ); + gdcm_assert( idx < Internal->Length[RED] ); + gdcm_assert( idx < Internal->Length[GREEN] ); + gdcm_assert( idx < Internal->Length[BLUE] ); } rgb[RED] = Internal->RGB[3*idx+RED]; rgb[GREEN] = Internal->RGB[3*idx+GREEN]; @@ -491,9 +491,9 @@ void LookupTable::Decode(std::istream &is, std::ostream &os) const if( is.eof() || !is.good() ) break; if( IncompleteLUT ) { - assert( idx < Internal->Length[RED] ); - assert( idx < Internal->Length[GREEN] ); - assert( idx < Internal->Length[BLUE] ); + gdcm_assert( idx < Internal->Length[RED] ); + gdcm_assert( idx < Internal->Length[GREEN] ); + gdcm_assert( idx < Internal->Length[BLUE] ); } rgb[RED] = rgb16[3*idx+RED]; rgb[GREEN] = rgb16[3*idx+GREEN]; @@ -524,9 +524,9 @@ bool LookupTable::Decode(char *output, size_t outlen, const char *input, size_t { if( IncompleteLUT ) { - assert( *idx < Internal->Length[RED] ); - assert( *idx < Internal->Length[GREEN] ); - assert( *idx < Internal->Length[BLUE] ); + gdcm_assert( *idx < Internal->Length[RED] ); + gdcm_assert( *idx < Internal->Length[GREEN] ); + gdcm_assert( *idx < Internal->Length[BLUE] ); } rgb[RED] = Internal->RGB[3 * *idx+RED]; rgb[GREEN] = Internal->RGB[3 * *idx+GREEN]; @@ -538,16 +538,16 @@ bool LookupTable::Decode(char *output, size_t outlen, const char *input, size_t else if ( BitSample == 16 ) { const uint16_t *rgb16 = (const uint16_t*)(void*)Internal->RGB.data(); - assert( inlen % 2 == 0 ); + gdcm_assert( inlen % 2 == 0 ); const uint16_t * end = (const uint16_t*)(const void*)(input + inlen); uint16_t * rgb = (uint16_t*)(void*)output; for( const uint16_t * idx = (const uint16_t*)(const void*)input; idx != end; ++idx ) { if( IncompleteLUT ) { - assert( *idx < Internal->Length[RED] ); - assert( *idx < Internal->Length[GREEN] ); - assert( *idx < Internal->Length[BLUE] ); + gdcm_assert( *idx < Internal->Length[RED] ); + gdcm_assert( *idx < Internal->Length[GREEN] ); + gdcm_assert( *idx < Internal->Length[BLUE] ); } rgb[RED] = rgb16[3 * *idx+RED]; rgb[GREEN] = rgb16[3 * *idx+GREEN]; @@ -580,9 +580,9 @@ bool LookupTable::Decode8(char *output, size_t outlen, const char *input, size_t { if( IncompleteLUT ) { - assert( *idx < Internal->Length[RED] ); - assert( *idx < Internal->Length[GREEN] ); - assert( *idx < Internal->Length[BLUE] ); + gdcm_assert( *idx < Internal->Length[RED] ); + gdcm_assert( *idx < Internal->Length[GREEN] ); + gdcm_assert( *idx < Internal->Length[BLUE] ); } rgb[RED] = Internal->RGB[3 * *idx+RED]; rgb[GREEN] = Internal->RGB[3 * *idx+GREEN]; @@ -594,16 +594,16 @@ bool LookupTable::Decode8(char *output, size_t outlen, const char *input, size_t else if ( BitSample == 16 ) { const uint16_t *rgb16 = (const uint16_t*)(void*)Internal->RGB.data(); - assert( inlen % 2 == 0 ); + gdcm_assert( inlen % 2 == 0 ); const uint16_t * end = (const uint16_t*)(const void*)(input + inlen); uint8_t * rgb = (uint8_t*)output; for( const uint16_t * idx = (const uint16_t*)(const void*)input; idx != end; ++idx ) { if( IncompleteLUT ) { - assert( *idx < Internal->Length[RED] ); - assert( *idx < Internal->Length[GREEN] ); - assert( *idx < Internal->Length[BLUE] ); + gdcm_assert( *idx < Internal->Length[RED] ); + gdcm_assert( *idx < Internal->Length[GREEN] ); + gdcm_assert( *idx < Internal->Length[BLUE] ); } rgb[RED] = rgb16[3 * *idx+RED] >> 8; rgb[GREEN] = rgb16[3 * *idx+GREEN] >> 8; @@ -646,13 +646,13 @@ bool LookupTable::GetBufferAsRGBA(unsigned char *rgba) const else if ( BitSample == 16 ) { /* - assert( Internal->Length[type]*(BitSample/8) == length ); + gdcm_assert( Internal->Length[type]*(BitSample/8) == length ); uint16_t *uchar16 = (uint16_t*)&Internal->RGB[0]; const uint16_t *array16 = (uint16_t*)array; for( unsigned int i = 0; i < Internal->Length[type]; ++i) { - assert( 2*i < length ); - assert( 2*(3*i+type) < Internal->RGB.size() ); + gdcm_assert( 2*i < length ); + gdcm_assert( 2*(3*i+type) < Internal->RGB.size() ); uchar16[3*i+type] = array16[i]; std::cout << i << " -> " << array16[i] << "\n"; } @@ -704,18 +704,18 @@ bool LookupTable::WriteBufferAsRGBA(const unsigned char *rgba) } else if ( BitSample == 16 ) { - //assert( Internal->Length[type]*(BitSample/8) == length ); + //gdcm_assert( Internal->Length[type]*(BitSample/8) == length ); uint16_t *uchar16 = (uint16_t*)(void*)Internal->RGB.data(); const uint16_t *rgba16 = (const uint16_t*)(const void*)rgba; size_t s = Internal->RGB.size(); s /= 2; s /= 3; - assert( s == 65536 ); + gdcm_assert( s == 65536 ); for( unsigned int i = 0; i < s /*i < Internal->Length[type]*/; ++i) { - //assert( 2*i < length ); - //assert( 2*(3*i+type) < Internal->RGB.size() ); + //gdcm_assert( 2*i < length ); + //gdcm_assert( 2*(3*i+type) < Internal->RGB.size() ); //uchar16[3*i+type] = array16[i]; //std::cout << i << " -> " << array16[i] << "\n"; // RED @@ -748,7 +748,7 @@ void LookupTable::Print(std::ostream &os) const os << std::dec <RGB.size() ); + gdcm_assert( 2*(3*i+type) < Internal->RGB.size() ); const uint16_t val = SwapperDoOp::Swap(uchar16[3*i+type]); minlut[type] = std::min( minlut[type], val ); maxlut[type] = std::max( maxlut[type], val ); @@ -780,7 +780,7 @@ bool LookupTable::IsRGB8() const { for(int type = RED; type <= BLUE; ++type ) { - assert( 2*(3*i+type) < Internal->RGB.size() ); + gdcm_assert( 2*(3*i+type) < Internal->RGB.size() ); const uint16_t val = SwapperDoOp::Swap(uchar16[3*i+type]); minlut[type] = std::min( minlut[type], val ); maxlut[type] = std::max( maxlut[type], val ); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmLookupTable.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmLookupTable.h index bc2eb7c6fd0..643dca011fa 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmLookupTable.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmLookupTable.h @@ -82,9 +82,9 @@ class GDCM_EXPORT LookupTable : public Object /// Decode into RGB 8 bits space bool Decode8(char *outputbuffer, size_t outlen, const char *inputbuffer, size_t inlen) const; - LookupTable(LookupTable const &lut):Object(lut) + LookupTable(LookupTable const &lut):Object(lut), Internal(nullptr), BitSample(0), IncompleteLUT(false) { - assert(0); + gdcm_assert(0); } /// return the LUT as RGBA buffer diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmMeshPrimitive.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmMeshPrimitive.cxx index 8eb67b239a6..626e4eb6673 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmMeshPrimitive.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmMeshPrimitive.cxx @@ -33,7 +33,7 @@ static const char * MPStrings[] = { const char * MeshPrimitive::GetMPTypeString(const MPType type) { - assert( type <= MPType_END ); + gdcm_assert( type <= MPType_END ); return MPStrings[(int)type]; } @@ -86,7 +86,7 @@ MeshPrimitive::MPType MeshPrimitive::GetPrimitiveType() const void MeshPrimitive::SetPrimitiveType(const MPType type) { - assert( type <= MPType_END ); + gdcm_assert( type <= MPType_END ); PrimitiveType = type; } @@ -132,12 +132,12 @@ void MeshPrimitive::AddPrimitiveData(DataElement const & de) const DataElement & MeshPrimitive::GetPrimitiveData(const unsigned int idx) const { - assert( idx < this->GetNumberOfPrimitivesData() ); + gdcm_assert( idx < this->GetNumberOfPrimitivesData() ); return PrimitiveData[idx]; } DataElement & MeshPrimitive::GetPrimitiveData(const unsigned int idx) { - assert( idx < this->GetNumberOfPrimitivesData() ); + gdcm_assert( idx < this->GetNumberOfPrimitivesData() ); return PrimitiveData[idx]; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmOverlay.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmOverlay.cxx index 2298687f458..fd832bed860 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmOverlay.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmOverlay.cxx @@ -94,7 +94,7 @@ Overlay::Overlay(Overlay const &ov):Object(ov) Overlay & Overlay::operator=(Overlay const &ov) { - assert( Internal ); + gdcm_assert( Internal ); *Internal = *ov.Internal; return *this; } @@ -118,13 +118,13 @@ void Overlay::Update(const DataElement & de) Bit Position (60xx,0102) is always 0. */ - assert( de.GetTag().IsPublic() ); + gdcm_assert( de.GetTag().IsPublic() ); const ByteValue* bv = de.GetByteValue(); if( !bv ) return; // Discard any empty element (will default to another value) - assert( bv->GetPointer() && bv->GetLength() ); + gdcm_assert( bv->GetPointer() && bv->GetLength() ); std::string s( bv->GetPointer(), bv->GetLength() ); // What if a \0 can be found before the end of string... - //assert( strlen( s.c_str() ) == s.size() ); + //gdcm_assert( strlen( s.c_str() ) == s.size() ); // First thing check consistency: if( !GetGroup() ) @@ -133,7 +133,7 @@ void Overlay::Update(const DataElement & de) } else // check consistency { - assert( GetGroup() == de.GetTag().GetGroup() ); // programmer error + gdcm_assert( GetGroup() == de.GetTag().GetGroup() ); // programmer error } //std::cerr << "Tag: " << de.GetTag() << std::endl; @@ -185,7 +185,7 @@ void Overlay::Update(const DataElement & de) } else if( de.GetTag().GetElement() == 0x0060 ) // OverlayCompressionCode (RET) { - assert( s == "NONE" ); // FIXME ?? + gdcm_assert( s == "NONE" ); // FIXME ?? } else if( de.GetTag().GetElement() == 0x0100 ) // OverlayBitsAllocated { @@ -211,7 +211,7 @@ void Overlay::Update(const DataElement & de) } else if( de.GetTag().GetElement() == 0x0110 ) // OverlayFormat (RET) { - assert( s == "RECT" ); + gdcm_assert( s == "RECT" ); } else if( de.GetTag().GetElement() == 0x0200 ) // OverlayLocation (RET) { @@ -242,7 +242,7 @@ void Overlay::Update(const DataElement & de) else { gdcmErrorMacro( "Tag is not supported: " << de.GetTag() << std::endl ); - assert(0); + gdcm_assert(0); } } @@ -268,7 +268,7 @@ bool Overlay::GrabOverlayFromPixelData(DataSet const &ds) const unsigned int length = ovlength * 8 * 1; //bv->GetLength(); const uint8_t *p = (const uint8_t*)(const void*)array; const uint8_t *end = (const uint8_t*)(const void*)(array + length); - assert( 8 * ovlength == (unsigned int)Internal->Rows * Internal->Columns ); + gdcm_assert( 8 * ovlength == (unsigned int)Internal->Rows * Internal->Columns ); if( Internal->Data.empty() ) { gdcmWarningMacro("Internal Data is empty." ); @@ -277,11 +277,11 @@ bool Overlay::GrabOverlayFromPixelData(DataSet const &ds) unsigned char * overlay = (unsigned char*)Internal->Data.data(); int c = 0; uint8_t pmask = (uint8_t)(1 << Internal->BitPosition); - assert( length / 1 == ovlength * 8 ); + gdcm_assert( length / 1 == ovlength * 8 ); while( p != end ) { const uint8_t val = *p & pmask; - assert( val == 0x0 || val == pmask ); + gdcm_assert( val == 0x0 || val == pmask ); // 128 -> 0x80 if( val ) { @@ -294,11 +294,11 @@ bool Overlay::GrabOverlayFromPixelData(DataSet const &ds) ++p; ++c; } - assert( (unsigned)c / 8 == ovlength ); + gdcm_assert( (unsigned)c / 8 == ovlength ); } else if( Internal->BitsAllocated == 16 ) { - //assert( Internal->BitPosition >= 12 ); + //gdcm_assert( Internal->BitPosition >= 12 ); if( !ds.FindDataElement( Tag(0x7fe0,0x0010) ) ) { gdcmWarningMacro("Could not find Pixel Data. Cannot extract Overlay." ); @@ -312,7 +312,7 @@ bool Overlay::GrabOverlayFromPixelData(DataSet const &ds) gdcmWarningMacro("Could not extract overlay from encapsulated stream." ); return false; } - assert( bv ); + gdcm_assert( bv ); const char *array = bv->GetPointer(); // SIEMENS_GBS_III-16-ACR_NEMA_1.acr is pain to support, // I cannot simply use the bv->GetLength I have to use the image dim: @@ -320,7 +320,7 @@ bool Overlay::GrabOverlayFromPixelData(DataSet const &ds) const uint16_t *p = (const uint16_t*)(const void*)array; const uint16_t *end = (const uint16_t*)(const void*)(array + length); //const unsigned int ovlength = length / (8*2); - assert( 8 * ovlength == (unsigned int)Internal->Rows * Internal->Columns ); + gdcm_assert( 8 * ovlength == (unsigned int)Internal->Rows * Internal->Columns ); if( Internal->Data.empty() ) { gdcmWarningMacro("Internal Data is empty." ); @@ -329,11 +329,11 @@ bool Overlay::GrabOverlayFromPixelData(DataSet const &ds) unsigned char * overlay = (unsigned char*)Internal->Data.data(); int c = 0; uint16_t pmask = (uint16_t)(1 << Internal->BitPosition); - assert( length / 2 == ovlength * 8 ); + gdcm_assert( length / 2 == ovlength * 8 ); while( p != end ) { const uint16_t val = *p & pmask; - assert( val == 0x0 || val == pmask ); + gdcm_assert( val == 0x0 || val == pmask ); // 128 -> 0x80 if( val ) { @@ -346,7 +346,7 @@ bool Overlay::GrabOverlayFromPixelData(DataSet const &ds) ++p; ++c; } - assert( (unsigned)c / 8 == ovlength ); + gdcm_assert( (unsigned)c / 8 == ovlength ); } else { @@ -473,8 +473,8 @@ void Overlay::SetOverlay(const char *array, size_t length) std::copy(array, array+computed_length, Internal->Data.begin()); } /* warning need to take into account padding to the next word (8bits) */ - //assert( length == compute_bit_and_dicom_padding(Internal->Rows, Internal->Columns) ); - assert( Internal->Data.size() == computed_length ); + //gdcm_assert( length == compute_bit_and_dicom_padding(Internal->Rows, Internal->Columns) ); + gdcm_assert( Internal->Data.size() == computed_length ); } const ByteValue &Overlay::GetOverlayData() const @@ -498,7 +498,7 @@ bool Overlay::GetUnpackBuffer(char *buffer, size_t len) const const unsigned char *begin = unpackedbytes; for( std::vector::const_iterator it = Internal->Data.begin(); it != Internal->Data.end(); ++it ) { - assert( unpackedbytes <= begin + len ); // We never store more than actually required + gdcm_assert( unpackedbytes <= begin + len ); // We never store more than actually required // const unsigned char &packedbytes = *it; // weird bug with gcc 3.3 (prerelease on SuSE) apparently: unsigned char packedbytes = static_cast(*it); @@ -517,7 +517,7 @@ bool Overlay::GetUnpackBuffer(char *buffer, size_t len) const mask <<= 1; } } - assert(unpackedbytes <= begin + len); + gdcm_assert(unpackedbytes <= begin + len); return true; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmOverlay.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmOverlay.h index 89f055dead2..6659f77b170 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmOverlay.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmOverlay.h @@ -93,7 +93,12 @@ class GDCM_EXPORT Overlay : public Object /// set overlay from byte array + length void SetOverlay(const char *array, size_t length); - /// + + /// \warning Before calling this method, you must verify the consistency + /// between the image metadata (Image PixelFormat, Rows, Columns) and the + /// overlay parameters. This pre-verification is required to ensure that the + /// bit-depth is compatible and that the overlay data fits within the + /// allocated pixel storage. bool GrabOverlayFromPixelData(DataSet const &ds); /// Return the Overlay Data as ByteValue: diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPNMCodec.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPNMCodec.cxx index e63a020c3c3..e6c730986c9 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPNMCodec.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPNMCodec.cxx @@ -108,7 +108,7 @@ bool PNMCodec::Write(const char *filename, const DataElement &out) const gdcmErrorMacro( "PNM Codec does not handle compress syntax. You need to decompress first." ); return false; } - assert(bv); + gdcm_assert(bv); if( pi == PhotometricInterpretation::PALETTE_COLOR ) { @@ -179,7 +179,7 @@ bool PNMCodec::Read(const char *filename, DataElement &out) const is.get(); } std::streampos pos = is.tellg(); - //assert(pos < INT_MAX); + //gdcm_assert(pos < INT_MAX); size_t m = (len - (size_t)pos ) / ( dims[0]*dims[1] ); if( m * dims[0] * dims[1] != len - pos ) { @@ -218,7 +218,7 @@ bool PNMCodec::Read(const char *filename, DataElement &out) const //if ( maxval * 8 != bpp ) return 1; size_t pdlen = GetBufferLength(); - assert( pdlen ); + gdcm_assert( pdlen ); char * buf = new char[pdlen]; // is should be at right offset, just read! is.read(buf, len); @@ -253,7 +253,7 @@ bool PNMCodec::GetHeaderInfo(std::istream &is, TransferSyntax &ts) { is.seekg( 0, std::ios::end ); std::streampos len = is.tellg(); - //assert(len < INT_MAX); + //gdcm_assert(len < INT_MAX); is.seekg( 0, std::ios::beg ); std::string type, str; @@ -291,8 +291,8 @@ bool PNMCodec::GetHeaderInfo(std::istream &is, TransferSyntax &ts) is.get(); } std::streamoff pos = is.tellg(); - //assert(len < INT_MAX); - //assert(pos < INT_MAX); + //gdcm_assert(len < INT_MAX); + //gdcm_assert(pos < INT_MAX); size_t m = ((size_t)len - (size_t)pos ) / ( dims[0]*dims[1] ); bool cond; if( type == "P4" ) { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPersonName.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPersonName.h index 6948f9e00cb..3f8a27efbf2 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPersonName.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPersonName.h @@ -45,7 +45,7 @@ class GDCM_EXPORT PersonName unsigned int GetMaxLength() const { return MaxLength; } void SetBlob(const std::vector& v) { (void)v; - //assert(0); //TODO + //gdcm_assert(0); //TODO } void SetComponents(const char *comp1 = "", const char *comp2 = "", @@ -60,7 +60,7 @@ class GDCM_EXPORT PersonName for(unsigned int i = 0; i < 5; ++i) { if( components[i] && strlen(components[i]) < GetMaxLength() ) strcpy(Component[i], components[i]); - assert( strlen(Component[i]) < GetMaxLength() ); + gdcm_assert( strlen(Component[i]) < GetMaxLength() ); } } void Print(std::ostream &os) const diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPhotometricInterpretation.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPhotometricInterpretation.cxx index 71e4ddbc621..09ea51bcbc7 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPhotometricInterpretation.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPhotometricInterpretation.cxx @@ -62,7 +62,7 @@ static const char *PIStrings[] = { const char *PhotometricInterpretation::GetPIString(PIType pi) { - //assert( pi < PhotometricInterpretation::PI_END ); + //gdcm_assert( pi < PhotometricInterpretation::PI_END ); return PIStrings[pi]; } @@ -100,7 +100,7 @@ PhotometricInterpretation::PIType PhotometricInterpretation::GetPIType(const cha return PIType(i); } } - //assert(0); + //gdcm_assert(0); return PI_END; } @@ -124,8 +124,8 @@ unsigned short PhotometricInterpretation::GetSamplesPerPixel() const } else { - assert( PIField != PI_END ); - assert( //PIField == PALETTE_COLOR + gdcm_assert( PIField != PI_END ); + gdcm_assert( //PIField == PALETTE_COLOR PIField == RGB || PIField == HSV //|| PIField == ARGB @@ -167,11 +167,11 @@ bool PhotometricInterpretation::IsLossless() const case YBR_ICT: return false; default: - assert(0); + gdcm_assert(0); return false; } - assert( 0 ); // technically one should not reach here, unless UNKNOWN ... + gdcm_assert( 0 ); // technically one should not reach here, unless UNKNOWN ... return false; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixelFormat.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixelFormat.cxx index 37a1b708085..acb23efe23d 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixelFormat.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixelFormat.cxx @@ -47,7 +47,7 @@ PixelFormat::PixelFormat(ScalarType st) unsigned short PixelFormat::GetSamplesPerPixel() const { // \postcondition - assert( SamplesPerPixel == 1 || SamplesPerPixel == 3 || SamplesPerPixel == 4 ); + gdcm_assert( SamplesPerPixel == 1 || SamplesPerPixel == 3 || SamplesPerPixel == 4 ); return SamplesPerPixel; } @@ -120,7 +120,7 @@ void PixelFormat::SetScalarType(ScalarType st) PixelRepresentation = 0; break; default: - assert(0); + gdcm_assert(0); break; } BitsStored = BitsAllocated; @@ -171,23 +171,23 @@ PixelFormat::ScalarType PixelFormat::GetScalarType() const } else if( PixelRepresentation == 1 ) { - assert( type <= INT64 ); + gdcm_assert( type <= INT64 ); // That's why you need to order properly type in ScalarType type = ScalarType(int(type)+1); } else if( PixelRepresentation == 2 ) { - assert( BitsAllocated == 16 ); + gdcm_assert( BitsAllocated == 16 ); return FLOAT16; } else if( PixelRepresentation == 3 ) { - assert( BitsAllocated == 32 ); + gdcm_assert( BitsAllocated == 32 ); return FLOAT32; } else if( PixelRepresentation == 4 ) { - assert( BitsAllocated == 64 ); + gdcm_assert( BitsAllocated == 64 ); return FLOAT64; } else @@ -212,7 +212,7 @@ uint8_t PixelFormat::GetPixelSize() const } else { - assert( !(BitsAllocated % 8) ); + gdcm_assert( !(BitsAllocated % 8) ); } pixelsize *= SamplesPerPixel; @@ -221,7 +221,7 @@ uint8_t PixelFormat::GetPixelSize() const int64_t PixelFormat::GetMin() const { - assert( BitsAllocated ); // cannot be unknown + gdcm_assert( BitsAllocated ); // cannot be unknown if( BitsStored <= 32 ) { if( PixelRepresentation == 1 ) @@ -239,7 +239,7 @@ int64_t PixelFormat::GetMin() const int64_t PixelFormat::GetMax() const { - assert( BitsAllocated ); // cannot be unknown + gdcm_assert( BitsAllocated ); // cannot be unknown if( BitsStored <= 32 ) { if( PixelRepresentation == 1 ) @@ -270,14 +270,19 @@ bool PixelFormat::IsValid() const bool PixelFormat::Validate() { if( !IsValid() ) return false; - //assert( BitsStored >= HighBit ); // DigitexAlpha_no_7FE0.dcm - assert( PixelRepresentation == 0 || PixelRepresentation == 1 ); - assert( SamplesPerPixel == 1 || SamplesPerPixel == 3 || SamplesPerPixel == 4 ); + //gdcm_assert( BitsStored >= HighBit ); // DigitexAlpha_no_7FE0.dcm + gdcm_assert( PixelRepresentation == 0 || PixelRepresentation == 1 ); + gdcm_assert( SamplesPerPixel == 1 || SamplesPerPixel == 3 || SamplesPerPixel == 4 ); if ( BitsStored == 0 ) { gdcmDebugMacro( "Bits Stored is 0. Setting is to max value" ); BitsStored = BitsAllocated; } + if ( HighBit == 0 && BitsStored > 1 ) + { + gdcmDebugMacro( "High Bit is 0. Setting is to BitStored - 1" ); + HighBit = BitsStored - 1; + } if ( BitsAllocated == 24 ) { gdcmDebugMacro( "ACR-NEMA way of storing RGB data. Updating" ); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixelFormat.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixelFormat.h index 89100e855dd..d736562a6fd 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixelFormat.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixelFormat.h @@ -93,7 +93,7 @@ class GDCM_EXPORT PixelFormat { gdcmAssertMacro( spp <= 4 ); SamplesPerPixel = spp; - assert( SamplesPerPixel == 1 || SamplesPerPixel == 3 || SamplesPerPixel == 4 ); + gdcm_assert( SamplesPerPixel == 1 || SamplesPerPixel == 3 || SamplesPerPixel == 4 ); } /// BitsAllocated see Tag (0028,0100) US Bits Allocated @@ -128,7 +128,7 @@ class GDCM_EXPORT PixelFormat /// BitsStored see Tag (0028,0101) US Bits Stored unsigned short GetBitsStored() const { - assert( BitsStored <= BitsAllocated ); + gdcm_assert( BitsStored <= BitsAllocated ); return BitsStored; } void SetBitsStored(unsigned short bs) @@ -151,7 +151,7 @@ class GDCM_EXPORT PixelFormat /// HighBit see Tag (0028,0102) US High Bit unsigned short GetHighBit() const { - assert( HighBit < BitsStored ); + gdcm_assert( HighBit < BitsStored ); return HighBit; } void SetHighBit(unsigned short hb) @@ -165,7 +165,9 @@ class GDCM_EXPORT PixelFormat case 0x0ffe: hb = 11; break; case 0x00fe: hb = 7; break; } - if( hb < BitsStored ) + if( BitsStored > 1 && hb == 0 ) + HighBit = BitsStored - 1; + else if( hb < BitsStored ) HighBit = hb; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmap.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmap.cxx index 13fb2d216df..1f41afa9e82 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmap.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmap.cxx @@ -45,7 +45,7 @@ bool Pixmap::AreOverlaysInPixelData() const { total += (int)it->IsInPixelData(); } - assert( total == (int)GetNumberOfOverlays() || !total ); + gdcm_assert( total == (int)GetNumberOfOverlays() || !total ); return total != 0; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmap.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmap.h index 85f9d9ce890..bd85a856338 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmap.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmap.h @@ -43,11 +43,11 @@ class GDCM_EXPORT Pixmap : public Bitmap /// Curve: group 50xx Curve& GetCurve(size_t i = 0) { - assert( i < Curves.size() ); + gdcm_assert( i < Curves.size() ); return Curves[i]; } const Curve& GetCurve(size_t i = 0) const { - assert( i < Curves.size() ); + gdcm_assert( i < Curves.size() ); return Curves[i]; } size_t GetNumberOfCurves() const { return Curves.size(); } @@ -55,17 +55,17 @@ class GDCM_EXPORT Pixmap : public Bitmap /// Overlay: group 60xx Overlay& GetOverlay(size_t i = 0) { - assert( i < Overlays.size() ); + gdcm_assert( i < Overlays.size() ); return Overlays[i]; } const Overlay& GetOverlay(size_t i = 0) const { - assert( i < Overlays.size() ); + gdcm_assert( i < Overlays.size() ); return Overlays[i]; } size_t GetNumberOfOverlays() const { return Overlays.size(); } void SetNumberOfOverlays(size_t n) { Overlays.resize(n); } void RemoveOverlay(size_t i) { - assert( i < Overlays.size() ); + gdcm_assert( i < Overlays.size() ); Overlays.erase( Overlays.begin() + i ); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmapReader.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmapReader.cxx index 258a23c1fcc..e4ce4397977 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmapReader.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmapReader.cxx @@ -81,8 +81,8 @@ bool PixmapReader::Read() { // I cannot leave this here, since ELSCINT1 / LOSSLESS RICE declares CT Image Storage, // when in fact this is a private Media Storage (no Pixel Data element) - //assert( ds.FindDataElement( Tag(0x7fe0,0x0010 ) ) ); - assert( ts != TransferSyntax::TS_END && ms != MediaStorage::MS_END ); + //gdcm_assert( ds.FindDataElement( Tag(0x7fe0,0x0010 ) ) ); + gdcm_assert( ts != TransferSyntax::TS_END && ms != MediaStorage::MS_END ); // Good it's the easy case. It's declared as an Image: //PixelData->SetCompressionFromTransferSyntax( ts ); res = ReadImage(ms); @@ -94,7 +94,7 @@ bool PixmapReader::Read() else { MediaStorage ms2 = ds.GetMediaStorage(); - //assert( !ds.FindDataElement( Tag(0x7fe0,0x0010 ) ) ); + //gdcm_assert( !ds.FindDataElement( Tag(0x7fe0,0x0010 ) ) ); if( ms == MediaStorage::MediaStorageDirectoryStorage && ms2 == MediaStorage::MS_END ) { gdcmDebugMacro( "DICOM file is not an Image file but a : " << @@ -146,7 +146,7 @@ bool PixmapReader::Read() } else // there is a Unknown Media Storage Syntax { - assert( ts != TransferSyntax::TS_END && ms == MediaStorage::MS_END ); + gdcm_assert( ts != TransferSyntax::TS_END && ms == MediaStorage::MS_END ); // god damit I don't know what to do... gdcmWarningMacro( "Attempting to read this file as a DICOM file" "\nDesperate attempt" ); @@ -253,7 +253,7 @@ static void DoIconImage(const DataSet& rootds, Pixmap& image) pi = PhotometricInterpretation::GetPIType( photometricinterpretation_str.c_str()); } - assert( pi != PhotometricInterpretation::UNKNOWN); + gdcm_assert( pi != PhotometricInterpretation::UNKNOWN); pixeldata.SetPhotometricInterpretation( pi ); // @@ -263,7 +263,7 @@ static void DoIconImage(const DataSet& rootds, Pixmap& image) const Tag testseglut(0x0028, (0x1221 + 0)); if( ds.FindDataElement( testseglut ) ) { - assert(0 && "Please report this image"); + gdcm_assert(0 && "Please report this image"); lut = new SegmentedPaletteColorLookupTable; } //SmartPointer lut = new SegmentedPaletteColorLookupTable; @@ -297,11 +297,11 @@ static void DoIconImage(const DataSet& rootds, Pixmap& image) if( ds.FindDataElement( tlut ) ) { const ByteValue *lut_raw = ds.GetDataElement( tlut ).GetByteValue(); - assert( lut_raw ); + gdcm_assert( lut_raw ); // LookupTableType::RED == 0 lut->SetLUT( LookupTable::LookupTableType(i), (const unsigned char*)lut_raw->GetPointer(), lut_raw->GetLength() ); - //assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); + //gdcm_assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); unsigned long check = (el_us3.GetValue(0) ? el_us3.GetValue(0) : 65536) @@ -316,15 +316,15 @@ static void DoIconImage(const DataSet& rootds, Pixmap& image) else if( ds.FindDataElement( seglut ) ) { const ByteValue *lut_raw = ds.GetDataElement( seglut ).GetByteValue(); - assert( lut_raw ); + gdcm_assert( lut_raw ); lut->SetLUT( LookupTable::LookupTableType(i), (const unsigned char*)lut_raw->GetPointer(), lut_raw->GetLength() ); - //assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); + //gdcm_assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); //unsigned long check = // (el_us3.GetValue(0) ? el_us3.GetValue(0) : 65536) // * el_us3.GetValue(2) / 8; - //assert( check == lut_raw->GetLength() ); (void)check; + //gdcm_assert( check == lut_raw->GetLength() ); (void)check; } else { @@ -389,7 +389,7 @@ static void DoCurves(const DataSet& ds, Pixmap& pixeldata) ++idxcurves; // move on to the next one curve = de.GetTag(); uint16_t currentcurve = curve.GetGroup(); - assert( !(currentcurve % 2) ); // 0x6001 is not an curve... + gdcm_assert( !(currentcurve % 2) ); // 0x6001 is not an curve... // Now loop on all element from this current group: DataElement de2 = de; while( de2.GetTag().GetGroup() == currentcurve ) @@ -406,7 +406,7 @@ static void DoCurves(const DataSet& ds, Pixmap& pixeldata) } } //std::cout << "Num of curves: " << numcurves << std::endl; - assert( idxcurves == numcurves ); + gdcm_assert( idxcurves == numcurves ); } } @@ -466,10 +466,10 @@ static unsigned int GetNumberOfOverlaysInternal(DataSet const & ds, std::vector< && ds.FindDataElement( toverlaybitpos ) ) { // Overlay Pixel are in Unused Pixel - assert( !ds.FindDataElement( toverlaydata ) ); + gdcm_assert( !ds.FindDataElement( toverlaydata ) ); const DataElement& overlayrows = ds.GetDataElement( toverlayrows ); const DataElement& overlaycols = ds.GetDataElement( toverlaycols ); - assert( ds.FindDataElement( toverlaybitpos ) ); + gdcm_assert( ds.FindDataElement( toverlaybitpos ) ); const DataElement& overlaybitpos = ds.GetDataElement( toverlaybitpos ); if( !overlayrows.IsEmpty() && !overlaycols.IsEmpty() && !overlaybitpos.IsEmpty() ) { @@ -485,13 +485,13 @@ static unsigned int GetNumberOfOverlaysInternal(DataSet const & ds, std::vector< } // at most one out of two : - assert( numoverlays < 0x00ff / 2 ); + gdcm_assert( numoverlays < 0x00ff / 2 ); // PS 3.3 - 2004: // C.9.2 Overlay plane module // Each Overlay Plane is one bit deep. Sixteen separate Overlay Planes may be associated with an // Image or exist as Standalone Overlays in a Series - assert( numoverlays <= 16 ); - assert( numoverlays == overlaylist.size() ); + gdcm_assert( numoverlays <= 16 ); + gdcm_assert( numoverlays == overlaylist.size() ); return numoverlays; } @@ -512,7 +512,7 @@ static bool DoOverlays(const DataSet& ds, Pixmap& pixeldata) Tag overlay(0x6000,0x0000); overlay.SetGroup( currentoverlay ); const DataElement &de = ds.FindNextDataElement( overlay ); - assert( !(currentoverlay % 2) ); // 0x6001 is not an overlay... + gdcm_assert( !(currentoverlay % 2) ); // 0x6001 is not an overlay... // Now loop on all element from this current group: DataElement de2 = de; while( de2.GetTag().GetGroup() == currentoverlay ) @@ -531,12 +531,12 @@ static bool DoOverlays(const DataSet& ds, Pixmap& pixeldata) // since the overlays are stored in the unused bit of the PixelData if( !ov.IsEmpty() ) { - //assert( unpack.str().size() / 8 == ((ov.GetRows() * ov.GetColumns()) + 7 ) / 8 ); - assert( ov.IsInPixelData( ) == false ); + //gdcm_assert( unpack.str().size() / 8 == ((ov.GetRows() * ov.GetColumns()) + 7 ) / 8 ); + gdcm_assert( ov.IsInPixelData( ) == false ); } else if( pixeldata.GetPixelFormat().GetSamplesPerPixel() == 1 ) { - assert( ov.IsEmpty() ); + gdcm_assert( ov.IsEmpty() ); gdcmDebugMacro( "This image does not contains Overlay in the 0x60xx tags. " << "Instead the overlay is stored in the unused bit of the Pixel Data." << std::endl ); @@ -546,7 +546,44 @@ static bool DoOverlays(const DataSet& ds, Pixmap& pixeldata) { gdcmWarningMacro( "Bits Allocated are wrong. Correcting." ); ov.SetBitsAllocated( pixeldata.GetPixelFormat().GetBitsAllocated() ); - } + } + const DataElement &pixeldataDe = ds.GetDataElement(Tag(0x7fe0, 0x0010)); + const ByteValue *bv = pixeldataDe.GetByteValue(); + if (!bv) { + gdcmWarningMacro( + "Could not extract overlay from encapsulated stream."); + continue; + } + unsigned long computedFramePixelsNb = + pixeldata.GetDimension(0) * pixeldata.GetDimension(1); + + if (pixeldata.GetPixelFormat().GetPixelSize() == 0 || + computedFramePixelsNb > + bv->GetLength() / pixeldata.GetPixelFormat().GetPixelSize()) { + gdcmWarningMacro("Image information is not persistent. Can't extract overlay #" + << idxoverlays); + continue; + } + signed short ovOriginY = ov.GetOrigin()[0]; + signed short ovOriginX = ov.GetOrigin()[1]; + long startPixel = + (ovOriginX - 1) + (ovOriginY - 1) * pixeldata.GetDimension(0); + if (startPixel < 0 || + (unsigned long)startPixel >= computedFramePixelsNb) { + gdcmWarningMacro( + "Origin is not in image buffer. Can't extract overlay #" + << idxoverlays); + continue; + } + unsigned long lastPixelAccessed = + (unsigned long)startPixel + + (ov.GetRows() - 1) * pixeldata.GetDimension(0) + + (ov.GetColumns() - 1); + if (lastPixelAccessed >= computedFramePixelsNb) { + gdcmWarningMacro("Overlay not fit image buffer. Can't extract overlay " + << idxoverlays); + continue; + } if( !ov.GrabOverlayFromPixelData(ds) ) { @@ -631,13 +668,17 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat { // PHILIPS_Gyroscan-12-MONO2-Jpeg_Lossless.dcm // PHILIPS_Gyroscan-12-Jpeg_Extended_Process_2_4.dcm - gdcmDebugMacro( "Mixture of ACR NEMA and DICOM file" ); - isacrnema = true; const char *str = ds.GetDataElement( trecognitioncode ).GetByteValue()->GetPointer(); - assert( strncmp( str, "ACR-NEMA", strlen( "ACR-NEMA" ) ) == 0 || - strncmp( str, "ACRNEMA", strlen( "ACRNEMA" ) ) == 0 || - strncmp( str, "MIPS 2.0", strlen( "MIPS 2.0" ) ) == 0 ); - (void)str;//warning removal + if( strncmp( str, "ACR-NEMA", strlen( "ACR-NEMA" ) ) == 0 || + strncmp( str, "ACRNEMA", strlen( "ACRNEMA" ) ) == 0 || + strncmp( str, "MIPS 2.0", strlen( "MIPS 2.0" ) ) == 0) { + gdcmDebugMacro("Mixture of ACR NEMA and DICOM file"); + isacrnema = true; + } else { + Attribute<0x0008, 0x0010> at; + at.SetFromDataSet(ds); + gdcmWarningMacro("Junk recognition code: " + at.GetValue()); + } } std::vector vdims = ImageHelper::GetDimensionsValue(*F); @@ -674,7 +715,9 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat } else { - assert( MediaStorage::IsImage( ms ) ); + if( !MediaStorage::IsImage( ms ) ) { + gdcmWarningMacro("Wrong SOP Class"); + } // D 0028|0100 [US] [Bits Allocated] [16] //pf.SetBitsAllocated( // ReadUSFromTag( Tag(0x0028, 0x0100), ss, conversion ) ); @@ -683,7 +726,7 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat Attribute<0x0028,0x0100> at = { 0 }; at.SetFromDataSet( ds ); pf.SetBitsAllocated( at.GetValue() ); - //assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0100), ss, conversion ) ); + //gdcm_assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0100), ss, conversion ) ); } // D 0028|0101 [US] [Bits Stored] [12] @@ -694,7 +737,7 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat Attribute<0x0028,0x0101> at = { 0 }; at.SetFromDataSet( ds ); pf.SetBitsStored( at.GetValue() ); - //assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0101), ss, conversion ) ); + //gdcm_assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0101), ss, conversion ) ); } // D 0028|0102 [US] [High Bit] [11] @@ -705,7 +748,7 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat Attribute<0x0028,0x0102> at = { 0 }; at.SetFromDataSet( ds ); pf.SetHighBit( at.GetValue() ); - //assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0102), ss, conversion ) ); + //gdcm_assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0102), ss, conversion ) ); } // D 0028|0103 [US] [Pixel Representation] [0] @@ -718,7 +761,7 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat Attribute<0x0028,0x0103> at = { 0 }; at.SetFromDataSet( ds ); pf.SetPixelRepresentation( at.GetValue() ); - //assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0103), ss, conversion ) ); + //gdcm_assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0103), ss, conversion ) ); } // else @@ -772,7 +815,7 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat return false; } } - assert( pi != PhotometricInterpretation::PI_END ); + gdcm_assert( pi != PhotometricInterpretation::PI_END ); if( !pf.GetSamplesPerPixel() || (pi.GetSamplesPerPixel() != pf.GetSamplesPerPixel()) ) { if( pi != PhotometricInterpretation::UNKNOWN ) @@ -928,7 +971,7 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat // LookupTableType::RED == 0 lut->SetLUT( LookupTable::LookupTableType(i), (const unsigned char*)lut_raw->GetPointer(), lut_raw->GetLength() ); - //assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); + //gdcm_assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); } else { @@ -938,7 +981,7 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat unsigned long check = (el_us3.GetValue(0) ? el_us3.GetValue(0) : 65536) * el_us3.GetValue(2) / 8; - assert( !lut->Initialized() || check == lut_raw->GetLength() ); (void)check; + gdcm_assert( !lut->Initialized() || check == lut_raw->GetLength() ); (void)check; } else if( ds.FindDataElement( seglut ) ) { @@ -947,7 +990,7 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat { lut->SetLUT( LookupTable::LookupTableType(i), (const unsigned char*)lut_raw->GetPointer(), lut_raw->GetLength() ); - //assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); + //gdcm_assert( pf.GetBitsAllocated() == el_us3.GetValue(2) ); } else { @@ -957,7 +1000,7 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat //unsigned long check = // (el_us3.GetValue(0) ? el_us3.GetValue(0) : 65536) // * el_us3.GetValue(2) / 8; - //assert( check == lut_raw->GetLength() ); (void)check; + //gdcm_assert( check == lut_raw->GetLength() ); (void)check; } else { @@ -968,10 +1011,10 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat PixelData->SetLUT(*lut); } // TODO - //assert( pi.GetSamplesPerPixel() == pf.GetSamplesPerPixel() ); + //gdcm_assert( pi.GetSamplesPerPixel() == pf.GetSamplesPerPixel() ); // 5.5 Do IconImage if any - assert( PixelData->GetIconImage().IsEmpty() ); + gdcm_assert( PixelData->GetIconImage().IsEmpty() ); DoIconImage(ds, *PixelData); // 6. Do the Curves if any @@ -1059,8 +1102,8 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat v[0] = PixelData->GetDimensions()[0]; v[1] = PixelData->GetDimensions()[1]; v[2] = PixelData->GetDimensions()[2]; - assert( jpeg.GetDimensions()[0] ); - assert( jpeg.GetDimensions()[1] ); + gdcm_assert( jpeg.GetDimensions()[0] ); + gdcm_assert( jpeg.GetDimensions()[1] ); v[0] = jpeg.GetDimensions()[0]; v[1] = jpeg.GetDimensions()[1]; PixelData->SetDimensions( v.data() ); @@ -1076,7 +1119,7 @@ bool PixmapReader::ReadImageInternal(MediaStorage const &ms, bool handlepixeldat gdcmDebugMacro( "Fix photometric interpretation." ); PixelData->SetPhotometricInterpretation( jpeg.GetPhotometricInterpretation() ); } - assert( PixelData->IsTransferSyntaxCompatible( ts ) ); + gdcm_assert( PixelData->IsTransferSyntaxCompatible( ts ) ); } else { @@ -1156,10 +1199,10 @@ bool PixmapReader::ReadACRNEMAImage() { Attribute<0x0028,0x0005> at0 = { 0 }; at0.SetFromDataElement( de0 ); - assert( at0.GetNumberOfValues() == 1 ); + gdcm_assert( at0.GetNumberOfValues() == 1 ); imagedimensions = at0.GetValue(); } - //assert( imagedimensions == ReadSSFromTag( timagedimensions, ss, conversion ) ); + //gdcm_assert( imagedimensions == ReadSSFromTag( timagedimensions, ss, conversion ) ); if ( imagedimensions == 3 ) { PixelData->SetNumberOfDimensions(3); @@ -1167,9 +1210,9 @@ bool PixmapReader::ReadACRNEMAImage() const DataElement& de1 = ds.GetDataElement( Tag(0x0028, 0x0012) ); Attribute<0x0028,0x0012> at1 = { 0 }; at1.SetFromDataElement( de1 ); - assert( at1.GetNumberOfValues() == 1 ); + gdcm_assert( at1.GetNumberOfValues() == 1 ); PixelData->SetDimension(2, at1.GetValue() ); - //assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0012), ss, conversion ) ); + //gdcm_assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0012), ss, conversion ) ); } else if ( imagedimensions == 2 ) { @@ -1194,7 +1237,7 @@ bool PixmapReader::ReadACRNEMAImage() Attribute<0x0028,0x0011> at = { 0 }; at.SetFromDataSet( ds ); PixelData->SetDimension(0, at.GetValue() ); - //assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0011), ss, conversion ) ); + //gdcm_assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0011), ss, conversion ) ); } // D 0028|0010 [US] [Rows] [512] @@ -1203,7 +1246,7 @@ bool PixmapReader::ReadACRNEMAImage() Attribute<0x0028,0x0010> at = { 0 }; at.SetFromDataSet( ds ); PixelData->SetDimension(1, at.GetValue() ); - //assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0010), ss, conversion ) ); + //gdcm_assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0010), ss, conversion ) ); } // This is the definition of an ACR NEMA image: @@ -1214,13 +1257,13 @@ bool PixmapReader::ReadACRNEMAImage() if( ds.FindDataElement( trecognitioncode ) && !ds.GetDataElement( trecognitioncode ).IsEmpty() ) { const ByteValue *libido = ds.GetDataElement(trecognitioncode).GetByteValue(); - assert( libido ); + gdcm_assert( libido ); std::string libido_str( libido->GetPointer(), libido->GetLength() ); - assert( libido_str != "CANRME_AILIBOD1_1." ); + gdcm_assert( libido_str != "CANRME_AILIBOD1_1." ); if( strcmp(libido_str.c_str() , "ACRNEMA_LIBIDO_1.1") == 0 || strcmp(libido_str.c_str() , "ACRNEMA_LIBIDO_1.0") == 0 ) { // Swap Columns & Rows - // assert( PixelData->GetNumberOfDimensions() == 2 ); + // gdcm_assert( PixelData->GetNumberOfDimensions() == 2 ); const unsigned int *dims = PixelData->GetDimensions(); unsigned int tmp = dims[0]; PixelData->SetDimension(0, dims[1] ); @@ -1228,7 +1271,7 @@ bool PixmapReader::ReadACRNEMAImage() } else { - assert( libido_str == "ACR-NEMA 2.0" + gdcm_assert( libido_str == "ACR-NEMA 2.0" || libido_str == "ACR-NEMA 1.0" ); } } @@ -1237,7 +1280,7 @@ bool PixmapReader::ReadACRNEMAImage() gdcmWarningMacro( "Reading as ACR NEMA an image which does not look likes ACR NEMA" ); // File: acc-max.dcm is it ACR or DICOM ? - // assert(0); + // gdcm_assert(0); } // 3. Pixel Format ? @@ -1248,7 +1291,7 @@ bool PixmapReader::ReadACRNEMAImage() Attribute<0x0028,0x0100> at = { 0 }; at.SetFromDataSet( ds ); pf.SetBitsAllocated( at.GetValue() ); - //assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0100), ss, conversion ) ); + //gdcm_assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0100), ss, conversion ) ); } // D 0028|0101 [US] [Bits Stored] [12] @@ -1257,7 +1300,7 @@ bool PixmapReader::ReadACRNEMAImage() Attribute<0x0028,0x0101> at = { 0 }; at.SetFromDataSet( ds ); pf.SetBitsStored( at.GetValue() ); - //assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0101), ss, conversion ) ); + //gdcm_assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0101), ss, conversion ) ); } // D 0028|0102 [US] [High Bit] [11] @@ -1266,7 +1309,7 @@ bool PixmapReader::ReadACRNEMAImage() Attribute<0x0028,0x0102> at = { 0 }; at.SetFromDataSet( ds ); pf.SetHighBit( at.GetValue() ); - //assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0102), ss, conversion ) ); + //gdcm_assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0102), ss, conversion ) ); } // D 0028|0103 [US] [Pixel Representation] [0] @@ -1275,7 +1318,7 @@ bool PixmapReader::ReadACRNEMAImage() Attribute<0x0028,0x0103> at = { 0 }; at.SetFromDataSet( ds ); pf.SetPixelRepresentation( at.GetValue() ); - //assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0103), ss, conversion ) ); + //gdcm_assert( at.GetValue() == ReadUSFromTag( Tag(0x0028, 0x0103), ss, conversion ) ); } PixelData->SetPixelFormat( pf ); @@ -1295,7 +1338,7 @@ bool PixmapReader::ReadACRNEMAImage() const DataElement& de = ds.GetDataElement( pixeldata ); if ( de.GetVR() == VR::OW ) { - //assert(0); + //gdcm_assert(0); //PixelData->SetNeedByteSwap(true); } PixelData->SetDataElement( de ); @@ -1328,7 +1371,7 @@ bool PixmapReader::ReadACRNEMAImage() { const ByteValue *photometricinterpretation = ds.GetDataElement( tphotometricinterpretation ).GetByteValue(); - assert( photometricinterpretation ); + gdcm_assert( photometricinterpretation ); std::string photometricinterpretation_str( photometricinterpretation->GetPointer(), photometricinterpretation->GetLength() ); @@ -1342,7 +1385,7 @@ bool PixmapReader::ReadACRNEMAImage() // Wild guess: if( PixelData->GetPixelFormat().GetSamplesPerPixel() == 1 ) { - assert( PixelData->GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME2 ); + gdcm_assert( PixelData->GetPhotometricInterpretation() == PhotometricInterpretation::MONOCHROME2 ); // No need... //PixelData->SetPhotometricInterpretation( PhotometricInterpretation::MONOCHROME2 ); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmapWriter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmapWriter.cxx index ecc6622877a..9cdab775da6 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmapWriter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPixmapWriter.cxx @@ -110,7 +110,7 @@ Attribute<0x0028,0x0004> piat; if ( pi == PhotometricInterpretation::PALETTE_COLOR ) { const LookupTable &lut = icon.GetLUT(); - assert( (pf.GetBitsAllocated() == 8 && pf.GetPixelRepresentation() == 0) + gdcm_assert( (pf.GetBitsAllocated() == 8 && pf.GetPixelRepresentation() == 0) || (pf.GetBitsAllocated() == 16 && pf.GetPixelRepresentation() == 0) ); // lut descriptor: // (0028,1101) US 256\0\16 # 6, 3 RedPaletteColorLookupTableDescriptor @@ -182,7 +182,7 @@ Attribute<0x0028,0x0004> piat; de.SetValue( v ); const ByteValue *bv = de.GetByteValue(); const TransferSyntax &ts = icon.GetTransferSyntax(); - assert( ts.IsExplicit() || ts.IsImplicit() ); + gdcm_assert( ts.IsExplicit() || ts.IsImplicit() ); VL vl; if( bv ) { @@ -207,7 +207,7 @@ Attribute<0x0028,0x0004> piat; de.SetVR( VR::OW ); break; default: - assert( 0 && "should not happen" ); + gdcm_assert( 0 && "should not happen" ); break; } } @@ -253,14 +253,14 @@ bool PixmapWriter::PrepareWrite( MediaStorage const & ref_ms ) if( PixelData->GetNumberOfDimensions() == 3 ) { Attribute<0x0028, 0x0008> numberofframes; - assert( PixelData->GetDimension(2) >= 1 ); + gdcm_assert( PixelData->GetDimension(2) >= 1 ); numberofframes.SetValue( PixelData->GetDimension(2) ); ds.Replace( numberofframes.GetAsDataElement() ); } else if( ds.FindDataElement(tnumberofframes) ) // Remove Number Of Frames { - assert( PixelData->GetNumberOfDimensions() == 2 ); - assert( PixelData->GetDimension(2) == 1 ); + gdcm_assert( PixelData->GetNumberOfDimensions() == 2 ); + gdcm_assert( PixelData->GetDimension(2) == 1 ); ds.Remove( tnumberofframes ); } #endif @@ -280,7 +280,7 @@ bool PixmapWriter::PrepareWrite( MediaStorage const & ref_ms ) } { - assert( pi != PhotometricInterpretation::UNKNOWN ); + gdcm_assert( pi != PhotometricInterpretation::UNKNOWN ); const char *pistr = PhotometricInterpretation::GetPIString(pi); DataElement de( Tag(0x0028, 0x0004 ) ); VL::Type strlenPistr = (VL::Type)strlen(pistr); @@ -335,8 +335,8 @@ bool PixmapWriter::PrepareWrite( MediaStorage const & ref_ms ) if ( pi == PhotometricInterpretation::PALETTE_COLOR ) { const LookupTable &lut = PixelData->GetLUT(); - assert( lut.Initialized() ); -// assert( (pf.GetBitsAllocated() == 8 && pf.GetPixelRepresentation() == 0) + gdcm_assert( lut.Initialized() ); +// gdcm_assert( (pf.GetBitsAllocated() == 8 && pf.GetPixelRepresentation() == 0) // || (pf.GetBitsAllocated() == 16 && pf.GetPixelRepresentation() == 0) ); // lut descriptor: // (0028,1101) US 256\0\16 # 6, 3 RedPaletteColorLookupTableDescriptor @@ -503,7 +503,7 @@ bool PixmapWriter::PrepareWrite( MediaStorage const & ref_ms ) bvpixdata = depixdata.GetByteValue(); } const TransferSyntax &ts = PixelData->GetTransferSyntax(); - assert( ts.IsExplicit() || ts.IsImplicit() ); + gdcm_assert( ts.IsExplicit() || ts.IsImplicit() ); // It is perfectly ok to store a lossy image using a J2K (this is odd, but valid). // as long as your mark LossyImageCompression with value 1 @@ -576,6 +576,12 @@ bool PixmapWriter::PrepareWrite( MediaStorage const & ref_ms ) } else { + if( ts_orig == TransferSyntax::JPEG2000Lossless ) + { + static const CSComp newvalues2[] = {"ISO_15444_1"}; + at3.SetValues( newvalues2, 1 ); + ds.Replace( at3.GetAsDataElement() ); + } if( ds.FindDataElement( at1.GetTag() ) ) { at1.Set( ds ); if( atoi(at1.GetValue().c_str()) != 1 ) { @@ -584,16 +590,13 @@ bool PixmapWriter::PrepareWrite( MediaStorage const & ref_ms ) ds.Replace( at1.GetAsDataElement() ); } } else { + at1.SetValue( "01" ); + ds.Replace( at1.GetAsDataElement() ); + // Assume originally JPEGLossy and override previous value ISO_15444_1 if( pi_orig == PhotometricInterpretation::YBR_FULL_422 ) { - at1.SetValue( "01" ); - ds.Replace( at1.GetAsDataElement() ); - static const CSComp newvalues2[] = {"ISO_10918_1"}; at3.SetValues( newvalues2, 1 ); ds.Replace( at3.GetAsDataElement() ); - } else { - gdcmErrorMacro( "Unhandled Lossy flag for Pixel Data" ); - return false; } } } @@ -627,7 +630,7 @@ bool PixmapWriter::PrepareWrite( MediaStorage const & ref_ms ) depixdata.SetVR( VR::OW ); break; default: - assert( 0 && "should not happen" ); + gdcm_assert( 0 && "should not happen" ); break; } } @@ -695,7 +698,7 @@ bool PixmapWriter::PrepareWrite( MediaStorage const & ref_ms ) } else { - assert( bv->GetLength() == strlen( msstr ) || bv->GetLength() == strlen(msstr) + 1 ); + gdcm_assert( bv->GetLength() == strlen( msstr ) || bv->GetLength() == strlen(msstr) + 1 ); } } ImageHelper::SetDimensionsValue(file, *PixelData); @@ -786,7 +789,7 @@ bool PixmapWriter::PrepareWrite( MediaStorage const & ref_ms ) if( GetCheckFileMetaInformation() ) { fmi.Clear(); - //assert( ts == TransferSyntax::ImplicitVRLittleEndian ); + //gdcm_assert( ts == TransferSyntax::ImplicitVRLittleEndian ); { const char *tsuid = TransferSyntax::GetTSString( ts ); DataElement de( Tag(0x0002,0x0010) ); @@ -829,7 +832,7 @@ bool PixmapWriter::Write() } if( !PrepareWrite( ms ) ) return false; - assert( Stream ); + gdcm_assert( Stream ); if( !Writer::Write() ) { return false; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPrinter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPrinter.cxx index b7a45fac90e..9dd66c92a7b 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPrinter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmPrinter.cxx @@ -141,8 +141,8 @@ void PrintValue(VR::VRType const &vr, VM const &vm, const Value &v); template inline char *bswap(char *out, const char *in, size_t length) { - assert( !(length % sizeof(T)) ); - assert( out != in ); + gdcm_assert( !(length % sizeof(T)) ); + gdcm_assert( out != in ); for(size_t i = 0; i < length; i+=2) { //const char copy = in[i]; @@ -193,15 +193,15 @@ void Printer::PrintElement(std::ostream& os, const ImplicitDataElement &ide, Dic #define PrinterTemplateSubCase1n(type,rep) \ case VM::rep: \ {Element e; \ - /*assert( VM::rep == VM::VM1_n );*/ \ + /*gdcm_assert( VM::rep == VM::VM1_n );*/ \ e.SetArray( (const VRToType::Type *)array, length, true ); \ e.Print( os ); }\ break; #define PrinterTemplateSubCase(type,rep) \ case VM::rep: \ {Element e; \ - /*assert( bv.GetLength() == VMToLength::Length * sizeof( VRToType::Type) ); */ \ - assert( bv.GetLength() == e.GetLength() * sizeof( VRToType::Type) ); \ + /*gdcm_assert( bv.GetLength() == VMToLength::Length * sizeof( VRToType::Type) ); */ \ + gdcm_assert( bv.GetLength() == e.GetLength() * sizeof( VRToType::Type) ); \ memcpy( (void*)(&e), array, e.GetLength() * sizeof( VRToType::Type) ); \ e.Print( os ); }\ break; @@ -215,12 +215,12 @@ PrinterTemplateSubCase(type, VM5) \ PrinterTemplateSubCase(type, VM6) \ PrinterTemplateSubCase(type, VM24) \ PrinterTemplateSubCase1n(type, VM1_n) \ -default: assert(0); } +default: gdcm_assert(0); } #define PrinterTemplateSub2(type) \ switch(vm) { \ PrinterTemplateSubCase1n(type, VM1) \ -default: assert(0); } +default: gdcm_assert(0); } #define PrinterTemplateCase(type) \ case VR::type: \ @@ -259,7 +259,7 @@ PrinterTemplateCase(UL) \ PrinterTemplateCase(UN) \ PrinterTemplateCase(US) \ PrinterTemplateCase(UT) \ -default: assert(0); } +default: gdcm_assert(0); } void PrintValue(VR::VRType const &vr, VM const &vm, const Value &v) { @@ -309,8 +309,8 @@ void Printer::PrintDataSet(std::ostream& os, const DataSet VM::VMType vm = entry.GetVM(); if( /*de.GetTag().GetGroup()%2 &&*/ de.GetTag().GetElement() == 0 ) { - assert( vr == VR::INVALID || vr == VR::UL ); - assert( vm == VM::VM0 || vm == VM::VM1 ); + gdcm_assert( vr == VR::INVALID || vr == VR::UL ); + gdcm_assert( vm == VM::VM0 || vm == VM::VM1 ); vr = VR::UL; vm = VM::VM1; } @@ -334,7 +334,7 @@ void Printer::PrintDataSet(std::ostream& os, const DataSet //VM::VMType vm = VM::VM1; if( t == Tag(0x7fe0,0x0010) ) { - assert( vr == VR::OB_OW ); + gdcm_assert( vr == VR::OB_OW ); vr = VR::OW; //vm = VM::VM1_n; } @@ -346,7 +346,7 @@ void Printer::PrintDataSet(std::ostream& os, const DataSet // The component points shall be encoded in Little Endian. else if( t == Tag(0x5004,0x3000) ) // FIXME { - assert( vr == VR::OB_OW ); + gdcm_assert( vr == VR::OB_OW ); vr = VR::OB; } // Value of pixels not present in the native image added to an image @@ -374,12 +374,12 @@ void Printer::PrintDataSet(std::ostream& os, const DataSet const ByteValue &bv = static_cast(value); // FIXME: unsigned short pixel_rep_value = *(unsigned short*)(bv.GetPointer()); - assert( pixel_rep_value == 0x0 || pixel_rep_value == 0x1 ); + gdcm_assert( pixel_rep_value == 0x0 || pixel_rep_value == 0x1 ); vr = pixel_rep_value ? VR::SS : VR::US; } else { - assert(0); + gdcm_assert(0); } } @@ -387,7 +387,7 @@ void Printer::PrintDataSet(std::ostream& os, const DataSet } else { - assert(0); + gdcm_assert(0); const Value& val = de.GetValue(); _os << de.GetTag(); if ( printVR ) @@ -448,7 +448,7 @@ void Printer::PrintDataSet(std::ostream& os, const DataSet os << ""; } \ else { if( de.IsEmpty() ) os << GDCM_TERMINAL_VT100_INVERSE << "(no value)" << GDCM_TERMINAL_VT100_NORMAL; \ else os << GDCM_TERMINAL_VT100_INVERSE << GDCM_TERMINAL_VT100_FOREGROUND_RED << "(VR=" << refvr << " is incompatible with length)" << GDCM_TERMINAL_VT100_NORMAL; } } \ - else { assert( de.IsEmpty()); os << GDCM_TERMINAL_VT100_INVERSE << "(no value)" << GDCM_TERMINAL_VT100_NORMAL; } \ + else { gdcm_assert( de.IsEmpty()); os << GDCM_TERMINAL_VT100_INVERSE << "(no value)" << GDCM_TERMINAL_VT100_NORMAL; } \ } break VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const DataSet & ds, @@ -472,7 +472,7 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D const VM &vm = entry.GetVM(); const char *name = entry.GetName(); bool retired = entry.GetRetired(); - //if( t.IsPrivate() ) assert( retired == false ); + //if( t.IsPrivate() ) gdcm_assert( retired == false ); const VR &vr_read = de.GetVR(); const VL &vl_read = de.GetVL(); @@ -500,8 +500,8 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D refvr = DataSetHelper::ComputeVR(*F,ds, t); } - assert( refvr != VR::US_SS ); - assert( refvr != VR::OB_OW ); + gdcm_assert( refvr != VR::US_SS ); + gdcm_assert( refvr != VR::OB_OW ); if( !de.IsEmpty() ) { @@ -510,21 +510,21 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D { sqi = de.GetValueAsSQ(); refvr = VR::SQ; - assert( refvr == VR::SQ ); + gdcm_assert( refvr == VR::SQ ); } #if 0 else if( vr == VR::SQ && vr_read != VR::SQ ) { sqi = de.GetValueAsSQ(); refvr = VR::SQ; - assert( refvr == VR::SQ ); + gdcm_assert( refvr == VR::SQ ); } #endif } if( (vr_read == VR::INVALID || vr_read == VR::UN ) && vl_read.IsUndefined() ) { - assert( refvr == VR::SQ ); + gdcm_assert( refvr == VR::SQ ); } // if( vr_read == VR::SQ || vr_read == VR::UN ) @@ -533,7 +533,7 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D // } if( vr != VR::INVALID && (!vr.Compatible( vr_read ) || vr_read == VR::INVALID || vr_read == VR::UN || vr_read != refvr ) ) { - assert( vr != VR::INVALID ); + gdcm_assert( vr != VR::INVALID ); bool valid = true; if( vr_read == VR::SQ ) { if( !vr.Compatible( vr_read ) ) { @@ -560,14 +560,14 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D os << GDCM_TERMINAL_VT100_FOREGROUND_GREEN; os << "(SQ) "; os << GDCM_TERMINAL_VT100_NORMAL; - assert( refvr == VR::INVALID ); + gdcm_assert( refvr == VR::INVALID ); refvr = VR::SQ; } // Print Value now: if( refvr & VR::VRASCII ) { - assert( !sqi && !sqf ); + gdcm_assert( !sqi && !sqf ); if( bv ) { VL l = std::min( bv->GetLength(), MaxPrintLength ); @@ -587,7 +587,7 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D } else { - assert( de.IsEmpty() ); + gdcm_assert( de.IsEmpty() ); os << GDCM_TERMINAL_VT100_INVERSE; os << "(no value)"; os << GDCM_TERMINAL_VT100_NORMAL; @@ -595,7 +595,7 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D } else { - assert( refvr & VR::VRBINARY || (vr == VR::INVALID && refvr == VR::INVALID) ); + gdcm_assert( refvr & VR::VRBINARY || (vr == VR::INVALID && refvr == VR::INVALID) ); //std::ostringstream os; std::string s; switch(refvr) @@ -642,7 +642,7 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D } else if ( sqf ) { - assert( t == Tag(0x7fe0,0x0010) ); + gdcm_assert( t == Tag(0x7fe0,0x0010) || t == Tag(0x7fe1,0x1060) ); //os << *sqf; } else if ( sqi ) @@ -653,15 +653,15 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D } else { - assert( !sqi && !sqf ); - assert( de.IsEmpty() ); + gdcm_assert( !sqi && !sqf ); + gdcm_assert( de.IsEmpty() ); os << GDCM_TERMINAL_VT100_INVERSE << "(no value)" << GDCM_TERMINAL_VT100_NORMAL; } } break; case VR::US_SS: // impossible... - assert( refvr != VR::US_SS ); + gdcm_assert( refvr != VR::US_SS ); break; case VR::SQ: if( !sqi /*!de.GetSequenceOfItems()*/ && !de.IsEmpty() && de.GetValue().GetLength() ) @@ -709,8 +709,8 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D } else { - assert( !sqi && !sqf ); - assert( de.IsEmpty() ); + gdcm_assert( !sqi && !sqf ); + gdcm_assert( de.IsEmpty() ); os << GDCM_TERMINAL_VT100_INVERSE << "(no value)" << GDCM_TERMINAL_VT100_NORMAL; } } @@ -742,7 +742,7 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D case VR::VR_VM1: case VR::VRALL: case VR::VR_END: - assert(0); + gdcm_assert(0); break; } os << s; @@ -788,8 +788,8 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D VM guessvm = VM::VM0; if( refvr & VR::VRASCII ) { - assert( refvr != VR::INVALID ); - assert( refvr & VR::VRASCII ); + gdcm_assert( refvr != VR::INVALID ); + gdcm_assert( refvr & VR::VRASCII ); if( bv ) { size_t count = VM::GetNumberOfElementsFromArray(bv->GetPointer(), bv->GetLength()); @@ -798,8 +798,8 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D } else if( refvr & VR::VRBINARY ) { - assert( refvr != VR::INVALID ); - assert( refvr & VR::VRBINARY ); + gdcm_assert( refvr != VR::INVALID ); + gdcm_assert( refvr & VR::VRBINARY ); if( refvr & VR::OB_OW || refvr == VR::OD || refvr == VR::OF || refvr == VR::SQ ) { guessvm = VM::VM1; @@ -816,7 +816,7 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D else { if( de.IsEmpty() ) guessvm = VM::VM0; - else assert( 0 && "Impossible" ); + else gdcm_assert( 0 && "Impossible" ); } } else if( refvr == VR::INVALID ) @@ -827,7 +827,7 @@ VR Printer::PrintDataElement(std::ostringstream &os, const Dicts &dicts, const D else { // Burst into flames ! - assert( 0 && "Impossible happen" ); + gdcm_assert( 0 && "Impossible happen" ); } if( !vm.Compatible( guessvm ) ) { @@ -939,7 +939,7 @@ void Printer::PrintDataSet(const DataSet &ds, std::ostream &out, std::string con const SequenceOfItems *sqi = de.GetSequenceOfItems(); if( sqi ) // empty SQ ? { - assert( sqi ); + gdcm_assert( sqi ); PrintSQ(sqi, os, indent); } else diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRAWCodec.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRAWCodec.cxx index 18ca7227415..65bd0d4421a 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRAWCodec.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRAWCodec.cxx @@ -62,7 +62,7 @@ bool RAWCodec::CanDecode(TransferSyntax const &ts) const bool RAWCodec::Code(DataElement const &in, DataElement &out) { out = in; - //assert(0); + //gdcm_assert(0); return true; } @@ -77,14 +77,14 @@ bool RAWCodec::DecodeBytes(const char* inBytes, size_t inBufferLength, GetPixelFormat().GetBitsAllocated() != 12 && !NeedOverlayCleanup ) { - assert( !NeedOverlayCleanup ); - assert( PI != PhotometricInterpretation::YBR_PARTIAL_422 ); - assert( PI != PhotometricInterpretation::YBR_PARTIAL_420 ); - assert( PI != PhotometricInterpretation::YBR_ICT ); - assert( this->GetPixelFormat() != PixelFormat::UINT12 ); - assert( this->GetPixelFormat() != PixelFormat::INT12 ); + gdcm_assert( !NeedOverlayCleanup ); + gdcm_assert( PI != PhotometricInterpretation::YBR_PARTIAL_422 ); + gdcm_assert( PI != PhotometricInterpretation::YBR_PARTIAL_420 ); + gdcm_assert( PI != PhotometricInterpretation::YBR_ICT ); + gdcm_assert( this->GetPixelFormat() != PixelFormat::UINT12 ); + gdcm_assert( this->GetPixelFormat() != PixelFormat::INT12 ); // DermaColorLossLess.dcm - //assert(inBufferLength == inOutBufferLength || inBufferLength == inOutBufferLength + 1); + //gdcm_assert(inBufferLength == inOutBufferLength || inBufferLength == inOutBufferLength + 1); // What if the user request a subportion of the image: // this happen in the case of MOSAIC image, where we are only interested in the non-zero // pixel of the tiled image. @@ -102,13 +102,13 @@ bool RAWCodec::DecodeBytes(const char* inBytes, size_t inBufferLength, return true; } // else - assert( inBytes ); - assert( outBytes ); + gdcm_assert( inBytes ); + gdcm_assert( outBytes ); std::stringstream is; is.write(inBytes, inBufferLength); std::stringstream os; bool r = DecodeByStreams(is, os); - assert( r ); + gdcm_assert( r ); if(!r) return false; std::string str = os.str(); @@ -116,36 +116,35 @@ bool RAWCodec::DecodeBytes(const char* inBytes, size_t inBufferLength, if( this->GetPixelFormat() == PixelFormat::UINT12 || this->GetPixelFormat() == PixelFormat::INT12 ) { - size_t len = str.size() * 16 / 12; - char * copy = new char[len]; - bool b = Unpacker12Bits::Unpack(copy, str.data(), str.size() ); - if (!b) - { - delete[] copy; - return false; - } - assert (len == inOutBufferLength); - assert(inOutBufferLength == len); - memcpy(outBytes, copy, len); - - delete[] copy; - this->GetPixelFormat().SetBitsAllocated( 16 ); + const size_t len = str.size() * 16 / 12; + if(len == inOutBufferLength) { + char * copy = new char[len]; + bool b = Unpacker12Bits::Unpack(copy, str.data(), str.size() ); + if (!b) + { + delete[] copy; + return false; + } + gdcm_assert(inOutBufferLength == len); + memcpy(outBytes, copy, len); + + delete[] copy; + return r; } + } + + // DermaColorLossLess.dcm + //assert (check == inOutBufferLength || check == inOutBufferLength + 1); + // problem with: SIEMENS_GBS_III-16-ACR_NEMA_1.acr + size_t len = str.size(); + if( inOutBufferLength <= len ) + memcpy(outBytes, str.c_str(), inOutBufferLength); else - { - // DermaColorLossLess.dcm - //assert (check == inOutBufferLength || check == inOutBufferLength + 1); - // problem with: SIEMENS_GBS_III-16-ACR_NEMA_1.acr - size_t len = str.size(); - if( inOutBufferLength <= len ) - memcpy(outBytes, str.c_str(), inOutBufferLength); - else - { - gdcmWarningMacro( "Requesting too much data. Truncating result" ); - memcpy(outBytes, str.c_str(), len); - } - } + { + gdcmWarningMacro( "Requesting too much data. Truncating result" ); + memcpy(outBytes, str.c_str(), len); + } return r; } @@ -160,20 +159,20 @@ bool RAWCodec::Decode(DataElement const &in, DataElement &out) GetPixelFormat().GetBitsAllocated() != 12 && !NeedOverlayCleanup ) { - assert( this->GetPixelFormat() != PixelFormat::UINT12 ); - assert( this->GetPixelFormat() != PixelFormat::INT12 ); + gdcm_assert( this->GetPixelFormat() != PixelFormat::UINT12 ); + gdcm_assert( this->GetPixelFormat() != PixelFormat::INT12 ); out = in; return true; } // else const ByteValue *bv = in.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); std::stringstream is; is.write(bv->GetPointer(), bv->GetLength()); std::stringstream os; bool r = DecodeByStreams(is, os); if(!r) return false; - assert( r ); + gdcm_assert( r ); std::string str = os.str(); //std::string::size_type check = str.size(); @@ -186,7 +185,7 @@ bool RAWCodec::Decode(DataElement const &in, DataElement &out) size_t len = str.size() * 16 / 12; char * copy = new char[len];//why use an array, and not a vector? bool b = Unpacker12Bits::Unpack(copy, str.data(), str.size() ); - assert( b ); + gdcm_assert(b); (void)b; VL::Type lenSize = (VL::Type)len; out.SetByteValue( copy, lenSize ); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRLECodec.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRLECodec.cxx index 38c77852fb3..8a741139441 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRLECodec.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRLECodec.cxx @@ -24,6 +24,7 @@ #include // ptrdiff_t fix #include #include +#include #include @@ -33,37 +34,75 @@ namespace gdcm // TODO ideally this code should be in utilities for ease of reuse class RLEHeader { +private: + uint32_t NumSegments = 0; + uint32_t Offset[15] = {0}; + public: - uint32_t NumSegments; - uint32_t Offset[15]; + uint32_t GetNumSegments() const { return NumSegments; } + bool SetNumSegments(uint32_t num) + { + if (num > 15) + { + gdcmErrorMacro("Number of segments cannot be bigger than 15"); + return false; + } + NumSegments = num; + return true; + }; + bool SetOffset(const std::array &offset) + { + std::copy(offset.begin(), offset.end(), Offset); + return true; + }; + uint32_t GetOffset(size_t index) const + { + if (index < 15) return Offset[index]; + return 0; + }; + bool SetOffset(size_t index, uint32_t value) { + if (index >= 15) return false; - void Print(std::ostream &os) + Offset[index] = value; + return true; + } + + bool Read(std::istream &is) { - os << "NumSegments:" << NumSegments << "\n"; - for(int i=0; i<15; ++i) - { - os << i << ":" << Offset[i] << "\n"; + // read Header (64 bytes) + uint32_t buffer[16] = {0}; + is.read(reinterpret_cast(buffer), 64); + if (static_cast(is.gcount()) != 64) + { + gdcmErrorMacro("RLE Header truncated: expected 64 bytes, got " << is.gcount()); + return false; + } + gdcm_assert(sizeof(uint32_t) * 16 == 64); + SwapperNoOp::SwapArray(reinterpret_cast(buffer), 16); + if (!SetNumSegments(buffer[0])) return false; + memcpy(Offset, &buffer[1], sizeof(uint32_t) * 15); + if (NumSegments >= 1) { + if (Offset[0] != 64) return false; + } + // We just check that we are indeed at the proper position start+64 + return true; + } + void Print(std::ostream &os) + { + os << "NumSegments:" << NumSegments << "\n"; + for (int i = 0; i < 15; ++i) { + os << i << ":" << Offset[i] << "\n"; } } -}; +}; +static_assert(sizeof(RLEHeader) == 64, "RLEHeader size must be 64 bits to comply with dicom standard"); class RLEFrame { public: bool Read(std::istream &is) { - // read Header (64 bytes) - is.read((char*)(&Header), sizeof(uint32_t)*16); - assert( sizeof(uint32_t)*16 == 64 ); - assert( sizeof(RLEHeader) == 64 ); - SwapperNoOp::SwapArray((uint32_t*)&Header,16); - uint32_t numSegments = Header.NumSegments; - if( numSegments >= 1 ) - { - if( Header.Offset[0] != 64 ) return false; - } - // We just check that we are indeed at the proper position start+64 - return true; + return Header.Read(is); } void Print(std::ostream &os) { @@ -125,7 +164,7 @@ separately and not cross a row boundary. */ inline int count_identical_bytes(const char *start, size_t len) { - assert( len ); + gdcm_assert( len ); #if 0 const char *p = start + 1; const unsigned int cmin = std::min(128u,len); @@ -144,8 +183,8 @@ inline int count_identical_bytes(const char *start, size_t len) //std::cerr << "count/len:" << count << "," << len << std::endl; ++count; } - assert( /*2 <= count && */ count <= 128 ); // remove post condition as it will be our return error code - assert( count >= 1 ); + gdcm_assert( /*2 <= count && */ count <= 128 ); // remove post condition as it will be our return error code + gdcm_assert( count >= 1 ); return count; #endif } @@ -158,7 +197,7 @@ inline int count_nonrepetitive_bytes(const char *start, size_t len) Note: It is common to encode a 2-byte repeat run as a Replicate Run except when preceded and followed by a Literal Run, in which case it's best to merge the three runs into a Literal Run. */ - assert( len ); + gdcm_assert( len ); #if 0 const char *prev = start; const char *p = start + 1; @@ -211,7 +250,7 @@ a Literal Run, in which case it's best to merge the three runs into a Literal Ru } #endif #endif - assert( 1 <= count && count <= 128 ); + gdcm_assert( 1 <= count && count <= 128 ); return count; #endif } @@ -224,8 +263,8 @@ ptrdiff_t rle_encode(char *output, size_t outputlength, const char *input, size_ size_t length = inputlength; while( pin != input + inputlength ) { - assert( length <= inputlength ); - assert( pin <= input + inputlength ); + gdcm_assert( length <= inputlength ); + gdcm_assert( pin <= input + inputlength ); int count = count_identical_bytes(pin, length); if( count > 1 ) /* or 2 ? */ { @@ -234,8 +273,8 @@ ptrdiff_t rle_encode(char *output, size_t outputlength, const char *input, size_ // Test first we are allowed to write two bytes: if( pout + 1 + 1 > output + outputlength ) return -1; *pout = (char)(-count + 1); - assert( /**pout != -128 &&*/ 1 - *pout == count ); - assert( *pout <= -1 && *pout >= -127 ); + gdcm_assert( /**pout != -128 &&*/ 1 - *pout == count ); + gdcm_assert( *pout <= -1 && *pout >= -127 ); ++pout; *pout = *pin; ++pout; @@ -248,8 +287,8 @@ ptrdiff_t rle_encode(char *output, size_t outputlength, const char *input, size_ // first test we are allowed to write 1 + count bytes in the output buffer: if( pout + count + 1 > output + outputlength ) return -1; *pout = (char)(count - 1); - assert( *pout != -128 && *pout+1 == count ); - assert( *pout >= 0 ); + gdcm_assert( *pout != -128 && *pout+1 == count ); + gdcm_assert( *pout >= 0 ); ++pout; memcpy(pout, pin, count); pout += count; @@ -257,7 +296,7 @@ ptrdiff_t rle_encode(char *output, size_t outputlength, const char *input, size_ // count byte where read, move pin to new position: pin += count; // compute remaining length: - assert( count <= (int)length ); + gdcm_assert( count <= (int)length ); length -= count; } return pout - output; @@ -270,8 +309,8 @@ bool DoInvertPlanarConfiguration(T *output, const T *input, uint32_t inputlength const T *g = input+1; const T *b = input+2; uint32_t length = (inputlength / 3) * 3; // remove the 0 padding - assert( length == inputlength || length == inputlength - 1 ); - assert( length % 3 == 0 ); + gdcm_assert( length == inputlength || length == inputlength - 1 ); + gdcm_assert( length % 3 == 0 ); uint32_t plane_length = length / 3; T *pout = output; // copy red plane: @@ -280,23 +319,23 @@ bool DoInvertPlanarConfiguration(T *output, const T *input, uint32_t inputlength *pout++ = *r; r += 3; } - assert( r == input + length ); + gdcm_assert( r == input + length ); // copy green plane: - assert( pout == output + plane_length ); + gdcm_assert( pout == output + plane_length ); while( pout != output + plane_length * 2 ) { *pout++ = *g; g += 3; } - assert( g == input + length + 1); + gdcm_assert( g == input + length + 1); // copy blue plane: - assert( pout == output + 2*plane_length ); + gdcm_assert( pout == output + 2*plane_length ); while( pout != output + plane_length * 3 ) { *pout++ = *b; b += 3; } - assert( b == input + length + 2); + gdcm_assert( b == input + length + 2); assert ( pout == output + length ); return true; } @@ -321,7 +360,7 @@ bool RLECodec::Code(DataElement const &in, DataElement &out) //sq->GetTable().SetByteValue( dummy, sizeof(dummy) ); const ByteValue *bv = in.GetByteValue(); - assert( bv ); + gdcm_assert( bv ); const char *input = bv->GetPointer(); unsigned long bvl = bv->GetLength(); unsigned long image_len = bvl / dims[2]; @@ -372,14 +411,16 @@ bool RLECodec::Code(DataElement const &in, DataElement &out) MaxNumSegments *= 3; } - assert( GetPixelFormat().GetBitsAllocated() == 8 || GetPixelFormat().GetBitsAllocated() == 16 + gdcm_assert( GetPixelFormat().GetBitsAllocated() == 8 || GetPixelFormat().GetBitsAllocated() == 16 || GetPixelFormat().GetBitsAllocated() == 32 ); if( GetPixelFormat().GetSamplesPerPixel() == 3 ) { - assert( MaxNumSegments % 3 == 0 ); + gdcm_assert( MaxNumSegments % 3 == 0 ); } - RLEHeader header = { static_cast ( MaxNumSegments ), { 64 } }; + RLEHeader header; + header.SetNumSegments(static_cast(MaxNumSegments)); + header.SetOffset({64}); // there cannot be any space in between the end of the RLE header and the start // of the first RLE segment // @@ -402,7 +443,7 @@ bool RLECodec::Code(DataElement const &in, DataElement &out) } else /* ( GetPixelFormat().GetBitsAllocated() == 32 ) */ { - assert( GetPixelFormat().GetBitsAllocated() == 32 ); + gdcm_assert( GetPixelFormat().GetBitsAllocated() == 32 ); DoInvertPlanarConfiguration( (int32_t*)(void*)bufferrgb, (const int32_t*)(const void*)ptr_img, @@ -413,15 +454,15 @@ bool RLECodec::Code(DataElement const &in, DataElement &out) } if( GetPixelFormat().GetBitsAllocated() == 32 ) { - assert( !(image_len % 4) ); - //assert( image_len % 3 == 0 ); + gdcm_assert( !(image_len % 4) ); + //gdcm_assert( image_len % 3 == 0 ); unsigned int div = GetPixelFormat().GetSamplesPerPixel(); for(unsigned int j = 0; j < div; ++j) { unsigned long iimage_len = image_len / div; char *ibuffer = buffer + j * iimage_len; const char *iptr_img = ptr_img + j * iimage_len; - assert( iimage_len % 4 == 0 ); + gdcm_assert( iimage_len % 4 == 0 ); for(unsigned long i = 0; i < iimage_len/4; ++i) { #ifdef GDCM_WORDS_BIGENDIAN @@ -459,15 +500,15 @@ bool RLECodec::Code(DataElement const &in, DataElement &out) } else if( GetPixelFormat().GetBitsAllocated() == 16 ) { - assert( !(image_len % 2) ); - //assert( image_len % 3 == 0 ); + gdcm_assert( !(image_len % 2) ); + //gdcm_assert( image_len % 3 == 0 ); unsigned int div = GetPixelFormat().GetSamplesPerPixel(); for(unsigned int j = 0; j < div; ++j) { unsigned long iimage_len = image_len / div; char *ibuffer = buffer + j * iimage_len; const char *iptr_img = ptr_img + j * iimage_len; - assert( iimage_len % 2 == 0 ); + gdcm_assert( iimage_len % 2 == 0 ); for(unsigned long i = 0; i < iimage_len/2; ++i) { #ifdef GDCM_WORDS_BIGENDIAN @@ -487,23 +528,23 @@ bool RLECodec::Code(DataElement const &in, DataElement &out) } ptr_img = buffer; } - assert( image_len % MaxNumSegments == 0 ); + gdcm_assert( image_len % MaxNumSegments == 0 ); const size_t input_seg_length = image_len / MaxNumSegments; std::string datastr; for(unsigned int seg = 0; seg < MaxNumSegments; ++seg ) { size_t partition = input_seg_length; const char *ptr = ptr_img + seg * input_seg_length; - assert( ptr < ptr_img + image_len ); + gdcm_assert( ptr < ptr_img + image_len ); if( seg == MaxNumSegments - 1 ) { partition += image_len % MaxNumSegments; - assert( (MaxNumSegments-1) * input_seg_length + partition == (size_t)image_len ); + gdcm_assert( (MaxNumSegments-1) * input_seg_length + partition == (size_t)image_len ); } - assert( partition == input_seg_length ); + gdcm_assert( partition == input_seg_length ); std::stringstream data; - assert( partition % dims[1] == 0 ); + gdcm_assert( partition % dims[1] == 0 ); size_t length = 0; // Do not cross row boundary: for(unsigned int y = 0; y < dims[1]; ++y) @@ -516,22 +557,22 @@ bool RLECodec::Code(DataElement const &in, DataElement &out) delete[] bufferrgb; return false; } - assert( llength ); + gdcm_assert( llength ); data.write((char*)outbuf, llength); length += llength; } // update header - header.Offset[1+seg] = (uint32_t)(header.Offset[seg] + length); + header.SetOffset(1 + seg, (uint32_t)(header.GetOffset(seg) + length)); - assert( data.str().size() == length ); + gdcm_assert( data.str().size() == length ); datastr += data.str(); } - header.Offset[MaxNumSegments] = 0; + header.SetOffset(MaxNumSegments, 0); std::stringstream os; //header.Print( std::cout ); os.write((char*)&header,sizeof(header)); std::string str = os.str() + datastr; - assert( !str.empty() ); + gdcm_assert( !str.empty() ); Fragment frag; //frag.SetTag( itemStart ); VL::Type strSize = (VL::Type)str.size(); @@ -574,7 +615,7 @@ size_t RLECodec::DecodeFragment(Fragment const & frag, char *buffer, size_t llen #if !defined(NDEBUG) const unsigned int * const dimensions = this->GetDimensions(); const PixelFormat & pf = this->GetPixelFormat(); - assert( llen == dimensions[0] * dimensions[1] * pf.GetPixelSize() ); + gdcm_assert( llen == dimensions[0] * dimensions[1] * pf.GetPixelSize() ); #endif bool r = DecodeByStreams(is, os); if( !r ) return 0; @@ -587,7 +628,7 @@ size_t RLECodec::DecodeFragment(Fragment const & frag, char *buffer, size_t llen // which is discarded std::streamoff check = bv.GetLength() - p; // check == 2 for gdcmDataExtra/gdcmSampleData/US_DataSet/GE_US/2929J686-breaker - //assert( check == 0 || check == 1 || check == 2 ); + //gdcm_assert( check == 0 || check == 1 || check == 2 ); if( check ) { gdcmDebugMacro( "tiny offset detected in between RLE segments: " << check ); } } else @@ -622,7 +663,7 @@ bool RLECodec::Decode(DataElement const &in, DataElement &out) } std::string str = os.str(); std::string::size_type check = str.size(); - assert( check == len ); + gdcm_assert( check == len ); VL::Type checkCast = (VL::Type)check; out.SetByteValue( str.data(), checkCast ); return true; @@ -644,7 +685,7 @@ bool RLECodec::Decode(DataElement const &in, DataElement &out) } char *buffer = new char[len]; const std::size_t llen = len / nframes; - // assert( GetNumberOfDimensions() == 2 + // gdcm_assert( GetNumberOfDimensions() == 2 // || GetDimension(2) == sf->GetNumberOfFragments() ); bool corruption = false; for(unsigned int i = 0; i < nframes; ++i) @@ -659,7 +700,7 @@ bool RLECodec::Decode(DataElement const &in, DataElement &out) pos += (unsigned long)llen; } if( !corruption ) - assert( pos == len ); + gdcm_assert( pos == len ); out.SetByteValue( buffer, (uint32_t)len ); delete[] buffer; return !corruption; @@ -682,9 +723,9 @@ bool RLECodec::DecodeExtent( const unsigned int * dimensions = this->GetDimensions(); const PixelFormat & pf = this->GetPixelFormat(); - assert( pf.GetBitsAllocated() % 8 == 0 ); - assert( pf != PixelFormat::SINGLEBIT ); - assert( pf != PixelFormat::UINT12 && pf != PixelFormat::INT12 ); + gdcm_assert( pf.GetBitsAllocated() % 8 == 0 ); + gdcm_assert( pf != PixelFormat::SINGLEBIT ); + gdcm_assert( pf != PixelFormat::UINT12 && pf != PixelFormat::INT12 ); // skip std::stringstream os; @@ -703,7 +744,7 @@ bool RLECodec::DecodeExtent( SetLength( dimensions[0] * dimensions[1] * pf.GetPixelSize() ); const bool r = DecodeByStreams(is, os); (void)r; if( !r ) return false; - assert( r ); + gdcm_assert( r ); // handle DICOM padding std::streampos end = is.tellg(); @@ -712,12 +753,12 @@ bool RLECodec::DecodeExtent( { // Special handling for ALOKA_SSD-8-MONO2-RLE-SQ.dcm size_t diff = numberOfReadBytes - frag.GetVL(); - assert( diff == 1 ); + gdcm_assert( diff == 1 ); os.seekp( 0 - (int)diff, std::ios::cur ); os.put( 0 ); end = (size_t)end - 1; } - assert( end - start == frag.GetVL() || (size_t)(end - start) + 1 == frag.GetVL() ); + gdcm_assert( end - start == frag.GetVL() || (size_t)(end - start) + 1 == frag.GetVL() ); // sync is (rle16loo.dcm) if( (end - start) % 2 == 1 ) { @@ -726,7 +767,7 @@ bool RLECodec::DecodeExtent( } // for each z os.seekg(0, std::ios::beg ); - assert( os.good() ); + gdcm_assert( os.good() ); std::istream *theStream = &os; unsigned int rowsize = xmax - xmin + 1; @@ -769,12 +810,12 @@ bool RLECodec::DecodeByStreams(std::istream &is, std::ostream &os) RLEFrame &frame = Internals->Frame; if( !frame.Read(is) ) return false; - unsigned long numSegments = frame.Header.NumSegments; + unsigned long numSegments = frame.Header.GetNumSegments(); unsigned long length = Length; - assert( length ); + gdcm_assert( length ); // Special case: - assert( GetPixelFormat().GetBitsAllocated() == 32 || + gdcm_assert( GetPixelFormat().GetBitsAllocated() == 32 || GetPixelFormat().GetBitsAllocated() == 16 || GetPixelFormat().GetBitsAllocated() == 8 ); if( GetPixelFormat().GetBitsAllocated() > 8 ) @@ -782,7 +823,7 @@ bool RLECodec::DecodeByStreams(std::istream &is, std::ostream &os) RequestPaddedCompositePixelCode = true; } - assert( GetPixelFormat().GetSamplesPerPixel() == 3 || GetPixelFormat().GetSamplesPerPixel() == 1 ); + gdcm_assert( GetPixelFormat().GetSamplesPerPixel() == 3 || GetPixelFormat().GetSamplesPerPixel() == 1 ); // A footnote: // RLE *by definition* with more than one component will have applied the // Planar Configuration because it simply does not make sense to do it @@ -801,18 +842,24 @@ bool RLECodec::DecodeByStreams(std::istream &is, std::ostream &os) { unsigned long numberOfReadBytes = 0; std::streampos pos = is.tellg() - start; - if ( frame.Header.Offset[i] - pos != 0 ) + if (frame.Header.GetOffset(i) > BufferLength) + { + gdcmErrorMacro("Offset is bigger then buffer Length"); + return false; + } + + if ( frame.Header.GetOffset(i) - pos != 0 ) { // ACUSON-24-YBR_FULL-RLE.dcm // D_CLUNIE_CT1_RLE.dcm // This should be at most the \0 padding //gdcmWarningMacro( "RLE Header says: " << frame.Header.Offset[i] << // " when it should says: " << pos << std::endl ); - std::streamoff check = frame.Header.Offset[i] - pos;//should it be a streampos or a uint32? mmr + std::streamoff check = frame.Header.GetOffset(i) - pos;//should it be a streampos or a uint32? mmr // check == 2 for gdcmDataExtra/gdcmSampleData/US_DataSet/GE_US/2929J686-breaker - //assert( check == 1 || check == 2); + //gdcm_assert( check == 1 || check == 2); (void)check; //warning removal - is.seekg( frame.Header.Offset[i] + start, std::ios::beg ); + is.seekg(frame.Header.GetOffset(i) + start, std::ios::beg); } unsigned long numOutBytes = 0; @@ -832,7 +879,7 @@ bool RLECodec::DecodeByStreams(std::istream &is, std::ostream &os) if( byte >= 0 /*&& byte <= 127*/ ) /* 2nd is always true */ { is.read( dummy_buffer, byte+1 ); - //assert( is.good() ); // impossible because ALOKA_SSD-8-MONO2-RLE-SQ.dc + //gdcm_assert( is.good() ); // impossible because ALOKA_SSD-8-MONO2-RLE-SQ.dc numberOfReadBytes += byte+1; numOutBytes += byte+ 1; tmpos.write( dummy_buffer, byte+1 ); @@ -848,9 +895,9 @@ bool RLECodec::DecodeByStreams(std::istream &is, std::ostream &os) } else /* byte == -128 */ { - assert( byte == -128 ); + gdcm_assert( byte == -128 ); } - //assert( numberOfReadBytes + frame.Header.Offset[i] - is.tellg() + start == 0); + //gdcm_assert( numberOfReadBytes + frame.Header.Offset[i] - is.tellg() + start == 0); } if( numOutBytes != length ) return false; } @@ -865,8 +912,8 @@ bool RLECodec::GetHeaderInfo(std::istream &is, TransferSyntax &ts) return false; // numsegments = num_comp * bpp / 8; // numsegments >0 && numsegments <= 12 - uint32_t bytespercomp = frame.Header.NumSegments; - if( frame.Header.NumSegments % 3 == 0 ) + uint32_t bytespercomp = frame.Header.GetNumSegments(); + if (frame.Header.GetNumSegments() % 3 == 0) { PI = PhotometricInterpretation::RGB; PlanarConfiguration = 1; @@ -912,23 +959,23 @@ class memsrc : public ::rle::source { memcpy( out, cur, l ); cur += l; - assert( cur <= ptr + len ); + gdcm_assert( cur <= ptr + len ); return l; } streampos_t tell() override { - assert( cur <= ptr + len ); + gdcm_assert( cur <= ptr + len ); return (streampos_t)(cur - ptr); } bool seek(streampos_t pos) override { cur = ptr + pos; - assert( cur <= ptr + len && cur >= ptr ); + gdcm_assert( cur <= ptr + len && cur >= ptr ); return true; } bool eof() override { - assert( cur <= ptr + len ); + gdcm_assert( cur <= ptr + len ); return cur == ptr + len; } memsrc * clone() override @@ -945,7 +992,7 @@ class memsrc : public ::rle::source bool RLECodec::AppendRowEncode( std::ostream & os, const char * data, size_t datalen) { (void)os; (void)data; (void)datalen; - assert(0); + gdcm_assert(0); return false; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRescaler.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRescaler.cxx index a24eaa21c25..16295e032fa 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRescaler.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRescaler.cxx @@ -32,13 +32,13 @@ void RescaleFunction(TOut *out, const TIn *in, double intercept, double slope, s // The rescale function does not add the usual +0.5 to do the proper integer type // cast, since TOut is expected to be floating point type whenever it would occur out[i] = (TOut)(slope * in[i] + intercept); - //assert( out[i] == (TOut)(slope * in[i] + intercept) ); // will really slow down stuff... - //assert( in[i] == (TIn)(((double)out[i] - intercept) / slope + 0.5) ); + //gdcm_assert( out[i] == (TOut)(slope * in[i] + intercept) ); // will really slow down stuff... + //gdcm_assert( in[i] == (TIn)(((double)out[i] - intercept) / slope + 0.5) ); // For image such as: gdcmData/MR16BitsAllocated_8BitsStored.dcm, the following line will not work: // Indeed the pixel declares itself as 16/8/7 with pixel representation of 1. In this case // anything outside the range [-127,128] is required to be discarded ! - //assert( (TIn)out[i] == in[i] ); + //gdcm_assert( (TIn)out[i] == in[i] ); } } @@ -63,8 +63,8 @@ struct FImpl { // If you read the code down below you'll see a specialized function for float, thus // if we reach here it pretty much means slope/intercept were integer type - assert( intercept == (int)intercept ); - assert( slope == (int)slope ); + gdcm_assert( intercept == (int)intercept ); + gdcm_assert( slope == (int)slope ); size /= sizeof(TIn); for(size_t i = 0; i != size; ++i) { @@ -97,7 +97,7 @@ struct FImpl // closest integer that will represent the transformation // TOut in this case is integer type, while input is floating point type out[i] = round_impl(((double)in[i] - intercept) / slope); - //assert( out[i] == (TOut)(((double)in[i] - intercept) / slope ) ); + //gdcm_assert( out[i] == (TOut)(((double)in[i] - intercept) / slope ) ); } } }; @@ -115,7 +115,7 @@ struct FImpl // closest integer that will represent the transformation // TOut in this case is integer type, while input is floating point type out[i] = round_impl(((double)in[i] - intercept) / slope); - //assert( out[i] == (TOut)(((double)in[i] - intercept) / slope ) ); + //gdcm_assert( out[i] == (TOut)(((double)in[i] - intercept) / slope ) ); } } }; @@ -123,15 +123,15 @@ struct FImpl static inline PixelFormat::ScalarType ComputeBestFit(const PixelFormat &pf, double intercept, double slope) { PixelFormat::ScalarType st = PixelFormat::UNKNOWN; - assert( slope == (int)slope && intercept == (int)intercept); + gdcm_assert( slope == (int)slope && intercept == (int)intercept); - assert( pf.GetMin() <= pf.GetMax() ); + gdcm_assert( pf.GetMin() <= pf.GetMax() ); const double pfmin = slope >= 0. ? (double)pf.GetMin() : (double)pf.GetMax(); const double pfmax = slope >= 0. ? (double)pf.GetMax() : (double)pf.GetMin(); const double min = slope * pfmin + intercept; const double max = slope * pfmax + intercept; - assert( min <= max ); - assert( min == (int64_t)min && max == (int64_t)max ); + gdcm_assert( min <= max ); + gdcm_assert( min == (int64_t)min && max == (int64_t)max ); if( min >= 0 ) // unsigned { if( max <= std::numeric_limits::max() ) @@ -187,15 +187,15 @@ static inline PixelFormat::ScalarType ComputeBestFit(const PixelFormat &pf, doub } } // postcondition: - assert( min >= PixelFormat(st).GetMin() ); - assert( max <= PixelFormat(st).GetMax() ); - assert( st != PixelFormat::UNKNOWN ); + gdcm_assert( min >= PixelFormat(st).GetMin() ); + gdcm_assert( max <= PixelFormat(st).GetMax() ); + gdcm_assert( st != PixelFormat::UNKNOWN ); return st; } PixelFormat::ScalarType Rescaler::ComputeInterceptSlopePixelType() { - assert( PF != PixelFormat::UNKNOWN ); + gdcm_assert( PF != PixelFormat::UNKNOWN ); if( PF.GetSamplesPerPixel() != 1 ) { gdcmErrorMacro( "Sample Per Pixel is required to be 1" ); @@ -205,8 +205,8 @@ PixelFormat::ScalarType Rescaler::ComputeInterceptSlopePixelType() if( PF == PixelFormat::SINGLEBIT ) return PixelFormat::SINGLEBIT; if( Slope != (int)Slope || Intercept != (int)Intercept) { - //assert( PF != PixelFormat::INT8 && PF != PixelFormat::UINT8 ); // Is there any Object that have Rescale on char ? - assert( PF != PixelFormat::SINGLEBIT ); + //gdcm_assert( PF != PixelFormat::INT8 && PF != PixelFormat::UINT8 ); // Is there any Object that have Rescale on char ? + gdcm_assert( PF != PixelFormat::SINGLEBIT ); return PixelFormat::FLOAT64; } //if( PF.IsValid() ) @@ -232,7 +232,7 @@ void Rescaler::RescaleFunctionIntoBestFit(char *out8, const TIn *in, size_t n) switch(output) { case PixelFormat::SINGLEBIT: - assert(0); + gdcm_assert(0); break; case PixelFormat::UINT8: RescaleFunction((uint8_t*)out,in,intercept,slope,n); @@ -259,7 +259,7 @@ void Rescaler::RescaleFunctionIntoBestFit(char *out8, const TIn *in, size_t n) RescaleFunction((double*)out,in,intercept,slope,n); break; default: - assert(0); + gdcm_assert(0); break; } } @@ -274,7 +274,7 @@ void Rescaler::InverseRescaleFunctionIntoBestFit(char *out8, const TIn *in, size switch(output) { case PixelFormat::SINGLEBIT: - assert(0); + gdcm_assert(0); break; case PixelFormat::UINT8: InverseRescaleFunction((uint8_t*)out,in,intercept,slope,n); @@ -295,7 +295,7 @@ void Rescaler::InverseRescaleFunctionIntoBestFit(char *out8, const TIn *in, size InverseRescaleFunction((int32_t*)out,in,intercept,slope,n); break; default: - assert(0); + gdcm_assert(0); break; } } @@ -325,7 +325,7 @@ bool Rescaler::InverseRescale(char *out, const char *in8, size_t n) if( Slope != (int)Slope || Intercept != (int)Intercept) { // need to rescale as double (64bits) as slope/intercept are 64bits - //assert(0); + //gdcm_assert(0); } // else integral type switch(PF) @@ -349,15 +349,15 @@ bool Rescaler::InverseRescale(char *out, const char *in8, size_t n) InverseRescaleFunctionIntoBestFit(out,(const int32_t*)in,n); break; case PixelFormat::FLOAT32: - assert( sizeof(float) == 32 / 8 ); + gdcm_assert( sizeof(float) == 32 / 8 ); InverseRescaleFunctionIntoBestFit(out,(const float*)in,n); break; case PixelFormat::FLOAT64: - assert( sizeof(double) == 64 / 8 ); + gdcm_assert( sizeof(double) == 64 / 8 ); InverseRescaleFunctionIntoBestFit(out,(const double*)in,n); break; default: - assert(0); + gdcm_assert(0); break; } @@ -409,7 +409,7 @@ bool Rescaler::Rescale(char *out, const char *in8, size_t n) break; default: gdcmErrorMacro( "Unhandled: " << PF ); - assert(0); + gdcm_assert(0); break; } @@ -419,9 +419,9 @@ bool Rescaler::Rescale(char *out, const char *in8, size_t n) static PixelFormat ComputeInverseBestFitFromMinMax(/*const PixelFormat &pf,*/ double intercept, double slope, double _min, double _max) { PixelFormat st = PixelFormat::UNKNOWN; - //assert( slope == (int)slope && intercept == (int)intercept); + //gdcm_assert( slope == (int)slope && intercept == (int)intercept); - assert( _min <= _max ); + gdcm_assert( _min <= _max ); double dmin = (_min - intercept ) / slope; double dmax = (_max - intercept ) / slope; if( slope < 0 ) @@ -429,9 +429,9 @@ static PixelFormat ComputeInverseBestFitFromMinMax(/*const PixelFormat &pf,*/ do dmin = (_max - intercept ) / slope; dmax = (_min - intercept ) / slope; } - assert( dmin <= dmax ); - assert( dmax <= static_cast(std::numeric_limits::max() ) ); - assert( dmin >= static_cast(std::numeric_limits::min() ) ); + gdcm_assert( dmin <= dmax ); + gdcm_assert( dmax <= static_cast(std::numeric_limits::max() ) ); + gdcm_assert( dmin >= static_cast(std::numeric_limits::min() ) ); /* * Tricky: what happen in the case where floating point approximate dmax as: 65535.000244081035 * Take for instance: _max = 64527, intercept = -1024, slope = 1.000244140625 @@ -487,7 +487,7 @@ static PixelFormat ComputeInverseBestFitFromMinMax(/*const PixelFormat &pf,*/ do { gdcmAssertAlwaysMacro(0); } - assert( min < 0 ); + gdcm_assert( min < 0 ); #if 0 int log2min = 0; int64_t min2 = -min; // make a copy @@ -500,14 +500,14 @@ static PixelFormat ComputeInverseBestFitFromMinMax(/*const PixelFormat &pf,*/ do while (max2 >>= 1) ++log2max; const int64_t bs = log2max + 1; #endif - assert( bs <= st.GetBitsAllocated() ); + gdcm_assert( bs <= st.GetBitsAllocated() ); st.SetBitsStored( (unsigned short)bs ); } // postcondition: - assert( min >= PixelFormat(st).GetMin() ); - assert( max <= PixelFormat(st).GetMax() ); - assert( st != PixelFormat::UNKNOWN ); - assert( st != PixelFormat::FLOAT32 && st != PixelFormat::FLOAT16 && st != PixelFormat::FLOAT64 ); + gdcm_assert( min >= PixelFormat(st).GetMin() ); + gdcm_assert( max <= PixelFormat(st).GetMax() ); + gdcm_assert( st != PixelFormat::UNKNOWN ); + gdcm_assert( st != PixelFormat::FLOAT32 && st != PixelFormat::FLOAT16 && st != PixelFormat::FLOAT64 ); return st; } @@ -528,12 +528,12 @@ void Rescaler::SetMinMaxForPixelType(double min, double max) PixelFormat Rescaler::ComputePixelTypeFromMinMax() { - assert( PF != PixelFormat::UNKNOWN ); + gdcm_assert( PF != PixelFormat::UNKNOWN ); const double intercept = Intercept; const double slope = Slope; const PixelFormat output = ComputeInverseBestFitFromMinMax (/*PF,*/intercept,slope,ScalarRangeMin,ScalarRangeMax); - assert( output != PixelFormat::UNKNOWN && output >= PixelFormat::UINT8 && output <= PixelFormat::INT32 ); + gdcm_assert( output != PixelFormat::UNKNOWN && output >= PixelFormat::UINT8 && output <= PixelFormat::INT32 ); return output; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner.cxx index c4f98c98883..68dcf52177f 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner.cxx @@ -43,7 +43,7 @@ void Scanner::ClearSkipTags() void Scanner::AddSkipTag( Tag const & t ) { SkipTags.insert( t ); - assert(0); // This is NOT implemented for now + gdcm_assert(0); // This is NOT implemented for now } // Warning: API is passing a public tag (no way to specify private tag) @@ -64,7 +64,7 @@ void Scanner::AddPrivateTag( PrivateTag const & t ) } else { - assert( entry.GetVR() & VR::VRBINARY ); + gdcm_assert( entry.GetVR() & VR::VRBINARY ); //gdcmWarningMacro( "Only ASCII VR are supported for now. Tag " << t << " will be discarded" ); PrivateTags.insert( t ); } @@ -86,7 +86,7 @@ void Scanner::AddTag( Tag const & t ) } else { - assert( entry.GetVR() & VR::VRBINARY ); + gdcm_assert( entry.GetVR() & VR::VRBINARY ); //gdcmWarningMacro( "Only ASCII VR are supported for now. Tag " << t << " will be discarded" ); Tags.insert( t ); } @@ -131,7 +131,7 @@ bool Scanner::Scan( Directory::FilenamesType const & filenames ) { Reader reader; const char *filename = it->c_str(); - assert( filename ); + gdcm_assert( filename ); reader.SetFileName( filename ); bool read = false; try @@ -183,7 +183,7 @@ void Scanner::Print( std::ostream & os ) const for(; file != Filenames.end(); ++file) { const char *filename = file->c_str(); - assert( filename && *filename ); + gdcm_assert( filename && *filename ); bool b = IsKey(filename); const char *comment = !b ? "could not be read" : "could be read"; os << "Filename: " << filename << " (" << comment << ")\n"; @@ -223,7 +223,7 @@ void Scanner::PrintTable( std::ostream & os ) const for(; file != Filenames.end(); ++file) { const char *filename = file->c_str(); - assert( filename && *filename ); + gdcm_assert( filename && *filename ); os << '"' << filename << '"' << "\t"; TagsType::const_iterator tag = Tags.begin(); const TagToValue &mapping = GetMapping(filename); @@ -245,8 +245,8 @@ void Scanner::PrintTable( std::ostream & os ) const Scanner::TagToValue const & Scanner::GetMapping(const char *filename) const { -// assert( Mappings.find(filename) != Mappings.end() ); - assert( filename && *filename ); +// gdcm_assert( Mappings.find(filename) != Mappings.end() ); + gdcm_assert( filename && *filename ); if( Mappings.find(filename) != Mappings.end() ) return Mappings.find(filename)->second; return Mappings.find("")->second; // dummy file could not be found @@ -264,7 +264,7 @@ bool Scanner::IsKey( const char * filename ) const } */ // Look for the file in Mappings table: - assert( filename && *filename ); + gdcm_assert( filename && *filename ); MappingType::const_iterator it2 = Mappings.find(filename); return it2 != Mappings.end(); } @@ -283,7 +283,7 @@ Directory::FilenamesType Scanner::GetKeys() const keys.push_back( filename ); } } - assert( keys.size() <= Filenames.size() ); + gdcm_assert( keys.size() <= Filenames.size() ); return keys; } @@ -291,7 +291,7 @@ Directory::FilenamesType Scanner::GetKeys() const const char* Scanner::GetValue(const char *filename, Tag const &t) const { // \precondition - assert( Tags.find( t ) != Tags.end() ); + gdcm_assert( Tags.find( t ) != Tags.end() ); TagToValue const &ftv = GetMapping(filename); if( ftv.find(t) != ftv.end() ) { @@ -393,7 +393,7 @@ Directory::FilenamesType Scanner::GetOrderedValues(Tag const &t) const void Scanner::ProcessPublicTag(StringFilter &sf, const char *filename) { - assert( filename ); + gdcm_assert( filename ); TagToValue &mapping = Mappings[filename]; const File& file = sf.GetFile(); @@ -409,7 +409,7 @@ void Scanner::ProcessPublicTag(StringFilter &sf, const char *filename) //std::string s; DataElement const & de = header.GetDataElement( *tag ); //const ByteValue *bv = de.GetByteValue(); - ////assert( VR::IsASCII( vr ) ); + ////gdcm_assert( VR::IsASCII( vr ) ); //if( bv ) // Hum, should I store an empty string or what ? // { // s = std::string( bv->GetPointer(), bv->GetLength() ); @@ -419,9 +419,9 @@ void Scanner::ProcessPublicTag(StringFilter &sf, const char *filename) // Store the potentially new value: Values.insert( s ); - assert( Values.find( s ) != Values.end() ); + gdcm_assert( Values.find( s ) != Values.end() ); const char *value = Values.find( s )->c_str(); - assert( value ); + gdcm_assert( value ); mapping.insert( TagToValue::value_type(*tag, value)); } @@ -433,7 +433,7 @@ void Scanner::ProcessPublicTag(StringFilter &sf, const char *filename) //std::string s; DataElement const & de = ds.GetDataElement( *tag ); //const ByteValue *bv = de.GetByteValue(); - ////assert( VR::IsASCII( vr ) ); + ////gdcm_assert( VR::IsASCII( vr ) ); //if( bv ) // Hum, should I store an empty string or what ? // { // s = std::string( bv->GetPointer(), bv->GetLength() ); @@ -443,9 +443,9 @@ void Scanner::ProcessPublicTag(StringFilter &sf, const char *filename) // Store the potentially new value: Values.insert( s ); - assert( Values.find( s ) != Values.end() ); + gdcm_assert( Values.find( s ) != Values.end() ); const char *value = Values.find( s )->c_str(); - assert( value ); + gdcm_assert( value ); mapping.insert( TagToValue::value_type(*tag, value)); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner.h index ba81fea4665..b1681a1cf54 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner.h @@ -56,7 +56,7 @@ class GDCM_EXPORT Scanner : public Subject { friend std::ostream& operator<<(std::ostream &_os, const Scanner &s); public: - Scanner():Values(),Filenames(),Mappings() {} + Scanner():Values(),Filenames(),Mappings(),Progress(0.0) {} ~Scanner() override; /// struct to map a filename to a value @@ -119,7 +119,7 @@ class GDCM_EXPORT Scanner : public Subject { bool operator()(const char* s1, const char* s2) const { - assert( s1 && s2 ); + gdcm_assert( s1 && s2 ); return strcmp(s1, s2) < 0; } }; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner2.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner2.cxx index 516900ff712..5ea2af6f6ff 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner2.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner2.cxx @@ -67,7 +67,7 @@ bool Scanner2::AddPrivateTag( PrivateTag const & t ) } else { - assert( entry.GetVR() & VR::VRBINARY ); + gdcm_assert( entry.GetVR() & VR::VRBINARY ); //gdcmWarningMacro( "Only ASCII VR are supported for now. Tag " << t << " will be discarded" ); PrivateTags.insert( t ); } @@ -92,7 +92,7 @@ bool Scanner2::AddPublicTag( Tag const & t ) } else { - assert( entry.GetVR() & VR::VRBINARY ); + gdcm_assert( entry.GetVR() & VR::VRBINARY ); //gdcmWarningMacro( "Only ASCII VR are supported for now. Tag " << t << " will be discarded" ); PublicTags.insert( t ); } @@ -142,7 +142,7 @@ bool Scanner2::Scan( Directory::FilenamesType const & filenames ) { Reader reader; const char *filename = it->c_str(); - assert( filename ); + gdcm_assert( filename ); reader.SetFileName( filename ); bool read = false; try @@ -194,7 +194,7 @@ void Scanner2::Print( std::ostream & os ) const for(; file != Filenames.end(); ++file) { const char *filename = file->c_str(); - assert( filename && *filename ); + gdcm_assert( filename && *filename ); bool b = IsKey(filename); const char *comment = !b ? "could not be read" : "could be read"; os << "Filename: " << filename << " (" << comment << ")\n"; @@ -270,7 +270,7 @@ void Scanner2::PrintTable( std::ostream & os, bool header ) const for(; file != Filenames.end(); ++file) { const char *filename = file->c_str(); - assert( filename && *filename ); + gdcm_assert( filename && *filename ); os << '"' << filename << '"' << "\t"; { PublicTagsType::const_iterator tag = PublicTags.begin(); @@ -310,7 +310,7 @@ void Scanner2::PrintTable( std::ostream & os, bool header ) const Scanner2::PublicTagToValue const & Scanner2::GetPublicMapping(const char *filename) const { - assert( filename && *filename ); + gdcm_assert( filename && *filename ); if( PublicMappings.find(filename) != PublicMappings.end() ) return PublicMappings.find(filename)->second; return PublicMappings.find("")->second; // dummy file could not be found @@ -318,7 +318,7 @@ Scanner2::PublicTagToValue const & Scanner2::GetPublicMapping(const char *filena Scanner2::PrivateTagToValue const & Scanner2::GetPrivateMapping(const char *filename) const { - assert( filename && *filename ); + gdcm_assert( filename && *filename ); if( PrivateMappings.find(filename) != PrivateMappings.end() ) return PrivateMappings.find(filename)->second; return PrivateMappings.find("")->second; // dummy file could not be found @@ -327,7 +327,7 @@ Scanner2::PrivateTagToValue const & Scanner2::GetPrivateMapping(const char *file bool Scanner2::IsKey( const char * filename ) const { // Look for the file in Mappings tables: - assert( filename && *filename ); + gdcm_assert( filename && *filename ); PublicMappingType::const_iterator it2 = PublicMappings.find(filename); PrivateMappingType::const_iterator it3 = PrivateMappings.find(filename); return it2 != PublicMappings.end() || it3 != PrivateMappings.end(); @@ -346,14 +346,14 @@ Directory::FilenamesType Scanner2::GetKeys() const keys.push_back( filename ); } } - assert( keys.size() <= Filenames.size() ); + gdcm_assert( keys.size() <= Filenames.size() ); return keys; } const char* Scanner2::GetPublicValue(const char *filename, Tag const &t) const { // \precondition - assert( PublicTags.find( t ) != PublicTags.end() ); + gdcm_assert( PublicTags.find( t ) != PublicTags.end() ); PublicTagToValue const &ftv = GetPublicMapping(filename); if( ftv.find(t) != ftv.end() ) { @@ -365,7 +365,7 @@ const char* Scanner2::GetPublicValue(const char *filename, Tag const &t) const const char* Scanner2::GetPrivateValue(const char *filename, PrivateTag const &t) const { // \precondition - assert( PrivateTags.find( t ) != PrivateTags.end() ); + gdcm_assert( PrivateTags.find( t ) != PrivateTags.end() ); PrivateTagToValue const &ftv = GetPrivateMapping(filename); if( ftv.find(t) != ftv.end() ) { @@ -540,7 +540,7 @@ Directory::FilenamesType Scanner2::GetPrivateOrderedValues(PrivateTag const &pt) void Scanner2::ProcessPublicTag(StringFilter &sf, const char *filename) { - assert( filename ); + gdcm_assert( filename ); PublicTagToValue &mapping = PublicMappings[filename]; const File& file = sf.GetFile(); @@ -558,9 +558,9 @@ void Scanner2::ProcessPublicTag(StringFilter &sf, const char *filename) // Store the potentially new value: Values.insert( s ); - assert( Values.find( s ) != Values.end() ); + gdcm_assert( Values.find( s ) != Values.end() ); const char *value = Values.find( s )->c_str(); - assert( value ); + gdcm_assert( value ); mapping.insert( PublicTagToValue::value_type(*tag, value)); } @@ -574,9 +574,9 @@ void Scanner2::ProcessPublicTag(StringFilter &sf, const char *filename) // Store the potentially new value: Values.insert( s ); - assert( Values.find( s ) != Values.end() ); + gdcm_assert( Values.find( s ) != Values.end() ); const char *value = Values.find( s )->c_str(); - assert( value ); + gdcm_assert( value ); mapping.insert( PublicTagToValue::value_type(*tag, value)); } @@ -586,7 +586,7 @@ void Scanner2::ProcessPublicTag(StringFilter &sf, const char *filename) void Scanner2::ProcessPrivateTag(StringFilter &sf, const char *filename) { - assert( filename ); + gdcm_assert( filename ); PrivateTagToValue &mapping = PrivateMappings[filename]; const File& file = sf.GetFile(); const DataSet & ds = file.GetDataSet(); @@ -600,9 +600,9 @@ void Scanner2::ProcessPrivateTag(StringFilter &sf, const char *filename) // Store the potentially new value: Values.insert( s ); - assert( Values.find( s ) != Values.end() ); + gdcm_assert( Values.find( s ) != Values.end() ); const char *value = Values.find( s )->c_str(); - assert( value ); + gdcm_assert( value ); mapping.insert( PrivateTagToValue::value_type(*ptag, value)); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner2.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner2.h index 568bca7ce57..e6589ca8625 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner2.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmScanner2.h @@ -128,7 +128,7 @@ class GDCM_EXPORT Scanner2 : public Subject { bool operator()(const char* s1, const char* s2) const { - assert( s1 && s2 ); + gdcm_assert( s1 && s2 ); return strcmp(s1, s2) < 0; } }; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSegment.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSegment.cxx index e3f1ed38c37..e4b29284b73 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSegment.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSegment.cxx @@ -29,7 +29,7 @@ static const char * ALGOTypeStrings[] = { const char * Segment::GetALGOTypeString(ALGOType type) { - assert( type <= ALGOType_END ); + gdcm_assert( type <= ALGOType_END ); return ALGOTypeStrings[(int)type]; } @@ -201,7 +201,7 @@ Segment::ALGOType Segment::GetSegmentAlgorithmType() const void Segment::SetSegmentAlgorithmType(Segment::ALGOType type) { - assert(type <= ALGOType_END); + gdcm_assert(type <= ALGOType_END); SegmentAlgorithmType = type; } @@ -252,7 +252,7 @@ Segment::SurfaceVector & Segment::GetSurfaces() SmartPointer< Surface > Segment::GetSurface(const unsigned int idx /*= 0*/) const { - assert( idx < SurfaceCount ); + gdcm_assert( idx < SurfaceCount ); return Surfaces[idx]; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSegmentWriter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSegmentWriter.cxx index 299ddcc4eef..8d2e18dde03 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSegmentWriter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSegmentWriter.cxx @@ -45,7 +45,7 @@ SegmentWriter::SegmentVector & SegmentWriter::GetSegments() SmartPointer< Segment > SegmentWriter::GetSegment(const unsigned int idx /*= 0*/) const { - assert( idx < Segments.size() ); + gdcm_assert( idx < Segments.size() ); return Segments[idx]; } @@ -159,7 +159,7 @@ bool SegmentWriter::PrepareWrite() { // Fill the Segment Sequence const unsigned int numberOfSegments = this->GetNumberOfSegments(); - assert( numberOfSegments ); + gdcm_assert( numberOfSegments ); const size_t nbItems = segmentsSQ->GetNumberOfItems(); if (nbItems < numberOfSegments) { @@ -182,7 +182,7 @@ bool SegmentWriter::PrepareWrite() for (; it0 != it0End; it0++) { SmartPointer< Segment > segment = *it0; - assert( segment ); + gdcm_assert( segment ); Item & segmentItem = segmentsSQ->GetItem(itemNumber); DataSet & segmentDS = segmentItem.GetNestedDataSet(); @@ -389,7 +389,7 @@ bool SegmentWriter::Write() return false; } - assert( Stream ); + gdcm_assert( Stream ); if( !Writer::Write() ) { return false; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSegmentedPaletteColorLookupTable.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSegmentedPaletteColorLookupTable.cxx index e033b72de9d..239c01a117c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSegmentedPaletteColorLookupTable.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSegmentedPaletteColorLookupTable.cxx @@ -124,7 +124,7 @@ namespace gdcm EntryType nNumCopies = *(this->_first + 1); typename SegmentMap::const_iterator ppSeg = ppHeadSeg; while ( std::distance(ppHeadSeg, ppSeg) second->Expand(instances, expanded); ++ppSeg; } @@ -181,7 +181,7 @@ void SegmentedPaletteColorLookupTable::SetLUT(LookupTableType type, const unsign { if( BitSample == 8 ) { - assert(0); // TODO + gdcm_assert(0); // TODO } else if( BitSample == 16 ) { @@ -190,7 +190,7 @@ void SegmentedPaletteColorLookupTable::SetLUT(LookupTableType type, const unsign std::vector palette; unsigned int num_entries = GetLUTLength(type); palette.reserve(num_entries); - assert( length % 2 == 0 ); + gdcm_assert( length % 2 == 0 ); // FIXME: inplace byteswapping (BAD!) SwapperNoOp::SwapArray(const_cast(segment_values),length/2); ExpandPalette(segment_values, length, palette); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSerieHelper.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSerieHelper.cxx index 28f6f2556b9..ace51f36107 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSerieHelper.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSerieHelper.cxx @@ -154,7 +154,7 @@ static bool CompareDicomString(const std::string &s1, const char *s2, int op) // s2 is the string from the DICOM reference e.g. : 'MONOCHROME1' std::string s1_even = s1; //Never change input parameter std::string s2_even = /*DicomString(*/ s2 ; - assert( s2_even.size() % 2 == 0 ); + gdcm_assert( s2_even.size() % 2 == 0 ); if ( s1_even[s1_even.size()-1] == ' ' ) { s1_even[s1_even.size()-1] = '\0'; //replace space character by null diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSpacing.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSpacing.cxx index e2622a173b4..960d773173e 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSpacing.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSpacing.cxx @@ -90,7 +90,7 @@ double frap(double frac[2], double startx, double maxden = 10 ) //printf("%ld/%ld, error = %e\n", m[0][0], m[1][0], // startx - ((double) m[0][0] / (double) m[1][0])); const double error2 = startx - ((double) m[0][0] / (double) m[1][0]); - assert( fabs(error) < fabs(error2) ); (void)error2; + gdcm_assert( fabs(error) < fabs(error2) ); (void)error2; return error; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSplitMosaicFilter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSplitMosaicFilter.cxx index 047432b3309..d6793c56c6a 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSplitMosaicFilter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSplitMosaicFilter.cxx @@ -16,6 +16,7 @@ #include "gdcmAttribute.h" #include "gdcmImageHelper.h" #include "gdcmDirectionCosines.h" +#include "gdcmEquipmentManufacturer.h" #include @@ -120,14 +121,57 @@ bool SplitMosaicFilter::GetAcquisitionSize(unsigned int size[2], DataSet const & return found; } +const DataElement& ComputeCSAHeaderInfo(const DataSet& ds, const PrivateTag &pt, const Tag &hardcodedCsaLocation, bool handleMissingPrivateCreator ) { + if ( handleMissingPrivateCreator && !ds.FindDataElement(pt) ) { + // check hardcoded location first: + if ( ds.FindDataElement(hardcodedCsaLocation) ) { + Attribute<0x0008, 0x0008> imageType; + imageType.SetFromDataSet(ds); + const unsigned int nvalues = imageType.GetNumberOfValues(); + const std::string str4 = nvalues >= 5 ? imageType.GetValue(4).Trim() : ""; + const char mosaic[] = "MOSAIC"; + if ( str4 == mosaic ) { + gdcmWarningMacro( "CSAImageHeaderInfo private creator missing. Using hardcoded location (0029,1010)" ); + return ds.GetDataElement(hardcodedCsaLocation); + } + const EquipmentManufacturer::Type manufacturer = EquipmentManufacturer::Compute(ds); + if ( manufacturer == EquipmentManufacturer::SIEMENS ) { + gdcmWarningMacro( "CSAImageHeaderInfo private creator missing. Using hardcoded location (0029,1010)" ); + return ds.GetDataElement(hardcodedCsaLocation); + } + } + } + return ds.GetDataElement(pt); +} + +// For some reason anoymizer from ADNI DICOM remove the private creator for SIEMENS CSA +// Since dcm2niix has a hardcoded location for SIEMENS CSA tag 0029,1010 we want to reproduce +// the behavior for the average user. +// ref: LEVEY^ADNI3 Basic / Axial rsfMRI (Eyes Open) +// (0029,1008) CS [IMAGE NUM 4] # 12, 1 Unknown Tag & Data +// (0029,1010) OB 53\56\31\30\04\03\02\01\65\00\00\00\4d\00\00\00\45\63\68\6f\4c\69... # 13012, 1 Unknown Tag & Data +// (0029,1018) CS [MR] # 2, 1 Unknown Tag & Data +// (0029,1020) OB 53\56\31\30\04\03\02\01\4f\00\00\00\4d\00\00\00\55\73\65\64\50\61... # 132968, 1 Unknown Tag & Data +const DataElement& SplitMosaicFilter::ComputeCSAImageHeaderInfo(const DataSet& ds, const bool handleMissingPrivateCreator ) { + const PrivateTag &pt = CSAHeader::GetCSAImageHeaderInfoTag(); + const Tag hardcodedCsaLocation(0x0029,0x1010); + return ComputeCSAHeaderInfo(ds, pt, hardcodedCsaLocation, handleMissingPrivateCreator); +} + +const DataElement& SplitMosaicFilter::ComputeCSASeriesHeaderInfo(const DataSet& ds, const bool handleMissingPrivateCreator ) { + const PrivateTag &pt = CSAHeader::GetCSASeriesHeaderInfoTag(); + const Tag hardcodedCsaLocation(0x0029,0x1020); + return ComputeCSAHeaderInfo(ds, pt, hardcodedCsaLocation, handleMissingPrivateCreator); +} + unsigned int SplitMosaicFilter::GetNumberOfImagesInMosaic( File const & file ) { unsigned int numberOfImagesInMosaic = 0; DataSet const &ds = file.GetDataSet(); CSAHeader csa; - const PrivateTag &t1 = csa.GetCSAImageHeaderInfoTag(); - if( csa.LoadFromDataElement( ds.GetDataElement( t1 ) ) ) + const DataElement& csaEl = ComputeCSAImageHeaderInfo( ds ) ; + if( csa.LoadFromDataElement( csaEl ) ) { if( csa.FindCSAElementByName( "NumberOfImagesInMosaic" ) ) { @@ -234,9 +278,9 @@ bool SplitMosaicFilter::ComputeMOSAICSliceNormal( double slicenormalvector[3], b double normal[3]; bool snvfound = false; - const PrivateTag &t1 = csa.GetCSAImageHeaderInfoTag(); static const char snvstr[] = "SliceNormalVector"; - if( csa.LoadFromDataElement( ds.GetDataElement( t1 ) ) ) + const DataElement& csaEl = ComputeCSAImageHeaderInfo( ds ) ; + if( csa.LoadFromDataElement( csaEl ) ) { if( csa.FindCSAElementByName( snvstr ) ) { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSplitMosaicFilter.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSplitMosaicFilter.h index 06f281a3dbd..8bfab243d90 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSplitMosaicFilter.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSplitMosaicFilter.h @@ -81,6 +81,12 @@ class GDCM_EXPORT SplitMosaicFilter /// Return the value for NumberOfImagesInMosaic, or compute it from Acquisition Size static unsigned int GetNumberOfImagesInMosaic( File const & file ); + + /// Return the DataElement for the CSA Image Header + static const DataElement& ComputeCSAImageHeaderInfo(const DataSet& ds, bool handleMissingPrivateCreator = true); + + /// Return the DataElement for the CSA Series Header + static const DataElement& ComputeCSASeriesHeaderInfo(const DataSet& ds, bool handleMissingPrivateCreator = true); protected: diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStreamImageReader.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStreamImageReader.cxx index e54b28af547..718ddd77523 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStreamImageReader.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStreamImageReader.cxx @@ -139,7 +139,7 @@ bool StreamImageReader::Read(char* inReadBuffer, const std::size_t& inBufferLeng bool StreamImageReader::ReadImageSubregionRAW(char* inReadBuffer, const std::size_t& inBufferLength) { //assumes that the file is organized in row-major format, with each row rastering across - assert( mFileOffset != -1 ); + gdcm_assert( mFileOffset != -1 ); (void)inBufferLength; int y, z; std::streamoff theOffset; @@ -377,7 +377,7 @@ bool StreamImageReader::ReadImageInformation() if( mFileOffset == -1 ) return false; // postcondition - assert( mFileOffset != -1 ); + gdcm_assert( mFileOffset != -1 ); const File &file_t = mReader.GetFile(); const DataSet &ds_t = file_t.GetDataSet(); @@ -485,7 +485,7 @@ File const &StreamImageReader::GetFile() const } else { - assert(0); + gdcm_assert(0); return mReader.GetFile(); } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStreamImageWriter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStreamImageWriter.cxx index 2ff2fa2f5a9..0e19d80390a 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStreamImageWriter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStreamImageWriter.cxx @@ -155,10 +155,10 @@ int StreamImageWriter::WriteRawHeader(RAWCodec* inCodec, std::ostream* inStream) memcpy(&(tmpBuffer1[5*sizeof(uint16_t)+sizeof(uint32_t)]), &seventhTag, sizeof(uint16_t));//e000 memcpy(&(tmpBuffer1[6*sizeof(uint16_t)+sizeof(uint32_t)]), &eightthTag, sizeof(uint32_t));//00000000H - assert( inStream && *inStream && !inStream->eof() && inStream->good() ); + gdcm_assert( inStream && *inStream && !inStream->eof() && inStream->good() ); inStream->write(tmpBuffer1, theBufferSize); inStream->flush(); - assert( inStream && *inStream ); + gdcm_assert( inStream && *inStream ); } uint16_t NinthTag = 0xfffe; @@ -197,10 +197,10 @@ int StreamImageWriter::WriteRawHeader(RAWCodec* inCodec, std::ostream* inStream) // inStream->seekp(std::ios::beg); // theOffset = mFileOffset; // inStream->seekp(theOffset); - assert( inStream && *inStream && !inStream->eof() && inStream->good() ); + gdcm_assert( inStream && *inStream && !inStream->eof() && inStream->good() ); inStream->write(tmpBuffer4, theBufferSize1); inStream->flush(); - assert( inStream && *inStream ); + gdcm_assert( inStream && *inStream ); } catch(...){ delete [] tmpBuffer3; @@ -220,7 +220,7 @@ bool StreamImageWriter::WriteImageSubregionRAW(char* inWriteBuffer, const std::s { (void)inBufferLength; //assumes that the file is organized in row-major format, with each row rastering across -// assert( mFileOffset != -1 ); +// gdcm_assert( mFileOffset != -1 ); int y, z; // std::streamoff theOffset; @@ -264,7 +264,7 @@ bool StreamImageWriter::WriteImageSubregionRAW(char* inWriteBuffer, const std::s //to ensure thread safety; if the stream ptr handler gets used simultaneously by different threads, //that would be BAD //tmpBuffer is for a single raster - assert( theStream && *theStream ); + gdcm_assert( theStream && *theStream ); char* tmpBuffer = new char[SubRowSize*bytesPerPixel]; char* tmpBuffer2 = new char[SubRowSize*bytesPerPixel]; try { @@ -301,10 +301,10 @@ bool StreamImageWriter::WriteImageSubregionRAW(char* inWriteBuffer, const std::s return false; } //should be appending - //assert( theStream && *theStream && !theStream->eof() && theStream->good() ); + //gdcm_assert( theStream && *theStream && !theStream->eof() && theStream->good() ); theStream->write(tmpBuffer2, SubRowSize*bytesPerPixel); theStream->flush(); - //assert( theStream && *theStream ); + //gdcm_assert( theStream && *theStream ); } } } @@ -341,10 +341,10 @@ bool StreamImageWriter::WriteImageInformation(){ { //question! is this file a copy of the file that was given in, or a reference? mFile.GetDataSet().Remove( Tag(0x7fe0,0x0010) ); // FIXME - assert( !mFile.GetDataSet().FindDataElement( Tag(0x7fe0,0x0010) ) ); + gdcm_assert( !mFile.GetDataSet().FindDataElement( Tag(0x7fe0,0x0010) ) ); if( !mWriter.Write() )//should write everything BUT the image tag. right? { - //assert( 0 );//this assert fires when the image is not writeable, ie, doesn't have + //gdcm_assert( 0 );//this assert fires when the image is not writeable, ie, doesn't have //tags 2,3 and 8,18 //if the writer can't write, then this should return false. return false; @@ -381,7 +381,7 @@ bool StreamImageWriter::WriteImageInformation(){ // if( mFileOffset == -1 ) return false; // postcondition -// assert( mFileOffset != -1 ); +// gdcm_assert( mFileOffset != -1 ); return true; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner.cxx index 55eab6f7538..16ba5b6ca71 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner.cxx @@ -43,7 +43,7 @@ void StrictScanner::ClearSkipTags() void StrictScanner::AddSkipTag( Tag const & t ) { SkipTags.insert( t ); - assert(0); // This is NOT implemented for now + gdcm_assert(0); // This is NOT implemented for now } // Warning: API is passing a public tag (no way to specify private tag) @@ -64,7 +64,7 @@ void StrictScanner::AddPrivateTag( PrivateTag const & t ) } else { - assert( entry.GetVR() & VR::VRBINARY ); + gdcm_assert( entry.GetVR() & VR::VRBINARY ); //gdcmWarningMacro( "Only ASCII VR are supported for now. Tag " << t << " will be discarded" ); PrivateTags.insert( t ); } @@ -86,7 +86,7 @@ void StrictScanner::AddTag( Tag const & t ) } else { - assert( entry.GetVR() & VR::VRBINARY ); + gdcm_assert( entry.GetVR() & VR::VRBINARY ); //gdcmWarningMacro( "Only ASCII VR are supported for now. Tag " << t << " will be discarded" ); Tags.insert( t ); } @@ -134,7 +134,7 @@ bool StrictScanner::Scan( Directory::FilenamesType const & filenames ) { Reader reader; const char *filename = it->c_str(); - assert( filename ); + gdcm_assert( filename ); reader.SetFileName( filename ); // Pass #1, just check if the file is valid (up to the tag) const bool strict = StrictReadUpToTag( filename, last, SkipTags ); @@ -192,7 +192,7 @@ void StrictScanner::Print( std::ostream & os ) const for(; file != Filenames.end(); ++file) { const char *filename = file->c_str(); - assert( filename && *filename ); + gdcm_assert( filename && *filename ); bool b = IsKey(filename); const char *comment = !b ? "could not be read" : "could be read"; os << "Filename: " << filename << " (" << comment << ")\n"; @@ -232,7 +232,7 @@ void StrictScanner::PrintTable( std::ostream & os ) const for(; file != Filenames.end(); ++file) { const char *filename = file->c_str(); - assert( filename && *filename ); + gdcm_assert( filename && *filename ); os << '"' << filename << '"' << "\t"; TagsType::const_iterator tag = Tags.begin(); const TagToValue &mapping = GetMapping(filename); @@ -254,8 +254,8 @@ void StrictScanner::PrintTable( std::ostream & os ) const StrictScanner::TagToValue const & StrictScanner::GetMapping(const char *filename) const { -// assert( Mappings.find(filename) != Mappings.end() ); - assert( filename && *filename ); +// gdcm_assert( Mappings.find(filename) != Mappings.end() ); + gdcm_assert( filename && *filename ); if( Mappings.find(filename) != Mappings.end() ) return Mappings.find(filename)->second; return Mappings.find("")->second; // dummy file could not be found @@ -273,7 +273,7 @@ bool StrictScanner::IsKey( const char * filename ) const } */ // Look for the file in Mappings table: - assert( filename && *filename ); + gdcm_assert( filename && *filename ); MappingType::const_iterator it2 = Mappings.find(filename); return it2 != Mappings.end(); } @@ -292,7 +292,7 @@ Directory::FilenamesType StrictScanner::GetKeys() const keys.push_back( filename ); } } - assert( keys.size() <= Filenames.size() ); + gdcm_assert( keys.size() <= Filenames.size() ); return keys; } @@ -300,7 +300,7 @@ Directory::FilenamesType StrictScanner::GetKeys() const const char* StrictScanner::GetValue(const char *filename, Tag const &t) const { // \precondition - assert( Tags.find( t ) != Tags.end() ); + gdcm_assert( Tags.find( t ) != Tags.end() ); TagToValue const &ftv = GetMapping(filename); if( ftv.find(t) != ftv.end() ) { @@ -402,7 +402,7 @@ Directory::FilenamesType StrictScanner::GetOrderedValues(Tag const &t) const void StrictScanner::ProcessPublicTag(StringFilter &sf, const char *filename) { - assert( filename ); + gdcm_assert( filename ); TagToValue &mapping = Mappings[filename]; const File& file = sf.GetFile(); @@ -418,7 +418,7 @@ void StrictScanner::ProcessPublicTag(StringFilter &sf, const char *filename) //std::string s; DataElement const & de = header.GetDataElement( *tag ); //const ByteValue *bv = de.GetByteValue(); - ////assert( VR::IsASCII( vr ) ); + ////gdcm_assert( VR::IsASCII( vr ) ); //if( bv ) // Hum, should I store an empty string or what ? // { // s = std::string( bv->GetPointer(), bv->GetLength() ); @@ -428,9 +428,9 @@ void StrictScanner::ProcessPublicTag(StringFilter &sf, const char *filename) // Store the potentially new value: Values.insert( s ); - assert( Values.find( s ) != Values.end() ); + gdcm_assert( Values.find( s ) != Values.end() ); const char *value = Values.find( s )->c_str(); - assert( value ); + gdcm_assert( value ); mapping.insert( TagToValue::value_type(*tag, value)); } @@ -442,7 +442,7 @@ void StrictScanner::ProcessPublicTag(StringFilter &sf, const char *filename) //std::string s; DataElement const & de = ds.GetDataElement( *tag ); //const ByteValue *bv = de.GetByteValue(); - ////assert( VR::IsASCII( vr ) ); + ////gdcm_assert( VR::IsASCII( vr ) ); //if( bv ) // Hum, should I store an empty string or what ? // { // s = std::string( bv->GetPointer(), bv->GetLength() ); @@ -452,9 +452,9 @@ void StrictScanner::ProcessPublicTag(StringFilter &sf, const char *filename) // Store the potentially new value: Values.insert( s ); - assert( Values.find( s ) != Values.end() ); + gdcm_assert( Values.find( s ) != Values.end() ); const char *value = Values.find( s )->c_str(); - assert( value ); + gdcm_assert( value ); mapping.insert( TagToValue::value_type(*tag, value)); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner.h index 1463607138a..3cf83377f54 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner.h @@ -56,7 +56,7 @@ class GDCM_EXPORT StrictScanner : public Subject { friend std::ostream& operator<<(std::ostream &_os, const StrictScanner &s); public: - StrictScanner():Values(),Filenames(),Mappings() {} + StrictScanner():Values(),Filenames(),Mappings(),Progress(0.0) {} ~StrictScanner() override; /// struct to map a filename to a value @@ -119,7 +119,7 @@ class GDCM_EXPORT StrictScanner : public Subject { bool operator()(const char* s1, const char* s2) const { - assert( s1 && s2 ); + gdcm_assert( s1 && s2 ); return strcmp(s1, s2) < 0; } }; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner2.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner2.cxx index f8754c96ce0..11774ba57ca 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner2.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner2.cxx @@ -67,7 +67,7 @@ bool StrictScanner2::AddPrivateTag( PrivateTag const & t ) } else { - assert( entry.GetVR() & VR::VRBINARY ); + gdcm_assert( entry.GetVR() & VR::VRBINARY ); //gdcmWarningMacro( "Only ASCII VR are supported for now. Tag " << t << " will be discarded" ); PrivateTags.insert( t ); } @@ -92,7 +92,7 @@ bool StrictScanner2::AddPublicTag( Tag const & t ) } else { - assert( entry.GetVR() & VR::VRBINARY ); + gdcm_assert( entry.GetVR() & VR::VRBINARY ); //gdcmWarningMacro( "Only ASCII VR are supported for now. Tag " << t << " will be discarded" ); PublicTags.insert( t ); } @@ -145,7 +145,7 @@ bool StrictScanner2::Scan( Directory::FilenamesType const & filenames ) { Reader reader; const char *filename = it->c_str(); - assert( filename ); + gdcm_assert( filename ); reader.SetFileName( filename ); // Pass #1, just check if the file is valid (up to the tag) const bool strict = StrictReadUpToTag( filename, last, SkipTags ); @@ -203,7 +203,7 @@ void StrictScanner2::Print( std::ostream & os ) const for(; file != Filenames.end(); ++file) { const char *filename = file->c_str(); - assert( filename && *filename ); + gdcm_assert( filename && *filename ); bool b = IsKey(filename); const char *comment = !b ? "could not be read" : "could be read"; os << "Filename: " << filename << " (" << comment << ")\n"; @@ -279,7 +279,7 @@ void StrictScanner2::PrintTable( std::ostream & os, bool header ) const for(; file != Filenames.end(); ++file) { const char *filename = file->c_str(); - assert( filename && *filename ); + gdcm_assert( filename && *filename ); os << '"' << filename << '"' << "\t"; { PublicTagsType::const_iterator tag = PublicTags.begin(); @@ -319,7 +319,7 @@ void StrictScanner2::PrintTable( std::ostream & os, bool header ) const StrictScanner2::PublicTagToValue const & StrictScanner2::GetPublicMapping(const char *filename) const { - assert( filename && *filename ); + gdcm_assert( filename && *filename ); if( PublicMappings.find(filename) != PublicMappings.end() ) return PublicMappings.find(filename)->second; return PublicMappings.find("")->second; // dummy file could not be found @@ -327,7 +327,7 @@ StrictScanner2::PublicTagToValue const & StrictScanner2::GetPublicMapping(const StrictScanner2::PrivateTagToValue const & StrictScanner2::GetPrivateMapping(const char *filename) const { - assert( filename && *filename ); + gdcm_assert( filename && *filename ); if( PrivateMappings.find(filename) != PrivateMappings.end() ) return PrivateMappings.find(filename)->second; return PrivateMappings.find("")->second; // dummy file could not be found @@ -336,7 +336,7 @@ StrictScanner2::PrivateTagToValue const & StrictScanner2::GetPrivateMapping(cons bool StrictScanner2::IsKey( const char * filename ) const { // Look for the file in Mappings tables: - assert( filename && *filename ); + gdcm_assert( filename && *filename ); PublicMappingType::const_iterator it2 = PublicMappings.find(filename); PrivateMappingType::const_iterator it3 = PrivateMappings.find(filename); return it2 != PublicMappings.end() || it3 != PrivateMappings.end(); @@ -355,14 +355,14 @@ Directory::FilenamesType StrictScanner2::GetKeys() const keys.push_back( filename ); } } - assert( keys.size() <= Filenames.size() ); + gdcm_assert( keys.size() <= Filenames.size() ); return keys; } const char* StrictScanner2::GetPublicValue(const char *filename, Tag const &t) const { // \precondition - assert( PublicTags.find( t ) != PublicTags.end() ); + gdcm_assert( PublicTags.find( t ) != PublicTags.end() ); PublicTagToValue const &ftv = GetPublicMapping(filename); if( ftv.find(t) != ftv.end() ) { @@ -374,7 +374,7 @@ const char* StrictScanner2::GetPublicValue(const char *filename, Tag const &t) c const char* StrictScanner2::GetPrivateValue(const char *filename, PrivateTag const &t) const { // \precondition - assert( PrivateTags.find( t ) != PrivateTags.end() ); + gdcm_assert( PrivateTags.find( t ) != PrivateTags.end() ); PrivateTagToValue const &ftv = GetPrivateMapping(filename); if( ftv.find(t) != ftv.end() ) { @@ -549,7 +549,7 @@ Directory::FilenamesType StrictScanner2::GetPrivateOrderedValues(PrivateTag cons void StrictScanner2::ProcessPublicTag(StringFilter &sf, const char *filename) { - assert( filename ); + gdcm_assert( filename ); PublicTagToValue &mapping = PublicMappings[filename]; const File& file = sf.GetFile(); @@ -567,9 +567,9 @@ void StrictScanner2::ProcessPublicTag(StringFilter &sf, const char *filename) // Store the potentially new value: Values.insert( s ); - assert( Values.find( s ) != Values.end() ); + gdcm_assert( Values.find( s ) != Values.end() ); const char *value = Values.find( s )->c_str(); - assert( value ); + gdcm_assert( value ); mapping.insert( PublicTagToValue::value_type(*tag, value)); } @@ -583,9 +583,9 @@ void StrictScanner2::ProcessPublicTag(StringFilter &sf, const char *filename) // Store the potentially new value: Values.insert( s ); - assert( Values.find( s ) != Values.end() ); + gdcm_assert( Values.find( s ) != Values.end() ); const char *value = Values.find( s )->c_str(); - assert( value ); + gdcm_assert( value ); mapping.insert( PublicTagToValue::value_type(*tag, value)); } @@ -595,7 +595,7 @@ void StrictScanner2::ProcessPublicTag(StringFilter &sf, const char *filename) void StrictScanner2::ProcessPrivateTag(StringFilter &sf, const char *filename) { - assert( filename ); + gdcm_assert( filename ); PrivateTagToValue &mapping = PrivateMappings[filename]; const File& file = sf.GetFile(); const DataSet & ds = file.GetDataSet(); @@ -609,9 +609,9 @@ void StrictScanner2::ProcessPrivateTag(StringFilter &sf, const char *filename) // Store the potentially new value: Values.insert( s ); - assert( Values.find( s ) != Values.end() ); + gdcm_assert( Values.find( s ) != Values.end() ); const char *value = Values.find( s )->c_str(); - assert( value ); + gdcm_assert( value ); mapping.insert( PrivateTagToValue::value_type(*ptag, value)); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner2.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner2.h index df5311eb8d7..eb38dae264e 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner2.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStrictScanner2.h @@ -125,7 +125,7 @@ class GDCM_EXPORT StrictScanner2 : public Subject { * comparison */ struct ltstr { bool operator()(const char *s1, const char *s2) const { - assert(s1 && s2); + gdcm_assert(s1 && s2); return strcmp(s1, s2) < 0; } }; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStringFilter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStringFilter.cxx index 7f81fda6843..aa5308e9e79 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStringFilter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmStringFilter.cxx @@ -34,7 +34,7 @@ StringFilter::~StringFilter() void StringFilter::SetDicts(const Dicts &dicts) { (void)dicts; - assert(0); // FIXME + gdcm_assert(0); // FIXME } std::string StringFilter::ToString(const Tag& t) const @@ -169,7 +169,7 @@ bool StringFilter::ExecuteQuery(std::string const & query_const, if( subtokens[0] == "DicomNativeModel" ) { // move to next state - assert( state == 0 ); + gdcm_assert( state == 0 ); state = 1; curds = &ds; } @@ -180,7 +180,7 @@ bool StringFilter::ExecuteQuery(std::string const & query_const, state = -1; break; } - assert( subtokens[1] == "keyword" ); + gdcm_assert( subtokens[1] == "keyword" ); const char *k = subtokens[2].c_str(); /*const DictEntry &dictentry = */pubdict.GetDictEntryByKeyword(k, t); if( !curds->FindDataElement( t ) ) @@ -192,9 +192,9 @@ bool StringFilter::ExecuteQuery(std::string const & query_const, } else if( subtokens[0] == "Item" ) { - assert( state == 1 ); - assert( curde ); - assert( subtokens[1] == "number" ); + gdcm_assert( state == 1 ); + gdcm_assert( curde ); + gdcm_assert( subtokens[1] == "number" ); sqi = curde->GetValueAsSQ(); if( !sqi ) { @@ -206,19 +206,19 @@ bool StringFilter::ExecuteQuery(std::string const & query_const, } else if( subtokens[0] == "Value" ) { - assert( state == 1 ); + gdcm_assert( state == 1 ); // move to next state state = 2; - assert( subtokens[1] == "number" ); + gdcm_assert( subtokens[1] == "number" ); #if !defined(NDEBUG) const ByteValue * const bv = curde->GetByteValue(); (void)bv; - assert( bv ); + gdcm_assert( bv ); //bv->Print( std::cout << std::endl ); #endif } else { - assert( !subtokens.empty() ); + gdcm_assert( !subtokens.empty() ); gdcmDebugMacro( "Unhandled token: " << subtokens[0] ); state = -1; } @@ -268,33 +268,33 @@ bool StringFilter::ExecuteQuery(std::string const & query_const, return false; } - assert( vr != VR::UN && vr != VR::INVALID ); + gdcm_assert( vr != VR::UN && vr != VR::INVALID ); //ret.first = entry.GetName(); if( VR::IsASCII( vr ) ) { - assert( vr & VR::VRASCII ); + gdcm_assert( vr & VR::VRASCII ); const ByteValue *bv = de.GetByteValue(); if( de.GetVL() ) { - assert( bv /*|| bv->IsEmpty()*/ ); + gdcm_assert( bv /*|| bv->IsEmpty()*/ ); retvalue = std::string( bv->GetPointer(), bv->GetLength() ); // Let's remove any trailing \0 : retvalue.resize( std::min( retvalue.size(), strlen( retvalue.c_str() ) ) ); // strlen is guarantee to be lower or equal to ::size() } else { - //assert( bv == NULL ); + //gdcm_assert( bv == NULL ); retvalue = ""; // ?? } } else { - assert( vr & VR::VRBINARY ); + gdcm_assert( vr & VR::VRBINARY ); const ByteValue *bv = de.GetByteValue(); if( bv ) { //VM::VMType vm = entry.GetVM();//!!mmr-- can I remove this, or will it mess with the stream? - //assert( vm == VM::VM1 ); + //gdcm_assert( vm == VM::VM1 ); if( vr.IsDual() ) // This mean vr was read from a dict entry: { vr = DataSetHelper::ComputeVR(GetFile(),ds, t); @@ -317,7 +317,7 @@ bool StringFilter::ExecuteQuery(std::string const & query_const, StringFilterCase(UT); case VR::UN: case VR::US_SS: - assert(0); + gdcm_assert(0); break; case VR::OB: case VR::OW: @@ -327,7 +327,7 @@ bool StringFilter::ExecuteQuery(std::string const & query_const, retvalue = ""; break; default: - assert(0); + gdcm_assert(0); break; } } @@ -358,7 +358,7 @@ std::pair StringFilter::ToStringPairInternal(const Dat gdcmDebugMacro( "DataSet is empty or does not contains tag:" ); return ret; } - //assert( de.GetTag().IsPublic() ); + //gdcm_assert( de.GetTag().IsPublic() ); std::string strowner; const char *owner = nullptr; const Tag &t = de.GetTag(); @@ -405,34 +405,34 @@ std::pair StringFilter::ToStringPairInternal(const Dat return ret; } - assert( vr != VR::UN && vr != VR::INVALID ); + gdcm_assert( vr != VR::UN && vr != VR::INVALID ); //std::cerr << "Found " << vr << " for " << de.GetTag() << std::endl; ret.first = entry.GetName(); if( VR::IsASCII( vr ) ) { - assert( vr & VR::VRASCII ); + gdcm_assert( vr & VR::VRASCII ); const ByteValue *bv = de.GetByteValue(); if( de.GetVL() ) { - assert( bv /*|| bv->IsEmpty()*/ ); + gdcm_assert( bv /*|| bv->IsEmpty()*/ ); ret.second = std::string( bv->GetPointer(), bv->GetLength() ); // Let's remove any trailing \0 : ret.second.resize( std::min( ret.second.size(), strlen( ret.second.c_str() ) ) ); // strlen is guarantee to be lower or equal to ::size() } else { - //assert( bv == NULL ); + //gdcm_assert( bv == NULL ); ret.second = ""; // ?? } } else { - assert( vr & VR::VRBINARY ); + gdcm_assert( vr & VR::VRBINARY ); const ByteValue *bv = de.GetByteValue(); if( bv ) { //VM::VMType vm = entry.GetVM();//!!mmr-- can I remove this, or will it mess with the stream? - //assert( vm == VM::VM1 ); + //gdcm_assert( vm == VM::VM1 ); if( vr.IsDual() ) // This mean vr was read from a dict entry: { vr = DataSetHelper::ComputeVR(GetFile(),ds, t); @@ -456,7 +456,7 @@ std::pair StringFilter::ToStringPairInternal(const Dat StringFilterCase(UT); case VR::UN: case VR::US_SS: - assert(0); + gdcm_assert(0); break; case VR::OB: case VR::OW: @@ -466,7 +466,7 @@ std::pair StringFilter::ToStringPairInternal(const Dat ret.second = ""; break; default: - assert(0); + gdcm_assert(0); break; } ret.second = retvalue; @@ -493,7 +493,7 @@ std::pair StringFilter::ToStringPairInternal(const Dat #if 0 static inline size_t count_backslash(const char *s, size_t len) { - assert( s ); + gdcm_assert( s ); size_t c = 0; for(size_t i = 0; i < len; ++i, ++s) { @@ -563,11 +563,11 @@ std::string StringFilter::FromString(const Tag&t, const char * value, size_t len if( vm.GetLength() == 0 ) { // VM1_n - vl = (VL)( count * vr.GetSizeof()); + vl = (VL)( (uint32_t)count * vr.GetSizeof()); #if !defined(NDEBUG) VM check = VM::GetVMTypeFromLength(count, 1); if( vm != VM::VM0 ) - assert( vm.Compatible( check ) ); + gdcm_assert( vm.Compatible( check ) ); #endif } @@ -590,7 +590,7 @@ std::string StringFilter::FromString(const Tag&t, const char * value, size_t len FromStringFilterCase(US); default: gdcmErrorMacro( "Not implemented" ); - assert(0); + gdcm_assert(0); } return os.str(); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurface.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurface.cxx index 725550c5d17..4065527ace1 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurface.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurface.cxx @@ -30,7 +30,7 @@ static const char * STATESStrings[] = { const char * Surface::GetSTATESString(STATES state) { - assert( state <= STATES_END ); + gdcm_assert( state <= STATES_END ); return STATESStrings[(int)state]; } @@ -77,7 +77,7 @@ static const char * VIEWStrings[] = { const char * Surface::GetVIEWTypeString(VIEWType type) { - assert( type <= VIEWType_END ); + gdcm_assert( type <= VIEWType_END ); return VIEWStrings[(int)type]; } @@ -171,7 +171,7 @@ const unsigned short * Surface::GetRecommendedDisplayCIELabValue() const unsigned short Surface::GetRecommendedDisplayCIELabValue(const unsigned int idx) const { - assert( idx < 3 ); + gdcm_assert( idx < 3 ); return RecommendedDisplayCIELabValue[idx]; } @@ -184,13 +184,13 @@ void Surface::SetRecommendedDisplayCIELabValue(const unsigned short vl[3]) void Surface::SetRecommendedDisplayCIELabValue(const unsigned short vl, const unsigned int idx/* = 0*/) { - assert( idx < 3 ); + gdcm_assert( idx < 3 ); RecommendedDisplayCIELabValue[idx] = vl; } void Surface::SetRecommendedDisplayCIELabValue(const std::vector< unsigned short > & vl) { - assert( vl.size() > 2 ); + gdcm_assert( vl.size() > 2 ); RecommendedDisplayCIELabValue[0] = vl[0]; RecommendedDisplayCIELabValue[1] = vl[1]; @@ -298,7 +298,7 @@ Surface::STATES Surface::GetFiniteVolume() const void Surface::SetFiniteVolume(STATES state) { - assert( state < STATES_END ); + gdcm_assert( state < STATES_END ); FiniteVolume = state; } @@ -309,7 +309,7 @@ Surface::STATES Surface::GetManifold() const void Surface::SetManifold(STATES state) { - assert( state < STATES_END ); + gdcm_assert( state < STATES_END ); Manifold = state; } @@ -383,7 +383,7 @@ const float * Surface::GetPointPositionAccuracy() const void Surface::SetPointPositionAccuracy(const float * accuracies) { - assert(accuracies); + gdcm_assert(accuracies); if (PointPositionAccuracy == nullptr) PointPositionAccuracy = new float[3]; @@ -419,7 +419,7 @@ const float * Surface::GetPointsBoundingBoxCoordinates() const void Surface::SetPointsBoundingBoxCoordinates(const float * coordinates) { - assert(coordinates); + gdcm_assert(coordinates); if (PointsBoundingBoxCoordinates == nullptr) PointsBoundingBoxCoordinates = new float[6]; @@ -438,7 +438,7 @@ const float * Surface::GetAxisOfRotation() const void Surface::SetAxisOfRotation(const float * axis) { - assert(axis); + gdcm_assert(axis); if (AxisOfRotation == nullptr) AxisOfRotation = new float[3]; @@ -454,7 +454,7 @@ const float * Surface::GetCenterOfRotation() const void Surface::SetCenterOfRotation(const float * center) { - assert(center); + gdcm_assert(center); if (CenterOfRotation == nullptr) CenterOfRotation = new float[3]; @@ -490,7 +490,7 @@ const float * Surface::GetVectorAccuracy() const void Surface::SetVectorAccuracy(const float * accuracy) { - assert(accuracy); + gdcm_assert(accuracy); if (VectorAccuracy == nullptr) VectorAccuracy = new float[ VectorDimensionality ]; @@ -523,7 +523,7 @@ MeshPrimitive & Surface::GetMeshPrimitive() return *Primitive; } -void Surface::SetMeshPrimitive(MeshPrimitive & mp) +void Surface::SetMeshPrimitive(MeshPrimitive const & mp) { Primitive = mp; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurface.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurface.h index 1786f73bb6c..a443958147d 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurface.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurface.h @@ -170,7 +170,7 @@ class GDCM_EXPORT Surface : public Object MeshPrimitive const & GetMeshPrimitive() const; MeshPrimitive & GetMeshPrimitive(); - void SetMeshPrimitive(MeshPrimitive & mp); + void SetMeshPrimitive(MeshPrimitive const & mp); private: diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurfaceHelper.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurfaceHelper.h index 5674bcdc21d..f1d32363501 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurfaceHelper.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurfaceHelper.h @@ -103,7 +103,7 @@ template unsigned short SurfaceHelper::RGBToRecommendedDisplayGrayscale(const std::vector & RGB, const U rangeMax/* = 255*/) { - assert(RGB.size() > 2); + gdcm_assert(RGB.size() > 2); unsigned short Grayscale = 0; @@ -121,7 +121,7 @@ template SurfaceHelper::ColorArray SurfaceHelper::RGBToRecommendedDisplayCIELab(const std::vector & RGB, const U rangeMax/* = 255*/) { - assert(RGB.size() > 2); + gdcm_assert(RGB.size() > 2); ColorArray CIELab(3); std::vector tmp(3); @@ -161,7 +161,7 @@ template std::vector SurfaceHelper::RecommendedDisplayCIELabToRGB(const ColorArray & CIELab, const U rangeMax/* = 255*/) { - assert(CIELab.size() > 2); + gdcm_assert(CIELab.size() > 2); std::vector RGB(3); std::vector tmp(3); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurfaceWriter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurfaceWriter.cxx index 0b4d764b050..e7fd7157359 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurfaceWriter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmSurfaceWriter.cxx @@ -63,7 +63,7 @@ bool SurfaceWriter::PrepareWrite() FileMetaInformation & fmi = file.GetHeader(); const TransferSyntax & ts = fmi.GetDataSetTransferSyntax(); - assert( ts.IsExplicit() || ts.IsImplicit() ); + gdcm_assert( ts.IsExplicit() || ts.IsImplicit() ); // Number Of Surface const unsigned long nbSurfaces = this->GetNumberOfSurfaces(); @@ -115,7 +115,7 @@ bool SurfaceWriter::PrepareWrite() for (; it0 != it0End; it0++) { SmartPointer< Segment > segment = *it0; - assert( segment ); + gdcm_assert( segment ); std::vector< SmartPointer< Surface > > surfaces = segment->GetSurfaces(); std::vector< SmartPointer< Surface > >::const_iterator it1 = surfaces.begin(); @@ -123,7 +123,7 @@ bool SurfaceWriter::PrepareWrite() for (; it1 != it1End; it1++) { SmartPointer< Surface > surface = *it1; - assert( surface ); + gdcm_assert( surface ); Item & surfaceItem = surfacesSQ->GetItem( numSurface ); DataSet & surfaceDS = surfaceItem.GetNestedDataSet(); @@ -342,7 +342,7 @@ bool SurfaceWriter::PrepareWrite() // Vector Dimensionality Attribute<0x0066, 0x001F> vectorDimensionalityAt; unsigned short vectorDimensionality = surface->GetVectorDimensionality(); - assert( vectorDimensionality ); + gdcm_assert( vectorDimensionality ); vectorDimensionalityAt.SetValue( vectorDimensionality ); surfacePointsNormalsDS.Replace( vectorDimensionalityAt.GetAsDataElement() ); @@ -508,7 +508,7 @@ bool SurfaceWriter::PrepareWrite() // Fill the Segment Sequence const unsigned int numberOfPrimitives = meshPrimitive->GetNumberOfPrimitivesData(); - assert( numberOfPrimitives ); + gdcm_assert( numberOfPrimitives ); const size_t nbItems = typedSequenceSQ->GetNumberOfItems(); if (nbItems < numberOfPrimitives) { @@ -822,7 +822,7 @@ bool SurfaceWriter::Write() return false; } - assert( Stream ); + gdcm_assert( Stream ); if( !Writer::Write() ) { return false; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmTagPath.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmTagPath.cxx index df32df5b56e..61581a059f1 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmTagPath.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmTagPath.cxx @@ -51,7 +51,7 @@ void TagPath::Print(std::ostream &os) const } else // item number { - // assert( it->GetElementTag() < 255 ); // how many item max can we have ? + // gdcm_assert( it->GetElementTag() < 255 ); // how many item max can we have ? os << it->GetElementTag() << "/"; } ++flip; @@ -126,7 +126,7 @@ bool TagPath::ConstructFromString(const char *path) } ++flip; if( pos != len && path[pos] == '/' ) ++pos; - //else assert(0); + //else gdcm_assert(0); } return true; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmUIDGenerator.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmUIDGenerator.cxx index 4d4a9d55ccf..06763b06d4e 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmUIDGenerator.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmUIDGenerator.cxx @@ -57,7 +57,7 @@ std::string UIDGenerator::EncodedHardwareAddress; // = System::GetHardwareAddres const char *UIDGenerator::GetRoot() { return Root.c_str(); } void UIDGenerator::SetRoot(const char * root) { - assert( IsValid( root ) ); + gdcm_assert( IsValid( root ) ); Root = root; } @@ -114,7 +114,7 @@ const char* UIDGenerator::Generate() if( !r ) return nullptr; char randbytesbuf[64]; size_t len = System::EncodeBytes(randbytesbuf, uuid, sizeof(uuid)); - assert( len < 64 ); // programmer error + gdcm_assert( len < 64 ); // programmer error Unique += "."; // This dot is compulsory to separate root from suffix if( Unique.size() + len > 64 ) { @@ -155,7 +155,7 @@ const char* UIDGenerator::Generate() // can now safely use randbytesbuf as is, no need to truncate any more: Unique += randbytesbuf; - assert( IsValid( Unique.c_str() ) ); + gdcm_assert( IsValid( Unique.c_str() ) ); return Unique.c_str(); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmUUIDGenerator.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmUUIDGenerator.cxx index eddf0ae6a66..4a59a5694ec 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmUUIDGenerator.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmUUIDGenerator.cxx @@ -40,7 +40,7 @@ const char* UUIDGenerator::Generate() Unique.resize( 36 ); char *uuid_data = &Unique[0]; #if defined(HAVE_UUID_GENERATE) - assert( sizeof(uuid_t) == 16 ); + gdcm_assert( sizeof(uuid_t) == 16 ); uuid_t g; uuid_generate(g); uuid_unparse(g, uuid_data); @@ -61,7 +61,7 @@ const char* UUIDGenerator::Generate() #else #error should not happen #endif - assert( IsValid( Unique.c_str() ) ); + gdcm_assert( IsValid( Unique.c_str() ) ); return Unique.c_str(); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmXMLPrinter.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmXMLPrinter.cxx index 23279811b10..4924124c6e7 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmXMLPrinter.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmXMLPrinter.cxx @@ -109,8 +109,8 @@ VR XMLPrinter::PrintDataElement(std::ostream &os, const Dicts &dicts, const Data } //as DataSetHelper would have been called - assert( refvr != VR::US_SS ); - assert( refvr != VR::OB_OW ); + gdcm_assert( refvr != VR::US_SS ); + gdcm_assert( refvr != VR::OB_OW ); if( !de.IsEmpty() ) { @@ -119,21 +119,21 @@ VR XMLPrinter::PrintDataElement(std::ostream &os, const Dicts &dicts, const Data { sqi = de.GetValueAsSQ(); refvr = VR::SQ; - assert( refvr == VR::SQ ); + gdcm_assert( refvr == VR::SQ ); } #if 0 else if( vr == VR::SQ && vr_read != VR::SQ ) { sqi = de.GetValueAsSQ(); refvr = VR::SQ; - assert( refvr == VR::SQ ); + gdcm_assert( refvr == VR::SQ ); } #endif } if( (vr_read == VR::INVALID || vr_read == VR::UN ) && vl_read.IsUndefined() ) { - assert( refvr == VR::SQ ); + gdcm_assert( refvr == VR::SQ ); } // if( vr_read == VR::SQ || vr_read == VR::UN ) @@ -142,7 +142,7 @@ VR XMLPrinter::PrintDataElement(std::ostream &os, const Dicts &dicts, const Data // } if( vr != VR::INVALID && (!vr.Compatible( vr_read ) || vr_read == VR::INVALID || vr_read == VR::UN ) ) { - assert( vr != VR::INVALID ); + gdcm_assert( vr != VR::INVALID ); /* No need as we will save only the VR to which it is stored by GDCM in the XML file @@ -164,7 +164,7 @@ VR XMLPrinter::PrintDataElement(std::ostream &os, const Dicts &dicts, const Data // the vr // eg. CD1/647662/647663/6471066 has a SQ at (2001,9000) - assert( refvr == VR::INVALID ); + gdcm_assert( refvr == VR::INVALID ); refvr = VR::SQ; } @@ -191,7 +191,7 @@ VR XMLPrinter::PrintDataElement(std::ostream &os, const Dicts &dicts, const Data /* retired element */ else if( retired ) { - assert( t.IsPublic() || t.GetElement() == 0x0 ); // Is there such thing as private and retired element ? + gdcm_assert( t.IsPublic() || t.GetElement() == 0x0 ); // Is there such thing as private and retired element ? //os << name; //os = PrintXML_char(os,name); } @@ -248,7 +248,7 @@ VR XMLPrinter::PrintDataElement(std::ostream &os, const Dicts &dicts, const Data } \ else { if( de.IsEmpty() ) \ {} } } \ - else { assert( de.IsEmpty()); } \ + else { gdcm_assert( de.IsEmpty()); } \ } break @@ -263,25 +263,25 @@ VR XMLPrinter::PrintDataElement(std::ostream &os, const Dicts &dicts, const Data } else { - assert( de.IsEmpty() ); + gdcm_assert( de.IsEmpty() ); } } else if( refvr & VR::VRASCII ) { - //assert( !sqi && !sqf); - assert(!sqi); + //gdcm_assert( !sqi && !sqf); + gdcm_assert(!sqi); if( bv ) { bv->PrintASCIIXML(os); //new function to print each value in new child tag } else { - assert( de.IsEmpty() ); + gdcm_assert( de.IsEmpty() ); } } else { - assert( refvr & VR::VRBINARY || (vr == VR::INVALID && refvr == VR::INVALID) ); + gdcm_assert( refvr & VR::VRBINARY || (vr == VR::INVALID && refvr == VR::INVALID) ); std::string s; switch(refvr) { @@ -324,7 +324,7 @@ VR XMLPrinter::PrintDataElement(std::ostream &os, const Dicts &dicts, const Data } else if ( sqf ) { - assert( t == Tag(0x7fe0,0x0010) ); + gdcm_assert( t == Tag(0x7fe0,0x0010) ); } else if ( sqi ) { @@ -332,13 +332,13 @@ VR XMLPrinter::PrintDataElement(std::ostream &os, const Dicts &dicts, const Data } else { - assert( !sqi && !sqf ); - assert( de.IsEmpty() ); + gdcm_assert( !sqi && !sqf ); + gdcm_assert( de.IsEmpty() ); } } break; case VR::US_SS: - assert( refvr != VR::US_SS ); + gdcm_assert( refvr != VR::US_SS ); break; case VR::SQ://The below info need not be printed into the XML infoset acc. to the standard if( !sqi && !de.IsEmpty() && de.GetValue().GetLength() ) @@ -374,8 +374,8 @@ VR XMLPrinter::PrintDataElement(std::ostream &os, const Dicts &dicts, const Data } else { - assert( !sqi && !sqf ); - assert( de.IsEmpty() ); + gdcm_assert( !sqi && !sqf ); + gdcm_assert( de.IsEmpty() ); } break; /* ASCII are treated elsewhere but we do not want to use default: here to get warnings */ @@ -405,7 +405,7 @@ VR XMLPrinter::PrintDataElement(std::ostream &os, const Dicts &dicts, const Data case VR::VR_VM1: case VR::VRALL: case VR::VR_END: - assert(0 && "No Match! Impossible!!"); + gdcm_assert(0 && "No Match! Impossible!!"); break; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAbortPDU.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAbortPDU.cxx index ae8ee7cea4a..db423c56415 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAbortPDU.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAbortPDU.cxx @@ -54,14 +54,14 @@ AAbortPDU::AAbortPDU() Reason = 0; ItemLength = (uint32_t)Size() - 6; - assert( (ItemLength + 4 + 1 + 1) == Size() ); + gdcm_assert( (ItemLength + 4 + 1 + 1) == Size() ); } std::istream &AAbortPDU::Read(std::istream &is) { //uint8_t itemtype = 0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2 = 0; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint32_t itemlength = ItemLength; @@ -79,7 +79,7 @@ std::istream &AAbortPDU::Read(std::istream &is) is.read( (char*)&reason, sizeof(Reason) ); Reason = reason; - assert( (ItemLength + 4 + 1 + 1) == Size() ); + gdcm_assert( (ItemLength + 4 + 1 + 1) == Size() ); return is; } @@ -138,7 +138,7 @@ static const char *PrintReasonAsString( uint8_t reason ) case 0x6: return "invalid-PDU-parameter value"; } - assert( 0 ); + gdcm_assert( 0 ); return nullptr; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateACPDU.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateACPDU.cxx index 261b2fc1000..3b7cfca3785 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateACPDU.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateACPDU.cxx @@ -40,14 +40,14 @@ AAssociateACPDU::AAssociateACPDU() void AAssociateACPDU::SetCalledAETitle(const char calledaetitle[16]) { //size_t len = strlen( calledaetitle ); - //assert( len <= 16 ); // since forwarded from AA-RQ no reason to be invalid + //gdcm_assert( len <= 16 ); // since forwarded from AA-RQ no reason to be invalid memcpy(Reserved11_26, calledaetitle, 16 ); } void AAssociateACPDU::SetCallingAETitle(const char callingaetitle[16]) { //size_t len = strlen( callingaetitle ); - //assert( len <= 16 ); // since forwarded from AA-RQ no reason to be invalid + //gdcm_assert( len <= 16 ); // since forwarded from AA-RQ no reason to be invalid memcpy(Reserved27_42, callingaetitle, 16 ); } @@ -55,8 +55,8 @@ std::istream &AAssociateACPDU::Read(std::istream &is) { //uint8_t itemtype = 0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); - assert( is.good() ); + //gdcm_assert( itemtype == ItemType ); + gdcm_assert( is.good() ); uint8_t reserved2; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint32_t pdulength = 0; @@ -119,8 +119,8 @@ std::istream &AAssociateACPDU::Read(std::istream &is) // length of remaining bytes to read. //curlen = Size(); } - assert( curlen + 68 == PDULength ); - assert( PDULength + 4 + 1 + 1 == Size() ); + gdcm_assert( curlen + 68 == PDULength ); + gdcm_assert( PDULength + 4 + 1 + 1 == Size() ); return is; } @@ -155,7 +155,7 @@ const std::ostream &AAssociateACPDU::Write(std::ostream &os) const } UserInfo.Write( os ); - assert( PDULength + 4 + 1 + 1 == Size() ); + gdcm_assert( PDULength + 4 + 1 + 1 == Size() ); return os; } @@ -185,7 +185,7 @@ void AAssociateACPDU::AddPresentationContextAC( PresentationContextAC const &pca { PresContextAC.push_back( pcac ); PDULength = (uint32_t)(Size() - 6); - assert( PDULength + 4 + 1 + 1 == Size() ); + gdcm_assert( PDULength + 4 + 1 + 1 == Size() ); } void AAssociateACPDU::Print(std::ostream &os) const @@ -219,11 +219,11 @@ void AAssociateACPDU::InitFromRQ( AAssociateRQPDU const & rqpdu ) const std::string reserved = rqpdu.GetReserved43_74(); memcpy( Reserved43_74, reserved.c_str(), sizeof(Reserved43_74) ); - assert( ProtocolVersion == 0x01 ); - assert( Reserved9_10 == 0x0 ); - assert( memcmp( Reserved11_26, called.c_str(), sizeof( Reserved11_26) ) == 0 ); - assert( memcmp( Reserved27_42, calling.c_str(), sizeof(Reserved27_42) ) == 0 ); - assert( memcmp( Reserved43_74, reserved.c_str(), sizeof(Reserved43_74) ) == 0 ); + gdcm_assert( ProtocolVersion == 0x01 ); + gdcm_assert( Reserved9_10 == 0x0 ); + gdcm_assert( memcmp( Reserved11_26, called.c_str(), sizeof( Reserved11_26) ) == 0 ); + gdcm_assert( memcmp( Reserved27_42, calling.c_str(), sizeof(Reserved27_42) ) == 0 ); + gdcm_assert( memcmp( Reserved43_74, reserved.c_str(), sizeof(Reserved43_74) ) == 0 ); } @@ -232,7 +232,7 @@ void AAssociateACPDU::InitSimple( AAssociateRQPDU const & rqpdu ) TransferSyntaxSub ts1; ts1.SetNameFromUID( UIDs::ImplicitVRLittleEndianDefaultTransferSyntaxforDICOM ); - assert( rqpdu.GetNumberOfPresentationContext() ); + gdcm_assert( rqpdu.GetNumberOfPresentationContext() ); for( unsigned int index = 0; index < rqpdu.GetNumberOfPresentationContext(); index++ ) { // FIXME / HARDCODED We only ever accept Little Endian diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateACPDU.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateACPDU.h index 9107000c36c..ece353a2f94 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateACPDU.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateACPDU.h @@ -45,7 +45,7 @@ class AAssociateACPDU : public BasePDU typedef std::vector::size_type SizeType; const PresentationContextAC &GetPresentationContextAC( SizeType i ) { - assert( !PresContextAC.empty() && i < PresContextAC.size() ); + gdcm_assert( !PresContextAC.empty() && i < PresContextAC.size() ); return PresContextAC[i]; } SizeType GetNumberOfPresentationContextAC() const { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateRJPDU.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateRJPDU.cxx index e9bf97cc754..e1d110b1482 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateRJPDU.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateRJPDU.cxx @@ -34,7 +34,7 @@ std::istream &AAssociateRJPDU::Read(std::istream &is) { //uint8_t itemtype = 0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2; is >> reserved2; uint32_t itemlength; @@ -53,7 +53,7 @@ std::istream &AAssociateRJPDU::Read(std::istream &is) is >> reason; Reason = reason; - //assert( ItemLength + 4 + 1 + 1 == Size() ); + //gdcm_assert( ItemLength + 4 + 1 + 1 == Size() ); return is; } @@ -73,7 +73,7 @@ static const char *PrintResultAsString( uint8_t result ) case 0x2: return "rejected-transient"; } - assert( 0 ); + gdcm_assert( 0 ); return nullptr; } @@ -88,7 +88,7 @@ static const char *PrintSourceAsString( uint8_t source ) case 0x2: return "DICOM UL service-provider (Presentation related function)"; } - assert( 0 ); + gdcm_assert( 0 ); return nullptr; } @@ -143,7 +143,7 @@ static const char *PrintReasonAsString( uint8_t source, uint8_t reason ) return "3-7 - reserved"; } } - assert( 0 ); + gdcm_assert( 0 ); return nullptr; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateRQPDU.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateRQPDU.cxx index 9076b647f5d..e5c9eba255b 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateRQPDU.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateRQPDU.cxx @@ -49,14 +49,14 @@ AAssociateRQPDU::AAssociateRQPDU() //SetCallingAETitle( "MOVESCU" ); ItemLength = (uint32_t)Size() - 6; - assert( (ItemLength + 4 + 1 + 1) == Size() ); + gdcm_assert( (ItemLength + 4 + 1 + 1) == Size() ); } std::istream &AAssociateRQPDU::Read(std::istream &is) { //uint8_t itemtype = 0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2; is >> reserved2; uint32_t itemlength; @@ -114,16 +114,16 @@ std::istream &AAssociateRQPDU::Read(std::istream &is) // length of remaining bytes to read. //curlen = Size(); } - assert( curlen + 68 == ItemLength ); + gdcm_assert( curlen + 68 == ItemLength ); - assert( ItemLength + 4 + 1 + 1 == Size() ); + gdcm_assert( ItemLength + 4 + 1 + 1 == Size() ); return is; } const std::ostream &AAssociateRQPDU::Write(std::ostream &os) const { - assert( ItemLength + 4 + 1 + 1 == Size() ); + gdcm_assert( ItemLength + 4 + 1 + 1 == Size() ); #if 0 // Need to check all context Id are ordered ? and odd number ? std::vector::const_iterator it = PresContext.begin(); @@ -141,9 +141,9 @@ const std::ostream &AAssociateRQPDU::Write(std::ostream &os) const SwapperDoOp::SwapArray(&protocolversion,1); os.write( (const char*)&protocolversion, sizeof(ProtocolVersion) ); os.write( (const char*)&Reserved9_10, sizeof(Reserved9_10) ); - assert( AAssociateRQPDU::IsAETitleValid(CalledAETitle) ); + gdcm_assert( AAssociateRQPDU::IsAETitleValid(CalledAETitle) ); os.write( CalledAETitle, 16 ); - assert( AAssociateRQPDU::IsAETitleValid(CallingAETitle) ); + gdcm_assert( AAssociateRQPDU::IsAETitleValid(CallingAETitle) ); os.write( CallingAETitle, 16 ); os.write( (const char*)&Reserved43_74, sizeof(Reserved43_74) ); AppContext.Write(os); @@ -216,12 +216,12 @@ void AAssociateRQPDU::AddPresentationContext( PresentationContextRQ const &pc ) { PresContext.push_back( pc ); ItemLength = (uint32_t)Size() - 6; - assert( (ItemLength + 4 + 1 + 1) == Size() ); + gdcm_assert( (ItemLength + 4 + 1 + 1) == Size() ); } void AAssociateRQPDU::SetCalledAETitle(const char calledaetitle[16]) { - assert( AAssociateRQPDU::IsAETitleValid(calledaetitle) ); + gdcm_assert( AAssociateRQPDU::IsAETitleValid(calledaetitle) ); size_t len = strlen( calledaetitle ); if( len <= 16 ) { @@ -234,7 +234,7 @@ void AAssociateRQPDU::SetCalledAETitle(const char calledaetitle[16]) void AAssociateRQPDU::SetCallingAETitle(const char callingaetitle[16]) { - assert( AAssociateRQPDU::IsAETitleValid(callingaetitle) ); + gdcm_assert( AAssociateRQPDU::IsAETitleValid(callingaetitle) ); size_t len = strlen( callingaetitle ); if( len <= 16 ) { @@ -307,7 +307,7 @@ void AAssociateRQPDU::SetUserInformation( UserInformation const & ui ) { UserInfo = ui; ItemLength = (uint32_t)Size() - 6; - assert( (ItemLength + 4 + 1 + 1) == Size() ); + gdcm_assert( (ItemLength + 4 + 1 + 1) == Size() ); } } // end namespace network diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateRQPDU.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateRQPDU.h index dff4eaae3ac..69edadb6ff2 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateRQPDU.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAAssociateRQPDU.h @@ -60,12 +60,12 @@ class AAssociateRQPDU : public BasePDU AAssociateRQPDU(const AAssociateRQPDU &pdu):BasePDU(pdu) { - assert( 0 ); + gdcm_assert( 0 ); } //this function fails to compile on windows. // AAssociateRQPDU &operator=(const AAssociateRQPDU &_val) // { -// assert( 0 ); +// gdcm_assert( 0 ); // } typedef std::vector::size_type SizeType; @@ -73,7 +73,7 @@ class AAssociateRQPDU : public BasePDU return PresContext.size(); } PresentationContextRQ const &GetPresentationContext(SizeType i) const { - assert( !PresContext.empty() && i < PresContext.size() ); + gdcm_assert( !PresContext.empty() && i < PresContext.size() ); return PresContext[i]; } typedef std::vector PresentationContextArrayType; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAReleaseRPPDU.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAReleaseRPPDU.cxx index 18021f85502..f2a98fa2498 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAReleaseRPPDU.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAReleaseRPPDU.cxx @@ -25,14 +25,14 @@ const uint32_t AReleaseRPPDU::Reserved7_10 = 0x0; AReleaseRPPDU::AReleaseRPPDU() { ItemLength = (uint32_t)(Size() - 6); // PDU Length - assert( ItemLength + 6 == Size() ); + gdcm_assert( ItemLength + 6 == Size() ); } std::istream &AReleaseRPPDU::Read(std::istream &is) { //uint8_t itemtype = 0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2 = 0; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint32_t itemlength = ItemLength; @@ -42,7 +42,7 @@ std::istream &AReleaseRPPDU::Read(std::istream &is) uint32_t reserved7_10; is.read( (char*)&reserved7_10, sizeof(Reserved7_10) ); - assert( ItemLength + 6 == Size() ); + gdcm_assert( ItemLength + 6 == Size() ); return is; } @@ -55,7 +55,7 @@ const std::ostream &AReleaseRPPDU::Write(std::ostream &os) const os.write( (const char*)©, sizeof(ItemLength) ); os.write( (const char*)&Reserved7_10, sizeof(Reserved7_10) ); - assert( ItemLength + 6 == Size() ); + gdcm_assert( ItemLength + 6 == Size() ); return os; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAReleaseRQPDU.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAReleaseRQPDU.cxx index 676db13e3bd..de03e77c240 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAReleaseRQPDU.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAReleaseRQPDU.cxx @@ -25,14 +25,14 @@ const uint32_t AReleaseRQPDU::Reserved7_10 = 0x0; AReleaseRQPDU::AReleaseRQPDU() { ItemLength = (uint32_t)(Size() - 6); // PDU Length - assert( ItemLength + 6 == Size() ); + gdcm_assert( ItemLength + 6 == Size() ); } std::istream &AReleaseRQPDU::Read(std::istream &is) { //uint8_t itemtype = 0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2 = 0; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint32_t itemlength = ItemLength; @@ -42,7 +42,7 @@ std::istream &AReleaseRQPDU::Read(std::istream &is) uint32_t reserved7_10; is.read( (char*)&reserved7_10, sizeof(Reserved7_10) ); - assert( ItemLength + 6 == Size() ); + gdcm_assert( ItemLength + 6 == Size() ); return is; } @@ -55,7 +55,7 @@ const std::ostream &AReleaseRQPDU::Write(std::ostream &os) const os.write( (const char*)©, sizeof(ItemLength) ); os.write( (const char*)&Reserved7_10, sizeof(Reserved7_10) ); - assert( ItemLength + 6 == Size() ); + gdcm_assert( ItemLength + 6 == Size() ); return os; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAbstractSyntax.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAbstractSyntax.cxx index 39972303df2..4d50ed65f08 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAbstractSyntax.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAbstractSyntax.cxx @@ -32,7 +32,7 @@ std::istream &AbstractSyntax::Read(std::istream &is) { uint8_t itemtype = 0x0; is.read( (char*)&itemtype, sizeof(ItemType) ); - assert( itemtype == ItemType ); + gdcm_assert( itemtype == ItemType ); uint8_t reserved2; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint16_t itemlength; @@ -41,7 +41,7 @@ std::istream &AbstractSyntax::Read(std::istream &is) ItemLength = itemlength; char name[256]; - assert( itemlength < 256 ); + gdcm_assert( itemlength < 256 ); is.read( name, itemlength ); Name = std::string(name,itemlength); @@ -64,13 +64,13 @@ const std::ostream &AbstractSyntax::Write(std::ostream &os) const size_t AbstractSyntax::Size() const { size_t ret = 0; - assert( Name.size() == ItemLength ); + gdcm_assert( Name.size() == ItemLength ); ret += sizeof(ItemType); ret += sizeof(Reserved2); ret += sizeof(ItemLength); ret += ItemLength; - assert(ret <= (size_t)std::numeric_limits::max); - assert(ret >= 4); + gdcm_assert(ret <= (size_t)std::numeric_limits::max); + gdcm_assert(ret >= 4); return ret; } @@ -84,9 +84,9 @@ void AbstractSyntax::UpdateName( const char *name ) { Name = name; size_t lenTemp = Name.size(); - assert(lenTemp < (size_t)std::numeric_limits::max); + gdcm_assert(lenTemp < (size_t)std::numeric_limits::max); ItemLength = (uint16_t)lenTemp; - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); return; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmApplicationContext.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmApplicationContext.cxx index f1fac467b72..1313036c871 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmApplicationContext.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmApplicationContext.cxx @@ -36,7 +36,7 @@ std::istream &ApplicationContext::Read(std::istream &is) { //uint8_t itemtype = 0x0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2 = 0x0; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint16_t itemlength; @@ -45,10 +45,10 @@ std::istream &ApplicationContext::Read(std::istream &is) ItemLength = itemlength; char name[256]; - assert( itemlength < 256 ); + gdcm_assert( itemlength < 256 ); is.read( name, ItemLength ); Name = std::string(name,itemlength); - assert( Name == DICOMApplicationContextName ); + gdcm_assert( Name == DICOMApplicationContextName ); return is; } @@ -61,7 +61,7 @@ const std::ostream &ApplicationContext::Write(std::ostream &os) const SwapperDoOp::SwapArray(©,1); os.write( (const char*)©, sizeof(ItemLength) ); - assert( Name == DICOMApplicationContextName ); + gdcm_assert( Name == DICOMApplicationContextName ); os.write( Name.c_str(), Name.size() ); return os; } @@ -69,7 +69,7 @@ const std::ostream &ApplicationContext::Write(std::ostream &os) const size_t ApplicationContext::Size() const { size_t ret = 0; - assert( Name.size() == ItemLength ); + gdcm_assert( Name.size() == ItemLength ); ret += sizeof(ItemType); ret += sizeof(Reserved2); ret += sizeof(ItemLength); @@ -82,9 +82,9 @@ void ApplicationContext::UpdateName( const char *name ) if( name ) { Name = name; - assert( Name.size() < std::numeric_limits::max() ); + gdcm_assert( Name.size() < std::numeric_limits::max() ); ItemLength = (uint16_t)Name.size(); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAsynchronousOperationsWindowSub.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAsynchronousOperationsWindowSub.cxx index bd85797ee0c..d8b70497bee 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAsynchronousOperationsWindowSub.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmAsynchronousOperationsWindowSub.cxx @@ -29,14 +29,14 @@ AsynchronousOperationsWindowSub::AsynchronousOperationsWindowSub() MaximumNumberOperationsPerformed = 0; ItemLength = (uint16_t)(Size() - 4); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } std::istream &AsynchronousOperationsWindowSub::Read(std::istream &is) { //uint8_t itemtype = 0x0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint16_t itemlength; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmBaseQuery.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmBaseQuery.cxx index baffb7a7b90..6f54d760332 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmBaseQuery.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmBaseQuery.cxx @@ -87,7 +87,7 @@ namespace gdcm thePaddedValue.push_back(' '); } - assert(thePaddedValue.length() < std::numeric_limits::max()); + gdcm_assert(thePaddedValue.length() < std::numeric_limits::max()); de.SetByteValue(thePaddedValue.c_str(), (uint32_t)thePaddedValue.length()); //Replace any existing values diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmBaseRootQuery.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmBaseRootQuery.cxx index 9cd61a45c99..30560e19eeb 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmBaseRootQuery.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmBaseRootQuery.cxx @@ -88,7 +88,7 @@ namespace gdcm { QueryBase* qb = nullptr; // Check no new extension: - assert( inRootType == ePatientRootType || inRootType == eStudyRootType ); + gdcm_assert( inRootType == ePatientRootType || inRootType == eStudyRootType ); if( qlevel == ePatient ) { @@ -124,7 +124,7 @@ namespace gdcm level = eStudy; break; } - assert( level == eStudy || level == ePatient ); + gdcm_assert( level == eStudy || level == ePatient ); return level; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCEchoMessages.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCEchoMessages.cxx index 8a25d22d29b..501e61360c5 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCEchoMessages.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCEchoMessages.cxx @@ -61,7 +61,7 @@ std::vector CEchoRQ::ConstructPDV( { Attribute<0x0,0x0> at = { 0 }; unsigned int glen = ds.GetLength(); - assert( (glen % 2) == 0 ); + gdcm_assert( (glen % 2) == 0 ); at.SetValue( glen ); ds.Insert( at.GetAsDataElement() ); } @@ -77,7 +77,7 @@ std::vector CEchoRQ::ConstructPDV( std::vector CEchoRSP::ConstructPDVByDataSet(const DataSet* inDataSet){ std::vector thePDV; (void)inDataSet; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCFindMessages.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCFindMessages.cxx index c5c376f75c1..f666ccfadfb 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCFindMessages.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCFindMessages.cxx @@ -91,7 +91,7 @@ std::vector CFindRQ::ConstructPDV( { Attribute<0x0,0x0> at = { 0 }; unsigned int glen = ds.GetLength(); - assert( (glen % 2) == 0 ); + gdcm_assert( (glen % 2) == 0 ); at.SetValue( glen ); ds.Insert( at.GetAsDataElement() ); } @@ -107,13 +107,13 @@ std::vector CFindRQ::ConstructPDV( std::vector CFindRSP::ConstructPDVByDataSet(const DataSet* inDataSet){ std::vector thePDV; (void)inDataSet; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } std::vector CFindCancelRQ::ConstructPDVByDataSet(const DataSet* inDataSet){ std::vector thePDV; (void)inDataSet; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCMoveMessages.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCMoveMessages.cxx index d7da4e7fab2..11922fe0ca9 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCMoveMessages.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCMoveMessages.cxx @@ -69,7 +69,7 @@ std::vector CMoveRQ::ConstructPDV( { Attribute<0x0,0x600> at = { "" }; const char *calling = inConnection.GetConnectionInfo().GetCallingAETitle(); - assert( AAssociateRQPDU::IsAETitleValid( calling ) ); + gdcm_assert( AAssociateRQPDU::IsAETitleValid( calling ) ); at.SetValue( calling ); ds.Insert( at.GetAsDataElement() ); } @@ -84,7 +84,7 @@ std::vector CMoveRQ::ConstructPDV( { Attribute<0x0,0x0> at = { 0 }; unsigned int glen = ds.GetLength(); - assert( (glen % 2) == 0 ); + gdcm_assert( (glen % 2) == 0 ); at.SetValue( glen ); ds.Insert( at.GetAsDataElement() ); } @@ -110,7 +110,7 @@ std::vector CMoveRQ::ConstructPDV( std::vector CMoveRQ::ConstructPDVByDataSet(const DataSet* inDataSet){ std::vector thePDVs; (void)inDataSet; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDVs; } @@ -118,13 +118,13 @@ std::vector CMoveRQ::ConstructPDVByDataSet(const DataSet* std::vector CMoveRSP::ConstructPDVByDataSet(const DataSet* inDataSet){ std::vector thePDV; (void)inDataSet; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } std::vector CMoveCancelRq::ConstructPDVByDataSet(const DataSet* inDataSet){ std::vector thePDV; (void)inDataSet; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCStoreMessages.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCStoreMessages.cxx index 3e606af91f5..e65b1db4bb9 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCStoreMessages.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCStoreMessages.cxx @@ -53,7 +53,7 @@ const DataSet* inDataSet = &file.GetDataSet(); PresentationContextRQ pc( UIDs::VerificationSOPClass ); uint8_t prescontid; { - assert( inDataSet ); + gdcm_assert( inDataSet ); PresentationDataValue thePDV; #if 0 std::string UIDString; @@ -91,12 +91,12 @@ const DataSet* inDataSet = &file.GetDataSet(); } const DataElement& msclass = inDataSet->GetDataElement( Tag(0x0008, 0x0016) ); const char *uid = msclass.GetByteValue()->GetPointer(); - assert( uid ); + gdcm_assert( uid ); std::string suid = std::string(uid, msclass.GetByteValue()->GetLength()); // self check // const PresentationContextAC * pc = inConnection.GetPresentationContextACByID(prescontid); -// assert( pc ); +// gdcm_assert( pc ); // TransferSyntaxSub const &tssub = pc->GetTransferSyntax(); const TransferSyntax & fmits = file.GetHeader().GetDataSetTransferSyntax(); const char *tsuidvalue = fmits.GetString(); @@ -109,9 +109,9 @@ const DataSet* inDataSet = &file.GetDataSet(); prescontid = inConnection.GetPresentationContextIDFromPresentationContext(pc); // prescontid cannot possibly be unknown since we are only looking in our own // AAssociateRQPDU - assert( prescontid != 0 ); + gdcm_assert( prescontid != 0 ); const PresentationContextRQ * rqpc = inConnection.GetPresentationContextRQByID(prescontid); - assert( rqpc ); + gdcm_assert( rqpc ); // Now let's see if this best matching PresentationContextRQ can be found in the AC // section of the AAssociateACPDU @@ -130,7 +130,7 @@ const DataSet* inDataSet = &file.GetDataSet(); } TransferSyntaxSub const & actssub = acpc->GetTransferSyntax(); - assert( rqpc->GetNumberOfTransferSyntaxes() == 1 ); // TODO FIXME + gdcm_assert( rqpc->GetNumberOfTransferSyntaxes() == 1 ); // TODO FIXME TransferSyntaxSub const & rqtssub = rqpc->GetTransferSyntax(0); if( !(actssub == rqtssub) ) { @@ -154,13 +154,13 @@ const DataSet* inDataSet = &file.GetDataSet(); thePDV.SetPresentationContextID( prescontid ); - assert(suid.size() < std::numeric_limits::max()); + gdcm_assert(suid.size() < std::numeric_limits::max()); de.SetByteValue( suid.c_str(), (uint32_t)suid.size() ); ds.Insert( de ); } { - assert( inDataSet->FindDataElement( Tag(0x0008, 0x0018) ) ); + gdcm_assert( inDataSet->FindDataElement( Tag(0x0008, 0x0018) ) ); const DataElement& msinst = inDataSet->GetDataElement( Tag(0x0008, 0x0018) ); std::string suid; DataElement de( Tag(0x0,0x1000) ); @@ -171,9 +171,9 @@ const DataSet* inDataSet = &file.GetDataSet(); if( bv ) { const char *uid = bv->GetPointer(); - assert( uid ); + gdcm_assert( uid ); suid = std::string(uid, bv->GetLength() ); - assert(suid.size() < std::numeric_limits::max()); + gdcm_assert(suid.size() < std::numeric_limits::max()); } } de.SetByteValue( suid.c_str(), (uint32_t)suid.size() ); @@ -188,7 +188,7 @@ static uint32_t messageid = 1; { Attribute<0x0,0x110> at = { 0 }; at.SetValue( (unsigned short)messageid++ ); - assert( messageid < std::numeric_limits::max()); + gdcm_assert( messageid < std::numeric_limits::max()); ds.Insert( at.GetAsDataElement() ); } { @@ -202,7 +202,7 @@ static uint32_t messageid = 1; { Attribute<0x0,0x0> at = { 0 }; unsigned int glen = ds.GetLength(); - assert( (glen % 2) == 0 ); + gdcm_assert( (glen % 2) == 0 ); at.SetValue( glen ); ds.Insert( at.GetAsDataElement() ); } @@ -252,7 +252,7 @@ if( !writeDataSet ) thePDV.SetMessageHeader( 0 ); else { - assert( cur == end ); + gdcm_assert( cur == end ); thePDV.SetMessageHeader( 2 ); } thePDVs.push_back(thePDV); @@ -270,7 +270,7 @@ const ULConnection &inConnection, const BaseRootQuery* inRootQuery) std::vector thePDVs; (void)inRootQuery; (void)inConnection; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDVs; } @@ -279,7 +279,7 @@ std::vector CStoreRSP::ConstructPDV(const ULConnection & { std::vector thePDVs; (void)inRootQuery; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDVs; } @@ -324,7 +324,7 @@ std::vector CStoreRSP::ConstructPDV(const DataSet* inData { Attribute<0x0,0x0> at = { 0 }; unsigned int glen = ds.GetLength(); - assert( (glen % 2) == 0 ); + gdcm_assert( (glen % 2) == 0 ); at.SetValue( glen ); ds.Insert( at.GetAsDataElement() ); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCompositeNetworkFunctions.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCompositeNetworkFunctions.cxx index 59692a20a47..b9f99332b27 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCompositeNetworkFunctions.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmCompositeNetworkFunctions.cxx @@ -257,7 +257,7 @@ bool CompositeNetworkFunctions::CFind( const char *remote, uint16_t portno, gdcmErrorMacro( "Failed to GetResponses." ); return false; } - assert( !theResponses.empty() ); + gdcm_assert( !theResponses.empty() ); // take the last one: const DataSet &ds = theResponses[ theResponses.size() - 1 ]; // FIXME assert ( ds.FindDataElement(Tag(0x0, 0x0900)) ); @@ -288,7 +288,7 @@ bool CompositeNetworkFunctions::CFind( const char *remote, uint16_t portno, Attribute<0x0,0x0902> errormsg; errormsg.SetFromDataSet( ds ); const char *themsg = errormsg.GetValue(); - assert( themsg ); (void)themsg; + gdcm_assert( themsg ); (void)themsg; gdcmErrorMacro( "Response Status: [" << themsg << "]" ); } break; @@ -305,7 +305,7 @@ bool CompositeNetworkFunctions::CFind( const char *remote, uint16_t portno, Attribute<0x0,0x0902> errormsg; errormsg.SetFromDataSet( ds ); const char *themsg = errormsg.GetValue(); - assert( themsg ); (void)themsg; + gdcm_assert( themsg ); (void)themsg; gdcmErrorMacro( "Response Status: " << themsg ); } } @@ -326,7 +326,7 @@ class MyWatcher : public SimpleSubjectWatcher void ShowIteration() override { index++; - assert( index <= nfiles ); + gdcm_assert( index <= nfiles ); refprogress = progress; } void ShowProgress(Subject *caller, const Event &evt) override @@ -384,7 +384,7 @@ bool CompositeNetworkFunctions::CStore( const char *remote, uint16_t portno, { const std::string & filename = files[i]; fn = filename.c_str(); - assert( fn && *fn ); (void)fn; + gdcm_assert( fn && *fn ); (void)fn; Reader reader; reader.SetFileName( filename.c_str() ); gdcmDebugMacro( "Processing: " << filename ); @@ -401,7 +401,7 @@ bool CompositeNetworkFunctions::CStore( const char *remote, uint16_t portno, gdcmErrorMacro( "Could not C-STORE: " << filename ); return false; } - assert( theDataSets.size() == 1 ); + gdcm_assert( theDataSets.size() == 1 ); const DataSet &ds = theDataSets[0]; assert ( ds.FindDataElement(Tag(0x0, 0x0900)) ); DataElement const & de = ds.GetDataElement(Tag(0x0,0x0900)); @@ -429,7 +429,7 @@ bool CompositeNetworkFunctions::CStore( const char *remote, uint16_t portno, Attribute<0x0,0x0902> errormsg; errormsg.SetFromDataSet( ds ); const char *themsg = errormsg.GetValue(); - assert( themsg ); (void)themsg; + gdcm_assert( themsg ); (void)themsg; gdcmErrorMacro( "Response Status: " << themsg ); ret = false; // at least one file was not sent correctly } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmFindPatientRootQuery.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmFindPatientRootQuery.cxx index 3ae1da3f2b2..cfabd21a9c3 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmFindPatientRootQuery.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmFindPatientRootQuery.cxx @@ -84,7 +84,7 @@ std::vector FindPatientRootQuery::GetTagListByLevel(const EQueryLevel& inQu case eImage: return mImage.GetAllTags(ePatientRootType); default: //have to return _something_ if a query level isn't given - assert(0); + gdcm_assert(0); { std::vector empty; return empty; @@ -225,7 +225,7 @@ bool FindPatientRootQuery::ValidateQuery(bool inStrict) const Tag t = itor->GetTag(); if (t == level.GetTag()) continue; if (t == language.GetTag()) continue; - assert( !tags.empty() ); + gdcm_assert( !tags.empty() ); if (std::find(tags.begin(), tags.end(), t) == tags.end()) { //check to see if it's a language tag, 8,5, and if it is, ignore if it's one diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmFindStudyRootQuery.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmFindStudyRootQuery.cxx index 2727b1461ce..98d938f0523 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmFindStudyRootQuery.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmFindStudyRootQuery.cxx @@ -76,7 +76,7 @@ std::vector FindStudyRootQuery::GetTagListByLevel(const EQueryLevel& inQuer case eImage: return mImage.GetAllTags(eStudyRootType); default: //have to return _something_ if a query level isn't given - assert(0); + gdcm_assert(0); { std::vector empty; return empty; @@ -232,7 +232,7 @@ bool FindStudyRootQuery::ValidateQuery(bool inStrict) const } if( thePresentTagCount != hiertags.size() ) { - assert( !hiertags.empty() ); + gdcm_assert( !hiertags.empty() ); gdcmWarningMacro( "Missing Key found (within the hierarchical search ones): " << hiertags[0] ); gdcmDebugMacro( "Current DataSet is: " << ds ); theReturn = false; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmImplementationClassUIDSub.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmImplementationClassUIDSub.cxx index 62752c4dff7..3f5a9b9636b 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmImplementationClassUIDSub.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmImplementationClassUIDSub.cxx @@ -27,14 +27,14 @@ ImplementationClassUIDSub::ImplementationClassUIDSub() ImplementationClassUID = FileMetaInformation::GetImplementationClassUID(); ItemLength = (uint16_t)ImplementationClassUID.size(); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } std::istream &ImplementationClassUIDSub::Read(std::istream &is) { //uint8_t itemtype = 0x0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint16_t itemlength; @@ -43,11 +43,11 @@ std::istream &ImplementationClassUIDSub::Read(std::istream &is) ItemLength = itemlength; char name[256]; - assert( itemlength < 256 ); + gdcm_assert( itemlength < 256 ); is.read( name, itemlength ); ImplementationClassUID = std::string(name, itemlength); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); return is; } @@ -68,7 +68,7 @@ const std::ostream &ImplementationClassUIDSub::Write(std::ostream &os) const size_t ImplementationClassUIDSub::Size() const { size_t ret = 0; - assert( ImplementationClassUID.size() == ItemLength ); + gdcm_assert( ImplementationClassUID.size() == ItemLength ); ret += sizeof(ItemType); ret += sizeof(Reserved2); ret += sizeof(ItemLength); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmImplementationVersionNameSub.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmImplementationVersionNameSub.cxx index 73a834fead4..88b6828e80f 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmImplementationVersionNameSub.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmImplementationVersionNameSub.cxx @@ -26,14 +26,14 @@ ImplementationVersionNameSub::ImplementationVersionNameSub() { ImplementationVersionName = FileMetaInformation::GetImplementationVersionName(); ItemLength = (uint16_t)ImplementationVersionName.size(); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } std::istream &ImplementationVersionNameSub::Read(std::istream &is) { //uint8_t itemtype = 0x0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint16_t itemlength; @@ -42,7 +42,7 @@ std::istream &ImplementationVersionNameSub::Read(std::istream &is) ItemLength = itemlength; char name[256]; - assert( itemlength < 256 ); + gdcm_assert( itemlength < 256 ); is.read( name, itemlength ); ImplementationVersionName = std::string(name,itemlength); @@ -66,7 +66,7 @@ const std::ostream &ImplementationVersionNameSub::Write(std::ostream &os) const size_t ImplementationVersionNameSub::Size() const { size_t ret = 0; - assert( ImplementationVersionName.size() == ItemLength ); + gdcm_assert( ImplementationVersionName.size() == ItemLength ); ret += sizeof(ItemType); ret += sizeof(Reserved2); ret += sizeof(ItemLength); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmMaximumLengthSub.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmMaximumLengthSub.cxx index 37fe583177a..65df08e804a 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmMaximumLengthSub.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmMaximumLengthSub.cxx @@ -25,14 +25,14 @@ MaximumLengthSub::MaximumLengthSub() { ItemLength = 0x4; MaximumLength = 0x4000; - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } std::istream &MaximumLengthSub::Read(std::istream &is) { //uint8_t itemtype = 0x0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint16_t itemlength; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmMovePatientRootQuery.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmMovePatientRootQuery.cxx index ba69a989907..23473d48a2c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmMovePatientRootQuery.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmMovePatientRootQuery.cxx @@ -84,7 +84,7 @@ std::vector MovePatientRootQuery::GetTagListByLevel(const EQueryLevel& inQu case eImage: return mImage.GetUniqueTags(ePatientRootType); default: //have to return _something_ if a query level isn't given - assert(0); + gdcm_assert(0); { std::vector empty; return empty; @@ -225,7 +225,7 @@ bool MovePatientRootQuery::ValidateQuery(bool inStrict) const const Tag &t = itor->GetTag(); if (t == level.GetTag()) continue; if (t == language.GetTag()) continue; - assert( !tags.empty() ); + gdcm_assert( !tags.empty() ); if (std::find(tags.begin(), tags.end(), t) == tags.end()) { //check to see if it's a language tag, 8,5, and if it is, ignore if it's one diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmMoveStudyRootQuery.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmMoveStudyRootQuery.cxx index 9c5d4400c82..ffaca759361 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmMoveStudyRootQuery.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmMoveStudyRootQuery.cxx @@ -74,7 +74,7 @@ std::vector MoveStudyRootQuery::GetTagListByLevel(const EQueryLevel& inQuer case eImage: return mImage.GetUniqueTags(eStudyRootType); default: //have to return _something_ if a query level isn't given - assert(0); + gdcm_assert(0); { std::vector empty; return empty; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNActionMessages.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNActionMessages.cxx index 6581caf01ba..c00a0ffa2e1 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNActionMessages.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNActionMessages.cxx @@ -28,7 +28,7 @@ namespace gdcm{ { std::vector thePDV; (void)inConnection; (void)inQuery; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } @@ -36,7 +36,7 @@ namespace gdcm{ NActionRSP::ConstructPDVByDataSet(const DataSet* inDataSet){ std::vector thePDV; (void)inDataSet; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNCreateMessages.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNCreateMessages.cxx index 27e76fd1799..e4727012c28 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNCreateMessages.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNCreateMessages.cxx @@ -73,7 +73,7 @@ namespace gdcm{ { Attribute<0x0,0x0> at = { 0 }; unsigned int glen = ds.GetLength(); - assert( (glen % 2) == 0 ); + gdcm_assert( (glen % 2) == 0 ); at.SetValue( glen ); ds.Insert( at.GetAsDataElement() ); } @@ -91,7 +91,7 @@ namespace gdcm{ NCreateRSP::ConstructPDVByDataSet(const DataSet* inDataSet){ std::vector thePDV; (void)inDataSet; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNDeleteMessages.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNDeleteMessages.cxx index 8570e6aa098..97cd8f31be6 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNDeleteMessages.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNDeleteMessages.cxx @@ -28,7 +28,7 @@ namespace gdcm{ { std::vector thePDV; (void)inConnection; (void)inQuery; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } @@ -36,7 +36,7 @@ namespace gdcm{ NDeleteRSP::ConstructPDVByDataSet(const DataSet* inDataSet){ std::vector thePDV; (void)inDataSet; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNEventReportMessages.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNEventReportMessages.cxx index cab8ed3e76c..1293c758e2a 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNEventReportMessages.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNEventReportMessages.cxx @@ -32,7 +32,7 @@ namespace gdcm{ { std::vector thePDV; (void)inConnection; (void)inQuery; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } @@ -40,7 +40,7 @@ namespace gdcm{ NEventReportRSP::ConstructPDVByDataSet(const DataSet* inDataSet){ std::vector thePDV; (void)inDataSet; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNGetMessages.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNGetMessages.cxx index d243309425d..c19030f672d 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNGetMessages.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNGetMessages.cxx @@ -28,7 +28,7 @@ namespace gdcm{ { std::vector thePDV; (void)inConnection; (void)inQuery; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } @@ -36,7 +36,7 @@ namespace gdcm{ NGetRSP::ConstructPDVByDataSet(const DataSet* inDataSet){ std::vector thePDV; (void)inDataSet; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNSetMessages.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNSetMessages.cxx index e3114addc3f..a9a5ca43250 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNSetMessages.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNSetMessages.cxx @@ -73,7 +73,7 @@ namespace gdcm{ { Attribute<0x0,0x0> at = { 0 }; unsigned int glen = ds.GetLength(); - assert( (glen % 2) == 0 ); + gdcm_assert( (glen % 2) == 0 ); at.SetValue( glen ); ds.Insert( at.GetAsDataElement() ); } @@ -90,7 +90,7 @@ namespace gdcm{ NSetRSP::ConstructPDVByDataSet(const DataSet* inDataSet){ std::vector thePDV; (void)inDataSet; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return thePDV; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNormalizedNetworkFunctions.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNormalizedNetworkFunctions.cxx index 9b2f3ead1b4..20f21b1f938 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNormalizedNetworkFunctions.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmNormalizedNetworkFunctions.cxx @@ -132,7 +132,7 @@ namespace gdcm gdcmErrorMacro( "Failed to GetResponses." ); return false; } - assert( !theResponses.empty() ); + gdcm_assert( !theResponses.empty() ); // take the last one: const DataSet &ds = theResponses[ theResponses.size() - 1 ]; // FIXME assert ( ds.FindDataElement(Tag(0x0, 0x0900)) ); @@ -243,7 +243,7 @@ namespace gdcm gdcmErrorMacro( "Failed to GetResponses." ); return false; } - assert( !theResponses.empty() ); + gdcm_assert( !theResponses.empty() ); // take the last one: const DataSet &ds = theResponses[ theResponses.size() - 1 ]; // FIXME assert ( ds.FindDataElement(Tag(0x0, 0x0900)) ); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPDUFactory.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPDUFactory.cxx index 3ffc8c6b82e..3b29d993511 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPDUFactory.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPDUFactory.cxx @@ -345,7 +345,7 @@ std::vector PDUFactory::GetPDVs(const std::vector(*itor); if (thePDataTFPDU == nullptr) { - assert(0); //shouldn't really get here. + gdcm_assert(0); //shouldn't really get here. return outPDVs; //just stop now, no longer with data pdus. } size_t theNumPDVsinPDU = thePDataTFPDU->GetNumberOfPresentationDataValues(); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPDataTFPDU.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPDataTFPDU.cxx index 8b4c1775c75..cfbc231256c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPDataTFPDU.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPDataTFPDU.cxx @@ -23,16 +23,16 @@ const uint8_t PDataTFPDU::Reserved2 = 0x00; PDataTFPDU::PDataTFPDU() { - assert(Size() < std::numeric_limits::max()); + gdcm_assert(Size() < std::numeric_limits::max()); ItemLength = (uint32_t)Size() - 6; - assert( (ItemLength + 4 + 1 + 1) == Size() ); + gdcm_assert( (ItemLength + 4 + 1 + 1) == Size() ); } std::istream &PDataTFPDU::Read(std::istream &is) { //uint8_t itemtype = 0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2 = 0; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint32_t itemlength = ItemLength; @@ -48,8 +48,8 @@ std::istream &PDataTFPDU::Read(std::istream &is) V.push_back( pdv ); curlen += pdv.Size(); } - assert( curlen == ItemLength ); - assert( (ItemLength + 4 + 1 + 1) == Size() ); + gdcm_assert( curlen == ItemLength ); + gdcm_assert( (ItemLength + 4 + 1 + 1) == Size() ); return is; } @@ -58,7 +58,7 @@ std::istream &PDataTFPDU::ReadInto(std::istream &is, std::ostream &os) { uint8_t itemtype = 0; is.read( (char*)&itemtype, sizeof(ItemType) ); - assert( itemtype == ItemType ); + gdcm_assert( itemtype == ItemType ); uint8_t reserved2 = 0; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint32_t itemlength = ItemLength; @@ -74,15 +74,15 @@ std::istream &PDataTFPDU::ReadInto(std::istream &is, std::ostream &os) V.push_back( pdv ); curlen += pdv.Size(); } - assert( curlen == ItemLength ); - assert( (ItemLength + 4 + 1 + 1) == Size() ); + gdcm_assert( curlen == ItemLength ); + gdcm_assert( (ItemLength + 4 + 1 + 1) == Size() ); return is; } const std::ostream &PDataTFPDU::Write(std::ostream &os) const { - assert( (ItemLength + 4 + 1 + 1) == Size() ); + gdcm_assert( (ItemLength + 4 + 1 + 1) == Size() ); os.write( (const char*)&ItemType, sizeof(ItemType) ); os.write( (const char*)&Reserved2, sizeof(Reserved2) ); //os.write( (const char*)&ItemLength, sizeof(ItemLength) ); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPDataTFPDU.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPDataTFPDU.h index 246735bc843..97832466aa6 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPDataTFPDU.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPDataTFPDU.h @@ -42,13 +42,13 @@ class GDCM_EXPORT PDataTFPDU : public BasePDU void AddPresentationDataValue( PresentationDataValue const &pdv ) { V.push_back( pdv ); - assert(Size() < std::numeric_limits::max()); + gdcm_assert(Size() < std::numeric_limits::max()); ItemLength = (uint32_t)Size() - 6; } typedef std::vector::size_type SizeType; PresentationDataValue const &GetPresentationDataValue(SizeType i) const { - assert( !V.empty() && i < V.size() ); + gdcm_assert( !V.empty() && i < V.size() ); return V[i]; } SizeType GetNumberOfPresentationDataValues() const { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContext.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContext.cxx index d5722bae9f1..476c3a51d14 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContext.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContext.cxx @@ -45,7 +45,7 @@ void PresentationContext::AddTransferSyntax( const char *tsstr ) void PresentationContext::SetPresentationContextID( uint8_t id ) { - assert( id ); + gdcm_assert( id ); ID = id; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContext.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContext.h index c4fba12a67a..a5c9ff8369c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContext.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContext.h @@ -53,8 +53,8 @@ class GDCM_EXPORT PresentationContext bool operator==(const PresentationContext & pc) const { - assert( TransferSyntaxes.size() == 1 ); // TODO - assert( pc.TransferSyntaxes.size() == 1 ); + gdcm_assert( TransferSyntaxes.size() == 1 ); // TODO + gdcm_assert( pc.TransferSyntaxes.size() == 1 ); return AbstractSyntax == pc.AbstractSyntax && TransferSyntaxes == pc.TransferSyntaxes; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextAC.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextAC.cxx index 52977cff20a..095565ed098 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextAC.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextAC.cxx @@ -30,14 +30,14 @@ PresentationContextAC::PresentationContextAC() ID = 1; // odd [1-255] Result = 0; ItemLength = 8; - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } std::istream &PresentationContextAC::Read(std::istream &is) { //uint8_t itemtype = 0x0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint16_t itemlength; @@ -56,7 +56,7 @@ std::istream &PresentationContextAC::Read(std::istream &is) is.read( (char*)&reserved8, sizeof(Reserved6) ); SubItems.Read( is ); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); return is; } @@ -74,7 +74,7 @@ const std::ostream &PresentationContextAC::Write(std::ostream &os) const os.write( (const char*)&Reserved8, sizeof(Reserved8) ); SubItems.Write(os); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); return os; } @@ -90,8 +90,8 @@ size_t PresentationContextAC::Size() const ret += sizeof(Reserved8); ret += SubItems.Size(); - assert(ret <= (size_t)std::numeric_limits::max); - assert(ret >= 4); + gdcm_assert(ret <= (size_t)std::numeric_limits::max); + gdcm_assert(ret >= 4); return ret; } @@ -99,7 +99,7 @@ void PresentationContextAC::SetTransferSyntax( TransferSyntaxSub const &ts ) { SubItems = ts; ItemLength = (uint16_t)(Size() - 4); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } void PresentationContextAC::Print(std::ostream &os) const diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextGenerator.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextGenerator.cxx index eaff8b5c987..a0a6932248a 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextGenerator.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextGenerator.cxx @@ -128,14 +128,14 @@ bool PresentationContextGenerator::GenerateFromFilenames(const Directory::Filena bool PresentationContextGenerator::AddPresentationContext( const char *as, const char * ts ) { // \precondition - assert( as ); - assert( ts ); + gdcm_assert( as ); + gdcm_assert( ts ); SizeType n = PresContext.size(); PresentationContext pc; pc.SetAbstractSyntax( as ); SizeType idn = 2*n + 1; - assert( idn <= std::numeric_limits::max() ); + gdcm_assert( idn <= std::numeric_limits::max() ); pc.SetPresentationContextID( (uint8_t)idn ); pc.AddTransferSyntax( ts ); @@ -159,7 +159,7 @@ void PresentationContextGenerator::SetMergeModeToAbstractSyntax() void PresentationContextGenerator::SetMergeModeToTransferSyntax() { - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); } } // end namespace gdcm diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextRQ.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextRQ.cxx index ec00b832d34..9f46af1aad7 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextRQ.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextRQ.cxx @@ -36,7 +36,7 @@ PresentationContextRQ::PresentationContextRQ() { ID = 0x01; ItemLength = 8; - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } PresentationContextRQ::PresentationContextRQ( UIDs::TSName asname, UIDs::TSName tsname ) @@ -48,7 +48,7 @@ PresentationContextRQ::PresentationContextRQ( UIDs::TSName asname, UIDs::TSName TransferSyntaxSub ts; ts.SetNameFromUID( tsname ); - assert( TransferSyntaxes.empty() ); + gdcm_assert( TransferSyntaxes.empty() ); AddTransferSyntax( ts ); } @@ -56,7 +56,7 @@ std::istream &PresentationContextRQ::Read(std::istream &is) { //uint8_t itemtype = 0x0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint16_t itemlength; @@ -70,7 +70,7 @@ std::istream &PresentationContextRQ::Read(std::istream &is) is.read( (char*)&reserved6, sizeof(Reserved6) ); uint8_t reserved7; is.read( (char*)&reserved7, sizeof(Reserved7) ); -// assert( reserved7 == 0 ); +// gdcm_assert( reserved7 == 0 ); //no need for this assert--'This reserved field shall be sent with a value 00H but not tested to this value when received.' uint8_t reserved8; is.read( (char*)&reserved8, sizeof(Reserved6) ); @@ -85,15 +85,15 @@ std::istream &PresentationContextRQ::Read(std::istream &is) TransferSyntaxes.push_back( ts ); curlen += ts.Size(); } - assert( curlen + offset == ItemLength ); + gdcm_assert( curlen + offset == ItemLength ); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); return is; } const std::ostream &PresentationContextRQ::Write(std::ostream &os) const { - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); os.write( (const char*)&ItemType, sizeof(ItemType) ); os.write( (const char*)&Reserved2, sizeof(Reserved2) ); uint16_t copy = ItemLength; @@ -131,8 +131,8 @@ size_t PresentationContextRQ::Size() const ret += it->Size(); } - assert(ret <= (size_t)std::numeric_limits::max); - assert(ret >= 4); + gdcm_assert(ret <= (size_t)std::numeric_limits::max); + gdcm_assert(ret >= 4); return ret; } @@ -140,19 +140,19 @@ void PresentationContextRQ::SetAbstractSyntax( AbstractSyntax const & as ) { SubItems = as; ItemLength = (uint16_t)(Size() - 4); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } void PresentationContextRQ::AddTransferSyntax( TransferSyntaxSub const &ts ) { TransferSyntaxes.push_back( ts ); ItemLength = (uint16_t)(Size() - 4); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } void PresentationContextRQ::SetPresentationContextID( uint8_t id ) { - assert( id ); + gdcm_assert( id ); ID = id; } @@ -192,7 +192,7 @@ PresentationContextRQ::PresentationContextRQ(const PresentationContext & in) AddTransferSyntax( ts ); } SetPresentationContextID( in.GetPresentationContextID() ); - assert( GetNumberOfTransferSyntaxes() == in.GetNumberOfTransferSyntaxes() ); + gdcm_assert( GetNumberOfTransferSyntaxes() == in.GetNumberOfTransferSyntaxes() ); } } // end namespace network diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextRQ.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextRQ.h index 992c0a41429..12c2ddd37c8 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextRQ.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationContextRQ.h @@ -64,8 +64,8 @@ class GDCM_EXPORT PresentationContextRQ bool operator==(const PresentationContextRQ & pc) const { - assert( TransferSyntaxes.size() == 1 ); // TODO - assert( pc.TransferSyntaxes.size() == 1 ); + gdcm_assert( TransferSyntaxes.size() == 1 ); // TODO + gdcm_assert( pc.TransferSyntaxes.size() == 1 ); return SubItems == pc.SubItems && TransferSyntaxes == pc.TransferSyntaxes; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationDataValue.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationDataValue.cxx index 5e83c175b96..cbea417d6bf 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationDataValue.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationDataValue.cxx @@ -31,7 +31,7 @@ PresentationDataValue::PresentationDataValue() PresentationContextID = 0; //MUST BE SET BY THE CALLER! // postcondition - assert(Size() < std::numeric_limits::max()); + gdcm_assert(Size() < std::numeric_limits::max()); ItemLength = (uint32_t)Size() - 4; assert (ItemLength + 4 == Size() ); } @@ -52,7 +52,7 @@ std::istream &PresentationDataValue::Read(std::istream &is) gdcmDebugMacro( "Bizarre MessageHeader: " << MessageHeader ); } - assert( ItemLength > 2 ); + gdcm_assert( ItemLength > 2 ); uint32_t vl = ItemLength - 2; Blob.resize( vl ); is.read( &Blob[0], vl ); @@ -77,7 +77,7 @@ std::istream &PresentationDataValue::ReadInto(std::istream &is, std::ostream &os gdcmDebugMacro( "Bizarre MessageHeader: " << MessageHeader ); } - assert( ItemLength > 2 ); + gdcm_assert( ItemLength > 2 ); uint32_t vl = ItemLength - 2; Blob.resize( vl ); is.read( &Blob[0], vl ); @@ -92,18 +92,18 @@ const std::ostream &PresentationDataValue::Write(std::ostream &os) const uint32_t copy = ItemLength; SwapperDoOp::SwapArray(©,1); os.write( (const char*)©, sizeof(ItemLength) ); - assert( os.good() ); + gdcm_assert( os.good() ); os.write( (const char*)&PresentationContextID, sizeof(PresentationContextID) ); - assert( os.good() ); + gdcm_assert( os.good() ); - assert( MessageHeader <= 3 ); + gdcm_assert( MessageHeader <= 3 ); uint8_t t = MessageHeader; os.write( (const char*)&t, 1 ); - assert( os.good() ); + gdcm_assert( os.good() ); os.write( Blob.c_str(), Blob.size() ); - assert( Blob.size() == ItemLength - 2 ); + gdcm_assert( Blob.size() == ItemLength - 2 ); assert (ItemLength + 4 == Size() ); return os; @@ -122,9 +122,9 @@ size_t PresentationDataValue::Size() const void PresentationDataValue::SetBlob(const std::string & partialblob) { - assert( !partialblob.empty() ); + gdcm_assert( !partialblob.empty() ); Blob = partialblob; - assert(Size() < std::numeric_limits::max()); + gdcm_assert(Size() < std::numeric_limits::max()); ItemLength = (uint32_t)Size() - 4; assert (ItemLength + 4 == Size() ); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationDataValue.h b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationDataValue.h index b20ceff1324..3dbcd6e4e71 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationDataValue.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmPresentationDataValue.h @@ -49,18 +49,18 @@ class GDCM_EXPORT PresentationDataValue uint8_t GetPresentationContextID() const { return PresentationContextID; } void SetPresentationContextID(uint8_t id) { - assert( id ); + gdcm_assert( id ); PresentationContextID = id; } uint8_t GetMessageHeader() const { - assert( MessageHeader <= 0x3 ); + gdcm_assert( MessageHeader <= 0x3 ); return MessageHeader; } // E.2 MESSAGE CONTROL HEADER ENCODING // Only the first two bits are considered void SetMessageHeader(uint8_t messageheader) { MessageHeader = messageheader; - assert( MessageHeader <= 0x3 ); + gdcm_assert( MessageHeader <= 0x3 ); } //flip the least significant bit of the message header to 1 //if this is a command, else set it to 0. diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmQueryFactory.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmQueryFactory.cxx index 1da856dc163..415b992a66f 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmQueryFactory.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmQueryFactory.cxx @@ -228,7 +228,7 @@ DataElement QueryFactory::ProduceCharacterSetDataElement(const std::vector QueryPatient::GetUniqueTags(const ERootType& inRootType) const std::vector QueryPatient::GetHierachicalSearchTags(const ERootType& inRootType) const { - assert( inRootType == ePatientRootType ); + gdcm_assert( inRootType == ePatientRootType ); std::vector tags; // Patient is always toplevel ! // just return Required and Unique diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmRoleSelectionSub.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmRoleSelectionSub.cxx index 85e607e41a7..3926c6c0eeb 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmRoleSelectionSub.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmRoleSelectionSub.cxx @@ -30,14 +30,14 @@ RoleSelectionSub::RoleSelectionSub() SCPRole = 0; ItemLength = (uint16_t)(Size() - 4); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } std::istream &RoleSelectionSub::Read(std::istream &is) { //uint8_t itemtype = 0x0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint16_t itemlength; @@ -51,7 +51,7 @@ std::istream &RoleSelectionSub::Read(std::istream &is) UIDLength = uidlength; char name[256]; - assert( uidlength < 256 ); + gdcm_assert( uidlength < 256 ); is.read( name, uidlength ); Name = std::string(name,uidlength); @@ -63,14 +63,14 @@ std::istream &RoleSelectionSub::Read(std::istream &is) is.read( (char*)&scprole, sizeof(SCPRole) ); SCPRole = scprole; - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); return is; } const std::ostream &RoleSelectionSub::Write(std::ostream &os) const { - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); os.write( (const char*)&ItemType, sizeof(ItemType) ); os.write( (const char*)&Reserved2, sizeof(Reserved2) ); @@ -79,20 +79,20 @@ const std::ostream &RoleSelectionSub::Write(std::ostream &os) const SwapperDoOp::SwapArray(©,1); os.write( (const char*)©, sizeof(ItemLength) ); - assert( ItemLength > UIDLength ); + gdcm_assert( ItemLength > UIDLength ); uint16_t uidlength = UIDLength; SwapperDoOp::SwapArray(&uidlength,1); os.write( (const char*)&uidlength, sizeof(UIDLength) ); - assert( (size_t)UIDLength == Name.size() ); + gdcm_assert( (size_t)UIDLength == Name.size() ); os.write( Name.c_str(), Name.size() ); uint8_t scurole = SCURole; - assert( scurole == 0 || scurole == 1 ); + gdcm_assert( scurole == 0 || scurole == 1 ); os.write( (const char*)&scurole, sizeof(SCURole) ); uint8_t scprole = SCPRole; - assert( scprole == 0 || scprole == 1 ); + gdcm_assert( scprole == 0 || scprole == 1 ); os.write( (const char*)&scprole, sizeof(SCPRole) ); return os; @@ -105,7 +105,7 @@ size_t RoleSelectionSub::Size() const ret += sizeof(Reserved2); ret += sizeof(ItemLength); ret += sizeof(UIDLength); - assert( Name.size() == UIDLength ); + gdcm_assert( Name.size() == UIDLength ); ret += UIDLength; ret += sizeof(SCURole); ret += sizeof(SCPRole); @@ -134,13 +134,13 @@ void RoleSelectionSub::SetTuple(const char *uid, uint8_t scurole, uint8_t scprol { Name = uid; UIDLength = (uint16_t)strlen( uid ); - assert( (size_t)UIDLength == Name.size() ); + gdcm_assert( (size_t)UIDLength == Name.size() ); SCURole = scurole % 2; SCPRole = scprole % 2; ItemLength = (uint16_t)(Size() - 4); } // post condition - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } void RoleSelectionSub::Print(std::ostream &os) const diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmSOPClassExtendedNegociationSub.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmSOPClassExtendedNegociationSub.cxx index 57b5c4f098b..ffbe8f43ef7 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmSOPClassExtendedNegociationSub.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmSOPClassExtendedNegociationSub.cxx @@ -28,14 +28,14 @@ SOPClassExtendedNegociationSub::SOPClassExtendedNegociationSub() UIDLength = 0; ItemLength = (uint16_t)(Size() - 4); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } std::istream &SOPClassExtendedNegociationSub::Read(std::istream &is) { //uint8_t itemtype = 0x0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint16_t itemlength; @@ -49,13 +49,13 @@ std::istream &SOPClassExtendedNegociationSub::Read(std::istream &is) UIDLength = uidlength; char name[256]; - assert( uidlength < 256 ); + gdcm_assert( uidlength < 256 ); is.read( name, uidlength ); Name = std::string(name,uidlength); - assert( uidlength < ItemLength ); + gdcm_assert( uidlength < ItemLength ); uint16_t bloblength = (uint16_t)(ItemLength - 2 - uidlength); - assert( bloblength == 6 ); (void)bloblength; + gdcm_assert( bloblength == 6 ); (void)bloblength; SCAI.Read( is ); return is; @@ -120,7 +120,7 @@ void SOPClassExtendedNegociationSub::SetTuple(const char *uid, uint8_t levelofsu ItemLength = (uint16_t)(Size() - 4); } // post condition - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } } // end namespace network diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmServiceClassApplicationInformation.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmServiceClassApplicationInformation.cxx index 48844bd8e6b..97b18c63049 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmServiceClassApplicationInformation.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmServiceClassApplicationInformation.cxx @@ -36,19 +36,19 @@ std::istream &ServiceClassApplicationInformation::Read(std::istream &is) const std::ostream &ServiceClassApplicationInformation::Write(std::ostream &os) const { - assert( InternalArray[0] < 4 ); - assert( InternalArray[1] == 0 ); - assert( InternalArray[2] < 4 ); - assert( InternalArray[3] == 0 ); - assert( InternalArray[4] < 3 ); - assert( InternalArray[5] == 0 ); + gdcm_assert( InternalArray[0] < 4 ); + gdcm_assert( InternalArray[1] == 0 ); + gdcm_assert( InternalArray[2] < 4 ); + gdcm_assert( InternalArray[3] == 0 ); + gdcm_assert( InternalArray[4] < 3 ); + gdcm_assert( InternalArray[5] == 0 ); os.write( (const char*)InternalArray, sizeof(InternalArray) ); return os; } size_t ServiceClassApplicationInformation::Size() const { - assert( sizeof(InternalArray) == 6 ); + gdcm_assert( sizeof(InternalArray) == 6 ); return 6; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmServiceClassUser.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmServiceClassUser.cxx index 3ce4e0ea697..7b911487bf8 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmServiceClassUser.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmServiceClassUser.cxx @@ -148,7 +148,7 @@ bool ServiceClassUser::StartAssociation() for( std::vector::const_iterator itor = thePDUs.begin(); itor != thePDUs.end(); itor++) { - assert(*itor); + gdcm_assert(*itor); if (*itor == nullptr) continue; //can have a nulled pdu, apparently (*itor)->Print(Trace::GetErrorStream()); } @@ -272,11 +272,11 @@ bool ServiceClassUser::SendStore(File const &file) ULEvent theEvent(ePDATArequest, theDataPDU); EStateID stateid = RunEventLoop(theEvent, mConnection, inCallback, false); - assert( stateid == eSta6TransferReady ); (void)stateid; + gdcm_assert( stateid == eSta6TransferReady ); (void)stateid; std::vector const &theDataSets = theCallback.GetResponses(); bool ret = true; - assert( theDataSets.size() == 1 ); + gdcm_assert( theDataSets.size() == 1 ); const DataSet &ds = theDataSets[0]; assert ( ds.FindDataElement(Tag(0x0, 0x0900)) ); DataElement const & de = ds.GetDataElement(Tag(0x0,0x0900)); @@ -299,7 +299,7 @@ bool ServiceClassUser::SendStore(File const &file) Attribute<0x0,0x0902> errormsg; errormsg.SetFromDataSet( ds ); const char *themsg = errormsg.GetValue(); - assert( themsg ); (void)themsg; + gdcm_assert( themsg ); (void)themsg; gdcmErrorMacro( "Response Status: " << themsg ); ret = false; // at least one file was not sent correctly } @@ -326,7 +326,7 @@ bool ServiceClassUser::SendFind(const BaseRootQuery* query, std::vector std::vector const & theResponses = theCallback.GetResponses(); bool ret = false; // by default an error - assert( !theResponses.empty() ); + gdcm_assert( !theResponses.empty() ); // take the last one: const DataSet &ds = theResponses[ theResponses.size() - 1 ]; // FIXME assert ( ds.FindDataElement(Tag(0x0, 0x0900)) ); @@ -364,7 +364,7 @@ bool ServiceClassUser::SendFind(const BaseRootQuery* query, std::vector Attribute<0x0,0x0902> errormsg; errormsg.SetFromDataSet( ds ); const char *themsg = errormsg.GetValue(); - assert( themsg ); (void)themsg; + gdcm_assert( themsg ); (void)themsg; gdcmErrorMacro( "Response Status: [" << themsg << "]" ); } break; @@ -381,7 +381,7 @@ bool ServiceClassUser::SendFind(const BaseRootQuery* query, std::vector Attribute<0x0,0x0902> errormsg; errormsg.SetFromDataSet( ds ); const char *themsg = errormsg.GetValue(); - assert( themsg ); (void)themsg; + gdcm_assert( themsg ); (void)themsg; gdcmErrorMacro( "Response Status: " << themsg ); } } @@ -462,7 +462,7 @@ bool ServiceClassUser::SendMove(const BaseRootQuery* query, std::vector &r { (void)query; (void)retFiles; - assert( 0 && "unimplemented do not use" ); + gdcm_assert( 0 && "unimplemented do not use" ); return false; } @@ -535,7 +535,7 @@ EStateID ServiceClassUser::RunEventLoop(network::ULEvent& currentEvent, catch (...) { //handle the exception, which is basically that nothing came in over the pipe. - assert( 0 ); + gdcm_assert( 0 ); } } //now, we have to figure out the event that just happened based on the PDU that was received. @@ -805,7 +805,7 @@ EStateID ServiceClassUser::RunMoveEventLoop(ULEvent& currentEvent, ULConnectionC } catch ( ... ) { - assert( 0 ); + gdcm_assert( 0 ); } } if (secondConnectionEstablished && diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmTransferSyntaxSub.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmTransferSyntaxSub.cxx index 341c1c0ecdf..da227701fb0 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmTransferSyntaxSub.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmTransferSyntaxSub.cxx @@ -34,7 +34,7 @@ void TransferSyntaxSub::SetName( const char *name ) if( name ) { Name = name; - assert( Name.size() <= std::numeric_limits::max() ); + gdcm_assert( Name.size() <= std::numeric_limits::max() ); ItemLength = (uint16_t)Name.size(); } } @@ -43,7 +43,7 @@ std::istream &TransferSyntaxSub::Read(std::istream &is) { uint8_t itemtype = 0xf; is.read( (char*)&itemtype, sizeof(ItemType) ); - assert( itemtype == ItemType ); + gdcm_assert( itemtype == ItemType ); uint8_t reserved2; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint16_t itemlength; @@ -52,7 +52,7 @@ std::istream &TransferSyntaxSub::Read(std::istream &is) ItemLength = itemlength; char name[256]; - assert( itemlength < 256 ); + gdcm_assert( itemlength < 256 ); is.read( name, itemlength ); Name = std::string(name,itemlength); @@ -68,7 +68,7 @@ const std::ostream &TransferSyntaxSub::Write(std::ostream &os) const SwapperDoOp::SwapArray(©,1); os.write( (const char*)©, sizeof(ItemLength) ); - assert( Name.size() < 256 ); + gdcm_assert( Name.size() < 256 ); os.write( Name.c_str(), Name.size() ); return os; } @@ -76,7 +76,7 @@ const std::ostream &TransferSyntaxSub::Write(std::ostream &os) const size_t TransferSyntaxSub::Size() const { size_t ret = 0; - assert( Name.size() == ItemLength ); + gdcm_assert( Name.size() == ItemLength ); ret += sizeof(ItemType); ret += sizeof(Reserved2); ret += sizeof(ItemLength); @@ -94,7 +94,7 @@ void TransferSyntaxSub::UpdateName( const char *name ) { Name = name; ItemLength = (uint16_t)Name.size(); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); return; } } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULActionAE.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULActionAE.cxx index b8245fac76b..02940cad665 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULActionAE.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULActionAE.cxx @@ -96,10 +96,10 @@ EStateID ULActionAE3::PerformAction(Subject *, ULEvent& inEvent, ULConnection& i // Mark please check this junk: - assert(!inEvent.GetPDUs().empty()); + gdcm_assert(!inEvent.GetPDUs().empty()); AAssociateACPDU* acpdu; acpdu = dynamic_cast(inEvent.GetPDUs()[0]); - assert( acpdu ); + gdcm_assert( acpdu ); uint32_t maxpdu = acpdu->GetUserInformation().GetMaximumLengthSub().GetMaximumLength(); inConnection.SetMaxPDUSize(maxpdu); @@ -175,7 +175,7 @@ EStateID ULActionAE6::PerformAction(Subject *, ULEvent& inEvent, ULConnection& i AAssociateACPDU acpdu; - assert( rqpdu->GetNumberOfPresentationContext() ); + gdcm_assert( rqpdu->GetNumberOfPresentationContext() ); for( unsigned int index = 0; index < rqpdu->GetNumberOfPresentationContext(); index++ ) { // FIXME / HARDCODED We only ever accept Little Endian @@ -229,7 +229,7 @@ EStateID ULActionAE6::PerformAction(Subject *, ULEvent& inEvent, ULConnection& i pcac1.SetReason( result ); acpdu.AddPresentationContextAC( pcac1 ); } - assert( acpdu.GetNumberOfPresentationContextAC() ); + gdcm_assert( acpdu.GetNumberOfPresentationContextAC() ); // Init AE-Titles: acpdu.InitFromRQ( *rqpdu ); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULActionAR.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULActionAR.cxx index 9a91e4b5188..a0bb1275a7f 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULActionAR.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULActionAR.cxx @@ -117,7 +117,7 @@ EStateID ULActionAR6::PerformAction(Subject *, ULEvent& , ULConnection& , EStateID ULActionAR7::PerformAction(Subject *, ULEvent& , ULConnection& inConnection, bool& , EEventID& ){ -assert(0); +gdcm_assert(0); PDataTFPDU thePDU;//for now, use Matheiu's default values thePDU.Write(*inConnection.GetProtocol()); inConnection.GetProtocol()->flush(); @@ -130,7 +130,7 @@ assert(0); EStateID ULActionAR8::PerformAction(Subject *, ULEvent& , ULConnection& , bool& , EEventID& ){ -assert(0); +gdcm_assert(0); return eSta10ReleaseCollisionAc; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULActionDT.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULActionDT.cxx index a96897672c0..8482e4477fd 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULActionDT.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULActionDT.cxx @@ -48,7 +48,7 @@ static void process_input(iosockinet& sio) { uint8_t itemtype = 0x0; sio.read( (char*)&itemtype, 1 ); - assert( itemtype == 0x1 ); + gdcm_assert( itemtype == 0x1 ); AAssociateRQPDU rqpdu; //rqpdu.SetCallingAETitle( "MOTESCU" ); @@ -82,7 +82,7 @@ static void process_input(iosockinet& sio) //std::cout << "done AAssociateACPDU !" << std::endl; sio.read( (char*)&itemtype, 1 ); - assert( itemtype == 0x4 ); + gdcm_assert( itemtype == 0x4 ); PDataTFPDU pdata; pdata.Read( sio ); @@ -90,7 +90,7 @@ static void process_input(iosockinet& sio) // pick the first one: size_t n = pdata.GetNumPDVs(); - assert( n == 1 ); + gdcm_assert( n == 1 ); PresentationDataValue const &input_pdv = pdata.GetPresentationDataValue(0); //std::cout << "done PDataTFPDU 1!" << std::endl; @@ -104,7 +104,7 @@ static void process_input(iosockinet& sio) //at.SetFromDataSet( input_pdv.GetDataSet() ); unsigned short commanddatasettype = at.GetValue(); //std::cout << "CommandDataSetType: " << at.GetValue() << std::endl; - assert( messageheader == 3 ); + gdcm_assert( messageheader == 3 ); // C-STORE if( commanddatasettype == 0 ) @@ -117,7 +117,7 @@ static void process_input(iosockinet& sio) pdata2.ReadInto( sio, out ); //pdata2.Print( std::cout ); size_t n2 = pdata.GetNumPDVs(); - assert( n2 == 1 ); + gdcm_assert( n2 == 1 ); PresentationDataValue const &pdv = pdata2.GetPresentationDataValue(0); messageheader = pdv.GetMessageHeader(); //std::cout << "---------------- done PDataTFPDU: " << i << std::endl; @@ -125,7 +125,7 @@ static void process_input(iosockinet& sio) ++i; } while( messageheader == 0 ); - assert( messageheader == 2 ); // end of data + gdcm_assert( messageheader == 2 ); // end of data out.close(); PresentationDataValue pdv; @@ -155,7 +155,7 @@ static void process_input(iosockinet& sio) } //sio.read( (char*)&itemtype, 1 ); - //assert( itemtype == 0x4 ); + //gdcm_assert( itemtype == 0x4 ); //AReleaseRQPDU rel0; //rel0.Read( sio ); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULConnection.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULConnection.cxx index a10f8bf437f..704455431dd 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULConnection.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULConnection.cxx @@ -139,7 +139,7 @@ void ULConnection::AddAcceptedPresentationContext(const PresentationContextAC& i PresentationContextRQ ULConnection::FindContext(const DataElement& ) const { PresentationContextRQ empty; - assert( 0 && "TODO" ); + gdcm_assert( 0 && "TODO" ); return empty; } @@ -323,7 +323,7 @@ uint8_t ULConnection::GetPresentationContextIDFromPresentationContext(Presentati ret = it->GetPresentationContextID(); } - assert( ret ); + gdcm_assert( ret ); return ret; } @@ -340,7 +340,7 @@ TransferSyntaxSub const & ULConnection::GetCStoreTransferSyntax( ) const TransferSyntaxSub ts2; ts2.SetNameFromUID( UIDs::ExplicitVRLittleEndian ); - assert( strcmp(cstorets.GetName(), ts1.GetName()) == 0 + gdcm_assert( strcmp(cstorets.GetName(), ts1.GetName()) == 0 || strcmp(cstorets.GetName(), ts2.GetName()) == 0 ); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULConnectionInfo.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULConnectionInfo.cxx index 4bcdb959965..2ece86cd2cc 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULConnectionInfo.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULConnectionInfo.cxx @@ -57,10 +57,10 @@ bool ULConnectionInfo::Initialize(UserInformation const & inUserInformation, if (inCalledIPAddress == 0 && inCalledComputerName.empty()){ return false; } - assert( inCalledAETitle ); - assert( inCallingAETitle ); - assert( AAssociateRQPDU::IsAETitleValid( inCalledAETitle ) ); - assert( AAssociateRQPDU::IsAETitleValid( inCallingAETitle ) ); + gdcm_assert( inCalledAETitle ); + gdcm_assert( inCallingAETitle ); + gdcm_assert( AAssociateRQPDU::IsAETitleValid( inCalledAETitle ) ); + gdcm_assert( AAssociateRQPDU::IsAETitleValid( inCallingAETitle ) ); const size_t lcalled = strlen( inCalledAETitle ); const size_t lcalling = strlen( inCallingAETitle ); mCalledAETitle = std::string(inCalledAETitle, lcalled > 16 ? 16 : lcalled ); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULConnectionManager.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULConnectionManager.cxx index 9ea5bc98efb..63fbc01857a 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULConnectionManager.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmULConnectionManager.cxx @@ -196,7 +196,7 @@ bool ULConnectionManager::EstablishConnection(const std::string& inAETitle, for( std::vector::const_iterator itor = thePDUs.begin(); itor != thePDUs.end(); itor++) { - //assert(*itor); + //gdcm_assert(*itor); if (*itor == nullptr) continue; //can have a nulled pdu, apparently (*itor)->Print(Trace::GetErrorStream()); } @@ -207,7 +207,7 @@ bool ULConnectionManager::EstablishConnection(const std::string& inAETitle, for( std::vector::const_iterator itor = thePDUs.begin(); itor != thePDUs.end(); itor++) { - assert(*itor); + gdcm_assert(*itor); if (*itor == nullptr) continue; //can have a nulled pdu, apparently (*itor)->Print(Trace::GetDebugStream()); } @@ -421,7 +421,7 @@ void ULConnectionManager::SendStore(const File & file, ULConnectionCallback* inC ULEvent theEvent(ePDATArequest, theDataPDU, pStream, dataSetOffset ); EStateID theState = RunEventLoop(theEvent, mConnection, inCallback, false); - assert( theState == eSta6TransferReady || theState == eStaDoesNotExist ); (void)theState; + gdcm_assert( theState == eSta6TransferReady || theState == eStaDoesNotExist ); (void)theState; } std::vector ULConnectionManager::SendNEventReport (const BaseQuery* inQuery) @@ -677,7 +677,7 @@ EStateID ULConnectionManager::RunMoveEventLoop(ULEvent& currentEvent, ULConnecti Attribute<0x0,0x0800> at; at.SetFromDataElement( de ); unsigned short datasettype = at.GetValue(); - assert( datasettype == 0x0101 || datasettype == 0x1 ); (void)datasettype; + gdcm_assert( datasettype == 0x0101 || datasettype == 0x1 ); (void)datasettype; } if (theRSP.FindDataElement(Tag(0x0, 0x0900))){ DataElement const & de = theRSP.GetDataElement(Tag(0x0,0x0900)); @@ -1134,7 +1134,7 @@ EStateID ULConnectionManager::RunEventLoop(ULEvent& currentEvent, ULConnection* { delete theData[i]; } - assert(inCallback); + gdcm_assert(inCallback); { inCallback->HandleDataSet(theCompleteFindResponse); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmUserInformation.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmUserInformation.cxx index 8823f1594cc..a61794289c0 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmUserInformation.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition/gdcmUserInformation.cxx @@ -133,7 +133,7 @@ UserInformation::UserInformation() if( !RSSI->Empty() ) ItemLength += RSSI->Size(); if( !SOPCENSI->Empty() ) ItemLength += SOPCENSI->Size(); #endif - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } UserInformation::~UserInformation() @@ -147,7 +147,7 @@ std::istream &UserInformation::Read(std::istream &is) { //uint8_t itemtype = 0x0; //is.read( (char*)&itemtype, sizeof(ItemType) ); - //assert( itemtype == ItemType ); + //gdcm_assert( itemtype == ItemType ); uint8_t reserved2; is.read( (char*)&reserved2, sizeof(Reserved2) ); uint16_t itemlength; @@ -175,13 +175,13 @@ std::istream &UserInformation::Read(std::istream &is) curlen += ICUID.Size(); break; case 0x53: // AsynchronousOperationsWindowSub - assert( !AOWS ); + gdcm_assert( !AOWS ); AOWS = new AsynchronousOperationsWindowSub; AOWS->Read( is ); curlen += AOWS->Size(); break; case 0x54: // RoleSelectionSub - assert( RSSI ); + gdcm_assert( RSSI ); { RoleSelectionSub rss; rss.Read( is ); @@ -194,7 +194,7 @@ std::istream &UserInformation::Read(std::istream &is) curlen += IVNS.Size(); break; case 0x56: // SOPClassExtendedNegociationSub - assert( SOPCENSI ); + gdcm_assert( SOPCENSI ); { SOPClassExtendedNegociationSub sopcens; sopcens.Read( is ); @@ -205,19 +205,19 @@ std::istream &UserInformation::Read(std::istream &is) default: gdcmErrorMacro( "Unknown ItemType: " << std::hex << (int) itemtype2 ); curlen = ItemLength; // make sure to exit - assert(0); + gdcm_assert(0); break; } } - assert( curlen == ItemLength ); + gdcm_assert( curlen == ItemLength ); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); return is; } const std::ostream &UserInformation::Write(std::ostream &os) const { - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); os.write( (const char*)&ItemType, sizeof(ItemType) ); os.write( (const char*)&Reserved2, sizeof(Reserved2) ); uint16_t copy = ItemLength; @@ -240,7 +240,7 @@ const std::ostream &UserInformation::Write(std::ostream &os) const SOPCENSI->Write(os); } - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); return os; } @@ -305,7 +305,7 @@ UserInformation &UserInformation::operator=(const UserInformation& ui) *SOPCENSI = *ui.SOPCENSI; IVNS = ui.IVNS; - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); return *this; } @@ -314,14 +314,14 @@ void UserInformation::AddRoleSelectionSub( RoleSelectionSub const & rss ) { RSSI->RSSArray.push_back( rss ); ItemLength = (uint16_t)(Size() - 4); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } void UserInformation::AddSOPClassExtendedNegociationSub( SOPClassExtendedNegociationSub const & sopcens ) { SOPCENSI->SOPCENSArray.push_back( sopcens ); ItemLength = (uint16_t)(Size() - 4); - assert( (size_t)ItemLength + 4 == Size() ); + gdcm_assert( (size_t)ItemLength + 4 == Size() ); } } // end namespace network diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmcharls/CMakeLists.txt b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmcharls/CMakeLists.txt index 69f093c0477..c212f0aa335 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmcharls/CMakeLists.txt +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmcharls/CMakeLists.txt @@ -1,5 +1,5 @@ if(NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION) - cmake_minimum_required(VERSION 2.8.7) + cmake_minimum_required(VERSION 2.8.7...${GDCM_MAX_VALIDATED_CMAKE_VERSION}) endif() if(NOT CHARLS_NAMESPACE) @@ -11,14 +11,6 @@ string(TOLOWER ${CHARLS_NAMESPACE} CHARLS_LIBRARY_NAME) project(${CHARLS_NAMESPACE} CXX) -foreach(p - CMP0042 - CMP0063 - ) - if(POLICY ${p}) - cmake_policy(SET ${p} NEW) - endif() -endforeach() #----------------------------------------------------------------------------- # CHARLS version number @@ -73,7 +65,7 @@ add_library(${CHARLS_LIBRARY_NAME} interface.cpp jpegls.cpp jpegmarkersegment.cpp jpegstreamreader.cpp jpegstreamwriter.cpp ) target_compile_features(${CHARLS_LIBRARY_NAME} -# PUBLIC cxx_strong_enums + PUBLIC cxx_strong_enums PRIVATE cxx_nullptr) set_target_properties( ${CHARLS_LIBRARY_NAME} PROPERTIES VERSION ${CHARLS_MAJOR_VERSION}.${CHARLS_MINOR_VERSION} diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmcharls/jpegmarkersegment.cpp b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmcharls/jpegmarkersegment.cpp index 1a047a6f646..48ea7e7abdc 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmcharls/jpegmarkersegment.cpp +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmcharls/jpegmarkersegment.cpp @@ -34,7 +34,7 @@ unique_ptr JpegMarkerSegment::CreateStartOfFrameSegment(int w content.push_back(0); // Tqi = Quantization table destination selector (reserved for JPEG-LS, should be set to 0) } - return make_unique(JpegMarkerCode::StartOfFrameJpegLS, move(content)); + return make_unique(JpegMarkerCode::StartOfFrameJpegLS, std::move(content)); } @@ -58,14 +58,14 @@ unique_ptr JpegMarkerSegment::CreateJpegFileInterchangeFormat content.push_back(static_cast(params.Ythumbnail)); if (params.Xthumbnail > 0) { - if (params.thumbnail) + if (!params.thumbnail) throw CreateSystemError(ApiResult::InvalidJlsParameters, "params.Xthumbnail is > 0 but params.thumbnail == null_ptr"); content.insert(content.end(), static_cast(params.thumbnail), static_cast(params.thumbnail) + 3 * params.Xthumbnail * params.Ythumbnail); } - return make_unique(JpegMarkerCode::ApplicationData0, move(content)); + return make_unique(JpegMarkerCode::ApplicationData0, std::move(content)); } @@ -82,7 +82,7 @@ unique_ptr JpegMarkerSegment::CreateJpegLSExtendedParametersS push_back(content, static_cast(params.T3)); push_back(content, static_cast(params.RESET)); - return make_unique(JpegMarkerCode::JpegLSExtendedParameters, move(content)); + return make_unique(JpegMarkerCode::JpegLSExtendedParameters, std::move(content)); } @@ -113,5 +113,5 @@ unique_ptr JpegMarkerSegment::CreateStartOfScanSegment(int co content.push_back(static_cast(interleaveMode)); // ILV parameter content.push_back(0); // transformation - return make_unique(JpegMarkerCode::StartOfScan, move(content)); + return make_unique(JpegMarkerCode::StartOfScan, std::move(content)); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmcharls/jpegstreamreader.cpp b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmcharls/jpegstreamreader.cpp index 71bbe460812..db6340bbb00 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmcharls/jpegstreamreader.cpp +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmcharls/jpegstreamreader.cpp @@ -78,7 +78,7 @@ void JpegImageDataSegment::Serialize(JpegStreamWriter& streamWriter) auto codec = JlsCodecFactory().GetCodec(info, _params.custom); unique_ptr processLine(codec->CreateProcess(_rawStreamInfo)); ByteStreamInfo compressedData = streamWriter.OutputStream(); - size_t cbyteWritten = codec->EncodeScan(move(processLine), compressedData, streamWriter._bCompare ? streamWriter.GetPos() : nullptr); + size_t cbyteWritten = codec->EncodeScan(std::move(processLine), compressedData, streamWriter._bCompare ? streamWriter.GetPos() : nullptr); streamWriter.Seek(cbyteWritten); } @@ -119,7 +119,7 @@ void JpegStreamReader::Read(ByteStreamInfo rawPixels) unique_ptr qcodec = JlsCodecFactory().GetCodec(_params, _params.custom); unique_ptr processLine(qcodec->CreateProcess(rawPixels)); - qcodec->DecodeScan(move(processLine), _rect, _byteStream, _bCompare); + qcodec->DecodeScan(std::move(processLine), _rect, _byteStream, _bCompare); SkipBytes(rawPixels, static_cast(bytesPerPlane)); if (_params.interleaveMode != InterleaveMode::None) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3.c index ca32fd8a7b7..3f94933c231 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3.c @@ -262,7 +262,10 @@ static bool read_info(struct app *self, struct mec_mr3_info *info) { // read key and type at once: size_t s = fread_mirror(info, sizeof *info, 1, self); ERROR_RETURN(s, 1); + ERROR_RETURN(info->key & 0xfff00000, 0x0); ERROR_RETURN(info->type & 0x00ff, 0x0); + const uint32_t sign = info->type >> 24; + ERROR_RETURN(sign == 0x0 || sign == 0xff, true); return true; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_dict.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_dict.c index 8b529476f01..29f1ad3878d 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_dict.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_dict.c @@ -13,8 +13,13 @@ =========================================================================*/ #include "mec_mr3_dict.h" +// #define MEC_MR3_DICT_DEBUG + #include #include +#ifdef MEC_MR3_DICT_DEBUG +#include +#endif struct mec_mr3_dict { uint8_t group; @@ -67,8 +72,7 @@ static const struct mec_mr3_dict dict[] = { {0x01, 0x000059d8, 0xff002400, ""}, // {0x01, 0x00006d61, 0xff002c00, "Requested Procedure ID"}, // {0x01, 0x00006d62, 0xff002c00, ""}, // - {0x01, 0x00006d63, 0xff002c00, - "Procedure Code Sequence: Coding Scheme Designator"}, // + {0x01, 0x00006d63, 0xff002c00, "Procedure Code Sequence: Coding Scheme Designator"}, // {0x01, 0x00006d64, 0xff002c00, "Procedure Code Sequence: Code Meaning"}, // {0x01, 0x00006d65, 0xff002c00, "Study Instance UID"}, // {0x01, 0x00006d66, 0xff002c00, "Stentor Remote AETitle Element"}, // @@ -77,8 +81,7 @@ static const struct mec_mr3_dict dict[] = { {0x01, 0x00006d69, 0xff002c00, "Requested Procedure ID"}, // {0x01, 0x00006d71, 0xff002c00, ""}, // {0x01, 0x00006d72, 0xff002c00, "Procedure Code Sequence: Code Value"}, // - {0x01, 0x00006d73, 0xff002c00, - "Procedure Code Sequence: Coding Scheme Designator"}, // + {0x01, 0x00006d73, 0xff002c00, "Procedure Code Sequence: Coding Scheme Designator"}, // {0x01, 0x00006d74, 0xff002c00, "Procedure Code Sequence: Code Meaning"}, // {0x01, 0x00006d75, 0xff002c00, ""}, // {0x01, 0x00006d76, 0xff002c00, "Scheduled Procedure Step Description"}, // @@ -208,7 +211,7 @@ static const struct mec_mr3_dict dict[] = { {0x02, 0x0000a81c, 0xff003200, ""}, // {0x02, 0x0000a81d, 0xff002a00, ""}, // {0x02, 0x0000a822, 0x00000500, ""}, // - {0x02, 0x0000a823, 0xff002c00, "MR Acquisition Type"}, // + {0x02, 0x0000a823, 0xff002c00, "MR Acquisition Type"}, // {0x02, 0x0000a824, 0xff002400, ""}, // {0x02, 0x0000a825, 0xff002400, ""}, // {0x02, 0x0000a826, 0xff003200, ""}, // @@ -720,6 +723,8 @@ static const struct mec_mr3_dict dict[] = { {0x04, 0x00001809, 0xff002400, ""}, // {0x04, 0x00001bc4, 0xff002400, ""}, // {0x04, 0x00001bc5, 0xff002400, ""}, // + {0x04, 0x00001bca, 0xff002800, ""}, // + {0x04, 0x00001bcb, 0xff002800, ""}, // {0x04, 0x00001bcc, 0xff002c00, ""}, // {0x04, 0x0000a806, 0x00000500, "FOV"}, // {0x04, 0x0000b3b4, 0x00000b00, ""}, // @@ -813,20 +818,36 @@ static const struct mec_mr3_dict dict[] = { {0x09, 0x00036728, 0xff002400, ""}, // {0x09, 0x0003672a, 0xff002400, ""}, // {0x09, 0x0003672b, 0x00000600, ""}, // + {0x0a, 0x00000c1d, 0xff002400, ""}, // + {0x0a, 0x00036718, 0xff002400, ""}, // + {0x0a, 0x00036719, 0x00000600, ""}, // + {0x0a, 0x0003671a, 0x00000600, ""}, // + {0x0a, 0x0003671b, 0x00000600, ""}, // + {0x0a, 0x0003671c, 0xff002800, ""}, // + {0x0a, 0x0003671e, 0xff002a00, ""}, // + {0x0a, 0x00036721, 0xff002400, ""}, // + {0x0a, 0x00036722, 0xff002a00, ""}, // {0x0a, 0x00036723, 0x00000600, ""}, // {0x0a, 0x00036724, 0x00000600, ""}, // + {0x0a, 0x00036725, 0xff002400, ""}, // + {0x0a, 0x00036727, 0xff002400, ""}, // + {0x0a, 0x00036728, 0xff002400, ""}, // {0x0a, 0x0003672a, 0xff002400, ""}, // {0x0a, 0x0003672b, 0x00000600, ""}, // - {0x0a, 0x00036722, 0xff002a00, ""}, // - {0x0a, 0x0003671e, 0xff002a00, ""}, // - {0x0a, 0x00036728, 0xff002400, ""}, // - {0x0a, 0x0003671c, 0xff002800, ""}, // - {0x0a, 0x00036727, 0xff002400, ""}, // + {0x0b, 0x0003671c, 0xff002800, ""}, // + {0x0b, 0x0003671e, 0xff002a00, ""}, // + {0x0b, 0x00036722, 0xff002a00, ""}, // + {0x0b, 0x00036723, 0x00000600, ""}, // + {0x0b, 0x00036724, 0x00000600, ""}, // + {0x0b, 0x00036727, 0xff002400, ""}, // + {0x0b, 0x00036728, 0xff002400, ""}, // + {0x0b, 0x0003672a, 0xff002400, ""}, // + {0x0b, 0x0003672b, 0x00000600, ""}, // }; static const uint32_t dict_size = sizeof(dict) / sizeof(*dict); -void check_mec_mr3_dict() { +void check_mec_mr3_dict(void) { const struct mec_mr3_dict *prev = dict + 0; for (uint32_t i = 1; i < dict_size; ++i) { const struct mec_mr3_dict *next = dict + i; @@ -840,7 +861,7 @@ void check_mec_mr3_dict() { bool check_mec_mr3_info(const uint8_t group, const uint32_t key, const uint32_t type) { - assert(group > 0x0 && group < 0x9); + assert(group > 0x0 && group < 0xc); assert((key & 0xfff00000) == 0x0); assert((type & 0x000000ff) == 0x0); const uint32_t sign = type >> 24u; @@ -853,6 +874,12 @@ bool check_mec_mr3_info(const uint8_t group, const uint32_t key, found = true; } } +#ifdef MEC_MR3_DICT_DEBUG + if (!found) { + fprintf(stderr, "{0x%02x, 0x%08x, 0x%08x, \"\"}, //\n", group, key, type); + // assert(0); + } +#endif return found; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_dict.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_dict.h index 062a71c1f3f..759cc1f9212 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_dict.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_dict.h @@ -29,4 +29,4 @@ const char *get_mec_mr3_info_name(uint8_t group, uint32_t key); } /* end extern "C" */ #endif -#endif // MEC_MR3_DICT_H +#endif // MEC_MR3_DICT_H diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c index fbf7592418a..659d16f0422 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.c @@ -24,12 +24,12 @@ #include #if defined(_MSC_VER) || defined(__OpenBSD__) -#define GDCM_HAS_ICONV 0 +#define MEC3_HAS_ICONV 0 #else -#define GDCM_HAS_ICONV 1 +#define MEC3_HAS_ICONV 1 #endif -#if GDCM_HAS_ICONV +#if MEC3_HAS_ICONV #include #endif #if defined(_MSC_VER) && (_MSC_VER < 1900) @@ -60,7 +60,7 @@ static size_t stream_read(void *ptr, size_t size, size_t nmemb, struct app { struct stream *in; -#if GDCM_HAS_ICONV +#if MEC3_HAS_ICONV iconv_t conv; #endif void *shift_jis_buffer; @@ -68,7 +68,7 @@ struct app { static struct app *create_app(struct app *self, struct stream *in) { self->in = in; -#if GDCM_HAS_ICONV +#if MEC3_HAS_ICONV self->conv = iconv_open("utf-8", "shift-jis"); assert(self->conv != (iconv_t)-1); #endif @@ -77,7 +77,7 @@ static struct app *create_app(struct app *self, struct stream *in) { return self; } -static void setup_buffer(struct app *self, const void *input, size_t len) { +static void setup_buffer(struct app *self, const void *input, const size_t len) { self->in->cur = (char *)input; self->in->start = input; self->in->end = (char *)input + len; @@ -99,12 +99,185 @@ static size_t fread_mirror(void *ptr, size_t size, size_t nmemb, return s; } +#if 0 +static void dump2file(const char *in, int len) { + static int debug = 0; + char buffer[512]; + sprintf(buffer, "out%04d", debug); + ++debug; + FILE *f = fopen(buffer, "wb"); + fwrite(in, 1, len, f); + fclose(f); +} +#endif + +static size_t is_ascii_string_with_trailing_nulls(const void *ptr, const size_t size) { + const unsigned char *byte_ptr = (const unsigned char *)ptr; + size_t ret; + size_t i = 0; + + // Check for null-terminated C string + while (i < size && byte_ptr[i] != '\0') { + if (byte_ptr[i] > 127u) { + return (size_t)-1; + } + i++; + } + + // If we reached the end without finding a null terminator, it's not a valid + // ASCII C string + if (i == size) { + return (size_t)-1; + } + + // Move past the null terminator + ret = i; + i++; + + // Check that the remaining bytes are all null + for (; i < size; ++i) { + if (byte_ptr[i] != 0) { + return (size_t)-1; + } + } + + return ret; +} + +void print_string_as_hex(const char *str) { + printf(" %%"); + while (*str) { + printf("%02x ", (unsigned char)*str); + str++; + } + printf("%% "); +} + +// https://stackoverflow.com/questions/28270310/how-to-easily-detect-utf8-encoding-in-the-string +static bool is_valid_utf8(const char *string) { + if (!string) return true; + + const unsigned char *bytes = (const unsigned char *)string; + unsigned int cp; + int num; + + while (*bytes != 0x00) { + if ((*bytes & 0x80) == 0x00) { + // U+0000 to U+007F + cp = (*bytes & 0x7F); + num = 1; + } else if ((*bytes & 0xE0) == 0xC0) { + // U+0080 to U+07FF + cp = (*bytes & 0x1F); + num = 2; + } else if ((*bytes & 0xF0) == 0xE0) { + // U+0800 to U+FFFF + cp = (*bytes & 0x0F); + num = 3; + } else if ((*bytes & 0xF8) == 0xF0) { + // U+10000 to U+10FFFF + cp = (*bytes & 0x07); + num = 4; + } else + return false; + + bytes += 1; + for (int i = 1; i < num; ++i) { + if ((*bytes & 0xC0) != 0x80) return false; + cp = (cp << 6) | (*bytes & 0x3F); + bytes += 1; + } + + if ((cp > 0x10FFFF) || ((cp >= 0xD800) && (cp <= 0xDFFF)) || + ((cp <= 0x007F) && (num != 1)) || + ((cp >= 0x0080) && (cp <= 0x07FF) && (num != 2)) || + ((cp >= 0x0800) && (cp <= 0xFFFF) && (num != 3)) || + ((cp >= 0x10000) && (cp <= 0x1FFFFF) && (num != 4))) + return false; + } + + return true; +} + +enum unicode_type +{ + kError = -1, + kUTF8 = 0, + kSHIFT_JIS = 1, + kEUC_JP = 2 +}; + +const char * unicode_type_as_string(const int unicode_type) +{ + switch (unicode_type) + { + case kUTF8: + return "UTF-8"; + case kSHIFT_JIS: + return "SHIFT-JIS"; + case kEUC_JP: + return "EUC-JP"; + default: + assert(0); + return NULL; + } +} + +static int guess_unicode_and_convert(struct app *self, const char *str, size_t len) { + const size_t guesstimate = len < 128 ? 128 : len * 2; + self->shift_jis_buffer = realloc(self->shift_jis_buffer, guesstimate); + char *dest_str = self->shift_jis_buffer; + int utype = kError; +#if MEC3_HAS_ICONV + const char *in_str = str; + char *out_str = dest_str; + size_t inbytes = len; + size_t outbytes = guesstimate; + utype = kSHIFT_JIS; + if (iconv(self->conv, (char**)&in_str, &inbytes, &out_str, &outbytes) == (size_t)-1) { +#if 0 + // at this point both gbk_str & inbytes have been modified, prefer original + // values: + dump2file(str, len); + printf("[%.*s]", (int)len, str); + fflush(stdout); +#endif + assert(strlen(in_str) <= 3); + if (is_valid_utf8(str)) { + utype = kUTF8; + strcpy(dest_str, str); + return utype; + } else { + self->conv = iconv_open("utf-8", "euc-jp"); + in_str = str; + size_t ret = iconv(self->conv, (char**)&in_str, &inbytes, &out_str, &outbytes); + assert(ret != (size_t)-1); + iconv_close(self->conv); + utype = kEUC_JP; + self->conv = iconv_open("utf-8", "shift-jis"); + } + } else + { + assert(inbytes==0); + // assert(is_ascii_string_with_trailing_nulls(str, len)!=(size_t)-1); + } + dest_str[guesstimate - outbytes] = 0; +#else + (void)str; + utype = kError; + // guesstimate imply at least 128 bytes: + strcpy(dest_str, "No iconv support"); +#endif + assert(is_valid_utf8(dest_str)); + return utype; +} + static bool write_trailer(struct app *self) { assert(self->in->cur <= self->in->end); if (self->in->cur == self->in->end) return true; // else it is missing one byte (nul byte): char padding; - size_t s = fread_mirror(&padding, sizeof padding, 1, self); + const size_t s = fread_mirror(&padding, sizeof padding, 1, self); ERROR_RETURN(s, 1); ERROR_RETURN(padding, 0); @@ -126,8 +299,9 @@ static const uint32_t magic2[] = {0, 0, 12, 0, 0}; static bool read_info(struct app *self, const uint8_t group, struct mec_mr3_info *info) { + (void)group; // read key and type at once: - size_t s = fread_mirror(info, sizeof *info, 1, self); + const size_t s = fread_mirror(info, sizeof *info, 1, self); ERROR_RETURN(s, 1); #ifdef MEC_MR3_IO_DEBUG bool found = check_mec_mr3_info(group, info->key, info->type); @@ -149,8 +323,7 @@ static void *aligned_alloc_impl(size_t alignment, size_t size) { #endif } -static struct mec_mr3_item_data *mec_mr3_aligned_realloc( - struct mec_mr3_item_data *data, size_t size) { +static struct mec_mr3_item_data *mec_mr3_aligned_realloc(struct mec_mr3_item_data *data, const size_t size) { if (!data) return NULL; // fast path if (size <= data->size) { @@ -166,7 +339,7 @@ static struct mec_mr3_item_data *mec_mr3_aligned_realloc( return data; } -static bool is_aligned(const void *pointer, size_t byte_count) { +static bool is_aligned(const void *pointer, const size_t byte_count) { // https://stackoverflow.com/questions/1898153/how-to-determine-if-memory-is-aligned return (uintptr_t)pointer % byte_count == 0; } @@ -210,19 +383,15 @@ static bool read_data(struct app *self, const uint8_t group, } enum Type { - ISO_8859_1_STRING = - 0x00000300, // ASCII string / or struct with 'ISO-8859-1' marker + ISO_8859_1_STRING = 0x00000300, // ASCII string / or struct with 'ISO-8859-1' marker FLOAT32_VM2N = 0x00000500, // float/32bits VM:2n FLOAT32_VM3N = 0x00000600, // float/32bits VM:3n DATETIME = 0x00000e00, // Date/Time stored as ASCII VM:1 - STRUCT_136 = - 0x001f4100, // Fixed struct 136 bytes (struct with ASCII strings) - STRUCT_436 = - 0x001f4300, // Fixed struct 436 bytes (struct with ASCII strings) - STRUCT_516 = - 0x001f4400, // Fixed struct 516 bytes (struct with ASCII strings) - STRUCT_325 = - 0x001f4600, // Fixed struct 325 bytes (struct with ASCII strings) + STR40 = 0x001f4000, // SHIFT-JIS strings x 7 + STRUCT_136 = 0x001f4100, // Fixed struct 136 bytes (struct with ASCII strings) + STRUCT_436 = 0x001f4300, // Fixed struct 436 bytes (struct with ASCII strings) + STRUCT_516 = 0x001f4400, // Fixed struct 516 bytes (struct with ASCII strings) + STRUCT_325 = 0x001f4600, // Fixed struct 325 bytes (struct with ASCII strings) UINT32_VM1 = (int)0xff000400, // uint32_t, range [0, 4] VM:1 FLOAT32_VM1 = (int)0xff000800, // float/32bits VM:1 INT32_VM1N = (int)0xff002400, // int32_t (signed) VM:1n @@ -230,6 +399,7 @@ enum Type { FLOAT64_VM1 = (int)0xff002900, // float/64bits VM:1 BOOL32_VM1 = (int)0xff002a00, // bool/32bits VM:1 UNICODE_STRING = (int)0xff002c00, // ASCII, UTF-8 or SHIFT-JIS string + CHARACTER_SET = (int)0xff002300, // 17f2 seems to store the character set used }; struct buffer19 { @@ -244,153 +414,9 @@ struct buffer19 { char sig5; }; -#if 0 -static void dump2file(const char *in, int len) { - static int debug = 0; - char buffer[512]; - sprintf(buffer, "out%04d", debug); - ++debug; - FILE *f = fopen(buffer, "wb"); - fwrite(in, 1, len, f); - fclose(f); -} -#endif - -// https://stackoverflow.com/questions/28270310/how-to-easily-detect-utf8-encoding-in-the-string -static bool is_valid_utf8(const char *string) { - if (!string) return true; - - const unsigned char *bytes = (const unsigned char *)string; - unsigned int cp; - int num; - - while (*bytes != 0x00) { - if ((*bytes & 0x80) == 0x00) { - // U+0000 to U+007F - cp = (*bytes & 0x7F); - num = 1; - } else if ((*bytes & 0xE0) == 0xC0) { - // U+0080 to U+07FF - cp = (*bytes & 0x1F); - num = 2; - } else if ((*bytes & 0xF0) == 0xE0) { - // U+0800 to U+FFFF - cp = (*bytes & 0x0F); - num = 3; - } else if ((*bytes & 0xF8) == 0xF0) { - // U+10000 to U+10FFFF - cp = (*bytes & 0x07); - num = 4; - } else - return false; - - bytes += 1; - for (int i = 1; i < num; ++i) { - if ((*bytes & 0xC0) != 0x80) return false; - cp = (cp << 6) | (*bytes & 0x3F); - bytes += 1; - } - - if ((cp > 0x10FFFF) || ((cp >= 0xD800) && (cp <= 0xDFFF)) || - ((cp <= 0x007F) && (num != 1)) || - ((cp >= 0x0080) && (cp <= 0x07FF) && (num != 2)) || - ((cp >= 0x0800) && (cp <= 0xFFFF) && (num != 3)) || - ((cp >= 0x10000) && (cp <= 0x1FFFFF) && (num != 4))) - return false; - } - - return true; -} - -// return -1 to indicate error: -static int remove_control_character_utf8(char *string) { - if (!string) return 0; - - unsigned char *bytes = (unsigned char *)string; - unsigned int cp; - int num; - int modified = 0; - - while (*bytes != 0x00) { - if ((*bytes & 0x80) == 0x00) { - // U+0000 to U+007F - cp = (*bytes & 0x7F); - num = 1; - } else if ((*bytes & 0xE0) == 0xC0) { - // U+0080 to U+07FF - cp = (*bytes & 0x1F); - num = 2; - } else if ((*bytes & 0xF0) == 0xE0) { - // U+0800 to U+FFFF - cp = (*bytes & 0x0F); - num = 3; - } else if ((*bytes & 0xF8) == 0xF0) { - // U+10000 to U+10FFFF - cp = (*bytes & 0x07); - num = 4; - } else - return -1; - - bytes += 1; - for (int i = 1; i < num; ++i) { - if ((*bytes & 0xC0) != 0x80) return -1; - cp = (cp << 6) | (*bytes & 0x3F); - bytes += 1; - } - - if ((cp > 0x10FFFF) || ((cp >= 0xD800) && (cp <= 0xDFFF)) || - ((cp <= 0x007F) && (num != 1)) || - ((cp >= 0x0080) && (cp <= 0x07FF) && (num != 2)) || - ((cp >= 0x0800) && (cp <= 0xFFFF) && (num != 3)) || - ((cp >= 0x10000) && (cp <= 0x1FFFFF) && (num != 4))) - return -1; - - if (cp <= 0x001F && num == 1) { - bytes[-1] = '.'; - modified++; - } else if (cp == 0x007F && num == 1) { - bytes[-1] = '?'; - modified++; - } - } - - return modified; -} - -static char *shift_jis_to_utf8(char *str, size_t len, struct app *self) { - if (len == 0) { - return ""; - } - const size_t guesstimate = len < 128 ? 128 : len * 2; - self->shift_jis_buffer = realloc(self->shift_jis_buffer, guesstimate); - char *dest_str = self->shift_jis_buffer; -#if GDCM_HAS_ICONV - char *in_str = str; - char *out_str = dest_str; - size_t inbytes = len; - size_t outbytes = guesstimate; - if (iconv(self->conv, &in_str, &inbytes, &out_str, &outbytes) == (size_t)-1) { -#if 0 - // at this point both gbk_str & inbytes have been modified, prefer original - // values: - dump2file(str, len); - printf("[%.*s]", (int)len, str); - fflush(stdout); -#endif - return NULL; - } - dest_str[guesstimate - outbytes] = 0; -#else - // guesstimate imply at least 128 bytes: - strcpy(dest_str, "No iconv support"); -#endif - assert(is_valid_utf8(dest_str)); - return dest_str; -} - static bool print_iso(void *ptr, size_t size, size_t nmemb, struct app *self) { assert(size == 1); - static const char magic[] = {0xdf, 0xff, 0x79}; + static const unsigned char magic[] = {0xdf, 0xff, 0x79}; if (nmemb >= sizeof magic && memcmp(ptr, magic, sizeof(magic)) == 0) { // iso struct buffer19 b19; @@ -402,13 +428,12 @@ static bool print_iso(void *ptr, size_t size, size_t nmemb, struct app *self) { const size_t diff = nmemb - sizeof b19; if (b19.len2 != nmemb - 4 || b19.len3 != 9 || b19.len4 != diff) return 0; if (strncmp(b19.iso, "ISO8859-1", 9) != 0) return 0; - char *str = (char *)ptr + sizeof b19; { - char *dest_str = shift_jis_to_utf8(str, b19.len4, self); - assert(dest_str != NULL); - const int modified = remove_control_character_utf8(dest_str); - assert(modified == 0); - printf("{%.*s : %s}", 9, b19.iso, dest_str); + const char *str = (char *)ptr + sizeof b19; + const int unicode_format = guess_unicode_and_convert(self, str, b19.len4); + assert(unicode_format == kSHIFT_JIS); + const char *dest_str = self->shift_jis_buffer; + printf("{%.*s : %s:%s}", 9, b19.iso, unicode_type_as_string(unicode_format), dest_str); } } else { // raw string buffer @@ -439,10 +464,44 @@ static bool print_datetime(void *ptr, size_t size, size_t nmemb, typedef char str16[16 + 1]; typedef char str64[64 + 1]; +struct str40 { + uint32_t index; + char str[7][0x30]; +}; + +static bool print_str40(void *ptr, size_t size, size_t nmemb, + struct app *self) { + const size_t len = nmemb; + const char *buffer = ptr; + assert(size == 1); + assert(len % 340 == 0); + printf("{"); + size_t j; + for (j = 0; j < len / 340; ++j) { + struct str40 a; + assert(sizeof a == 340); + memcpy(&a, buffer + j * 340, sizeof a); + if (j) + printf(","); + printf("%u:[", a.index); + int i; + for (i = 0; i < 7; ++i) { + if (i) + printf(","); + const int unicode_format = guess_unicode_and_convert(self, a.str[i], sizeof a.str[i]); + const char *dest_str = self->shift_jis_buffer; + printf("%s:%s", unicode_type_as_string(unicode_format), dest_str); + } + printf("]"); + } + printf("}"); + + return true; +} + struct buffer136 { uint32_t zero1; - str64 - uid1; // Detached Study Management SOP Class (1.2.840.10008.3.1.2.3.1) ? + str64 uid1; // Detached Study Management SOP Class (1.2.840.10008.3.1.2.3.1) ? str64 uid2; // 1.2.840.113745.101000.1098000.X.Y.Z uint16_t zero2; }; @@ -450,20 +509,44 @@ struct buffer136 { void print_buffer136(struct buffer136 *b136) { assert(b136->zero1 == 0); assert(b136->zero2 == 0); + assert(65 == sizeof b136->uid1); + assert(65 == sizeof b136->uid2); + assert(is_ascii_string_with_trailing_nulls(b136->uid1, sizeof b136->uid1)!=(size_t)-1); + assert(is_ascii_string_with_trailing_nulls(b136->uid2, sizeof b136->uid2)!=(size_t)-1); printf("{%u,%s,%s,%hu}", b136->zero1, b136->uid1, b136->uid2, b136->zero2); } struct buffer436 { uint32_t zero; - char iver[0x45]; - char buf3[0x100]; // phi + char iver[16 + 1]; + char idate[8 + 1]; + char itime[6 + 1 + 6 + 1]; // eg. 113000.000000 + char junk[29]; + char buf3[0x100]; // phi str64 buf4; str16 buf5; - char modality[0x15]; + char modality[3]; + char junk2[21 - 3]; uint32_t val; }; static void print_buffer436(struct buffer436 *b436) { + assert(b436->zero == 0); + assert(is_ascii_string_with_trailing_nulls(b436->iver, sizeof b436->iver)!= (size_t)-1); + assert(is_ascii_string_with_trailing_nulls(b436->idate, sizeof b436->idate)!= (size_t)-1); + assert(is_ascii_string_with_trailing_nulls(b436->itime, sizeof b436->itime)!= (size_t)-1); + assert(*b436->junk == 0); + assert(is_ascii_string_with_trailing_nulls(b436->junk, sizeof b436->junk)!= (size_t)-1); + assert(is_ascii_string_with_trailing_nulls(b436->buf3, sizeof b436->buf3)!= (size_t)-1); +#if 0 + assert(is_ascii_string_with_trailing_nulls(b436->buf4, sizeof b436->buf4)); +#else + const int len4 = strnlen(b436->buf4, sizeof b436->buf4); +#endif + assert(is_ascii_string_with_trailing_nulls(b436->buf5, sizeof b436->buf5)!= (size_t)-1); + assert(is_ascii_string_with_trailing_nulls(b436->modality, + sizeof b436->modality)!= (size_t)-1); + assert(is_ascii_string_with_trailing_nulls(b436->junk2, sizeof b436->junk2)!= (size_t)-1); #if 0 static const char vers1[] = "TM_MR_DCM_V1.0"; static const char vers2[] = "TM_MR_DCM_V2.0"; @@ -472,13 +555,11 @@ static void print_buffer436(struct buffer436 *b436) { assert(strcmp(b436->iver, vers1) == 0 || strcmp(b436->iver, vers2) == 0 || strcmp(b436->iver, vers3) == 0 || strcmp(b436->iver, vers4) == 0); #endif - assert(b436->zero == 0); assert(strcmp(b436->modality, "MR") == 0); -#if 0 - assert(b436->val == 0 || b436->val == 1 || b436->val == 3 || b436->val == 4); -#endif - printf("{%u;%s;%s;%s;%s;%s;%u}", b436->zero, b436->iver, b436->buf3, - b436->buf4, b436->buf5, b436->modality, b436->val); + assert(b436->val == 0 || b436->val == 1 || b436->val == 3 || b436->val == 4 || b436->val == 6 ); + printf("{%u;%s;%s;%s;%s;%.*s;%s;%s;%s;%u}", b436->zero, b436->iver, + b436->idate, b436->itime, b436->buf3, len4, b436->buf4, b436->buf5, + b436->modality, b436->junk2, b436->val); } struct buffer516 { @@ -492,8 +573,18 @@ struct buffer516 { }; static void print_buffer516(struct buffer516 *b516) { - printf("{%s;%s;%s;%s;%s;%s", b516->zero, b516->buf2, b516->buf3, b516->buf4, - b516->buf5, b516->buf6); + assert(is_ascii_string_with_trailing_nulls(b516->zero, sizeof b516->zero)!= (size_t)-1); + assert(is_ascii_string_with_trailing_nulls(b516->buf2, sizeof b516->buf2)!= (size_t)-1); + assert(is_ascii_string_with_trailing_nulls(b516->buf3, sizeof b516->buf3)!= (size_t)-1); + assert(is_ascii_string_with_trailing_nulls(b516->buf4, sizeof b516->buf4)!= (size_t)-1); + assert(is_ascii_string_with_trailing_nulls(b516->buf5, sizeof b516->buf5)!= (size_t)-1); +#if 0 + assert(is_ascii_string_with_trailing_nulls(b516->buf6, sizeof b516->buf6)); +#else + const int len6 = strnlen(b516->buf6, sizeof b516->buf6); +#endif + printf("{%s;%s;%s;%s;%s;%.*s", b516->zero, b516->buf2, b516->buf3, b516->buf4, + b516->buf5, len6, b516->buf6); uint32_t c; for (c = 0; c < 6; ++c) { assert(b516->bools[c] == c % 2); @@ -514,6 +605,8 @@ static void print_buffer325(struct buffer325 *b325) { int c; printf("{"); for (c = 0; c < 5; ++c) { + assert(is_ascii_string_with_trailing_nulls(b325->array[c], + sizeof b325->array[c])!= (size_t)-1); if (c) printf(";"); printf("%s", b325->array[c]); } @@ -548,27 +641,14 @@ static bool print_struct(void *ptr, size_t size, size_t nmemb, return true; } -static bool print_shift_jis(void *ptr, size_t size, size_t nmemb, +static bool print_unicode(void *ptr, size_t size, size_t nmemb, struct app *self) { assert(size == 1); - char *dest_str = shift_jis_to_utf8(ptr, nmemb, self); - if (dest_str) { - const int modified = remove_control_character_utf8(dest_str); - assert(modified >= 0); - printf("|%sSJIS| \"%s\"", modified > 0 ? "?-" : "", dest_str); - } else { - char *str = ptr; - const size_t len = strlen(str); - assert(len == nmemb || (len + 1 == nmemb && str[len] == 0)); - const bool ok = is_valid_utf8(str); - if (ok) { - const int modified = remove_control_character_utf8(str); - assert(modified >= 0); - printf("|%sUTF-8| \"%s\"", modified > 0 ? "?-" : "", str); - } else { - printf("|FIXME: Invalid SHIFT-JIS/UTF-8|"); - } - } + const char *str = ptr; + const int unicode_format = guess_unicode_and_convert(self, str, nmemb); + assert(unicode_format == kSHIFT_JIS || unicode_format == kUTF8); + const char *dest_str = self->shift_jis_buffer; + printf("[%s:%s]", unicode_type_as_string(unicode_format), dest_str); return true; } @@ -587,6 +667,25 @@ static void print_int(const int32_t *buffer, int len) { printf("]"); } +#if 0 +static void print_uint(const uint32_t *buffer, int len) { + const int m = sizeof(uint32_t); + assert(is_aligned(buffer, m)); + assert(len % m == 0); + int i; + printf("["); + for (i = 0; i < len / m; i++) { + if (i) + printf(","); + uint32_t cur = (uint32_t)-1; + memcpy(&cur, buffer + i, sizeof cur); + assert(cur == 0x0 || cur == 0x1 || cur == 0x4); + printf("%u", cur); + } + printf("]"); +} +#endif + static void print_float(const float *buffer, int len) { const int m = sizeof(float); assert(is_aligned(buffer, m)); @@ -630,6 +729,25 @@ static bool print_int32(void *ptr, size_t size, size_t nmemb, return true; } +static bool print_uint32(void *ptr, size_t size, size_t nmemb, + struct app *self) { + assert(size == 1); + assert(is_aligned(ptr, 4)); + (void)self; +#if 0 + assert(nmemb % 4 == 0); + print_uint(ptr, nmemb); +#else + assert(nmemb == 4); + uint32_t u; + memcpy(&u, ptr, nmemb); + assert(u == 0x0 || u == 0x1 || u == 0x4); + printf("%u", u); +#endif + + return true; +} + static bool print_float32(void *ptr, size_t size, size_t nmemb, struct app *self) { assert(size == 1); @@ -655,7 +773,8 @@ static bool print_float32_vm2n(void *ptr, size_t size, size_t nmemb, assert(size == 1); (void)self; assert((nmemb / 4) % 2 == 0); - assert(nmemb == 8 || nmemb == 40 || nmemb == 80 || nmemb == 88); + assert(nmemb == 8 || nmemb == 40 || nmemb == 80 || nmemb == 72 || + nmemb == 88 || nmemb == 64); // FIXME: low/high value for nmemb==40&80 makes them look like double... print_float(ptr, nmemb); @@ -682,19 +801,6 @@ static bool print_float64(void *ptr, size_t size, size_t nmemb, return true; } -static bool print_uint32(void *ptr, size_t size, size_t nmemb, - struct app *self) { - assert(size == 1); - assert(is_aligned(ptr, 4)); - (void)self; - assert(nmemb == 4); - uint32_t u; - memcpy(&u, ptr, nmemb); - assert(u == 0x0 || u == 0x1 || u == 0x4); - printf("%u", u); - return true; -} - static bool print_bool32(void *ptr, size_t size, size_t nmemb, struct app *self) { assert(size == 1); @@ -722,53 +828,62 @@ static bool print(struct app *self, const uint8_t group, (info->type & 0x00ffff00) >> 8); // print data: switch (info->type) { - case ISO_8859_1_STRING: - ret = print_iso(data->buffer, 1, data->len, self); - break; - case FLOAT32_VM2N: - ret = print_float32_vm2n(data->buffer, 1, data->len, self); - break; - case FLOAT32_VM3N: - ret = print_float32_vm3n(data->buffer, 1, data->len, self); - break; - case DATETIME: - ret = print_datetime(data->buffer, 1, data->len, self); - break; - case STRUCT_136: - case STRUCT_436: - case STRUCT_516: - case STRUCT_325: - ret = print_struct(data->buffer, 1, data->len, self); - break; - case UNICODE_STRING: - ret = print_shift_jis(data->buffer, 1, data->len, self); - break; - case FLOAT32_VM1: - ret = print_float32(data->buffer, 1, data->len, self); - break; - case INT32_VM1N: - ret = print_int32(data->buffer, 1, data->len, self); - break; - case FLOAT32_VM1N: - ret = print_float32_vm1n(data->buffer, 1, data->len, self); - break; - case FLOAT64_VM1: - ret = print_float64(data->buffer, 1, data->len, self); - break; - case UINT32_VM1: - ret = print_uint32(data->buffer, 1, data->len, self); - break; - case BOOL32_VM1: - ret = print_bool32(data->buffer, 1, data->len, self); - break; - default: - printf("|NotImplemented|"); - ret = true; + case ISO_8859_1_STRING: + ret = print_iso(data->buffer, 1, data->len, self); + break; + case FLOAT32_VM2N: + ret = print_float32_vm2n(data->buffer, 1, data->len, self); + break; + case FLOAT32_VM3N: + ret = print_float32_vm3n(data->buffer, 1, data->len, self); + break; + case DATETIME: + ret = print_datetime(data->buffer, 1, data->len, self); + break; + case STR40: + ret = print_str40(data->buffer, 1, data->len, self); + break; + case STRUCT_136: + case STRUCT_436: + case STRUCT_516: + case STRUCT_325: + ret = print_struct(data->buffer, 1, data->len, self); + break; + case UNICODE_STRING: + ret = print_unicode(data->buffer, 1, data->len, self); + break; + case FLOAT32_VM1: + ret = print_float32(data->buffer, 1, data->len, self); + break; + case INT32_VM1N: + ret = print_int32(data->buffer, 1, data->len, self); + break; + case FLOAT32_VM1N: + ret = print_float32_vm1n(data->buffer, 1, data->len, self); + break; + case FLOAT64_VM1: + ret = print_float64(data->buffer, 1, data->len, self); + break; + case UINT32_VM1: + ret = print_uint32(data->buffer, 1, data->len, self); + break; + case BOOL32_VM1: + ret = print_bool32(data->buffer, 1, data->len, self); + break; + case CHARACTER_SET: +#if 0 + dump2file(data->buffer, data->len); +#endif + ret = true; + break; + default: + printf("|NotImplemented|"); + ret = true; } // print key name if (!name) { static char buf[512]; - snprintf(buf, sizeof buf, "Missing: {0x%02x, 0x%08x, 0x%08x, \"\"}, //", + (void)snprintf(buf, sizeof buf, "Missing: {0x%02x, 0x%08x, 0x%08x, \"\"}, //", group, info->key, info->type); name = buf; } @@ -791,11 +906,10 @@ static bool read_group(struct app *self, uint8_t group, uint32_t nitems, return good; } -// If the number of element read is below the magic value, this indicate the -// last groups of elements: -#define MAGIC_NUM_ELEMENTS 5 +// If we reach group #5, we have to handle the remaining groups magic: +#define MAGIC_GROUP_NUMBER 5 -bool mec_mr3_print(const void *input, size_t len) { +bool mec_mr3_print(const void *input, const size_t len) { if (!input) return false; struct stream sin; struct app a; @@ -819,7 +933,7 @@ bool mec_mr3_print(const void *input, size_t len) { if (s != 1 || nitems == 0) { good = false; } - if (good && nitems <= MAGIC_NUM_ELEMENTS) { + if (good && group == MAGIC_GROUP_NUMBER) { // special case to handle last groups remain = nitems; last_groups = true; @@ -836,7 +950,7 @@ bool mec_mr3_print(const void *input, size_t len) { while (good && --remain != 0) { uint32_t nitems; s = fread_mirror(&nitems, sizeof nitems, 1, self); - if (s != 1 || nitems <= MAGIC_NUM_ELEMENTS) { + if (s != 1) { good = false; } ++group; @@ -848,7 +962,7 @@ bool mec_mr3_print(const void *input, size_t len) { #else free(data.buffer); #endif -#if GDCM_HAS_ICONV +#if MEC3_HAS_ICONV iconv_close(self->conv); #endif free(self->shift_jis_buffer); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.h index 1e13853a818..fe07848b097 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmext/mec_mr3_io.h @@ -27,4 +27,4 @@ bool mec_mr3_print(const void *input, size_t len); } /* end extern "C" */ #endif -#endif // MEC_MR3_IO_H +#endif // MEC_MR3_IO_H diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmjpeg/CMakeLists.txt b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmjpeg/CMakeLists.txt index d1649f3c6cc..023f9ce306f 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmjpeg/CMakeLists.txt +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmjpeg/CMakeLists.txt @@ -1,5 +1,5 @@ if(NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION) - cmake_minimum_required(VERSION 2.8.7) + cmake_minimum_required(VERSION 2.8.7...${GDCM_MAX_VALIDATED_CMAKE_VERSION}) endif() if(NOT JPEG_NAMESPACE) @@ -17,14 +17,6 @@ string(TOLOWER ${JPEG_NAMESPACE} JPEG_LIBRARY_NAME) project(${JPEG_NAMESPACE} C) -foreach(p - CMP0042 - CMP0063 - ) - if(POLICY ${p}) - cmake_policy(SET ${p} NEW) - endif() -endforeach() # Do full dependency headers. include_regular_expression("^.*$") diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmmd5/CMakeLists.txt b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmmd5/CMakeLists.txt index 176887694dd..8bbef0f428e 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmmd5/CMakeLists.txt +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmmd5/CMakeLists.txt @@ -1,5 +1,5 @@ if(NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION) - cmake_minimum_required(VERSION 2.8.7) + cmake_minimum_required(VERSION 2.8.7...${GDCM_MAX_VALIDATED_CMAKE_VERSION}) endif() if(NOT MD5_NAMESPACE) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/CMakeLists.txt b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/CMakeLists.txt index c4544a7a16e..cd8eecddb21 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/CMakeLists.txt +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/CMakeLists.txt @@ -8,23 +8,7 @@ # e.g.: # set(OPENJPEG_NAMESPACE "GDCMOPENJPEG") if(NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION) - cmake_minimum_required(VERSION 2.8.2) -endif() - -if(COMMAND CMAKE_POLICY) - cmake_policy(SET CMP0003 NEW) - if (NOT (${CMAKE_VERSION} VERSION_LESS 3.0)) - cmake_policy(SET CMP0042 NEW) - endif() - - foreach(p - CMP0042 - CMP0063 - ) - if(POLICY ${p}) - cmake_policy(SET ${p} NEW) - endif() - endforeach() + cmake_minimum_required(VERSION 2.8.2...${GDCM_MAX_VALIDATED_CMAKE_VERSION}) endif() if(NOT OPENJPEG_NAMESPACE) @@ -166,9 +150,15 @@ if(NOT OPENJPEG_INSTALL_PACKAGE_DIR) endif() if (APPLE) - list(APPEND OPENJPEG_LIBRARY_PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${OPENJPEG_INSTALL_LIB_DIR}") - option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF) - mark_as_advanced(OPJ_USE_DSYMUTIL) + if (${CMAKE_VERSION} VERSION_LESS 3.0) + # For cmake >= 3.0, we turn on CMP0042 and + # https://cmake.org/cmake/help/v3.0/policy/CMP0042.html mentions + # "Projects wanting @rpath in a target’s install name may remove any + # setting of the INSTALL_NAME_DIR and CMAKE_INSTALL_NAME_DIR variables" + list(APPEND OPENJPEG_LIBRARY_PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${OPENJPEG_INSTALL_LIB_DIR}") + endif() + option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF) + mark_as_advanced(OPJ_USE_DSYMUTIL) endif() #----------------------------------------------------------------------------- diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/README.GDCM.txt b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/README.GDCM.txt index f6fc570266c..c8b298305ae 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/README.GDCM.txt +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/README.GDCM.txt @@ -1,9 +1,6 @@ This directory contains a subset of the OpenJPEG project (https://github.com/uclouvain/openjpeg/) -It was retrieved on Wed Mar 20 16:01:08 2019 +0100 -URL: -https://github.com/uclouvain/openjpeg/archive/v2.3.0.tar.gz -This is the 2.3.0 Release +It was retrieved on December 2024 from tag v2.5.3. Project Description OpenJPEG is an open-source JPEG 2000 codec written in C language. It has been diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/CMakeLists.txt b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/CMakeLists.txt index c4adb91a223..8665dbf7d39 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/CMakeLists.txt +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/CMakeLists.txt @@ -28,6 +28,7 @@ set(OPENJPEG_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/dwt.h ${CMAKE_CURRENT_SOURCE_DIR}/event.c ${CMAKE_CURRENT_SOURCE_DIR}/event.h + ${CMAKE_CURRENT_SOURCE_DIR}/ht_dec.c ${CMAKE_CURRENT_SOURCE_DIR}/image.c ${CMAKE_CURRENT_SOURCE_DIR}/image.h ${CMAKE_CURRENT_SOURCE_DIR}/invert.c @@ -62,7 +63,6 @@ set(OPENJPEG_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/opj_intmath.h ${CMAKE_CURRENT_SOURCE_DIR}/opj_malloc.c ${CMAKE_CURRENT_SOURCE_DIR}/opj_malloc.h - ${CMAKE_CURRENT_SOURCE_DIR}/opj_stdint.h ${CMAKE_CURRENT_SOURCE_DIR}/sparse_array.c ${CMAKE_CURRENT_SOURCE_DIR}/sparse_array.h ) @@ -91,37 +91,28 @@ if(NOT WIN32 AND CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER MATCHES ".*mingw32 endif() # Build the library +add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS}) +set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME}) if(WIN32) if(BUILD_SHARED_LIBS) - add_definitions(-DOPJ_EXPORTS) + target_compile_definitions(${OPENJPEG_LIBRARY_NAME} PRIVATE OPJ_EXPORTS) else() - add_definitions(-DOPJ_STATIC) - endif() - add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS}) - set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME}) -else() - if(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS) - # Builds both static and dynamic libs - add_library(${OPENJPEG_LIBRARY_NAME} SHARED ${OPENJPEG_SRCS}) - add_library(openjp2_static STATIC ${OPENJPEG_SRCS}) - set_target_properties(openjp2_static PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME}) - target_compile_definitions(openjp2_static PRIVATE OPJ_STATIC ) - set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME} openjp2_static) - else() - add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS}) - endif() - if(NOT BUILD_SHARED_LIBS) - target_compile_definitions(${OPENJPEG_LIBRARY_NAME} PRIVATE OPJ_STATIC ) + target_compile_definitions(${OPENJPEG_LIBRARY_NAME} PUBLIC OPJ_STATIC) endif() +elseif(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS) + # Builds both static and dynamic libs + add_library(openjp2_static STATIC ${OPENJPEG_SRCS}) + set_target_properties(openjp2_static PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME}) + list(APPEND INSTALL_LIBS openjp2_static) + target_include_directories(openjp2_static PUBLIC $) endif() +#target_include_directories(${OPENJPEG_LIBRARY_NAME} PUBLIC $) if(UNIX) target_link_libraries(${OPENJPEG_LIBRARY_NAME} m) endif() set_target_properties(${OPENJPEG_LIBRARY_NAME} PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES}) -if(${CMAKE_VERSION} VERSION_GREATER "2.8.11") - target_compile_options(${OPENJPEG_LIBRARY_NAME} PRIVATE ${OPENJP2_COMPILE_OPTIONS}) -endif() +target_compile_options(${OPENJPEG_LIBRARY_NAME} PRIVATE ${OPENJP2_COMPILE_OPTIONS}) # Install library install(TARGETS ${OPENJPEG_LIBRARY_NAME} @@ -132,7 +123,7 @@ install(TARGETS ${OPENJPEG_LIBRARY_NAME} ) # Install includes files -install(FILES openjpeg.h opj_stdint.h +install(FILES openjpeg.h DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers ) @@ -144,9 +135,9 @@ install( endif() if(BUILD_LUTS_GENERATOR) -# internal utility to generate t1_luts.h (part of the jp2 lib) +# internal utility to generate t1_luts.h and t1_ht_luts.h (part of the jp2 lib) # no need to install: - add_executable(t1_generate_luts t1_generate_luts.c) + add_executable(t1_generate_luts t1_generate_luts.c t1_ht_generate_luts.c) if(UNIX) target_link_libraries(t1_generate_luts m) endif() @@ -211,7 +202,7 @@ if(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT) TARGET_LINK_LIBRARIES(${OPENJPEG_LIBRARY_NAME} ${CMAKE_THREAD_LIBS_INIT}) endif(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT) -if(BUILD_UNIT_TESTS) +if(BUILD_UNIT_TESTS AND UNIX) add_executable(bench_dwt bench_dwt.c) if(UNIX) target_link_libraries(bench_dwt m ${OPENJPEG_LIBRARY_NAME}) @@ -227,4 +218,4 @@ if(BUILD_UNIT_TESTS) if(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT) target_link_libraries(test_sparse_array ${CMAKE_THREAD_LIBS_INIT}) endif(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT) -endif(BUILD_UNIT_TESTS) +endif(BUILD_UNIT_TESTS AND UNIX) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/bio.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/bio.c index 09dcd7f5249..8106df754ed 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/bio.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/bio.c @@ -43,12 +43,6 @@ /** @name Local static functions */ /*@{*/ -/** -Write a bit -@param bio BIO handle -@param b Bit to write (0 or 1) -*/ -static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b); /** Read a bit @param bio BIO handle @@ -100,16 +94,6 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) return OPJ_TRUE; } -static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) -{ - if (bio->ct == 0) { - opj_bio_byteout( - bio); /* MSD: why not check the return value of this function ? */ - } - bio->ct--; - bio->buf |= b << bio->ct; -} - static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) { if (bio->ct == 0) { @@ -162,6 +146,16 @@ void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) bio->ct = 0; } +void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) +{ + if (bio->ct == 0) { + opj_bio_byteout( + bio); /* MSD: why not check the return value of this function ? */ + } + bio->ct--; + bio->buf |= b << bio->ct; +} + void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n) { OPJ_INT32 i; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/bio.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/bio.h index 448fdda2190..d482f9ead5a 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/bio.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/bio.h @@ -106,6 +106,14 @@ Write bits @param n Number of bits to write */ void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n); + +/** +Write a bit +@param bio BIO handle +@param b Bit to write (0 or 1) +*/ +void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b); + /** Read bits @param bio BIO handle diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/cio.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/cio.h index 6996a9a0a11..7caee30af9c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/cio.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/cio.h @@ -118,7 +118,7 @@ typedef struct opj_stream_private { opj_stream_seek_fn m_seek_fn; /** - * Actual data stored into the stream if readed from. Data is read by chunk of fixed size. + * Actual data stored into the stream if read from. Data is read by chunk of fixed size. * you should never access this data directly. */ OPJ_BYTE * m_stored_data; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/dwt.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/dwt.c index 5b98d2b3805..11aae472def 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/dwt.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/dwt.c @@ -52,7 +52,7 @@ #ifdef __SSSE3__ #include #endif -#ifdef __AVX2__ +#if (defined(__AVX2__) || defined(__AVX512F__)) #include #endif @@ -66,7 +66,10 @@ #define OPJ_WS(i) v->mem[(i)*2] #define OPJ_WD(i) v->mem[(1+(i)*2)] -#ifdef __AVX2__ +#if defined(__AVX512F__) +/** Number of int32 values in a AVX512 register */ +#define VREG_INT_COUNT 16 +#elif defined(__AVX2__) /** Number of int32 values in a AVX2 register */ #define VREG_INT_COUNT 8 #else @@ -87,12 +90,14 @@ typedef struct dwt_local { OPJ_INT32 cas; /* 0 = start on even coord, 1 = start on odd coord */ } opj_dwt_t; +#define NB_ELTS_V8 8 + typedef union { - OPJ_FLOAT32 f[4]; -} opj_v4_t; + OPJ_FLOAT32 f[NB_ELTS_V8]; +} opj_v8_t; -typedef struct v4dwt_local { - opj_v4_t* wavelet ; +typedef struct v8dwt_local { + opj_v8_t* wavelet ; OPJ_INT32 dn ; /* number of elements in high pass band */ OPJ_INT32 sn ; /* number of elements in low pass band */ OPJ_INT32 cas ; /* 0 = start on even coord, 1 = start on odd coord */ @@ -100,45 +105,34 @@ typedef struct v4dwt_local { OPJ_UINT32 win_l_x1; /* end coord in low pass band */ OPJ_UINT32 win_h_x0; /* start coord in high pass band */ OPJ_UINT32 win_h_x1; /* end coord in high pass band */ -} opj_v4dwt_t ; +} opj_v8dwt_t ; -static const OPJ_FLOAT32 opj_dwt_alpha = 1.586134342f; /* 12994 */ -static const OPJ_FLOAT32 opj_dwt_beta = 0.052980118f; /* 434 */ -static const OPJ_FLOAT32 opj_dwt_gamma = -0.882911075f; /* -7233 */ -static const OPJ_FLOAT32 opj_dwt_delta = -0.443506852f; /* -3633 */ +/* From table F.4 from the standard */ +static const OPJ_FLOAT32 opj_dwt_alpha = -1.586134342f; +static const OPJ_FLOAT32 opj_dwt_beta = -0.052980118f; +static const OPJ_FLOAT32 opj_dwt_gamma = 0.882911075f; +static const OPJ_FLOAT32 opj_dwt_delta = 0.443506852f; -static const OPJ_FLOAT32 opj_K = 1.230174105f; /* 10078 */ -static const OPJ_FLOAT32 opj_c13318 = 1.625732422f; +static const OPJ_FLOAT32 opj_K = 1.230174105f; +static const OPJ_FLOAT32 opj_invK = (OPJ_FLOAT32)(1.0 / 1.230174105); /*@}*/ -/** -Virtual function type for wavelet transform in 1-D -*/ -typedef void (*DWT1DFN)(const opj_dwt_t* v); - /** @name Local static functions */ /*@{*/ /** Forward lazy transform (horizontal) */ -static void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, +static void opj_dwt_deinterleave_h(const OPJ_INT32 * OPJ_RESTRICT a, + OPJ_INT32 * OPJ_RESTRICT b, + OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas); -/** -Forward lazy transform (vertical) -*/ -static void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, - OPJ_INT32 sn, OPJ_INT32 x, OPJ_INT32 cas); -/** -Forward 5-3 wavelet transform in 1-D -*/ -static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, - OPJ_INT32 cas); + /** Forward 9-7 wavelet transform in 1-D */ -static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, +static void opj_dwt_encode_1_real(void *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas); /** Explicit calculation of the Quantization Stepsizes @@ -155,8 +149,29 @@ static OPJ_BOOL opj_dwt_decode_partial_tile( opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres); -static OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec, - void (*p_function)(OPJ_INT32 *, OPJ_INT32, OPJ_INT32, OPJ_INT32)); +/* Forward transform, for the vertical pass, processing cols columns */ +/* where cols <= NB_ELTS_V8 */ +/* Where void* is a OPJ_INT32* for 5x3 and OPJ_FLOAT32* for 9x7 */ +typedef void (*opj_encode_and_deinterleave_v_fnptr_type)( + void *array, + void *tmp, + OPJ_UINT32 height, + OPJ_BOOL even, + OPJ_UINT32 stride_width, + OPJ_UINT32 cols); + +/* Where void* is a OPJ_INT32* for 5x3 and OPJ_FLOAT32* for 9x7 */ +typedef void (*opj_encode_and_deinterleave_h_one_row_fnptr_type)( + void *row, + void *tmp, + OPJ_UINT32 width, + OPJ_BOOL even); + +static OPJ_BOOL opj_dwt_encode_procedure(opj_thread_pool_t* tp, + opj_tcd_tilecomp_t * tilec, + opj_encode_and_deinterleave_v_fnptr_type p_encode_and_deinterleave_v, + opj_encode_and_deinterleave_h_one_row_fnptr_type + p_encode_and_deinterleave_h_one_row); static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* OPJ_RESTRICT r, OPJ_UINT32 i); @@ -164,42 +179,6 @@ static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* OPJ_RESTRICT r, /* */ /* Inverse 9-7 wavelet transform in 1-D. */ /* */ -static void opj_v4dwt_decode(opj_v4dwt_t* OPJ_RESTRICT dwt); - -static void opj_v4dwt_interleave_h(opj_v4dwt_t* OPJ_RESTRICT dwt, - OPJ_FLOAT32* OPJ_RESTRICT a, - OPJ_UINT32 width, - OPJ_UINT32 remaining_height); - -static void opj_v4dwt_interleave_v(opj_v4dwt_t* OPJ_RESTRICT dwt, - OPJ_FLOAT32* OPJ_RESTRICT a, - OPJ_UINT32 width, - OPJ_UINT32 nb_elts_read); - -#ifdef __SSE__ -static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, - OPJ_UINT32 start, - OPJ_UINT32 end, - const __m128 c); - -static void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, - OPJ_UINT32 start, - OPJ_UINT32 end, - OPJ_UINT32 m, __m128 c); - -#else -static void opj_v4dwt_decode_step1(opj_v4_t* w, - OPJ_UINT32 start, - OPJ_UINT32 end, - const OPJ_FLOAT32 c); - -static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, - OPJ_UINT32 start, - OPJ_UINT32 end, - OPJ_UINT32 m, - OPJ_FLOAT32 c); - -#endif /*@}*/ @@ -246,12 +225,14 @@ static const OPJ_FLOAT64 opj_dwt_norms_real[4][10] = { /* */ /* Forward lazy transform (horizontal). */ /* */ -static void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, +static void opj_dwt_deinterleave_h(const OPJ_INT32 * OPJ_RESTRICT a, + OPJ_INT32 * OPJ_RESTRICT b, + OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { OPJ_INT32 i; - OPJ_INT32 * l_dest = b; - OPJ_INT32 * l_src = a + cas; + OPJ_INT32 * OPJ_RESTRICT l_dest = b; + const OPJ_INT32 * OPJ_RESTRICT l_src = a + cas; for (i = 0; i < sn; ++i) { *l_dest++ = *l_src; @@ -267,40 +248,13 @@ static void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, } } -/* */ -/* Forward lazy transform (vertical). */ -/* */ -static void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, - OPJ_INT32 sn, OPJ_INT32 x, OPJ_INT32 cas) -{ - OPJ_INT32 i = sn; - OPJ_INT32 * l_dest = b; - OPJ_INT32 * l_src = a + cas; - - while (i--) { - *l_dest = *l_src; - l_dest += x; - l_src += 2; - } /* b[i*x]=a[2*i+cas]; */ - - l_dest = b + (OPJ_SIZE_T)sn * (OPJ_SIZE_T)x; - l_src = a + 1 - cas; - - i = dn; - while (i--) { - *l_dest = *l_src; - l_dest += x; - l_src += 2; - } /*b[(sn+i)*x]=a[(2*i+1-cas)];*/ -} - #ifdef STANDARD_SLOW_VERSION /* */ /* Inverse lazy transform (horizontal). */ /* */ static void opj_dwt_interleave_h(const opj_dwt_t* h, OPJ_INT32 *a) { - OPJ_INT32 *ai = a; + const OPJ_INT32 *ai = a; OPJ_INT32 *bi = h->mem + h->cas; OPJ_INT32 i = h->sn; while (i--) { @@ -321,7 +275,7 @@ static void opj_dwt_interleave_h(const opj_dwt_t* h, OPJ_INT32 *a) /* */ static void opj_dwt_interleave_v(const opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) { - OPJ_INT32 *ai = a; + const OPJ_INT32 *ai = a; OPJ_INT32 *bi = v->mem + v->cas; OPJ_INT32 i = v->sn; while (i--) { @@ -341,37 +295,6 @@ static void opj_dwt_interleave_v(const opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) #endif /* STANDARD_SLOW_VERSION */ -/* */ -/* Forward 5-3 wavelet transform in 1-D. */ -/* */ -static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, - OPJ_INT32 cas) -{ - OPJ_INT32 i; - - if (!cas) { - if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ - for (i = 0; i < dn; i++) { - OPJ_D(i) -= (OPJ_S_(i) + OPJ_S_(i + 1)) >> 1; - } - for (i = 0; i < sn; i++) { - OPJ_S(i) += (OPJ_D_(i - 1) + OPJ_D_(i) + 2) >> 2; - } - } - } else { - if (!sn && dn == 1) { /* NEW : CASE ONE ELEMENT */ - OPJ_S(0) *= 2; - } else { - for (i = 0; i < dn; i++) { - OPJ_S(i) -= (OPJ_DD_(i) + OPJ_DD_(i - 1)) >> 1; - } - for (i = 0; i < sn; i++) { - OPJ_D(i) += (OPJ_SS_(i) + OPJ_SS_(i + 1) + 2) >> 2; - } - } - } -} - #ifdef STANDARD_SLOW_VERSION /* */ /* Inverse 5-3 wavelet transform in 1-D. */ @@ -411,6 +334,51 @@ static void opj_dwt_decode_1(const opj_dwt_t *v) #endif /* STANDARD_SLOW_VERSION */ +#if defined(__AVX512F__) +static int32_t loop_short_sse(int32_t len, const int32_t** lf_ptr, + const int32_t** hf_ptr, int32_t** out_ptr, + int32_t* prev_even) +{ + int32_t next_even; + __m128i odd, even_m1, unpack1, unpack2; + const int32_t batch = (len - 2) / 8; + const __m128i two = _mm_set1_epi32(2); + + for (int32_t i = 0; i < batch; i++) { + const __m128i lf_ = _mm_loadu_si128((__m128i*)(*lf_ptr + 1)); + const __m128i hf1_ = _mm_loadu_si128((__m128i*)(*hf_ptr)); + const __m128i hf2_ = _mm_loadu_si128((__m128i*)(*hf_ptr + 1)); + + __m128i even = _mm_add_epi32(hf1_, hf2_); + even = _mm_add_epi32(even, two); + even = _mm_srai_epi32(even, 2); + even = _mm_sub_epi32(lf_, even); + + next_even = _mm_extract_epi32(even, 3); + even_m1 = _mm_bslli_si128(even, 4); + even_m1 = _mm_insert_epi32(even_m1, *prev_even, 0); + + //out[0] + out[2] + odd = _mm_add_epi32(even_m1, even); + odd = _mm_srai_epi32(odd, 1); + odd = _mm_add_epi32(odd, hf1_); + + unpack1 = _mm_unpacklo_epi32(even_m1, odd); + unpack2 = _mm_unpackhi_epi32(even_m1, odd); + + _mm_storeu_si128((__m128i*)(*out_ptr + 0), unpack1); + _mm_storeu_si128((__m128i*)(*out_ptr + 4), unpack2); + + *prev_even = next_even; + + *out_ptr += 8; + *lf_ptr += 4; + *hf_ptr += 4; + } + return batch; +} +#endif + #if !defined(STANDARD_SLOW_VERSION) static void opj_idwt53_h_cas0(OPJ_INT32* tmp, const OPJ_INT32 sn, @@ -443,6 +411,145 @@ static void opj_idwt53_h_cas0(OPJ_INT32* tmp, if (!(len & 1)) { /* if len is even */ tmp[len - 1] = in_odd[(len - 1) / 2] + tmp[len - 2]; } +#else +#if defined(__AVX512F__) + OPJ_INT32* out_ptr = tmp; + int32_t prev_even = in_even[0] - ((in_odd[0] + 1) >> 1); + + const __m512i permutevar_mask = _mm512_setr_epi32( + 0x10, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, + 0x0c, 0x0d, 0x0e); + const __m512i store1_perm = _mm512_setr_epi64(0x00, 0x01, 0x08, 0x09, 0x02, + 0x03, 0x0a, 0x0b); + const __m512i store2_perm = _mm512_setr_epi64(0x04, 0x05, 0x0c, 0x0d, 0x06, + 0x07, 0x0e, 0x0f); + + const __m512i two = _mm512_set1_epi32(2); + + int32_t simd_batch_512 = (len - 2) / 32; + int32_t leftover; + + for (i = 0; i < simd_batch_512; i++) { + const __m512i lf_avx2 = _mm512_loadu_si512((__m512i*)(in_even + 1)); + const __m512i hf1_avx2 = _mm512_loadu_si512((__m512i*)(in_odd)); + const __m512i hf2_avx2 = _mm512_loadu_si512((__m512i*)(in_odd + 1)); + int32_t next_even; + __m512i duplicate, even_m1, odd, unpack1, unpack2, store1, store2; + + __m512i even = _mm512_add_epi32(hf1_avx2, hf2_avx2); + even = _mm512_add_epi32(even, two); + even = _mm512_srai_epi32(even, 2); + even = _mm512_sub_epi32(lf_avx2, even); + + next_even = _mm_extract_epi32(_mm512_extracti32x4_epi32(even, 3), 3); + + duplicate = _mm512_set1_epi32(prev_even); + even_m1 = _mm512_permutex2var_epi32(even, permutevar_mask, duplicate); + + //out[0] + out[2] + odd = _mm512_add_epi32(even_m1, even); + odd = _mm512_srai_epi32(odd, 1); + odd = _mm512_add_epi32(odd, hf1_avx2); + + unpack1 = _mm512_unpacklo_epi32(even_m1, odd); + unpack2 = _mm512_unpackhi_epi32(even_m1, odd); + + store1 = _mm512_permutex2var_epi64(unpack1, store1_perm, unpack2); + store2 = _mm512_permutex2var_epi64(unpack1, store2_perm, unpack2); + + _mm512_storeu_si512(out_ptr, store1); + _mm512_storeu_si512(out_ptr + 16, store2); + + prev_even = next_even; + + out_ptr += 32; + in_even += 16; + in_odd += 16; + } + + leftover = len - simd_batch_512 * 32; + if (leftover > 8) { + leftover -= 8 * loop_short_sse(leftover, &in_even, &in_odd, &out_ptr, + &prev_even); + } + out_ptr[0] = prev_even; + + for (j = 1; j < (leftover - 2); j += 2) { + out_ptr[2] = in_even[1] - ((in_odd[0] + (in_odd[1]) + 2) >> 2); + out_ptr[1] = in_odd[0] + ((out_ptr[0] + out_ptr[2]) >> 1); + in_even++; + in_odd++; + out_ptr += 2; + } + + if (len & 1) { + out_ptr[2] = in_even[1] - ((in_odd[0] + 1) >> 1); + out_ptr[1] = in_odd[0] + ((out_ptr[0] + out_ptr[2]) >> 1); + } else { //!(len & 1) + out_ptr[1] = in_odd[0] + out_ptr[0]; + } +#elif defined(__AVX2__) + OPJ_INT32* out_ptr = tmp; + int32_t prev_even = in_even[0] - ((in_odd[0] + 1) >> 1); + + const __m256i reg_permutevar_mask_move_right = _mm256_setr_epi32(0x00, 0x00, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06); + const __m256i two = _mm256_set1_epi32(2); + + int32_t simd_batch = (len - 2) / 16; + int32_t next_even; + __m256i even_m1, odd, unpack1_avx2, unpack2_avx2; + + for (i = 0; i < simd_batch; i++) { + const __m256i lf_avx2 = _mm256_loadu_si256((__m256i*)(in_even + 1)); + const __m256i hf1_avx2 = _mm256_loadu_si256((__m256i*)(in_odd)); + const __m256i hf2_avx2 = _mm256_loadu_si256((__m256i*)(in_odd + 1)); + + __m256i even = _mm256_add_epi32(hf1_avx2, hf2_avx2); + even = _mm256_add_epi32(even, two); + even = _mm256_srai_epi32(even, 2); + even = _mm256_sub_epi32(lf_avx2, even); + + next_even = _mm_extract_epi32(_mm256_extracti128_si256(even, 1), 3); + even_m1 = _mm256_permutevar8x32_epi32(even, reg_permutevar_mask_move_right); + even_m1 = _mm256_blend_epi32(even_m1, _mm256_set1_epi32(prev_even), (1 << 0)); + + //out[0] + out[2] + odd = _mm256_add_epi32(even_m1, even); + odd = _mm256_srai_epi32(odd, 1); + odd = _mm256_add_epi32(odd, hf1_avx2); + + unpack1_avx2 = _mm256_unpacklo_epi32(even_m1, odd); + unpack2_avx2 = _mm256_unpackhi_epi32(even_m1, odd); + + _mm_storeu_si128((__m128i*)(out_ptr + 0), _mm256_castsi256_si128(unpack1_avx2)); + _mm_storeu_si128((__m128i*)(out_ptr + 4), _mm256_castsi256_si128(unpack2_avx2)); + _mm_storeu_si128((__m128i*)(out_ptr + 8), _mm256_extracti128_si256(unpack1_avx2, + 0x1)); + _mm_storeu_si128((__m128i*)(out_ptr + 12), + _mm256_extracti128_si256(unpack2_avx2, 0x1)); + + prev_even = next_even; + + out_ptr += 16; + in_even += 8; + in_odd += 8; + } + out_ptr[0] = prev_even; + for (j = simd_batch * 16 + 1; j < (len - 2); j += 2) { + out_ptr[2] = in_even[1] - ((in_odd[0] + in_odd[1] + 2) >> 2); + out_ptr[1] = in_odd[0] + ((out_ptr[0] + out_ptr[2]) >> 1); + in_even++; + in_odd++; + out_ptr += 2; + } + + if (len & 1) { + out_ptr[2] = in_even[1] - ((in_odd[0] + 1) >> 1); + out_ptr[1] = in_odd[0] + ((out_ptr[0] + out_ptr[2]) >> 1); + } else { //!(len & 1) + out_ptr[1] = in_odd[0] + out_ptr[0]; + } #else OPJ_INT32 d1c, d1n, s1n, s0c, s0n; @@ -465,7 +572,8 @@ static void opj_idwt53_h_cas0(OPJ_INT32* tmp, s0n = s1n - ((d1c + d1n + 2) >> 2); tmp[i ] = s0c; - tmp[i + 1] = d1c + ((s0c + s0n) >> 1); + tmp[i + 1] = opj_int_add_no_overflow(d1c, opj_int_add_no_overflow(s0c, + s0n) >> 1); } tmp[i] = s0n; @@ -476,7 +584,8 @@ static void opj_idwt53_h_cas0(OPJ_INT32* tmp, } else { tmp[len - 1] = d1n + s0n; } -#endif +#endif /*(__AVX512F__ || __AVX2__)*/ +#endif /*TWO_PASS_VERSION*/ memcpy(tiledp, tmp, (OPJ_UINT32)len * sizeof(OPJ_INT32)); } @@ -530,7 +639,7 @@ static void opj_idwt53_h_cas1(OPJ_INT32* tmp, dn = in_odd[j] - ((s1 + s2 + 2) >> 2); tmp[i ] = dc; - tmp[i + 1] = s1 + ((dn + dc) >> 1); + tmp[i + 1] = opj_int_add_no_overflow(s1, opj_int_add_no_overflow(dn, dc) >> 1); dc = dn; s1 = s2; @@ -590,10 +699,20 @@ static void opj_idwt53_h(const opj_dwt_t *dwt, #endif } -#if (defined(__SSE2__) || defined(__AVX2__)) && !defined(STANDARD_SLOW_VERSION) - -/* Conveniency macros to improve the readabilty of the formulas */ -#if __AVX2__ +#if (defined(__SSE2__) || defined(__AVX2__) || defined(__AVX512F__)) && !defined(STANDARD_SLOW_VERSION) + +/* Conveniency macros to improve the readability of the formulas */ +#if defined(__AVX512F__) +#define VREG __m512i +#define LOAD_CST(x) _mm512_set1_epi32(x) +#define LOAD(x) _mm512_loadu_si512((const VREG*)(x)) +#define LOADU(x) _mm512_loadu_si512((const VREG*)(x)) +#define STORE(x,y) _mm512_storeu_si512((VREG*)(x),(y)) +#define STOREU(x,y) _mm512_storeu_si512((VREG*)(x),(y)) +#define ADD(x,y) _mm512_add_epi32((x),(y)) +#define SUB(x,y) _mm512_sub_epi32((x),(y)) +#define SAR(x,y) _mm512_srai_epi32((x),(y)) +#elif defined(__AVX2__) #define VREG __m256i #define LOAD_CST(x) _mm256_set1_epi32(x) #define LOAD(x) _mm256_load_si256((const VREG*)(x)) @@ -655,7 +774,10 @@ static void opj_idwt53_v_cas0_mcols_SSE2_OR_AVX2( const VREG two = LOAD_CST(2); assert(len > 1); -#if __AVX2__ +#if defined(__AVX512F__) + assert(PARALLEL_COLS_53 == 32); + assert(VREG_INT_COUNT == 16); +#elif defined(__AVX2__) assert(PARALLEL_COLS_53 == 16); assert(VREG_INT_COUNT == 8); #else @@ -663,10 +785,13 @@ static void opj_idwt53_v_cas0_mcols_SSE2_OR_AVX2( assert(VREG_INT_COUNT == 4); #endif +//For AVX512 code aligned load/store is set to it's unaligned equivalents +#if !defined(__AVX512F__) /* Note: loads of input even/odd values must be done in a unaligned */ /* fashion. But stores in tmp can be done with aligned store, since */ /* the temporary buffer is properly aligned */ assert((OPJ_SIZE_T)tmp % (sizeof(OPJ_INT32) * VREG_INT_COUNT) == 0); +#endif s1n_0 = LOADU(in_even + 0); s1n_1 = LOADU(in_even + VREG_INT_COUNT); @@ -757,7 +882,10 @@ static void opj_idwt53_v_cas1_mcols_SSE2_OR_AVX2( const OPJ_INT32* in_odd = &tiledp_col[0]; assert(len > 2); -#if __AVX2__ +#if defined(__AVX512F__) + assert(PARALLEL_COLS_53 == 32); + assert(VREG_INT_COUNT == 16); +#elif defined(__AVX2__) assert(PARALLEL_COLS_53 == 16); assert(VREG_INT_COUNT == 8); #else @@ -765,10 +893,13 @@ static void opj_idwt53_v_cas1_mcols_SSE2_OR_AVX2( assert(VREG_INT_COUNT == 4); #endif +//For AVX512 code aligned load/store is set to it's unaligned equivalents +#if !defined(__AVX512F__) /* Note: loads of input even/odd values must be done in a unaligned */ /* fashion. But stores in tmp can be done with aligned store, since */ /* the temporary buffer is properly aligned */ assert((OPJ_SIZE_T)tmp % (sizeof(OPJ_INT32) * VREG_INT_COUNT) == 0); +#endif s1_0 = LOADU(in_even + stride); /* in_odd[0] - ((in_even[0] + s1 + 2) >> 2); */ @@ -876,10 +1007,12 @@ static void opj_idwt3_v_cas0(OPJ_INT32* tmp, s1n = tiledp_col[(OPJ_SIZE_T)(j + 1) * stride]; d1n = tiledp_col[(OPJ_SIZE_T)(sn + j + 1) * stride]; - s0n = s1n - ((d1c + d1n + 2) >> 2); + s0n = opj_int_sub_no_overflow(s1n, + opj_int_add_no_overflow(opj_int_add_no_overflow(d1c, d1n), 2) >> 2); tmp[i ] = s0c; - tmp[i + 1] = d1c + ((s0c + s0n) >> 1); + tmp[i + 1] = opj_int_add_no_overflow(d1c, opj_int_add_no_overflow(s0c, + s0n) >> 1); } tmp[i] = s0n; @@ -974,7 +1107,7 @@ static void opj_idwt53_v(const opj_dwt_t *dwt, #if (defined(__SSE2__) || defined(__AVX2__)) if (len > 1 && nb_cols == PARALLEL_COLS_53) { /* Same as below general case, except that thanks to SSE2/AVX2 */ - /* we can efficently process 8/16 columns in parallel */ + /* we can efficiently process 8/16 columns in parallel */ opj_idwt53_v_cas0_mcols_SSE2_OR_AVX2(dwt->mem, sn, len, tiledp_col, stride); return; } @@ -1017,7 +1150,7 @@ static void opj_idwt53_v(const opj_dwt_t *dwt, #if (defined(__SSE2__) || defined(__AVX2__)) if (len > 2 && nb_cols == PARALLEL_COLS_53) { /* Same as below general case, except that thanks to SSE2/AVX2 */ - /* we can efficently process 8/16 columns in parallel */ + /* we can efficiently process 8/16 columns in parallel */ opj_idwt53_v_cas1_mcols_SSE2_OR_AVX2(dwt->mem, sn, len, tiledp_col, stride); return; } @@ -1033,110 +1166,799 @@ static void opj_idwt53_v(const opj_dwt_t *dwt, #endif } +#if 0 +static void opj_dwt_encode_step1(OPJ_FLOAT32* fw, + OPJ_UINT32 end, + const OPJ_FLOAT32 c) +{ + OPJ_UINT32 i = 0; + for (; i < end; ++i) { + fw[0] *= c; + fw += 2; + } +} +#else +static void opj_dwt_encode_step1_combined(OPJ_FLOAT32* fw, + OPJ_UINT32 iters_c1, + OPJ_UINT32 iters_c2, + const OPJ_FLOAT32 c1, + const OPJ_FLOAT32 c2) +{ + OPJ_UINT32 i = 0; + const OPJ_UINT32 iters_common = opj_uint_min(iters_c1, iters_c2); + assert((((OPJ_SIZE_T)fw) & 0xf) == 0); + assert(opj_int_abs((OPJ_INT32)iters_c1 - (OPJ_INT32)iters_c2) <= 1); + for (; i + 3 < iters_common; i += 4) { +#ifdef __SSE__ + const __m128 vcst = _mm_set_ps(c2, c1, c2, c1); + *(__m128*)fw = _mm_mul_ps(*(__m128*)fw, vcst); + *(__m128*)(fw + 4) = _mm_mul_ps(*(__m128*)(fw + 4), vcst); +#else + fw[0] *= c1; + fw[1] *= c2; + fw[2] *= c1; + fw[3] *= c2; + fw[4] *= c1; + fw[5] *= c2; + fw[6] *= c1; + fw[7] *= c2; +#endif + fw += 8; + } + for (; i < iters_common; i++) { + fw[0] *= c1; + fw[1] *= c2; + fw += 2; + } + if (i < iters_c1) { + fw[0] *= c1; + } else if (i < iters_c2) { + fw[1] *= c2; + } +} + +#endif -/* */ -/* Forward 9-7 wavelet transform in 1-D. */ -/* */ -static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, +static void opj_dwt_encode_step2(OPJ_FLOAT32* fl, OPJ_FLOAT32* fw, + OPJ_UINT32 end, + OPJ_UINT32 m, + OPJ_FLOAT32 c) +{ + OPJ_UINT32 i; + OPJ_UINT32 imax = opj_uint_min(end, m); + if (imax > 0) { + fw[-1] += (fl[0] + fw[0]) * c; + fw += 2; + i = 1; + for (; i + 3 < imax; i += 4) { + fw[-1] += (fw[-2] + fw[0]) * c; + fw[1] += (fw[0] + fw[2]) * c; + fw[3] += (fw[2] + fw[4]) * c; + fw[5] += (fw[4] + fw[6]) * c; + fw += 8; + } + for (; i < imax; ++i) { + fw[-1] += (fw[-2] + fw[0]) * c; + fw += 2; + } + } + if (m < end) { + assert(m + 1 == end); + fw[-1] += (2 * fw[-2]) * c; + } +} + +static void opj_dwt_encode_1_real(void *aIn, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { - OPJ_INT32 i; - if (!cas) { - if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ - for (i = 0; i < dn; i++) { - OPJ_D(i) -= opj_int_fix_mul(OPJ_S_(i) + OPJ_S_(i + 1), 12993); + OPJ_FLOAT32* w = (OPJ_FLOAT32*)aIn; + OPJ_INT32 a, b; + assert(dn + sn > 1); + if (cas == 0) { + a = 0; + b = 1; + } else { + a = 1; + b = 0; + } + opj_dwt_encode_step2(w + a, w + b + 1, + (OPJ_UINT32)dn, + (OPJ_UINT32)opj_int_min(dn, sn - b), + opj_dwt_alpha); + opj_dwt_encode_step2(w + b, w + a + 1, + (OPJ_UINT32)sn, + (OPJ_UINT32)opj_int_min(sn, dn - a), + opj_dwt_beta); + opj_dwt_encode_step2(w + a, w + b + 1, + (OPJ_UINT32)dn, + (OPJ_UINT32)opj_int_min(dn, sn - b), + opj_dwt_gamma); + opj_dwt_encode_step2(w + b, w + a + 1, + (OPJ_UINT32)sn, + (OPJ_UINT32)opj_int_min(sn, dn - a), + opj_dwt_delta); +#if 0 + opj_dwt_encode_step1(w + b, (OPJ_UINT32)dn, + opj_K); + opj_dwt_encode_step1(w + a, (OPJ_UINT32)sn, + opj_invK); +#else + if (a == 0) { + opj_dwt_encode_step1_combined(w, + (OPJ_UINT32)sn, + (OPJ_UINT32)dn, + opj_invK, + opj_K); + } else { + opj_dwt_encode_step1_combined(w, + (OPJ_UINT32)dn, + (OPJ_UINT32)sn, + opj_K, + opj_invK); + } +#endif +} + +static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, + opj_stepsize_t *bandno_stepsize) +{ + OPJ_INT32 p, n; + p = opj_int_floorlog2(stepsize) - 13; + n = 11 - opj_int_floorlog2(stepsize); + bandno_stepsize->mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff; + bandno_stepsize->expn = numbps - p; +} + +/* +========================================================== + DWT interface +========================================================== +*/ + +/** Process one line for the horizontal pass of the 5x3 forward transform */ +static +void opj_dwt_encode_and_deinterleave_h_one_row(void* rowIn, + void* tmpIn, + OPJ_UINT32 width, + OPJ_BOOL even) +{ + OPJ_INT32* OPJ_RESTRICT row = (OPJ_INT32*)rowIn; + OPJ_INT32* OPJ_RESTRICT tmp = (OPJ_INT32*)tmpIn; + const OPJ_INT32 sn = (OPJ_INT32)((width + (even ? 1 : 0)) >> 1); + const OPJ_INT32 dn = (OPJ_INT32)(width - (OPJ_UINT32)sn); + + if (even) { + if (width > 1) { + OPJ_INT32 i; + for (i = 0; i < sn - 1; i++) { + tmp[sn + i] = row[2 * i + 1] - ((row[(i) * 2] + row[(i + 1) * 2]) >> 1); } - for (i = 0; i < sn; i++) { - OPJ_S(i) -= opj_int_fix_mul(OPJ_D_(i - 1) + OPJ_D_(i), 434); + if ((width % 2) == 0) { + tmp[sn + i] = row[2 * i + 1] - row[(i) * 2]; } - for (i = 0; i < dn; i++) { - OPJ_D(i) += opj_int_fix_mul(OPJ_S_(i) + OPJ_S_(i + 1), 7233); + row[0] += (tmp[sn] + tmp[sn] + 2) >> 2; + for (i = 1; i < dn; i++) { + row[i] = row[2 * i] + ((tmp[sn + (i - 1)] + tmp[sn + i] + 2) >> 2); } - for (i = 0; i < sn; i++) { - OPJ_S(i) += opj_int_fix_mul(OPJ_D_(i - 1) + OPJ_D_(i), 3633); + if ((width % 2) == 1) { + row[i] = row[2 * i] + ((tmp[sn + (i - 1)] + tmp[sn + (i - 1)] + 2) >> 2); } - for (i = 0; i < dn; i++) { - OPJ_D(i) = opj_int_fix_mul(OPJ_D(i), 5038); /*5038 */ + memcpy(row + sn, tmp + sn, (OPJ_SIZE_T)dn * sizeof(OPJ_INT32)); + } + } else { + if (width == 1) { + row[0] *= 2; + } else { + OPJ_INT32 i; + tmp[sn + 0] = row[0] - row[1]; + for (i = 1; i < sn; i++) { + tmp[sn + i] = row[2 * i] - ((row[2 * i + 1] + row[2 * (i - 1) + 1]) >> 1); } - for (i = 0; i < sn; i++) { - OPJ_S(i) = opj_int_fix_mul(OPJ_S(i), 6659); /*6660 */ + if ((width % 2) == 1) { + tmp[sn + i] = row[2 * i] - row[2 * (i - 1) + 1]; + } + + for (i = 0; i < dn - 1; i++) { + row[i] = row[2 * i + 1] + ((tmp[sn + i] + tmp[sn + i + 1] + 2) >> 2); } + if ((width % 2) == 0) { + row[i] = row[2 * i + 1] + ((tmp[sn + i] + tmp[sn + i] + 2) >> 2); + } + memcpy(row + sn, tmp + sn, (OPJ_SIZE_T)dn * sizeof(OPJ_INT32)); + } + } +} + +/** Process one line for the horizontal pass of the 9x7 forward transform */ +static +void opj_dwt_encode_and_deinterleave_h_one_row_real(void* rowIn, + void* tmpIn, + OPJ_UINT32 width, + OPJ_BOOL even) +{ + OPJ_FLOAT32* OPJ_RESTRICT row = (OPJ_FLOAT32*)rowIn; + OPJ_FLOAT32* OPJ_RESTRICT tmp = (OPJ_FLOAT32*)tmpIn; + const OPJ_INT32 sn = (OPJ_INT32)((width + (even ? 1 : 0)) >> 1); + const OPJ_INT32 dn = (OPJ_INT32)(width - (OPJ_UINT32)sn); + if (width == 1) { + return; + } + memcpy(tmp, row, width * sizeof(OPJ_FLOAT32)); + opj_dwt_encode_1_real(tmp, dn, sn, even ? 0 : 1); + opj_dwt_deinterleave_h((OPJ_INT32 * OPJ_RESTRICT)tmp, + (OPJ_INT32 * OPJ_RESTRICT)row, + dn, sn, even ? 0 : 1); +} + +typedef struct { + opj_dwt_t h; + OPJ_UINT32 rw; /* Width of the resolution to process */ + OPJ_UINT32 w; /* Width of tiledp */ + OPJ_INT32 * OPJ_RESTRICT tiledp; + OPJ_UINT32 min_j; + OPJ_UINT32 max_j; + opj_encode_and_deinterleave_h_one_row_fnptr_type p_function; +} opj_dwt_encode_h_job_t; + +static void opj_dwt_encode_h_func(void* user_data, opj_tls_t* tls) +{ + OPJ_UINT32 j; + opj_dwt_encode_h_job_t* job; + (void)tls; + + job = (opj_dwt_encode_h_job_t*)user_data; + for (j = job->min_j; j < job->max_j; j++) { + OPJ_INT32* OPJ_RESTRICT aj = job->tiledp + j * job->w; + (*job->p_function)(aj, job->h.mem, job->rw, + job->h.cas == 0 ? OPJ_TRUE : OPJ_FALSE); + } + + opj_aligned_free(job->h.mem); + opj_free(job); +} + +typedef struct { + opj_dwt_t v; + OPJ_UINT32 rh; + OPJ_UINT32 w; + OPJ_INT32 * OPJ_RESTRICT tiledp; + OPJ_UINT32 min_j; + OPJ_UINT32 max_j; + opj_encode_and_deinterleave_v_fnptr_type p_encode_and_deinterleave_v; +} opj_dwt_encode_v_job_t; + +static void opj_dwt_encode_v_func(void* user_data, opj_tls_t* tls) +{ + OPJ_UINT32 j; + opj_dwt_encode_v_job_t* job; + (void)tls; + + job = (opj_dwt_encode_v_job_t*)user_data; + for (j = job->min_j; j + NB_ELTS_V8 - 1 < job->max_j; j += NB_ELTS_V8) { + (*job->p_encode_and_deinterleave_v)(job->tiledp + j, + job->v.mem, + job->rh, + job->v.cas == 0, + job->w, + NB_ELTS_V8); + } + if (j < job->max_j) { + (*job->p_encode_and_deinterleave_v)(job->tiledp + j, + job->v.mem, + job->rh, + job->v.cas == 0, + job->w, + job->max_j - j); + } + + opj_aligned_free(job->v.mem); + opj_free(job); +} + +/** Fetch up to cols <= NB_ELTS_V8 for each line, and put them in tmpOut */ +/* that has a NB_ELTS_V8 interleave factor. */ +static void opj_dwt_fetch_cols_vertical_pass(const void *arrayIn, + void *tmpOut, + OPJ_UINT32 height, + OPJ_UINT32 stride_width, + OPJ_UINT32 cols) +{ + const OPJ_INT32* OPJ_RESTRICT array = (const OPJ_INT32 * OPJ_RESTRICT)arrayIn; + OPJ_INT32* OPJ_RESTRICT tmp = (OPJ_INT32 * OPJ_RESTRICT)tmpOut; + if (cols == NB_ELTS_V8) { + OPJ_UINT32 k; + for (k = 0; k < height; ++k) { + memcpy(tmp + NB_ELTS_V8 * k, + array + k * stride_width, + NB_ELTS_V8 * sizeof(OPJ_INT32)); } } else { - if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */ - for (i = 0; i < dn; i++) { - OPJ_S(i) -= opj_int_fix_mul(OPJ_DD_(i) + OPJ_DD_(i - 1), 12993); + OPJ_UINT32 k; + for (k = 0; k < height; ++k) { + OPJ_UINT32 c; + for (c = 0; c < cols; c++) { + tmp[NB_ELTS_V8 * k + c] = array[c + k * stride_width]; } - for (i = 0; i < sn; i++) { - OPJ_D(i) -= opj_int_fix_mul(OPJ_SS_(i) + OPJ_SS_(i + 1), 434); + for (; c < NB_ELTS_V8; c++) { + tmp[NB_ELTS_V8 * k + c] = 0; } - for (i = 0; i < dn; i++) { - OPJ_S(i) += opj_int_fix_mul(OPJ_DD_(i) + OPJ_DD_(i - 1), 7233); + } + } +} + +/* Deinterleave result of forward transform, where cols <= NB_ELTS_V8 */ +/* and src contains NB_ELTS_V8 consecutive values for up to NB_ELTS_V8 */ +/* columns. */ +static INLINE void opj_dwt_deinterleave_v_cols( + const OPJ_INT32 * OPJ_RESTRICT src, + OPJ_INT32 * OPJ_RESTRICT dst, + OPJ_INT32 dn, + OPJ_INT32 sn, + OPJ_UINT32 stride_width, + OPJ_INT32 cas, + OPJ_UINT32 cols) +{ + OPJ_INT32 k; + OPJ_INT32 i = sn; + OPJ_INT32 * OPJ_RESTRICT l_dest = dst; + const OPJ_INT32 * OPJ_RESTRICT l_src = src + cas * NB_ELTS_V8; + OPJ_UINT32 c; + + for (k = 0; k < 2; k++) { + while (i--) { + if (cols == NB_ELTS_V8) { + memcpy(l_dest, l_src, NB_ELTS_V8 * sizeof(OPJ_INT32)); + } else { + c = 0; + switch (cols) { + case 7: + l_dest[c] = l_src[c]; + c++; /* fallthru */ + case 6: + l_dest[c] = l_src[c]; + c++; /* fallthru */ + case 5: + l_dest[c] = l_src[c]; + c++; /* fallthru */ + case 4: + l_dest[c] = l_src[c]; + c++; /* fallthru */ + case 3: + l_dest[c] = l_src[c]; + c++; /* fallthru */ + case 2: + l_dest[c] = l_src[c]; + c++; /* fallthru */ + default: + l_dest[c] = l_src[c]; + break; + } } - for (i = 0; i < sn; i++) { - OPJ_D(i) += opj_int_fix_mul(OPJ_SS_(i) + OPJ_SS_(i + 1), 3633); + l_dest += stride_width; + l_src += 2 * NB_ELTS_V8; + } + + l_dest = dst + (OPJ_SIZE_T)sn * (OPJ_SIZE_T)stride_width; + l_src = src + (1 - cas) * NB_ELTS_V8; + i = dn; + } +} + + +/* Forward 5-3 transform, for the vertical pass, processing cols columns */ +/* where cols <= NB_ELTS_V8 */ +static void opj_dwt_encode_and_deinterleave_v( + void *arrayIn, + void *tmpIn, + OPJ_UINT32 height, + OPJ_BOOL even, + OPJ_UINT32 stride_width, + OPJ_UINT32 cols) +{ + OPJ_INT32* OPJ_RESTRICT array = (OPJ_INT32 * OPJ_RESTRICT)arrayIn; + OPJ_INT32* OPJ_RESTRICT tmp = (OPJ_INT32 * OPJ_RESTRICT)tmpIn; + const OPJ_UINT32 sn = (height + (even ? 1 : 0)) >> 1; + const OPJ_UINT32 dn = height - sn; + + opj_dwt_fetch_cols_vertical_pass(arrayIn, tmpIn, height, stride_width, cols); + +#define OPJ_Sc(i) tmp[(i)*2* NB_ELTS_V8 + c] +#define OPJ_Dc(i) tmp[((1+(i)*2))* NB_ELTS_V8 + c] + +#ifdef __SSE2__ + if (height == 1) { + if (!even) { + OPJ_UINT32 c; + for (c = 0; c < NB_ELTS_V8; c++) { + tmp[c] *= 2; } - for (i = 0; i < dn; i++) { - OPJ_S(i) = opj_int_fix_mul(OPJ_S(i), 5038); /*5038 */ + } + } else if (even) { + OPJ_UINT32 c; + OPJ_UINT32 i; + i = 0; + if (i + 1 < sn) { + __m128i xmm_Si_0 = *(const __m128i*)(tmp + 4 * 0); + __m128i xmm_Si_1 = *(const __m128i*)(tmp + 4 * 1); + for (; i + 1 < sn; i++) { + __m128i xmm_Sip1_0 = *(const __m128i*)(tmp + + (i + 1) * 2 * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Sip1_1 = *(const __m128i*)(tmp + + (i + 1) * 2 * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Di_0 = *(const __m128i*)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Di_1 = *(const __m128i*)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 1); + xmm_Di_0 = _mm_sub_epi32(xmm_Di_0, + _mm_srai_epi32(_mm_add_epi32(xmm_Si_0, xmm_Sip1_0), 1)); + xmm_Di_1 = _mm_sub_epi32(xmm_Di_1, + _mm_srai_epi32(_mm_add_epi32(xmm_Si_1, xmm_Sip1_1), 1)); + *(__m128i*)(tmp + (1 + i * 2) * NB_ELTS_V8 + 4 * 0) = xmm_Di_0; + *(__m128i*)(tmp + (1 + i * 2) * NB_ELTS_V8 + 4 * 1) = xmm_Di_1; + xmm_Si_0 = xmm_Sip1_0; + xmm_Si_1 = xmm_Sip1_1; } - for (i = 0; i < sn; i++) { - OPJ_D(i) = opj_int_fix_mul(OPJ_D(i), 6659); /*6660 */ + } + if (((height) % 2) == 0) { + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Dc(i) -= OPJ_Sc(i); + } + } + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Sc(0) += (OPJ_Dc(0) + OPJ_Dc(0) + 2) >> 2; + } + i = 1; + if (i < dn) { + __m128i xmm_Dim1_0 = *(const __m128i*)(tmp + (1 + + (i - 1) * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Dim1_1 = *(const __m128i*)(tmp + (1 + + (i - 1) * 2) * NB_ELTS_V8 + 4 * 1); + const __m128i xmm_two = _mm_set1_epi32(2); + for (; i < dn; i++) { + __m128i xmm_Di_0 = *(const __m128i*)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Di_1 = *(const __m128i*)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Si_0 = *(const __m128i*)(tmp + + (i * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Si_1 = *(const __m128i*)(tmp + + (i * 2) * NB_ELTS_V8 + 4 * 1); + xmm_Si_0 = _mm_add_epi32(xmm_Si_0, + _mm_srai_epi32(_mm_add_epi32(_mm_add_epi32(xmm_Dim1_0, xmm_Di_0), xmm_two), 2)); + xmm_Si_1 = _mm_add_epi32(xmm_Si_1, + _mm_srai_epi32(_mm_add_epi32(_mm_add_epi32(xmm_Dim1_1, xmm_Di_1), xmm_two), 2)); + *(__m128i*)(tmp + (i * 2) * NB_ELTS_V8 + 4 * 0) = xmm_Si_0; + *(__m128i*)(tmp + (i * 2) * NB_ELTS_V8 + 4 * 1) = xmm_Si_1; + xmm_Dim1_0 = xmm_Di_0; + xmm_Dim1_1 = xmm_Di_1; + } + } + if (((height) % 2) == 1) { + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Sc(i) += (OPJ_Dc(i - 1) + OPJ_Dc(i - 1) + 2) >> 2; + } + } + } else { + OPJ_UINT32 c; + OPJ_UINT32 i; + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Sc(0) -= OPJ_Dc(0); + } + i = 1; + if (i < sn) { + __m128i xmm_Dim1_0 = *(const __m128i*)(tmp + (1 + + (i - 1) * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Dim1_1 = *(const __m128i*)(tmp + (1 + + (i - 1) * 2) * NB_ELTS_V8 + 4 * 1); + for (; i < sn; i++) { + __m128i xmm_Di_0 = *(const __m128i*)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Di_1 = *(const __m128i*)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Si_0 = *(const __m128i*)(tmp + + (i * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Si_1 = *(const __m128i*)(tmp + + (i * 2) * NB_ELTS_V8 + 4 * 1); + xmm_Si_0 = _mm_sub_epi32(xmm_Si_0, + _mm_srai_epi32(_mm_add_epi32(xmm_Di_0, xmm_Dim1_0), 1)); + xmm_Si_1 = _mm_sub_epi32(xmm_Si_1, + _mm_srai_epi32(_mm_add_epi32(xmm_Di_1, xmm_Dim1_1), 1)); + *(__m128i*)(tmp + (i * 2) * NB_ELTS_V8 + 4 * 0) = xmm_Si_0; + *(__m128i*)(tmp + (i * 2) * NB_ELTS_V8 + 4 * 1) = xmm_Si_1; + xmm_Dim1_0 = xmm_Di_0; + xmm_Dim1_1 = xmm_Di_1; + } + } + if (((height) % 2) == 1) { + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Sc(i) -= OPJ_Dc(i - 1); + } + } + i = 0; + if (i + 1 < dn) { + __m128i xmm_Si_0 = *((const __m128i*)(tmp + 4 * 0)); + __m128i xmm_Si_1 = *((const __m128i*)(tmp + 4 * 1)); + const __m128i xmm_two = _mm_set1_epi32(2); + for (; i + 1 < dn; i++) { + __m128i xmm_Sip1_0 = *(const __m128i*)(tmp + + (i + 1) * 2 * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Sip1_1 = *(const __m128i*)(tmp + + (i + 1) * 2 * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Di_0 = *(const __m128i*)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Di_1 = *(const __m128i*)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 1); + xmm_Di_0 = _mm_add_epi32(xmm_Di_0, + _mm_srai_epi32(_mm_add_epi32(_mm_add_epi32(xmm_Si_0, xmm_Sip1_0), xmm_two), 2)); + xmm_Di_1 = _mm_add_epi32(xmm_Di_1, + _mm_srai_epi32(_mm_add_epi32(_mm_add_epi32(xmm_Si_1, xmm_Sip1_1), xmm_two), 2)); + *(__m128i*)(tmp + (1 + i * 2) * NB_ELTS_V8 + 4 * 0) = xmm_Di_0; + *(__m128i*)(tmp + (1 + i * 2) * NB_ELTS_V8 + 4 * 1) = xmm_Di_1; + xmm_Si_0 = xmm_Sip1_0; + xmm_Si_1 = xmm_Sip1_1; + } + } + if (((height) % 2) == 0) { + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Dc(i) += (OPJ_Sc(i) + OPJ_Sc(i) + 2) >> 2; + } + } + } +#else + if (even) { + OPJ_UINT32 c; + if (height > 1) { + OPJ_UINT32 i; + for (i = 0; i + 1 < sn; i++) { + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Dc(i) -= (OPJ_Sc(i) + OPJ_Sc(i + 1)) >> 1; + } + } + if (((height) % 2) == 0) { + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Dc(i) -= OPJ_Sc(i); + } + } + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Sc(0) += (OPJ_Dc(0) + OPJ_Dc(0) + 2) >> 2; + } + for (i = 1; i < dn; i++) { + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Sc(i) += (OPJ_Dc(i - 1) + OPJ_Dc(i) + 2) >> 2; + } + } + if (((height) % 2) == 1) { + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Sc(i) += (OPJ_Dc(i - 1) + OPJ_Dc(i - 1) + 2) >> 2; + } + } + } + } else { + OPJ_UINT32 c; + if (height == 1) { + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Sc(0) *= 2; + } + } else { + OPJ_UINT32 i; + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Sc(0) -= OPJ_Dc(0); + } + for (i = 1; i < sn; i++) { + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Sc(i) -= (OPJ_Dc(i) + OPJ_Dc(i - 1)) >> 1; + } + } + if (((height) % 2) == 1) { + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Sc(i) -= OPJ_Dc(i - 1); + } + } + for (i = 0; i + 1 < dn; i++) { + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Dc(i) += (OPJ_Sc(i) + OPJ_Sc(i + 1) + 2) >> 2; + } + } + if (((height) % 2) == 0) { + for (c = 0; c < NB_ELTS_V8; c++) { + OPJ_Dc(i) += (OPJ_Sc(i) + OPJ_Sc(i) + 2) >> 2; + } + } + } + } +#endif + + if (cols == NB_ELTS_V8) { + opj_dwt_deinterleave_v_cols(tmp, array, (OPJ_INT32)dn, (OPJ_INT32)sn, + stride_width, even ? 0 : 1, NB_ELTS_V8); + } else { + opj_dwt_deinterleave_v_cols(tmp, array, (OPJ_INT32)dn, (OPJ_INT32)sn, + stride_width, even ? 0 : 1, cols); + } +} + +static void opj_v8dwt_encode_step1(OPJ_FLOAT32* fw, + OPJ_UINT32 end, + const OPJ_FLOAT32 cst) +{ + OPJ_UINT32 i; +#ifdef __SSE__ + __m128* vw = (__m128*) fw; + const __m128 vcst = _mm_set1_ps(cst); + for (i = 0; i < end; ++i) { + vw[0] = _mm_mul_ps(vw[0], vcst); + vw[1] = _mm_mul_ps(vw[1], vcst); + vw += 2 * (NB_ELTS_V8 * sizeof(OPJ_FLOAT32) / sizeof(__m128)); + } +#else + OPJ_UINT32 c; + for (i = 0; i < end; ++i) { + for (c = 0; c < NB_ELTS_V8; c++) { + fw[i * 2 * NB_ELTS_V8 + c] *= cst; + } + } +#endif +} + +static void opj_v8dwt_encode_step2(OPJ_FLOAT32* fl, OPJ_FLOAT32* fw, + OPJ_UINT32 end, + OPJ_UINT32 m, + OPJ_FLOAT32 cst) +{ + OPJ_UINT32 i; + OPJ_UINT32 imax = opj_uint_min(end, m); +#ifdef __SSE__ + __m128* vw = (__m128*) fw; + __m128 vcst = _mm_set1_ps(cst); + if (imax > 0) { + __m128* vl = (__m128*) fl; + vw[-2] = _mm_add_ps(vw[-2], _mm_mul_ps(_mm_add_ps(vl[0], vw[0]), vcst)); + vw[-1] = _mm_add_ps(vw[-1], _mm_mul_ps(_mm_add_ps(vl[1], vw[1]), vcst)); + vw += 2 * (NB_ELTS_V8 * sizeof(OPJ_FLOAT32) / sizeof(__m128)); + i = 1; + + for (; i < imax; ++i) { + vw[-2] = _mm_add_ps(vw[-2], _mm_mul_ps(_mm_add_ps(vw[-4], vw[0]), vcst)); + vw[-1] = _mm_add_ps(vw[-1], _mm_mul_ps(_mm_add_ps(vw[-3], vw[1]), vcst)); + vw += 2 * (NB_ELTS_V8 * sizeof(OPJ_FLOAT32) / sizeof(__m128)); + } + } + if (m < end) { + assert(m + 1 == end); + vcst = _mm_add_ps(vcst, vcst); + vw[-2] = _mm_add_ps(vw[-2], _mm_mul_ps(vw[-4], vcst)); + vw[-1] = _mm_add_ps(vw[-1], _mm_mul_ps(vw[-3], vcst)); + } +#else + OPJ_INT32 c; + if (imax > 0) { + for (c = 0; c < NB_ELTS_V8; c++) { + fw[-1 * NB_ELTS_V8 + c] += (fl[0 * NB_ELTS_V8 + c] + fw[0 * NB_ELTS_V8 + c]) * + cst; + } + fw += 2 * NB_ELTS_V8; + i = 1; + for (; i < imax; ++i) { + for (c = 0; c < NB_ELTS_V8; c++) { + fw[-1 * NB_ELTS_V8 + c] += (fw[-2 * NB_ELTS_V8 + c] + fw[0 * NB_ELTS_V8 + c]) * + cst; } + fw += 2 * NB_ELTS_V8; + } + } + if (m < end) { + assert(m + 1 == end); + for (c = 0; c < NB_ELTS_V8; c++) { + fw[-1 * NB_ELTS_V8 + c] += (2 * fw[-2 * NB_ELTS_V8 + c]) * cst; } } +#endif } -static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, - opj_stepsize_t *bandno_stepsize) +/* Forward 9-7 transform, for the vertical pass, processing cols columns */ +/* where cols <= NB_ELTS_V8 */ +static void opj_dwt_encode_and_deinterleave_v_real( + void *arrayIn, + void *tmpIn, + OPJ_UINT32 height, + OPJ_BOOL even, + OPJ_UINT32 stride_width, + OPJ_UINT32 cols) { - OPJ_INT32 p, n; - p = opj_int_floorlog2(stepsize) - 13; - n = 11 - opj_int_floorlog2(stepsize); - bandno_stepsize->mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff; - bandno_stepsize->expn = numbps - p; -} + OPJ_FLOAT32* OPJ_RESTRICT array = (OPJ_FLOAT32 * OPJ_RESTRICT)arrayIn; + OPJ_FLOAT32* OPJ_RESTRICT tmp = (OPJ_FLOAT32 * OPJ_RESTRICT)tmpIn; + const OPJ_INT32 sn = (OPJ_INT32)((height + (even ? 1 : 0)) >> 1); + const OPJ_INT32 dn = (OPJ_INT32)(height - (OPJ_UINT32)sn); + OPJ_INT32 a, b; -/* -========================================================== - DWT interface -========================================================== -*/ + if (height == 1) { + return; + } + + opj_dwt_fetch_cols_vertical_pass(arrayIn, tmpIn, height, stride_width, cols); + + if (even) { + a = 0; + b = 1; + } else { + a = 1; + b = 0; + } + opj_v8dwt_encode_step2(tmp + a * NB_ELTS_V8, + tmp + (b + 1) * NB_ELTS_V8, + (OPJ_UINT32)dn, + (OPJ_UINT32)opj_int_min(dn, sn - b), + opj_dwt_alpha); + opj_v8dwt_encode_step2(tmp + b * NB_ELTS_V8, + tmp + (a + 1) * NB_ELTS_V8, + (OPJ_UINT32)sn, + (OPJ_UINT32)opj_int_min(sn, dn - a), + opj_dwt_beta); + opj_v8dwt_encode_step2(tmp + a * NB_ELTS_V8, + tmp + (b + 1) * NB_ELTS_V8, + (OPJ_UINT32)dn, + (OPJ_UINT32)opj_int_min(dn, sn - b), + opj_dwt_gamma); + opj_v8dwt_encode_step2(tmp + b * NB_ELTS_V8, + tmp + (a + 1) * NB_ELTS_V8, + (OPJ_UINT32)sn, + (OPJ_UINT32)opj_int_min(sn, dn - a), + opj_dwt_delta); + opj_v8dwt_encode_step1(tmp + b * NB_ELTS_V8, (OPJ_UINT32)dn, + opj_K); + opj_v8dwt_encode_step1(tmp + a * NB_ELTS_V8, (OPJ_UINT32)sn, + opj_invK); + + + if (cols == NB_ELTS_V8) { + opj_dwt_deinterleave_v_cols((OPJ_INT32*)tmp, + (OPJ_INT32*)array, + (OPJ_INT32)dn, (OPJ_INT32)sn, + stride_width, even ? 0 : 1, NB_ELTS_V8); + } else { + opj_dwt_deinterleave_v_cols((OPJ_INT32*)tmp, + (OPJ_INT32*)array, + (OPJ_INT32)dn, (OPJ_INT32)sn, + stride_width, even ? 0 : 1, cols); + } +} /* */ /* Forward 5-3 wavelet transform in 2-D. */ /* */ -static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec, - void (*p_function)(OPJ_INT32 *, OPJ_INT32, OPJ_INT32, OPJ_INT32)) +static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_thread_pool_t* tp, + opj_tcd_tilecomp_t * tilec, + opj_encode_and_deinterleave_v_fnptr_type p_encode_and_deinterleave_v, + opj_encode_and_deinterleave_h_one_row_fnptr_type + p_encode_and_deinterleave_h_one_row) { - OPJ_INT32 i, j, k; - OPJ_INT32 *a = 00; - OPJ_INT32 *aj = 00; + OPJ_INT32 i; OPJ_INT32 *bj = 00; - OPJ_INT32 w, l; + OPJ_UINT32 w; + OPJ_INT32 l; - OPJ_INT32 rw; /* width of the resolution level computed */ - OPJ_INT32 rh; /* height of the resolution level computed */ OPJ_SIZE_T l_data_size; opj_tcd_resolution_t * l_cur_res = 0; opj_tcd_resolution_t * l_last_res = 0; + const int num_threads = opj_thread_pool_get_thread_count(tp); + OPJ_INT32 * OPJ_RESTRICT tiledp = tilec->data; - w = tilec->x1 - tilec->x0; + w = (OPJ_UINT32)(tilec->x1 - tilec->x0); l = (OPJ_INT32)tilec->numresolutions - 1; - a = tilec->data; l_cur_res = tilec->resolutions + l; l_last_res = l_cur_res - 1; l_data_size = opj_dwt_max_resolution(tilec->resolutions, tilec->numresolutions); /* overflow check */ - if (l_data_size > (SIZE_MAX / sizeof(OPJ_INT32))) { + if (l_data_size > (SIZE_MAX / (NB_ELTS_V8 * sizeof(OPJ_INT32)))) { /* FIXME event manager error callback */ return OPJ_FALSE; } - l_data_size *= sizeof(OPJ_INT32); - bj = (OPJ_INT32*)opj_malloc(l_data_size); + l_data_size *= NB_ELTS_V8 * sizeof(OPJ_INT32); + bj = (OPJ_INT32*)opj_aligned_32_malloc(l_data_size); /* l_data_size is equal to 0 when numresolutions == 1 but bj is not used */ /* in that case, so do not error out */ if (l_data_size != 0 && ! bj) { @@ -1145,43 +1967,135 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec, i = l; while (i--) { - OPJ_INT32 rw1; /* width of the resolution level once lower than computed one */ - OPJ_INT32 rh1; /* height of the resolution level once lower than computed one */ + OPJ_UINT32 j; + OPJ_UINT32 rw; /* width of the resolution level computed */ + OPJ_UINT32 rh; /* height of the resolution level computed */ + OPJ_UINT32 + rw1; /* width of the resolution level once lower than computed one */ + OPJ_UINT32 + rh1; /* height of the resolution level once lower than computed one */ OPJ_INT32 cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */ OPJ_INT32 cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */ OPJ_INT32 dn, sn; - rw = l_cur_res->x1 - l_cur_res->x0; - rh = l_cur_res->y1 - l_cur_res->y0; - rw1 = l_last_res->x1 - l_last_res->x0; - rh1 = l_last_res->y1 - l_last_res->y0; + rw = (OPJ_UINT32)(l_cur_res->x1 - l_cur_res->x0); + rh = (OPJ_UINT32)(l_cur_res->y1 - l_cur_res->y0); + rw1 = (OPJ_UINT32)(l_last_res->x1 - l_last_res->x0); + rh1 = (OPJ_UINT32)(l_last_res->y1 - l_last_res->y0); cas_row = l_cur_res->x0 & 1; cas_col = l_cur_res->y0 & 1; - sn = rh1; - dn = rh - rh1; - for (j = 0; j < rw; ++j) { - aj = a + j; - for (k = 0; k < rh; ++k) { - bj[k] = aj[k * w]; + sn = (OPJ_INT32)rh1; + dn = (OPJ_INT32)(rh - rh1); + + /* Perform vertical pass */ + if (num_threads <= 1 || rw < 2 * NB_ELTS_V8) { + for (j = 0; j + NB_ELTS_V8 - 1 < rw; j += NB_ELTS_V8) { + p_encode_and_deinterleave_v(tiledp + j, + bj, + rh, + cas_col == 0, + w, + NB_ELTS_V8); + } + if (j < rw) { + p_encode_and_deinterleave_v(tiledp + j, + bj, + rh, + cas_col == 0, + w, + rw - j); + } + } else { + OPJ_UINT32 num_jobs = (OPJ_UINT32)num_threads; + OPJ_UINT32 step_j; + + if (rw < num_jobs) { + num_jobs = rw; } + step_j = ((rw / num_jobs) / NB_ELTS_V8) * NB_ELTS_V8; - (*p_function)(bj, dn, sn, cas_col); + for (j = 0; j < num_jobs; j++) { + opj_dwt_encode_v_job_t* job; - opj_dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col); + job = (opj_dwt_encode_v_job_t*) opj_malloc(sizeof(opj_dwt_encode_v_job_t)); + if (!job) { + opj_thread_pool_wait_completion(tp, 0); + opj_aligned_free(bj); + return OPJ_FALSE; + } + job->v.mem = (OPJ_INT32*)opj_aligned_32_malloc(l_data_size); + if (!job->v.mem) { + opj_thread_pool_wait_completion(tp, 0); + opj_free(job); + opj_aligned_free(bj); + return OPJ_FALSE; + } + job->v.dn = dn; + job->v.sn = sn; + job->v.cas = cas_col; + job->rh = rh; + job->w = w; + job->tiledp = tiledp; + job->min_j = j * step_j; + job->max_j = (j + 1 == num_jobs) ? rw : (j + 1) * step_j; + job->p_encode_and_deinterleave_v = p_encode_and_deinterleave_v; + opj_thread_pool_submit_job(tp, opj_dwt_encode_v_func, job); + } + opj_thread_pool_wait_completion(tp, 0); } - sn = rw1; - dn = rw - rw1; + sn = (OPJ_INT32)rw1; + dn = (OPJ_INT32)(rw - rw1); - for (j = 0; j < rh; j++) { - aj = a + j * w; - for (k = 0; k < rw; k++) { - bj[k] = aj[k]; + /* Perform horizontal pass */ + if (num_threads <= 1 || rh <= 1) { + for (j = 0; j < rh; j++) { + OPJ_INT32* OPJ_RESTRICT aj = tiledp + j * w; + (*p_encode_and_deinterleave_h_one_row)(aj, bj, rw, + cas_row == 0 ? OPJ_TRUE : OPJ_FALSE); + } + } else { + OPJ_UINT32 num_jobs = (OPJ_UINT32)num_threads; + OPJ_UINT32 step_j; + + if (rh < num_jobs) { + num_jobs = rh; + } + step_j = (rh / num_jobs); + + for (j = 0; j < num_jobs; j++) { + opj_dwt_encode_h_job_t* job; + + job = (opj_dwt_encode_h_job_t*) opj_malloc(sizeof(opj_dwt_encode_h_job_t)); + if (!job) { + opj_thread_pool_wait_completion(tp, 0); + opj_aligned_free(bj); + return OPJ_FALSE; + } + job->h.mem = (OPJ_INT32*)opj_aligned_32_malloc(l_data_size); + if (!job->h.mem) { + opj_thread_pool_wait_completion(tp, 0); + opj_free(job); + opj_aligned_free(bj); + return OPJ_FALSE; + } + job->h.dn = dn; + job->h.sn = sn; + job->h.cas = cas_row; + job->rw = rw; + job->w = w; + job->tiledp = tiledp; + job->min_j = j * step_j; + job->max_j = (j + 1U) * step_j; /* this can overflow */ + if (j == (num_jobs - 1U)) { /* this will take care of the overflow */ + job->max_j = rh; + } + job->p_function = p_encode_and_deinterleave_h_one_row; + opj_thread_pool_submit_job(tp, opj_dwt_encode_h_func, job); } - (*p_function)(bj, dn, sn, cas_row); - opj_dwt_deinterleave_h(bj, aj, dn, sn, cas_row); + opj_thread_pool_wait_completion(tp, 0); } l_cur_res = l_last_res; @@ -1189,15 +2103,18 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec, --l_last_res; } - opj_free(bj); + opj_aligned_free(bj); return OPJ_TRUE; } /* Forward 5-3 wavelet transform in 2-D. */ /* */ -OPJ_BOOL opj_dwt_encode(opj_tcd_tilecomp_t * tilec) +OPJ_BOOL opj_dwt_encode(opj_tcd_t *p_tcd, + opj_tcd_tilecomp_t * tilec) { - return opj_dwt_encode_procedure(tilec, opj_dwt_encode_1); + return opj_dwt_encode_procedure(p_tcd->thread_pool, tilec, + opj_dwt_encode_and_deinterleave_v, + opj_dwt_encode_and_deinterleave_h_one_row); } /* */ @@ -1213,21 +2130,6 @@ OPJ_BOOL opj_dwt_decode(opj_tcd_t *p_tcd, opj_tcd_tilecomp_t* tilec, } } - -/* */ -/* Get gain of 5-3 wavelet transform. */ -/* */ -OPJ_UINT32 opj_dwt_getgain(OPJ_UINT32 orient) -{ - if (orient == 0) { - return 0; - } - if (orient == 1 || orient == 2) { - return 1; - } - return 2; -} - /* */ /* Get norm of 5-3 wavelet. */ /* */ @@ -1247,18 +2149,12 @@ OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient) /* */ /* Forward 9-7 wavelet transform in 2-D. */ /* */ -OPJ_BOOL opj_dwt_encode_real(opj_tcd_tilecomp_t * tilec) -{ - return opj_dwt_encode_procedure(tilec, opj_dwt_encode_1_real); -} - -/* */ -/* Get gain of 9-7 wavelet transform. */ -/* */ -OPJ_UINT32 opj_dwt_getgain_real(OPJ_UINT32 orient) +OPJ_BOOL opj_dwt_encode_real(opj_tcd_t *p_tcd, + opj_tcd_tilecomp_t * tilec) { - (void)orient; - return 0; + return opj_dwt_encode_procedure(p_tcd->thread_pool, tilec, + opj_dwt_encode_and_deinterleave_v_real, + opj_dwt_encode_and_deinterleave_h_one_row_real); } /* */ @@ -1293,7 +2189,7 @@ void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec) if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) { stepsize = 1.0; } else { - OPJ_FLOAT64 norm = opj_dwt_norms_real[orient][level]; + OPJ_FLOAT64 norm = opj_dwt_getnorm_real(level, orient); stepsize = (1 << (gain)) / norm; } opj_dwt_encode_stepsize((OPJ_INT32) floor(stepsize * 8192.0), @@ -1328,15 +2224,15 @@ typedef struct { OPJ_INT32 * OPJ_RESTRICT tiledp; OPJ_UINT32 min_j; OPJ_UINT32 max_j; -} opj_dwd_decode_h_job_t; +} opj_dwt_decode_h_job_t; static void opj_dwt_decode_h_func(void* user_data, opj_tls_t* tls) { OPJ_UINT32 j; - opj_dwd_decode_h_job_t* job; + opj_dwt_decode_h_job_t* job; (void)tls; - job = (opj_dwd_decode_h_job_t*)user_data; + job = (opj_dwt_decode_h_job_t*)user_data; for (j = job->min_j; j < job->max_j; j++) { opj_idwt53_h(&job->h, &job->tiledp[j * job->w]); } @@ -1352,15 +2248,15 @@ typedef struct { OPJ_INT32 * OPJ_RESTRICT tiledp; OPJ_UINT32 min_j; OPJ_UINT32 max_j; -} opj_dwd_decode_v_job_t; +} opj_dwt_decode_v_job_t; static void opj_dwt_decode_v_func(void* user_data, opj_tls_t* tls) { OPJ_UINT32 j; - opj_dwd_decode_v_job_t* job; + opj_dwt_decode_v_job_t* job; (void)tls; - job = (opj_dwd_decode_v_job_t*)user_data; + job = (opj_dwt_decode_v_job_t*)user_data; for (j = job->min_j; j + PARALLEL_COLS_53 <= job->max_j; j += PARALLEL_COLS_53) { opj_idwt53_v(&job->v, &job->tiledp[j], (OPJ_SIZE_T)job->w, @@ -1397,7 +2293,9 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, OPJ_SIZE_T h_mem_size; int num_threads; - if (numres == 1U) { + /* Not entirely sure for the return code of w == 0 which is triggered per */ + /* https://github.com/uclouvain/openjpeg/issues/1505 */ + if (numres == 1U || w == 0) { return OPJ_TRUE; } num_threads = opj_thread_pool_get_thread_count(tp); @@ -1447,9 +2345,9 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, step_j = (rh / num_jobs); for (j = 0; j < num_jobs; j++) { - opj_dwd_decode_h_job_t* job; + opj_dwt_decode_h_job_t* job; - job = (opj_dwd_decode_h_job_t*) opj_malloc(sizeof(opj_dwd_decode_h_job_t)); + job = (opj_dwt_decode_h_job_t*) opj_malloc(sizeof(opj_dwt_decode_h_job_t)); if (!job) { /* It would be nice to fallback to single thread case, but */ /* unfortunately some jobs may be launched and have modified */ @@ -1502,9 +2400,9 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, step_j = (rw / num_jobs); for (j = 0; j < num_jobs; j++) { - opj_dwd_decode_v_job_t* job; + opj_dwt_decode_v_job_t* job; - job = (opj_dwd_decode_v_job_t*) opj_malloc(sizeof(opj_dwd_decode_v_job_t)); + job = (opj_dwt_decode_v_job_t*) opj_malloc(sizeof(opj_dwt_decode_v_job_t)); if (!job) { /* It would be nice to fallback to single thread case, but */ /* unfortunately some jobs may be launched and have modified */ @@ -1660,10 +2558,13 @@ static void opj_dwt_decode_partial_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_S(0) /= 2; } else { for (i = win_l_x0; i < win_l_x1; i++) { - OPJ_D(i) -= (OPJ_SS_(i) + OPJ_SS_(i + 1) + 2) >> 2; + OPJ_D(i) = opj_int_sub_no_overflow(OPJ_D(i), + opj_int_add_no_overflow(opj_int_add_no_overflow(OPJ_SS_(i), OPJ_SS_(i + 1)), + 2) >> 2); } for (i = win_h_x0; i < win_h_x1; i++) { - OPJ_S(i) += (OPJ_DD_(i) + OPJ_DD_(i - 1)) >> 1; + OPJ_S(i) = opj_int_add_no_overflow(OPJ_S(i), + opj_int_add_no_overflow(OPJ_DD_(i), OPJ_DD_(i - 1)) >> 1); } } } @@ -1801,12 +2702,17 @@ static void opj_dwt_decode_partial_1_parallel(OPJ_INT32 *a, } else { for (i = win_l_x0; i < win_l_x1; i++) { for (off = 0; off < 4; off++) { - OPJ_D_off(i, off) -= (OPJ_SS__off(i, off) + OPJ_SS__off(i + 1, off) + 2) >> 2; + OPJ_D_off(i, off) = opj_int_sub_no_overflow( + OPJ_D_off(i, off), + opj_int_add_no_overflow( + opj_int_add_no_overflow(OPJ_SS__off(i, off), OPJ_SS__off(i + 1, off)), 2) >> 2); } } for (i = win_h_x0; i < win_h_x1; i++) { for (off = 0; off < 4; off++) { - OPJ_S_off(i, off) += (OPJ_DD__off(i, off) + OPJ_DD__off(i - 1, off)) >> 1; + OPJ_S_off(i, off) = opj_int_add_no_overflow( + OPJ_S_off(i, off), + opj_int_add_no_overflow(OPJ_DD__off(i, off), OPJ_DD__off(i - 1, off)) >> 1); } } } @@ -2041,7 +2947,7 @@ static OPJ_BOOL opj_dwt_decode_partial_tile( tr_hl_x0 = (OPJ_UINT32)tr->bands[0].x0; tr_lh_y0 = (OPJ_UINT32)tr->bands[1].y0; - /* Substract the origin of the bands for this tile, to the subwindow */ + /* Subtract the origin of the bands for this tile, to the subwindow */ /* of interest band coordinates, so as to get them relative to the */ /* tile */ win_ll_x0 = opj_uint_subs(win_ll_x0, tr_ll_x0); @@ -2168,7 +3074,7 @@ static OPJ_BOOL opj_dwt_decode_partial_tile( return OPJ_TRUE; } -static void opj_v4dwt_interleave_h(opj_v4dwt_t* OPJ_RESTRICT dwt, +static void opj_v8dwt_interleave_h(opj_v8dwt_t* OPJ_RESTRICT dwt, OPJ_FLOAT32* OPJ_RESTRICT a, OPJ_UINT32 width, OPJ_UINT32 remaining_height) @@ -2179,39 +3085,69 @@ static void opj_v4dwt_interleave_h(opj_v4dwt_t* OPJ_RESTRICT dwt, OPJ_UINT32 x1 = dwt->win_l_x1; for (k = 0; k < 2; ++k) { - if (remaining_height >= 4 && ((OPJ_SIZE_T) a & 0x0f) == 0 && - ((OPJ_SIZE_T) bi & 0x0f) == 0 && (width & 0x0f) == 0) { + if (remaining_height >= NB_ELTS_V8 && ((OPJ_SIZE_T) a & 0x0f) == 0 && + ((OPJ_SIZE_T) bi & 0x0f) == 0) { /* Fast code path */ for (i = x0; i < x1; ++i) { OPJ_UINT32 j = i; - bi[i * 8 ] = a[j]; + OPJ_FLOAT32* OPJ_RESTRICT dst = bi + i * 2 * NB_ELTS_V8; + dst[0] = a[j]; + j += width; + dst[1] = a[j]; j += width; - bi[i * 8 + 1] = a[j]; + dst[2] = a[j]; j += width; - bi[i * 8 + 2] = a[j]; + dst[3] = a[j]; j += width; - bi[i * 8 + 3] = a[j]; + dst[4] = a[j]; + j += width; + dst[5] = a[j]; + j += width; + dst[6] = a[j]; + j += width; + dst[7] = a[j]; } } else { /* Slow code path */ for (i = x0; i < x1; ++i) { OPJ_UINT32 j = i; - bi[i * 8 ] = a[j]; + OPJ_FLOAT32* OPJ_RESTRICT dst = bi + i * 2 * NB_ELTS_V8; + dst[0] = a[j]; j += width; if (remaining_height == 1) { continue; } - bi[i * 8 + 1] = a[j]; + dst[1] = a[j]; j += width; if (remaining_height == 2) { continue; } - bi[i * 8 + 2] = a[j]; + dst[2] = a[j]; j += width; if (remaining_height == 3) { continue; } - bi[i * 8 + 3] = a[j]; /* This one*/ + dst[3] = a[j]; + j += width; + if (remaining_height == 4) { + continue; + } + dst[4] = a[j]; + j += width; + if (remaining_height == 5) { + continue; + } + dst[5] = a[j]; + j += width; + if (remaining_height == 6) { + continue; + } + dst[6] = a[j]; + j += width; + if (remaining_height == 7) { + continue; + } + dst[7] = a[j]; } } @@ -2222,7 +3158,7 @@ static void opj_v4dwt_interleave_h(opj_v4dwt_t* OPJ_RESTRICT dwt, } } -static void opj_v4dwt_interleave_partial_h(opj_v4dwt_t* dwt, +static void opj_v8dwt_interleave_partial_h(opj_v8dwt_t* dwt, opj_sparse_array_int32_t* sa, OPJ_UINT32 sa_line, OPJ_UINT32 remaining_height) @@ -2235,25 +3171,25 @@ static void opj_v4dwt_interleave_partial_h(opj_v4dwt_t* dwt, dwt->win_l_x1, sa_line + i + 1, /* Nasty cast from float* to int32* */ (OPJ_INT32*)(dwt->wavelet + dwt->cas + 2 * dwt->win_l_x0) + i, - 8, 0, OPJ_TRUE); + 2 * NB_ELTS_V8, 0, OPJ_TRUE); assert(ret); ret = opj_sparse_array_int32_read(sa, (OPJ_UINT32)dwt->sn + dwt->win_h_x0, sa_line + i, (OPJ_UINT32)dwt->sn + dwt->win_h_x1, sa_line + i + 1, /* Nasty cast from float* to int32* */ (OPJ_INT32*)(dwt->wavelet + 1 - dwt->cas + 2 * dwt->win_h_x0) + i, - 8, 0, OPJ_TRUE); + 2 * NB_ELTS_V8, 0, OPJ_TRUE); assert(ret); OPJ_UNUSED(ret); } } -static void opj_v4dwt_interleave_v(opj_v4dwt_t* OPJ_RESTRICT dwt, - OPJ_FLOAT32* OPJ_RESTRICT a, - OPJ_UINT32 width, - OPJ_UINT32 nb_elts_read) +static INLINE void opj_v8dwt_interleave_v(opj_v8dwt_t* OPJ_RESTRICT dwt, + OPJ_FLOAT32* OPJ_RESTRICT a, + OPJ_UINT32 width, + OPJ_UINT32 nb_elts_read) { - opj_v4_t* OPJ_RESTRICT bi = dwt->wavelet + dwt->cas; + opj_v8_t* OPJ_RESTRICT bi = dwt->wavelet + dwt->cas; OPJ_UINT32 i; for (i = dwt->win_l_x0; i < dwt->win_l_x1; ++i) { @@ -2270,7 +3206,7 @@ static void opj_v4dwt_interleave_v(opj_v4dwt_t* OPJ_RESTRICT dwt, } } -static void opj_v4dwt_interleave_partial_v(opj_v4dwt_t* OPJ_RESTRICT dwt, +static void opj_v8dwt_interleave_partial_v(opj_v8dwt_t* OPJ_RESTRICT dwt, opj_sparse_array_int32_t* sa, OPJ_UINT32 sa_col, OPJ_UINT32 nb_elts_read) @@ -2280,44 +3216,36 @@ static void opj_v4dwt_interleave_partial_v(opj_v4dwt_t* OPJ_RESTRICT dwt, sa_col, dwt->win_l_x0, sa_col + nb_elts_read, dwt->win_l_x1, (OPJ_INT32*)(dwt->wavelet + dwt->cas + 2 * dwt->win_l_x0), - 1, 8, OPJ_TRUE); + 1, 2 * NB_ELTS_V8, OPJ_TRUE); assert(ret); ret = opj_sparse_array_int32_read(sa, sa_col, (OPJ_UINT32)dwt->sn + dwt->win_h_x0, sa_col + nb_elts_read, (OPJ_UINT32)dwt->sn + dwt->win_h_x1, (OPJ_INT32*)(dwt->wavelet + 1 - dwt->cas + 2 * dwt->win_h_x0), - 1, 8, OPJ_TRUE); + 1, 2 * NB_ELTS_V8, OPJ_TRUE); assert(ret); OPJ_UNUSED(ret); } #ifdef __SSE__ -static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, +static void opj_v8dwt_decode_step1_sse(opj_v8_t* w, OPJ_UINT32 start, OPJ_UINT32 end, const __m128 c) { __m128* OPJ_RESTRICT vw = (__m128*) w; - OPJ_UINT32 i; - /* 4x unrolled loop */ - vw += 2 * start; - for (i = start; i + 3 < end; i += 4, vw += 8) { - __m128 xmm0 = _mm_mul_ps(vw[0], c); - __m128 xmm2 = _mm_mul_ps(vw[2], c); - __m128 xmm4 = _mm_mul_ps(vw[4], c); - __m128 xmm6 = _mm_mul_ps(vw[6], c); - vw[0] = xmm0; - vw[2] = xmm2; - vw[4] = xmm4; - vw[6] = xmm6; - } - for (; i < end; ++i, vw += 2) { + OPJ_UINT32 i = start; + /* To be adapted if NB_ELTS_V8 changes */ + vw += 4 * start; + /* Note: attempt at loop unrolling x2 doesn't help */ + for (; i < end; ++i, vw += 4) { vw[0] = _mm_mul_ps(vw[0], c); + vw[1] = _mm_mul_ps(vw[1], c); } } -static void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, +static void opj_v8dwt_decode_step2_sse(opj_v8_t* l, opj_v8_t* w, OPJ_UINT32 start, OPJ_UINT32 end, OPJ_UINT32 m, @@ -2325,74 +3253,58 @@ static void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, { __m128* OPJ_RESTRICT vl = (__m128*) l; __m128* OPJ_RESTRICT vw = (__m128*) w; + /* To be adapted if NB_ELTS_V8 changes */ OPJ_UINT32 i; OPJ_UINT32 imax = opj_uint_min(end, m); - __m128 tmp1, tmp2, tmp3; if (start == 0) { - tmp1 = vl[0]; + if (imax >= 1) { + vw[-2] = _mm_add_ps(vw[-2], _mm_mul_ps(_mm_add_ps(vl[0], vw[0]), c)); + vw[-1] = _mm_add_ps(vw[-1], _mm_mul_ps(_mm_add_ps(vl[1], vw[1]), c)); + vw += 4; + start = 1; + } } else { - vw += start * 2; - tmp1 = vw[-3]; + vw += start * 4; } i = start; - - /* 4x loop unrolling */ - for (; i + 3 < imax; i += 4) { - __m128 tmp4, tmp5, tmp6, tmp7, tmp8, tmp9; - tmp2 = vw[-1]; - tmp3 = vw[ 0]; - tmp4 = vw[ 1]; - tmp5 = vw[ 2]; - tmp6 = vw[ 3]; - tmp7 = vw[ 4]; - tmp8 = vw[ 5]; - tmp9 = vw[ 6]; - vw[-1] = _mm_add_ps(tmp2, _mm_mul_ps(_mm_add_ps(tmp1, tmp3), c)); - vw[ 1] = _mm_add_ps(tmp4, _mm_mul_ps(_mm_add_ps(tmp3, tmp5), c)); - vw[ 3] = _mm_add_ps(tmp6, _mm_mul_ps(_mm_add_ps(tmp5, tmp7), c)); - vw[ 5] = _mm_add_ps(tmp8, _mm_mul_ps(_mm_add_ps(tmp7, tmp9), c)); - tmp1 = tmp9; - vw += 8; - } - + /* Note: attempt at loop unrolling x2 doesn't help */ for (; i < imax; ++i) { - tmp2 = vw[-1]; - tmp3 = vw[ 0]; - vw[-1] = _mm_add_ps(tmp2, _mm_mul_ps(_mm_add_ps(tmp1, tmp3), c)); - tmp1 = tmp3; - vw += 2; + vw[-2] = _mm_add_ps(vw[-2], _mm_mul_ps(_mm_add_ps(vw[-4], vw[0]), c)); + vw[-1] = _mm_add_ps(vw[-1], _mm_mul_ps(_mm_add_ps(vw[-3], vw[1]), c)); + vw += 4; } if (m < end) { assert(m + 1 == end); c = _mm_add_ps(c, c); - c = _mm_mul_ps(c, vw[-2]); - vw[-1] = _mm_add_ps(vw[-1], c); + vw[-2] = _mm_add_ps(vw[-2], _mm_mul_ps(c, vw[-4])); + vw[-1] = _mm_add_ps(vw[-1], _mm_mul_ps(c, vw[-3])); } } #else -static void opj_v4dwt_decode_step1(opj_v4_t* w, +static void opj_v8dwt_decode_step1(opj_v8_t* w, OPJ_UINT32 start, OPJ_UINT32 end, const OPJ_FLOAT32 c) { OPJ_FLOAT32* OPJ_RESTRICT fw = (OPJ_FLOAT32*) w; OPJ_UINT32 i; + /* To be adapted if NB_ELTS_V8 changes */ for (i = start; i < end; ++i) { - OPJ_FLOAT32 tmp1 = fw[i * 8 ]; - OPJ_FLOAT32 tmp2 = fw[i * 8 + 1]; - OPJ_FLOAT32 tmp3 = fw[i * 8 + 2]; - OPJ_FLOAT32 tmp4 = fw[i * 8 + 3]; - fw[i * 8 ] = tmp1 * c; - fw[i * 8 + 1] = tmp2 * c; - fw[i * 8 + 2] = tmp3 * c; - fw[i * 8 + 3] = tmp4 * c; + fw[i * 2 * 8 ] = fw[i * 2 * 8 ] * c; + fw[i * 2 * 8 + 1] = fw[i * 2 * 8 + 1] * c; + fw[i * 2 * 8 + 2] = fw[i * 2 * 8 + 2] * c; + fw[i * 2 * 8 + 3] = fw[i * 2 * 8 + 3] * c; + fw[i * 2 * 8 + 4] = fw[i * 2 * 8 + 4] * c; + fw[i * 2 * 8 + 5] = fw[i * 2 * 8 + 5] * c; + fw[i * 2 * 8 + 6] = fw[i * 2 * 8 + 6] * c; + fw[i * 2 * 8 + 7] = fw[i * 2 * 8 + 7] * c; } } -static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, +static void opj_v8dwt_decode_step2(opj_v8_t* l, opj_v8_t* w, OPJ_UINT32 start, OPJ_UINT32 end, OPJ_UINT32 m, @@ -2403,36 +3315,33 @@ static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_UINT32 i; OPJ_UINT32 imax = opj_uint_min(end, m); if (start > 0) { - fw += 8 * start; - fl = fw - 8; + fw += 2 * NB_ELTS_V8 * start; + fl = fw - 2 * NB_ELTS_V8; } + /* To be adapted if NB_ELTS_V8 changes */ for (i = start; i < imax; ++i) { - OPJ_FLOAT32 tmp1_1 = fl[0]; - OPJ_FLOAT32 tmp1_2 = fl[1]; - OPJ_FLOAT32 tmp1_3 = fl[2]; - OPJ_FLOAT32 tmp1_4 = fl[3]; - OPJ_FLOAT32 tmp2_1 = fw[-4]; - OPJ_FLOAT32 tmp2_2 = fw[-3]; - OPJ_FLOAT32 tmp2_3 = fw[-2]; - OPJ_FLOAT32 tmp2_4 = fw[-1]; - OPJ_FLOAT32 tmp3_1 = fw[0]; - OPJ_FLOAT32 tmp3_2 = fw[1]; - OPJ_FLOAT32 tmp3_3 = fw[2]; - OPJ_FLOAT32 tmp3_4 = fw[3]; - fw[-4] = tmp2_1 + ((tmp1_1 + tmp3_1) * c); - fw[-3] = tmp2_2 + ((tmp1_2 + tmp3_2) * c); - fw[-2] = tmp2_3 + ((tmp1_3 + tmp3_3) * c); - fw[-1] = tmp2_4 + ((tmp1_4 + tmp3_4) * c); + fw[-8] = fw[-8] + ((fl[0] + fw[0]) * c); + fw[-7] = fw[-7] + ((fl[1] + fw[1]) * c); + fw[-6] = fw[-6] + ((fl[2] + fw[2]) * c); + fw[-5] = fw[-5] + ((fl[3] + fw[3]) * c); + fw[-4] = fw[-4] + ((fl[4] + fw[4]) * c); + fw[-3] = fw[-3] + ((fl[5] + fw[5]) * c); + fw[-2] = fw[-2] + ((fl[6] + fw[6]) * c); + fw[-1] = fw[-1] + ((fl[7] + fw[7]) * c); fl = fw; - fw += 8; + fw += 2 * NB_ELTS_V8; } if (m < end) { assert(m + 1 == end); c += c; - fw[-4] = fw[-4] + fl[0] * c; - fw[-3] = fw[-3] + fl[1] * c; - fw[-2] = fw[-2] + fl[2] * c; - fw[-1] = fw[-1] + fl[3] * c; + fw[-8] = fw[-8] + fl[0] * c; + fw[-7] = fw[-7] + fl[1] * c; + fw[-6] = fw[-6] + fl[2] * c; + fw[-5] = fw[-5] + fl[3] * c; + fw[-4] = fw[-4] + fl[4] * c; + fw[-3] = fw[-3] + fl[5] * c; + fw[-2] = fw[-2] + fl[6] * c; + fw[-1] = fw[-1] + fl[7] * c; } } @@ -2441,9 +3350,17 @@ static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, /* */ /* Inverse 9-7 wavelet transform in 1-D. */ /* */ -static void opj_v4dwt_decode(opj_v4dwt_t* OPJ_RESTRICT dwt) +static void opj_v8dwt_decode(opj_v8dwt_t* OPJ_RESTRICT dwt) { OPJ_INT32 a, b; + /* BUG_WEIRD_TWO_INVK (look for this identifier in tcd.c) */ + /* Historic value for 2 / opj_invK */ + /* Normally, we should use invK, but if we do so, we have failures in the */ + /* conformance test, due to MSE and peak errors significantly higher than */ + /* accepted value */ + /* Due to using two_invK instead of invK, we have to compensate in tcd.c */ + /* the computation of the stepsize for the non LL subbands */ + const float two_invK = 1.625732422f; if (dwt->cas == 0) { if (!((dwt->dn > 0) || (dwt->sn > 1))) { return; @@ -2458,60 +3375,147 @@ static void opj_v4dwt_decode(opj_v4dwt_t* OPJ_RESTRICT dwt) b = 0; } #ifdef __SSE__ - opj_v4dwt_decode_step1_sse(dwt->wavelet + a, dwt->win_l_x0, dwt->win_l_x1, + opj_v8dwt_decode_step1_sse(dwt->wavelet + a, dwt->win_l_x0, dwt->win_l_x1, _mm_set1_ps(opj_K)); - opj_v4dwt_decode_step1_sse(dwt->wavelet + b, dwt->win_h_x0, dwt->win_h_x1, - _mm_set1_ps(opj_c13318)); - opj_v4dwt_decode_step2_sse(dwt->wavelet + b, dwt->wavelet + a + 1, + opj_v8dwt_decode_step1_sse(dwt->wavelet + b, dwt->win_h_x0, dwt->win_h_x1, + _mm_set1_ps(two_invK)); + opj_v8dwt_decode_step2_sse(dwt->wavelet + b, dwt->wavelet + a + 1, dwt->win_l_x0, dwt->win_l_x1, (OPJ_UINT32)opj_int_min(dwt->sn, dwt->dn - a), - _mm_set1_ps(opj_dwt_delta)); - opj_v4dwt_decode_step2_sse(dwt->wavelet + a, dwt->wavelet + b + 1, + _mm_set1_ps(-opj_dwt_delta)); + opj_v8dwt_decode_step2_sse(dwt->wavelet + a, dwt->wavelet + b + 1, dwt->win_h_x0, dwt->win_h_x1, (OPJ_UINT32)opj_int_min(dwt->dn, dwt->sn - b), - _mm_set1_ps(opj_dwt_gamma)); - opj_v4dwt_decode_step2_sse(dwt->wavelet + b, dwt->wavelet + a + 1, + _mm_set1_ps(-opj_dwt_gamma)); + opj_v8dwt_decode_step2_sse(dwt->wavelet + b, dwt->wavelet + a + 1, dwt->win_l_x0, dwt->win_l_x1, (OPJ_UINT32)opj_int_min(dwt->sn, dwt->dn - a), - _mm_set1_ps(opj_dwt_beta)); - opj_v4dwt_decode_step2_sse(dwt->wavelet + a, dwt->wavelet + b + 1, + _mm_set1_ps(-opj_dwt_beta)); + opj_v8dwt_decode_step2_sse(dwt->wavelet + a, dwt->wavelet + b + 1, dwt->win_h_x0, dwt->win_h_x1, (OPJ_UINT32)opj_int_min(dwt->dn, dwt->sn - b), - _mm_set1_ps(opj_dwt_alpha)); + _mm_set1_ps(-opj_dwt_alpha)); #else - opj_v4dwt_decode_step1(dwt->wavelet + a, dwt->win_l_x0, dwt->win_l_x1, + opj_v8dwt_decode_step1(dwt->wavelet + a, dwt->win_l_x0, dwt->win_l_x1, opj_K); - opj_v4dwt_decode_step1(dwt->wavelet + b, dwt->win_h_x0, dwt->win_h_x1, - opj_c13318); - opj_v4dwt_decode_step2(dwt->wavelet + b, dwt->wavelet + a + 1, + opj_v8dwt_decode_step1(dwt->wavelet + b, dwt->win_h_x0, dwt->win_h_x1, + two_invK); + opj_v8dwt_decode_step2(dwt->wavelet + b, dwt->wavelet + a + 1, dwt->win_l_x0, dwt->win_l_x1, (OPJ_UINT32)opj_int_min(dwt->sn, dwt->dn - a), - opj_dwt_delta); - opj_v4dwt_decode_step2(dwt->wavelet + a, dwt->wavelet + b + 1, + -opj_dwt_delta); + opj_v8dwt_decode_step2(dwt->wavelet + a, dwt->wavelet + b + 1, dwt->win_h_x0, dwt->win_h_x1, (OPJ_UINT32)opj_int_min(dwt->dn, dwt->sn - b), - opj_dwt_gamma); - opj_v4dwt_decode_step2(dwt->wavelet + b, dwt->wavelet + a + 1, + -opj_dwt_gamma); + opj_v8dwt_decode_step2(dwt->wavelet + b, dwt->wavelet + a + 1, dwt->win_l_x0, dwt->win_l_x1, (OPJ_UINT32)opj_int_min(dwt->sn, dwt->dn - a), - opj_dwt_beta); - opj_v4dwt_decode_step2(dwt->wavelet + a, dwt->wavelet + b + 1, + -opj_dwt_beta); + opj_v8dwt_decode_step2(dwt->wavelet + a, dwt->wavelet + b + 1, dwt->win_h_x0, dwt->win_h_x1, (OPJ_UINT32)opj_int_min(dwt->dn, dwt->sn - b), - opj_dwt_alpha); + -opj_dwt_alpha); #endif } +typedef struct { + opj_v8dwt_t h; + OPJ_UINT32 rw; + OPJ_UINT32 w; + OPJ_FLOAT32 * OPJ_RESTRICT aj; + OPJ_UINT32 nb_rows; +} opj_dwt97_decode_h_job_t; + +static void opj_dwt97_decode_h_func(void* user_data, opj_tls_t* tls) +{ + OPJ_UINT32 j; + opj_dwt97_decode_h_job_t* job; + OPJ_FLOAT32 * OPJ_RESTRICT aj; + OPJ_UINT32 w; + (void)tls; + + job = (opj_dwt97_decode_h_job_t*)user_data; + w = job->w; + + assert((job->nb_rows % NB_ELTS_V8) == 0); + + aj = job->aj; + for (j = 0; j + NB_ELTS_V8 <= job->nb_rows; j += NB_ELTS_V8) { + OPJ_UINT32 k; + opj_v8dwt_interleave_h(&job->h, aj, job->w, NB_ELTS_V8); + opj_v8dwt_decode(&job->h); + + /* To be adapted if NB_ELTS_V8 changes */ + for (k = 0; k < job->rw; k++) { + aj[k ] = job->h.wavelet[k].f[0]; + aj[k + (OPJ_SIZE_T)w ] = job->h.wavelet[k].f[1]; + aj[k + (OPJ_SIZE_T)w * 2] = job->h.wavelet[k].f[2]; + aj[k + (OPJ_SIZE_T)w * 3] = job->h.wavelet[k].f[3]; + } + for (k = 0; k < job->rw; k++) { + aj[k + (OPJ_SIZE_T)w * 4] = job->h.wavelet[k].f[4]; + aj[k + (OPJ_SIZE_T)w * 5] = job->h.wavelet[k].f[5]; + aj[k + (OPJ_SIZE_T)w * 6] = job->h.wavelet[k].f[6]; + aj[k + (OPJ_SIZE_T)w * 7] = job->h.wavelet[k].f[7]; + } + + aj += w * NB_ELTS_V8; + } + + opj_aligned_free(job->h.wavelet); + opj_free(job); +} + + +typedef struct { + opj_v8dwt_t v; + OPJ_UINT32 rh; + OPJ_UINT32 w; + OPJ_FLOAT32 * OPJ_RESTRICT aj; + OPJ_UINT32 nb_columns; +} opj_dwt97_decode_v_job_t; + +static void opj_dwt97_decode_v_func(void* user_data, opj_tls_t* tls) +{ + OPJ_UINT32 j; + opj_dwt97_decode_v_job_t* job; + OPJ_FLOAT32 * OPJ_RESTRICT aj; + (void)tls; + + job = (opj_dwt97_decode_v_job_t*)user_data; + + assert((job->nb_columns % NB_ELTS_V8) == 0); + + aj = job->aj; + for (j = 0; j + NB_ELTS_V8 <= job->nb_columns; j += NB_ELTS_V8) { + OPJ_UINT32 k; + + opj_v8dwt_interleave_v(&job->v, aj, job->w, NB_ELTS_V8); + opj_v8dwt_decode(&job->v); + + for (k = 0; k < job->rh; ++k) { + memcpy(&aj[k * (OPJ_SIZE_T)job->w], &job->v.wavelet[k], + NB_ELTS_V8 * sizeof(OPJ_FLOAT32)); + } + aj += NB_ELTS_V8; + } + + opj_aligned_free(job->v.wavelet); + opj_free(job); +} + /* */ /* Inverse 9-7 wavelet transform in 2-D. */ /* */ static -OPJ_BOOL opj_dwt_decode_tile_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, +OPJ_BOOL opj_dwt_decode_tile_97(opj_thread_pool_t* tp, + opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, OPJ_UINT32 numres) { - opj_v4dwt_t h; - opj_v4dwt_t v; + opj_v8dwt_t h; + opj_v8dwt_t v; opj_tcd_resolution_t* res = tilec->resolutions; @@ -2525,20 +3529,19 @@ OPJ_BOOL opj_dwt_decode_tile_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, tilec->resolutions[tilec->minimum_num_resolutions - 1].x0); OPJ_SIZE_T l_data_size; + const int num_threads = opj_thread_pool_get_thread_count(tp); - l_data_size = opj_dwt_max_resolution(res, numres); - /* overflow check */ - if (l_data_size > (SIZE_MAX - 5U)) { - /* FIXME event manager error callback */ - return OPJ_FALSE; + if (numres == 1) { + return OPJ_TRUE; } - l_data_size += 5U; + + l_data_size = opj_dwt_max_resolution(res, numres); /* overflow check */ - if (l_data_size > (SIZE_MAX / sizeof(opj_v4_t))) { + if (l_data_size > (SIZE_MAX / sizeof(opj_v8_t))) { /* FIXME event manager error callback */ return OPJ_FALSE; } - h.wavelet = (opj_v4_t*) opj_aligned_malloc(l_data_size * sizeof(opj_v4_t)); + h.wavelet = (opj_v8_t*) opj_aligned_malloc(l_data_size * sizeof(opj_v8_t)); if (!h.wavelet) { /* FIXME event manager error callback */ return OPJ_FALSE; @@ -2566,35 +3569,80 @@ OPJ_BOOL opj_dwt_decode_tile_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, h.win_l_x1 = (OPJ_UINT32)h.sn; h.win_h_x0 = 0; h.win_h_x1 = (OPJ_UINT32)h.dn; - for (j = 0; j + 3 < rh; j += 4) { - OPJ_UINT32 k; - opj_v4dwt_interleave_h(&h, aj, w, rh - j); - opj_v4dwt_decode(&h); - for (k = 0; k < rw; k++) { - aj[k ] = h.wavelet[k].f[0]; - aj[k + (OPJ_SIZE_T)w ] = h.wavelet[k].f[1]; - aj[k + (OPJ_SIZE_T)w * 2] = h.wavelet[k].f[2]; - aj[k + (OPJ_SIZE_T)w * 3] = h.wavelet[k].f[3]; + if (num_threads <= 1 || rh < 2 * NB_ELTS_V8) { + for (j = 0; j + (NB_ELTS_V8 - 1) < rh; j += NB_ELTS_V8) { + OPJ_UINT32 k; + opj_v8dwt_interleave_h(&h, aj, w, NB_ELTS_V8); + opj_v8dwt_decode(&h); + + /* To be adapted if NB_ELTS_V8 changes */ + for (k = 0; k < rw; k++) { + aj[k ] = h.wavelet[k].f[0]; + aj[k + (OPJ_SIZE_T)w ] = h.wavelet[k].f[1]; + aj[k + (OPJ_SIZE_T)w * 2] = h.wavelet[k].f[2]; + aj[k + (OPJ_SIZE_T)w * 3] = h.wavelet[k].f[3]; + } + for (k = 0; k < rw; k++) { + aj[k + (OPJ_SIZE_T)w * 4] = h.wavelet[k].f[4]; + aj[k + (OPJ_SIZE_T)w * 5] = h.wavelet[k].f[5]; + aj[k + (OPJ_SIZE_T)w * 6] = h.wavelet[k].f[6]; + aj[k + (OPJ_SIZE_T)w * 7] = h.wavelet[k].f[7]; + } + + aj += w * NB_ELTS_V8; + } + } else { + OPJ_UINT32 num_jobs = (OPJ_UINT32)num_threads; + OPJ_UINT32 step_j; + + if ((rh / NB_ELTS_V8) < num_jobs) { + num_jobs = rh / NB_ELTS_V8; } + step_j = ((rh / num_jobs) / NB_ELTS_V8) * NB_ELTS_V8; + for (j = 0; j < num_jobs; j++) { + opj_dwt97_decode_h_job_t* job; - aj += w * 4; + job = (opj_dwt97_decode_h_job_t*) opj_malloc(sizeof(opj_dwt97_decode_h_job_t)); + if (!job) { + opj_thread_pool_wait_completion(tp, 0); + opj_aligned_free(h.wavelet); + return OPJ_FALSE; + } + job->h.wavelet = (opj_v8_t*)opj_aligned_malloc(l_data_size * sizeof(opj_v8_t)); + if (!job->h.wavelet) { + opj_thread_pool_wait_completion(tp, 0); + opj_free(job); + opj_aligned_free(h.wavelet); + return OPJ_FALSE; + } + job->h.dn = h.dn; + job->h.sn = h.sn; + job->h.cas = h.cas; + job->h.win_l_x0 = h.win_l_x0; + job->h.win_l_x1 = h.win_l_x1; + job->h.win_h_x0 = h.win_h_x0; + job->h.win_h_x1 = h.win_h_x1; + job->rw = rw; + job->w = w; + job->aj = aj; + job->nb_rows = (j + 1 == num_jobs) ? (rh & (OPJ_UINT32)~ + (NB_ELTS_V8 - 1)) - j * step_j : step_j; + aj += w * job->nb_rows; + opj_thread_pool_submit_job(tp, opj_dwt97_decode_h_func, job); + } + opj_thread_pool_wait_completion(tp, 0); + j = rh & (OPJ_UINT32)~(NB_ELTS_V8 - 1); } if (j < rh) { OPJ_UINT32 k; - opj_v4dwt_interleave_h(&h, aj, w, rh - j); - opj_v4dwt_decode(&h); + opj_v8dwt_interleave_h(&h, aj, w, rh - j); + opj_v8dwt_decode(&h); for (k = 0; k < rw; k++) { - switch (rh - j) { - case 3: - aj[k + (OPJ_SIZE_T)w * 2] = h.wavelet[k].f[2]; - /* FALLTHRU */ - case 2: - aj[k + (OPJ_SIZE_T)w ] = h.wavelet[k].f[1]; - /* FALLTHRU */ - case 1: - aj[k] = h.wavelet[k].f[0]; + OPJ_UINT32 l; + for (l = 0; l < rh - j; l++) { + aj[k + (OPJ_SIZE_T)w * l ] = h.wavelet[k].f[l]; } } } @@ -2607,25 +3655,71 @@ OPJ_BOOL opj_dwt_decode_tile_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, v.win_h_x1 = (OPJ_UINT32)v.dn; aj = (OPJ_FLOAT32*) tilec->data; - for (j = rw; j > 3; j -= 4) { - OPJ_UINT32 k; + if (num_threads <= 1 || rw < 2 * NB_ELTS_V8) { + for (j = rw; j > (NB_ELTS_V8 - 1); j -= NB_ELTS_V8) { + OPJ_UINT32 k; - opj_v4dwt_interleave_v(&v, aj, w, 4); - opj_v4dwt_decode(&v); + opj_v8dwt_interleave_v(&v, aj, w, NB_ELTS_V8); + opj_v8dwt_decode(&v); - for (k = 0; k < rh; ++k) { - memcpy(&aj[k * (OPJ_SIZE_T)w], &v.wavelet[k], 4 * sizeof(OPJ_FLOAT32)); + for (k = 0; k < rh; ++k) { + memcpy(&aj[k * (OPJ_SIZE_T)w], &v.wavelet[k], NB_ELTS_V8 * sizeof(OPJ_FLOAT32)); + } + aj += NB_ELTS_V8; + } + } else { + /* "bench_dwt -I" shows that scaling is poor, likely due to RAM + transfer being the limiting factor. So limit the number of + threads. + */ + OPJ_UINT32 num_jobs = opj_uint_max((OPJ_UINT32)num_threads / 2, 2U); + OPJ_UINT32 step_j; + + if ((rw / NB_ELTS_V8) < num_jobs) { + num_jobs = rw / NB_ELTS_V8; + } + step_j = ((rw / num_jobs) / NB_ELTS_V8) * NB_ELTS_V8; + for (j = 0; j < num_jobs; j++) { + opj_dwt97_decode_v_job_t* job; + + job = (opj_dwt97_decode_v_job_t*) opj_malloc(sizeof(opj_dwt97_decode_v_job_t)); + if (!job) { + opj_thread_pool_wait_completion(tp, 0); + opj_aligned_free(h.wavelet); + return OPJ_FALSE; + } + job->v.wavelet = (opj_v8_t*)opj_aligned_malloc(l_data_size * sizeof(opj_v8_t)); + if (!job->v.wavelet) { + opj_thread_pool_wait_completion(tp, 0); + opj_free(job); + opj_aligned_free(h.wavelet); + return OPJ_FALSE; + } + job->v.dn = v.dn; + job->v.sn = v.sn; + job->v.cas = v.cas; + job->v.win_l_x0 = v.win_l_x0; + job->v.win_l_x1 = v.win_l_x1; + job->v.win_h_x0 = v.win_h_x0; + job->v.win_h_x1 = v.win_h_x1; + job->rh = rh; + job->w = w; + job->aj = aj; + job->nb_columns = (j + 1 == num_jobs) ? (rw & (OPJ_UINT32)~ + (NB_ELTS_V8 - 1)) - j * step_j : step_j; + aj += job->nb_columns; + opj_thread_pool_submit_job(tp, opj_dwt97_decode_v_func, job); } - aj += 4; + opj_thread_pool_wait_completion(tp, 0); } - if (rw & 0x03) { + if (rw & (NB_ELTS_V8 - 1)) { OPJ_UINT32 k; - j = rw & 0x03; + j = rw & (NB_ELTS_V8 - 1); - opj_v4dwt_interleave_v(&v, aj, w, j); - opj_v4dwt_decode(&v); + opj_v8dwt_interleave_v(&v, aj, w, j); + opj_v8dwt_decode(&v); for (k = 0; k < rh; ++k) { memcpy(&aj[k * (OPJ_SIZE_T)w], &v.wavelet[k], @@ -2643,8 +3737,8 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, OPJ_UINT32 numres) { opj_sparse_array_int32_t* sa; - opj_v4dwt_t h; - opj_v4dwt_t v; + opj_v8dwt_t h; + opj_v8dwt_t v; OPJ_UINT32 resno; /* This value matches the maximum left/right extension given in tables */ /* F.2 and F.3 of the standard. Note: in opj_tcd_is_subband_area_of_interest() */ @@ -2694,19 +3788,15 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, l_data_size = opj_dwt_max_resolution(tr, numres); /* overflow check */ - if (l_data_size > (SIZE_MAX - 5U)) { - /* FIXME event manager error callback */ - return OPJ_FALSE; - } - l_data_size += 5U; - /* overflow check */ - if (l_data_size > (SIZE_MAX / sizeof(opj_v4_t))) { + if (l_data_size > (SIZE_MAX / sizeof(opj_v8_t))) { /* FIXME event manager error callback */ + opj_sparse_array_int32_free(sa); return OPJ_FALSE; } - h.wavelet = (opj_v4_t*) opj_aligned_malloc(l_data_size * sizeof(opj_v4_t)); + h.wavelet = (opj_v8_t*) opj_aligned_malloc(l_data_size * sizeof(opj_v8_t)); if (!h.wavelet) { /* FIXME event manager error callback */ + opj_sparse_array_int32_free(sa); return OPJ_FALSE; } v.wavelet = h.wavelet; @@ -2759,7 +3849,7 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, tr_hl_x0 = (OPJ_UINT32)tr->bands[0].x0; tr_lh_y0 = (OPJ_UINT32)tr->bands[1].y0; - /* Substract the origin of the bands for this tile, to the subwindow */ + /* Subtract the origin of the bands for this tile, to the subwindow */ /* of interest band coordinates, so as to get them relative to the */ /* tile */ win_ll_x0 = opj_uint_subs(win_ll_x0, tr_ll_x0); @@ -2798,17 +3888,17 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, h.win_l_x1 = win_ll_x1; h.win_h_x0 = win_hl_x0; h.win_h_x1 = win_hl_x1; - for (j = 0; j + 3 < rh; j += 4) { - if ((j + 3 >= win_ll_y0 && j < win_ll_y1) || - (j + 3 >= win_lh_y0 + (OPJ_UINT32)v.sn && + for (j = 0; j + (NB_ELTS_V8 - 1) < rh; j += NB_ELTS_V8) { + if ((j + (NB_ELTS_V8 - 1) >= win_ll_y0 && j < win_ll_y1) || + (j + (NB_ELTS_V8 - 1) >= win_lh_y0 + (OPJ_UINT32)v.sn && j < win_lh_y1 + (OPJ_UINT32)v.sn)) { - opj_v4dwt_interleave_partial_h(&h, sa, j, opj_uint_min(4U, rh - j)); - opj_v4dwt_decode(&h); + opj_v8dwt_interleave_partial_h(&h, sa, j, opj_uint_min(NB_ELTS_V8, rh - j)); + opj_v8dwt_decode(&h); if (!opj_sparse_array_int32_write(sa, win_tr_x0, j, - win_tr_x1, j + 4, + win_tr_x1, j + NB_ELTS_V8, (OPJ_INT32*)&h.wavelet[win_tr_x0].f[0], - 4, 1, OPJ_TRUE)) { + NB_ELTS_V8, 1, OPJ_TRUE)) { /* FIXME event manager error callback */ opj_sparse_array_int32_free(sa); opj_aligned_free(h.wavelet); @@ -2818,16 +3908,16 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, } if (j < rh && - ((j + 3 >= win_ll_y0 && j < win_ll_y1) || - (j + 3 >= win_lh_y0 + (OPJ_UINT32)v.sn && + ((j + (NB_ELTS_V8 - 1) >= win_ll_y0 && j < win_ll_y1) || + (j + (NB_ELTS_V8 - 1) >= win_lh_y0 + (OPJ_UINT32)v.sn && j < win_lh_y1 + (OPJ_UINT32)v.sn))) { - opj_v4dwt_interleave_partial_h(&h, sa, j, rh - j); - opj_v4dwt_decode(&h); + opj_v8dwt_interleave_partial_h(&h, sa, j, rh - j); + opj_v8dwt_decode(&h); if (!opj_sparse_array_int32_write(sa, win_tr_x0, j, win_tr_x1, rh, (OPJ_INT32*)&h.wavelet[win_tr_x0].f[0], - 4, 1, OPJ_TRUE)) { + NB_ELTS_V8, 1, OPJ_TRUE)) { /* FIXME event manager error callback */ opj_sparse_array_int32_free(sa); opj_aligned_free(h.wavelet); @@ -2839,17 +3929,17 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, v.win_l_x1 = win_ll_y1; v.win_h_x0 = win_lh_y0; v.win_h_x1 = win_lh_y1; - for (j = win_tr_x0; j < win_tr_x1; j += 4) { - OPJ_UINT32 nb_elts = opj_uint_min(4U, win_tr_x1 - j); + for (j = win_tr_x0; j < win_tr_x1; j += NB_ELTS_V8) { + OPJ_UINT32 nb_elts = opj_uint_min(NB_ELTS_V8, win_tr_x1 - j); - opj_v4dwt_interleave_partial_v(&v, sa, j, nb_elts); - opj_v4dwt_decode(&v); + opj_v8dwt_interleave_partial_v(&v, sa, j, nb_elts); + opj_v8dwt_decode(&v); if (!opj_sparse_array_int32_write(sa, j, win_tr_y0, j + nb_elts, win_tr_y1, (OPJ_INT32*)&h.wavelet[win_tr_y0].f[0], - 1, 4, OPJ_TRUE)) { + 1, NB_ELTS_V8, OPJ_TRUE)) { /* FIXME event manager error callback */ opj_sparse_array_int32_free(sa); opj_aligned_free(h.wavelet); @@ -2882,7 +3972,7 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_t *p_tcd, OPJ_UINT32 numres) { if (p_tcd->whole_tile_decoding) { - return opj_dwt_decode_tile_97(tilec, numres); + return opj_dwt_decode_tile_97(p_tcd->thread_pool, tilec, numres); } else { return opj_dwt_decode_partial_97(tilec, numres); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/dwt.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/dwt.h index 4f63e524a60..215061e6b9c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/dwt.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/dwt.h @@ -56,9 +56,11 @@ DWT.C are used by some function in TCD.C. /** Forward 5-3 wavelet transform in 2-D. Apply a reversible DWT transform to a component of an image. +@param p_tcd TCD handle @param tilec Tile component information (current tile) */ -OPJ_BOOL opj_dwt_encode(opj_tcd_tilecomp_t * tilec); +OPJ_BOOL opj_dwt_encode(opj_tcd_t *p_tcd, + opj_tcd_tilecomp_t * tilec); /** Inverse 5-3 wavelet transform in 2-D. @@ -71,12 +73,6 @@ OPJ_BOOL opj_dwt_decode(opj_tcd_t *p_tcd, opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres); -/** -Get the gain of a subband for the reversible 5-3 DWT. -@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH) -@return Returns 0 if orient = 0, returns 1 if orient = 1 or 2, returns 2 otherwise -*/ -OPJ_UINT32 opj_dwt_getgain(OPJ_UINT32 orient) ; /** Get the norm of a wavelet function of a subband at a specified level for the reversible 5-3 DWT. @param level Level of the wavelet function @@ -87,9 +83,11 @@ OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient); /** Forward 9-7 wavelet transform in 2-D. Apply an irreversible DWT transform to a component of an image. +@param p_tcd TCD handle @param tilec Tile component information (current tile) */ -OPJ_BOOL opj_dwt_encode_real(opj_tcd_tilecomp_t * tilec); +OPJ_BOOL opj_dwt_encode_real(opj_tcd_t *p_tcd, + opj_tcd_tilecomp_t * tilec); /** Inverse 9-7 wavelet transform in 2-D. Apply an irreversible inverse DWT transform to a component of an image. @@ -101,12 +99,6 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_t *p_tcd, opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, OPJ_UINT32 numres); -/** -Get the gain of a subband for the irreversible 9-7 DWT. -@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH) -@return Returns the gain of the 9-7 wavelet transform -*/ -OPJ_UINT32 opj_dwt_getgain_real(OPJ_UINT32 orient); /** Get the norm of a wavelet function of a subband at a specified level for the irreversible 9-7 DWT @param level Level of the wavelet function diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/ht_dec.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/ht_dec.c new file mode 100644 index 00000000000..2984f56098b --- /dev/null +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/ht_dec.c @@ -0,0 +1,2689 @@ +//***************************************************************************/ +// This software is released under the 2-Clause BSD license, included +// below. +// +// Copyright (c) 2021, Aous Naman +// Copyright (c) 2021, Kakadu Software Pty Ltd, Australia +// Copyright (c) 2021, The University of New South Wales, Australia +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +//***************************************************************************/ +// This file is part of the OpenJpeg software implementation. +// File: ht_dec.c +// Author: Aous Naman +// Date: 01 September 2021 +//***************************************************************************/ + +//***************************************************************************/ +/** @file ht_dec.c + * @brief implements HTJ2K block decoder + */ + +#include +#include +#include "opj_includes.h" + +#include "t1_ht_luts.h" + +///////////////////////////////////////////////////////////////////////////// +// compiler detection +///////////////////////////////////////////////////////////////////////////// +#ifdef _MSC_VER +#define OPJ_COMPILER_MSVC +#elif (defined __GNUC__) +#define OPJ_COMPILER_GNUC +#endif + +#if defined(OPJ_COMPILER_MSVC) && defined(_M_ARM64) \ + && !defined(_M_ARM64EC) && !defined(_M_CEE_PURE) && !defined(__CUDACC__) \ + && !defined(__INTEL_COMPILER) && !defined(__clang__) +#define MSVC_NEON_INTRINSICS +#endif + +#ifdef MSVC_NEON_INTRINSICS +#include +#endif + +//************************************************************************/ +/** @brief Displays the error message for disabling the decoding of SPP and + * MRP passes + */ +static OPJ_BOOL only_cleanup_pass_is_decoded = OPJ_FALSE; + +//************************************************************************/ +/** @brief Generates population count (i.e., the number of set bits) + * + * @param [in] val is the value for which population count is sought + */ +static INLINE +OPJ_UINT32 population_count(OPJ_UINT32 val) +{ +#if defined(OPJ_COMPILER_MSVC) && (defined(_M_IX86) || defined(_M_AMD64)) + return (OPJ_UINT32)__popcnt(val); +#elif defined(OPJ_COMPILER_MSVC) && defined(MSVC_NEON_INTRINSICS) + const __n64 temp = neon_cnt(__uint64ToN64_v(val)); + return neon_addv8(temp).n8_i8[0]; +#elif (defined OPJ_COMPILER_GNUC) + return (OPJ_UINT32)__builtin_popcount(val); +#else + val -= ((val >> 1) & 0x55555555); + val = (((val >> 2) & 0x33333333) + (val & 0x33333333)); + val = (((val >> 4) + val) & 0x0f0f0f0f); + val += (val >> 8); + val += (val >> 16); + return (OPJ_UINT32)(val & 0x0000003f); +#endif +} + +//************************************************************************/ +/** @brief Counts the number of leading zeros + * + * @param [in] val is the value for which leading zero count is sought + */ +#ifdef OPJ_COMPILER_MSVC +#pragma intrinsic(_BitScanReverse) +#endif +static INLINE +OPJ_UINT32 count_leading_zeros(OPJ_UINT32 val) +{ +#ifdef OPJ_COMPILER_MSVC + unsigned long result = 0; + _BitScanReverse(&result, val); + return 31U ^ (OPJ_UINT32)result; +#elif (defined OPJ_COMPILER_GNUC) + return (OPJ_UINT32)__builtin_clz(val); +#else + val |= (val >> 1); + val |= (val >> 2); + val |= (val >> 4); + val |= (val >> 8); + val |= (val >> 16); + return 32U - population_count(val); +#endif +} + +//************************************************************************/ +/** @brief Read a little-endian serialized UINT32. + * + * @param [in] dataIn pointer to byte stream to read from + */ +static INLINE OPJ_UINT32 read_le_uint32(const void* dataIn) +{ +#if defined(OPJ_BIG_ENDIAN) + const OPJ_UINT8* data = (const OPJ_UINT8*)dataIn; + return ((OPJ_UINT32)data[0]) | (OPJ_UINT32)(data[1] << 8) | (OPJ_UINT32)( + data[2] << 16) | ((( + OPJ_UINT32)data[3]) << + 24U); +#else + return *(OPJ_UINT32*)dataIn; +#endif +} + +//************************************************************************/ +/** @brief MEL state structure for reading and decoding the MEL bitstream + * + * A number of events is decoded from the MEL bitstream ahead of time + * and stored in run/num_runs. + * Each run represents the number of zero events before a one event. + */ +typedef struct dec_mel { + // data decoding machinery + OPJ_UINT8* data; //!bits > 32) { //there are enough bits in the tmp variable + return; // return without reading new data + } + + val = 0xFFFFFFFF; // feed in 0xFF if buffer is exhausted + if (melp->size > 4) { // if there is more than 4 bytes the MEL segment + val = read_le_uint32(melp->data); // read 32 bits from MEL data + melp->data += 4; // advance pointer + melp->size -= 4; // reduce counter + } else if (melp->size > 0) { // 4 or less + OPJ_UINT32 m, v; + int i = 0; + while (melp->size > 1) { + OPJ_UINT32 v = *melp->data++; // read one byte at a time + OPJ_UINT32 m = ~(0xFFu << i); // mask of location + val = (val & m) | (v << i); // put byte in its correct location + --melp->size; + i += 8; + } + // size equal to 1 + v = *melp->data++; // the one before the last is different + v |= 0xF; // MEL and VLC segments can overlap + m = ~(0xFFu << i); + val = (val & m) | (v << i); + --melp->size; + } + + // next we unstuff them before adding them to the buffer + bits = 32 - melp->unstuff; // number of bits in val, subtract 1 if + // the previously read byte requires + // unstuffing + + // data is unstuffed and accumulated in t + // bits has the number of bits in t + t = val & 0xFF; + unstuff = ((val & 0xFF) == 0xFF); // true if the byte needs unstuffing + bits -= unstuff; // there is one less bit in t if unstuffing is needed + t = t << (8 - unstuff); // move up to make room for the next byte + + //this is a repeat of the above + t |= (val >> 8) & 0xFF; + unstuff = (((val >> 8) & 0xFF) == 0xFF); + bits -= unstuff; + t = t << (8 - unstuff); + + t |= (val >> 16) & 0xFF; + unstuff = (((val >> 16) & 0xFF) == 0xFF); + bits -= unstuff; + t = t << (8 - unstuff); + + t |= (val >> 24) & 0xFF; + melp->unstuff = (((val >> 24) & 0xFF) == 0xFF); + + // move t to tmp, and push the result all the way up, so we read from + // the MSB + melp->tmp |= ((OPJ_UINT64)t) << (64 - bits - melp->bits); + melp->bits += bits; //increment the number of bits in tmp +} + +//************************************************************************/ +/** @brief Decodes unstuffed MEL segment bits stored in tmp to runs + * + * Runs are stored in "runs" and the number of runs in "num_runs". + * Each run represents a number of zero events that may or may not + * terminate in a 1 event. + * Each run is stored in 7 bits. The LSB is 1 if the run terminates in + * a 1 event, 0 otherwise. The next 6 bits, for the case terminating + * with 1, contain the number of consecutive 0 zero events * 2; for the + * case terminating with 0, they store (number of consecutive 0 zero + * events - 1) * 2. + * A total of 6 bits (made up of 1 + 5) should have been enough. + * + * @param [in] melp is a pointer to dec_mel_t structure + */ +static INLINE +void mel_decode(dec_mel_t *melp) +{ + static const int mel_exp[13] = { //MEL exponents + 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5 + }; + + if (melp->bits < 6) { // if there are less than 6 bits in tmp + mel_read(melp); // then read from the MEL bitstream + } + // 6 bits is the largest decodable MEL cwd + + //repeat so long that there is enough decodable bits in tmp, + // and the runs store is not full (num_runs < 8) + while (melp->bits >= 6 && melp->num_runs < 8) { + int eval = mel_exp[melp->k]; // number of bits associated with state + int run = 0; + if (melp->tmp & (1ull << 63)) { //The next bit to decode (stored in MSB) + //one is found + run = 1 << eval; + run--; // consecutive runs of 0 events - 1 + melp->k = melp->k + 1 < 12 ? melp->k + 1 : 12;//increment, max is 12 + melp->tmp <<= 1; // consume one bit from tmp + melp->bits -= 1; + run = run << 1; // a stretch of zeros not terminating in one + } else { + //0 is found + run = (int)(melp->tmp >> (63 - eval)) & ((1 << eval) - 1); + melp->k = melp->k - 1 > 0 ? melp->k - 1 : 0; //decrement, min is 0 + melp->tmp <<= eval + 1; //consume eval + 1 bits (max is 6) + melp->bits -= eval + 1; + run = (run << 1) + 1; // a stretch of zeros terminating with one + } + eval = melp->num_runs * 7; // 7 bits per run + melp->runs &= ~((OPJ_UINT64)0x3F << eval); // 6 bits are sufficient + melp->runs |= ((OPJ_UINT64)run) << eval; // store the value in runs + melp->num_runs++; // increment count + } +} + +//************************************************************************/ +/** @brief Initiates a dec_mel_t structure for MEL decoding and reads + * some bytes in order to get the read address to a multiple + * of 4 + * + * @param [in] melp is a pointer to dec_mel_t structure + * @param [in] bbuf is a pointer to byte buffer + * @param [in] lcup is the length of MagSgn+MEL+VLC segments + * @param [in] scup is the length of MEL+VLC segments + */ +static INLINE +OPJ_BOOL mel_init(dec_mel_t *melp, OPJ_UINT8* bbuf, int lcup, int scup) +{ + int num; + int i; + + melp->data = bbuf + lcup - scup; // move the pointer to the start of MEL + melp->bits = 0; // 0 bits in tmp + melp->tmp = 0; // + melp->unstuff = OPJ_FALSE; // no unstuffing + melp->size = scup - 1; // size is the length of MEL+VLC-1 + melp->k = 0; // 0 for state + melp->num_runs = 0; // num_runs is 0 + melp->runs = 0; // + + //This code is borrowed; original is for a different architecture + //These few lines take care of the case where data is not at a multiple + // of 4 boundary. It reads 1,2,3 up to 4 bytes from the MEL segment + num = 4 - (int)((intptr_t)(melp->data) & 0x3); + for (i = 0; i < num; ++i) { // this code is similar to mel_read + OPJ_UINT64 d; + int d_bits; + + if (melp->unstuff == OPJ_TRUE && melp->data[0] > 0x8F) { + return OPJ_FALSE; + } + d = (melp->size > 0) ? *melp->data : 0xFF; // if buffer is consumed + // set data to 0xFF + if (melp->size == 1) { + d |= 0xF; //if this is MEL+VLC-1, set LSBs to 0xF + } + // see the standard + melp->data += melp->size-- > 0; //increment if the end is not reached + d_bits = 8 - melp->unstuff; //if unstuffing is needed, reduce by 1 + melp->tmp = (melp->tmp << d_bits) | d; //store bits in tmp + melp->bits += d_bits; //increment tmp by number of bits + melp->unstuff = ((d & 0xFF) == 0xFF); //true of next byte needs + //unstuffing + } + melp->tmp <<= (64 - melp->bits); //push all the way up so the first bit + // is the MSB + return OPJ_TRUE; +} + +//************************************************************************/ +/** @brief Retrieves one run from dec_mel_t; if there are no runs stored + * MEL segment is decoded + * + * @param [in] melp is a pointer to dec_mel_t structure + */ +static INLINE +int mel_get_run(dec_mel_t *melp) +{ + int t; + if (melp->num_runs == 0) { //if no runs, decode more bit from MEL segment + mel_decode(melp); + } + + t = melp->runs & 0x7F; //retrieve one run + melp->runs >>= 7; // remove the retrieved run + melp->num_runs--; + return t; // return run +} + +//************************************************************************/ +/** @brief A structure for reading and unstuffing a segment that grows + * backward, such as VLC and MRP + */ +typedef struct rev_struct { + //storage + OPJ_UINT8* data; //!bits > 32) { // if there are more than 32 bits in tmp, then + return; // reading 32 bits can overflow vlcp->tmp + } + val = 0; + //the next line (the if statement) needs to be tested first + if (vlcp->size > 3) { // if there are more than 3 bytes left in VLC + // (vlcp->data - 3) move pointer back to read 32 bits at once + val = read_le_uint32(vlcp->data - 3); // then read 32 bits + vlcp->data -= 4; // move data pointer back by 4 + vlcp->size -= 4; // reduce available byte by 4 + } else if (vlcp->size > 0) { // 4 or less + int i = 24; + while (vlcp->size > 0) { + OPJ_UINT32 v = *vlcp->data--; // read one byte at a time + val |= (v << i); // put byte in its correct location + --vlcp->size; + i -= 8; + } + } + + //accumulate in tmp, number of bits in tmp are stored in bits + tmp = val >> 24; //start with the MSB byte + + // test unstuff (previous byte is >0x8F), and this byte is 0x7F + bits = 8u - ((vlcp->unstuff && (((val >> 24) & 0x7F) == 0x7F)) ? 1u : 0u); + unstuff = (val >> 24) > 0x8F; //this is for the next byte + + tmp |= ((val >> 16) & 0xFF) << bits; //process the next byte + bits += 8u - ((unstuff && (((val >> 16) & 0x7F) == 0x7F)) ? 1u : 0u); + unstuff = ((val >> 16) & 0xFF) > 0x8F; + + tmp |= ((val >> 8) & 0xFF) << bits; + bits += 8u - ((unstuff && (((val >> 8) & 0x7F) == 0x7F)) ? 1u : 0u); + unstuff = ((val >> 8) & 0xFF) > 0x8F; + + tmp |= (val & 0xFF) << bits; + bits += 8u - ((unstuff && ((val & 0x7F) == 0x7F)) ? 1u : 0u); + unstuff = (val & 0xFF) > 0x8F; + + // now move the read and unstuffed bits into vlcp->tmp + vlcp->tmp |= (OPJ_UINT64)tmp << vlcp->bits; + vlcp->bits += bits; + vlcp->unstuff = unstuff; // this for the next read +} + +//************************************************************************/ +/** @brief Initiates the rev_struct_t structure and reads a few bytes to + * move the read address to multiple of 4 + * + * There is another similar rev_init_mrp subroutine. The difference is + * that this one, rev_init, discards the first 12 bits (they have the + * sum of the lengths of VLC and MEL segments), and first unstuff depends + * on first 4 bits. + * + * @param [in] vlcp is a pointer to rev_struct_t structure + * @param [in] data is a pointer to byte at the start of the cleanup pass + * @param [in] lcup is the length of MagSgn+MEL+VLC segments + * @param [in] scup is the length of MEL+VLC segments + */ +static INLINE +void rev_init(rev_struct_t *vlcp, OPJ_UINT8* data, int lcup, int scup) +{ + OPJ_UINT32 d; + int num, tnum, i; + + //first byte has only the upper 4 bits + vlcp->data = data + lcup - 2; + + //size can not be larger than this, in fact it should be smaller + vlcp->size = scup - 2; + + d = *vlcp->data--; // read one byte (this is a half byte) + vlcp->tmp = d >> 4; // both initialize and set + vlcp->bits = 4 - ((vlcp->tmp & 7) == 7); //check standard + vlcp->unstuff = (d | 0xF) > 0x8F; //this is useful for the next byte + + //This code is designed for an architecture that read address should + // align to the read size (address multiple of 4 if read size is 4) + //These few lines take care of the case where data is not at a multiple + // of 4 boundary. It reads 1,2,3 up to 4 bytes from the VLC bitstream. + // To read 32 bits, read from (vlcp->data - 3) + num = 1 + (int)((intptr_t)(vlcp->data) & 0x3); + tnum = num < vlcp->size ? num : vlcp->size; + for (i = 0; i < tnum; ++i) { + OPJ_UINT64 d; + OPJ_UINT32 d_bits; + d = *vlcp->data--; // read one byte and move read pointer + //check if the last byte was >0x8F (unstuff == true) and this is 0x7F + d_bits = 8u - ((vlcp->unstuff && ((d & 0x7F) == 0x7F)) ? 1u : 0u); + vlcp->tmp |= d << vlcp->bits; // move data to vlcp->tmp + vlcp->bits += d_bits; + vlcp->unstuff = d > 0x8F; // for next byte + } + vlcp->size -= tnum; + rev_read(vlcp); // read another 32 buts +} + +//************************************************************************/ +/** @brief Retrieves 32 bits from the head of a rev_struct structure + * + * By the end of this call, vlcp->tmp must have no less than 33 bits + * + * @param [in] vlcp is a pointer to rev_struct structure + */ +static INLINE +OPJ_UINT32 rev_fetch(rev_struct_t *vlcp) +{ + if (vlcp->bits < 32) { // if there are less then 32 bits, read more + rev_read(vlcp); // read 32 bits, but unstuffing might reduce this + if (vlcp->bits < 32) { // if there is still space in vlcp->tmp for 32 bits + rev_read(vlcp); // read another 32 + } + } + return (OPJ_UINT32)vlcp->tmp; // return the head (bottom-most) of vlcp->tmp +} + +//************************************************************************/ +/** @brief Consumes num_bits from a rev_struct structure + * + * @param [in] vlcp is a pointer to rev_struct structure + * @param [in] num_bits is the number of bits to be removed + */ +static INLINE +OPJ_UINT32 rev_advance(rev_struct_t *vlcp, OPJ_UINT32 num_bits) +{ + assert(num_bits <= vlcp->bits); // vlcp->tmp must have more than num_bits + vlcp->tmp >>= num_bits; // remove bits + vlcp->bits -= num_bits; // decrement the number of bits + return (OPJ_UINT32)vlcp->tmp; +} + +//************************************************************************/ +/** @brief Reads and unstuffs from rev_struct + * + * This is different than rev_read in that this fills in zeros when the + * the available data is consumed. The other does not care about the + * values when all data is consumed. + * + * See rev_read for more information about unstuffing + * + * @param [in] mrp is a pointer to rev_struct structure + */ +static INLINE +void rev_read_mrp(rev_struct_t *mrp) +{ + OPJ_UINT32 val; + OPJ_UINT32 tmp; + OPJ_UINT32 bits; + OPJ_BOOL unstuff; + + //process 4 bytes at a time + if (mrp->bits > 32) { + return; + } + val = 0; + if (mrp->size > 3) { // If there are 3 byte or more + // (mrp->data - 3) move pointer back to read 32 bits at once + val = read_le_uint32(mrp->data - 3); // read 32 bits + mrp->data -= 4; // move back pointer + mrp->size -= 4; // reduce count + } else if (mrp->size > 0) { + int i = 24; + while (mrp->size > 0) { + OPJ_UINT32 v = *mrp->data--; // read one byte at a time + val |= (v << i); // put byte in its correct location + --mrp->size; + i -= 8; + } + } + + + //accumulate in tmp, and keep count in bits + tmp = val >> 24; + + //test if the last byte > 0x8F (unstuff must be true) and this is 0x7F + bits = 8u - ((mrp->unstuff && (((val >> 24) & 0x7F) == 0x7F)) ? 1u : 0u); + unstuff = (val >> 24) > 0x8F; + + //process the next byte + tmp |= ((val >> 16) & 0xFF) << bits; + bits += 8u - ((unstuff && (((val >> 16) & 0x7F) == 0x7F)) ? 1u : 0u); + unstuff = ((val >> 16) & 0xFF) > 0x8F; + + tmp |= ((val >> 8) & 0xFF) << bits; + bits += 8u - ((unstuff && (((val >> 8) & 0x7F) == 0x7F)) ? 1u : 0u); + unstuff = ((val >> 8) & 0xFF) > 0x8F; + + tmp |= (val & 0xFF) << bits; + bits += 8u - ((unstuff && ((val & 0x7F) == 0x7F)) ? 1u : 0u); + unstuff = (val & 0xFF) > 0x8F; + + mrp->tmp |= (OPJ_UINT64)tmp << mrp->bits; // move data to mrp pointer + mrp->bits += bits; + mrp->unstuff = unstuff; // next byte +} + +//************************************************************************/ +/** @brief Initialized rev_struct structure for MRP segment, and reads + * a number of bytes such that the next 32 bits read are from + * an address that is a multiple of 4. Note this is designed for + * an architecture that read size must be compatible with the + * alignment of the read address + * + * There is another similar subroutine rev_init. This subroutine does + * NOT skip the first 12 bits, and starts with unstuff set to true. + * + * @param [in] mrp is a pointer to rev_struct structure + * @param [in] data is a pointer to byte at the start of the cleanup pass + * @param [in] lcup is the length of MagSgn+MEL+VLC segments + * @param [in] len2 is the length of SPP+MRP segments + */ +static INLINE +void rev_init_mrp(rev_struct_t *mrp, OPJ_UINT8* data, int lcup, int len2) +{ + int num, i; + + mrp->data = data + lcup + len2 - 1; + mrp->size = len2; + mrp->unstuff = OPJ_TRUE; + mrp->bits = 0; + mrp->tmp = 0; + + //This code is designed for an architecture that read address should + // align to the read size (address multiple of 4 if read size is 4) + //These few lines take care of the case where data is not at a multiple + // of 4 boundary. It reads 1,2,3 up to 4 bytes from the MRP stream + num = 1 + (int)((intptr_t)(mrp->data) & 0x3); + for (i = 0; i < num; ++i) { + OPJ_UINT64 d; + OPJ_UINT32 d_bits; + + //read a byte, 0 if no more data + d = (mrp->size-- > 0) ? *mrp->data-- : 0; + //check if unstuffing is needed + d_bits = 8u - ((mrp->unstuff && ((d & 0x7F) == 0x7F)) ? 1u : 0u); + mrp->tmp |= d << mrp->bits; // move data to vlcp->tmp + mrp->bits += d_bits; + mrp->unstuff = d > 0x8F; // for next byte + } + rev_read_mrp(mrp); +} + +//************************************************************************/ +/** @brief Retrieves 32 bits from the head of a rev_struct structure + * + * By the end of this call, mrp->tmp must have no less than 33 bits + * + * @param [in] mrp is a pointer to rev_struct structure + */ +static INLINE +OPJ_UINT32 rev_fetch_mrp(rev_struct_t *mrp) +{ + if (mrp->bits < 32) { // if there are less than 32 bits in mrp->tmp + rev_read_mrp(mrp); // read 30-32 bits from mrp + if (mrp->bits < 32) { // if there is a space of 32 bits + rev_read_mrp(mrp); // read more + } + } + return (OPJ_UINT32)mrp->tmp; // return the head of mrp->tmp +} + +//************************************************************************/ +/** @brief Consumes num_bits from a rev_struct structure + * + * @param [in] mrp is a pointer to rev_struct structure + * @param [in] num_bits is the number of bits to be removed + */ +static INLINE +OPJ_UINT32 rev_advance_mrp(rev_struct_t *mrp, OPJ_UINT32 num_bits) +{ + assert(num_bits <= mrp->bits); // we must not consume more than mrp->bits + mrp->tmp >>= num_bits; // discard the lowest num_bits bits + mrp->bits -= num_bits; + return (OPJ_UINT32)mrp->tmp; // return data after consumption +} + +//************************************************************************/ +/** @brief Decode initial UVLC to get the u value (or u_q) + * + * @param [in] vlc is the head of the VLC bitstream + * @param [in] mode is 0, 1, 2, 3, or 4. Values in 0 to 3 are composed of + * u_off of 1st quad and 2nd quad of a quad pair. The value + * 4 occurs when both bits are 1, and the event decoded + * from MEL bitstream is also 1. + * @param [out] u is the u value (or u_q) + 1. Note: we produce u + 1; + * this value is a partial calculation of u + kappa. + */ +static INLINE +OPJ_UINT32 decode_init_uvlc(OPJ_UINT32 vlc, OPJ_UINT32 mode, OPJ_UINT32 *u) +{ + //table stores possible decoding three bits from vlc + // there are 8 entries for xx1, x10, 100, 000, where x means do not care + // table value is made up of + // 2 bits in the LSB for prefix length + // 3 bits for suffix length + // 3 bits in the MSB for prefix value (u_pfx in Table 3 of ITU T.814) + static const OPJ_UINT8 dec[8] = { // the index is the prefix codeword + 3 | (5 << 2) | (5 << 5), //000 == 000, prefix codeword "000" + 1 | (0 << 2) | (1 << 5), //001 == xx1, prefix codeword "1" + 2 | (0 << 2) | (2 << 5), //010 == x10, prefix codeword "01" + 1 | (0 << 2) | (1 << 5), //011 == xx1, prefix codeword "1" + 3 | (1 << 2) | (3 << 5), //100 == 100, prefix codeword "001" + 1 | (0 << 2) | (1 << 5), //101 == xx1, prefix codeword "1" + 2 | (0 << 2) | (2 << 5), //110 == x10, prefix codeword "01" + 1 | (0 << 2) | (1 << 5) //111 == xx1, prefix codeword "1" + }; + + OPJ_UINT32 consumed_bits = 0; + if (mode == 0) { // both u_off are 0 + u[0] = u[1] = 1; //Kappa is 1 for initial line + } else if (mode <= 2) { // u_off are either 01 or 10 + OPJ_UINT32 d; + OPJ_UINT32 suffix_len; + + d = dec[vlc & 0x7]; //look at the least significant 3 bits + vlc >>= d & 0x3; //prefix length + consumed_bits += d & 0x3; + + suffix_len = ((d >> 2) & 0x7); + consumed_bits += suffix_len; + + d = (d >> 5) + (vlc & ((1U << suffix_len) - 1)); // u value + u[0] = (mode == 1) ? d + 1 : 1; // kappa is 1 for initial line + u[1] = (mode == 1) ? 1 : d + 1; // kappa is 1 for initial line + } else if (mode == 3) { // both u_off are 1, and MEL event is 0 + OPJ_UINT32 d1 = dec[vlc & 0x7]; // LSBs of VLC are prefix codeword + vlc >>= d1 & 0x3; // Consume bits + consumed_bits += d1 & 0x3; + + if ((d1 & 0x3) > 2) { + OPJ_UINT32 suffix_len; + + //u_{q_2} prefix + u[1] = (vlc & 1) + 1 + 1; //Kappa is 1 for initial line + ++consumed_bits; + vlc >>= 1; + + suffix_len = ((d1 >> 2) & 0x7); + consumed_bits += suffix_len; + d1 = (d1 >> 5) + (vlc & ((1U << suffix_len) - 1)); // u value + u[0] = d1 + 1; //Kappa is 1 for initial line + } else { + OPJ_UINT32 d2; + OPJ_UINT32 suffix_len; + + d2 = dec[vlc & 0x7]; // LSBs of VLC are prefix codeword + vlc >>= d2 & 0x3; // Consume bits + consumed_bits += d2 & 0x3; + + suffix_len = ((d1 >> 2) & 0x7); + consumed_bits += suffix_len; + + d1 = (d1 >> 5) + (vlc & ((1U << suffix_len) - 1)); // u value + u[0] = d1 + 1; //Kappa is 1 for initial line + vlc >>= suffix_len; + + suffix_len = ((d2 >> 2) & 0x7); + consumed_bits += suffix_len; + + d2 = (d2 >> 5) + (vlc & ((1U << suffix_len) - 1)); // u value + u[1] = d2 + 1; //Kappa is 1 for initial line + } + } else if (mode == 4) { // both u_off are 1, and MEL event is 1 + OPJ_UINT32 d1; + OPJ_UINT32 d2; + OPJ_UINT32 suffix_len; + + d1 = dec[vlc & 0x7]; // LSBs of VLC are prefix codeword + vlc >>= d1 & 0x3; // Consume bits + consumed_bits += d1 & 0x3; + + d2 = dec[vlc & 0x7]; // LSBs of VLC are prefix codeword + vlc >>= d2 & 0x3; // Consume bits + consumed_bits += d2 & 0x3; + + suffix_len = ((d1 >> 2) & 0x7); + consumed_bits += suffix_len; + + d1 = (d1 >> 5) + (vlc & ((1U << suffix_len) - 1)); // u value + u[0] = d1 + 3; // add 2+kappa + vlc >>= suffix_len; + + suffix_len = ((d2 >> 2) & 0x7); + consumed_bits += suffix_len; + + d2 = (d2 >> 5) + (vlc & ((1U << suffix_len) - 1)); // u value + u[1] = d2 + 3; // add 2+kappa + } + return consumed_bits; +} + +//************************************************************************/ +/** @brief Decode non-initial UVLC to get the u value (or u_q) + * + * @param [in] vlc is the head of the VLC bitstream + * @param [in] mode is 0, 1, 2, or 3. The 1st bit is u_off of 1st quad + * and 2nd for 2nd quad of a quad pair + * @param [out] u is the u value (or u_q) + 1. Note: we produce u + 1; + * this value is a partial calculation of u + kappa. + */ +static INLINE +OPJ_UINT32 decode_noninit_uvlc(OPJ_UINT32 vlc, OPJ_UINT32 mode, OPJ_UINT32 *u) +{ + //table stores possible decoding three bits from vlc + // there are 8 entries for xx1, x10, 100, 000, where x means do not care + // table value is made up of + // 2 bits in the LSB for prefix length + // 3 bits for suffix length + // 3 bits in the MSB for prefix value (u_pfx in Table 3 of ITU T.814) + static const OPJ_UINT8 dec[8] = { + 3 | (5 << 2) | (5 << 5), //000 == 000, prefix codeword "000" + 1 | (0 << 2) | (1 << 5), //001 == xx1, prefix codeword "1" + 2 | (0 << 2) | (2 << 5), //010 == x10, prefix codeword "01" + 1 | (0 << 2) | (1 << 5), //011 == xx1, prefix codeword "1" + 3 | (1 << 2) | (3 << 5), //100 == 100, prefix codeword "001" + 1 | (0 << 2) | (1 << 5), //101 == xx1, prefix codeword "1" + 2 | (0 << 2) | (2 << 5), //110 == x10, prefix codeword "01" + 1 | (0 << 2) | (1 << 5) //111 == xx1, prefix codeword "1" + }; + + OPJ_UINT32 consumed_bits = 0; + if (mode == 0) { + u[0] = u[1] = 1; //for kappa + } else if (mode <= 2) { //u_off are either 01 or 10 + OPJ_UINT32 d; + OPJ_UINT32 suffix_len; + + d = dec[vlc & 0x7]; //look at the least significant 3 bits + vlc >>= d & 0x3; //prefix length + consumed_bits += d & 0x3; + + suffix_len = ((d >> 2) & 0x7); + consumed_bits += suffix_len; + + d = (d >> 5) + (vlc & ((1U << suffix_len) - 1)); // u value + u[0] = (mode == 1) ? d + 1 : 1; //for kappa + u[1] = (mode == 1) ? 1 : d + 1; //for kappa + } else if (mode == 3) { // both u_off are 1 + OPJ_UINT32 d1; + OPJ_UINT32 d2; + OPJ_UINT32 suffix_len; + + d1 = dec[vlc & 0x7]; // LSBs of VLC are prefix codeword + vlc >>= d1 & 0x3; // Consume bits + consumed_bits += d1 & 0x3; + + d2 = dec[vlc & 0x7]; // LSBs of VLC are prefix codeword + vlc >>= d2 & 0x3; // Consume bits + consumed_bits += d2 & 0x3; + + suffix_len = ((d1 >> 2) & 0x7); + consumed_bits += suffix_len; + + d1 = (d1 >> 5) + (vlc & ((1U << suffix_len) - 1)); // u value + u[0] = d1 + 1; //1 for kappa + vlc >>= suffix_len; + + suffix_len = ((d2 >> 2) & 0x7); + consumed_bits += suffix_len; + + d2 = (d2 >> 5) + (vlc & ((1U << suffix_len) - 1)); // u value + u[1] = d2 + 1; //1 for kappa + } + return consumed_bits; +} + +//************************************************************************/ +/** @brief State structure for reading and unstuffing of forward-growing + * bitstreams; these are: MagSgn and SPP bitstreams + */ +typedef struct frwd_struct { + const OPJ_UINT8* data; //!bits <= 32); // assert that there is a space for 32 bits + + val = 0u; + if (msp->size > 3) { + val = read_le_uint32(msp->data); // read 32 bits + msp->data += 4; // increment pointer + msp->size -= 4; // reduce size + } else if (msp->size > 0) { + int i = 0; + val = msp->X != 0 ? 0xFFFFFFFFu : 0; + while (msp->size > 0) { + OPJ_UINT32 v = *msp->data++; // read one byte at a time + OPJ_UINT32 m = ~(0xFFu << i); // mask of location + val = (val & m) | (v << i); // put one byte in its correct location + --msp->size; + i += 8; + } + } else { + val = msp->X != 0 ? 0xFFFFFFFFu : 0; + } + + // we accumulate in t and keep a count of the number of bits in bits + bits = 8u - (msp->unstuff ? 1u : 0u); + t = val & 0xFF; + unstuff = ((val & 0xFF) == 0xFF); // Do we need unstuffing next? + + t |= ((val >> 8) & 0xFF) << bits; + bits += 8u - (unstuff ? 1u : 0u); + unstuff = (((val >> 8) & 0xFF) == 0xFF); + + t |= ((val >> 16) & 0xFF) << bits; + bits += 8u - (unstuff ? 1u : 0u); + unstuff = (((val >> 16) & 0xFF) == 0xFF); + + t |= ((val >> 24) & 0xFF) << bits; + bits += 8u - (unstuff ? 1u : 0u); + msp->unstuff = (((val >> 24) & 0xFF) == 0xFF); // for next byte + + msp->tmp |= ((OPJ_UINT64)t) << msp->bits; // move data to msp->tmp + msp->bits += bits; +} + +//************************************************************************/ +/** @brief Initialize frwd_struct_t struct and reads some bytes + * + * @param [in] msp is a pointer to frwd_struct_t + * @param [in] data is a pointer to the start of data + * @param [in] size is the number of byte in the bitstream + * @param [in] X is the value fed in when the bitstream is exhausted. + * See frwd_read. + */ +static INLINE +void frwd_init(frwd_struct_t *msp, const OPJ_UINT8* data, int size, + OPJ_UINT32 X) +{ + int num, i; + + msp->data = data; + msp->tmp = 0; + msp->bits = 0; + msp->unstuff = OPJ_FALSE; + msp->size = size; + msp->X = X; + assert(msp->X == 0 || msp->X == 0xFF); + + //This code is designed for an architecture that read address should + // align to the read size (address multiple of 4 if read size is 4) + //These few lines take care of the case where data is not at a multiple + // of 4 boundary. It reads 1,2,3 up to 4 bytes from the bitstream + num = 4 - (int)((intptr_t)(msp->data) & 0x3); + for (i = 0; i < num; ++i) { + OPJ_UINT64 d; + //read a byte if the buffer is not exhausted, otherwise set it to X + d = msp->size-- > 0 ? *msp->data++ : msp->X; + msp->tmp |= (d << msp->bits); // store data in msp->tmp + msp->bits += 8u - (msp->unstuff ? 1u : 0u); // number of bits added to msp->tmp + msp->unstuff = ((d & 0xFF) == 0xFF); // unstuffing for next byte + } + frwd_read(msp); // read 32 bits more +} + +//************************************************************************/ +/** @brief Consume num_bits bits from the bitstream of frwd_struct_t + * + * @param [in] msp is a pointer to frwd_struct_t + * @param [in] num_bits is the number of bit to consume + */ +static INLINE +void frwd_advance(frwd_struct_t *msp, OPJ_UINT32 num_bits) +{ + assert(num_bits <= msp->bits); + msp->tmp >>= num_bits; // consume num_bits + msp->bits -= num_bits; +} + +//************************************************************************/ +/** @brief Fetches 32 bits from the frwd_struct_t bitstream + * + * @param [in] msp is a pointer to frwd_struct_t + */ +static INLINE +OPJ_UINT32 frwd_fetch(frwd_struct_t *msp) +{ + if (msp->bits < 32) { + frwd_read(msp); + if (msp->bits < 32) { //need to test + frwd_read(msp); + } + } + return (OPJ_UINT32)msp->tmp; +} + +//************************************************************************/ +/** @brief Allocates T1 buffers + * + * @param [in, out] t1 is codeblock coefficients storage + * @param [in] w is codeblock width + * @param [in] h is codeblock height + */ +static OPJ_BOOL opj_t1_allocate_buffers( + opj_t1_t *t1, + OPJ_UINT32 w, + OPJ_UINT32 h) +{ + OPJ_UINT32 flagssize; + + /* No risk of overflow. Prior checks ensure those assert are met */ + /* They are per the specification */ + assert(w <= 1024); + assert(h <= 1024); + assert(w * h <= 4096); + + /* encoder uses tile buffer, so no need to allocate */ + { + OPJ_UINT32 datasize = w * h; + + if (datasize > t1->datasize) { + opj_aligned_free(t1->data); + t1->data = (OPJ_INT32*) + opj_aligned_malloc(datasize * sizeof(OPJ_INT32)); + if (!t1->data) { + /* FIXME event manager error callback */ + return OPJ_FALSE; + } + t1->datasize = datasize; + } + /* memset first arg is declared to never be null by gcc */ + if (t1->data != NULL) { + memset(t1->data, 0, datasize * sizeof(OPJ_INT32)); + } + } + + // We expand these buffers to multiples of 16 bytes. + // We need 4 buffers of 129 integers each, expanded to 132 integers each + // We also need 514 bytes of buffer, expanded to 528 bytes + flagssize = 132U * sizeof(OPJ_UINT32) * 4U; // expanded to multiple of 16 + flagssize += 528U; // 514 expanded to multiples of 16 + + { + if (flagssize > t1->flagssize) { + + opj_aligned_free(t1->flags); + t1->flags = (opj_flag_t*) opj_aligned_malloc(flagssize * sizeof(opj_flag_t)); + if (!t1->flags) { + /* FIXME event manager error callback */ + return OPJ_FALSE; + } + } + t1->flagssize = flagssize; + + memset(t1->flags, 0, flagssize * sizeof(opj_flag_t)); + } + + t1->w = w; + t1->h = h; + + return OPJ_TRUE; +} + +/** +Decode 1 HT code-block +@param t1 T1 handle +@param cblk Code-block coding parameters +@param orient +@param roishift Region of interest shifting value +@param cblksty Code-block style +@param p_manager the event manager +@param p_manager_mutex mutex for the event manager +@param check_pterm whether PTERM correct termination should be checked +*/ +OPJ_BOOL opj_t1_ht_decode_cblk(opj_t1_t *t1, + opj_tcd_cblk_dec_t* cblk, + OPJ_UINT32 orient, + OPJ_UINT32 roishift, + OPJ_UINT32 cblksty, + opj_event_mgr_t *p_manager, + opj_mutex_t* p_manager_mutex, + OPJ_BOOL check_pterm); + +//************************************************************************/ +/** @brief Decodes one codeblock, processing the cleanup, siginificance + * propagation, and magnitude refinement pass + * + * @param [in, out] t1 is codeblock coefficients storage + * @param [in] cblk is codeblock properties + * @param [in] orient is the subband to which the codeblock belongs (not needed) + * @param [in] roishift is region of interest shift + * @param [in] cblksty is codeblock style + * @param [in] p_manager is events print manager + * @param [in] p_manager_mutex a mutex to control access to p_manager + * @param [in] check_pterm: check termination (not used) + */ +OPJ_BOOL opj_t1_ht_decode_cblk(opj_t1_t *t1, + opj_tcd_cblk_dec_t* cblk, + OPJ_UINT32 orient, + OPJ_UINT32 roishift, + OPJ_UINT32 cblksty, + opj_event_mgr_t *p_manager, + opj_mutex_t* p_manager_mutex, + OPJ_BOOL check_pterm) +{ + OPJ_BYTE* cblkdata = NULL; + OPJ_UINT8* coded_data; + OPJ_UINT32* decoded_data; + OPJ_UINT32 zero_bplanes; + OPJ_UINT32 num_passes; + OPJ_UINT32 lengths1; + OPJ_UINT32 lengths2; + OPJ_INT32 width; + OPJ_INT32 height; + OPJ_INT32 stride; + OPJ_UINT32 *pflags, *sigma1, *sigma2, *mbr1, *mbr2, *sip, sip_shift; + OPJ_UINT32 p; + OPJ_UINT32 zero_bplanes_p1; + int lcup, scup; + dec_mel_t mel; + rev_struct_t vlc; + frwd_struct_t magsgn; + frwd_struct_t sigprop; + rev_struct_t magref; + OPJ_UINT8 *lsp, *line_state; + int run; + OPJ_UINT32 vlc_val; // fetched data from VLC bitstream + OPJ_UINT32 qinf[2]; + OPJ_UINT32 c_q; + OPJ_UINT32* sp; + OPJ_INT32 x, y; // loop indices + OPJ_BOOL stripe_causal = (cblksty & J2K_CCP_CBLKSTY_VSC) != 0; + OPJ_UINT32 cblk_len = 0; + + (void)(orient); // stops unused parameter message + (void)(check_pterm); // stops unused parameter message + + // We ignor orient, because the same decoder is used for all subbands + // We also ignore check_pterm, because I am not sure how it applies + if (roishift != 0) { + if (p_manager_mutex) { + opj_mutex_lock(p_manager_mutex); + } + opj_event_msg(p_manager, EVT_ERROR, "We do not support ROI in decoding " + "HT codeblocks\n"); + if (p_manager_mutex) { + opj_mutex_unlock(p_manager_mutex); + } + return OPJ_FALSE; + } + + if (!opj_t1_allocate_buffers( + t1, + (OPJ_UINT32)(cblk->x1 - cblk->x0), + (OPJ_UINT32)(cblk->y1 - cblk->y0))) { + return OPJ_FALSE; + } + + if (cblk->Mb == 0) { + return OPJ_TRUE; + } + + /* numbps = Mb + 1 - zero_bplanes, Mb = Kmax, zero_bplanes = missing_msbs */ + zero_bplanes = (cblk->Mb + 1) - cblk->numbps; + + /* Compute whole codeblock length from chunk lengths */ + cblk_len = 0; + { + OPJ_UINT32 i; + for (i = 0; i < cblk->numchunks; i++) { + cblk_len += cblk->chunks[i].len; + } + } + + if (cblk->numchunks > 1 || t1->mustuse_cblkdatabuffer) { + OPJ_UINT32 i; + + /* Allocate temporary memory if needed */ + if (cblk_len > t1->cblkdatabuffersize) { + cblkdata = (OPJ_BYTE*)opj_realloc( + t1->cblkdatabuffer, cblk_len); + if (cblkdata == NULL) { + return OPJ_FALSE; + } + t1->cblkdatabuffer = cblkdata; + t1->cblkdatabuffersize = cblk_len; + } + + /* Concatenate all chunks */ + cblkdata = t1->cblkdatabuffer; + if (cblkdata == NULL) { + return OPJ_FALSE; + } + cblk_len = 0; + for (i = 0; i < cblk->numchunks; i++) { + memcpy(cblkdata + cblk_len, cblk->chunks[i].data, cblk->chunks[i].len); + cblk_len += cblk->chunks[i].len; + } + } else if (cblk->numchunks == 1) { + cblkdata = cblk->chunks[0].data; + } else { + /* Not sure if that can happen in practice, but avoid Coverity to */ + /* think we will dereference a null cblkdta pointer */ + return OPJ_TRUE; + } + + // OPJ_BYTE* coded_data is a pointer to bitstream + coded_data = cblkdata; + // OPJ_UINT32* decoded_data is a pointer to decoded codeblock data buf. + decoded_data = (OPJ_UINT32*)t1->data; + // OPJ_UINT32 num_passes is the number of passes: 1 if CUP only, 2 for + // CUP+SPP, and 3 for CUP+SPP+MRP + num_passes = cblk->numsegs > 0 ? cblk->segs[0].real_num_passes : 0; + num_passes += cblk->numsegs > 1 ? cblk->segs[1].real_num_passes : 0; + // OPJ_UINT32 lengths1 is the length of cleanup pass + lengths1 = num_passes > 0 ? cblk->segs[0].len : 0; + // OPJ_UINT32 lengths2 is the length of refinement passes (either SPP only or SPP+MRP) + lengths2 = num_passes > 1 ? cblk->segs[1].len : 0; + // OPJ_INT32 width is the decoded codeblock width + width = cblk->x1 - cblk->x0; + // OPJ_INT32 height is the decoded codeblock height + height = cblk->y1 - cblk->y0; + // OPJ_INT32 stride is the decoded codeblock buffer stride + stride = width; + + /* sigma1 and sigma2 contains significant (i.e., non-zero) pixel + * locations. The buffers are used interchangeably, because we need + * more than 4 rows of significance information at a given time. + * Each 32 bits contain significance information for 4 rows of 8 + * columns each. If we denote 32 bits by 0xaaaaaaaa, the each "a" is + * called a nibble and has significance information for 4 rows. + * The least significant nibble has information for the first column, + * and so on. The nibble's LSB is for the first row, and so on. + * Since, at most, we can have 1024 columns in a quad, we need 128 + * entries; we added 1 for convenience when propagation of signifcance + * goes outside the structure + * To work in OpenJPEG these buffers has been expanded to 132. + */ + // OPJ_UINT32 *pflags, *sigma1, *sigma2, *mbr1, *mbr2, *sip, sip_shift; + pflags = (OPJ_UINT32 *)t1->flags; + sigma1 = pflags; + sigma2 = sigma1 + 132; + // mbr arrangement is similar to sigma; mbr contains locations + // that become significant during significance propagation pass + mbr1 = sigma2 + 132; + mbr2 = mbr1 + 132; + //a pointer to sigma + sip = sigma1; //pointers to arrays to be used interchangeably + sip_shift = 0; //the amount of shift needed for sigma + + if (num_passes > 1 && lengths2 == 0) { + if (p_manager_mutex) { + opj_mutex_lock(p_manager_mutex); + } + opj_event_msg(p_manager, EVT_WARNING, "A malformed codeblock that has " + "more than one coding pass, but zero length for " + "2nd and potentially the 3rd pass in an HT codeblock.\n"); + if (p_manager_mutex) { + opj_mutex_unlock(p_manager_mutex); + } + num_passes = 1; + } + if (num_passes > 3) { + if (p_manager_mutex) { + opj_mutex_lock(p_manager_mutex); + } + opj_event_msg(p_manager, EVT_ERROR, "We do not support more than 3 " + "coding passes in an HT codeblock; This codeblocks has " + "%d passes.\n", num_passes); + if (p_manager_mutex) { + opj_mutex_unlock(p_manager_mutex); + } + return OPJ_FALSE; + } + + if (cblk->Mb > 30) { + /* This check is better moved to opj_t2_read_packet_header() in t2.c + We do not have enough precision to decode any passes + The design of openjpeg assumes that the bits of a 32-bit integer are + assigned as follows: + bit 31 is for sign + bits 30-1 are for magnitude + bit 0 is for the center of the quantization bin + Therefore we can only do values of cblk->Mb <= 30 + */ + if (p_manager_mutex) { + opj_mutex_lock(p_manager_mutex); + } + opj_event_msg(p_manager, EVT_ERROR, "32 bits are not enough to " + "decode this codeblock, since the number of " + "bitplane, %d, is larger than 30.\n", cblk->Mb); + if (p_manager_mutex) { + opj_mutex_unlock(p_manager_mutex); + } + return OPJ_FALSE; + } + if (zero_bplanes > cblk->Mb) { + /* This check is better moved to opj_t2_read_packet_header() in t2.c, + in the line "l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i;" + where i is the zero bitplanes, and should be no larger than cblk->Mb + We cannot have more zero bitplanes than there are planes. */ + if (p_manager_mutex) { + opj_mutex_lock(p_manager_mutex); + } + opj_event_msg(p_manager, EVT_ERROR, "Malformed HT codeblock. " + "Decoding this codeblock is stopped. There are " + "%d zero bitplanes in %d bitplanes.\n", + zero_bplanes, cblk->Mb); + + if (p_manager_mutex) { + opj_mutex_unlock(p_manager_mutex); + } + return OPJ_FALSE; + } else if (zero_bplanes == cblk->Mb && num_passes > 1) { + /* When the number of zero bitplanes is equal to the number of bitplanes, + only the cleanup pass makes sense*/ + if (only_cleanup_pass_is_decoded == OPJ_FALSE) { + if (p_manager_mutex) { + opj_mutex_lock(p_manager_mutex); + } + /* We have a second check to prevent the possibility of an overrun condition, + in the very unlikely event of a second thread discovering that + only_cleanup_pass_is_decoded is false before the first thread changing + the condition. */ + if (only_cleanup_pass_is_decoded == OPJ_FALSE) { + only_cleanup_pass_is_decoded = OPJ_TRUE; + opj_event_msg(p_manager, EVT_WARNING, "Malformed HT codeblock. " + "When the number of zero planes bitplanes is " + "equal to the number of bitplanes, only the cleanup " + "pass makes sense, but we have %d passes in this " + "codeblock. Therefore, only the cleanup pass will be " + "decoded. This message will not be displayed again.\n", + num_passes); + } + if (p_manager_mutex) { + opj_mutex_unlock(p_manager_mutex); + } + } + num_passes = 1; + } + + /* OPJ_UINT32 */ + p = cblk->numbps; + + // OPJ_UINT32 zero planes plus 1 + zero_bplanes_p1 = zero_bplanes + 1; + + if (lengths1 < 2 || (OPJ_UINT32)lengths1 > cblk_len || + (OPJ_UINT32)(lengths1 + lengths2) > cblk_len) { + if (p_manager_mutex) { + opj_mutex_lock(p_manager_mutex); + } + opj_event_msg(p_manager, EVT_ERROR, "Malformed HT codeblock. " + "Invalid codeblock length values.\n"); + + if (p_manager_mutex) { + opj_mutex_unlock(p_manager_mutex); + } + return OPJ_FALSE; + } + // read scup and fix the bytes there + lcup = (int)lengths1; // length of CUP + //scup is the length of MEL + VLC + scup = (((int)coded_data[lcup - 1]) << 4) + (coded_data[lcup - 2] & 0xF); + if (scup < 2 || scup > lcup || scup > 4079) { //something is wrong + /* The standard stipulates 2 <= Scup <= min(Lcup, 4079) */ + if (p_manager_mutex) { + opj_mutex_lock(p_manager_mutex); + } + opj_event_msg(p_manager, EVT_ERROR, "Malformed HT codeblock. " + "One of the following condition is not met: " + "2 <= Scup <= min(Lcup, 4079)\n"); + + if (p_manager_mutex) { + opj_mutex_unlock(p_manager_mutex); + } + return OPJ_FALSE; + } + + // init structures + if (mel_init(&mel, coded_data, lcup, scup) == OPJ_FALSE) { + if (p_manager_mutex) { + opj_mutex_lock(p_manager_mutex); + } + opj_event_msg(p_manager, EVT_ERROR, "Malformed HT codeblock. " + "Incorrect MEL segment sequence.\n"); + if (p_manager_mutex) { + opj_mutex_unlock(p_manager_mutex); + } + return OPJ_FALSE; + } + rev_init(&vlc, coded_data, lcup, scup); + frwd_init(&magsgn, coded_data, lcup - scup, 0xFF); + if (num_passes > 1) { // needs to be tested + frwd_init(&sigprop, coded_data + lengths1, (int)lengths2, 0); + } + if (num_passes > 2) { + rev_init_mrp(&magref, coded_data, (int)lengths1, (int)lengths2); + } + + /** State storage + * One byte per quad; for 1024 columns, or 512 quads, we need + * 512 bytes. We are using 2 extra bytes one on the left and one on + * the right for convenience. + * + * The MSB bit in each byte is (\sigma^nw | \sigma^n), and the 7 LSBs + * contain max(E^nw | E^n) + */ + + // 514 is enough for a block width of 1024, +2 extra + // here expanded to 528 + line_state = (OPJ_UINT8 *)(mbr2 + 132); + + //initial 2 lines + ///////////////// + lsp = line_state; // point to line state + lsp[0] = 0; // for initial row of quad, we set to 0 + run = mel_get_run(&mel); // decode runs of events from MEL bitstrm + // data represented as runs of 0 events + // See mel_decode description + qinf[0] = qinf[1] = 0; // quad info decoded from VLC bitstream + c_q = 0; // context for quad q + sp = decoded_data; // decoded codeblock samples + // vlc_val; // fetched data from VLC bitstream + + for (x = 0; x < width; x += 4) { // one iteration per quad pair + OPJ_UINT32 U_q[2]; // u values for the quad pair + OPJ_UINT32 uvlc_mode; + OPJ_UINT32 consumed_bits; + OPJ_UINT32 m_n, v_n; + OPJ_UINT32 ms_val; + OPJ_UINT32 locs; + + // decode VLC + ///////////// + + //first quad + // Get the head of the VLC bitstream. One fetch is enough for two + // quads, since the largest VLC code is 7 bits, and maximum number of + // bits used for u is 8. Therefore for two quads we need 30 bits + // (if we include unstuffing, then 32 bits are enough, since we have + // a maximum of one stuffing per two bytes) + vlc_val = rev_fetch(&vlc); + + //decode VLC using the context c_q and the head of the VLC bitstream + qinf[0] = vlc_tbl0[(c_q << 7) | (vlc_val & 0x7F) ]; + + if (c_q == 0) { // if zero context, we need to use one MEL event + run -= 2; //the number of 0 events is multiplied by 2, so subtract 2 + + // Is the run terminated in 1? if so, use decoded VLC code, + // otherwise, discard decoded data, since we will decoded again + // using a different context + qinf[0] = (run == -1) ? qinf[0] : 0; + + // is run -1 or -2? this means a run has been consumed + if (run < 0) { + run = mel_get_run(&mel); // get another run + } + } + + // prepare context for the next quad; eqn. 1 in ITU T.814 + c_q = ((qinf[0] & 0x10) >> 4) | ((qinf[0] & 0xE0) >> 5); + + //remove data from vlc stream (0 bits are removed if qinf is not used) + vlc_val = rev_advance(&vlc, qinf[0] & 0x7); + + //update sigma + // The update depends on the value of x; consider one OPJ_UINT32 + // if x is 0, 8, 16 and so on, then this line update c locations + // nibble (4 bits) number 0 1 2 3 4 5 6 7 + // LSB c c 0 0 0 0 0 0 + // c c 0 0 0 0 0 0 + // 0 0 0 0 0 0 0 0 + // 0 0 0 0 0 0 0 0 + // if x is 4, 12, 20, then this line update locations c + // nibble (4 bits) number 0 1 2 3 4 5 6 7 + // LSB 0 0 0 0 c c 0 0 + // 0 0 0 0 c c 0 0 + // 0 0 0 0 0 0 0 0 + // 0 0 0 0 0 0 0 0 + *sip |= (((qinf[0] & 0x30) >> 4) | ((qinf[0] & 0xC0) >> 2)) << sip_shift; + + //second quad + qinf[1] = 0; + if (x + 2 < width) { // do not run if codeblock is narrower + //decode VLC using the context c_q and the head of the VLC bitstream + qinf[1] = vlc_tbl0[(c_q << 7) | (vlc_val & 0x7F)]; + + // if context is zero, use one MEL event + if (c_q == 0) { //zero context + run -= 2; //subtract 2, since events number if multiplied by 2 + + // if event is 0, discard decoded qinf + qinf[1] = (run == -1) ? qinf[1] : 0; + + if (run < 0) { // have we consumed all events in a run + run = mel_get_run(&mel); // if yes, then get another run + } + } + + //prepare context for the next quad, eqn. 1 in ITU T.814 + c_q = ((qinf[1] & 0x10) >> 4) | ((qinf[1] & 0xE0) >> 5); + + //remove data from vlc stream, if qinf is not used, cwdlen is 0 + vlc_val = rev_advance(&vlc, qinf[1] & 0x7); + } + + //update sigma + // The update depends on the value of x; consider one OPJ_UINT32 + // if x is 0, 8, 16 and so on, then this line update c locations + // nibble (4 bits) number 0 1 2 3 4 5 6 7 + // LSB 0 0 c c 0 0 0 0 + // 0 0 c c 0 0 0 0 + // 0 0 0 0 0 0 0 0 + // 0 0 0 0 0 0 0 0 + // if x is 4, 12, 20, then this line update locations c + // nibble (4 bits) number 0 1 2 3 4 5 6 7 + // LSB 0 0 0 0 0 0 c c + // 0 0 0 0 0 0 c c + // 0 0 0 0 0 0 0 0 + // 0 0 0 0 0 0 0 0 + *sip |= (((qinf[1] & 0x30) | ((qinf[1] & 0xC0) << 2))) << (4 + sip_shift); + + sip += x & 0x7 ? 1 : 0; // move sigma pointer to next entry + sip_shift ^= 0x10; // increment/decrement sip_shift by 16 + + // retrieve u + ///////////// + + // uvlc_mode is made up of u_offset bits from the quad pair + uvlc_mode = ((qinf[0] & 0x8) >> 3) | ((qinf[1] & 0x8) >> 2); + if (uvlc_mode == 3) { // if both u_offset are set, get an event from + // the MEL run of events + run -= 2; //subtract 2, since events number if multiplied by 2 + uvlc_mode += (run == -1) ? 1 : 0; //increment uvlc_mode if event is 1 + if (run < 0) { // if run is consumed (run is -1 or -2), get another run + run = mel_get_run(&mel); + } + } + //decode uvlc_mode to get u for both quads + consumed_bits = decode_init_uvlc(vlc_val, uvlc_mode, U_q); + if (U_q[0] > zero_bplanes_p1 || U_q[1] > zero_bplanes_p1) { + if (p_manager_mutex) { + opj_mutex_lock(p_manager_mutex); + } + opj_event_msg(p_manager, EVT_ERROR, "Malformed HT codeblock. Decoding " + "this codeblock is stopped. U_q is larger than zero " + "bitplanes + 1 \n"); + if (p_manager_mutex) { + opj_mutex_unlock(p_manager_mutex); + } + return OPJ_FALSE; + } + + //consume u bits in the VLC code + vlc_val = rev_advance(&vlc, consumed_bits); + + //decode magsgn and update line_state + ///////////////////////////////////// + + //We obtain a mask for the samples locations that needs evaluation + locs = 0xFF; + if (x + 4 > width) { + locs >>= (x + 4 - width) << 1; // limits width + } + locs = height > 1 ? locs : (locs & 0x55); // limits height + + if ((((qinf[0] & 0xF0) >> 4) | (qinf[1] & 0xF0)) & ~locs) { + if (p_manager_mutex) { + opj_mutex_lock(p_manager_mutex); + } + opj_event_msg(p_manager, EVT_ERROR, "Malformed HT codeblock. " + "VLC code produces significant samples outside " + "the codeblock area.\n"); + if (p_manager_mutex) { + opj_mutex_unlock(p_manager_mutex); + } + return OPJ_FALSE; + } + + //first quad, starting at first sample in quad and moving on + if (qinf[0] & 0x10) { //is it significant? (sigma_n) + OPJ_UINT32 val; + + ms_val = frwd_fetch(&magsgn); //get 32 bits of magsgn data + m_n = U_q[0] - ((qinf[0] >> 12) & 1); //evaluate m_n (number of bits + // to read from bitstream), using EMB e_k + frwd_advance(&magsgn, m_n); //consume m_n + val = ms_val << 31; //get sign bit + v_n = ms_val & ((1U << m_n) - 1); //keep only m_n bits + v_n |= ((qinf[0] & 0x100) >> 8) << m_n; //add EMB e_1 as MSB + v_n |= 1; //add center of bin + //v_n now has 2 * (\mu - 1) + 0.5 with correct sign bit + //add 2 to make it 2*\mu+0.5, shift it up to missing MSBs + sp[0] = val | ((v_n + 2) << (p - 1)); + } else if (locs & 0x1) { // if this is inside the codeblock, set the + sp[0] = 0; // sample to zero + } + + if (qinf[0] & 0x20) { //sigma_n + OPJ_UINT32 val, t; + + ms_val = frwd_fetch(&magsgn); //get 32 bits + m_n = U_q[0] - ((qinf[0] >> 13) & 1); //m_n, uses EMB e_k + frwd_advance(&magsgn, m_n); //consume m_n + val = ms_val << 31; //get sign bit + v_n = ms_val & ((1U << m_n) - 1); //keep only m_n bits + v_n |= ((qinf[0] & 0x200) >> 9) << m_n; //add EMB e_1 + v_n |= 1; //bin center + //v_n now has 2 * (\mu - 1) + 0.5 with correct sign bit + //add 2 to make it 2*\mu+0.5, shift it up to missing MSBs + sp[stride] = val | ((v_n + 2) << (p - 1)); + + //update line_state: bit 7 (\sigma^N), and E^N + t = lsp[0] & 0x7F; // keep E^NW + v_n = 32 - count_leading_zeros(v_n); + lsp[0] = (OPJ_UINT8)(0x80 | (t > v_n ? t : v_n)); //max(E^NW, E^N) | s + } else if (locs & 0x2) { // if this is inside the codeblock, set the + sp[stride] = 0; // sample to zero + } + + ++lsp; // move to next quad information + ++sp; // move to next column of samples + + //this is similar to the above two samples + if (qinf[0] & 0x40) { + OPJ_UINT32 val; + + ms_val = frwd_fetch(&magsgn); + m_n = U_q[0] - ((qinf[0] >> 14) & 1); + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= (((qinf[0] & 0x400) >> 10) << m_n); + v_n |= 1; + sp[0] = val | ((v_n + 2) << (p - 1)); + } else if (locs & 0x4) { + sp[0] = 0; + } + + lsp[0] = 0; + if (qinf[0] & 0x80) { + OPJ_UINT32 val; + ms_val = frwd_fetch(&magsgn); + m_n = U_q[0] - ((qinf[0] >> 15) & 1); //m_n + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= ((qinf[0] & 0x800) >> 11) << m_n; + v_n |= 1; //center of bin + sp[stride] = val | ((v_n + 2) << (p - 1)); + + //line_state: bit 7 (\sigma^NW), and E^NW for next quad + lsp[0] = (OPJ_UINT8)(0x80 | (32 - count_leading_zeros(v_n))); + } else if (locs & 0x8) { //if outside set to 0 + sp[stride] = 0; + } + + ++sp; //move to next column + + //second quad + if (qinf[1] & 0x10) { + OPJ_UINT32 val; + + ms_val = frwd_fetch(&magsgn); + m_n = U_q[1] - ((qinf[1] >> 12) & 1); //m_n + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= (((qinf[1] & 0x100) >> 8) << m_n); + v_n |= 1; + sp[0] = val | ((v_n + 2) << (p - 1)); + } else if (locs & 0x10) { + sp[0] = 0; + } + + if (qinf[1] & 0x20) { + OPJ_UINT32 val, t; + + ms_val = frwd_fetch(&magsgn); + m_n = U_q[1] - ((qinf[1] >> 13) & 1); //m_n + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= (((qinf[1] & 0x200) >> 9) << m_n); + v_n |= 1; + sp[stride] = val | ((v_n + 2) << (p - 1)); + + //update line_state: bit 7 (\sigma^N), and E^N + t = lsp[0] & 0x7F; //E^NW + v_n = 32 - count_leading_zeros(v_n); //E^N + lsp[0] = (OPJ_UINT8)(0x80 | (t > v_n ? t : v_n)); //max(E^NW, E^N) | s + } else if (locs & 0x20) { + sp[stride] = 0; //no need to update line_state + } + + ++lsp; //move line state to next quad + ++sp; //move to next sample + + if (qinf[1] & 0x40) { + OPJ_UINT32 val; + + ms_val = frwd_fetch(&magsgn); + m_n = U_q[1] - ((qinf[1] >> 14) & 1); //m_n + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= (((qinf[1] & 0x400) >> 10) << m_n); + v_n |= 1; + sp[0] = val | ((v_n + 2) << (p - 1)); + } else if (locs & 0x40) { + sp[0] = 0; + } + + lsp[0] = 0; + if (qinf[1] & 0x80) { + OPJ_UINT32 val; + + ms_val = frwd_fetch(&magsgn); + m_n = U_q[1] - ((qinf[1] >> 15) & 1); //m_n + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= (((qinf[1] & 0x800) >> 11) << m_n); + v_n |= 1; //center of bin + sp[stride] = val | ((v_n + 2) << (p - 1)); + + //line_state: bit 7 (\sigma^NW), and E^NW for next quad + lsp[0] = (OPJ_UINT8)(0x80 | (32 - count_leading_zeros(v_n))); + } else if (locs & 0x80) { + sp[stride] = 0; + } + + ++sp; + } + + //non-initial lines + ////////////////////////// + for (y = 2; y < height; /*done at the end of loop*/) { + OPJ_UINT32 *sip; + OPJ_UINT8 ls0; + OPJ_INT32 x; + + sip_shift ^= 0x2; // shift sigma to the upper half od the nibble + sip_shift &= 0xFFFFFFEFU; //move back to 0 (it might have been at 0x10) + sip = y & 0x4 ? sigma2 : sigma1; //choose sigma array + + lsp = line_state; + ls0 = lsp[0]; // read the line state value + lsp[0] = 0; // and set it to zero + sp = decoded_data + y * stride; // generated samples + c_q = 0; // context + for (x = 0; x < width; x += 4) { + OPJ_UINT32 U_q[2]; + OPJ_UINT32 uvlc_mode, consumed_bits; + OPJ_UINT32 m_n, v_n; + OPJ_UINT32 ms_val; + OPJ_UINT32 locs; + + // decode vlc + ///////////// + + //first quad + // get context, eqn. 2 ITU T.814 + // c_q has \sigma^W | \sigma^SW + c_q |= (ls0 >> 7); //\sigma^NW | \sigma^N + c_q |= (lsp[1] >> 5) & 0x4; //\sigma^NE | \sigma^NF + + //the following is very similar to previous code, so please refer to + // that + vlc_val = rev_fetch(&vlc); + qinf[0] = vlc_tbl1[(c_q << 7) | (vlc_val & 0x7F)]; + if (c_q == 0) { //zero context + run -= 2; + qinf[0] = (run == -1) ? qinf[0] : 0; + if (run < 0) { + run = mel_get_run(&mel); + } + } + //prepare context for the next quad, \sigma^W | \sigma^SW + c_q = ((qinf[0] & 0x40) >> 5) | ((qinf[0] & 0x80) >> 6); + + //remove data from vlc stream + vlc_val = rev_advance(&vlc, qinf[0] & 0x7); + + //update sigma + // The update depends on the value of x and y; consider one OPJ_UINT32 + // if x is 0, 8, 16 and so on, and y is 2, 6, etc., then this + // line update c locations + // nibble (4 bits) number 0 1 2 3 4 5 6 7 + // LSB 0 0 0 0 0 0 0 0 + // 0 0 0 0 0 0 0 0 + // c c 0 0 0 0 0 0 + // c c 0 0 0 0 0 0 + *sip |= (((qinf[0] & 0x30) >> 4) | ((qinf[0] & 0xC0) >> 2)) << sip_shift; + + //second quad + qinf[1] = 0; + if (x + 2 < width) { + c_q |= (lsp[1] >> 7); + c_q |= (lsp[2] >> 5) & 0x4; + qinf[1] = vlc_tbl1[(c_q << 7) | (vlc_val & 0x7F)]; + if (c_q == 0) { //zero context + run -= 2; + qinf[1] = (run == -1) ? qinf[1] : 0; + if (run < 0) { + run = mel_get_run(&mel); + } + } + //prepare context for the next quad + c_q = ((qinf[1] & 0x40) >> 5) | ((qinf[1] & 0x80) >> 6); + //remove data from vlc stream + vlc_val = rev_advance(&vlc, qinf[1] & 0x7); + } + + //update sigma + *sip |= (((qinf[1] & 0x30) | ((qinf[1] & 0xC0) << 2))) << (4 + sip_shift); + + sip += x & 0x7 ? 1 : 0; + sip_shift ^= 0x10; + + //retrieve u + //////////// + uvlc_mode = ((qinf[0] & 0x8) >> 3) | ((qinf[1] & 0x8) >> 2); + consumed_bits = decode_noninit_uvlc(vlc_val, uvlc_mode, U_q); + vlc_val = rev_advance(&vlc, consumed_bits); + + //calculate E^max and add it to U_q, eqns 5 and 6 in ITU T.814 + if ((qinf[0] & 0xF0) & ((qinf[0] & 0xF0) - 1)) { // is \gamma_q 1? + OPJ_UINT32 E = (ls0 & 0x7Fu); + E = E > (lsp[1] & 0x7Fu) ? E : (lsp[1] & 0x7Fu); //max(E, E^NE, E^NF) + //since U_q already has u_q + 1, we subtract 2 instead of 1 + U_q[0] += E > 2 ? E - 2 : 0; + } + + if ((qinf[1] & 0xF0) & ((qinf[1] & 0xF0) - 1)) { //is \gamma_q 1? + OPJ_UINT32 E = (lsp[1] & 0x7Fu); + E = E > (lsp[2] & 0x7Fu) ? E : (lsp[2] & 0x7Fu); //max(E, E^NE, E^NF) + //since U_q already has u_q + 1, we subtract 2 instead of 1 + U_q[1] += E > 2 ? E - 2 : 0; + } + + if (U_q[0] > zero_bplanes_p1 || U_q[1] > zero_bplanes_p1) { + if (p_manager_mutex) { + opj_mutex_lock(p_manager_mutex); + } + opj_event_msg(p_manager, EVT_ERROR, "Malformed HT codeblock. " + "Decoding this codeblock is stopped. U_q is" + "larger than bitplanes + 1 \n"); + if (p_manager_mutex) { + opj_mutex_unlock(p_manager_mutex); + } + return OPJ_FALSE; + } + + ls0 = lsp[2]; //for next double quad + lsp[1] = lsp[2] = 0; + + //decode magsgn and update line_state + ///////////////////////////////////// + + //locations where samples need update + locs = 0xFF; + if (x + 4 > width) { + locs >>= (x + 4 - width) << 1; + } + locs = y + 2 <= height ? locs : (locs & 0x55); + + if ((((qinf[0] & 0xF0) >> 4) | (qinf[1] & 0xF0)) & ~locs) { + if (p_manager_mutex) { + opj_mutex_lock(p_manager_mutex); + } + opj_event_msg(p_manager, EVT_ERROR, "Malformed HT codeblock. " + "VLC code produces significant samples outside " + "the codeblock area.\n"); + if (p_manager_mutex) { + opj_mutex_unlock(p_manager_mutex); + } + return OPJ_FALSE; + } + + + + if (qinf[0] & 0x10) { //sigma_n + OPJ_UINT32 val; + + ms_val = frwd_fetch(&magsgn); + m_n = U_q[0] - ((qinf[0] >> 12) & 1); //m_n + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= ((qinf[0] & 0x100) >> 8) << m_n; + v_n |= 1; //center of bin + sp[0] = val | ((v_n + 2) << (p - 1)); + } else if (locs & 0x1) { + sp[0] = 0; + } + + if (qinf[0] & 0x20) { //sigma_n + OPJ_UINT32 val, t; + + ms_val = frwd_fetch(&magsgn); + m_n = U_q[0] - ((qinf[0] >> 13) & 1); //m_n + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= ((qinf[0] & 0x200) >> 9) << m_n; + v_n |= 1; //center of bin + sp[stride] = val | ((v_n + 2) << (p - 1)); + + //update line_state: bit 7 (\sigma^N), and E^N + t = lsp[0] & 0x7F; //E^NW + v_n = 32 - count_leading_zeros(v_n); + lsp[0] = (OPJ_UINT8)(0x80 | (t > v_n ? t : v_n)); + } else if (locs & 0x2) { + sp[stride] = 0; //no need to update line_state + } + + ++lsp; + ++sp; + + if (qinf[0] & 0x40) { //sigma_n + OPJ_UINT32 val; + + ms_val = frwd_fetch(&magsgn); + m_n = U_q[0] - ((qinf[0] >> 14) & 1); //m_n + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= (((qinf[0] & 0x400) >> 10) << m_n); + v_n |= 1; //center of bin + sp[0] = val | ((v_n + 2) << (p - 1)); + } else if (locs & 0x4) { + sp[0] = 0; + } + + if (qinf[0] & 0x80) { //sigma_n + OPJ_UINT32 val; + + ms_val = frwd_fetch(&magsgn); + m_n = U_q[0] - ((qinf[0] >> 15) & 1); //m_n + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= ((qinf[0] & 0x800) >> 11) << m_n; + v_n |= 1; //center of bin + sp[stride] = val | ((v_n + 2) << (p - 1)); + + //update line_state: bit 7 (\sigma^NW), and E^NW for next quad + lsp[0] = (OPJ_UINT8)(0x80 | (32 - count_leading_zeros(v_n))); + } else if (locs & 0x8) { + sp[stride] = 0; + } + + ++sp; + + if (qinf[1] & 0x10) { //sigma_n + OPJ_UINT32 val; + + ms_val = frwd_fetch(&magsgn); + m_n = U_q[1] - ((qinf[1] >> 12) & 1); //m_n + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= (((qinf[1] & 0x100) >> 8) << m_n); + v_n |= 1; //center of bin + sp[0] = val | ((v_n + 2) << (p - 1)); + } else if (locs & 0x10) { + sp[0] = 0; + } + + if (qinf[1] & 0x20) { //sigma_n + OPJ_UINT32 val, t; + + ms_val = frwd_fetch(&magsgn); + m_n = U_q[1] - ((qinf[1] >> 13) & 1); //m_n + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= (((qinf[1] & 0x200) >> 9) << m_n); + v_n |= 1; //center of bin + sp[stride] = val | ((v_n + 2) << (p - 1)); + + //update line_state: bit 7 (\sigma^N), and E^N + t = lsp[0] & 0x7F; //E^NW + v_n = 32 - count_leading_zeros(v_n); + lsp[0] = (OPJ_UINT8)(0x80 | (t > v_n ? t : v_n)); + } else if (locs & 0x20) { + sp[stride] = 0; //no need to update line_state + } + + ++lsp; + ++sp; + + if (qinf[1] & 0x40) { //sigma_n + OPJ_UINT32 val; + + ms_val = frwd_fetch(&magsgn); + m_n = U_q[1] - ((qinf[1] >> 14) & 1); //m_n + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= (((qinf[1] & 0x400) >> 10) << m_n); + v_n |= 1; //center of bin + sp[0] = val | ((v_n + 2) << (p - 1)); + } else if (locs & 0x40) { + sp[0] = 0; + } + + if (qinf[1] & 0x80) { //sigma_n + OPJ_UINT32 val; + + ms_val = frwd_fetch(&magsgn); + m_n = U_q[1] - ((qinf[1] >> 15) & 1); //m_n + frwd_advance(&magsgn, m_n); + val = ms_val << 31; + v_n = ms_val & ((1U << m_n) - 1); + v_n |= (((qinf[1] & 0x800) >> 11) << m_n); + v_n |= 1; //center of bin + sp[stride] = val | ((v_n + 2) << (p - 1)); + + //update line_state: bit 7 (\sigma^NW), and E^NW for next quad + lsp[0] = (OPJ_UINT8)(0x80 | (32 - count_leading_zeros(v_n))); + } else if (locs & 0x80) { + sp[stride] = 0; + } + + ++sp; + } + + y += 2; + if (num_passes > 1 && (y & 3) == 0) { //executed at multiples of 4 + // This is for SPP and potentially MRP + + if (num_passes > 2) { //do MRP + // select the current stripe + OPJ_UINT32 *cur_sig = y & 0x4 ? sigma1 : sigma2; + // the address of the data that needs updating + OPJ_UINT32 *dpp = decoded_data + (y - 4) * stride; + OPJ_UINT32 half = 1u << (p - 2); // half the center of the bin + OPJ_INT32 i; + for (i = 0; i < width; i += 8) { + //Process one entry from sigma array at a time + // Each nibble (4 bits) in the sigma array represents 4 rows, + // and the 32 bits contain 8 columns + OPJ_UINT32 cwd = rev_fetch_mrp(&magref); // get 32 bit data + OPJ_UINT32 sig = *cur_sig++; // 32 bit that will be processed now + OPJ_UINT32 col_mask = 0xFu; // a mask for a column in sig + OPJ_UINT32 *dp = dpp + i; // next column in decode samples + if (sig) { // if any of the 32 bits are set + int j; + for (j = 0; j < 8; ++j, dp++) { //one column at a time + if (sig & col_mask) { // lowest nibble + OPJ_UINT32 sample_mask = 0x11111111u & col_mask; //LSB + + if (sig & sample_mask) { //if LSB is set + OPJ_UINT32 sym; + + assert(dp[0] != 0); // decoded value cannot be zero + sym = cwd & 1; // get it value + // remove center of bin if sym is 0 + dp[0] ^= (1 - sym) << (p - 1); + dp[0] |= half; // put half the center of bin + cwd >>= 1; //consume word + } + sample_mask += sample_mask; //next row + + if (sig & sample_mask) { + OPJ_UINT32 sym; + + assert(dp[stride] != 0); + sym = cwd & 1; + dp[stride] ^= (1 - sym) << (p - 1); + dp[stride] |= half; + cwd >>= 1; + } + sample_mask += sample_mask; + + if (sig & sample_mask) { + OPJ_UINT32 sym; + + assert(dp[2 * stride] != 0); + sym = cwd & 1; + dp[2 * stride] ^= (1 - sym) << (p - 1); + dp[2 * stride] |= half; + cwd >>= 1; + } + sample_mask += sample_mask; + + if (sig & sample_mask) { + OPJ_UINT32 sym; + + assert(dp[3 * stride] != 0); + sym = cwd & 1; + dp[3 * stride] ^= (1 - sym) << (p - 1); + dp[3 * stride] |= half; + cwd >>= 1; + } + sample_mask += sample_mask; + } + col_mask <<= 4; //next column + } + } + // consume data according to the number of bits set + rev_advance_mrp(&magref, population_count(sig)); + } + } + + if (y >= 4) { // update mbr array at the end of each stripe + //generate mbr corresponding to a stripe + OPJ_UINT32 *sig = y & 0x4 ? sigma1 : sigma2; + OPJ_UINT32 *mbr = y & 0x4 ? mbr1 : mbr2; + + //data is processed in patches of 8 columns, each + // each 32 bits in sigma1 or mbr1 represent 4 rows + + //integrate horizontally + OPJ_UINT32 prev = 0; // previous columns + OPJ_INT32 i; + for (i = 0; i < width; i += 8, mbr++, sig++) { + OPJ_UINT32 t, z; + + mbr[0] = sig[0]; //start with significant samples + mbr[0] |= prev >> 28; //for first column, left neighbors + mbr[0] |= sig[0] << 4; //left neighbors + mbr[0] |= sig[0] >> 4; //right neighbors + mbr[0] |= sig[1] << 28; //for last column, right neighbors + prev = sig[0]; // for next group of columns + + //integrate vertically + t = mbr[0], z = mbr[0]; + z |= (t & 0x77777777) << 1; //above neighbors + z |= (t & 0xEEEEEEEE) >> 1; //below neighbors + mbr[0] = z & ~sig[0]; //remove already significance samples + } + } + + if (y >= 8) { //wait until 8 rows has been processed + OPJ_UINT32 *cur_sig, *cur_mbr, *nxt_sig, *nxt_mbr; + OPJ_UINT32 prev; + OPJ_UINT32 val; + OPJ_INT32 i; + + // add membership from the next stripe, obtained above + cur_sig = y & 0x4 ? sigma2 : sigma1; + cur_mbr = y & 0x4 ? mbr2 : mbr1; + nxt_sig = y & 0x4 ? sigma1 : sigma2; //future samples + prev = 0; // the columns before these group of 8 columns + for (i = 0; i < width; i += 8, cur_mbr++, cur_sig++, nxt_sig++) { + OPJ_UINT32 t = nxt_sig[0]; + t |= prev >> 28; //for first column, left neighbors + t |= nxt_sig[0] << 4; //left neighbors + t |= nxt_sig[0] >> 4; //right neighbors + t |= nxt_sig[1] << 28; //for last column, right neighbors + prev = nxt_sig[0]; // for next group of columns + + if (!stripe_causal) { + cur_mbr[0] |= (t & 0x11111111u) << 3; //propagate up to cur_mbr + } + cur_mbr[0] &= ~cur_sig[0]; //remove already significance samples + } + + //find new locations and get signs + cur_sig = y & 0x4 ? sigma2 : sigma1; + cur_mbr = y & 0x4 ? mbr2 : mbr1; + nxt_sig = y & 0x4 ? sigma1 : sigma2; //future samples + nxt_mbr = y & 0x4 ? mbr1 : mbr2; //future samples + val = 3u << (p - 2); // sample values for newly discovered + // significant samples including the bin center + for (i = 0; i < width; + i += 8, cur_sig++, cur_mbr++, nxt_sig++, nxt_mbr++) { + OPJ_UINT32 ux, tx; + OPJ_UINT32 mbr = *cur_mbr; + OPJ_UINT32 new_sig = 0; + if (mbr) { //are there any samples that might be significant + OPJ_INT32 n; + for (n = 0; n < 8; n += 4) { + OPJ_UINT32 col_mask; + OPJ_UINT32 inv_sig; + OPJ_INT32 end; + OPJ_INT32 j; + + OPJ_UINT32 cwd = frwd_fetch(&sigprop); //get 32 bits + OPJ_UINT32 cnt = 0; + + OPJ_UINT32 *dp = decoded_data + (y - 8) * stride; + dp += i + n; //address for decoded samples + + col_mask = 0xFu << (4 * n); //a mask to select a column + + inv_sig = ~cur_sig[0]; // insignificant samples + + //find the last sample we operate on + end = n + 4 + i < width ? n + 4 : width - i; + + for (j = n; j < end; ++j, ++dp, col_mask <<= 4) { + OPJ_UINT32 sample_mask; + + if ((col_mask & mbr) == 0) { //no samples need checking + continue; + } + + //scan mbr to find a new significant sample + sample_mask = 0x11111111u & col_mask; // LSB + if (mbr & sample_mask) { + assert(dp[0] == 0); // the sample must have been 0 + if (cwd & 1) { //if this sample has become significant + // must propagate it to nearby samples + OPJ_UINT32 t; + new_sig |= sample_mask; // new significant samples + t = 0x32u << (j * 4);// propagation to neighbors + mbr |= t & inv_sig; //remove already significant samples + } + cwd >>= 1; + ++cnt; //consume bit and increment number of + //consumed bits + } + + sample_mask += sample_mask; // next row + if (mbr & sample_mask) { + assert(dp[stride] == 0); + if (cwd & 1) { + OPJ_UINT32 t; + new_sig |= sample_mask; + t = 0x74u << (j * 4); + mbr |= t & inv_sig; + } + cwd >>= 1; + ++cnt; + } + + sample_mask += sample_mask; + if (mbr & sample_mask) { + assert(dp[2 * stride] == 0); + if (cwd & 1) { + OPJ_UINT32 t; + new_sig |= sample_mask; + t = 0xE8u << (j * 4); + mbr |= t & inv_sig; + } + cwd >>= 1; + ++cnt; + } + + sample_mask += sample_mask; + if (mbr & sample_mask) { + assert(dp[3 * stride] == 0); + if (cwd & 1) { + OPJ_UINT32 t; + new_sig |= sample_mask; + t = 0xC0u << (j * 4); + mbr |= t & inv_sig; + } + cwd >>= 1; + ++cnt; + } + } + + //obtain signs here + if (new_sig & (0xFFFFu << (4 * n))) { //if any + OPJ_UINT32 col_mask; + OPJ_INT32 j; + OPJ_UINT32 *dp = decoded_data + (y - 8) * stride; + dp += i + n; // decoded samples address + col_mask = 0xFu << (4 * n); //mask to select a column + + for (j = n; j < end; ++j, ++dp, col_mask <<= 4) { + OPJ_UINT32 sample_mask; + + if ((col_mask & new_sig) == 0) { //if non is significant + continue; + } + + //scan 4 signs + sample_mask = 0x11111111u & col_mask; + if (new_sig & sample_mask) { + assert(dp[0] == 0); + dp[0] |= ((cwd & 1) << 31) | val; //put value and sign + cwd >>= 1; + ++cnt; //consume bit and increment number + //of consumed bits + } + + sample_mask += sample_mask; + if (new_sig & sample_mask) { + assert(dp[stride] == 0); + dp[stride] |= ((cwd & 1) << 31) | val; + cwd >>= 1; + ++cnt; + } + + sample_mask += sample_mask; + if (new_sig & sample_mask) { + assert(dp[2 * stride] == 0); + dp[2 * stride] |= ((cwd & 1) << 31) | val; + cwd >>= 1; + ++cnt; + } + + sample_mask += sample_mask; + if (new_sig & sample_mask) { + assert(dp[3 * stride] == 0); + dp[3 * stride] |= ((cwd & 1) << 31) | val; + cwd >>= 1; + ++cnt; + } + } + + } + frwd_advance(&sigprop, cnt); //consume the bits from bitstrm + cnt = 0; + + //update the next 8 columns + if (n == 4) { + //horizontally + OPJ_UINT32 t = new_sig >> 28; + t |= ((t & 0xE) >> 1) | ((t & 7) << 1); + cur_mbr[1] |= t & ~cur_sig[1]; + } + } + } + //update the next stripe (vertically propagation) + new_sig |= cur_sig[0]; + ux = (new_sig & 0x88888888) >> 3; + tx = ux | (ux << 4) | (ux >> 4); //left and right neighbors + if (i > 0) { + nxt_mbr[-1] |= (ux << 28) & ~nxt_sig[-1]; + } + nxt_mbr[0] |= tx & ~nxt_sig[0]; + nxt_mbr[1] |= (ux >> 28) & ~nxt_sig[1]; + } + + //clear current sigma + //mbr need not be cleared because it is overwritten + cur_sig = y & 0x4 ? sigma2 : sigma1; + memset(cur_sig, 0, ((((OPJ_UINT32)width + 7u) >> 3) + 1u) << 2); + } + } + } + + //terminating + if (num_passes > 1) { + OPJ_INT32 st, y; + + if (num_passes > 2 && ((height & 3) == 1 || (height & 3) == 2)) { + //do magref + OPJ_UINT32 *cur_sig = height & 0x4 ? sigma2 : sigma1; //reversed + OPJ_UINT32 *dpp = decoded_data + (height & 0xFFFFFC) * stride; + OPJ_UINT32 half = 1u << (p - 2); + OPJ_INT32 i; + for (i = 0; i < width; i += 8) { + OPJ_UINT32 cwd = rev_fetch_mrp(&magref); + OPJ_UINT32 sig = *cur_sig++; + OPJ_UINT32 col_mask = 0xF; + OPJ_UINT32 *dp = dpp + i; + if (sig) { + int j; + for (j = 0; j < 8; ++j, dp++) { + if (sig & col_mask) { + OPJ_UINT32 sample_mask = 0x11111111 & col_mask; + + if (sig & sample_mask) { + OPJ_UINT32 sym; + assert(dp[0] != 0); + sym = cwd & 1; + dp[0] ^= (1 - sym) << (p - 1); + dp[0] |= half; + cwd >>= 1; + } + sample_mask += sample_mask; + + if (sig & sample_mask) { + OPJ_UINT32 sym; + assert(dp[stride] != 0); + sym = cwd & 1; + dp[stride] ^= (1 - sym) << (p - 1); + dp[stride] |= half; + cwd >>= 1; + } + sample_mask += sample_mask; + + if (sig & sample_mask) { + OPJ_UINT32 sym; + assert(dp[2 * stride] != 0); + sym = cwd & 1; + dp[2 * stride] ^= (1 - sym) << (p - 1); + dp[2 * stride] |= half; + cwd >>= 1; + } + sample_mask += sample_mask; + + if (sig & sample_mask) { + OPJ_UINT32 sym; + assert(dp[3 * stride] != 0); + sym = cwd & 1; + dp[3 * stride] ^= (1 - sym) << (p - 1); + dp[3 * stride] |= half; + cwd >>= 1; + } + sample_mask += sample_mask; + } + col_mask <<= 4; + } + } + rev_advance_mrp(&magref, population_count(sig)); + } + } + + //do the last incomplete stripe + // for cases of (height & 3) == 0 and 3 + // the should have been processed previously + if ((height & 3) == 1 || (height & 3) == 2) { + //generate mbr of first stripe + OPJ_UINT32 *sig = height & 0x4 ? sigma2 : sigma1; + OPJ_UINT32 *mbr = height & 0x4 ? mbr2 : mbr1; + //integrate horizontally + OPJ_UINT32 prev = 0; + OPJ_INT32 i; + for (i = 0; i < width; i += 8, mbr++, sig++) { + OPJ_UINT32 t, z; + + mbr[0] = sig[0]; + mbr[0] |= prev >> 28; //for first column, left neighbors + mbr[0] |= sig[0] << 4; //left neighbors + mbr[0] |= sig[0] >> 4; //left neighbors + mbr[0] |= sig[1] << 28; //for last column, right neighbors + prev = sig[0]; + + //integrate vertically + t = mbr[0], z = mbr[0]; + z |= (t & 0x77777777) << 1; //above neighbors + z |= (t & 0xEEEEEEEE) >> 1; //below neighbors + mbr[0] = z & ~sig[0]; //remove already significance samples + } + } + + st = height; + st -= height > 6 ? (((height + 1) & 3) + 3) : height; + for (y = st; y < height; y += 4) { + OPJ_UINT32 *cur_sig, *cur_mbr, *nxt_sig, *nxt_mbr; + OPJ_UINT32 val; + OPJ_INT32 i; + + OPJ_UINT32 pattern = 0xFFFFFFFFu; // a pattern needed samples + if (height - y == 3) { + pattern = 0x77777777u; + } else if (height - y == 2) { + pattern = 0x33333333u; + } else if (height - y == 1) { + pattern = 0x11111111u; + } + + //add membership from the next stripe, obtained above + if (height - y > 4) { + OPJ_UINT32 prev = 0; + OPJ_INT32 i; + cur_sig = y & 0x4 ? sigma2 : sigma1; + cur_mbr = y & 0x4 ? mbr2 : mbr1; + nxt_sig = y & 0x4 ? sigma1 : sigma2; + for (i = 0; i < width; i += 8, cur_mbr++, cur_sig++, nxt_sig++) { + OPJ_UINT32 t = nxt_sig[0]; + t |= prev >> 28; //for first column, left neighbors + t |= nxt_sig[0] << 4; //left neighbors + t |= nxt_sig[0] >> 4; //left neighbors + t |= nxt_sig[1] << 28; //for last column, right neighbors + prev = nxt_sig[0]; + + if (!stripe_causal) { + cur_mbr[0] |= (t & 0x11111111u) << 3; + } + //remove already significance samples + cur_mbr[0] &= ~cur_sig[0]; + } + } + + //find new locations and get signs + cur_sig = y & 0x4 ? sigma2 : sigma1; + cur_mbr = y & 0x4 ? mbr2 : mbr1; + nxt_sig = y & 0x4 ? sigma1 : sigma2; + nxt_mbr = y & 0x4 ? mbr1 : mbr2; + val = 3u << (p - 2); + for (i = 0; i < width; i += 8, + cur_sig++, cur_mbr++, nxt_sig++, nxt_mbr++) { + OPJ_UINT32 mbr = *cur_mbr & pattern; //skip unneeded samples + OPJ_UINT32 new_sig = 0; + OPJ_UINT32 ux, tx; + if (mbr) { + OPJ_INT32 n; + for (n = 0; n < 8; n += 4) { + OPJ_UINT32 col_mask; + OPJ_UINT32 inv_sig; + OPJ_INT32 end; + OPJ_INT32 j; + + OPJ_UINT32 cwd = frwd_fetch(&sigprop); + OPJ_UINT32 cnt = 0; + + OPJ_UINT32 *dp = decoded_data + y * stride; + dp += i + n; + + col_mask = 0xFu << (4 * n); + + inv_sig = ~cur_sig[0] & pattern; + + end = n + 4 + i < width ? n + 4 : width - i; + for (j = n; j < end; ++j, ++dp, col_mask <<= 4) { + OPJ_UINT32 sample_mask; + + if ((col_mask & mbr) == 0) { + continue; + } + + //scan 4 mbr + sample_mask = 0x11111111u & col_mask; + if (mbr & sample_mask) { + assert(dp[0] == 0); + if (cwd & 1) { + OPJ_UINT32 t; + new_sig |= sample_mask; + t = 0x32u << (j * 4); + mbr |= t & inv_sig; + } + cwd >>= 1; + ++cnt; + } + + sample_mask += sample_mask; + if (mbr & sample_mask) { + assert(dp[stride] == 0); + if (cwd & 1) { + OPJ_UINT32 t; + new_sig |= sample_mask; + t = 0x74u << (j * 4); + mbr |= t & inv_sig; + } + cwd >>= 1; + ++cnt; + } + + sample_mask += sample_mask; + if (mbr & sample_mask) { + assert(dp[2 * stride] == 0); + if (cwd & 1) { + OPJ_UINT32 t; + new_sig |= sample_mask; + t = 0xE8u << (j * 4); + mbr |= t & inv_sig; + } + cwd >>= 1; + ++cnt; + } + + sample_mask += sample_mask; + if (mbr & sample_mask) { + assert(dp[3 * stride] == 0); + if (cwd & 1) { + OPJ_UINT32 t; + new_sig |= sample_mask; + t = 0xC0u << (j * 4); + mbr |= t & inv_sig; + } + cwd >>= 1; + ++cnt; + } + } + + //signs here + if (new_sig & (0xFFFFu << (4 * n))) { + OPJ_UINT32 col_mask; + OPJ_INT32 j; + OPJ_UINT32 *dp = decoded_data + y * stride; + dp += i + n; + col_mask = 0xFu << (4 * n); + + for (j = n; j < end; ++j, ++dp, col_mask <<= 4) { + OPJ_UINT32 sample_mask; + if ((col_mask & new_sig) == 0) { + continue; + } + + //scan 4 signs + sample_mask = 0x11111111u & col_mask; + if (new_sig & sample_mask) { + assert(dp[0] == 0); + dp[0] |= ((cwd & 1) << 31) | val; + cwd >>= 1; + ++cnt; + } + + sample_mask += sample_mask; + if (new_sig & sample_mask) { + assert(dp[stride] == 0); + dp[stride] |= ((cwd & 1) << 31) | val; + cwd >>= 1; + ++cnt; + } + + sample_mask += sample_mask; + if (new_sig & sample_mask) { + assert(dp[2 * stride] == 0); + dp[2 * stride] |= ((cwd & 1) << 31) | val; + cwd >>= 1; + ++cnt; + } + + sample_mask += sample_mask; + if (new_sig & sample_mask) { + assert(dp[3 * stride] == 0); + dp[3 * stride] |= ((cwd & 1) << 31) | val; + cwd >>= 1; + ++cnt; + } + } + + } + frwd_advance(&sigprop, cnt); + cnt = 0; + + //update next columns + if (n == 4) { + //horizontally + OPJ_UINT32 t = new_sig >> 28; + t |= ((t & 0xE) >> 1) | ((t & 7) << 1); + cur_mbr[1] |= t & ~cur_sig[1]; + } + } + } + //propagate down (vertically propagation) + new_sig |= cur_sig[0]; + ux = (new_sig & 0x88888888) >> 3; + tx = ux | (ux << 4) | (ux >> 4); + if (i > 0) { + nxt_mbr[-1] |= (ux << 28) & ~nxt_sig[-1]; + } + nxt_mbr[0] |= tx & ~nxt_sig[0]; + nxt_mbr[1] |= (ux >> 28) & ~nxt_sig[1]; + } + } + } + + { + OPJ_INT32 x, y; + for (y = 0; y < height; ++y) { + OPJ_INT32* sp = (OPJ_INT32*)decoded_data + y * stride; + for (x = 0; x < width; ++x, ++sp) { + OPJ_INT32 val = (*sp & 0x7FFFFFFF); + *sp = ((OPJ_UINT32) * sp & 0x80000000) ? -val : val; + } + } + } + + return OPJ_TRUE; +} diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/image.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/image.c index 13bcb8e45f6..017201a002b 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/image.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/image.c @@ -48,8 +48,8 @@ opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, image->color_space = clrspc; image->numcomps = numcmpts; /* allocate memory for the per-component information */ - image->comps = (opj_image_comp_t*)opj_calloc(1, - image->numcomps * sizeof(opj_image_comp_t)); + image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, + sizeof(opj_image_comp_t)); if (!image->comps) { /* TODO replace with event manager, breaks API */ /* fprintf(stderr,"Unable to allocate memory for image.\n"); */ @@ -66,7 +66,6 @@ opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, comp->x0 = cmptparms[compno].x0; comp->y0 = cmptparms[compno].y0; comp->prec = cmptparms[compno].prec; - comp->bpp = cmptparms[compno].bpp; comp->sgnd = cmptparms[compno].sgnd; if (comp->h != 0 && (OPJ_SIZE_T)comp->w > SIZE_MAX / comp->h / sizeof(OPJ_INT32)) { diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/j2k.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/j2k.c index 3df18a989fd..5a741547fbd 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/j2k.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/j2k.c @@ -43,6 +43,10 @@ #include "opj_includes.h" +#if defined(_MSC_VER) && (_MSC_VER < 1900) +#define snprintf _snprintf +#endif + /** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */ /*@{*/ @@ -50,7 +54,7 @@ /*@{*/ /** - * Sets up the procedures to do on reading header. Developpers wanting to extend the library can add their own reading procedures. + * Sets up the procedures to do on reading header. Developers wanting to extend the library can add their own reading procedures. */ static OPJ_BOOL opj_j2k_setup_header_reading(opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager); @@ -89,22 +93,22 @@ static OPJ_BOOL opj_j2k_decoding_validation(opj_j2k_t * p_j2k, opj_event_mgr_t * p_manager); /** - * Sets up the validation ,i.e. adds the procedures to lauch to make sure the codec parameters - * are valid. Developpers wanting to extend the library can add their own validation procedures. + * Sets up the validation ,i.e. adds the procedures to launch to make sure the codec parameters + * are valid. Developers wanting to extend the library can add their own validation procedures. */ static OPJ_BOOL opj_j2k_setup_encoding_validation(opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager); /** - * Sets up the validation ,i.e. adds the procedures to lauch to make sure the codec parameters - * are valid. Developpers wanting to extend the library can add their own validation procedures. + * Sets up the validation ,i.e. adds the procedures to launch to make sure the codec parameters + * are valid. Developers wanting to extend the library can add their own validation procedures. */ static OPJ_BOOL opj_j2k_setup_decoding_validation(opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager); /** - * Sets up the validation ,i.e. adds the procedures to lauch to make sure the codec parameters - * are valid. Developpers wanting to extend the library can add their own validation procedures. + * Sets up the validation ,i.e. adds the procedures to launch to make sure the codec parameters + * are valid. Developers wanting to extend the library can add their own validation procedures. */ static OPJ_BOOL opj_j2k_setup_end_compress(opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager); @@ -147,7 +151,7 @@ static OPJ_BOOL opj_j2k_create_tcd(opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager); /** - * Excutes the given procedures on the given codec. + * Executes the given procedures on the given codec. * * @param p_procedure_list the list of procedures to execute * @param p_j2k the jpeg2000 codec to execute the procedures on. @@ -400,14 +404,14 @@ static OPJ_BOOL opj_j2k_setup_header_writing(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_first_tile_part(opj_j2k_t *p_j2k, OPJ_BYTE * p_data, OPJ_UINT32 * p_data_written, - OPJ_UINT32 p_total_data_size, + OPJ_UINT32 total_data_size, opj_stream_private_t *p_stream, struct opj_event_mgr * p_manager); static OPJ_BOOL opj_j2k_write_all_tile_parts(opj_j2k_t *p_j2k, OPJ_BYTE * p_data, OPJ_UINT32 * p_data_written, - OPJ_UINT32 p_total_data_size, + OPJ_UINT32 total_data_size, opj_stream_private_t *p_stream, struct opj_event_mgr * p_manager); @@ -508,7 +512,7 @@ static OPJ_BOOL opj_j2k_write_cod(opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager); /** - * Reads a COD marker (Coding Styke defaults) + * Reads a COD marker (Coding style defaults) * @param p_header_data the data contained in the COD box. * @param p_j2k the jpeg2000 codec. * @param p_header_size the size of the data contained in the COD marker. @@ -832,14 +836,14 @@ static OPJ_BOOL opj_j2k_write_tlm(opj_j2k_t *p_j2k, * * @param p_j2k J2K codec. * @param p_data Output buffer - * @param p_total_data_size Output buffer size + * @param total_data_size Output buffer size * @param p_data_written Number of bytes written into stream * @param p_stream the stream to write data to. * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_write_sot(opj_j2k_t *p_j2k, OPJ_BYTE * p_data, - OPJ_UINT32 p_total_data_size, + OPJ_UINT32 total_data_size, OPJ_UINT32 * p_data_written, const opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager); @@ -879,11 +883,13 @@ static OPJ_BOOL opj_j2k_read_sot(opj_j2k_t *p_j2k, /** * Writes the SOD marker (Start of data) * + * This also writes optional PLT markers (before SOD) + * * @param p_j2k J2K codec. * @param p_tile_coder FIXME DOC * @param p_data FIXME DOC * @param p_data_written FIXME DOC - * @param p_total_data_size FIXME DOC + * @param total_data_size FIXME DOC * @param p_stream the stream to write data to. * @param p_manager the user event manager. */ @@ -891,7 +897,7 @@ static OPJ_BOOL opj_j2k_write_sod(opj_j2k_t *p_j2k, opj_tcd_t * p_tile_coder, OPJ_BYTE * p_data, OPJ_UINT32 * p_data_written, - OPJ_UINT32 p_total_data_size, + OPJ_UINT32 total_data_size, const opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager); @@ -908,9 +914,15 @@ static OPJ_BOOL opj_j2k_read_sod(opj_j2k_t *p_j2k, static void opj_j2k_update_tlm(opj_j2k_t * p_j2k, OPJ_UINT32 p_tile_part_size) { - opj_write_bytes(p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current, - p_j2k->m_current_tile_number, 1); /* PSOT */ - ++p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current; + if (p_j2k->m_specific_param.m_encoder.m_Ttlmi_is_byte) { + opj_write_bytes(p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current, + p_j2k->m_current_tile_number, 1); + p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current += 1; + } else { + opj_write_bytes(p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current, + p_j2k->m_current_tile_number, 2); + p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current += 2; + } opj_write_bytes(p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current, p_tile_part_size, 4); /* PSOT */ @@ -1169,6 +1181,32 @@ static OPJ_BOOL opj_j2k_read_cbd(opj_j2k_t *p_j2k, OPJ_UINT32 p_header_size, opj_event_mgr_t * p_manager); +/** + * Reads a CAP marker (extended capabilities definition). Empty implementation. + * Found in HTJ2K files + * + * @param p_header_data the data contained in the CAP box. + * @param p_j2k the jpeg2000 codec. + * @param p_header_size the size of the data contained in the CAP marker. + * @param p_manager the user event manager. +*/ +static OPJ_BOOL opj_j2k_read_cap(opj_j2k_t *p_j2k, + OPJ_BYTE * p_header_data, + OPJ_UINT32 p_header_size, + opj_event_mgr_t * p_manager); + +/** + * Reads a CPF marker (corresponding profile). Empty implementation. Found in HTJ2K files + * @param p_header_data the data contained in the CPF box. + * @param p_j2k the jpeg2000 codec. + * @param p_header_size the size of the data contained in the CPF marker. + * @param p_manager the user event manager. +*/ +static OPJ_BOOL opj_j2k_read_cpf(opj_j2k_t *p_j2k, + OPJ_BYTE * p_header_data, + OPJ_UINT32 p_header_size, + opj_event_mgr_t * p_manager); + /** * Writes COC marker for each component. @@ -1219,6 +1257,7 @@ static OPJ_BOOL opj_j2k_write_epc(opj_j2k_t *p_j2k, * A nice message is outputted at errors. * * @param p_pocs the progression order changes. + * @param tileno the tile number of interest * @param p_nb_pocs the number of progression order changes. * @param p_nb_resolutions the number of resolutions. * @param numcomps the number of components @@ -1228,6 +1267,7 @@ static OPJ_BOOL opj_j2k_write_epc(opj_j2k_t *p_j2k, * @return true if the pocs are valid. */ static OPJ_BOOL opj_j2k_check_poc_val(const opj_poc_t *p_pocs, + OPJ_UINT32 tileno, OPJ_UINT32 p_nb_pocs, OPJ_UINT32 p_nb_resolutions, OPJ_UINT32 numcomps, @@ -1282,6 +1322,13 @@ static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, opj_event_mgr_t *p_manager); +static void opj_j2k_set_imf_parameters(opj_cparameters_t *parameters, + opj_image_t *image, opj_event_mgr_t *p_manager); + +static OPJ_BOOL opj_j2k_is_imf_compliant(opj_cparameters_t *parameters, + opj_image_t *image, + opj_event_mgr_t *p_manager); + /** * Checks for invalid number of tile-parts in SOT marker (TPsot==TNsot). See issue 254. * @@ -1382,10 +1429,12 @@ static const opj_dec_memory_marker_handler_t j2k_memory_marker_handler_tab [] = {J2K_MS_COM, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_com}, {J2K_MS_MCT, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_mct}, {J2K_MS_CBD, J2K_STATE_MH, opj_j2k_read_cbd}, + {J2K_MS_CAP, J2K_STATE_MH, opj_j2k_read_cap}, + {J2K_MS_CPF, J2K_STATE_MH, opj_j2k_read_cpf}, {J2K_MS_MCC, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_mcc}, {J2K_MS_MCO, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_mco}, #ifdef USE_JPWL -#ifdef TODO_MS /* remove these functions which are not commpatible with the v2 API */ +#ifdef TODO_MS /* remove these functions which are not compatible with the v2 API */ {J2K_MS_EPC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_epc}, {J2K_MS_EPB, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_epb}, {J2K_MS_ESD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_esd}, @@ -1615,6 +1664,7 @@ const char *opj_j2k_convert_progression_order(OPJ_PROG_ORDER prg_order) } static OPJ_BOOL opj_j2k_check_poc_val(const opj_poc_t *p_pocs, + OPJ_UINT32 tileno, OPJ_UINT32 p_nb_pocs, OPJ_UINT32 p_nb_resolutions, OPJ_UINT32 p_num_comps, @@ -1628,9 +1678,10 @@ static OPJ_BOOL opj_j2k_check_poc_val(const opj_poc_t *p_pocs, OPJ_UINT32 step_r = p_num_comps * step_c; OPJ_UINT32 step_l = p_nb_resolutions * step_r; OPJ_BOOL loss = OPJ_FALSE; - OPJ_UINT32 layno0 = 0; - packet_array = (OPJ_UINT32*) opj_calloc(step_l * p_num_layers, + assert(p_nb_pocs > 0); + + packet_array = (OPJ_UINT32*) opj_calloc((size_t)step_l * p_num_layers, sizeof(OPJ_UINT32)); if (packet_array == 00) { opj_event_msg(p_manager, EVT_ERROR, @@ -1638,63 +1689,37 @@ static OPJ_BOOL opj_j2k_check_poc_val(const opj_poc_t *p_pocs, return OPJ_FALSE; } - if (p_nb_pocs == 0) { - opj_free(packet_array); - return OPJ_TRUE; - } - - index = step_r * p_pocs->resno0; - /* take each resolution for each poc */ - for (resno = p_pocs->resno0 ; resno < p_pocs->resno1 ; ++resno) { - OPJ_UINT32 res_index = index + p_pocs->compno0 * step_c; - - /* take each comp of each resolution for each poc */ - for (compno = p_pocs->compno0 ; compno < p_pocs->compno1 ; ++compno) { - OPJ_UINT32 comp_index = res_index + layno0 * step_l; - - /* and finally take each layer of each res of ... */ - for (layno = layno0; layno < p_pocs->layno1 ; ++layno) { - /*index = step_r * resno + step_c * compno + step_l * layno;*/ - packet_array[comp_index] = 1; - comp_index += step_l; - } - - res_index += step_c; - } - - index += step_r; - } - ++p_pocs; - - /* iterate through all the pocs */ - for (i = 1; i < p_nb_pocs ; ++i) { - OPJ_UINT32 l_last_layno1 = (p_pocs - 1)->layno1 ; + /* iterate through all the pocs that match our tile of interest. */ + for (i = 0; i < p_nb_pocs; ++i) { + const opj_poc_t *poc = &p_pocs[i]; + if (tileno + 1 == poc->tile) { + index = step_r * poc->resno0; - layno0 = (p_pocs->layno1 > l_last_layno1) ? l_last_layno1 : 0; - index = step_r * p_pocs->resno0; + /* take each resolution for each poc */ + for (resno = poc->resno0 ; + resno < opj_uint_min(poc->resno1, p_nb_resolutions); ++resno) { + OPJ_UINT32 res_index = index + poc->compno0 * step_c; - /* take each resolution for each poc */ - for (resno = p_pocs->resno0 ; resno < p_pocs->resno1 ; ++resno) { - OPJ_UINT32 res_index = index + p_pocs->compno0 * step_c; + /* take each comp of each resolution for each poc */ + for (compno = poc->compno0 ; + compno < opj_uint_min(poc->compno1, p_num_comps); ++compno) { + /* The layer index always starts at zero for every progression. */ + const OPJ_UINT32 layno0 = 0; + OPJ_UINT32 comp_index = res_index + layno0 * step_l; - /* take each comp of each resolution for each poc */ - for (compno = p_pocs->compno0 ; compno < p_pocs->compno1 ; ++compno) { - OPJ_UINT32 comp_index = res_index + layno0 * step_l; + /* and finally take each layer of each res of ... */ + for (layno = layno0; layno < opj_uint_min(poc->layno1, p_num_layers); + ++layno) { + packet_array[comp_index] = 1; + comp_index += step_l; + } - /* and finally take each layer of each res of ... */ - for (layno = layno0; layno < p_pocs->layno1 ; ++layno) { - /*index = step_r * resno + step_c * compno + step_l * layno;*/ - packet_array[comp_index] = 1; - comp_index += step_l; + res_index += step_c; } - res_index += step_c; + index += step_r; } - - index += step_r; } - - ++p_pocs; } index = 0; @@ -1702,7 +1727,13 @@ static OPJ_BOOL opj_j2k_check_poc_val(const opj_poc_t *p_pocs, for (resno = 0; resno < p_nb_resolutions; ++resno) { for (compno = 0; compno < p_num_comps; ++compno) { loss |= (packet_array[index] != 1); - /*index = step_r * resno + step_c * compno + step_l * layno;*/ +#ifdef DEBUG_VERBOSE + if (packet_array[index] != 1) { + fprintf(stderr, + "Missing packet in POC: layno=%d resno=%d compno=%d\n", + layno, resno, compno); + } +#endif index += step_c; } } @@ -1763,7 +1794,7 @@ static OPJ_UINT32 opj_j2k_get_num_tp(opj_cp_t *cp, OPJ_UINT32 pino, tpnum *= l_current_poc->layE; break; } - /* whould we split here ? */ + /* would we split here ? */ if (cp->m_specific_param.m_enc.m_tp_flag == prog[i]) { cp->m_specific_param.m_enc.m_tp_pos = i; break; @@ -1925,7 +1956,8 @@ static OPJ_BOOL opj_j2k_read_soc(opj_j2k_t *p_j2k, /* FIXME move it in a index structure included in p_j2k*/ p_j2k->cstr_index->main_head_start = opj_stream_tell(p_stream) - 2; - opj_event_msg(p_manager, EVT_INFO, "Start to read j2k main header (%ld).\n", + opj_event_msg(p_manager, EVT_INFO, + "Start to read j2k main header (%" PRId64 ").\n", p_j2k->cstr_index->main_head_start); /* Add the marker to the codestream index*/ @@ -2305,10 +2337,8 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, } /* Compute the number of tiles */ - l_cp->tw = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(l_image->x1 - l_cp->tx0), - (OPJ_INT32)l_cp->tdx); - l_cp->th = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(l_image->y1 - l_cp->ty0), - (OPJ_INT32)l_cp->tdy); + l_cp->tw = opj_uint_ceildiv(l_image->x1 - l_cp->tx0, l_cp->tdx); + l_cp->th = opj_uint_ceildiv(l_image->y1 - l_cp->ty0, l_cp->tdy); /* Check that the number of tiles is valid */ if (l_cp->tw == 0 || l_cp->th == 0 || l_cp->tw > 65535 / l_cp->th) { @@ -2325,12 +2355,12 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, (p_j2k->m_specific_param.m_decoder.m_start_tile_x - l_cp->tx0) / l_cp->tdx; p_j2k->m_specific_param.m_decoder.m_start_tile_y = (p_j2k->m_specific_param.m_decoder.m_start_tile_y - l_cp->ty0) / l_cp->tdy; - p_j2k->m_specific_param.m_decoder.m_end_tile_x = (OPJ_UINT32)opj_int_ceildiv(( - OPJ_INT32)(p_j2k->m_specific_param.m_decoder.m_end_tile_x - l_cp->tx0), - (OPJ_INT32)l_cp->tdx); - p_j2k->m_specific_param.m_decoder.m_end_tile_y = (OPJ_UINT32)opj_int_ceildiv(( - OPJ_INT32)(p_j2k->m_specific_param.m_decoder.m_end_tile_y - l_cp->ty0), - (OPJ_INT32)l_cp->tdy); + p_j2k->m_specific_param.m_decoder.m_end_tile_x = opj_uint_ceildiv( + p_j2k->m_specific_param.m_decoder.m_end_tile_x - l_cp->tx0, + l_cp->tdx); + p_j2k->m_specific_param.m_decoder.m_end_tile_y = opj_uint_ceildiv( + p_j2k->m_specific_param.m_decoder.m_end_tile_y - l_cp->ty0, + l_cp->tdy); } else { p_j2k->m_specific_param.m_decoder.m_start_tile_x = 0; p_j2k->m_specific_param.m_decoder.m_start_tile_y = 0; @@ -2458,6 +2488,11 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, ++l_current_tile_param; } + /*Allocate and initialize some elements of codestrem index*/ + if (!opj_j2k_allocate_tile_element_cstr_index(p_j2k)) { + return OPJ_FALSE; + } + p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_MH; opj_image_comp_header_update(l_image, l_cp); @@ -2625,7 +2660,7 @@ static OPJ_BOOL opj_j2k_write_cod(opj_j2k_t *p_j2k, } /** - * Reads a COD marker (Coding Styke defaults) + * Reads a COD marker (Coding style defaults) * @param p_header_data the data contained in the COD box. * @param p_j2k the jpeg2000 codec. * @param p_header_size the size of the data contained in the COD marker. @@ -2657,12 +2692,17 @@ static OPJ_BOOL opj_j2k_read_cod(opj_j2k_t *p_j2k, &l_cp->tcps[p_j2k->m_current_tile_number] : p_j2k->m_specific_param.m_decoder.m_default_tcp; +#if 0 + /* This check was added per https://github.com/uclouvain/openjpeg/commit/daed8cc9195555e101ab708a501af2dfe6d5e001 */ + /* but this is no longer necessary to handle issue476.jp2 */ + /* and this actually cause issues on legit files. See https://github.com/uclouvain/openjpeg/issues/1043 */ /* Only one COD per tile */ if (l_tcp->cod) { opj_event_msg(p_manager, EVT_ERROR, "COD marker already read. No more than one COD marker per tile.\n"); return OPJ_FALSE; } +#endif l_tcp->cod = 1; /* Make sure room is sufficient */ @@ -2708,6 +2748,12 @@ static OPJ_BOOL opj_j2k_read_cod(opj_j2k_t *p_j2k, opj_read_bytes(p_header_data, &l_tcp->mct, 1); /* SGcod (C) */ ++p_header_data; + if (l_tcp->mct > 1) { + opj_event_msg(p_manager, EVT_ERROR, + "Invalid multiple component transformation\n"); + return OPJ_FALSE; + } + p_header_size -= 5; for (i = 0; i < l_image->numcomps; ++i) { l_tcp->tccps[i].csty = l_tcp->csty & J2K_CCP_CSTY_PRT; @@ -3446,6 +3492,28 @@ static OPJ_UINT32 opj_j2k_get_specific_header_sizes(opj_j2k_t *p_j2k) l_nb_bytes += opj_j2k_get_max_poc_size(p_j2k); + if (p_j2k->m_specific_param.m_encoder.m_PLT) { + /* Reserve space for PLT markers */ + + OPJ_UINT32 i; + const opj_cp_t * l_cp = &(p_j2k->m_cp); + OPJ_UINT32 l_max_packet_count = 0; + for (i = 0; i < l_cp->th * l_cp->tw; ++i) { + l_max_packet_count = opj_uint_max(l_max_packet_count, + opj_get_encoding_packet_count(p_j2k->m_private_image, l_cp, i)); + } + /* Minimum 6 bytes per PLT marker, and at a minimum (taking a pessimistic */ + /* estimate of 4 bytes for a packet size), one can write */ + /* (65536-6) / 4 = 16382 paquet sizes per PLT marker */ + p_j2k->m_specific_param.m_encoder.m_reserved_bytes_for_PLT = + 6 * opj_uint_ceildiv(l_max_packet_count, 16382); + /* Maximum 5 bytes per packet to encode a full UINT32 */ + p_j2k->m_specific_param.m_encoder.m_reserved_bytes_for_PLT += + l_nb_bytes += 5 * l_max_packet_count; + p_j2k->m_specific_param.m_encoder.m_reserved_bytes_for_PLT += 1; + l_nb_bytes += p_j2k->m_specific_param.m_encoder.m_reserved_bytes_for_PLT; + } + /*** DEVELOPER CORNER, Add room for your headers ***/ return l_nb_bytes; @@ -3598,21 +3666,29 @@ static OPJ_BOOL opj_j2k_read_tlm(opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager ) { - OPJ_UINT32 l_Ztlm, l_Stlm, l_ST, l_SP, l_tot_num_tp_remaining, l_quotient, - l_Ptlm_size; + OPJ_UINT32 l_Ztlm, l_Stlm, l_ST, l_SP, + l_Ptlm_size, l_entry_size, l_num_tileparts; + OPJ_UINT32 i; + opj_j2k_tlm_tile_part_info_t* l_tile_part_infos; + opj_j2k_tlm_info_t* l_tlm; + /* preconditions */ assert(p_header_data != 00); assert(p_j2k != 00); assert(p_manager != 00); - OPJ_UNUSED(p_j2k); + l_tlm = &(p_j2k->m_specific_param.m_decoder.m_tlm); if (p_header_size < 2) { - opj_event_msg(p_manager, EVT_ERROR, "Error reading TLM marker\n"); + opj_event_msg(p_manager, EVT_ERROR, "Error reading TLM marker.\n"); return OPJ_FALSE; } p_header_size -= 2; + if (l_tlm->m_is_invalid) { + return OPJ_TRUE; + } + opj_read_bytes(p_header_data, &l_Ztlm, 1); /* Ztlm */ ++p_header_data; @@ -3621,27 +3697,83 @@ static OPJ_BOOL opj_j2k_read_tlm(opj_j2k_t *p_j2k, ++p_header_data; l_ST = ((l_Stlm >> 4) & 0x3); + if (l_ST == 3) { + l_tlm->m_is_invalid = OPJ_TRUE; + opj_event_msg(p_manager, EVT_WARNING, + "opj_j2k_read_tlm(): ST = 3 is invalid.\n"); + return OPJ_TRUE; + } l_SP = (l_Stlm >> 6) & 0x1; l_Ptlm_size = (l_SP + 1) * 2; - l_quotient = l_Ptlm_size + l_ST; + l_entry_size = l_Ptlm_size + l_ST; - l_tot_num_tp_remaining = p_header_size % l_quotient; + if ((p_header_size % l_entry_size) != 0) { + l_tlm->m_is_invalid = OPJ_TRUE; + opj_event_msg(p_manager, EVT_WARNING, + "opj_j2k_read_tlm(): TLM marker not of expected size.\n"); + return OPJ_TRUE; + } - if (l_tot_num_tp_remaining != 0) { - opj_event_msg(p_manager, EVT_ERROR, "Error reading TLM marker\n"); - return OPJ_FALSE; + l_num_tileparts = p_header_size / l_entry_size; + if (l_num_tileparts == 0) { + /* not totally sure if this is valid... */ + return OPJ_TRUE; } - /* FIXME Do not care of this at the moment since only local variables are set here */ - /* - for - (i = 0; i < l_tot_num_tp; ++i) - { - opj_read_bytes(p_header_data,&l_Ttlm_i,l_ST); // Ttlm_i + + /* Highly unlikely, unless there are gazillions of TLM markers */ + if (l_tlm->m_entries_count > UINT32_MAX - l_num_tileparts || + l_tlm->m_entries_count + l_num_tileparts > UINT32_MAX / sizeof( + opj_j2k_tlm_tile_part_info_t)) { + l_tlm->m_is_invalid = OPJ_TRUE; + opj_event_msg(p_manager, EVT_WARNING, + "opj_j2k_read_tlm(): too many TLM markers.\n"); + return OPJ_TRUE; + } + + l_tile_part_infos = (opj_j2k_tlm_tile_part_info_t*)opj_realloc( + l_tlm->m_tile_part_infos, + (l_tlm->m_entries_count + l_num_tileparts) * sizeof( + opj_j2k_tlm_tile_part_info_t)); + if (!l_tile_part_infos) { + l_tlm->m_is_invalid = OPJ_TRUE; + opj_event_msg(p_manager, EVT_WARNING, + "opj_j2k_read_tlm(): cannot allocate m_tile_part_infos.\n"); + return OPJ_TRUE; + } + + l_tlm->m_tile_part_infos = l_tile_part_infos; + + for (i = 0; i < l_num_tileparts; ++ i) { + OPJ_UINT32 l_tile_index; + OPJ_UINT32 l_length; + + /* Read Ttlm_i */ + if (l_ST == 0) { + l_tile_index = l_tlm->m_entries_count; + } else { + opj_read_bytes(p_header_data, &l_tile_index, l_ST); p_header_data += l_ST; - opj_read_bytes(p_header_data,&l_Ptlm_i,l_Ptlm_size); // Ptlm_i - p_header_data += l_Ptlm_size; - }*/ + } + + if (l_tile_index >= p_j2k->m_cp.tw * p_j2k->m_cp.th) { + l_tlm->m_is_invalid = OPJ_TRUE; + opj_event_msg(p_manager, EVT_WARNING, + "opj_j2k_read_tlm(): invalid tile number %d\n", + l_tile_index); + return OPJ_TRUE; + } + + /* Read Ptlm_i */ + opj_read_bytes(p_header_data, &l_length, l_Ptlm_size); + p_header_data += l_Ptlm_size; + + l_tile_part_infos[l_tlm->m_entries_count].m_tile_index = + (OPJ_UINT16)l_tile_index; + l_tile_part_infos[l_tlm->m_entries_count].m_length = l_length; + ++l_tlm->m_entries_count; + } + return OPJ_TRUE; } @@ -3900,9 +4032,12 @@ static OPJ_BOOL opj_j2k_merge_ppm(opj_cp_t *p_cp, opj_event_mgr_t * p_manager) opj_read_bytes(l_data, &l_N_ppm, 4); l_data += 4; l_data_size -= 4; - l_ppm_data_size += - l_N_ppm; /* can't overflow, max 256 markers of max 65536 bytes, that is when PPM markers are not corrupted which is checked elsewhere */ + if (l_ppm_data_size > UINT_MAX - l_N_ppm) { + opj_event_msg(p_manager, EVT_ERROR, "Too large value for Nppm\n"); + return OPJ_FALSE; + } + l_ppm_data_size += l_N_ppm; if (l_data_size >= l_N_ppm) { l_data_size -= l_N_ppm; l_data += l_N_ppm; @@ -4089,7 +4224,12 @@ static OPJ_BOOL opj_j2k_merge_ppt(opj_tcp_t *p_tcp, opj_event_mgr_t * p_manager) /* preconditions */ assert(p_tcp != 00); assert(p_manager != 00); - assert(p_tcp->ppt_buffer == NULL); + + if (p_tcp->ppt_buffer != NULL) { + opj_event_msg(p_manager, EVT_ERROR, + "opj_j2k_merge_ppt() has already been called\n"); + return OPJ_FALSE; + } if (p_tcp->ppt == 0U) { return OPJ_TRUE; @@ -4138,13 +4278,33 @@ static OPJ_BOOL opj_j2k_write_tlm(opj_j2k_t *p_j2k, { OPJ_BYTE * l_current_data = 00; OPJ_UINT32 l_tlm_size; + OPJ_UINT32 size_per_tile_part; /* preconditions */ assert(p_j2k != 00); assert(p_manager != 00); assert(p_stream != 00); - l_tlm_size = 6 + (5 * p_j2k->m_specific_param.m_encoder.m_total_tile_parts); + /* 10921 = (65535 - header_size) / size_per_tile_part where */ + /* header_size = 4 and size_per_tile_part = 6 */ + if (p_j2k->m_specific_param.m_encoder.m_total_tile_parts > 10921) { + /* We could do more but it would require writing several TLM markers */ + opj_event_msg(p_manager, EVT_ERROR, + "A maximum of 10921 tile-parts are supported currently " + "when writing TLM marker\n"); + return OPJ_FALSE; + } + + if (p_j2k->m_specific_param.m_encoder.m_total_tile_parts <= 255) { + size_per_tile_part = 5; + p_j2k->m_specific_param.m_encoder.m_Ttlmi_is_byte = OPJ_TRUE; + } else { + size_per_tile_part = 6; + p_j2k->m_specific_param.m_encoder.m_Ttlmi_is_byte = OPJ_FALSE; + } + + l_tlm_size = 2 + 4 + (size_per_tile_part * + p_j2k->m_specific_param.m_encoder.m_total_tile_parts); if (l_tlm_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) { OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc( @@ -4159,6 +4319,7 @@ static OPJ_BOOL opj_j2k_write_tlm(opj_j2k_t *p_j2k, p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data; p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_tlm_size; } + memset(p_j2k->m_specific_param.m_encoder.m_header_tile_data, 0, l_tlm_size); l_current_data = p_j2k->m_specific_param.m_encoder.m_header_tile_data; @@ -4178,11 +4339,14 @@ static OPJ_BOOL opj_j2k_write_tlm(opj_j2k_t *p_j2k, 1); /* Ztlm=0*/ ++l_current_data; - opj_write_bytes(l_current_data, 0x50, - 1); /* Stlm ST=1(8bits-255 tiles max),SP=1(Ptlm=32bits) */ + /* Stlm 0x50= ST=1(8bits-255 tiles max),SP=1(Ptlm=32bits) */ + /* Stlm 0x60= ST=2(16bits-65535 tiles max),SP=1(Ptlm=32bits) */ + opj_write_bytes(l_current_data, + size_per_tile_part == 5 ? 0x50 : 0x60, + 1); ++l_current_data; - /* do nothing on the 5 * l_j2k->m_specific_param.m_encoder.m_total_tile_parts remaining data */ + /* do nothing on the size_per_tile_part * l_j2k->m_specific_param.m_encoder.m_total_tile_parts remaining data */ if (opj_stream_write_data(p_stream, p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_tlm_size, p_manager) != l_tlm_size) { @@ -4194,7 +4358,7 @@ static OPJ_BOOL opj_j2k_write_tlm(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_sot(opj_j2k_t *p_j2k, OPJ_BYTE * p_data, - OPJ_UINT32 p_total_data_size, + OPJ_UINT32 total_data_size, OPJ_UINT32 * p_data_written, const opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager @@ -4207,7 +4371,7 @@ static OPJ_BOOL opj_j2k_write_sot(opj_j2k_t *p_j2k, OPJ_UNUSED(p_stream); - if (p_total_data_size < 12) { + if (total_data_size < 12) { opj_event_msg(p_manager, EVT_ERROR, "Not enough bytes in output buffer to write SOT marker\n"); return OPJ_FALSE; @@ -4492,14 +4656,26 @@ static OPJ_BOOL opj_j2k_read_sot(opj_j2k_t *p_j2k, } /* Index */ - if (p_j2k->cstr_index) { + { assert(p_j2k->cstr_index->tile_index != 00); p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tileno = p_j2k->m_current_tile_number; p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_tpsno = l_current_part; - if (l_num_parts != 0) { + if (!p_j2k->m_specific_param.m_decoder.m_tlm.m_is_invalid && + l_num_parts > + p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].nb_tps) { + opj_event_msg(p_manager, EVT_WARNING, + "SOT marker for tile %u declares more tile-parts than found in TLM marker.", + p_j2k->m_current_tile_number); + p_j2k->m_specific_param.m_decoder.m_tlm.m_is_invalid = OPJ_TRUE; + } + + if (!p_j2k->m_specific_param.m_decoder.m_tlm.m_is_invalid) { + /* do nothing */ + } else if (l_num_parts != 0) { + p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].nb_tps = l_num_parts; p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = @@ -4570,33 +4746,93 @@ static OPJ_BOOL opj_j2k_read_sot(opj_j2k_t *p_j2k, } - /* FIXME move this onto a separate method to call before reading any SOT, remove part about main_end header, use a index struct inside p_j2k */ - /* if (p_j2k->cstr_info) { - if (l_tcp->first) { - if (tileno == 0) { - p_j2k->cstr_info->main_head_end = p_stream_tell(p_stream) - 13; - } + return OPJ_TRUE; +} + +/** + * Write one or more PLT markers in the provided buffer + */ +static OPJ_BOOL opj_j2k_write_plt_in_memory(opj_j2k_t *p_j2k, + opj_tcd_marker_info_t* marker_info, + OPJ_BYTE * p_data, + OPJ_UINT32 * p_data_written, + opj_event_mgr_t * p_manager) +{ + OPJ_BYTE Zplt = 0; + OPJ_UINT16 Lplt; + OPJ_BYTE* p_data_start = p_data; + OPJ_BYTE* p_data_Lplt = p_data + 2; + OPJ_UINT32 i; + + OPJ_UNUSED(p_j2k); + + opj_write_bytes(p_data, J2K_MS_PLT, 2); + p_data += 2; + + /* Reserve space for Lplt */ + p_data += 2; + + opj_write_bytes(p_data, Zplt, 1); + p_data += 1; + + Lplt = 3; + + for (i = 0; i < marker_info->packet_count; i++) { + OPJ_BYTE var_bytes[5]; + OPJ_UINT8 var_bytes_size = 0; + OPJ_UINT32 packet_size = marker_info->p_packet_size[i]; + + /* Packet size written in variable-length way, starting with LSB */ + var_bytes[var_bytes_size] = (OPJ_BYTE)(packet_size & 0x7f); + var_bytes_size ++; + packet_size >>= 7; + while (packet_size > 0) { + var_bytes[var_bytes_size] = (OPJ_BYTE)((packet_size & 0x7f) | 0x80); + var_bytes_size ++; + packet_size >>= 7; + } + + /* Check if that can fit in the current PLT marker. If not, finish */ + /* current one, and start a new one */ + if (Lplt + var_bytes_size > 65535) { + if (Zplt == 255) { + opj_event_msg(p_manager, EVT_ERROR, + "More than 255 PLT markers would be needed for current tile-part !\n"); + return OPJ_FALSE; + } + + /* Patch Lplt */ + opj_write_bytes(p_data_Lplt, Lplt, 2); + + /* Start new segment */ + opj_write_bytes(p_data, J2K_MS_PLT, 2); + p_data += 2; + + /* Reserve space for Lplt */ + p_data_Lplt = p_data; + p_data += 2; + + Zplt ++; + opj_write_bytes(p_data, Zplt, 1); + p_data += 1; + + Lplt = 3; + } + + Lplt = (OPJ_UINT16)(Lplt + var_bytes_size); + + /* Serialize variable-length packet size, starting with MSB */ + for (; var_bytes_size > 0; --var_bytes_size) { + opj_write_bytes(p_data, var_bytes[var_bytes_size - 1], 1); + p_data += 1; + } + } - p_j2k->cstr_info->tile[tileno].tileno = tileno; - p_j2k->cstr_info->tile[tileno].start_pos = p_stream_tell(p_stream) - 12; - p_j2k->cstr_info->tile[tileno].end_pos = p_j2k->cstr_info->tile[tileno].start_pos + totlen - 1; - p_j2k->cstr_info->tile[tileno].num_tps = numparts; + *p_data_written = (OPJ_UINT32)(p_data - p_data_start); - if (numparts) { - p_j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_malloc(numparts * sizeof(opj_tp_info_t)); - } - else { - p_j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_malloc(10 * sizeof(opj_tp_info_t)); // Fixme (10) - } - } - else { - p_j2k->cstr_info->tile[tileno].end_pos += totlen; - } + /* Patch Lplt */ + opj_write_bytes(p_data_Lplt, Lplt, 2); - p_j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos = p_stream_tell(p_stream) - 12; - p_j2k->cstr_info->tile[tileno].tp[partno].tp_end_pos = - p_j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos + totlen - 1; - }*/ return OPJ_TRUE; } @@ -4604,13 +4840,14 @@ static OPJ_BOOL opj_j2k_write_sod(opj_j2k_t *p_j2k, opj_tcd_t * p_tile_coder, OPJ_BYTE * p_data, OPJ_UINT32 * p_data_written, - OPJ_UINT32 p_total_data_size, + OPJ_UINT32 total_data_size, const opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager ) { opj_codestream_info_t *l_cstr_info = 00; OPJ_UINT32 l_remaining_data; + opj_tcd_marker_info_t* marker_info = NULL; /* preconditions */ assert(p_j2k != 00); @@ -4619,7 +4856,7 @@ static OPJ_BOOL opj_j2k_write_sod(opj_j2k_t *p_j2k, OPJ_UNUSED(p_stream); - if (p_total_data_size < 4) { + if (total_data_size < 4) { opj_event_msg(p_manager, EVT_ERROR, "Not enough bytes in output buffer to write SOD marker\n"); return OPJ_FALSE; @@ -4627,10 +4864,9 @@ static OPJ_BOOL opj_j2k_write_sod(opj_j2k_t *p_j2k, opj_write_bytes(p_data, J2K_MS_SOD, 2); /* SOD */ - p_data += 2; /* make room for the EOF marker */ - l_remaining_data = p_total_data_size - 4; + l_remaining_data = total_data_size - 4; /* update tile coder */ p_tile_coder->tp_num = @@ -4677,15 +4913,69 @@ static OPJ_BOOL opj_j2k_write_sod(opj_j2k_t *p_j2k, *p_data_written = 0; - if (! opj_tcd_encode_tile(p_tile_coder, p_j2k->m_current_tile_number, p_data, + if (p_j2k->m_specific_param.m_encoder.m_PLT) { + marker_info = opj_tcd_marker_info_create( + p_j2k->m_specific_param.m_encoder.m_PLT); + if (marker_info == NULL) { + opj_event_msg(p_manager, EVT_ERROR, + "Cannot encode tile: opj_tcd_marker_info_create() failed\n"); + return OPJ_FALSE; + } + } + + if (l_remaining_data < + p_j2k->m_specific_param.m_encoder.m_reserved_bytes_for_PLT) { + opj_event_msg(p_manager, EVT_ERROR, + "Not enough bytes in output buffer to write SOD marker\n"); + opj_tcd_marker_info_destroy(marker_info); + return OPJ_FALSE; + } + l_remaining_data -= p_j2k->m_specific_param.m_encoder.m_reserved_bytes_for_PLT; + + if (! opj_tcd_encode_tile(p_tile_coder, p_j2k->m_current_tile_number, + p_data + 2, p_data_written, l_remaining_data, l_cstr_info, + marker_info, p_manager)) { opj_event_msg(p_manager, EVT_ERROR, "Cannot encode tile\n"); + opj_tcd_marker_info_destroy(marker_info); return OPJ_FALSE; } + /* For SOD */ *p_data_written += 2; + if (p_j2k->m_specific_param.m_encoder.m_PLT) { + OPJ_UINT32 l_data_written_PLT = 0; + OPJ_BYTE* p_PLT_buffer = (OPJ_BYTE*)opj_malloc( + p_j2k->m_specific_param.m_encoder.m_reserved_bytes_for_PLT); + if (!p_PLT_buffer) { + opj_event_msg(p_manager, EVT_ERROR, "Cannot allocate memory\n"); + opj_tcd_marker_info_destroy(marker_info); + return OPJ_FALSE; + } + if (!opj_j2k_write_plt_in_memory(p_j2k, + marker_info, + p_PLT_buffer, + &l_data_written_PLT, + p_manager)) { + opj_tcd_marker_info_destroy(marker_info); + opj_free(p_PLT_buffer); + return OPJ_FALSE; + } + + assert(l_data_written_PLT <= + p_j2k->m_specific_param.m_encoder.m_reserved_bytes_for_PLT); + + /* Move PLT marker(s) before SOD */ + memmove(p_data + l_data_written_PLT, p_data, *p_data_written); + memcpy(p_data, p_PLT_buffer, l_data_written_PLT); + opj_free(p_PLT_buffer); + *p_data_written += l_data_written_PLT; + } + + opj_tcd_marker_info_destroy(marker_info); + return OPJ_TRUE; } @@ -4733,9 +5023,14 @@ static OPJ_BOOL opj_j2k_read_sod(opj_j2k_t *p_j2k, /* Check enough bytes left in stream before allocation */ if ((OPJ_OFF_T)p_j2k->m_specific_param.m_decoder.m_sot_length > opj_stream_get_number_byte_left(p_stream)) { - opj_event_msg(p_manager, EVT_ERROR, - "Tile part length size inconsistent with stream length\n"); - return OPJ_FALSE; + if (p_j2k->m_cp.strict) { + opj_event_msg(p_manager, EVT_ERROR, + "Tile part length size inconsistent with stream length\n"); + return OPJ_FALSE; + } else { + opj_event_msg(p_manager, EVT_WARNING, + "Tile part length size inconsistent with stream length\n"); + } } if (p_j2k->m_specific_param.m_decoder.m_sot_length > UINT_MAX - OPJ_COMMON_CBLK_DATA_EXTRA) { @@ -4786,7 +5081,7 @@ static OPJ_BOOL opj_j2k_read_sod(opj_j2k_t *p_j2k, /* Index */ l_cstr_index = p_j2k->cstr_index; - if (l_cstr_index) { + { OPJ_OFF_T l_current_pos = opj_stream_tell(p_stream) - 2; OPJ_UINT32 l_current_tile_part = @@ -4822,6 +5117,11 @@ static OPJ_BOOL opj_j2k_read_sod(opj_j2k_t *p_j2k, } if (l_current_read_size != p_j2k->m_specific_param.m_decoder.m_sot_length) { + if (l_current_read_size == (OPJ_SIZE_T)(-1)) { + /* Avoid issue of https://github.com/uclouvain/openjpeg/issues/1533 */ + opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n"); + return OPJ_FALSE; + } p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC; } else { p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT; @@ -5035,7 +5335,7 @@ static OPJ_BOOL opj_j2k_update_rates(opj_j2k_t *p_j2k, OPJ_FLOAT32 * l_rates = 0; OPJ_FLOAT32 l_sot_remove; OPJ_UINT32 l_bits_empty, l_size_pixel; - OPJ_UINT32 l_tile_size = 0; + OPJ_UINT64 l_tile_size = 0; OPJ_UINT32 l_last_res; OPJ_FLOAT32(* l_tp_stride_func)(opj_tcp_t *) = 00; @@ -5079,25 +5379,12 @@ static OPJ_BOOL opj_j2k_update_rates(opj_j2k_t *p_j2k, l_rates = l_tcp->rates; /* Modification of the RATE >> */ - if (*l_rates > 0.0f) { - *l_rates = (((OPJ_FLOAT32)(l_size_pixel * (OPJ_UINT32)(l_x1 - l_x0) * - (OPJ_UINT32)(l_y1 - l_y0))) - / - ((*l_rates) * (OPJ_FLOAT32)l_bits_empty) - ) - - - l_offset; - } - - ++l_rates; - - for (k = 1; k < l_tcp->numlayers; ++k) { + for (k = 0; k < l_tcp->numlayers; ++k) { if (*l_rates > 0.0f) { - *l_rates = (((OPJ_FLOAT32)(l_size_pixel * (OPJ_UINT32)(l_x1 - l_x0) * - (OPJ_UINT32)(l_y1 - l_y0))) - / - ((*l_rates) * (OPJ_FLOAT32)l_bits_empty) - ) + *l_rates = (OPJ_FLOAT32)(((OPJ_FLOAT64)l_size_pixel * (OPJ_UINT32)( + l_x1 - l_x0) * + (OPJ_UINT32)(l_y1 - l_y0)) + / ((*l_rates) * (OPJ_FLOAT32)l_bits_empty)) - l_offset; } @@ -5157,12 +5444,11 @@ static OPJ_BOOL opj_j2k_update_rates(opj_j2k_t *p_j2k, l_tile_size = 0; for (i = 0; i < l_image->numcomps; ++i) { - l_tile_size += (opj_uint_ceildiv(l_cp->tdx, l_img_comp->dx) - * - opj_uint_ceildiv(l_cp->tdy, l_img_comp->dy) - * - l_img_comp->prec - ); + l_tile_size += (OPJ_UINT64)opj_uint_ceildiv(l_cp->tdx, l_img_comp->dx) + * + opj_uint_ceildiv(l_cp->tdy, l_img_comp->dy) + * + l_img_comp->prec; ++l_img_comp; } @@ -5173,7 +5459,7 @@ static OPJ_BOOL opj_j2k_update_rates(opj_j2k_t *p_j2k, /* bin/test_tile_encoder 1 256 256 32 32 8 0 reversible_with_precinct.j2k 4 4 3 0 0 1 16 16 */ /* TODO revise this to take into account the overhead linked to the */ /* number of packets and number of code blocks in packets */ - l_tile_size = (OPJ_UINT32)(l_tile_size * 1.4 / 8); + l_tile_size = (OPJ_UINT64)((double)l_tile_size * 1.4 / 8); /* Arbitrary amount to make the following work: */ /* bin/test_tile_encoder 1 256 256 17 16 8 0 reversible_no_precinct.j2k 4 4 3 0 0 1 */ @@ -5181,16 +5467,23 @@ static OPJ_BOOL opj_j2k_update_rates(opj_j2k_t *p_j2k, l_tile_size += opj_j2k_get_specific_header_sizes(p_j2k); - p_j2k->m_specific_param.m_encoder.m_encoded_tile_size = l_tile_size; + if (l_tile_size > UINT_MAX) { + l_tile_size = UINT_MAX; + } + + p_j2k->m_specific_param.m_encoder.m_encoded_tile_size = (OPJ_UINT32)l_tile_size; p_j2k->m_specific_param.m_encoder.m_encoded_tile_data = (OPJ_BYTE *) opj_malloc(p_j2k->m_specific_param.m_encoder.m_encoded_tile_size); if (p_j2k->m_specific_param.m_encoder.m_encoded_tile_data == 00) { + opj_event_msg(p_manager, EVT_ERROR, + "Not enough memory to allocate m_encoded_tile_data. %u MB required\n", + (OPJ_UINT32)(l_tile_size / 1024 / 1024)); return OPJ_FALSE; } - if (OPJ_IS_CINEMA(l_cp->rsiz)) { + if (p_j2k->m_specific_param.m_encoder.m_TLM) { p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_buffer = - (OPJ_BYTE *) opj_malloc(5 * + (OPJ_BYTE *) opj_malloc(6 * p_j2k->m_specific_param.m_encoder.m_total_tile_parts); if (! p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_buffer) { return OPJ_FALSE; @@ -6398,6 +6691,60 @@ static OPJ_BOOL opj_j2k_read_cbd(opj_j2k_t *p_j2k, return OPJ_TRUE; } +/** + * Reads a CAP marker (extended capabilities definition). Empty implementation. + * Found in HTJ2K files. + * + * @param p_header_data the data contained in the CAP box. + * @param p_j2k the jpeg2000 codec. + * @param p_header_size the size of the data contained in the CAP marker. + * @param p_manager the user event manager. +*/ +static OPJ_BOOL opj_j2k_read_cap(opj_j2k_t *p_j2k, + OPJ_BYTE * p_header_data, + OPJ_UINT32 p_header_size, + opj_event_mgr_t * p_manager + ) +{ + /* preconditions */ + assert(p_header_data != 00); + assert(p_j2k != 00); + assert(p_manager != 00); + + (void)p_j2k; + (void)p_header_data; + (void)p_header_size; + (void)p_manager; + + return OPJ_TRUE; +} + +/** + * Reads a CPF marker (corresponding profile). Empty implementation. Found in HTJ2K files + * @param p_header_data the data contained in the CPF box. + * @param p_j2k the jpeg2000 codec. + * @param p_header_size the size of the data contained in the CPF marker. + * @param p_manager the user event manager. +*/ +static OPJ_BOOL opj_j2k_read_cpf(opj_j2k_t *p_j2k, + OPJ_BYTE * p_header_data, + OPJ_UINT32 p_header_size, + opj_event_mgr_t * p_manager + ) +{ + /* preconditions */ + assert(p_header_data != 00); + assert(p_j2k != 00); + assert(p_manager != 00); + + (void)p_j2k; + (void)p_header_data; + (void)p_header_size; + (void)p_manager; + + return OPJ_TRUE; +} + /* ----------------------------------------------------------------------- */ /* J2K / JPT decoder interface */ /* ----------------------------------------------------------------------- */ @@ -6417,9 +6764,21 @@ void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters) } } +void opj_j2k_decoder_set_strict_mode(opj_j2k_t *j2k, OPJ_BOOL strict) +{ + if (j2k) { + j2k->m_cp.strict = strict; + if (strict) { + j2k->m_specific_param.m_decoder.m_nb_tile_parts_correction_checked = 1; + } + } +} + OPJ_BOOL opj_j2k_set_threads(opj_j2k_t *j2k, OPJ_UINT32 num_threads) { - if (opj_has_thread_support()) { + /* Currently we pass the thread-pool to the tcd, so we cannot re-set it */ + /* afterwards */ + if (opj_has_thread_support() && j2k->m_tcd == NULL) { opj_thread_pool_destroy(j2k->m_tp); j2k->m_tp = NULL; if (num_threads <= (OPJ_UINT32)INT_MAX) { @@ -6434,7 +6793,7 @@ OPJ_BOOL opj_j2k_set_threads(opj_j2k_t *j2k, OPJ_UINT32 num_threads) return OPJ_FALSE; } -static int opj_j2k_get_default_thread_count() +static int opj_j2k_get_default_thread_count(void) { const char* num_threads_str = getenv("OPJ_NUM_THREADS"); int num_cpus; @@ -6614,7 +6973,7 @@ static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, } /* Precincts */ - parameters->csty |= 0x01; + parameters->csty |= J2K_CP_CSTY_PRT; if (parameters->numresolution == 1) { parameters->res_spec = 1; parameters->prcw_init[0] = 128; @@ -6695,7 +7054,7 @@ static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, /* Bitdepth */ for (i = 0; i < image->numcomps; i++) { - if ((image->comps[i].bpp != 12) | (image->comps[i].sgnd)) { + if ((image->comps[i].prec != 12) | (image->comps[i].sgnd)) { char signed_str[] = "signed"; char unsigned_str[] = "unsigned"; char *tmp_str = image->comps[i].sgnd ? signed_str : unsigned_str; @@ -6704,7 +7063,7 @@ static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, "Precision of each component shall be 12 bits unsigned" "-> At least component %d of input image (%d bits, %s) is not compliant\n" "-> Non-profile-3 codestream will be generated\n", - i, image->comps[i].bpp, tmp_str); + i, image->comps[i].prec, tmp_str); return OPJ_FALSE; } } @@ -6740,19 +7099,600 @@ static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, return OPJ_TRUE; } -OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, - opj_cparameters_t *parameters, - opj_image_t *image, - opj_event_mgr_t * p_manager) +static int opj_j2k_get_imf_max_NL(opj_cparameters_t *parameters, + opj_image_t *image) { - OPJ_UINT32 i, j, tileno, numpocs_tile; - opj_cp_t *cp = 00; - OPJ_UINT32 cblkw, cblkh; - - if (!p_j2k || !parameters || ! image) { - return OPJ_FALSE; + /* Decomposition levels */ + const OPJ_UINT16 rsiz = parameters->rsiz; + const OPJ_UINT16 profile = OPJ_GET_IMF_PROFILE(rsiz); + const OPJ_UINT32 XTsiz = parameters->tile_size_on ? (OPJ_UINT32) + parameters->cp_tdx : image->x1; + switch (profile) { + case OPJ_PROFILE_IMF_2K: + return 5; + case OPJ_PROFILE_IMF_4K: + return 6; + case OPJ_PROFILE_IMF_8K: + return 7; + case OPJ_PROFILE_IMF_2K_R: { + if (XTsiz >= 2048) { + return 5; + } else if (XTsiz >= 1024) { + return 4; + } + break; } - + case OPJ_PROFILE_IMF_4K_R: { + if (XTsiz >= 4096) { + return 6; + } else if (XTsiz >= 2048) { + return 5; + } else if (XTsiz >= 1024) { + return 4; + } + break; + } + case OPJ_PROFILE_IMF_8K_R: { + if (XTsiz >= 8192) { + return 7; + } else if (XTsiz >= 4096) { + return 6; + } else if (XTsiz >= 2048) { + return 5; + } else if (XTsiz >= 1024) { + return 4; + } + break; + } + default: + break; + } + return -1; +} + +static void opj_j2k_set_imf_parameters(opj_cparameters_t *parameters, + opj_image_t *image, opj_event_mgr_t *p_manager) +{ + const OPJ_UINT16 rsiz = parameters->rsiz; + const OPJ_UINT16 profile = OPJ_GET_IMF_PROFILE(rsiz); + + OPJ_UNUSED(p_manager); + + /* Override defaults set by opj_set_default_encoder_parameters */ + if (parameters->cblockw_init == OPJ_COMP_PARAM_DEFAULT_CBLOCKW && + parameters->cblockh_init == OPJ_COMP_PARAM_DEFAULT_CBLOCKH) { + parameters->cblockw_init = 32; + parameters->cblockh_init = 32; + } + + /* One tile part for each component */ + parameters->tp_flag = 'C'; + parameters->tp_on = 1; + + if (parameters->prog_order == OPJ_COMP_PARAM_DEFAULT_PROG_ORDER) { + parameters->prog_order = OPJ_CPRL; + } + + if (profile == OPJ_PROFILE_IMF_2K || + profile == OPJ_PROFILE_IMF_4K || + profile == OPJ_PROFILE_IMF_8K) { + /* 9-7 transform */ + parameters->irreversible = 1; + } + + /* Adjust the number of resolutions if set to its defaults */ + if (parameters->numresolution == OPJ_COMP_PARAM_DEFAULT_NUMRESOLUTION && + image->x0 == 0 && + image->y0 == 0) { + const int max_NL = opj_j2k_get_imf_max_NL(parameters, image); + if (max_NL >= 0 && parameters->numresolution > max_NL) { + parameters->numresolution = max_NL + 1; + } + + /* Note: below is generic logic */ + if (!parameters->tile_size_on) { + while (parameters->numresolution > 0) { + if (image->x1 < (1U << ((OPJ_UINT32)parameters->numresolution - 1U))) { + parameters->numresolution --; + continue; + } + if (image->y1 < (1U << ((OPJ_UINT32)parameters->numresolution - 1U))) { + parameters->numresolution --; + continue; + } + break; + } + } + } + + /* Set defaults precincts */ + if (parameters->csty == 0) { + parameters->csty |= J2K_CP_CSTY_PRT; + if (parameters->numresolution == 1) { + parameters->res_spec = 1; + parameters->prcw_init[0] = 128; + parameters->prch_init[0] = 128; + } else { + int i; + parameters->res_spec = parameters->numresolution - 1; + for (i = 0; i < parameters->res_spec; i++) { + parameters->prcw_init[i] = 256; + parameters->prch_init[i] = 256; + } + } + } +} + +/* Table A.53 from JPEG2000 standard */ +static const OPJ_UINT16 tabMaxSubLevelFromMainLevel[] = { + 15, /* unspecified */ + 1, + 1, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 +}; + +static OPJ_BOOL opj_j2k_is_imf_compliant(opj_cparameters_t *parameters, + opj_image_t *image, + opj_event_mgr_t *p_manager) +{ + OPJ_UINT32 i; + const OPJ_UINT16 rsiz = parameters->rsiz; + const OPJ_UINT16 profile = OPJ_GET_IMF_PROFILE(rsiz); + const OPJ_UINT16 mainlevel = OPJ_GET_IMF_MAINLEVEL(rsiz); + const OPJ_UINT16 sublevel = OPJ_GET_IMF_SUBLEVEL(rsiz); + const int NL = parameters->numresolution - 1; + const OPJ_UINT32 XTsiz = parameters->tile_size_on ? (OPJ_UINT32) + parameters->cp_tdx : image->x1; + OPJ_BOOL ret = OPJ_TRUE; + + /* Validate mainlevel */ + if (mainlevel > OPJ_IMF_MAINLEVEL_MAX) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profile require mainlevel <= 11.\n" + "-> %d is thus not compliant\n" + "-> Non-IMF codestream will be generated\n", + mainlevel); + ret = OPJ_FALSE; + } else { + /* Validate sublevel */ + assert(sizeof(tabMaxSubLevelFromMainLevel) == + (OPJ_IMF_MAINLEVEL_MAX + 1) * sizeof(tabMaxSubLevelFromMainLevel[0])); + if (sublevel > tabMaxSubLevelFromMainLevel[mainlevel]) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profile require sublevel <= %d for mainlevel = %d.\n" + "-> %d is thus not compliant\n" + "-> Non-IMF codestream will be generated\n", + tabMaxSubLevelFromMainLevel[mainlevel], + mainlevel, + sublevel); + ret = OPJ_FALSE; + } + } + + /* Number of components */ + if (image->numcomps > 3) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profiles require at most 3 components.\n" + "-> Number of components of input image (%d) is not compliant\n" + "-> Non-IMF codestream will be generated\n", + image->numcomps); + ret = OPJ_FALSE; + } + + if (image->x0 != 0 || image->y0 != 0) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profiles require image origin to be at 0,0.\n" + "-> %d,%d is not compliant\n" + "-> Non-IMF codestream will be generated\n", + image->x0, image->y0 != 0); + ret = OPJ_FALSE; + } + + if (parameters->cp_tx0 != 0 || parameters->cp_ty0 != 0) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profiles require tile origin to be at 0,0.\n" + "-> %d,%d is not compliant\n" + "-> Non-IMF codestream will be generated\n", + parameters->cp_tx0, parameters->cp_ty0); + ret = OPJ_FALSE; + } + + if (parameters->tile_size_on) { + if (profile == OPJ_PROFILE_IMF_2K || + profile == OPJ_PROFILE_IMF_4K || + profile == OPJ_PROFILE_IMF_8K) { + if ((OPJ_UINT32)parameters->cp_tdx < image->x1 || + (OPJ_UINT32)parameters->cp_tdy < image->y1) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 2K/4K/8K single tile profiles require tile to be greater or equal to image size.\n" + "-> %d,%d is lesser than %d,%d\n" + "-> Non-IMF codestream will be generated\n", + parameters->cp_tdx, + parameters->cp_tdy, + image->x1, + image->y1); + ret = OPJ_FALSE; + } + } else { + if ((OPJ_UINT32)parameters->cp_tdx >= image->x1 && + (OPJ_UINT32)parameters->cp_tdy >= image->y1) { + /* ok */ + } else if (parameters->cp_tdx == 1024 && + parameters->cp_tdy == 1024) { + /* ok */ + } else if (parameters->cp_tdx == 2048 && + parameters->cp_tdy == 2048 && + (profile == OPJ_PROFILE_IMF_4K || + profile == OPJ_PROFILE_IMF_8K)) { + /* ok */ + } else if (parameters->cp_tdx == 4096 && + parameters->cp_tdy == 4096 && + profile == OPJ_PROFILE_IMF_8K) { + /* ok */ + } else { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 2K_R/4K_R/8K_R single/multiple tile profiles " + "require tile to be greater or equal to image size,\n" + "or to be (1024,1024), or (2048,2048) for 4K_R/8K_R " + "or (4096,4096) for 8K_R.\n" + "-> %d,%d is non conformant\n" + "-> Non-IMF codestream will be generated\n", + parameters->cp_tdx, + parameters->cp_tdy); + ret = OPJ_FALSE; + } + } + } + + /* Bitdepth */ + for (i = 0; i < image->numcomps; i++) { + if (!(image->comps[i].prec >= 8 && image->comps[i].prec <= 16) || + (image->comps[i].sgnd)) { + char signed_str[] = "signed"; + char unsigned_str[] = "unsigned"; + char *tmp_str = image->comps[i].sgnd ? signed_str : unsigned_str; + opj_event_msg(p_manager, EVT_WARNING, + "IMF profiles require precision of each component to b in [8-16] bits unsigned" + "-> At least component %d of input image (%d bits, %s) is not compliant\n" + "-> Non-IMF codestream will be generated\n", + i, image->comps[i].prec, tmp_str); + ret = OPJ_FALSE; + } + } + + /* Sub-sampling */ + for (i = 0; i < image->numcomps; i++) { + if (i == 0 && image->comps[i].dx != 1) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profiles require XRSiz1 == 1. Here it is set to %d.\n" + "-> Non-IMF codestream will be generated\n", + image->comps[i].dx); + ret = OPJ_FALSE; + } + if (i == 1 && image->comps[i].dx != 1 && image->comps[i].dx != 2) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profiles require XRSiz2 == 1 or 2. Here it is set to %d.\n" + "-> Non-IMF codestream will be generated\n", + image->comps[i].dx); + ret = OPJ_FALSE; + } + if (i > 1 && image->comps[i].dx != image->comps[i - 1].dx) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profiles require XRSiz%d to be the same as XRSiz2. " + "Here it is set to %d instead of %d.\n" + "-> Non-IMF codestream will be generated\n", + i + 1, image->comps[i].dx, image->comps[i - 1].dx); + ret = OPJ_FALSE; + } + if (image->comps[i].dy != 1) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profiles require YRsiz == 1. " + "Here it is set to %d for component %d.\n" + "-> Non-IMF codestream will be generated\n", + image->comps[i].dy, i); + ret = OPJ_FALSE; + } + } + + /* Image size */ + switch (profile) { + case OPJ_PROFILE_IMF_2K: + case OPJ_PROFILE_IMF_2K_R: + if (((image->comps[0].w > 2048) | (image->comps[0].h > 1556))) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 2K/2K_R profile require:\n" + "width <= 2048 and height <= 1556\n" + "-> Input image size %d x %d is not compliant\n" + "-> Non-IMF codestream will be generated\n", + image->comps[0].w, image->comps[0].h); + ret = OPJ_FALSE; + } + break; + case OPJ_PROFILE_IMF_4K: + case OPJ_PROFILE_IMF_4K_R: + if (((image->comps[0].w > 4096) | (image->comps[0].h > 3112))) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K/4K_R profile require:\n" + "width <= 4096 and height <= 3112\n" + "-> Input image size %d x %d is not compliant\n" + "-> Non-IMF codestream will be generated\n", + image->comps[0].w, image->comps[0].h); + ret = OPJ_FALSE; + } + break; + case OPJ_PROFILE_IMF_8K: + case OPJ_PROFILE_IMF_8K_R: + if (((image->comps[0].w > 8192) | (image->comps[0].h > 6224))) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 8K/8K_R profile require:\n" + "width <= 8192 and height <= 6224\n" + "-> Input image size %d x %d is not compliant\n" + "-> Non-IMF codestream will be generated\n", + image->comps[0].w, image->comps[0].h); + ret = OPJ_FALSE; + } + break; + default : + assert(0); + return OPJ_FALSE; + } + + if (parameters->roi_compno != -1) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profile forbid RGN / region of interest marker.\n" + "-> Compression parameters specify a ROI\n" + "-> Non-IMF codestream will be generated\n"); + ret = OPJ_FALSE; + } + + if (parameters->cblockw_init != 32 || parameters->cblockh_init != 32) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profile require code block size to be 32x32.\n" + "-> Compression parameters set it to %dx%d.\n" + "-> Non-IMF codestream will be generated\n", + parameters->cblockw_init, + parameters->cblockh_init); + ret = OPJ_FALSE; + } + + if (parameters->prog_order != OPJ_CPRL) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profile require progression order to be CPRL.\n" + "-> Compression parameters set it to %d.\n" + "-> Non-IMF codestream will be generated\n", + parameters->prog_order); + ret = OPJ_FALSE; + } + + if (parameters->numpocs != 0) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profile forbid POC markers.\n" + "-> Compression parameters set %d POC.\n" + "-> Non-IMF codestream will be generated\n", + parameters->numpocs); + ret = OPJ_FALSE; + } + + /* Codeblock style: no mode switch enabled */ + if (parameters->mode != 0) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profile forbid mode switch in code block style.\n" + "-> Compression parameters set code block style to %d.\n" + "-> Non-IMF codestream will be generated\n", + parameters->mode); + ret = OPJ_FALSE; + } + + if (profile == OPJ_PROFILE_IMF_2K || + profile == OPJ_PROFILE_IMF_4K || + profile == OPJ_PROFILE_IMF_8K) { + /* Expect 9-7 transform */ + if (parameters->irreversible != 1) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 2K/4K/8K profiles require 9-7 Irreversible Transform.\n" + "-> Compression parameters set it to reversible.\n" + "-> Non-IMF codestream will be generated\n"); + ret = OPJ_FALSE; + } + } else { + /* Expect 5-3 transform */ + if (parameters->irreversible != 0) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 2K/4K/8K profiles require 5-3 reversible Transform.\n" + "-> Compression parameters set it to irreversible.\n" + "-> Non-IMF codestream will be generated\n"); + ret = OPJ_FALSE; + } + } + + /* Number of layers */ + if (parameters->tcp_numlayers != 1) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 2K/4K/8K profiles require 1 single quality layer.\n" + "-> Number of layers is %d.\n" + "-> Non-IMF codestream will be generated\n", + parameters->tcp_numlayers); + ret = OPJ_FALSE; + } + + /* Decomposition levels */ + switch (profile) { + case OPJ_PROFILE_IMF_2K: + if (!(NL >= 1 && NL <= 5)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 2K profile requires 1 <= NL <= 5:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + break; + case OPJ_PROFILE_IMF_4K: + if (!(NL >= 1 && NL <= 6)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K profile requires 1 <= NL <= 6:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + break; + case OPJ_PROFILE_IMF_8K: + if (!(NL >= 1 && NL <= 7)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 8K profile requires 1 <= NL <= 7:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + break; + case OPJ_PROFILE_IMF_2K_R: { + if (XTsiz >= 2048) { + if (!(NL >= 1 && NL <= 5)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 2K_R profile requires 1 <= NL <= 5 for XTsiz >= 2048:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } else if (XTsiz >= 1024) { + if (!(NL >= 1 && NL <= 4)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 2K_R profile requires 1 <= NL <= 4 for XTsiz in [1024,2048[:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } + break; + } + case OPJ_PROFILE_IMF_4K_R: { + if (XTsiz >= 4096) { + if (!(NL >= 1 && NL <= 6)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 6 for XTsiz >= 4096:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } else if (XTsiz >= 2048) { + if (!(NL >= 1 && NL <= 5)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 5 for XTsiz in [2048,4096[:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } else if (XTsiz >= 1024) { + if (!(NL >= 1 && NL <= 4)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 4 for XTsiz in [1024,2048[:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } + break; + } + case OPJ_PROFILE_IMF_8K_R: { + if (XTsiz >= 8192) { + if (!(NL >= 1 && NL <= 7)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 7 for XTsiz >= 8192:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } else if (XTsiz >= 4096) { + if (!(NL >= 1 && NL <= 6)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 6 for XTsiz in [4096,8192[:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } else if (XTsiz >= 2048) { + if (!(NL >= 1 && NL <= 5)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 5 for XTsiz in [2048,4096[:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } else if (XTsiz >= 1024) { + if (!(NL >= 1 && NL <= 4)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 4 for XTsiz in [1024,2048[:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } + break; + } + default: + break; + } + + if (parameters->numresolution == 1) { + if (parameters->res_spec != 1 || + parameters->prcw_init[0] != 128 || + parameters->prch_init[0] != 128) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profiles require PPx = PPy = 7 for NLLL band, else 8.\n" + "-> Supplied values are different from that.\n" + "-> Non-IMF codestream will be generated\n"); + ret = OPJ_FALSE; + } + } else { + int i; + for (i = 0; i < parameters->res_spec; i++) { + if (parameters->prcw_init[i] != 256 || + parameters->prch_init[i] != 256) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF profiles require PPx = PPy = 7 for NLLL band, else 8.\n" + "-> Supplied values are different from that.\n" + "-> Non-IMF codestream will be generated\n"); + ret = OPJ_FALSE; + } + } + } + + return ret; +} + + +OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, + opj_cparameters_t *parameters, + opj_image_t *image, + opj_event_mgr_t * p_manager) +{ + OPJ_UINT32 i, j, tileno, numpocs_tile; + opj_cp_t *cp = 00; + OPJ_UINT32 cblkw, cblkh; + + if (!p_j2k || !parameters || ! image) { + return OPJ_FALSE; + } + if ((parameters->numresolution <= 0) || (parameters->numresolution > OPJ_J2K_MAXRLVLS)) { opj_event_msg(p_manager, EVT_ERROR, @@ -6793,6 +7733,29 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, return OPJ_FALSE; } + if (parameters->cp_fixed_alloc) { + if (parameters->cp_matrice == NULL) { + opj_event_msg(p_manager, EVT_ERROR, + "cp_fixed_alloc set, but cp_matrice missing\n"); + return OPJ_FALSE; + } + + if (parameters->tcp_numlayers > J2K_TCD_MATRIX_MAX_LAYER_COUNT) { + opj_event_msg(p_manager, EVT_ERROR, + "tcp_numlayers when cp_fixed_alloc set should not exceed %d\n", + J2K_TCD_MATRIX_MAX_LAYER_COUNT); + return OPJ_FALSE; + } + if (parameters->numresolution > J2K_TCD_MATRIX_MAX_RESOLUTION_COUNT) { + opj_event_msg(p_manager, EVT_ERROR, + "numresolution when cp_fixed_alloc set should not exceed %d\n", + J2K_TCD_MATRIX_MAX_RESOLUTION_COUNT); + return OPJ_FALSE; + } + } + + p_j2k->m_specific_param.m_encoder.m_nb_comps = image->numcomps; + /* keep a link to cp so that we can destroy it later in j2k_destroy_compress */ cp = &(p_j2k->m_cp); @@ -6922,7 +7885,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, ((double)parameters->tcp_rates[parameters->tcp_numlayers - 1] * 8 * image->comps[0].dx * image->comps[0].dy)); if (temp_size > (OPJ_FLOAT32)INT_MAX) { - parameters->max_cs_size = (OPJ_FLOAT32)INT_MAX; + parameters->max_cs_size = INT_MAX; } else { parameters->max_cs_size = (int) floor(temp_size); } @@ -6932,6 +7895,15 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, } else { OPJ_FLOAT32 temp_rate; OPJ_BOOL cap = OPJ_FALSE; + + if (OPJ_IS_IMF(parameters->rsiz) && parameters->max_cs_size > 0 && + parameters->tcp_numlayers == 1 && parameters->tcp_rates[0] == 0) { + parameters->tcp_rates[0] = (OPJ_FLOAT32)(image->numcomps * image->comps[0].w * + image->comps[0].h * image->comps[0].prec) / + (OPJ_FLOAT32)(((OPJ_UINT32)parameters->max_cs_size) * 8 * image->comps[0].dx * + image->comps[0].dy); + } + temp_rate = (OPJ_FLOAT32)(((double)image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec) / (((double)parameters->max_cs_size) * 8 * image->comps[0].dx * @@ -6949,6 +7921,10 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, } } + if (OPJ_IS_CINEMA(parameters->rsiz) || OPJ_IS_IMF(parameters->rsiz)) { + p_j2k->m_specific_param.m_encoder.m_TLM = OPJ_TRUE; + } + /* Manage profiles and applications and set RSIZ */ /* set cinema parameters if required */ if (OPJ_IS_CINEMA(parameters->rsiz)) { @@ -6972,9 +7948,10 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, "JPEG 2000 Broadcast profiles not yet supported\n"); parameters->rsiz = OPJ_PROFILE_NONE; } else if (OPJ_IS_IMF(parameters->rsiz)) { - opj_event_msg(p_manager, EVT_WARNING, - "JPEG 2000 IMF profiles not yet supported\n"); - parameters->rsiz = OPJ_PROFILE_NONE; + opj_j2k_set_imf_parameters(parameters, image, p_manager); + if (!opj_j2k_is_imf_compliant(parameters, image, p_manager)) { + parameters->rsiz = OPJ_PROFILE_NONE; + } } else if (OPJ_IS_PART2(parameters->rsiz)) { if (parameters->rsiz == ((OPJ_PROFILE_PART2) | (OPJ_EXTENSION_NONE))) { opj_event_msg(p_manager, EVT_WARNING, @@ -6996,15 +7973,17 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, cp->m_specific_param.m_enc.m_max_comp_size = (OPJ_UINT32) parameters->max_comp_size; cp->rsiz = parameters->rsiz; - cp->m_specific_param.m_enc.m_disto_alloc = (OPJ_UINT32) - parameters->cp_disto_alloc & 1u; - cp->m_specific_param.m_enc.m_fixed_alloc = (OPJ_UINT32) - parameters->cp_fixed_alloc & 1u; - cp->m_specific_param.m_enc.m_fixed_quality = (OPJ_UINT32) - parameters->cp_fixed_quality & 1u; - - /* mod fixed_quality */ - if (parameters->cp_fixed_alloc && parameters->cp_matrice) { + if (parameters->cp_fixed_alloc) { + cp->m_specific_param.m_enc.m_quality_layer_alloc_strategy = FIXED_LAYER; + } else if (parameters->cp_fixed_quality) { + cp->m_specific_param.m_enc.m_quality_layer_alloc_strategy = + FIXED_DISTORTION_RATIO; + } else { + cp->m_specific_param.m_enc.m_quality_layer_alloc_strategy = + RATE_DISTORTION_RATIO; + } + + if (parameters->cp_fixed_alloc) { size_t array_size = (size_t)parameters->tcp_numlayers * (size_t)parameters->numresolution * 3 * sizeof(OPJ_INT32); cp->m_specific_param.m_enc.m_matrice = (OPJ_INT32 *) opj_malloc(array_size); @@ -7042,21 +8021,24 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, /* UniPG>> */ #ifdef USE_JPWL - cp->comment = (char*)opj_malloc(clen + strlen(version) + 11); + const size_t cp_comment_buf_size = clen + strlen(version) + 11; + cp->comment = (char*)opj_malloc(cp_comment_buf_size); if (!cp->comment) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate comment string\n"); return OPJ_FALSE; } - sprintf(cp->comment, "%s%s with JPWL", comment, version); + snprintf(cp->comment, cp_comment_buf_size, "%s%s with JPWL", + comment, version); #else - cp->comment = (char*)opj_malloc(clen + strlen(version) + 1); + const size_t cp_comment_buf_size = clen + strlen(version) + 1; + cp->comment = (char*)opj_malloc(cp_comment_buf_size); if (!cp->comment) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate comment string\n"); return OPJ_FALSE; } - sprintf(cp->comment, "%s%s", comment, version); + snprintf(cp->comment, cp_comment_buf_size, "%s%s", comment, version); #endif /* <tile_size_on) { - cp->tw = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(image->x1 - cp->tx0), - (OPJ_INT32)cp->tdx); - cp->th = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(image->y1 - cp->ty0), - (OPJ_INT32)cp->tdy); + if (cp->tdx == 0) { + opj_event_msg(p_manager, EVT_ERROR, "Invalid tile width\n"); + return OPJ_FALSE; + } + if (cp->tdy == 0) { + opj_event_msg(p_manager, EVT_ERROR, "Invalid tile height\n"); + return OPJ_FALSE; + } + cp->tw = opj_uint_ceildiv(image->x1 - cp->tx0, cp->tdx); + cp->th = opj_uint_ceildiv(image->y1 - cp->ty0, cp->tdy); + /* Check that the number of tiles is valid */ + if (cp->tw > 65535 / cp->th) { + opj_event_msg(p_manager, EVT_ERROR, + "Invalid number of tiles : %u x %u (maximum fixed by jpeg2000 norm is 65535 tiles)\n", + cp->tw, cp->th); + return OPJ_FALSE; + } } else { cp->tdx = image->x1 - cp->tx0; cp->tdy = image->y1 - cp->ty0; @@ -7136,7 +8131,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, } #endif /* USE_JPWL */ - /* initialize the mutiple tiles */ + /* initialize the multiple tiles */ /* ---------------------------- */ cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t)); if (!cp->tcps) { @@ -7144,32 +8139,28 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, "Not enough memory to allocate tile coding parameters\n"); return OPJ_FALSE; } - if (parameters->numpocs) { - /* initialisation of POC */ - opj_j2k_check_poc_val(parameters->POC, parameters->numpocs, - (OPJ_UINT32)parameters->numresolution, image->numcomps, - (OPJ_UINT32)parameters->tcp_numlayers, p_manager); - /* TODO MSD use the return value*/ - } for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { opj_tcp_t *tcp = &cp->tcps[tileno]; + const OPJ_BOOL fixed_distoratio = + cp->m_specific_param.m_enc.m_quality_layer_alloc_strategy == + FIXED_DISTORTION_RATIO; tcp->numlayers = (OPJ_UINT32)parameters->tcp_numlayers; for (j = 0; j < tcp->numlayers; j++) { - if (OPJ_IS_CINEMA(cp->rsiz)) { - if (cp->m_specific_param.m_enc.m_fixed_quality) { + if (OPJ_IS_CINEMA(cp->rsiz) || OPJ_IS_IMF(cp->rsiz)) { + if (fixed_distoratio) { tcp->distoratio[j] = parameters->tcp_distoratio[j]; } tcp->rates[j] = parameters->tcp_rates[j]; } else { - if (cp->m_specific_param.m_enc.m_fixed_quality) { /* add fixed_quality */ + if (fixed_distoratio) { tcp->distoratio[j] = parameters->tcp_distoratio[j]; } else { tcp->rates[j] = parameters->tcp_rates[j]; } } - if (!cp->m_specific_param.m_enc.m_fixed_quality && + if (!fixed_distoratio && tcp->rates[j] <= 1.0) { tcp->rates[j] = 0.0; /* force lossless */ } @@ -7184,16 +8175,22 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, if (parameters->numpocs) { /* initialisation of POC */ - tcp->POC = 1; for (i = 0; i < parameters->numpocs; i++) { if (tileno + 1 == parameters->POC[i].tile) { opj_poc_t *tcp_poc = &tcp->pocs[numpocs_tile]; + if (parameters->POC[numpocs_tile].compno0 >= image->numcomps) { + opj_event_msg(p_manager, EVT_ERROR, + "Invalid compno0 for POC %d\n", i); + return OPJ_FALSE; + } + tcp_poc->resno0 = parameters->POC[numpocs_tile].resno0; tcp_poc->compno0 = parameters->POC[numpocs_tile].compno0; tcp_poc->layno1 = parameters->POC[numpocs_tile].layno1; tcp_poc->resno1 = parameters->POC[numpocs_tile].resno1; - tcp_poc->compno1 = parameters->POC[numpocs_tile].compno1; + tcp_poc->compno1 = opj_uint_min(parameters->POC[numpocs_tile].compno1, + image->numcomps); tcp_poc->prg1 = parameters->POC[numpocs_tile].prg1; tcp_poc->tile = parameters->POC[numpocs_tile].tile; @@ -7201,7 +8198,16 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, } } - tcp->numpocs = numpocs_tile - 1 ; + if (numpocs_tile) { + + /* TODO MSD use the return value*/ + opj_j2k_check_poc_val(parameters->POC, tileno, parameters->numpocs, + (OPJ_UINT32)parameters->numresolution, image->numcomps, + (OPJ_UINT32)parameters->tcp_numlayers, p_manager); + + tcp->POC = 1; + tcp->numpocs = numpocs_tile - 1 ; + } } else { tcp->numpocs = 0; } @@ -7311,7 +8317,14 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, tccp->qmfbid = parameters->irreversible ? 0 : 1; tccp->qntsty = parameters->irreversible ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT; - tccp->numgbits = 2; + + if (OPJ_IS_CINEMA(parameters->rsiz) && + parameters->rsiz == OPJ_PROFILE_CINEMA_2K) { + /* From https://github.com/uclouvain/openjpeg/issues/1340 */ + tccp->numgbits = 1; + } else { + tccp->numgbits = 2; + } if ((OPJ_INT32)i == parameters->roi_compno) { tccp->roishift = parameters->roi_shift; @@ -7450,7 +8463,8 @@ static OPJ_BOOL opj_j2k_add_tlmarker(OPJ_UINT32 tileno, if (type == J2K_MS_SOT) { OPJ_UINT32 l_current_tile_part = cstr_index->tile_index[tileno].current_tpsno; - if (cstr_index->tile_index[tileno].tp_index) { + if (cstr_index->tile_index[tileno].tp_index && + l_current_tile_part < cstr_index->tile_index[tileno].nb_tps) { cstr_index->tile_index[tileno].tp_index[l_current_tile_part].start_pos = pos; } @@ -7527,11 +8541,6 @@ OPJ_BOOL opj_j2k_read_header(opj_stream_private_t *p_stream, /* Copy codestream image information to the output image */ opj_copy_image_header(p_j2k->m_private_image, *p_image); - /*Allocate and initialize some elements of codestrem index*/ - if (!opj_j2k_allocate_tile_element_cstr_index(p_j2k)) { - return OPJ_FALSE; - } - return OPJ_TRUE; } @@ -7883,6 +8892,87 @@ static OPJ_BOOL opj_j2k_decoding_validation(opj_j2k_t *p_j2k, return l_is_valid; } +/** Fill p_j2k->cstr_index->tp_index[].start_pos/end_pos fields from TLM marker segments */ +static void opj_j2k_build_tp_index_from_tlm(opj_j2k_t* p_j2k, + opj_event_mgr_t * p_manager) +{ + opj_j2k_tlm_info_t* l_tlm; + OPJ_UINT32 i; + OPJ_OFF_T l_cur_offset; + + assert(p_j2k->cstr_index->main_head_end > 0); + assert(p_j2k->cstr_index->nb_of_tiles > 0); + assert(p_j2k->cstr_index->tile_index != NULL); + + l_tlm = &(p_j2k->m_specific_param.m_decoder.m_tlm); + + if (l_tlm->m_entries_count == 0) { + l_tlm->m_is_invalid = OPJ_TRUE; + return; + } + + if (l_tlm->m_is_invalid) { + return; + } + + /* Initial pass to count the number of tile-parts per tile */ + for (i = 0; i < l_tlm->m_entries_count; ++i) { + OPJ_UINT32 l_tile_index_no = l_tlm->m_tile_part_infos[i].m_tile_index; + assert(l_tile_index_no < p_j2k->cstr_index->nb_of_tiles); + p_j2k->cstr_index->tile_index[l_tile_index_no].tileno = l_tile_index_no; + ++p_j2k->cstr_index->tile_index[l_tile_index_no].current_nb_tps; + } + + /* Now check that all tiles have at least one tile-part */ + for (i = 0; i < p_j2k->cstr_index->nb_of_tiles; ++i) { + if (p_j2k->cstr_index->tile_index[i].current_nb_tps == 0) { + opj_event_msg(p_manager, EVT_ERROR, + "opj_j2k_build_tp_index_from_tlm(): tile %d has no " + "registered tile-part in TLM marker segments.\n", i); + goto error; + } + } + + /* Final pass to fill p_j2k->cstr_index */ + l_cur_offset = p_j2k->cstr_index->main_head_end; + for (i = 0; i < l_tlm->m_entries_count; ++i) { + OPJ_UINT32 l_tile_index_no = l_tlm->m_tile_part_infos[i].m_tile_index; + opj_tile_index_t* l_tile_index = & + (p_j2k->cstr_index->tile_index[l_tile_index_no]); + if (!l_tile_index->tp_index) { + l_tile_index->tp_index = (opj_tp_index_t *) opj_calloc( + l_tile_index->current_nb_tps, sizeof(opj_tp_index_t)); + if (! l_tile_index->tp_index) { + opj_event_msg(p_manager, EVT_ERROR, + "opj_j2k_build_tp_index_from_tlm(): tile index allocation failed\n"); + goto error; + } + } + + assert(l_tile_index->nb_tps < l_tile_index->current_nb_tps); + l_tile_index->tp_index[l_tile_index->nb_tps].start_pos = l_cur_offset; + /* We don't know how to set the tp_index[].end_header field, but this is not really needed */ + /* If there would be no markers between SOT and SOD, that would be : */ + /* l_tile_index->tp_index[l_tile_index->nb_tps].end_header = l_cur_offset + 12; */ + l_tile_index->tp_index[l_tile_index->nb_tps].end_pos = l_cur_offset + + l_tlm->m_tile_part_infos[i].m_length; + ++l_tile_index->nb_tps; + + l_cur_offset += l_tlm->m_tile_part_infos[i].m_length; + } + + return; + +error: + l_tlm->m_is_invalid = OPJ_TRUE; + for (i = 0; i < l_tlm->m_entries_count; ++i) { + OPJ_UINT32 l_tile_index = l_tlm->m_tile_part_infos[i].m_tile_index; + p_j2k->cstr_index->tile_index[l_tile_index].current_nb_tps = 0; + opj_free(p_j2k->cstr_index->tile_index[l_tile_index].tp_index); + p_j2k->cstr_index->tile_index[l_tile_index].tp_index = NULL; + } +} + static OPJ_BOOL opj_j2k_read_header_procedure(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager) @@ -7936,7 +9026,7 @@ static OPJ_BOOL opj_j2k_read_header_procedure(opj_j2k_t *p_j2k, if (l_marker_handler->id == J2K_MS_UNK) { if (! opj_j2k_read_unk(p_j2k, p_stream, &l_current_marker, p_manager)) { opj_event_msg(p_manager, EVT_ERROR, - "Unknow marker have been detected and generated error.\n"); + "Unknown marker has been detected and generated error.\n"); return OPJ_FALSE; } @@ -8062,6 +9152,9 @@ static OPJ_BOOL opj_j2k_read_header_procedure(opj_j2k_t *p_j2k, /* Position of the last element if the main header */ p_j2k->cstr_index->main_head_end = (OPJ_UINT32) opj_stream_tell(p_stream) - 2; + /* Build tile-part index from TLM information */ + opj_j2k_build_tp_index_from_tlm(p_j2k, p_manager); + /* Next step: read a tile-part header */ p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT; @@ -8285,6 +9378,12 @@ void opj_j2k_destroy(opj_j2k_t *p_j2k) p_j2k->m_specific_param.m_decoder.m_comps_indices_to_decode = 00; p_j2k->m_specific_param.m_decoder.m_numcomps_to_decode = 0; + opj_free(p_j2k->m_specific_param.m_decoder.m_tlm.m_tile_part_infos); + p_j2k->m_specific_param.m_decoder.m_tlm.m_tile_part_infos = NULL; + + opj_free(p_j2k->m_specific_param.m_decoder.m_intersecting_tile_parts_offset); + p_j2k->m_specific_param.m_decoder.m_intersecting_tile_parts_offset = NULL; + } else { if (p_j2k->m_specific_param.m_encoder.m_encoded_tile_data) { @@ -8615,6 +9714,7 @@ OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t * p_j2k, OPJ_UINT32 l_marker_size; const opj_dec_memory_marker_handler_t * l_marker_handler = 00; opj_tcp_t * l_tcp = NULL; + const OPJ_UINT32 l_nb_tiles = p_j2k->m_cp.tw * p_j2k->m_cp.th; /* preconditions */ assert(p_stream != 00); @@ -8634,6 +9734,39 @@ OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t * p_j2k, while ((!p_j2k->m_specific_param.m_decoder.m_can_decode) && (l_current_marker != J2K_MS_EOC)) { + if (p_j2k->m_specific_param.m_decoder.m_num_intersecting_tile_parts > 0 && + p_j2k->m_specific_param.m_decoder.m_idx_intersecting_tile_parts < + p_j2k->m_specific_param.m_decoder.m_num_intersecting_tile_parts) { + OPJ_OFF_T next_tp_sot_pos; + + next_tp_sot_pos = + p_j2k->m_specific_param.m_decoder.m_intersecting_tile_parts_offset[p_j2k->m_specific_param.m_decoder.m_idx_intersecting_tile_parts]; + ++p_j2k->m_specific_param.m_decoder.m_idx_intersecting_tile_parts; + if (!(opj_stream_read_seek(p_stream, + next_tp_sot_pos, + p_manager))) { + opj_event_msg(p_manager, EVT_ERROR, "Problem with seek function\n"); + return OPJ_FALSE; + } + + /* Try to read 2 bytes (the marker ID) from stream and copy them into the buffer */ + if (opj_stream_read_data(p_stream, + p_j2k->m_specific_param.m_decoder.m_header_data, 2, p_manager) != 2) { + opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n"); + return OPJ_FALSE; + } + + /* Read 2 bytes from the buffer as the marker ID */ + opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data, + &l_current_marker, + 2); + + if (l_current_marker != J2K_MS_SOT) { + opj_event_msg(p_manager, EVT_ERROR, "Did not get expected SOT marker\n"); + return OPJ_FALSE; + } + } + /* Try to read until the Start Of Data is detected */ while (l_current_marker != J2K_MS_SOD) { @@ -8667,7 +9800,13 @@ OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t * p_j2k, } /* Why this condition? FIXME */ - if (p_j2k->m_specific_param.m_decoder.m_state & J2K_STATE_TPH) { + if ((p_j2k->m_specific_param.m_decoder.m_state & J2K_STATE_TPH) && + p_j2k->m_specific_param.m_decoder.m_sot_length != 0) { + if (p_j2k->m_specific_param.m_decoder.m_sot_length < l_marker_size + 2) { + opj_event_msg(p_manager, EVT_ERROR, + "Sot length is less than marker size + marker ID\n"); + return OPJ_FALSE; + } p_j2k->m_specific_param.m_decoder.m_sot_length -= (l_marker_size + 2); } l_marker_size -= 2; /* Subtract the size of the marker ID already read */ @@ -8777,20 +9916,83 @@ OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t * p_j2k, if (! opj_j2k_read_sod(p_j2k, p_stream, p_manager)) { return OPJ_FALSE; } + + /* Check if we can use the TLM index to access the next tile-part */ + if (!p_j2k->m_specific_param.m_decoder.m_can_decode && + p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec >= 0 && + p_j2k->m_current_tile_number == (OPJ_UINT32) + p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec && + !p_j2k->m_specific_param.m_decoder.m_tlm.m_is_invalid && + opj_stream_has_seek(p_stream)) { + l_tcp = p_j2k->m_cp.tcps + p_j2k->m_current_tile_number; + if (l_tcp->m_nb_tile_parts == + p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].nb_tps && + (OPJ_UINT32)l_tcp->m_current_tile_part_number + 1 < l_tcp->m_nb_tile_parts) { + const OPJ_OFF_T next_tp_sot_pos = p_j2k->cstr_index->tile_index[ + p_j2k->m_current_tile_number].tp_index[l_tcp->m_current_tile_part_number + + 1].start_pos; + + if (next_tp_sot_pos != opj_stream_tell(p_stream)) { +#if 0 + opj_event_msg(p_manager, EVT_INFO, + "opj_j2k_read_tile_header(tile=%u): seek to tile part %u at %" PRId64 "\n", + p_j2k->m_current_tile_number, + l_tcp->m_current_tile_part_number + 1, + next_tp_sot_pos); +#endif + + if (!(opj_stream_read_seek(p_stream, + next_tp_sot_pos, + p_manager))) { + opj_event_msg(p_manager, EVT_ERROR, "Problem with seek function\n"); + return OPJ_FALSE; + } + } + + /* Try to read 2 bytes (the marker ID) from stream and copy them into the buffer */ + if (opj_stream_read_data(p_stream, + p_j2k->m_specific_param.m_decoder.m_header_data, 2, p_manager) != 2) { + opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n"); + return OPJ_FALSE; + } + + /* Read 2 bytes from the buffer as the marker ID */ + opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data, + &l_current_marker, + 2); + + if (l_current_marker != J2K_MS_SOT) { + opj_event_msg(p_manager, EVT_ERROR, "Did not get expected SOT marker\n"); + return OPJ_FALSE; + } + + continue; + } + } + if (p_j2k->m_specific_param.m_decoder.m_can_decode && !p_j2k->m_specific_param.m_decoder.m_nb_tile_parts_correction_checked) { /* Issue 254 */ - OPJ_BOOL l_correction_needed; + OPJ_BOOL l_correction_needed = OPJ_FALSE; p_j2k->m_specific_param.m_decoder.m_nb_tile_parts_correction_checked = 1; - if (!opj_j2k_need_nb_tile_parts_correction(p_stream, - p_j2k->m_current_tile_number, &l_correction_needed, p_manager)) { + if (p_j2k->m_cp.tcps[p_j2k->m_current_tile_number].m_nb_tile_parts == 1) { + /* Skip opj_j2k_need_nb_tile_parts_correction() if there is + * only a single tile part declared. The + * opj_j2k_need_nb_tile_parts_correction() hack was needed + * for files with 5 declared tileparts (where they were + * actually 6). + * Doing it systematically hurts performance when reading + * Sentinel2 L1C JPEG2000 files as explained in + * https://lists.osgeo.org/pipermail/gdal-dev/2024-November/059805.html + */ + } else if (!opj_j2k_need_nb_tile_parts_correction(p_stream, + p_j2k->m_current_tile_number, &l_correction_needed, p_manager)) { opj_event_msg(p_manager, EVT_ERROR, "opj_j2k_apply_nb_tile_parts_correction error\n"); return OPJ_FALSE; } if (l_correction_needed) { - OPJ_UINT32 l_nb_tiles = p_j2k->m_cp.tw * p_j2k->m_cp.th; OPJ_UINT32 l_tile_no; p_j2k->m_specific_param.m_decoder.m_can_decode = 0; @@ -8805,27 +10007,42 @@ OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t * p_j2k, "Non conformant codestream TPsot==TNsot.\n"); } } - if (! p_j2k->m_specific_param.m_decoder.m_can_decode) { - /* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer */ - if (opj_stream_read_data(p_stream, - p_j2k->m_specific_param.m_decoder.m_header_data, 2, p_manager) != 2) { - opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n"); - return OPJ_FALSE; - } - - /* Read 2 bytes from buffer as the new marker ID */ - opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data, - &l_current_marker, 2); - } } else { /* Indicate we will try to read a new tile-part header*/ p_j2k->m_specific_param.m_decoder.m_skip_data = 0; p_j2k->m_specific_param.m_decoder.m_can_decode = 0; p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT; + } + if (! p_j2k->m_specific_param.m_decoder.m_can_decode) { /* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer */ if (opj_stream_read_data(p_stream, p_j2k->m_specific_param.m_decoder.m_header_data, 2, p_manager) != 2) { + + /* Deal with likely non conformant SPOT6 files, where the last */ + /* row of tiles have TPsot == 0 and TNsot == 0, and missing EOC, */ + /* but no other tile-parts were found. */ + if (p_j2k->m_current_tile_number + 1 == l_nb_tiles) { + OPJ_UINT32 l_tile_no; + for (l_tile_no = 0U; l_tile_no < l_nb_tiles; ++l_tile_no) { + if (p_j2k->m_cp.tcps[l_tile_no].m_current_tile_part_number == 0 && + p_j2k->m_cp.tcps[l_tile_no].m_nb_tile_parts == 0) { + break; + } + } + if (l_tile_no < l_nb_tiles) { + opj_event_msg(p_manager, EVT_INFO, + "Tile %u has TPsot == 0 and TNsot == 0, " + "but no other tile-parts were found. " + "EOC is also missing.\n", + l_tile_no); + p_j2k->m_current_tile_number = l_tile_no; + l_current_marker = J2K_MS_EOC; + p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_EOC; + break; + } + } + opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n"); return OPJ_FALSE; } @@ -8838,12 +10055,14 @@ OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t * p_j2k, /* Current marker is the EOC marker ?*/ if (l_current_marker == J2K_MS_EOC) { - p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_EOC; + if (p_j2k->m_specific_param.m_decoder.m_state != J2K_STATE_EOC) { + p_j2k->m_current_tile_number = 0; + p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_EOC; + } } - /* FIXME DOC ???*/ + /* Deal with tiles that have a single tile-part with TPsot == 0 and TNsot == 0 */ if (! p_j2k->m_specific_param.m_decoder.m_can_decode) { - OPJ_UINT32 l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw; l_tcp = p_j2k->m_cp.tcps + p_j2k->m_current_tile_number; while ((p_j2k->m_current_tile_number < l_nb_tiles) && (l_tcp->m_data == 00)) { @@ -8924,7 +10143,7 @@ OPJ_BOOL opj_j2k_decode_tile(opj_j2k_t * p_j2k, /* When using the opj_read_tile_header / opj_decode_tile_data API */ /* such as in test_tile_decoder, m_output_image is NULL, so fall back */ /* to the full image dimension. This is a bit surprising that */ - /* opj_set_decode_area() is only used to determinte intersecting tiles, */ + /* opj_set_decode_area() is only used to determine intersecting tiles, */ /* but full tile decoding is done */ l_image_for_bounds = p_j2k->m_output_image ? p_j2k->m_output_image : p_j2k->m_private_image; @@ -8970,10 +10189,10 @@ OPJ_BOOL opj_j2k_decode_tile(opj_j2k_t * p_j2k, if (p_j2k->m_specific_param.m_decoder.m_state != J2K_STATE_EOC) { if (opj_stream_read_data(p_stream, l_data, 2, p_manager) != 2) { - opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n"); - return OPJ_FALSE; + opj_event_msg(p_manager, p_j2k->m_cp.strict ? EVT_ERROR : EVT_WARNING, + "Stream too short\n"); + return p_j2k->m_cp.strict ? OPJ_FALSE : OPJ_TRUE; } - opj_read_bytes(l_data, &l_current_marker, 2); if (l_current_marker == J2K_MS_EOC) { @@ -9220,11 +10439,17 @@ static OPJ_BOOL opj_j2k_update_image_dimensions(opj_image_t* p_image, l_img_comp = p_image->comps; for (it_comp = 0; it_comp < p_image->numcomps; ++it_comp) { OPJ_INT32 l_h, l_w; + if (p_image->x0 > (OPJ_UINT32)INT_MAX || + p_image->y0 > (OPJ_UINT32)INT_MAX || + p_image->x1 > (OPJ_UINT32)INT_MAX || + p_image->y1 > (OPJ_UINT32)INT_MAX) { + opj_event_msg(p_manager, EVT_ERROR, + "Image coordinates above INT_MAX are not supported\n"); + return OPJ_FALSE; + } - l_img_comp->x0 = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)p_image->x0, - (OPJ_INT32)l_img_comp->dx); - l_img_comp->y0 = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)p_image->y0, - (OPJ_INT32)l_img_comp->dy); + l_img_comp->x0 = opj_uint_ceildiv(p_image->x0, l_img_comp->dx); + l_img_comp->y0 = opj_uint_ceildiv(p_image->y0, l_img_comp->dy); l_comp_x1 = opj_int_ceildiv((OPJ_INT32)p_image->x1, (OPJ_INT32)l_img_comp->dx); l_comp_y1 = opj_int_ceildiv((OPJ_INT32)p_image->y1, (OPJ_INT32)l_img_comp->dy); @@ -9427,8 +10652,8 @@ OPJ_BOOL opj_j2k_set_decode_area(opj_j2k_t *p_j2k, p_j2k->m_specific_param.m_decoder.m_end_tile_x = l_cp->tw; p_image->x1 = l_image->x1; } else { - p_j2k->m_specific_param.m_decoder.m_end_tile_x = (OPJ_UINT32)opj_int_ceildiv( - p_end_x - (OPJ_INT32)l_cp->tx0, (OPJ_INT32)l_cp->tdx); + p_j2k->m_specific_param.m_decoder.m_end_tile_x = opj_uint_ceildiv(( + OPJ_UINT32)p_end_x - l_cp->tx0, l_cp->tdx); p_image->x1 = (OPJ_UINT32)p_end_x; } @@ -9451,8 +10676,8 @@ OPJ_BOOL opj_j2k_set_decode_area(opj_j2k_t *p_j2k, p_j2k->m_specific_param.m_decoder.m_end_tile_y = l_cp->th; p_image->y1 = l_image->y1; } else { - p_j2k->m_specific_param.m_decoder.m_end_tile_y = (OPJ_UINT32)opj_int_ceildiv( - p_end_y - (OPJ_INT32)l_cp->ty0, (OPJ_INT32)l_cp->tdy); + p_j2k->m_specific_param.m_decoder.m_end_tile_y = opj_uint_ceildiv(( + OPJ_UINT32)p_end_y - l_cp->ty0, l_cp->tdy); p_image->y1 = (OPJ_UINT32)p_end_y; } /* ----- */ @@ -9482,6 +10707,9 @@ opj_j2k_t* opj_j2k_create_decompress(void) /* per component is allowed */ l_j2k->m_cp.allow_different_bit_depth_sign = 1; + /* Default to using strict mode. */ + l_j2k->m_cp.strict = OPJ_TRUE; + #ifdef OPJ_DISABLE_TPSOT_FIX l_j2k->m_specific_param.m_decoder.m_nb_tile_parts_correction_checked = 1; #endif @@ -9738,9 +10966,9 @@ static OPJ_BOOL opj_j2k_read_SPCod_SPCoc(opj_j2k_t *p_j2k, return OPJ_FALSE; } - opj_read_bytes(l_current_ptr, &l_tccp->numresolutions, - 1); /* SPcox (D) */ - ++l_tccp->numresolutions; /* tccp->numresolutions = read() + 1 */ + /* SPcod (D) / SPcoc (A) */ + opj_read_bytes(l_current_ptr, &l_tccp->numresolutions, 1); + ++l_tccp->numresolutions; /* tccp->numresolutions = read() + 1 */ if (l_tccp->numresolutions > OPJ_J2K_MAXRLVLS) { opj_event_msg(p_manager, EVT_ERROR, "Invalid value for numresolutions : %d, max value is set in openjpeg.h at %d\n", @@ -9761,11 +10989,13 @@ static OPJ_BOOL opj_j2k_read_SPCod_SPCoc(opj_j2k_t *p_j2k, return OPJ_FALSE; } - opj_read_bytes(l_current_ptr, &l_tccp->cblkw, 1); /* SPcoc (E) */ + /* SPcod (E) / SPcoc (B) */ + opj_read_bytes(l_current_ptr, &l_tccp->cblkw, 1); ++l_current_ptr; l_tccp->cblkw += 2; - opj_read_bytes(l_current_ptr, &l_tccp->cblkh, 1); /* SPcoc (F) */ + /* SPcod (F) / SPcoc (C) */ + opj_read_bytes(l_current_ptr, &l_tccp->cblkh, 1); ++l_current_ptr; l_tccp->cblkh += 2; @@ -9776,18 +11006,26 @@ static OPJ_BOOL opj_j2k_read_SPCod_SPCoc(opj_j2k_t *p_j2k, return OPJ_FALSE; } - - opj_read_bytes(l_current_ptr, &l_tccp->cblksty, 1); /* SPcoc (G) */ + /* SPcod (G) / SPcoc (D) */ + opj_read_bytes(l_current_ptr, &l_tccp->cblksty, 1); ++l_current_ptr; - if (l_tccp->cblksty & 0xC0U) { /* 2 msb are reserved, assume we can't read */ + if ((l_tccp->cblksty & J2K_CCP_CBLKSTY_HTMIXED) != 0) { + /* We do not support HT mixed mode yet. For conformance, it should be supported.*/ opj_event_msg(p_manager, EVT_ERROR, - "Error reading SPCod SPCoc element, Invalid code-block style found\n"); + "Error reading SPCod SPCoc element. Unsupported Mixed HT code-block style found\n"); return OPJ_FALSE; } - opj_read_bytes(l_current_ptr, &l_tccp->qmfbid, 1); /* SPcoc (H) */ + /* SPcod (H) / SPcoc (E) */ + opj_read_bytes(l_current_ptr, &l_tccp->qmfbid, 1); ++l_current_ptr; + if (l_tccp->qmfbid > 1) { + opj_event_msg(p_manager, EVT_ERROR, + "Error reading SPCod SPCoc element, Invalid transformation found\n"); + return OPJ_FALSE; + } + *p_header_size = *p_header_size - 5; /* use custom precinct size ? */ @@ -9797,8 +11035,9 @@ static OPJ_BOOL opj_j2k_read_SPCod_SPCoc(opj_j2k_t *p_j2k, return OPJ_FALSE; } + /* SPcod (I_i) / SPcoc (F_i) */ for (i = 0; i < l_tccp->numresolutions; ++i) { - opj_read_bytes(l_current_ptr, &l_tmp, 1); /* SPcoc (I_i) */ + opj_read_bytes(l_current_ptr, &l_tmp, 1); ++l_current_ptr; /* Precinct exponent 0 is only allowed for lowest resolution level (Table A.21) */ if ((i != 0) && (((l_tmp & 0xf) == 0) || ((l_tmp >> 4) == 0))) { @@ -10125,6 +11364,10 @@ static OPJ_BOOL opj_j2k_read_SQcd_SQcc(opj_j2k_t *p_j2k, l_tccp->stepsizes[l_band_no].mant = 0; } } + + if (*p_header_size < l_num_band) { + return OPJ_FALSE; + } *p_header_size = *p_header_size - l_num_band; } else { for (l_band_no = 0; l_band_no < l_num_band; l_band_no++) { @@ -10135,6 +11378,10 @@ static OPJ_BOOL opj_j2k_read_SQcd_SQcc(opj_j2k_t *p_j2k, l_tccp->stepsizes[l_band_no].mant = l_tmp & 0x7ff; } } + + if (*p_header_size < 2 * l_num_band) { + return OPJ_FALSE; + } *p_header_size = *p_header_size - 2 * l_num_band; } @@ -10316,6 +11563,17 @@ static void opj_j2k_dump_MH_index(opj_j2k_t* p_j2k, FILE* out_stream) OPJ_UINT32 l_acc_nb_of_tile_part = 0; for (it_tile = 0; it_tile < cstr_index->nb_of_tiles ; it_tile++) { l_acc_nb_of_tile_part += cstr_index->tile_index[it_tile].nb_tps; + + /* To avoid regenerating expected opj_dump results from the test */ + /* suite when there is a TLM marker present */ + if (cstr_index->tile_index[it_tile].nb_tps && + cstr_index->tile_index[it_tile].tp_index && + cstr_index->tile_index[it_tile].tp_index[0].start_pos > 0 && + cstr_index->tile_index[it_tile].tp_index[0].end_header == 0 && + getenv("OJP_DO_NOT_DISPLAY_TILE_INDEX_IF_TLM") != NULL) { + l_acc_nb_of_tile_part = 0; + break; + } } if (l_acc_nb_of_tile_part) { @@ -10362,9 +11620,12 @@ static void opj_j2k_dump_MH_info(opj_j2k_t* p_j2k, FILE* out_stream) fprintf(out_stream, "Codestream info from main header: {\n"); - fprintf(out_stream, "\t tx0=%d, ty0=%d\n", p_j2k->m_cp.tx0, p_j2k->m_cp.ty0); - fprintf(out_stream, "\t tdx=%d, tdy=%d\n", p_j2k->m_cp.tdx, p_j2k->m_cp.tdy); - fprintf(out_stream, "\t tw=%d, th=%d\n", p_j2k->m_cp.tw, p_j2k->m_cp.th); + fprintf(out_stream, "\t tx0=%" PRIu32 ", ty0=%" PRIu32 "\n", p_j2k->m_cp.tx0, + p_j2k->m_cp.ty0); + fprintf(out_stream, "\t tdx=%" PRIu32 ", tdy=%" PRIu32 "\n", p_j2k->m_cp.tdx, + p_j2k->m_cp.tdy); + fprintf(out_stream, "\t tw=%" PRIu32 ", th=%" PRIu32 "\n", p_j2k->m_cp.tw, + p_j2k->m_cp.th); opj_j2k_dump_tile_info(p_j2k->m_specific_param.m_decoder.m_default_tcp, (OPJ_INT32)p_j2k->m_private_image->numcomps, out_stream); fprintf(out_stream, "}\n"); @@ -10641,6 +11902,54 @@ static OPJ_BOOL opj_j2k_allocate_tile_element_cstr_index(opj_j2k_t *p_j2k) return OPJ_TRUE; } +static OPJ_BOOL opj_j2k_are_all_used_components_decoded(opj_j2k_t *p_j2k, + opj_event_mgr_t * p_manager) +{ + OPJ_UINT32 compno; + OPJ_BOOL decoded_all_used_components = OPJ_TRUE; + + if (p_j2k->m_specific_param.m_decoder.m_numcomps_to_decode) { + for (compno = 0; + compno < p_j2k->m_specific_param.m_decoder.m_numcomps_to_decode; compno++) { + OPJ_UINT32 dec_compno = + p_j2k->m_specific_param.m_decoder.m_comps_indices_to_decode[compno]; + if (p_j2k->m_output_image->comps[dec_compno].data == NULL) { + opj_event_msg(p_manager, EVT_WARNING, "Failed to decode component %d\n", + dec_compno); + decoded_all_used_components = OPJ_FALSE; + } + } + } else { + for (compno = 0; compno < p_j2k->m_output_image->numcomps; compno++) { + if (p_j2k->m_output_image->comps[compno].data == NULL) { + opj_event_msg(p_manager, EVT_WARNING, "Failed to decode component %d\n", + compno); + decoded_all_used_components = OPJ_FALSE; + } + } + } + + if (decoded_all_used_components == OPJ_FALSE) { + opj_event_msg(p_manager, EVT_ERROR, "Failed to decode all used components\n"); + return OPJ_FALSE; + } + + return OPJ_TRUE; +} + +static int CompareOffT(const void* a, const void* b) +{ + const OPJ_OFF_T offA = *(const OPJ_OFF_T*)a; + const OPJ_OFF_T offB = *(const OPJ_OFF_T*)b; + if (offA < offB) { + return -1; + } + if (offA == offB) { + return 0; + } + return 1; +} + static OPJ_BOOL opj_j2k_decode_tiles(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager) @@ -10650,6 +11959,7 @@ static OPJ_BOOL opj_j2k_decode_tiles(opj_j2k_t *p_j2k, OPJ_INT32 l_tile_x0, l_tile_y0, l_tile_x1, l_tile_y1; OPJ_UINT32 l_nb_comps; OPJ_UINT32 nr_tiles = 0; + OPJ_OFF_T end_pos = 0; /* Particular case for whole single tile decoding */ /* We can avoid allocating intermediate tile buffers */ @@ -10672,8 +11982,9 @@ static OPJ_BOOL opj_j2k_decode_tiles(opj_j2k_t *p_j2k, return OPJ_FALSE; } - if (! opj_j2k_decode_tile(p_j2k, l_current_tile_no, NULL, 0, - p_stream, p_manager)) { + if (!l_go_on || + ! opj_j2k_decode_tile(p_j2k, l_current_tile_no, NULL, 0, + p_stream, p_manager)) { opj_event_msg(p_manager, EVT_ERROR, "Failed to decode tile 1/1\n"); return OPJ_FALSE; } @@ -10691,6 +12002,77 @@ static OPJ_BOOL opj_j2k_decode_tiles(opj_j2k_t *p_j2k, return OPJ_TRUE; } + p_j2k->m_specific_param.m_decoder.m_num_intersecting_tile_parts = 0; + p_j2k->m_specific_param.m_decoder.m_idx_intersecting_tile_parts = 0; + opj_free(p_j2k->m_specific_param.m_decoder.m_intersecting_tile_parts_offset); + p_j2k->m_specific_param.m_decoder.m_intersecting_tile_parts_offset = NULL; + + /* If the area to decode only intersects a subset of tiles, and we have + * valid TLM information, then use it to plan the tilepart offsets to + * seek to. + */ + if (!(p_j2k->m_specific_param.m_decoder.m_start_tile_x == 0 && + p_j2k->m_specific_param.m_decoder.m_start_tile_y == 0 && + p_j2k->m_specific_param.m_decoder.m_end_tile_x == p_j2k->m_cp.tw && + p_j2k->m_specific_param.m_decoder.m_end_tile_y == p_j2k->m_cp.th) && + !p_j2k->m_specific_param.m_decoder.m_tlm.m_is_invalid && + opj_stream_has_seek(p_stream)) { + OPJ_UINT32 m_num_intersecting_tile_parts = 0; + + OPJ_UINT32 j; + for (j = 0; j < p_j2k->m_cp.tw * p_j2k->m_cp.th; ++j) { + if (p_j2k->cstr_index->tile_index[j].nb_tps > 0 && + p_j2k->cstr_index->tile_index[j].tp_index[ + p_j2k->cstr_index->tile_index[j].nb_tps - 1].end_pos > end_pos) { + end_pos = p_j2k->cstr_index->tile_index[j].tp_index[ + p_j2k->cstr_index->tile_index[j].nb_tps - 1].end_pos; + } + } + + for (j = p_j2k->m_specific_param.m_decoder.m_start_tile_y; + j < p_j2k->m_specific_param.m_decoder.m_end_tile_y; ++j) { + OPJ_UINT32 i; + for (i = p_j2k->m_specific_param.m_decoder.m_start_tile_x; + i < p_j2k->m_specific_param.m_decoder.m_end_tile_x; ++i) { + const OPJ_UINT32 tile_number = j * p_j2k->m_cp.tw + i; + m_num_intersecting_tile_parts += + p_j2k->cstr_index->tile_index[tile_number].nb_tps; + } + } + + p_j2k->m_specific_param.m_decoder.m_intersecting_tile_parts_offset = + (OPJ_OFF_T*) + opj_malloc(m_num_intersecting_tile_parts * sizeof(OPJ_OFF_T)); + if (m_num_intersecting_tile_parts > 0 && + p_j2k->m_specific_param.m_decoder.m_intersecting_tile_parts_offset) { + OPJ_UINT32 idx = 0; + for (j = p_j2k->m_specific_param.m_decoder.m_start_tile_y; + j < p_j2k->m_specific_param.m_decoder.m_end_tile_y; ++j) { + OPJ_UINT32 i; + for (i = p_j2k->m_specific_param.m_decoder.m_start_tile_x; + i < p_j2k->m_specific_param.m_decoder.m_end_tile_x; ++i) { + const OPJ_UINT32 tile_number = j * p_j2k->m_cp.tw + i; + OPJ_UINT32 k; + for (k = 0; k < p_j2k->cstr_index->tile_index[tile_number].nb_tps; ++k) { + const OPJ_OFF_T next_tp_sot_pos = + p_j2k->cstr_index->tile_index[tile_number].tp_index[k].start_pos; + p_j2k->m_specific_param.m_decoder.m_intersecting_tile_parts_offset[idx] = + next_tp_sot_pos; + ++idx; + } + } + } + + p_j2k->m_specific_param.m_decoder.m_num_intersecting_tile_parts = idx; + + /* Sort by increasing offset */ + qsort(p_j2k->m_specific_param.m_decoder.m_intersecting_tile_parts_offset, + p_j2k->m_specific_param.m_decoder.m_num_intersecting_tile_parts, + sizeof(OPJ_OFF_T), + CompareOffT); + } + } + for (;;) { if (p_j2k->m_cp.tw == 1 && p_j2k->m_cp.th == 1 && p_j2k->m_cp.tcps[0].m_data != NULL) { @@ -10750,13 +12132,23 @@ static OPJ_BOOL opj_j2k_decode_tiles(opj_j2k_t *p_j2k, if (++nr_tiles == p_j2k->m_cp.th * p_j2k->m_cp.tw) { break; } + if (p_j2k->m_specific_param.m_decoder.m_num_intersecting_tile_parts > 0 && + p_j2k->m_specific_param.m_decoder.m_idx_intersecting_tile_parts == + p_j2k->m_specific_param.m_decoder.m_num_intersecting_tile_parts) { + opj_stream_seek(p_stream, end_pos + 2, p_manager); + break; + } + } + + if (! opj_j2k_are_all_used_components_decoded(p_j2k, p_manager)) { + return OPJ_FALSE; } return OPJ_TRUE; } /** - * Sets up the procedures to do on decoding data. Developpers wanting to extend the library can add their own reading procedures. + * Sets up the procedures to do on decoding data. Developers wanting to extend the library can add their own reading procedures. */ static OPJ_BOOL opj_j2k_setup_decoding(opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager) @@ -10789,12 +12181,6 @@ static OPJ_BOOL opj_j2k_decode_one_tile(opj_j2k_t *p_j2k, OPJ_UINT32 l_nb_tiles; OPJ_UINT32 i; - /*Allocate and initialize some elements of codestrem index if not already done*/ - if (!p_j2k->cstr_index->tile_index) { - if (!opj_j2k_allocate_tile_element_cstr_index(p_j2k)) { - return OPJ_FALSE; - } - } /* Move into the codestream to the first SOT used to decode the desired tile */ l_tile_no_to_dec = (OPJ_UINT32) p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec; @@ -10809,12 +12195,38 @@ static OPJ_BOOL opj_j2k_decode_one_tile(opj_j2k_t *p_j2k, return OPJ_FALSE; } } else { + OPJ_OFF_T sot_pos = + p_j2k->cstr_index->tile_index[l_tile_no_to_dec].tp_index[0].start_pos; + OPJ_UINT32 l_marker; + +#if 0 + opj_event_msg(p_manager, EVT_INFO, + "opj_j2k_decode_one_tile(%u): seek to %" PRId64 "\n", + l_tile_no_to_dec, + sot_pos); +#endif if (!(opj_stream_read_seek(p_stream, - p_j2k->cstr_index->tile_index[l_tile_no_to_dec].tp_index[0].start_pos + 2, + sot_pos, p_manager))) { opj_event_msg(p_manager, EVT_ERROR, "Problem with seek function\n"); return OPJ_FALSE; } + + /* Try to read 2 bytes (the marker ID) from stream and copy them into the buffer */ + if (opj_stream_read_data(p_stream, + p_j2k->m_specific_param.m_decoder.m_header_data, 2, p_manager) != 2) { + opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n"); + return OPJ_FALSE; + } + + /* Read 2 bytes from the buffer as the marker ID */ + opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data, &l_marker, + 2); + + if (l_marker != J2K_MS_SOT) { + opj_event_msg(p_manager, EVT_ERROR, "Did not get expected SOT marker\n"); + return OPJ_FALSE; + } } /* Special case if we have previously read the EOC marker (if the previous tile getted is the last ) */ if (p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_EOC) { @@ -10880,11 +12292,15 @@ static OPJ_BOOL opj_j2k_decode_one_tile(opj_j2k_t *p_j2k, } + if (! opj_j2k_are_all_used_components_decoded(p_j2k, p_manager)) { + return OPJ_FALSE; + } + return OPJ_TRUE; } /** - * Sets up the procedures to do on decoding one tile. Developpers wanting to extend the library can add their own reading procedures. + * Sets up the procedures to do on decoding one tile. Developers wanting to extend the library can add their own reading procedures. */ static OPJ_BOOL opj_j2k_setup_decoding_tile(opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager) @@ -10950,7 +12366,7 @@ static OPJ_BOOL opj_j2k_move_data_from_codec_to_output_image(opj_j2k_t * p_j2k, p_image->comps[compno].data = p_j2k->m_output_image->comps[compno].data; #if 0 char fn[256]; - sprintf(fn, "/tmp/%d.raw", compno); + snprintf(fn, sizeof fn, "/tmp/%d.raw", compno); FILE *debug = fopen(fn, "wb"); fwrite(p_image->comps[compno].data, sizeof(OPJ_INT32), p_image->comps[compno].w * p_image->comps[compno].h, debug); @@ -11076,10 +12492,8 @@ OPJ_BOOL opj_j2k_get_tile(opj_j2k_t *p_j2k, l_img_comp->factor = p_j2k->m_private_image->comps[compno].factor; - l_img_comp->x0 = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)p_image->x0, - (OPJ_INT32)l_img_comp->dx); - l_img_comp->y0 = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)p_image->y0, - (OPJ_INT32)l_img_comp->dy); + l_img_comp->x0 = opj_uint_ceildiv(p_image->x0, l_img_comp->dx); + l_img_comp->y0 = opj_uint_ceildiv(p_image->y0, l_img_comp->dy); l_comp_x1 = opj_int_ceildiv((OPJ_INT32)p_image->x1, (OPJ_INT32)l_img_comp->dx); l_comp_y1 = opj_int_ceildiv((OPJ_INT32)p_image->y1, (OPJ_INT32)l_img_comp->dy); @@ -11110,7 +12524,7 @@ OPJ_BOOL opj_j2k_get_tile(opj_j2k_t *p_j2k, opj_image_destroy(p_j2k->m_output_image); } - /* Create the ouput image from the information previously computed*/ + /* Create the output image from the information previously computed*/ p_j2k->m_output_image = opj_image_create0(); if (!(p_j2k->m_output_image)) { return OPJ_FALSE; @@ -11166,6 +12580,71 @@ OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k, return OPJ_FALSE; } +/* ----------------------------------------------------------------------- */ + +OPJ_BOOL opj_j2k_encoder_set_extra_options( + opj_j2k_t *p_j2k, + const char* const* p_options, + opj_event_mgr_t * p_manager) +{ + const char* const* p_option_iter; + + if (p_options == NULL) { + return OPJ_TRUE; + } + + for (p_option_iter = p_options; *p_option_iter != NULL; ++p_option_iter) { + if (strncmp(*p_option_iter, "PLT=", 4) == 0) { + if (strcmp(*p_option_iter, "PLT=YES") == 0) { + p_j2k->m_specific_param.m_encoder.m_PLT = OPJ_TRUE; + } else if (strcmp(*p_option_iter, "PLT=NO") == 0) { + p_j2k->m_specific_param.m_encoder.m_PLT = OPJ_FALSE; + } else { + opj_event_msg(p_manager, EVT_ERROR, + "Invalid value for option: %s.\n", *p_option_iter); + return OPJ_FALSE; + } + } else if (strncmp(*p_option_iter, "TLM=", 4) == 0) { + if (strcmp(*p_option_iter, "TLM=YES") == 0) { + p_j2k->m_specific_param.m_encoder.m_TLM = OPJ_TRUE; + } else if (strcmp(*p_option_iter, "TLM=NO") == 0) { + p_j2k->m_specific_param.m_encoder.m_TLM = OPJ_FALSE; + } else { + opj_event_msg(p_manager, EVT_ERROR, + "Invalid value for option: %s.\n", *p_option_iter); + return OPJ_FALSE; + } + } else if (strncmp(*p_option_iter, "GUARD_BITS=", strlen("GUARD_BITS=")) == 0) { + OPJ_UINT32 tileno; + opj_cp_t *cp = cp = &(p_j2k->m_cp); + + int numgbits = atoi(*p_option_iter + strlen("GUARD_BITS=")); + if (numgbits < 0 || numgbits > 7) { + opj_event_msg(p_manager, EVT_ERROR, + "Invalid value for option: %s. Should be in [0,7]\n", *p_option_iter); + return OPJ_FALSE; + } + + for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { + OPJ_UINT32 i; + opj_tcp_t *tcp = &cp->tcps[tileno]; + for (i = 0; i < p_j2k->m_specific_param.m_encoder.m_nb_comps; i++) { + opj_tccp_t *tccp = &tcp->tccps[i]; + tccp->numgbits = (OPJ_UINT32)numgbits; + } + } + } else { + opj_event_msg(p_manager, EVT_ERROR, + "Invalid option: %s.\n", *p_option_iter); + return OPJ_FALSE; + } + } + + return OPJ_TRUE; +} + +/* ----------------------------------------------------------------------- */ + OPJ_BOOL opj_j2k_encode(opj_j2k_t * p_j2k, opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager) @@ -11223,7 +12702,7 @@ OPJ_BOOL opj_j2k_encode(opj_j2k_t * p_j2k, } } } - l_current_tile_size = opj_tcd_get_encoded_tile_size(p_j2k->m_tcd); + l_current_tile_size = opj_tcd_get_encoder_input_buffer_size(p_j2k->m_tcd); if (!l_reuse_data) { if (l_current_tile_size > l_max_tile_size) { OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(l_current_data, @@ -11394,12 +12873,9 @@ static void opj_get_tile_dimensions(opj_image_t * l_image, *l_width = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0); *l_height = (OPJ_UINT32)(l_tilec->y1 - l_tilec->y0); - *l_offset_x = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)l_image->x0, - (OPJ_INT32)l_img_comp->dx); - *l_offset_y = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)l_image->y0, - (OPJ_INT32)l_img_comp->dy); - *l_image_width = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)l_image->x1 - - (OPJ_INT32)l_image->x0, (OPJ_INT32)l_img_comp->dx); + *l_offset_x = opj_uint_ceildiv(l_image->x0, l_img_comp->dx); + *l_offset_y = opj_uint_ceildiv(l_image->y0, l_img_comp->dy); + *l_image_width = opj_uint_ceildiv(l_image->x1 - l_image->x0, l_img_comp->dx); *l_stride = *l_image_width - *l_width; *l_tile_offset = ((OPJ_UINT32)l_tilec->x0 - *l_offset_x) + (( OPJ_UINT32)l_tilec->y0 - *l_offset_y) * *l_image_width; @@ -11551,7 +13027,7 @@ static OPJ_BOOL opj_j2k_setup_end_compress(opj_j2k_t *p_j2k, return OPJ_FALSE; } - if (OPJ_IS_CINEMA(p_j2k->m_cp.rsiz)) { + if (p_j2k->m_specific_param.m_encoder.m_TLM) { if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list, (opj_procedure)opj_j2k_write_updated_tlm, p_manager)) { return OPJ_FALSE; @@ -11634,7 +13110,7 @@ static OPJ_BOOL opj_j2k_setup_header_writing(opj_j2k_t *p_j2k, return OPJ_FALSE; } - if (OPJ_IS_CINEMA(p_j2k->m_cp.rsiz)) { + if (p_j2k->m_specific_param.m_encoder.m_TLM) { if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list, (opj_procedure)opj_j2k_write_tlm, p_manager)) { return OPJ_FALSE; @@ -11661,7 +13137,8 @@ static OPJ_BOOL opj_j2k_setup_header_writing(opj_j2k_t *p_j2k, } /* DEVELOPER CORNER, insert your custom procedures */ - if (p_j2k->m_cp.rsiz & OPJ_EXTENSION_MCT) { + if ((p_j2k->m_cp.rsiz & (OPJ_PROFILE_PART2 | OPJ_EXTENSION_MCT)) == + (OPJ_PROFILE_PART2 | OPJ_EXTENSION_MCT)) { if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list, (opj_procedure)opj_j2k_write_mct_data_group, p_manager)) { return OPJ_FALSE; @@ -11691,7 +13168,7 @@ static OPJ_BOOL opj_j2k_setup_header_writing(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_first_tile_part(opj_j2k_t *p_j2k, OPJ_BYTE * p_data, OPJ_UINT32 * p_data_written, - OPJ_UINT32 p_total_data_size, + OPJ_UINT32 total_data_size, opj_stream_private_t *p_stream, struct opj_event_mgr * p_manager) { @@ -11715,7 +13192,7 @@ static OPJ_BOOL opj_j2k_write_first_tile_part(opj_j2k_t *p_j2k, l_current_nb_bytes_written = 0; l_begin_data = p_data; - if (! opj_j2k_write_sot(p_j2k, p_data, p_total_data_size, + if (! opj_j2k_write_sot(p_j2k, p_data, total_data_size, &l_current_nb_bytes_written, p_stream, p_manager)) { return OPJ_FALSE; @@ -11723,7 +13200,7 @@ static OPJ_BOOL opj_j2k_write_first_tile_part(opj_j2k_t *p_j2k, l_nb_bytes_written += l_current_nb_bytes_written; p_data += l_current_nb_bytes_written; - p_total_data_size -= l_current_nb_bytes_written; + total_data_size -= l_current_nb_bytes_written; if (!OPJ_IS_CINEMA(l_cp->rsiz)) { #if 0 @@ -11733,29 +13210,29 @@ static OPJ_BOOL opj_j2k_write_first_tile_part(opj_j2k_t *p_j2k, p_manager); l_nb_bytes_written += l_current_nb_bytes_written; p_data += l_current_nb_bytes_written; - p_total_data_size -= l_current_nb_bytes_written; + total_data_size -= l_current_nb_bytes_written; l_current_nb_bytes_written = 0; opj_j2k_write_qcc_in_memory(p_j2k, compno, p_data, &l_current_nb_bytes_written, p_manager); l_nb_bytes_written += l_current_nb_bytes_written; p_data += l_current_nb_bytes_written; - p_total_data_size -= l_current_nb_bytes_written; + total_data_size -= l_current_nb_bytes_written; } #endif - if (l_cp->tcps[p_j2k->m_current_tile_number].numpocs) { + if (l_cp->tcps[p_j2k->m_current_tile_number].POC) { l_current_nb_bytes_written = 0; opj_j2k_write_poc_in_memory(p_j2k, p_data, &l_current_nb_bytes_written, p_manager); l_nb_bytes_written += l_current_nb_bytes_written; p_data += l_current_nb_bytes_written; - p_total_data_size -= l_current_nb_bytes_written; + total_data_size -= l_current_nb_bytes_written; } } l_current_nb_bytes_written = 0; if (! opj_j2k_write_sod(p_j2k, l_tcd, p_data, &l_current_nb_bytes_written, - p_total_data_size, p_stream, p_manager)) { + total_data_size, p_stream, p_manager)) { return OPJ_FALSE; } @@ -11766,7 +13243,7 @@ static OPJ_BOOL opj_j2k_write_first_tile_part(opj_j2k_t *p_j2k, opj_write_bytes(l_begin_data + 6, l_nb_bytes_written, 4); /* PSOT */ - if (OPJ_IS_CINEMA(l_cp->rsiz)) { + if (p_j2k->m_specific_param.m_encoder.m_TLM) { opj_j2k_update_tlm(p_j2k, l_nb_bytes_written); } @@ -11776,7 +13253,7 @@ static OPJ_BOOL opj_j2k_write_first_tile_part(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_all_tile_parts(opj_j2k_t *p_j2k, OPJ_BYTE * p_data, OPJ_UINT32 * p_data_written, - OPJ_UINT32 p_total_data_size, + OPJ_UINT32 total_data_size, opj_stream_private_t *p_stream, struct opj_event_mgr * p_manager ) @@ -11809,7 +13286,7 @@ static OPJ_BOOL opj_j2k_write_all_tile_parts(opj_j2k_t *p_j2k, l_begin_data = p_data; if (! opj_j2k_write_sot(p_j2k, p_data, - p_total_data_size, + total_data_size, &l_current_nb_bytes_written, p_stream, p_manager)) { @@ -11818,25 +13295,25 @@ static OPJ_BOOL opj_j2k_write_all_tile_parts(opj_j2k_t *p_j2k, l_nb_bytes_written += l_current_nb_bytes_written; p_data += l_current_nb_bytes_written; - p_total_data_size -= l_current_nb_bytes_written; + total_data_size -= l_current_nb_bytes_written; l_part_tile_size += l_current_nb_bytes_written; l_current_nb_bytes_written = 0; if (! opj_j2k_write_sod(p_j2k, l_tcd, p_data, &l_current_nb_bytes_written, - p_total_data_size, p_stream, p_manager)) { + total_data_size, p_stream, p_manager)) { return OPJ_FALSE; } p_data += l_current_nb_bytes_written; l_nb_bytes_written += l_current_nb_bytes_written; - p_total_data_size -= l_current_nb_bytes_written; + total_data_size -= l_current_nb_bytes_written; l_part_tile_size += l_current_nb_bytes_written; /* Writing Psot in SOT marker */ opj_write_bytes(l_begin_data + 6, l_part_tile_size, 4); /* PSOT */ - if (OPJ_IS_CINEMA(l_cp->rsiz)) { + if (p_j2k->m_specific_param.m_encoder.m_TLM) { opj_j2k_update_tlm(p_j2k, l_part_tile_size); } @@ -11855,7 +13332,7 @@ static OPJ_BOOL opj_j2k_write_all_tile_parts(opj_j2k_t *p_j2k, l_begin_data = p_data; if (! opj_j2k_write_sot(p_j2k, p_data, - p_total_data_size, + total_data_size, &l_current_nb_bytes_written, p_stream, p_manager)) { return OPJ_FALSE; @@ -11863,26 +13340,26 @@ static OPJ_BOOL opj_j2k_write_all_tile_parts(opj_j2k_t *p_j2k, l_nb_bytes_written += l_current_nb_bytes_written; p_data += l_current_nb_bytes_written; - p_total_data_size -= l_current_nb_bytes_written; + total_data_size -= l_current_nb_bytes_written; l_part_tile_size += l_current_nb_bytes_written; l_current_nb_bytes_written = 0; if (! opj_j2k_write_sod(p_j2k, l_tcd, p_data, &l_current_nb_bytes_written, - p_total_data_size, p_stream, p_manager)) { + total_data_size, p_stream, p_manager)) { return OPJ_FALSE; } l_nb_bytes_written += l_current_nb_bytes_written; p_data += l_current_nb_bytes_written; - p_total_data_size -= l_current_nb_bytes_written; + total_data_size -= l_current_nb_bytes_written; l_part_tile_size += l_current_nb_bytes_written; /* Writing Psot in SOT marker */ opj_write_bytes(l_begin_data + 6, l_part_tile_size, 4); /* PSOT */ - if (OPJ_IS_CINEMA(l_cp->rsiz)) { + if (p_j2k->m_specific_param.m_encoder.m_TLM) { opj_j2k_update_tlm(p_j2k, l_part_tile_size); } @@ -11901,13 +13378,16 @@ static OPJ_BOOL opj_j2k_write_updated_tlm(opj_j2k_t *p_j2k, { OPJ_UINT32 l_tlm_size; OPJ_OFF_T l_tlm_position, l_current_position; + OPJ_UINT32 size_per_tile_part; /* preconditions */ assert(p_j2k != 00); assert(p_manager != 00); assert(p_stream != 00); - l_tlm_size = 5 * p_j2k->m_specific_param.m_encoder.m_total_tile_parts; + size_per_tile_part = p_j2k->m_specific_param.m_encoder.m_Ttlmi_is_byte ? 5 : 6; + l_tlm_size = size_per_tile_part * + p_j2k->m_specific_param.m_encoder.m_total_tile_parts; l_tlm_position = 6 + p_j2k->m_specific_param.m_encoder.m_tlm_start; l_current_position = opj_stream_tell(p_stream); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/j2k.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/j2k.h index 5d393c98130..bcf70a419c6 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/j2k.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/j2k.h @@ -61,6 +61,8 @@ The functions in J2K.C have for goal to read/write the several parts of the code #define J2K_CCP_CBLKSTY_VSC 0x08 /**< Vertically stripe causal context */ #define J2K_CCP_CBLKSTY_PTERM 0x10 /**< Predictable termination */ #define J2K_CCP_CBLKSTY_SEGSYM 0x20 /**< Segmentation symbols are used */ +#define J2K_CCP_CBLKSTY_HT 0x40 /**< (high throughput) HT codeblocks */ +#define J2K_CCP_CBLKSTY_HTMIXED 0x80 /**< MIXED mode HT codeblocks */ #define J2K_CCP_QNTSTY_NOQNT 0 #define J2K_CCP_QNTSTY_SIQNT 1 #define J2K_CCP_QNTSTY_SEQNT 2 @@ -71,9 +73,11 @@ The functions in J2K.C have for goal to read/write the several parts of the code #define J2K_MS_SOT 0xff90 /**< SOT marker value */ #define J2K_MS_SOD 0xff93 /**< SOD marker value */ #define J2K_MS_EOC 0xffd9 /**< EOC marker value */ +#define J2K_MS_CAP 0xff50 /**< CAP marker value */ #define J2K_MS_SIZ 0xff51 /**< SIZ marker value */ #define J2K_MS_COD 0xff52 /**< COD marker value */ #define J2K_MS_COC 0xff53 /**< COC marker value */ +#define J2K_MS_CPF 0xff59 /**< CPF marker value */ #define J2K_MS_RGN 0xff5e /**< RGN marker value */ #define J2K_MS_QCD 0xff5c /**< QCD marker value */ #define J2K_MS_QCC 0xff5d /**< QCC marker value */ @@ -109,6 +113,9 @@ The functions in J2K.C have for goal to read/write the several parts of the code #define J2K_MAX_POCS 32 /**< Maximum number of POCs */ +#define J2K_TCD_MATRIX_MAX_LAYER_COUNT 10 +#define J2K_TCD_MATRIX_MAX_RESOLUTION_COUNT 10 + /* ----------------------------------------------------------------------- */ /** @@ -268,7 +275,7 @@ typedef struct opj_tcp { OPJ_UINT32 ppt_data_size; /** size of ppt_data*/ OPJ_UINT32 ppt_len; - /** add fixed_quality */ + /** PSNR values */ OPJ_FLOAT32 distoratio[100]; /** tile-component coding parameters */ opj_tccp_t *tccps; @@ -310,6 +317,14 @@ typedef struct opj_tcp { } opj_tcp_t; +/** +Rate allocation strategy +*/ +typedef enum { + RATE_DISTORTION_RATIO = 0, /** allocation by rate/distortion */ + FIXED_DISTORTION_RATIO = 1, /** allocation by fixed distortion ratio (PSNR) (fixed quality) */ + FIXED_LAYER = 2, /** allocation by fixed layer (number of passes per layer / resolution / subband) */ +} J2K_QUALITY_LAYER_ALLOCATION_STRATEGY; typedef struct opj_encoding_param { @@ -321,12 +336,8 @@ typedef struct opj_encoding_param { OPJ_INT32 *m_matrice; /** Flag determining tile part generation*/ OPJ_BYTE m_tp_flag; - /** allocation by rate/distortion */ - OPJ_BITFIELD m_disto_alloc : 1; - /** allocation by fixed layer */ - OPJ_BITFIELD m_fixed_alloc : 1; - /** add fixed_quality */ - OPJ_BITFIELD m_fixed_quality : 1; + /** Quality layer allocation strategy */ + J2K_QUALITY_LAYER_ALLOCATION_STRATEGY m_quality_layer_alloc_strategy; /** Enabling Tile part generation*/ OPJ_BITFIELD m_tp_on : 1; } @@ -398,6 +409,8 @@ typedef struct opj_cp { } m_specific_param; + /** OPJ_TRUE if entire bit stream must be decoded, OPJ_FALSE if partial bitstream decoding allowed */ + OPJ_BOOL strict; /* UniPG>> */ #ifdef USE_JPWL @@ -453,6 +466,24 @@ typedef struct opj_cp { /* <cp. */ void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters); +void opj_j2k_decoder_set_strict_mode(opj_j2k_t *j2k, OPJ_BOOL strict); + OPJ_BOOL opj_j2k_set_threads(opj_j2k_t *j2k, OPJ_UINT32 num_threads); /** @@ -827,6 +888,19 @@ OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k, OPJ_UINT32 res_factor, opj_event_mgr_t * p_manager); +/** + * Specify extra options for the encoder. + * + * @param p_j2k the jpeg2000 codec. + * @param p_options options + * @param p_manager the user event manager + * + * @see opj_encoder_set_extra_options() for more details. + */ +OPJ_BOOL opj_j2k_encoder_set_extra_options( + opj_j2k_t *p_j2k, + const char* const* p_options, + opj_event_mgr_t * p_manager); /** * Writes a tile. diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/jp2.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/jp2.c index c79ea7316af..4df055a542a 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/jp2.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/jp2.c @@ -331,14 +331,14 @@ static OPJ_BOOL opj_jp2_read_colr(opj_jp2_t *jp2, /** * Sets up the procedures to do on writing header after the codestream. - * Developpers wanting to extend the library can add their own writing procedures. + * Developers wanting to extend the library can add their own writing procedures. */ static OPJ_BOOL opj_jp2_setup_end_header_writing(opj_jp2_t *jp2, opj_event_mgr_t * p_manager); /** * Sets up the procedures to do on reading header after the codestream. - * Developpers wanting to extend the library can add their own writing procedures. + * Developers wanting to extend the library can add their own writing procedures. */ static OPJ_BOOL opj_jp2_setup_end_header_reading(opj_jp2_t *jp2, opj_event_mgr_t * p_manager); @@ -388,13 +388,13 @@ static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box, /** * Sets up the validation ,i.e. adds the procedures to launch to make sure the codec parameters - * are valid. Developpers wanting to extend the library can add their own validation procedures. + * are valid. Developers wanting to extend the library can add their own validation procedures. */ static OPJ_BOOL opj_jp2_setup_encoding_validation(opj_jp2_t *jp2, opj_event_mgr_t * p_manager); /** - * Sets up the procedures to do on writing header. Developpers wanting to extend the library can add their own writing procedures. + * Sets up the procedures to do on writing header. Developers wanting to extend the library can add their own writing procedures. */ static OPJ_BOOL opj_jp2_setup_header_writing(opj_jp2_t *jp2, opj_event_mgr_t * p_manager); @@ -457,14 +457,14 @@ static OPJ_BOOL opj_jp2_read_boxhdr_char(opj_jp2_box_t *box, /** * Sets up the validation ,i.e. adds the procedures to launch to make sure the codec parameters - * are valid. Developpers wanting to extend the library can add their own validation procedures. + * are valid. Developers wanting to extend the library can add their own validation procedures. */ static OPJ_BOOL opj_jp2_setup_decoding_validation(opj_jp2_t *jp2, opj_event_mgr_t * p_manager); /** * Sets up the procedures to do on reading header. - * Developpers wanting to extend the library can add their own writing procedures. + * Developers wanting to extend the library can add their own writing procedures. */ static OPJ_BOOL opj_jp2_setup_header_reading(opj_jp2_t *jp2, opj_event_mgr_t * p_manager); @@ -586,6 +586,12 @@ static OPJ_BOOL opj_jp2_read_ihdr(opj_jp2_t *jp2, opj_read_bytes(p_image_header_data, &(jp2->numcomps), 2); /* NC */ p_image_header_data += 2; + if (jp2->h < 1 || jp2->w < 1 || jp2->numcomps < 1) { + opj_event_msg(p_manager, EVT_ERROR, + "Wrong values for: w(%d) h(%d) numcomps(%d) (ihdr)\n", + jp2->w, jp2->h, jp2->numcomps); + return OPJ_FALSE; + } if ((jp2->numcomps - 1U) >= 16384U) { /* unsigned underflow is well defined: 1U <= jp2->numcomps <= 16384U */ opj_event_msg(p_manager, EVT_ERROR, "Invalid number of components (ihdr)\n"); @@ -1005,7 +1011,7 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, if (!pcol_usage[i]) { is_sane = 0U; opj_event_msg(p_manager, EVT_WARNING, - "Component mapping seems wrong. Trying to correct.\n", i); + "Component mapping seems wrong. Trying to correct.\n"); break; } } @@ -1079,7 +1085,7 @@ static OPJ_BOOL opj_jp2_apply_pclr(opj_image_t *image, /* Palette mapping: */ new_comps[i].data = (OPJ_INT32*) - opj_image_data_alloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(OPJ_INT32)); + opj_image_data_alloc(sizeof(OPJ_INT32) * old_comps[cmp].w * old_comps[cmp].h); if (!new_comps[i].data) { while (i > 0) { -- i; @@ -1102,11 +1108,10 @@ static OPJ_BOOL opj_jp2_apply_pclr(opj_image_t *image, pcol = cmap[i].pcol; src = old_comps[cmp].data; assert(src); /* verified above */ - max = new_comps[pcol].w * new_comps[pcol].h; + max = new_comps[i].w * new_comps[i].h; /* Direct use: */ if (cmap[i].mtyp == 0) { - assert(cmp == 0); dst = new_comps[i].data; assert(dst); for (j = 0; j < max; ++j) { @@ -1131,9 +1136,9 @@ static OPJ_BOOL opj_jp2_apply_pclr(opj_image_t *image, } max = image->numcomps; - for (i = 0; i < max; ++i) { - if (old_comps[i].data) { - opj_image_data_free(old_comps[i].data); + for (j = 0; j < max; ++j) { + if (old_comps[j].data) { + opj_image_data_free(old_comps[j].data); } } @@ -1194,8 +1199,8 @@ static OPJ_BOOL opj_jp2_read_pclr(opj_jp2_t *jp2, return OPJ_FALSE; } - entries = (OPJ_UINT32*) opj_malloc((size_t)nr_channels * nr_entries * sizeof( - OPJ_UINT32)); + entries = (OPJ_UINT32*) opj_malloc(sizeof(OPJ_UINT32) * nr_channels * + nr_entries); if (!entries) { return OPJ_FALSE; } @@ -1585,28 +1590,14 @@ static OPJ_BOOL opj_jp2_read_colr(opj_jp2_t *jp2, "COLR BOX meth value is not a regular value (%d), " "so we will ignore the entire Colour Specification box. \n", jp2->meth); } - if (jp2->color.jp2_has_colr) { - jp2->j2k->enumcs = jp2->enumcs; - } + return OPJ_TRUE; } -OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, - opj_stream_private_t *p_stream, - opj_image_t* p_image, - opj_event_mgr_t * p_manager) +static OPJ_BOOL opj_jp2_apply_color_postprocessing(opj_jp2_t *jp2, + opj_image_t* p_image, + opj_event_mgr_t * p_manager) { - if (!p_image) { - return OPJ_FALSE; - } - - /* J2K decoding */ - if (! opj_j2k_decode(jp2->j2k, p_stream, p_image, p_manager)) { - opj_event_msg(p_manager, EVT_ERROR, - "Failed to decode the codestream in the JP2 file\n"); - return OPJ_FALSE; - } - if (jp2->j2k->m_specific_param.m_decoder.m_numcomps_to_decode) { /* Bypass all JP2 component transforms */ return OPJ_TRUE; @@ -1617,21 +1608,6 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, return OPJ_FALSE; } - /* Set Image Color Space */ - if (jp2->enumcs == 16) { - p_image->color_space = OPJ_CLRSPC_SRGB; - } else if (jp2->enumcs == 17) { - p_image->color_space = OPJ_CLRSPC_GRAY; - } else if (jp2->enumcs == 18) { - p_image->color_space = OPJ_CLRSPC_SYCC; - } else if (jp2->enumcs == 24) { - p_image->color_space = OPJ_CLRSPC_EYCC; - } else if (jp2->enumcs == 12) { - p_image->color_space = OPJ_CLRSPC_CMYK; - } else { - p_image->color_space = OPJ_CLRSPC_UNKNOWN; - } - if (jp2->color.jp2_pclr) { /* Part 1, I.5.3.4: Either both or none : */ if (!jp2->color.jp2_pclr->cmap) { @@ -1647,17 +1623,30 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, if (jp2->color.jp2_cdef) { opj_jp2_apply_cdef(p_image, &(jp2->color), p_manager); } - - if (jp2->color.icc_profile_buf) { - p_image->icc_profile_buf = jp2->color.icc_profile_buf; - p_image->icc_profile_len = jp2->color.icc_profile_len; - jp2->color.icc_profile_buf = NULL; - } } return OPJ_TRUE; } +OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, + opj_stream_private_t *p_stream, + opj_image_t* p_image, + opj_event_mgr_t * p_manager) +{ + if (!p_image) { + return OPJ_FALSE; + } + + /* J2K decoding */ + if (! opj_j2k_decode(jp2->j2k, p_stream, p_image, p_manager)) { + opj_event_msg(p_manager, EVT_ERROR, + "Failed to decode the codestream in the JP2 file\n"); + return OPJ_FALSE; + } + + return opj_jp2_apply_color_postprocessing(jp2, p_image, p_manager); +} + static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2, opj_stream_private_t *stream, opj_event_mgr_t * p_manager @@ -1898,6 +1887,11 @@ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG; } +void opj_jp2_decoder_set_strict_mode(opj_jp2_t *jp2, OPJ_BOOL strict) +{ + opj_j2k_decoder_set_strict_mode(jp2->j2k, strict); +} + OPJ_BOOL opj_jp2_set_threads(opj_jp2_t *jp2, OPJ_UINT32 num_threads) { return opj_j2k_set_threads(jp2->j2k, num_threads); @@ -1995,12 +1989,16 @@ OPJ_BOOL opj_jp2_setup_encoder(opj_jp2_t *jp2, jp2->enumcs = 0; } else { jp2->meth = 1; - if (image->color_space == 1) { + if (image->color_space == OPJ_CLRSPC_SRGB) { jp2->enumcs = 16; /* sRGB as defined by IEC 61966-2-1 */ - } else if (image->color_space == 2) { - jp2->enumcs = 17; /* greyscale */ - } else if (image->color_space == 3) { + } else if (image->color_space == OPJ_CLRSPC_GRAY) { + jp2->enumcs = 17; + } else if (image->color_space == OPJ_CLRSPC_SYCC) { jp2->enumcs = 18; /* YUV */ + } else if (image->color_space == OPJ_CLRSPC_EYCC) { + jp2->enumcs = 24; + } else if (image->color_space == OPJ_CLRSPC_CMYK) { + jp2->enumcs = 12; } } @@ -2835,6 +2833,8 @@ OPJ_BOOL opj_jp2_read_header(opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager ) { + int ret; + /* preconditions */ assert(jp2 != 00); assert(p_stream != 00); @@ -2868,10 +2868,34 @@ OPJ_BOOL opj_jp2_read_header(opj_stream_private_t *p_stream, return OPJ_FALSE; } - return opj_j2k_read_header(p_stream, - jp2->j2k, - p_image, - p_manager); + ret = opj_j2k_read_header(p_stream, + jp2->j2k, + p_image, + p_manager); + + if (p_image && *p_image) { + /* Set Image Color Space */ + if (jp2->enumcs == 16) { + (*p_image)->color_space = OPJ_CLRSPC_SRGB; + } else if (jp2->enumcs == 17) { + (*p_image)->color_space = OPJ_CLRSPC_GRAY; + } else if (jp2->enumcs == 18) { + (*p_image)->color_space = OPJ_CLRSPC_SYCC; + } else if (jp2->enumcs == 24) { + (*p_image)->color_space = OPJ_CLRSPC_EYCC; + } else if (jp2->enumcs == 12) { + (*p_image)->color_space = OPJ_CLRSPC_CMYK; + } else { + (*p_image)->color_space = OPJ_CLRSPC_UNKNOWN; + } + + if (jp2->color.icc_profile_buf) { + (*p_image)->icc_profile_buf = jp2->color.icc_profile_buf; + (*p_image)->icc_profile_len = jp2->color.icc_profile_len; + jp2->color.icc_profile_buf = NULL; + } + } + return ret; } static OPJ_BOOL opj_jp2_setup_encoding_validation(opj_jp2_t *jp2, @@ -3115,53 +3139,7 @@ OPJ_BOOL opj_jp2_get_tile(opj_jp2_t *p_jp2, return OPJ_FALSE; } - if (p_jp2->j2k->m_specific_param.m_decoder.m_numcomps_to_decode) { - /* Bypass all JP2 component transforms */ - return OPJ_TRUE; - } - - if (!opj_jp2_check_color(p_image, &(p_jp2->color), p_manager)) { - return OPJ_FALSE; - } - - /* Set Image Color Space */ - if (p_jp2->enumcs == 16) { - p_image->color_space = OPJ_CLRSPC_SRGB; - } else if (p_jp2->enumcs == 17) { - p_image->color_space = OPJ_CLRSPC_GRAY; - } else if (p_jp2->enumcs == 18) { - p_image->color_space = OPJ_CLRSPC_SYCC; - } else if (p_jp2->enumcs == 24) { - p_image->color_space = OPJ_CLRSPC_EYCC; - } else if (p_jp2->enumcs == 12) { - p_image->color_space = OPJ_CLRSPC_CMYK; - } else { - p_image->color_space = OPJ_CLRSPC_UNKNOWN; - } - - if (p_jp2->color.jp2_pclr) { - /* Part 1, I.5.3.4: Either both or none : */ - if (!p_jp2->color.jp2_pclr->cmap) { - opj_jp2_free_pclr(&(p_jp2->color)); - } else { - if (!opj_jp2_apply_pclr(p_image, &(p_jp2->color), p_manager)) { - return OPJ_FALSE; - } - } - } - - /* Apply the color space if needed */ - if (p_jp2->color.jp2_cdef) { - opj_jp2_apply_cdef(p_image, &(p_jp2->color), p_manager); - } - - if (p_jp2->color.icc_profile_buf) { - p_image->icc_profile_buf = p_jp2->color.icc_profile_buf; - p_image->icc_profile_len = p_jp2->color.icc_profile_len; - p_jp2->color.icc_profile_buf = NULL; - } - - return OPJ_TRUE; + return opj_jp2_apply_color_postprocessing(p_jp2, p_image, p_manager); } /* ----------------------------------------------------------------------- */ @@ -3237,6 +3215,18 @@ OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2, return opj_j2k_set_decoded_resolution_factor(p_jp2->j2k, res_factor, p_manager); } +/* ----------------------------------------------------------------------- */ + +OPJ_BOOL opj_jp2_encoder_set_extra_options( + opj_jp2_t *p_jp2, + const char* const* p_options, + opj_event_mgr_t * p_manager) +{ + return opj_j2k_encoder_set_extra_options(p_jp2->j2k, p_options, p_manager); +} + +/* ----------------------------------------------------------------------- */ + /* JPIP specific */ #ifdef USE_JPIP diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/jp2.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/jp2.h index 34abd5118e3..173f25119ba 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/jp2.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/jp2.h @@ -235,6 +235,15 @@ Decoding parameters are returned in jp2->j2k->cp. */ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters); +/** +Set the strict mode parameter. When strict mode is enabled, the entire +bitstream must be decoded or an error is returned. When it is disabled, +the decoder will decode partial bitstreams. +@param jp2 JP2 decompressor handle +@param strict OPJ_TRUE for strict mode +*/ +void opj_jp2_decoder_set_strict_mode(opj_jp2_t *jp2, OPJ_BOOL strict); + /** Allocates worker threads for the compressor/decompressor. * * @param jp2 JP2 decompressor handle @@ -459,6 +468,20 @@ OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2, OPJ_UINT32 res_factor, opj_event_mgr_t * p_manager); +/** + * Specify extra options for the encoder. + * + * @param p_jp2 the jpeg2000 codec. + * @param p_options options + * @param p_manager the user event manager + * + * @see opj_encoder_set_extra_options() for more details. + */ +OPJ_BOOL opj_jp2_encoder_set_extra_options( + opj_jp2_t *p_jp2, + const char* const* p_options, + opj_event_mgr_t * p_manager); + /* TODO MSD: clean these 3 functions */ /** diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/libopenjp2.pc.cmake.in b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/libopenjp2.pc.cmake.in index 62159b00a4b..2ade312b294 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/libopenjp2.pc.cmake.in +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/libopenjp2.pc.cmake.in @@ -1,9 +1,9 @@ prefix=@CMAKE_INSTALL_PREFIX@ -bindir=${prefix}/@OPENJPEG_INSTALL_BIN_DIR@ -mandir=${prefix}/@OPENJPEG_INSTALL_MAN_DIR@ -docdir=${prefix}/@OPENJPEG_INSTALL_DOC_DIR@ -libdir=${prefix}/@OPENJPEG_INSTALL_LIB_DIR@ -includedir=${prefix}/@OPENJPEG_INSTALL_INCLUDE_DIR@ +bindir=@bindir@ +mandir=@mandir@ +docdir=@docdir@ +libdir=@libdir@ +includedir=@includedir@ Name: openjp2 Description: JPEG2000 library (Part 1 and 2) @@ -12,3 +12,4 @@ Version: @OPENJPEG_VERSION@ Libs: -L${libdir} -lopenjp2 Libs.private: -lm Cflags: -I${includedir} +Cflags.private: -DOPJ_STATIC diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mct.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mct.c index b79d4b87c49..9db839820b1 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mct.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mct.c @@ -59,12 +59,12 @@ static const OPJ_FLOAT64 opj_mct_norms[3] = { 1.732, .8292, .8292 }; /* */ static const OPJ_FLOAT64 opj_mct_norms_real[3] = { 1.732, 1.805, 1.573 }; -const OPJ_FLOAT64 * opj_mct_get_mct_norms() +const OPJ_FLOAT64 * opj_mct_get_mct_norms(void) { return opj_mct_norms; } -const OPJ_FLOAT64 * opj_mct_get_mct_norms_real() +const OPJ_FLOAT64 * opj_mct_get_mct_norms_real(void) { return opj_mct_norms_real; } @@ -183,7 +183,7 @@ void opj_mct_decode( OPJ_INT32* OPJ_RESTRICT c2, OPJ_SIZE_T n) { - OPJ_UINT32 i; + OPJ_SIZE_T i; for (i = 0; i < n; ++i) { OPJ_INT32 y = c0[i]; OPJ_INT32 u = c1[i]; @@ -209,175 +209,72 @@ OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) /* */ /* Forward irreversible MCT. */ /* */ -#ifdef __SSE4_1__ void opj_mct_encode_real( - OPJ_INT32* OPJ_RESTRICT c0, - OPJ_INT32* OPJ_RESTRICT c1, - OPJ_INT32* OPJ_RESTRICT c2, + OPJ_FLOAT32* OPJ_RESTRICT c0, + OPJ_FLOAT32* OPJ_RESTRICT c1, + OPJ_FLOAT32* OPJ_RESTRICT c2, OPJ_SIZE_T n) { OPJ_SIZE_T i; - const OPJ_SIZE_T len = n; - - const __m128i ry = _mm_set1_epi32(2449); - const __m128i gy = _mm_set1_epi32(4809); - const __m128i by = _mm_set1_epi32(934); - const __m128i ru = _mm_set1_epi32(1382); - const __m128i gu = _mm_set1_epi32(2714); - /* const __m128i bu = _mm_set1_epi32(4096); */ - /* const __m128i rv = _mm_set1_epi32(4096); */ - const __m128i gv = _mm_set1_epi32(3430); - const __m128i bv = _mm_set1_epi32(666); - const __m128i mulround = _mm_shuffle_epi32(_mm_cvtsi32_si128(4096), - _MM_SHUFFLE(1, 0, 1, 0)); - - for (i = 0; i < (len & ~3U); i += 4) { - __m128i lo, hi; - __m128i y, u, v; - __m128i r = _mm_load_si128((const __m128i *) & (c0[i])); - __m128i g = _mm_load_si128((const __m128i *) & (c1[i])); - __m128i b = _mm_load_si128((const __m128i *) & (c2[i])); - - lo = r; - hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1)); - lo = _mm_mul_epi32(lo, ry); - hi = _mm_mul_epi32(hi, ry); - lo = _mm_add_epi64(lo, mulround); - hi = _mm_add_epi64(hi, mulround); - lo = _mm_srli_epi64(lo, 13); - hi = _mm_slli_epi64(hi, 32 - 13); - y = _mm_blend_epi16(lo, hi, 0xCC); - - lo = g; - hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1)); - lo = _mm_mul_epi32(lo, gy); - hi = _mm_mul_epi32(hi, gy); - lo = _mm_add_epi64(lo, mulround); - hi = _mm_add_epi64(hi, mulround); - lo = _mm_srli_epi64(lo, 13); - hi = _mm_slli_epi64(hi, 32 - 13); - y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC)); - - lo = b; - hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1)); - lo = _mm_mul_epi32(lo, by); - hi = _mm_mul_epi32(hi, by); - lo = _mm_add_epi64(lo, mulround); - hi = _mm_add_epi64(hi, mulround); - lo = _mm_srli_epi64(lo, 13); - hi = _mm_slli_epi64(hi, 32 - 13); - y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC)); - _mm_store_si128((__m128i *) & (c0[i]), y); - - /*lo = b; - hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1)); - lo = _mm_mul_epi32(lo, mulround); - hi = _mm_mul_epi32(hi, mulround);*/ - lo = _mm_cvtepi32_epi64(_mm_shuffle_epi32(b, _MM_SHUFFLE(3, 2, 2, 0))); - hi = _mm_cvtepi32_epi64(_mm_shuffle_epi32(b, _MM_SHUFFLE(3, 2, 3, 1))); - lo = _mm_slli_epi64(lo, 12); - hi = _mm_slli_epi64(hi, 12); - lo = _mm_add_epi64(lo, mulround); - hi = _mm_add_epi64(hi, mulround); - lo = _mm_srli_epi64(lo, 13); - hi = _mm_slli_epi64(hi, 32 - 13); - u = _mm_blend_epi16(lo, hi, 0xCC); - - lo = r; - hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1)); - lo = _mm_mul_epi32(lo, ru); - hi = _mm_mul_epi32(hi, ru); - lo = _mm_add_epi64(lo, mulround); - hi = _mm_add_epi64(hi, mulround); - lo = _mm_srli_epi64(lo, 13); - hi = _mm_slli_epi64(hi, 32 - 13); - u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC)); - - lo = g; - hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1)); - lo = _mm_mul_epi32(lo, gu); - hi = _mm_mul_epi32(hi, gu); - lo = _mm_add_epi64(lo, mulround); - hi = _mm_add_epi64(hi, mulround); - lo = _mm_srli_epi64(lo, 13); - hi = _mm_slli_epi64(hi, 32 - 13); - u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC)); - _mm_store_si128((__m128i *) & (c1[i]), u); +#ifdef __SSE__ + const __m128 YR = _mm_set1_ps(0.299f); + const __m128 YG = _mm_set1_ps(0.587f); + const __m128 YB = _mm_set1_ps(0.114f); + const __m128 UR = _mm_set1_ps(-0.16875f); + const __m128 UG = _mm_set1_ps(-0.331260f); + const __m128 UB = _mm_set1_ps(0.5f); + const __m128 VR = _mm_set1_ps(0.5f); + const __m128 VG = _mm_set1_ps(-0.41869f); + const __m128 VB = _mm_set1_ps(-0.08131f); + for (i = 0; i < (n >> 3); i ++) { + __m128 r, g, b, y, u, v; + + r = _mm_load_ps(c0); + g = _mm_load_ps(c1); + b = _mm_load_ps(c2); + y = _mm_add_ps(_mm_add_ps(_mm_mul_ps(r, YR), _mm_mul_ps(g, YG)), + _mm_mul_ps(b, YB)); + u = _mm_add_ps(_mm_add_ps(_mm_mul_ps(r, UR), _mm_mul_ps(g, UG)), + _mm_mul_ps(b, UB)); + v = _mm_add_ps(_mm_add_ps(_mm_mul_ps(r, VR), _mm_mul_ps(g, VG)), + _mm_mul_ps(b, VB)); + _mm_store_ps(c0, y); + _mm_store_ps(c1, u); + _mm_store_ps(c2, v); + c0 += 4; + c1 += 4; + c2 += 4; - /*lo = r; - hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1)); - lo = _mm_mul_epi32(lo, mulround); - hi = _mm_mul_epi32(hi, mulround);*/ - lo = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 2, 0))); - hi = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 3, 1))); - lo = _mm_slli_epi64(lo, 12); - hi = _mm_slli_epi64(hi, 12); - lo = _mm_add_epi64(lo, mulround); - hi = _mm_add_epi64(hi, mulround); - lo = _mm_srli_epi64(lo, 13); - hi = _mm_slli_epi64(hi, 32 - 13); - v = _mm_blend_epi16(lo, hi, 0xCC); - - lo = g; - hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1)); - lo = _mm_mul_epi32(lo, gv); - hi = _mm_mul_epi32(hi, gv); - lo = _mm_add_epi64(lo, mulround); - hi = _mm_add_epi64(hi, mulround); - lo = _mm_srli_epi64(lo, 13); - hi = _mm_slli_epi64(hi, 32 - 13); - v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC)); - - lo = b; - hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1)); - lo = _mm_mul_epi32(lo, bv); - hi = _mm_mul_epi32(hi, bv); - lo = _mm_add_epi64(lo, mulround); - hi = _mm_add_epi64(hi, mulround); - lo = _mm_srli_epi64(lo, 13); - hi = _mm_slli_epi64(hi, 32 - 13); - v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC)); - _mm_store_si128((__m128i *) & (c2[i]), v); - } - for (; i < len; ++i) { - OPJ_INT32 r = c0[i]; - OPJ_INT32 g = c1[i]; - OPJ_INT32 b = c2[i]; - OPJ_INT32 y = opj_int_fix_mul(r, 2449) + opj_int_fix_mul(g, - 4809) + opj_int_fix_mul(b, 934); - OPJ_INT32 u = -opj_int_fix_mul(r, 1382) - opj_int_fix_mul(g, - 2714) + opj_int_fix_mul(b, 4096); - OPJ_INT32 v = opj_int_fix_mul(r, 4096) - opj_int_fix_mul(g, - 3430) - opj_int_fix_mul(b, 666); - c0[i] = y; - c1[i] = u; - c2[i] = v; + r = _mm_load_ps(c0); + g = _mm_load_ps(c1); + b = _mm_load_ps(c2); + y = _mm_add_ps(_mm_add_ps(_mm_mul_ps(r, YR), _mm_mul_ps(g, YG)), + _mm_mul_ps(b, YB)); + u = _mm_add_ps(_mm_add_ps(_mm_mul_ps(r, UR), _mm_mul_ps(g, UG)), + _mm_mul_ps(b, UB)); + v = _mm_add_ps(_mm_add_ps(_mm_mul_ps(r, VR), _mm_mul_ps(g, VG)), + _mm_mul_ps(b, VB)); + _mm_store_ps(c0, y); + _mm_store_ps(c1, u); + _mm_store_ps(c2, v); + c0 += 4; + c1 += 4; + c2 += 4; } -} -#else -void opj_mct_encode_real( - OPJ_INT32* OPJ_RESTRICT c0, - OPJ_INT32* OPJ_RESTRICT c1, - OPJ_INT32* OPJ_RESTRICT c2, - OPJ_SIZE_T n) -{ - OPJ_UINT32 i; + n &= 7; +#endif for (i = 0; i < n; ++i) { - OPJ_INT32 r = c0[i]; - OPJ_INT32 g = c1[i]; - OPJ_INT32 b = c2[i]; - OPJ_INT32 y = opj_int_fix_mul(r, 2449) + opj_int_fix_mul(g, - 4809) + opj_int_fix_mul(b, 934); - OPJ_INT32 u = -opj_int_fix_mul(r, 1382) - opj_int_fix_mul(g, - 2714) + opj_int_fix_mul(b, 4096); - OPJ_INT32 v = opj_int_fix_mul(r, 4096) - opj_int_fix_mul(g, - 3430) - opj_int_fix_mul(b, 666); + OPJ_FLOAT32 r = c0[i]; + OPJ_FLOAT32 g = c1[i]; + OPJ_FLOAT32 b = c2[i]; + OPJ_FLOAT32 y = 0.299f * r + 0.587f * g + 0.114f * b; + OPJ_FLOAT32 u = -0.16875f * r - 0.331260f * g + 0.5f * b; + OPJ_FLOAT32 v = 0.5f * r - 0.41869f * g - 0.08131f * b; c0[i] = y; c1[i] = u; c2[i] = v; } } -#endif /* */ /* Inverse irreversible MCT. */ @@ -388,7 +285,7 @@ void opj_mct_decode_real( OPJ_FLOAT32* OPJ_RESTRICT c2, OPJ_SIZE_T n) { - OPJ_UINT32 i; + OPJ_SIZE_T i; #ifdef __SSE__ __m128 vrv, vgu, vgv, vbu; vrv = _mm_set1_ps(1.402f); @@ -560,7 +457,7 @@ void opj_calculate_norms(OPJ_FLOAT64 * pNorms, for (j = 0; j < pNbComps; ++j) { lCurrentValue = lMatrix[lIndex]; lIndex += pNbComps; - lNorms[i] += lCurrentValue * lCurrentValue; + lNorms[i] += (OPJ_FLOAT64) lCurrentValue * lCurrentValue; } lNorms[i] = sqrt(lNorms[i]); } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mct.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mct.h index 2e37ce7333f..3e1f5e4946c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mct.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mct.h @@ -85,8 +85,9 @@ Apply an irreversible multi-component transform to an image @param c2 Samples blue component @param n Number of samples for each component */ -void opj_mct_encode_real(OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* OPJ_RESTRICT c1, - OPJ_INT32* OPJ_RESTRICT c2, OPJ_SIZE_T n); +void opj_mct_encode_real(OPJ_FLOAT32* OPJ_RESTRICT c0, + OPJ_FLOAT32* OPJ_RESTRICT c1, + OPJ_FLOAT32* OPJ_RESTRICT c2, OPJ_SIZE_T n); /** Apply an irreversible multi-component inverse transform to an image @param c0 Samples for luminance component diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mqc.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mqc.c index 6299b171d87..ed118402382 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mqc.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mqc.c @@ -46,27 +46,6 @@ /** @name Local static functions */ /*@{*/ -/** -Output a byte, doing bit-stuffing if necessary. -After a 0xff byte, the next byte must be smaller than 0x90. -@param mqc MQC handle -*/ -static void opj_mqc_byteout(opj_mqc_t *mqc); -/** -Renormalize mqc->a and mqc->c while encoding, so that mqc->a stays between 0x8000 and 0x10000 -@param mqc MQC handle -*/ -static void opj_mqc_renorme(opj_mqc_t *mqc); -/** -Encode the most probable symbol -@param mqc MQC handle -*/ -static void opj_mqc_codemps(opj_mqc_t *mqc); -/** -Encode the most least symbol -@param mqc MQC handle -*/ -static void opj_mqc_codelps(opj_mqc_t *mqc); /** Fill mqc->c with 1's for flushing @param mqc MQC handle @@ -182,80 +161,6 @@ static const opj_mqc_state_t mqc_states[47 * 2] = { ========================================================== */ -static void opj_mqc_byteout(opj_mqc_t *mqc) -{ - /* bp is initialized to start - 1 in opj_mqc_init_enc() */ - /* but this is safe, see opj_tcd_code_block_enc_allocate_data() */ - assert(mqc->bp >= mqc->start - 1); - if (*mqc->bp == 0xff) { - mqc->bp++; - *mqc->bp = (OPJ_BYTE)(mqc->c >> 20); - mqc->c &= 0xfffff; - mqc->ct = 7; - } else { - if ((mqc->c & 0x8000000) == 0) { - mqc->bp++; - *mqc->bp = (OPJ_BYTE)(mqc->c >> 19); - mqc->c &= 0x7ffff; - mqc->ct = 8; - } else { - (*mqc->bp)++; - if (*mqc->bp == 0xff) { - mqc->c &= 0x7ffffff; - mqc->bp++; - *mqc->bp = (OPJ_BYTE)(mqc->c >> 20); - mqc->c &= 0xfffff; - mqc->ct = 7; - } else { - mqc->bp++; - *mqc->bp = (OPJ_BYTE)(mqc->c >> 19); - mqc->c &= 0x7ffff; - mqc->ct = 8; - } - } - } -} - -static void opj_mqc_renorme(opj_mqc_t *mqc) -{ - do { - mqc->a <<= 1; - mqc->c <<= 1; - mqc->ct--; - if (mqc->ct == 0) { - opj_mqc_byteout(mqc); - } - } while ((mqc->a & 0x8000) == 0); -} - -static void opj_mqc_codemps(opj_mqc_t *mqc) -{ - mqc->a -= (*mqc->curctx)->qeval; - if ((mqc->a & 0x8000) == 0) { - if (mqc->a < (*mqc->curctx)->qeval) { - mqc->a = (*mqc->curctx)->qeval; - } else { - mqc->c += (*mqc->curctx)->qeval; - } - *mqc->curctx = (*mqc->curctx)->nmps; - opj_mqc_renorme(mqc); - } else { - mqc->c += (*mqc->curctx)->qeval; - } -} - -static void opj_mqc_codelps(opj_mqc_t *mqc) -{ - mqc->a -= (*mqc->curctx)->qeval; - if (mqc->a < (*mqc->curctx)->qeval) { - mqc->c += (*mqc->curctx)->qeval; - } else { - mqc->a = (*mqc->curctx)->qeval; - } - *mqc->curctx = (*mqc->curctx)->nlps; - opj_mqc_renorme(mqc); -} - static void opj_mqc_setbits(opj_mqc_t *mqc) { OPJ_UINT32 tempc = mqc->c + mqc->a; @@ -303,14 +208,6 @@ void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) mqc->end_of_byte_stream_counter = 0; } -void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) -{ - if ((*mqc->curctx)->mps == d) { - opj_mqc_codemps(mqc); - } else { - opj_mqc_codelps(mqc); - } -} void opj_mqc_flush(opj_mqc_t *mqc) { @@ -329,8 +226,6 @@ void opj_mqc_flush(opj_mqc_t *mqc) } } -#define BYPASS_CT_INIT 0xDEADBEEF - void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) { /* This function is normally called after at least one opj_mqc_flush() */ @@ -475,6 +370,43 @@ void opj_mqc_erterm_enc(opj_mqc_t *mqc) } } +static INLINE void opj_mqc_renorme(opj_mqc_t *mqc) +{ + opj_mqc_renorme_macro(mqc, mqc->a, mqc->c, mqc->ct); +} + +/** +Encode the most probable symbol +@param mqc MQC handle +*/ +static INLINE void opj_mqc_codemps(opj_mqc_t *mqc) +{ + opj_mqc_codemps_macro(mqc, mqc->curctx, mqc->a, mqc->c, mqc->ct); +} + +/** +Encode the most least symbol +@param mqc MQC handle +*/ +static INLINE void opj_mqc_codelps(opj_mqc_t *mqc) +{ + opj_mqc_codelps_macro(mqc, mqc->curctx, mqc->a, mqc->c, mqc->ct); +} + +/** +Encode a symbol using the MQ-coder +@param mqc MQC handle +@param d The symbol to be encoded (0 or 1) +*/ +static INLINE void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) +{ + if ((*mqc->curctx)->mps == d) { + opj_mqc_codemps(mqc); + } else { + opj_mqc_codelps(mqc); + } +} + void opj_mqc_segmark_enc(opj_mqc_t *mqc) { OPJ_UINT32 i; @@ -557,4 +489,36 @@ void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)]; } - +void opj_mqc_byteout(opj_mqc_t *mqc) +{ + /* bp is initialized to start - 1 in opj_mqc_init_enc() */ + /* but this is safe, see opj_tcd_code_block_enc_allocate_data() */ + assert(mqc->bp >= mqc->start - 1); + if (*mqc->bp == 0xff) { + mqc->bp++; + *mqc->bp = (OPJ_BYTE)(mqc->c >> 20); + mqc->c &= 0xfffff; + mqc->ct = 7; + } else { + if ((mqc->c & 0x8000000) == 0) { + mqc->bp++; + *mqc->bp = (OPJ_BYTE)(mqc->c >> 19); + mqc->c &= 0x7ffff; + mqc->ct = 8; + } else { + (*mqc->bp)++; + if (*mqc->bp == 0xff) { + mqc->c &= 0x7ffffff; + mqc->bp++; + *mqc->bp = (OPJ_BYTE)(mqc->c >> 20); + mqc->c &= 0xfffff; + mqc->ct = 7; + } else { + mqc->bp++; + *mqc->bp = (OPJ_BYTE)(mqc->c >> 19); + mqc->c &= 0x7ffff; + mqc->ct = 8; + } + } + } +} diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mqc.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mqc.h index 69a2a79dc06..9850fed0316 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mqc.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mqc.h @@ -96,6 +96,8 @@ typedef struct opj_mqc { OPJ_BYTE backup[OPJ_COMMON_CBLK_DATA_EXTRA]; } opj_mqc_t; +#define BYPASS_CT_INIT 0xDEADBEEF + #include "mqc_inl.h" /** @name Exported functions */ @@ -135,12 +137,7 @@ Set the current context used for coding/decoding @param ctxno Number that identifies the context */ #define opj_mqc_setcurctx(mqc, ctxno) (mqc)->curctx = &(mqc)->ctxs[(OPJ_UINT32)(ctxno)] -/** -Encode a symbol using the MQ-coder -@param mqc MQC handle -@param d The symbol to be encoded (0 or 1) -*/ -void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d); + /** Flush the encoder, so that all remaining data is written @param mqc MQC handle diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mqc_inl.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mqc_inl.h index 310a3287fd9..0031b94be31 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mqc_inl.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/mqc_inl.h @@ -156,13 +156,13 @@ static INLINE OPJ_UINT32 opj_mqc_raw_decode(opj_mqc_t *mqc) } \ } -#define DOWNLOAD_MQC_VARIABLES(mqc, curctx, c, a, ct) \ +#define DOWNLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct) \ register const opj_mqc_state_t **curctx = mqc->curctx; \ register OPJ_UINT32 c = mqc->c; \ register OPJ_UINT32 a = mqc->a; \ register OPJ_UINT32 ct = mqc->ct -#define UPLOAD_MQC_VARIABLES(mqc, curctx, c, a, ct) \ +#define UPLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct) \ mqc->curctx = curctx; \ mqc->c = c; \ mqc->a = a; \ @@ -193,4 +193,90 @@ Decode a symbol #define opj_mqc_decode(d, mqc) \ opj_mqc_decode_macro(d, mqc, mqc->curctx, mqc->a, mqc->c, mqc->ct) +/** +Output a byte, doing bit-stuffing if necessary. +After a 0xff byte, the next byte must be smaller than 0x90. +@param mqc MQC handle +*/ +void opj_mqc_byteout(opj_mqc_t *mqc); + +/** +Renormalize mqc->a and mqc->c while encoding, so that mqc->a stays between 0x8000 and 0x10000 +@param mqc MQC handle +@param a_ value of mqc->a +@param c_ value of mqc->c_ +@param ct_ value of mqc->ct_ +*/ +#define opj_mqc_renorme_macro(mqc, a_, c_, ct_) \ +{ \ + do { \ + a_ <<= 1; \ + c_ <<= 1; \ + ct_--; \ + if (ct_ == 0) { \ + mqc->c = c_; \ + opj_mqc_byteout(mqc); \ + c_ = mqc->c; \ + ct_ = mqc->ct; \ + } \ + } while( (a_ & 0x8000) == 0); \ +} + +#define opj_mqc_codemps_macro(mqc, curctx, a, c, ct) \ +{ \ + a -= (*curctx)->qeval; \ + if ((a & 0x8000) == 0) { \ + if (a < (*curctx)->qeval) { \ + a = (*curctx)->qeval; \ + } else { \ + c += (*curctx)->qeval; \ + } \ + *curctx = (*curctx)->nmps; \ + opj_mqc_renorme_macro(mqc, a, c, ct); \ + } else { \ + c += (*curctx)->qeval; \ + } \ +} + +#define opj_mqc_codelps_macro(mqc, curctx, a, c, ct) \ +{ \ + a -= (*curctx)->qeval; \ + if (a < (*curctx)->qeval) { \ + c += (*curctx)->qeval; \ + } else { \ + a = (*curctx)->qeval; \ + } \ + *curctx = (*curctx)->nlps; \ + opj_mqc_renorme_macro(mqc, a, c, ct); \ +} + +#define opj_mqc_encode_macro(mqc, curctx, a, c, ct, d) \ +{ \ + if ((*curctx)->mps == (d)) { \ + opj_mqc_codemps_macro(mqc, curctx, a, c, ct); \ + } else { \ + opj_mqc_codelps_macro(mqc, curctx, a, c, ct); \ + } \ +} + + +#define opj_mqc_bypass_enc_macro(mqc, c, ct, d) \ +{\ + if (ct == BYPASS_CT_INIT) {\ + ct = 8;\ + }\ + ct--;\ + c = c + ((d) << ct);\ + if (ct == 0) {\ + *mqc->bp = (OPJ_BYTE)c;\ + ct = 8;\ + /* If the previous byte was 0xff, make sure that the next msb is 0 */ \ + if (*mqc->bp == 0xff) {\ + ct = 7;\ + }\ + mqc->bp++;\ + c = 0;\ + }\ +} + #endif /* OPJ_MQC_INL_H */ diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/openjpeg.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/openjpeg.c index 7b12303423b..382d8f4f0f1 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/openjpeg.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/openjpeg.c @@ -89,14 +89,16 @@ OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, /* ---------------------------------------------------------------------- */ static OPJ_SIZE_T opj_read_from_file(void * p_buffer, OPJ_SIZE_T p_nb_bytes, - FILE * p_file) + void * p_user_data) { - OPJ_SIZE_T l_nb_read = fread(p_buffer, 1, p_nb_bytes, p_file); + FILE* p_file = (FILE*)p_user_data; + OPJ_SIZE_T l_nb_read = fread(p_buffer, 1, p_nb_bytes, (FILE*)p_file); return l_nb_read ? l_nb_read : (OPJ_SIZE_T) - 1; } -static OPJ_UINT64 opj_get_data_length_from_file(FILE * p_file) +static OPJ_UINT64 opj_get_data_length_from_file(void * p_user_data) { + FILE* p_file = (FILE*)p_user_data; OPJ_OFF_T file_length = 0; OPJ_FSEEK(p_file, 0, SEEK_END); @@ -107,32 +109,46 @@ static OPJ_UINT64 opj_get_data_length_from_file(FILE * p_file) } static OPJ_SIZE_T opj_write_from_file(void * p_buffer, OPJ_SIZE_T p_nb_bytes, - FILE * p_file) + void * p_user_data) { + FILE* p_file = (FILE*)p_user_data; return fwrite(p_buffer, 1, p_nb_bytes, p_file); } -static OPJ_OFF_T opj_skip_from_file(OPJ_OFF_T p_nb_bytes, FILE * p_user_data) +static OPJ_OFF_T opj_skip_from_file(OPJ_OFF_T p_nb_bytes, void * p_user_data) { - if (OPJ_FSEEK(p_user_data, p_nb_bytes, SEEK_CUR)) { + FILE* p_file = (FILE*)p_user_data; + if (OPJ_FSEEK(p_file, p_nb_bytes, SEEK_CUR)) { return -1; } return p_nb_bytes; } -static OPJ_BOOL opj_seek_from_file(OPJ_OFF_T p_nb_bytes, FILE * p_user_data) +static OPJ_BOOL opj_seek_from_file(OPJ_OFF_T p_nb_bytes, void * p_user_data) { - if (OPJ_FSEEK(p_user_data, p_nb_bytes, SEEK_SET)) { + FILE* p_file = (FILE*)p_user_data; + if (OPJ_FSEEK(p_file, p_nb_bytes, SEEK_SET)) { return OPJ_FALSE; } return OPJ_TRUE; } +static void opj_close_from_file(void* p_user_data) +{ + FILE* p_file = (FILE*)p_user_data; + fclose(p_file); +} + /* ---------------------------------------------------------------------- */ #ifdef _WIN32 #ifndef OPJ_STATIC + +/* declaration to avoid warning: no previous prototype for 'DllMain' */ +BOOL APIENTRY +DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved); + BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { @@ -208,6 +224,10 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format) l_codec->m_codec_data.m_decompression.opj_setup_decoder = (void (*)(void *, opj_dparameters_t *)) opj_j2k_setup_decoder; + l_codec->m_codec_data.m_decompression.opj_decoder_set_strict_mode = + (void (*)(void *, OPJ_BOOL)) opj_j2k_decoder_set_strict_mode; + + l_codec->m_codec_data.m_decompression.opj_read_tile_header = (OPJ_BOOL(*)(void *, OPJ_UINT32*, @@ -315,6 +335,9 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format) l_codec->m_codec_data.m_decompression.opj_setup_decoder = (void (*)(void *, opj_dparameters_t *)) opj_jp2_setup_decoder; + l_codec->m_codec_data.m_decompression.opj_decoder_set_strict_mode = + (void (*)(void *, OPJ_BOOL)) opj_jp2_decoder_set_strict_mode; + l_codec->m_codec_data.m_decompression.opj_set_decode_area = (OPJ_BOOL(*)(void *, opj_image_t*, @@ -415,6 +438,26 @@ OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec, return OPJ_FALSE; } +OPJ_BOOL OPJ_CALLCONV opj_decoder_set_strict_mode(opj_codec_t *p_codec, + OPJ_BOOL strict) +{ + if (p_codec) { + opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; + + if (! l_codec->is_decompressor) { + opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR, + "Codec provided to the opj_decoder_set_strict_mode function is not a decompressor handler.\n"); + return OPJ_FALSE; + } + + l_codec->m_codec_data.m_decompression.opj_decoder_set_strict_mode( + l_codec->m_codec, + strict); + return OPJ_TRUE; + } + return OPJ_FALSE; +} + OPJ_BOOL OPJ_CALLCONV opj_read_header(opj_stream_t *p_stream, opj_codec_t *p_codec, opj_image_t **p_image) @@ -652,6 +695,14 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format) struct opj_image *, struct opj_event_mgr *)) opj_j2k_setup_encoder; + l_codec->m_codec_data.m_compression.opj_encoder_set_extra_options = (OPJ_BOOL( + *)(void *, + const char* const*, + struct opj_event_mgr *)) opj_j2k_encoder_set_extra_options; + + l_codec->opj_set_threads = + (OPJ_BOOL(*)(void * p_codec, OPJ_UINT32 num_threads)) opj_j2k_set_threads; + l_codec->m_codec = opj_j2k_create_compress(); if (! l_codec->m_codec) { opj_free(l_codec); @@ -690,6 +741,14 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format) struct opj_image *, struct opj_event_mgr *)) opj_jp2_setup_encoder; + l_codec->m_codec_data.m_compression.opj_encoder_set_extra_options = (OPJ_BOOL( + *)(void *, + const char* const*, + struct opj_event_mgr *)) opj_jp2_encoder_set_extra_options; + + l_codec->opj_set_threads = + (OPJ_BOOL(*)(void * p_codec, OPJ_UINT32 num_threads)) opj_jp2_set_threads; + l_codec->m_codec = opj_jp2_create(OPJ_FALSE); if (! l_codec->m_codec) { opj_free(l_codec); @@ -718,11 +777,11 @@ void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t parameters->cp_cinema = OPJ_OFF; /* DEPRECATED */ parameters->rsiz = OPJ_PROFILE_NONE; parameters->max_comp_size = 0; - parameters->numresolution = 6; + parameters->numresolution = OPJ_COMP_PARAM_DEFAULT_NUMRESOLUTION; parameters->cp_rsiz = OPJ_STD_RSIZ; /* DEPRECATED */ - parameters->cblockw_init = 64; - parameters->cblockh_init = 64; - parameters->prog_order = OPJ_LRCP; + parameters->cblockw_init = OPJ_COMP_PARAM_DEFAULT_CBLOCKW; + parameters->cblockh_init = OPJ_COMP_PARAM_DEFAULT_CBLOCKH; + parameters->prog_order = OPJ_COMP_PARAM_DEFAULT_PROG_ORDER; parameters->roi_compno = -1; /* no ROI */ parameters->subsampling_dx = 1; parameters->subsampling_dy = 1; @@ -788,6 +847,27 @@ OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec, return OPJ_FALSE; } +/* ----------------------------------------------------------------------- */ + +OPJ_BOOL OPJ_CALLCONV opj_encoder_set_extra_options(opj_codec_t *p_codec, + const char* const* options) +{ + if (p_codec) { + opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; + + if (! l_codec->is_decompressor) { + return l_codec->m_codec_data.m_compression.opj_encoder_set_extra_options( + l_codec->m_codec, + options, + &(l_codec->m_event_mgr)); + } + } + + return OPJ_FALSE; +} + +/* ----------------------------------------------------------------------- */ + OPJ_BOOL OPJ_CALLCONV opj_start_compress(opj_codec_t *p_codec, opj_image_t * p_image, opj_stream_t *p_stream) @@ -1037,15 +1117,14 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream( return NULL; } - opj_stream_set_user_data(l_stream, p_file, - (opj_stream_free_user_data_fn) fclose); + opj_stream_set_user_data(l_stream, p_file, opj_close_from_file); opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file)); - opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file); + opj_stream_set_read_function(l_stream, opj_read_from_file); opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file); - opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file); - opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file); + opj_stream_set_skip_function(l_stream, opj_skip_from_file); + opj_stream_set_seek_function(l_stream, opj_seek_from_file); return l_stream; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/openjpeg.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/openjpeg.h index 1f94604afb6..e19e8eceae1 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/openjpeg.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/openjpeg.h @@ -76,9 +76,15 @@ Most compilers implement their own version of this keyword ... #define OPJ_DEPRECATED(func) func #endif +#if defined(__GNUC__) && __GNUC__ >= 6 +#define OPJ_DEPRECATED_STRUCT_MEMBER(memb, msg) __attribute__ ((deprecated(msg))) memb +#else +#define OPJ_DEPRECATED_STRUCT_MEMBER(memb, msg) memb +#endif + #if defined(OPJ_STATIC) || !defined(_WIN32) /* http://gcc.gnu.org/wiki/Visibility */ -# if __GNUC__ >= 4 +# if !defined(_WIN32) && __GNUC__ >= 4 # if defined(OPJ_STATIC) /* static library uses "hidden" */ # define OPJ_API __attribute__ ((visibility ("hidden"))) # else @@ -117,7 +123,7 @@ typedef double OPJ_FLOAT64; typedef unsigned char OPJ_BYTE; #include "openjpeg_mangle.h" -#include "opj_stdint.h" +#include typedef int8_t OPJ_INT8; typedef uint8_t OPJ_UINT8; @@ -133,6 +139,8 @@ typedef int64_t OPJ_OFF_T; /* 64-bit file offset type */ #include typedef size_t OPJ_SIZE_T; +#include "opj_config.h" + /* Avoid compile-time warning because parameter is not used */ #define OPJ_ARG_NOT_USED(x) (void)(x) @@ -205,11 +213,11 @@ typedef size_t OPJ_SIZE_T; #define OPJ_PROFILE_BC_MULTI 0x0200 /** Multi Tile Broadcast profile defined in 15444-1 AMD3 */ #define OPJ_PROFILE_BC_MULTI_R 0x0300 /** Multi Tile Reversible Broadcast profile defined in 15444-1 AMD3 */ #define OPJ_PROFILE_IMF_2K 0x0400 /** 2K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */ -#define OPJ_PROFILE_IMF_4K 0x0401 /** 4K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */ -#define OPJ_PROFILE_IMF_8K 0x0402 /** 8K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */ -#define OPJ_PROFILE_IMF_2K_R 0x0403 /** 2K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */ +#define OPJ_PROFILE_IMF_4K 0x0500 /** 4K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */ +#define OPJ_PROFILE_IMF_8K 0x0600 /** 8K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */ +#define OPJ_PROFILE_IMF_2K_R 0x0700 /** 2K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */ #define OPJ_PROFILE_IMF_4K_R 0x0800 /** 4K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */ -#define OPJ_PROFILE_IMF_8K_R 0x0801 /** 8K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */ +#define OPJ_PROFILE_IMF_8K_R 0x0900 /** 8K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */ /** * JPEG 2000 Part-2 extensions @@ -226,6 +234,36 @@ typedef size_t OPJ_SIZE_T; #define OPJ_IS_IMF(v) (((v) >= OPJ_PROFILE_IMF_2K)&&((v) <= ((OPJ_PROFILE_IMF_8K_R) | (0x009b)))) #define OPJ_IS_PART2(v) ((v) & OPJ_PROFILE_PART2) +#define OPJ_GET_IMF_PROFILE(v) ((v) & 0xff00) /** Extract IMF profile without mainlevel/sublevel */ +#define OPJ_GET_IMF_MAINLEVEL(v) ((v) & 0xf) /** Extract IMF main level */ +#define OPJ_GET_IMF_SUBLEVEL(v) (((v) >> 4) & 0xf) /** Extract IMF sub level */ + +#define OPJ_IMF_MAINLEVEL_MAX 11 /** Maximum main level */ + +/** Max. Components Sampling Rate (MSamples/sec) per IMF main level */ +#define OPJ_IMF_MAINLEVEL_1_MSAMPLESEC 65 /** MSamples/sec for IMF main level 1 */ +#define OPJ_IMF_MAINLEVEL_2_MSAMPLESEC 130 /** MSamples/sec for IMF main level 2 */ +#define OPJ_IMF_MAINLEVEL_3_MSAMPLESEC 195 /** MSamples/sec for IMF main level 3 */ +#define OPJ_IMF_MAINLEVEL_4_MSAMPLESEC 260 /** MSamples/sec for IMF main level 4 */ +#define OPJ_IMF_MAINLEVEL_5_MSAMPLESEC 520 /** MSamples/sec for IMF main level 5 */ +#define OPJ_IMF_MAINLEVEL_6_MSAMPLESEC 1200 /** MSamples/sec for IMF main level 6 */ +#define OPJ_IMF_MAINLEVEL_7_MSAMPLESEC 2400 /** MSamples/sec for IMF main level 7 */ +#define OPJ_IMF_MAINLEVEL_8_MSAMPLESEC 4800 /** MSamples/sec for IMF main level 8 */ +#define OPJ_IMF_MAINLEVEL_9_MSAMPLESEC 9600 /** MSamples/sec for IMF main level 9 */ +#define OPJ_IMF_MAINLEVEL_10_MSAMPLESEC 19200 /** MSamples/sec for IMF main level 10 */ +#define OPJ_IMF_MAINLEVEL_11_MSAMPLESEC 38400 /** MSamples/sec for IMF main level 11 */ + +/** Max. compressed Bit Rate (Mbits/s) per IMF sub level */ +#define OPJ_IMF_SUBLEVEL_1_MBITSSEC 200 /** Mbits/s for IMF sub level 1 */ +#define OPJ_IMF_SUBLEVEL_2_MBITSSEC 400 /** Mbits/s for IMF sub level 2 */ +#define OPJ_IMF_SUBLEVEL_3_MBITSSEC 800 /** Mbits/s for IMF sub level 3 */ +#define OPJ_IMF_SUBLEVEL_4_MBITSSEC 1600 /** Mbits/s for IMF sub level 4 */ +#define OPJ_IMF_SUBLEVEL_5_MBITSSEC 3200 /** Mbits/s for IMF sub level 5 */ +#define OPJ_IMF_SUBLEVEL_6_MBITSSEC 6400 /** Mbits/s for IMF sub level 6 */ +#define OPJ_IMF_SUBLEVEL_7_MBITSSEC 12800 /** Mbits/s for IMF sub level 7 */ +#define OPJ_IMF_SUBLEVEL_8_MBITSSEC 25600 /** Mbits/s for IMF sub level 8 */ +#define OPJ_IMF_SUBLEVEL_9_MBITSSEC 51200 /** Mbits/s for IMF sub level 9 */ + /** * JPEG 2000 codestream and component size limits in cinema profiles * */ @@ -319,6 +357,10 @@ typedef void (*opj_msg_callback)(const char *msg, void *client_data); ========================================================== */ +#ifndef OPJ_UINT32_SEMANTICALLY_BUT_INT32 +#define OPJ_UINT32_SEMANTICALLY_BUT_INT32 OPJ_INT32 +#endif + /** * Progression order changes * @@ -334,10 +376,10 @@ typedef struct opj_poc { OPJ_PROG_ORDER prg1, prg; /** Progression order string*/ OPJ_CHAR progorder[5]; - /** Tile number */ + /** Tile number (starting at 1) */ OPJ_UINT32 tile; /** Start and end values for Tile width and height*/ - OPJ_INT32 tx0, tx1, ty0, ty1; + OPJ_UINT32_SEMANTICALLY_BUT_INT32 tx0, tx1, ty0, ty1; /** Start value, initialised in pi_initialise_encode*/ OPJ_UINT32 layS, resS, compS, prcS; /** End value, initialised in pi_initialise_encode */ @@ -366,7 +408,7 @@ typedef struct opj_cparameters { int cp_disto_alloc; /** allocation by fixed layer */ int cp_fixed_alloc; - /** add fixed_quality */ + /** allocation by fixed quality (PSNR) */ int cp_fixed_quality; /** fixed layer */ int *cp_matrice; @@ -416,9 +458,9 @@ typedef struct opj_cparameters { char infile[OPJ_PATH_LEN]; /** output file name */ char outfile[OPJ_PATH_LEN]; - /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */ + /** DEPRECATED. Index generation is now handled with the opj_encode_with_info() function. Set to NULL */ int index_on; - /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */ + /** DEPRECATED. Index generation is now handled with the opj_encode_with_info() function. Set to NULL */ char index[OPJ_PATH_LEN]; /** subimage encoding: origin image offset in x direction */ int image_offset_x0; @@ -505,7 +547,7 @@ typedef struct opj_cparameters { } opj_cparameters_t; #define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG 0x0001 -#define OPJ_DPARAMETERS_DUMP_FLAG 0x0002 +#define OPJ_DPARAMETERS_DUMP_FLAG 0x0002 /** * Decompression parameters @@ -549,7 +591,7 @@ typedef struct opj_dparameters { /** Verbose mode */ OPJ_BOOL m_verbose; - /** tile number ot the decoded tile*/ + /** tile number of the decoded tile */ OPJ_UINT32 tile_index; /** Nb of tile to decode */ OPJ_UINT32 nb_tile_to_decode; @@ -648,10 +690,10 @@ typedef struct opj_image_comp { OPJ_UINT32 x0; /** y component offset compared to the whole image */ OPJ_UINT32 y0; - /** precision */ + /** precision: number of bits per component per pixel */ OPJ_UINT32 prec; - /** image depth in bits */ - OPJ_UINT32 bpp; + /** obsolete: use prec instead */ + OPJ_DEPRECATED_STRUCT_MEMBER(OPJ_UINT32 bpp, "Use prec instead"); /** signed (1) / unsigned (0) */ OPJ_UINT32 sgnd; /** number of decoded resolution */ @@ -705,10 +747,10 @@ typedef struct opj_image_comptparm { OPJ_UINT32 x0; /** y component offset compared to the whole image */ OPJ_UINT32 y0; - /** precision */ + /** precision: number of bits per component per pixel */ OPJ_UINT32 prec; - /** image depth in bits */ - OPJ_UINT32 bpp; + /** obsolete: use prec instead */ + OPJ_DEPRECATED_STRUCT_MEMBER(OPJ_UINT32 bpp, "Use prec instead"); /** signed (1) / unsigned (0) */ OPJ_UINT32 sgnd; } opj_image_cmptparm_t; @@ -731,7 +773,7 @@ typedef struct opj_packet_info { OPJ_OFF_T end_ph_pos; /** packet end position */ OPJ_OFF_T end_pos; - /** packet distorsion */ + /** packet distortion */ double disto; } opj_packet_info_t; @@ -790,9 +832,9 @@ typedef struct opj_tile_info { int pdy[33]; /** information concerning packets inside tile */ opj_packet_info_t *packet; - /** add fixed_quality */ + /** number of pixels of the tile */ int numpix; - /** add fixed_quality */ + /** distortion of the tile */ double distotile; /** number of markers */ int marknum; @@ -1179,7 +1221,8 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function); /** - * Sets the given function to be used as a seek function, the stream is then seekable. + * Sets the given function to be used as a seek function, the stream is then seekable, + * using SEEK_SET behavior. * @param p_stream the stream to modify * @param p_function the function to use a skip function. */ @@ -1305,6 +1348,24 @@ OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters( OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec, opj_dparameters_t *parameters); +/** + * Set strict decoding parameter for this decoder. + * If strict decoding is enabled, partial bit streams will fail to decode, and + * the check for invalid TPSOT values added in https://github.com/uclouvain/openjpeg/pull/514 + * will be disabled. + * If strict decoding is disabled, the decoder will decode partial + * bitstreams as much as possible without erroring, and the TPSOT fixing logic + * will be enabled. + * + * @param p_codec decompressor handler + * @param strict OPJ_TRUE to enable strict decoding, OPJ_FALSE to disable + * + * @return true if the decoder is correctly set + */ + +OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decoder_set_strict_mode(opj_codec_t *p_codec, + OPJ_BOOL strict); + /** * Allocates worker threads for the compressor/decompressor. * @@ -1314,12 +1375,14 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec, * number, or "ALL_CPUS". If OPJ_NUM_THREADS is set and this function is called, * this function will override the behaviour of the environment variable. * - * Note: currently only has effect on the decompressor. + * This function must be called after opj_setup_decoder() and + * before opj_read_header() for the decoding side, or after opj_setup_encoder() + * and before opj_start_compress() for the encoding side. * - * @param p_codec decompressor handler + * @param p_codec decompressor or compressor handler * @param num_threads number of threads. * - * @return OPJ_TRUE if the decoder is correctly set + * @return OPJ_TRUE if the function is successful. */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_codec_set_threads(opj_codec_t *p_codec, int num_threads); @@ -1382,7 +1445,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_components(opj_codec_t *p_codec, * performance improvements when reading an image by chunks. * * @param p_codec the jpeg2000 codec. - * @param p_image the decoded image previously setted by opj_read_header + * @param p_image the decoded image previously set by opj_read_header * @param p_start_x the left position of the rectangle to decode (in image coordinates). * @param p_end_x the right position of the rectangle to decode (in image coordinates). * @param p_start_y the up position of the rectangle to decode (in image coordinates). @@ -1411,7 +1474,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode(opj_codec_t *p_decompressor, * Get the decoded tile from the codec * * @param p_codec the jpeg2000 codec. - * @param p_stream input streamm + * @param p_stream input stream * @param p_image output image * @param tile_index index of the tile which will be decode * @@ -1543,6 +1606,39 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec, opj_cparameters_t *parameters, opj_image_t *image); + +/** + * Specify extra options for the encoder. + * + * This may be called after opj_setup_encoder() and before opj_start_compress() + * + * This is the way to add new options in a fully ABI compatible way, without + * extending the opj_cparameters_t structure. + * + * Currently supported options are: + *
    + *
  • PLT=YES/NO. Defaults to NO. If set to YES, PLT marker segments, + * indicating the length of each packet in the tile-part header, will be + * written. Since 2.4.0
  • + *
  • TLM=YES/NO. Defaults to NO (except for Cinema and IMF profiles). + * If set to YES, TLM marker segments, indicating the length of each + * tile-part part will be written. Since 2.4.0
  • + *
  • GUARD_BITS=value. Number of guard bits in [0,7] range. Default value is 2. + * 1 may be used sometimes (like in SMPTE DCP Bv2.1 Application Profile for 2K images). + * Since 2.5.0
  • + *
+ * + * @param p_codec Compressor handle + * @param p_options Compression options. This should be a NULL terminated + * array of strings. Each string is of the form KEY=VALUE. + * + * @return OPJ_TRUE in case of success. + * @since 2.4.0 + */ +OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encoder_set_extra_options( + opj_codec_t *p_codec, + const char* const* p_options); + /** * Start to compress the current image. * @param p_codec Compressor handle diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/openjpeg_mangle.h.in b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/openjpeg_mangle.h.in index 3a8c9214de2..570a93862a5 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/openjpeg_mangle.h.in +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/openjpeg_mangle.h.in @@ -12,262 +12,270 @@ * The following command was used to obtain the symbol list: * * nm lib@MANGLE_PREFIX@.a | grep " [RT] " + * Mac: nm -g lib/libgdcmopenjpeg* 2> /dev/null | grep " [TDRS] " | awk '{ print substr($3, 2); }' | awk '{ sub(/@MANGLE_PREFIX@_/, ""); print }' | sed 's/\(.*\)/#define \1\ @MANGLE_PREFIX@_\1/' | sort + */ -#define opj_cond_create @MANGLE_PREFIX@opj_cond_create -#define opj_cond_destroy @MANGLE_PREFIX@opj_cond_destroy -#define opj_cond_signal @MANGLE_PREFIX@opj_cond_signal -#define opj_cond_wait @MANGLE_PREFIX@opj_cond_wait -#define opj_get_num_cpus @MANGLE_PREFIX@opj_get_num_cpus -#define opj_has_thread_support @MANGLE_PREFIX@opj_has_thread_support -#define opj_mutex_create @MANGLE_PREFIX@opj_mutex_create -#define opj_mutex_destroy @MANGLE_PREFIX@opj_mutex_destroy -#define opj_mutex_lock @MANGLE_PREFIX@opj_mutex_lock -#define opj_mutex_unlock @MANGLE_PREFIX@opj_mutex_unlock -#define opj_thread_create @MANGLE_PREFIX@opj_thread_create -#define opj_thread_join @MANGLE_PREFIX@opj_thread_join -#define opj_thread_pool_create @MANGLE_PREFIX@opj_thread_pool_create -#define opj_thread_pool_destroy @MANGLE_PREFIX@opj_thread_pool_destroy -#define opj_thread_pool_get_thread_count @MANGLE_PREFIX@opj_thread_pool_get_thread_count -#define opj_thread_pool_submit_job @MANGLE_PREFIX@opj_thread_pool_submit_job -#define opj_thread_pool_wait_completion @MANGLE_PREFIX@opj_thread_pool_wait_completion -#define opj_tls_get @MANGLE_PREFIX@opj_tls_get -#define opj_tls_set @MANGLE_PREFIX@opj_tls_set -#define opj_bio_create @MANGLE_PREFIX@opj_bio_create -#define opj_bio_destroy @MANGLE_PREFIX@opj_bio_destroy -#define opj_bio_flush @MANGLE_PREFIX@opj_bio_flush -#define opj_bio_inalign @MANGLE_PREFIX@opj_bio_inalign -#define opj_bio_init_dec @MANGLE_PREFIX@opj_bio_init_dec -#define opj_bio_init_enc @MANGLE_PREFIX@opj_bio_init_enc -#define opj_bio_numbytes @MANGLE_PREFIX@opj_bio_numbytes -#define opj_bio_read @MANGLE_PREFIX@opj_bio_read -#define opj_bio_write @MANGLE_PREFIX@opj_bio_write -#define opj_read_bytes_BE @MANGLE_PREFIX@opj_read_bytes_BE -#define opj_read_bytes_LE @MANGLE_PREFIX@opj_read_bytes_LE -#define opj_read_double_BE @MANGLE_PREFIX@opj_read_double_BE -#define opj_read_double_LE @MANGLE_PREFIX@opj_read_double_LE -#define opj_read_float_BE @MANGLE_PREFIX@opj_read_float_BE -#define opj_read_float_LE @MANGLE_PREFIX@opj_read_float_LE -#define opj_stream_create @MANGLE_PREFIX@opj_stream_create -#define opj_stream_default_create @MANGLE_PREFIX@opj_stream_default_create -#define opj_stream_default_read @MANGLE_PREFIX@opj_stream_default_read -#define opj_stream_default_seek @MANGLE_PREFIX@opj_stream_default_seek -#define opj_stream_default_skip @MANGLE_PREFIX@opj_stream_default_skip -#define opj_stream_default_write @MANGLE_PREFIX@opj_stream_default_write -#define opj_stream_destroy @MANGLE_PREFIX@opj_stream_destroy -#define opj_stream_flush @MANGLE_PREFIX@opj_stream_flush -#define opj_stream_get_number_byte_left @MANGLE_PREFIX@opj_stream_get_number_byte_left -#define opj_stream_has_seek @MANGLE_PREFIX@opj_stream_has_seek -#define opj_stream_read_data @MANGLE_PREFIX@opj_stream_read_data -#define opj_stream_read_seek @MANGLE_PREFIX@opj_stream_read_seek -#define opj_stream_read_skip @MANGLE_PREFIX@opj_stream_read_skip -#define opj_stream_seek @MANGLE_PREFIX@opj_stream_seek -#define opj_stream_set_read_function @MANGLE_PREFIX@opj_stream_set_read_function -#define opj_stream_set_seek_function @MANGLE_PREFIX@opj_stream_set_seek_function -#define opj_stream_set_skip_function @MANGLE_PREFIX@opj_stream_set_skip_function -#define opj_stream_set_user_data @MANGLE_PREFIX@opj_stream_set_user_data -#define opj_stream_set_user_data_length @MANGLE_PREFIX@opj_stream_set_user_data_length -#define opj_stream_set_write_function @MANGLE_PREFIX@opj_stream_set_write_function -#define opj_stream_skip @MANGLE_PREFIX@opj_stream_skip -#define opj_stream_tell @MANGLE_PREFIX@opj_stream_tell -#define opj_stream_write_data @MANGLE_PREFIX@opj_stream_write_data -#define opj_stream_write_seek @MANGLE_PREFIX@opj_stream_write_seek -#define opj_stream_write_skip @MANGLE_PREFIX@opj_stream_write_skip -#define opj_write_bytes_BE @MANGLE_PREFIX@opj_write_bytes_BE -#define opj_write_bytes_LE @MANGLE_PREFIX@opj_write_bytes_LE -#define opj_write_double_BE @MANGLE_PREFIX@opj_write_double_BE -#define opj_write_double_LE @MANGLE_PREFIX@opj_write_double_LE -#define opj_write_float_BE @MANGLE_PREFIX@opj_write_float_BE -#define opj_write_float_LE @MANGLE_PREFIX@opj_write_float_LE -#define opj_dwt_calc_explicit_stepsizes @MANGLE_PREFIX@opj_dwt_calc_explicit_stepsizes -#define opj_dwt_decode @MANGLE_PREFIX@opj_dwt_decode -#define opj_dwt_decode_real @MANGLE_PREFIX@opj_dwt_decode_real -#define opj_dwt_encode @MANGLE_PREFIX@opj_dwt_encode -#define opj_dwt_encode_real @MANGLE_PREFIX@opj_dwt_encode_real -#define opj_dwt_getgain @MANGLE_PREFIX@opj_dwt_getgain -#define opj_dwt_getgain_real @MANGLE_PREFIX@opj_dwt_getgain_real -#define opj_dwt_getnorm @MANGLE_PREFIX@opj_dwt_getnorm -#define opj_dwt_getnorm_real @MANGLE_PREFIX@opj_dwt_getnorm_real -#define opj_event_msg @MANGLE_PREFIX@opj_event_msg -#define opj_set_default_event_handler @MANGLE_PREFIX@opj_set_default_event_handler -#define opj_copy_image_header @MANGLE_PREFIX@opj_copy_image_header -#define opj_image_comp_header_update @MANGLE_PREFIX@opj_image_comp_header_update -#define opj_image_create @MANGLE_PREFIX@opj_image_create -#define opj_image_create0 @MANGLE_PREFIX@opj_image_create0 -#define opj_image_destroy @MANGLE_PREFIX@opj_image_destroy -#define opj_image_tile_create @MANGLE_PREFIX@opj_image_tile_create -#define opj_matrix_inversion_f @MANGLE_PREFIX@opj_matrix_inversion_f -#define j2k_destroy_cstr_index @MANGLE_PREFIX@j2k_destroy_cstr_index -#define j2k_dump @MANGLE_PREFIX@j2k_dump -#define j2k_dump_image_comp_header @MANGLE_PREFIX@j2k_dump_image_comp_header -#define j2k_dump_image_header @MANGLE_PREFIX@j2k_dump_image_header -#define j2k_get_cstr_index @MANGLE_PREFIX@j2k_get_cstr_index -#define j2k_get_cstr_info @MANGLE_PREFIX@j2k_get_cstr_info -#define opj_j2k_convert_progression_order @MANGLE_PREFIX@opj_j2k_convert_progression_order -#define opj_j2k_create_compress @MANGLE_PREFIX@opj_j2k_create_compress -#define opj_j2k_create_decompress @MANGLE_PREFIX@opj_j2k_create_decompress -#define opj_j2k_decode @MANGLE_PREFIX@opj_j2k_decode -#define opj_j2k_decode_tile @MANGLE_PREFIX@opj_j2k_decode_tile -#define opj_j2k_destroy @MANGLE_PREFIX@opj_j2k_destroy -#define opj_j2k_encode @MANGLE_PREFIX@opj_j2k_encode -#define opj_j2k_end_compress @MANGLE_PREFIX@opj_j2k_end_compress -#define opj_j2k_end_decompress @MANGLE_PREFIX@opj_j2k_end_decompress -#define opj_j2k_get_tile @MANGLE_PREFIX@opj_j2k_get_tile -#define opj_j2k_read_header @MANGLE_PREFIX@opj_j2k_read_header -#define opj_j2k_read_tile_header @MANGLE_PREFIX@opj_j2k_read_tile_header -#define opj_j2k_set_decode_area @MANGLE_PREFIX@opj_j2k_set_decode_area -#define opj_j2k_set_decoded_components @MANGLE_PREFIX@opj_j2k_set_decoded_components -#define opj_j2k_set_decoded_resolution_factor @MANGLE_PREFIX@opj_j2k_set_decoded_resolution_factor -#define opj_j2k_set_threads @MANGLE_PREFIX@opj_j2k_set_threads -#define opj_j2k_setup_decoder @MANGLE_PREFIX@opj_j2k_setup_decoder -#define opj_j2k_setup_encoder @MANGLE_PREFIX@opj_j2k_setup_encoder -#define opj_j2k_setup_mct_encoding @MANGLE_PREFIX@opj_j2k_setup_mct_encoding -#define opj_j2k_start_compress @MANGLE_PREFIX@opj_j2k_start_compress -#define opj_j2k_write_tile @MANGLE_PREFIX@opj_j2k_write_tile -#define jp2_dump @MANGLE_PREFIX@jp2_dump -#define jp2_get_cstr_index @MANGLE_PREFIX@jp2_get_cstr_index -#define jp2_get_cstr_info @MANGLE_PREFIX@jp2_get_cstr_info -#define opj_jp2_create @MANGLE_PREFIX@opj_jp2_create -#define opj_jp2_decode @MANGLE_PREFIX@opj_jp2_decode -#define opj_jp2_decode_tile @MANGLE_PREFIX@opj_jp2_decode_tile -#define opj_jp2_destroy @MANGLE_PREFIX@opj_jp2_destroy -#define opj_jp2_encode @MANGLE_PREFIX@opj_jp2_encode -#define opj_jp2_end_compress @MANGLE_PREFIX@opj_jp2_end_compress -#define opj_jp2_end_decompress @MANGLE_PREFIX@opj_jp2_end_decompress -#define opj_jp2_get_tile @MANGLE_PREFIX@opj_jp2_get_tile -#define opj_jp2_read_header @MANGLE_PREFIX@opj_jp2_read_header -#define opj_jp2_read_tile_header @MANGLE_PREFIX@opj_jp2_read_tile_header -#define opj_jp2_set_decode_area @MANGLE_PREFIX@opj_jp2_set_decode_area -#define opj_jp2_set_decoded_components @MANGLE_PREFIX@opj_jp2_set_decoded_components -#define opj_jp2_set_decoded_resolution_factor @MANGLE_PREFIX@opj_jp2_set_decoded_resolution_factor -#define opj_jp2_set_threads @MANGLE_PREFIX@opj_jp2_set_threads -#define opj_jp2_setup_decoder @MANGLE_PREFIX@opj_jp2_setup_decoder -#define opj_jp2_setup_encoder @MANGLE_PREFIX@opj_jp2_setup_encoder -#define opj_jp2_start_compress @MANGLE_PREFIX@opj_jp2_start_compress -#define opj_jp2_write_tile @MANGLE_PREFIX@opj_jp2_write_tile -#define opj_calculate_norms @MANGLE_PREFIX@opj_calculate_norms -#define opj_mct_decode @MANGLE_PREFIX@opj_mct_decode -#define opj_mct_decode_custom @MANGLE_PREFIX@opj_mct_decode_custom -#define opj_mct_decode_real @MANGLE_PREFIX@opj_mct_decode_real -#define opj_mct_encode @MANGLE_PREFIX@opj_mct_encode -#define opj_mct_encode_custom @MANGLE_PREFIX@opj_mct_encode_custom -#define opj_mct_encode_real @MANGLE_PREFIX@opj_mct_encode_real -#define opj_mct_get_mct_norms @MANGLE_PREFIX@opj_mct_get_mct_norms -#define opj_mct_get_mct_norms_real @MANGLE_PREFIX@opj_mct_get_mct_norms_real -#define opj_mct_getnorm @MANGLE_PREFIX@opj_mct_getnorm -#define opj_mct_getnorm_real @MANGLE_PREFIX@opj_mct_getnorm_real -#define opj_mqc_bypass_enc @MANGLE_PREFIX@opj_mqc_bypass_enc -#define opj_mqc_bypass_flush_enc @MANGLE_PREFIX@opj_mqc_bypass_flush_enc -#define opj_mqc_bypass_get_extra_bytes @MANGLE_PREFIX@opj_mqc_bypass_get_extra_bytes -#define opj_mqc_bypass_init_enc @MANGLE_PREFIX@opj_mqc_bypass_init_enc -#define opj_mqc_encode @MANGLE_PREFIX@opj_mqc_encode -#define opj_mqc_erterm_enc @MANGLE_PREFIX@opj_mqc_erterm_enc -#define opj_mqc_flush @MANGLE_PREFIX@opj_mqc_flush -#define opj_mqc_init_dec @MANGLE_PREFIX@opj_mqc_init_dec -#define opj_mqc_init_enc @MANGLE_PREFIX@opj_mqc_init_enc -#define opj_mqc_numbytes @MANGLE_PREFIX@opj_mqc_numbytes -#define opj_mqc_raw_init_dec @MANGLE_PREFIX@opj_mqc_raw_init_dec -#define opj_mqc_reset_enc @MANGLE_PREFIX@opj_mqc_reset_enc -#define opj_mqc_resetstates @MANGLE_PREFIX@opj_mqc_resetstates -#define opj_mqc_restart_init_enc @MANGLE_PREFIX@opj_mqc_restart_init_enc -#define opj_mqc_segmark_enc @MANGLE_PREFIX@opj_mqc_segmark_enc -#define opj_mqc_setstate @MANGLE_PREFIX@opj_mqc_setstate -#define opq_mqc_finish_dec @MANGLE_PREFIX@opq_mqc_finish_dec -#define opj_codec_set_threads @MANGLE_PREFIX@opj_codec_set_threads -#define opj_create_compress @MANGLE_PREFIX@opj_create_compress -#define opj_create_decompress @MANGLE_PREFIX@opj_create_decompress -#define opj_decode @MANGLE_PREFIX@opj_decode -#define opj_decode_tile_data @MANGLE_PREFIX@opj_decode_tile_data -#define opj_destroy_codec @MANGLE_PREFIX@opj_destroy_codec -#define opj_destroy_cstr_index @MANGLE_PREFIX@opj_destroy_cstr_index -#define opj_destroy_cstr_info @MANGLE_PREFIX@opj_destroy_cstr_info -#define opj_dump_codec @MANGLE_PREFIX@opj_dump_codec -#define opj_encode @MANGLE_PREFIX@opj_encode -#define opj_end_compress @MANGLE_PREFIX@opj_end_compress -#define opj_end_decompress @MANGLE_PREFIX@opj_end_decompress -#define opj_get_cstr_index @MANGLE_PREFIX@opj_get_cstr_index -#define opj_get_cstr_info @MANGLE_PREFIX@opj_get_cstr_info -#define opj_get_decoded_tile @MANGLE_PREFIX@opj_get_decoded_tile -#define opj_image_data_alloc @MANGLE_PREFIX@opj_image_data_alloc -#define opj_image_data_free @MANGLE_PREFIX@opj_image_data_free -#define opj_read_header @MANGLE_PREFIX@opj_read_header -#define opj_read_tile_header @MANGLE_PREFIX@opj_read_tile_header -#define opj_set_decode_area @MANGLE_PREFIX@opj_set_decode_area -#define opj_set_decoded_components @MANGLE_PREFIX@opj_set_decoded_components -#define opj_set_decoded_resolution_factor @MANGLE_PREFIX@opj_set_decoded_resolution_factor -#define opj_set_default_decoder_parameters @MANGLE_PREFIX@opj_set_default_decoder_parameters -#define opj_set_default_encoder_parameters @MANGLE_PREFIX@opj_set_default_encoder_parameters -#define opj_set_error_handler @MANGLE_PREFIX@opj_set_error_handler -#define opj_set_info_handler @MANGLE_PREFIX@opj_set_info_handler -#define opj_set_MCT @MANGLE_PREFIX@opj_set_MCT -#define opj_setup_decoder @MANGLE_PREFIX@opj_setup_decoder -#define opj_setup_encoder @MANGLE_PREFIX@opj_setup_encoder -#define opj_set_warning_handler @MANGLE_PREFIX@opj_set_warning_handler -#define opj_start_compress @MANGLE_PREFIX@opj_start_compress -#define opj_stream_create_default_file_stream @MANGLE_PREFIX@opj_stream_create_default_file_stream -#define opj_stream_create_file_stream @MANGLE_PREFIX@opj_stream_create_file_stream -#define opj_version @MANGLE_PREFIX@opj_version -#define opj_write_tile @MANGLE_PREFIX@opj_write_tile -#define opj_clock @MANGLE_PREFIX@opj_clock -#define opj_pi_create_decode @MANGLE_PREFIX@opj_pi_create_decode -#define opj_pi_create_encode @MANGLE_PREFIX@opj_pi_create_encode -#define opj_pi_destroy @MANGLE_PREFIX@opj_pi_destroy -#define opj_pi_initialise_encode @MANGLE_PREFIX@opj_pi_initialise_encode -#define opj_pi_next @MANGLE_PREFIX@opj_pi_next -#define opj_pi_update_encoding_parameters @MANGLE_PREFIX@opj_pi_update_encoding_parameters -#define opj_t1_create @MANGLE_PREFIX@opj_t1_create -#define opj_t1_decode_cblks @MANGLE_PREFIX@opj_t1_decode_cblks -#define opj_t1_destroy @MANGLE_PREFIX@opj_t1_destroy -#define opj_t1_encode_cblks @MANGLE_PREFIX@opj_t1_encode_cblks -#define opj_t2_create @MANGLE_PREFIX@opj_t2_create -#define opj_t2_decode_packets @MANGLE_PREFIX@opj_t2_decode_packets -#define opj_t2_destroy @MANGLE_PREFIX@opj_t2_destroy -#define opj_t2_encode_packets @MANGLE_PREFIX@opj_t2_encode_packets -#define opj_alloc_tile_component_data @MANGLE_PREFIX@opj_alloc_tile_component_data -#define opj_tcd_copy_tile_data @MANGLE_PREFIX@opj_tcd_copy_tile_data -#define opj_tcd_create @MANGLE_PREFIX@opj_tcd_create -#define opj_tcd_decode_tile @MANGLE_PREFIX@opj_tcd_decode_tile -#define opj_tcd_destroy @MANGLE_PREFIX@opj_tcd_destroy -#define opj_tcd_encode_tile @MANGLE_PREFIX@opj_tcd_encode_tile -#define opj_tcd_get_decoded_tile_size @MANGLE_PREFIX@opj_tcd_get_decoded_tile_size -#define opj_tcd_get_encoded_tile_size @MANGLE_PREFIX@opj_tcd_get_encoded_tile_size -#define opj_tcd_init @MANGLE_PREFIX@opj_tcd_init -#define opj_tcd_init_decode_tile @MANGLE_PREFIX@opj_tcd_init_decode_tile -#define opj_tcd_init_encode_tile @MANGLE_PREFIX@opj_tcd_init_encode_tile -#define opj_tcd_is_band_empty @MANGLE_PREFIX@opj_tcd_is_band_empty -#define opj_tcd_is_subband_area_of_interest @MANGLE_PREFIX@opj_tcd_is_subband_area_of_interest -#define opj_tcd_makelayer @MANGLE_PREFIX@opj_tcd_makelayer -#define opj_tcd_makelayer_fixed @MANGLE_PREFIX@opj_tcd_makelayer_fixed -#define opj_tcd_rateallocate @MANGLE_PREFIX@opj_tcd_rateallocate -#define opj_tcd_rateallocate_fixed @MANGLE_PREFIX@opj_tcd_rateallocate_fixed -#define opj_tcd_reinit_segment @MANGLE_PREFIX@opj_tcd_reinit_segment -#define opj_tcd_update_tile_data @MANGLE_PREFIX@opj_tcd_update_tile_data -#define opj_tgt_create @MANGLE_PREFIX@opj_tgt_create -#define opj_tgt_decode @MANGLE_PREFIX@opj_tgt_decode -#define opj_tgt_destroy @MANGLE_PREFIX@opj_tgt_destroy -#define opj_tgt_encode @MANGLE_PREFIX@opj_tgt_encode -#define opj_tgt_init @MANGLE_PREFIX@opj_tgt_init -#define opj_tgt_reset @MANGLE_PREFIX@opj_tgt_reset -#define opj_tgt_setvalue @MANGLE_PREFIX@opj_tgt_setvalue -#define opj_procedure_list_add_procedure @MANGLE_PREFIX@opj_procedure_list_add_procedure -#define opj_procedure_list_clear @MANGLE_PREFIX@opj_procedure_list_clear -#define opj_procedure_list_create @MANGLE_PREFIX@opj_procedure_list_create -#define opj_procedure_list_destroy @MANGLE_PREFIX@opj_procedure_list_destroy -#define opj_procedure_list_get_first_procedure @MANGLE_PREFIX@opj_procedure_list_get_first_procedure -#define opj_procedure_list_get_nb_procedures @MANGLE_PREFIX@opj_procedure_list_get_nb_procedures -#define opj_aligned_32_malloc @MANGLE_PREFIX@opj_aligned_32_malloc -#define opj_aligned_32_realloc @MANGLE_PREFIX@opj_aligned_32_realloc -#define opj_aligned_free @MANGLE_PREFIX@opj_aligned_free -#define opj_aligned_malloc @MANGLE_PREFIX@opj_aligned_malloc -#define opj_aligned_realloc @MANGLE_PREFIX@opj_aligned_realloc -#define opj_calloc @MANGLE_PREFIX@opj_calloc -#define opj_free @MANGLE_PREFIX@opj_free -#define opj_malloc @MANGLE_PREFIX@opj_malloc -#define opj_realloc @MANGLE_PREFIX@opj_realloc -#define opj_sparse_array_int32_create @MANGLE_PREFIX@opj_sparse_array_int32_create -#define opj_sparse_array_int32_free @MANGLE_PREFIX@opj_sparse_array_int32_free -#define opj_sparse_array_int32_read @MANGLE_PREFIX@opj_sparse_array_int32_read -#define opj_sparse_array_int32_write @MANGLE_PREFIX@opj_sparse_array_int32_write -#define opj_sparse_array_is_region_valid @MANGLE_PREFIX@opj_sparse_array_is_region_valid +#define j2k_destroy_cstr_index @MANGLE_PREFIX@_j2k_destroy_cstr_index +#define j2k_dump @MANGLE_PREFIX@_j2k_dump +#define j2k_dump_image_comp_header @MANGLE_PREFIX@_j2k_dump_image_comp_header +#define j2k_dump_image_header @MANGLE_PREFIX@_j2k_dump_image_header +#define j2k_get_cstr_index @MANGLE_PREFIX@_j2k_get_cstr_index +#define j2k_get_cstr_info @MANGLE_PREFIX@_j2k_get_cstr_info +#define jp2_dump @MANGLE_PREFIX@_jp2_dump +#define jp2_get_cstr_index @MANGLE_PREFIX@_jp2_get_cstr_index +#define jp2_get_cstr_info @MANGLE_PREFIX@_jp2_get_cstr_info +#define opj_aligned_32_malloc @MANGLE_PREFIX@_opj_aligned_32_malloc +#define opj_aligned_32_realloc @MANGLE_PREFIX@_opj_aligned_32_realloc +#define opj_aligned_free @MANGLE_PREFIX@_opj_aligned_free +#define opj_aligned_malloc @MANGLE_PREFIX@_opj_aligned_malloc +#define opj_aligned_realloc @MANGLE_PREFIX@_opj_aligned_realloc +#define opj_alloc_tile_component_data @MANGLE_PREFIX@_opj_alloc_tile_component_data +#define opj_bio_create @MANGLE_PREFIX@_opj_bio_create +#define opj_bio_destroy @MANGLE_PREFIX@_opj_bio_destroy +#define opj_bio_flush @MANGLE_PREFIX@_opj_bio_flush +#define opj_bio_inalign @MANGLE_PREFIX@_opj_bio_inalign +#define opj_bio_init_dec @MANGLE_PREFIX@_opj_bio_init_dec +#define opj_bio_init_enc @MANGLE_PREFIX@_opj_bio_init_enc +#define opj_bio_numbytes @MANGLE_PREFIX@_opj_bio_numbytes +#define opj_bio_putbit @MANGLE_PREFIX@_opj_bio_putbit +#define opj_bio_read @MANGLE_PREFIX@_opj_bio_read +#define opj_bio_write @MANGLE_PREFIX@_opj_bio_write +#define opj_calculate_norms @MANGLE_PREFIX@_opj_calculate_norms +#define opj_calloc @MANGLE_PREFIX@_opj_calloc +#define opj_clock @MANGLE_PREFIX@_opj_clock +#define opj_codec_set_threads @MANGLE_PREFIX@_opj_codec_set_threads +#define opj_cond_create @MANGLE_PREFIX@_opj_cond_create +#define opj_cond_destroy @MANGLE_PREFIX@_opj_cond_destroy +#define opj_cond_signal @MANGLE_PREFIX@_opj_cond_signal +#define opj_cond_wait @MANGLE_PREFIX@_opj_cond_wait +#define opj_copy_image_header @MANGLE_PREFIX@_opj_copy_image_header +#define opj_create_compress @MANGLE_PREFIX@_opj_create_compress +#define opj_create_decompress @MANGLE_PREFIX@_opj_create_decompress +#define opj_decode @MANGLE_PREFIX@_opj_decode +#define opj_decode_tile_data @MANGLE_PREFIX@_opj_decode_tile_data +#define opj_decoder_set_strict_mode @MANGLE_PREFIX@_opj_decoder_set_strict_mode +#define opj_destroy_codec @MANGLE_PREFIX@_opj_destroy_codec +#define opj_destroy_cstr_index @MANGLE_PREFIX@_opj_destroy_cstr_index +#define opj_destroy_cstr_info @MANGLE_PREFIX@_opj_destroy_cstr_info +#define opj_dump_codec @MANGLE_PREFIX@_opj_dump_codec +#define opj_dwt_calc_explicit_stepsizes @MANGLE_PREFIX@_opj_dwt_calc_explicit_stepsizes +#define opj_dwt_decode @MANGLE_PREFIX@_opj_dwt_decode +#define opj_dwt_decode_real @MANGLE_PREFIX@_opj_dwt_decode_real +#define opj_dwt_encode @MANGLE_PREFIX@_opj_dwt_encode +#define opj_dwt_encode_real @MANGLE_PREFIX@_opj_dwt_encode_real +#define opj_dwt_getnorm @MANGLE_PREFIX@_opj_dwt_getnorm +#define opj_dwt_getnorm_real @MANGLE_PREFIX@_opj_dwt_getnorm_real +#define opj_encode @MANGLE_PREFIX@_opj_encode +#define opj_encoder_set_extra_options @MANGLE_PREFIX@_opj_encoder_set_extra_options +#define opj_end_compress @MANGLE_PREFIX@_opj_end_compress +#define opj_end_decompress @MANGLE_PREFIX@_opj_end_decompress +#define opj_event_msg @MANGLE_PREFIX@_opj_event_msg +#define opj_free @MANGLE_PREFIX@_opj_free +#define opj_get_cstr_index @MANGLE_PREFIX@_opj_get_cstr_index +#define opj_get_cstr_info @MANGLE_PREFIX@_opj_get_cstr_info +#define opj_get_decoded_tile @MANGLE_PREFIX@_opj_get_decoded_tile +#define opj_get_encoding_packet_count @MANGLE_PREFIX@_opj_get_encoding_packet_count +#define opj_get_num_cpus @MANGLE_PREFIX@_opj_get_num_cpus +#define opj_has_thread_support @MANGLE_PREFIX@_opj_has_thread_support +#define opj_image_comp_header_update @MANGLE_PREFIX@_opj_image_comp_header_update +#define opj_image_create @MANGLE_PREFIX@_opj_image_create +#define opj_image_create0 @MANGLE_PREFIX@_opj_image_create0 +#define opj_image_data_alloc @MANGLE_PREFIX@_opj_image_data_alloc +#define opj_image_data_free @MANGLE_PREFIX@_opj_image_data_free +#define opj_image_destroy @MANGLE_PREFIX@_opj_image_destroy +#define opj_image_tile_create @MANGLE_PREFIX@_opj_image_tile_create +#define opj_j2k_convert_progression_order @MANGLE_PREFIX@_opj_j2k_convert_progression_order +#define opj_j2k_create_compress @MANGLE_PREFIX@_opj_j2k_create_compress +#define opj_j2k_create_decompress @MANGLE_PREFIX@_opj_j2k_create_decompress +#define opj_j2k_decode @MANGLE_PREFIX@_opj_j2k_decode +#define opj_j2k_decode_tile @MANGLE_PREFIX@_opj_j2k_decode_tile +#define opj_j2k_decoder_set_strict_mode @MANGLE_PREFIX@_opj_j2k_decoder_set_strict_mode +#define opj_j2k_destroy @MANGLE_PREFIX@_opj_j2k_destroy +#define opj_j2k_encode @MANGLE_PREFIX@_opj_j2k_encode +#define opj_j2k_encoder_set_extra_options @MANGLE_PREFIX@_opj_j2k_encoder_set_extra_options +#define opj_j2k_end_compress @MANGLE_PREFIX@_opj_j2k_end_compress +#define opj_j2k_end_decompress @MANGLE_PREFIX@_opj_j2k_end_decompress +#define opj_j2k_get_tile @MANGLE_PREFIX@_opj_j2k_get_tile +#define opj_j2k_read_header @MANGLE_PREFIX@_opj_j2k_read_header +#define opj_j2k_read_tile_header @MANGLE_PREFIX@_opj_j2k_read_tile_header +#define opj_j2k_set_decode_area @MANGLE_PREFIX@_opj_j2k_set_decode_area +#define opj_j2k_set_decoded_components @MANGLE_PREFIX@_opj_j2k_set_decoded_components +#define opj_j2k_set_decoded_resolution_factor @MANGLE_PREFIX@_opj_j2k_set_decoded_resolution_factor +#define opj_j2k_set_threads @MANGLE_PREFIX@_opj_j2k_set_threads +#define opj_j2k_setup_decoder @MANGLE_PREFIX@_opj_j2k_setup_decoder +#define opj_j2k_setup_encoder @MANGLE_PREFIX@_opj_j2k_setup_encoder +#define opj_j2k_setup_mct_encoding @MANGLE_PREFIX@_opj_j2k_setup_mct_encoding +#define opj_j2k_start_compress @MANGLE_PREFIX@_opj_j2k_start_compress +#define opj_j2k_write_tile @MANGLE_PREFIX@_opj_j2k_write_tile +#define opj_jp2_create @MANGLE_PREFIX@_opj_jp2_create +#define opj_jp2_decode @MANGLE_PREFIX@_opj_jp2_decode +#define opj_jp2_decode_tile @MANGLE_PREFIX@_opj_jp2_decode_tile +#define opj_jp2_decoder_set_strict_mode @MANGLE_PREFIX@_opj_jp2_decoder_set_strict_mode +#define opj_jp2_destroy @MANGLE_PREFIX@_opj_jp2_destroy +#define opj_jp2_encode @MANGLE_PREFIX@_opj_jp2_encode +#define opj_jp2_encoder_set_extra_options @MANGLE_PREFIX@_opj_jp2_encoder_set_extra_options +#define opj_jp2_end_compress @MANGLE_PREFIX@_opj_jp2_end_compress +#define opj_jp2_end_decompress @MANGLE_PREFIX@_opj_jp2_end_decompress +#define opj_jp2_get_tile @MANGLE_PREFIX@_opj_jp2_get_tile +#define opj_jp2_read_header @MANGLE_PREFIX@_opj_jp2_read_header +#define opj_jp2_read_tile_header @MANGLE_PREFIX@_opj_jp2_read_tile_header +#define opj_jp2_set_decode_area @MANGLE_PREFIX@_opj_jp2_set_decode_area +#define opj_jp2_set_decoded_components @MANGLE_PREFIX@_opj_jp2_set_decoded_components +#define opj_jp2_set_decoded_resolution_factor @MANGLE_PREFIX@_opj_jp2_set_decoded_resolution_factor +#define opj_jp2_set_threads @MANGLE_PREFIX@_opj_jp2_set_threads +#define opj_jp2_setup_decoder @MANGLE_PREFIX@_opj_jp2_setup_decoder +#define opj_jp2_setup_encoder @MANGLE_PREFIX@_opj_jp2_setup_encoder +#define opj_jp2_start_compress @MANGLE_PREFIX@_opj_jp2_start_compress +#define opj_jp2_write_tile @MANGLE_PREFIX@_opj_jp2_write_tile +#define opj_malloc @MANGLE_PREFIX@_opj_malloc +#define opj_matrix_inversion_f @MANGLE_PREFIX@_opj_matrix_inversion_f +#define opj_mct_decode @MANGLE_PREFIX@_opj_mct_decode +#define opj_mct_decode_custom @MANGLE_PREFIX@_opj_mct_decode_custom +#define opj_mct_decode_real @MANGLE_PREFIX@_opj_mct_decode_real +#define opj_mct_encode @MANGLE_PREFIX@_opj_mct_encode +#define opj_mct_encode_custom @MANGLE_PREFIX@_opj_mct_encode_custom +#define opj_mct_encode_real @MANGLE_PREFIX@_opj_mct_encode_real +#define opj_mct_get_mct_norms @MANGLE_PREFIX@_opj_mct_get_mct_norms +#define opj_mct_get_mct_norms_real @MANGLE_PREFIX@_opj_mct_get_mct_norms_real +#define opj_mct_getnorm @MANGLE_PREFIX@_opj_mct_getnorm +#define opj_mct_getnorm_real @MANGLE_PREFIX@_opj_mct_getnorm_real +#define opj_mqc_bypass_enc @MANGLE_PREFIX@_opj_mqc_bypass_enc +#define opj_mqc_bypass_flush_enc @MANGLE_PREFIX@_opj_mqc_bypass_flush_enc +#define opj_mqc_bypass_get_extra_bytes @MANGLE_PREFIX@_opj_mqc_bypass_get_extra_bytes +#define opj_mqc_bypass_init_enc @MANGLE_PREFIX@_opj_mqc_bypass_init_enc +#define opj_mqc_byteout @MANGLE_PREFIX@_opj_mqc_byteout +#define opj_mqc_erterm_enc @MANGLE_PREFIX@_opj_mqc_erterm_enc +#define opj_mqc_flush @MANGLE_PREFIX@_opj_mqc_flush +#define opj_mqc_init_dec @MANGLE_PREFIX@_opj_mqc_init_dec +#define opj_mqc_init_enc @MANGLE_PREFIX@_opj_mqc_init_enc +#define opj_mqc_numbytes @MANGLE_PREFIX@_opj_mqc_numbytes +#define opj_mqc_raw_init_dec @MANGLE_PREFIX@_opj_mqc_raw_init_dec +#define opj_mqc_reset_enc @MANGLE_PREFIX@_opj_mqc_reset_enc +#define opj_mqc_resetstates @MANGLE_PREFIX@_opj_mqc_resetstates +#define opj_mqc_restart_init_enc @MANGLE_PREFIX@_opj_mqc_restart_init_enc +#define opj_mqc_segmark_enc @MANGLE_PREFIX@_opj_mqc_segmark_enc +#define opj_mqc_setstate @MANGLE_PREFIX@_opj_mqc_setstate +#define opj_mutex_create @MANGLE_PREFIX@_opj_mutex_create +#define opj_mutex_destroy @MANGLE_PREFIX@_opj_mutex_destroy +#define opj_mutex_lock @MANGLE_PREFIX@_opj_mutex_lock +#define opj_mutex_unlock @MANGLE_PREFIX@_opj_mutex_unlock +#define opj_pi_create_decode @MANGLE_PREFIX@_opj_pi_create_decode +#define opj_pi_create_encode @MANGLE_PREFIX@_opj_pi_create_encode +#define opj_pi_destroy @MANGLE_PREFIX@_opj_pi_destroy +#define opj_pi_initialise_encode @MANGLE_PREFIX@_opj_pi_initialise_encode +#define opj_pi_next @MANGLE_PREFIX@_opj_pi_next +#define opj_pi_update_encoding_parameters @MANGLE_PREFIX@_opj_pi_update_encoding_parameters +#define opj_procedure_list_add_procedure @MANGLE_PREFIX@_opj_procedure_list_add_procedure +#define opj_procedure_list_clear @MANGLE_PREFIX@_opj_procedure_list_clear +#define opj_procedure_list_create @MANGLE_PREFIX@_opj_procedure_list_create +#define opj_procedure_list_destroy @MANGLE_PREFIX@_opj_procedure_list_destroy +#define opj_procedure_list_get_first_procedure @MANGLE_PREFIX@_opj_procedure_list_get_first_procedure +#define opj_procedure_list_get_nb_procedures @MANGLE_PREFIX@_opj_procedure_list_get_nb_procedures +#define opj_read_bytes_BE @MANGLE_PREFIX@_opj_read_bytes_BE +#define opj_read_bytes_LE @MANGLE_PREFIX@_opj_read_bytes_LE +#define opj_read_double_BE @MANGLE_PREFIX@_opj_read_double_BE +#define opj_read_double_LE @MANGLE_PREFIX@_opj_read_double_LE +#define opj_read_float_BE @MANGLE_PREFIX@_opj_read_float_BE +#define opj_read_float_LE @MANGLE_PREFIX@_opj_read_float_LE +#define opj_read_header @MANGLE_PREFIX@_opj_read_header +#define opj_read_tile_header @MANGLE_PREFIX@_opj_read_tile_header +#define opj_realloc @MANGLE_PREFIX@_opj_realloc +#define opj_set_MCT @MANGLE_PREFIX@_opj_set_MCT +#define opj_set_decode_area @MANGLE_PREFIX@_opj_set_decode_area +#define opj_set_decoded_components @MANGLE_PREFIX@_opj_set_decoded_components +#define opj_set_decoded_resolution_factor @MANGLE_PREFIX@_opj_set_decoded_resolution_factor +#define opj_set_default_decoder_parameters @MANGLE_PREFIX@_opj_set_default_decoder_parameters +#define opj_set_default_encoder_parameters @MANGLE_PREFIX@_opj_set_default_encoder_parameters +#define opj_set_default_event_handler @MANGLE_PREFIX@_opj_set_default_event_handler +#define opj_set_error_handler @MANGLE_PREFIX@_opj_set_error_handler +#define opj_set_info_handler @MANGLE_PREFIX@_opj_set_info_handler +#define opj_set_warning_handler @MANGLE_PREFIX@_opj_set_warning_handler +#define opj_setup_decoder @MANGLE_PREFIX@_opj_setup_decoder +#define opj_setup_encoder @MANGLE_PREFIX@_opj_setup_encoder +#define opj_sparse_array_int32_create @MANGLE_PREFIX@_opj_sparse_array_int32_create +#define opj_sparse_array_int32_free @MANGLE_PREFIX@_opj_sparse_array_int32_free +#define opj_sparse_array_int32_read @MANGLE_PREFIX@_opj_sparse_array_int32_read +#define opj_sparse_array_int32_write @MANGLE_PREFIX@_opj_sparse_array_int32_write +#define opj_sparse_array_is_region_valid @MANGLE_PREFIX@_opj_sparse_array_is_region_valid +#define opj_start_compress @MANGLE_PREFIX@_opj_start_compress +#define opj_stream_create @MANGLE_PREFIX@_opj_stream_create +#define opj_stream_create_default_file_stream @MANGLE_PREFIX@_opj_stream_create_default_file_stream +#define opj_stream_create_file_stream @MANGLE_PREFIX@_opj_stream_create_file_stream +#define opj_stream_default_create @MANGLE_PREFIX@_opj_stream_default_create +#define opj_stream_default_read @MANGLE_PREFIX@_opj_stream_default_read +#define opj_stream_default_seek @MANGLE_PREFIX@_opj_stream_default_seek +#define opj_stream_default_skip @MANGLE_PREFIX@_opj_stream_default_skip +#define opj_stream_default_write @MANGLE_PREFIX@_opj_stream_default_write +#define opj_stream_destroy @MANGLE_PREFIX@_opj_stream_destroy +#define opj_stream_flush @MANGLE_PREFIX@_opj_stream_flush +#define opj_stream_get_number_byte_left @MANGLE_PREFIX@_opj_stream_get_number_byte_left +#define opj_stream_has_seek @MANGLE_PREFIX@_opj_stream_has_seek +#define opj_stream_read_data @MANGLE_PREFIX@_opj_stream_read_data +#define opj_stream_read_seek @MANGLE_PREFIX@_opj_stream_read_seek +#define opj_stream_read_skip @MANGLE_PREFIX@_opj_stream_read_skip +#define opj_stream_seek @MANGLE_PREFIX@_opj_stream_seek +#define opj_stream_set_read_function @MANGLE_PREFIX@_opj_stream_set_read_function +#define opj_stream_set_seek_function @MANGLE_PREFIX@_opj_stream_set_seek_function +#define opj_stream_set_skip_function @MANGLE_PREFIX@_opj_stream_set_skip_function +#define opj_stream_set_user_data @MANGLE_PREFIX@_opj_stream_set_user_data +#define opj_stream_set_user_data_length @MANGLE_PREFIX@_opj_stream_set_user_data_length +#define opj_stream_set_write_function @MANGLE_PREFIX@_opj_stream_set_write_function +#define opj_stream_skip @MANGLE_PREFIX@_opj_stream_skip +#define opj_stream_tell @MANGLE_PREFIX@_opj_stream_tell +#define opj_stream_write_data @MANGLE_PREFIX@_opj_stream_write_data +#define opj_stream_write_seek @MANGLE_PREFIX@_opj_stream_write_seek +#define opj_stream_write_skip @MANGLE_PREFIX@_opj_stream_write_skip +#define opj_t1_create @MANGLE_PREFIX@_opj_t1_create +#define opj_t1_decode_cblks @MANGLE_PREFIX@_opj_t1_decode_cblks +#define opj_t1_destroy @MANGLE_PREFIX@_opj_t1_destroy +#define opj_t1_encode_cblks @MANGLE_PREFIX@_opj_t1_encode_cblks +#define opj_t1_ht_decode_cblk @MANGLE_PREFIX@_opj_t1_ht_decode_cblk +#define opj_t2_create @MANGLE_PREFIX@_opj_t2_create +#define opj_t2_decode_packets @MANGLE_PREFIX@_opj_t2_decode_packets +#define opj_t2_destroy @MANGLE_PREFIX@_opj_t2_destroy +#define opj_t2_encode_packets @MANGLE_PREFIX@_opj_t2_encode_packets +#define opj_tcd_copy_tile_data @MANGLE_PREFIX@_opj_tcd_copy_tile_data +#define opj_tcd_create @MANGLE_PREFIX@_opj_tcd_create +#define opj_tcd_decode_tile @MANGLE_PREFIX@_opj_tcd_decode_tile +#define opj_tcd_destroy @MANGLE_PREFIX@_opj_tcd_destroy +#define opj_tcd_encode_tile @MANGLE_PREFIX@_opj_tcd_encode_tile +#define opj_tcd_get_decoded_tile_size @MANGLE_PREFIX@_opj_tcd_get_decoded_tile_size +#define opj_tcd_get_encoder_input_buffer_size @MANGLE_PREFIX@_opj_tcd_get_encoder_input_buffer_size +#define opj_tcd_init @MANGLE_PREFIX@_opj_tcd_init +#define opj_tcd_init_decode_tile @MANGLE_PREFIX@_opj_tcd_init_decode_tile +#define opj_tcd_init_encode_tile @MANGLE_PREFIX@_opj_tcd_init_encode_tile +#define opj_tcd_is_band_empty @MANGLE_PREFIX@_opj_tcd_is_band_empty +#define opj_tcd_is_subband_area_of_interest @MANGLE_PREFIX@_opj_tcd_is_subband_area_of_interest +#define opj_tcd_marker_info_create @MANGLE_PREFIX@_opj_tcd_marker_info_create +#define opj_tcd_marker_info_destroy @MANGLE_PREFIX@_opj_tcd_marker_info_destroy +#define opj_tcd_reinit_segment @MANGLE_PREFIX@_opj_tcd_reinit_segment +#define opj_tcd_update_tile_data @MANGLE_PREFIX@_opj_tcd_update_tile_data +#define opj_tgt_create @MANGLE_PREFIX@_opj_tgt_create +#define opj_tgt_decode @MANGLE_PREFIX@_opj_tgt_decode +#define opj_tgt_destroy @MANGLE_PREFIX@_opj_tgt_destroy +#define opj_tgt_encode @MANGLE_PREFIX@_opj_tgt_encode +#define opj_tgt_init @MANGLE_PREFIX@_opj_tgt_init +#define opj_tgt_reset @MANGLE_PREFIX@_opj_tgt_reset +#define opj_tgt_setvalue @MANGLE_PREFIX@_opj_tgt_setvalue +#define opj_thread_create @MANGLE_PREFIX@_opj_thread_create +#define opj_thread_join @MANGLE_PREFIX@_opj_thread_join +#define opj_thread_pool_create @MANGLE_PREFIX@_opj_thread_pool_create +#define opj_thread_pool_destroy @MANGLE_PREFIX@_opj_thread_pool_destroy +#define opj_thread_pool_get_thread_count @MANGLE_PREFIX@_opj_thread_pool_get_thread_count +#define opj_thread_pool_submit_job @MANGLE_PREFIX@_opj_thread_pool_submit_job +#define opj_thread_pool_wait_completion @MANGLE_PREFIX@_opj_thread_pool_wait_completion +#define opj_tls_get @MANGLE_PREFIX@_opj_tls_get +#define opj_tls_set @MANGLE_PREFIX@_opj_tls_set +#define opj_version @MANGLE_PREFIX@_opj_version +#define opj_write_bytes_BE @MANGLE_PREFIX@_opj_write_bytes_BE +#define opj_write_bytes_LE @MANGLE_PREFIX@_opj_write_bytes_LE +#define opj_write_double_BE @MANGLE_PREFIX@_opj_write_double_BE +#define opj_write_double_LE @MANGLE_PREFIX@_opj_write_double_LE +#define opj_write_float_BE @MANGLE_PREFIX@_opj_write_float_BE +#define opj_write_float_LE @MANGLE_PREFIX@_opj_write_float_LE +#define opj_write_tile @MANGLE_PREFIX@_opj_write_tile +#define opq_mqc_finish_dec @MANGLE_PREFIX@_opq_mqc_finish_dec + #endif diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_codec.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_codec.h index b962b121633..7cff6708246 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_codec.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_codec.h @@ -90,6 +90,9 @@ typedef struct opj_codec_private { /** Setup decoder function handler */ void (*opj_setup_decoder)(void * p_codec, opj_dparameters_t * p_param); + /** Strict mode function handler */ + void (*opj_decoder_set_strict_mode)(void * p_codec, OPJ_BOOL strict); + /** Set decode area function handler */ OPJ_BOOL(*opj_set_decode_area)(void * p_codec, opj_image_t * p_image, @@ -148,6 +151,11 @@ typedef struct opj_codec_private { opj_cparameters_t * p_param, struct opj_image * p_image, struct opj_event_mgr * p_manager); + + OPJ_BOOL(* opj_encoder_set_extra_options)(void * p_codec, + const char* const* p_options, + struct opj_event_mgr * p_manager); + } m_compression; } m_codec_data; /** FIXME DOC*/ diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_common.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_common.h index a051339154b..2923a35b7fe 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_common.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_common.h @@ -28,8 +28,8 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef OPJ_COMMMON_H -#define OPJ_COMMMON_H +#ifndef OPJ_COMMON_H +#define OPJ_COMMON_H /* ========================================================== @@ -38,4 +38,10 @@ */ #define OPJ_COMMON_CBLK_DATA_EXTRA 2 /**< Margin for a fake FFFF marker */ -#endif /* OPJ_COMMMON_H */ + +#define OPJ_COMP_PARAM_DEFAULT_CBLOCKW 64 +#define OPJ_COMP_PARAM_DEFAULT_CBLOCKH 64 +#define OPJ_COMP_PARAM_DEFAULT_PROG_ORDER OPJ_LRCP +#define OPJ_COMP_PARAM_DEFAULT_NUMRESOLUTION 6 + +#endif /* OPJ_COMMON_H */ diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_config.h.cmake.in b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_config.h.cmake.in index 5f762ca3daa..64884b65248 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_config.h.cmake.in +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_config.h.cmake.in @@ -1,5 +1,7 @@ +#ifndef OPJ_CONFIG_H_INCLUDED +#define OPJ_CONFIG_H_INCLUDED + /* create opj_config.h for CMake */ -#cmakedefine OPJ_HAVE_STDINT_H @OPJ_HAVE_STDINT_H@ /*--------------------------------------------------------------------------*/ /* OpenJPEG Versioning */ @@ -8,3 +10,5 @@ #define OPJ_VERSION_MAJOR @OPENJPEG_VERSION_MAJOR@ #define OPJ_VERSION_MINOR @OPENJPEG_VERSION_MINOR@ #define OPJ_VERSION_BUILD @OPENJPEG_VERSION_BUILD@ + +#endif diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_config_private.h.cmake.in b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_config_private.h.cmake.in index c41f9066242..c559282c578 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_config_private.h.cmake.in +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_config_private.h.cmake.in @@ -1,5 +1,4 @@ /* create opj_config_private.h for CMake */ -#cmakedefine OPJ_HAVE_INTTYPES_H @OPJ_HAVE_INTTYPES_H@ #define OPJ_PACKAGE_VERSION "@PACKAGE_VERSION@" @@ -11,6 +10,8 @@ /*#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@*/ /*#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ */ /*#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@*/ +/*#cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@ */ +/*#cmakedefine HAVE_STDINT_H @HAVE_STDINT_H@ */ #cmakedefine _LARGEFILE_SOURCE #cmakedefine _LARGE_FILES diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_includes.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_includes.h index 0a8628c96b3..13613ce521c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_includes.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_includes.h @@ -55,6 +55,8 @@ #include #include #include +#include +#include /* Use fseeko() and ftello() if they are available since they use @@ -218,7 +220,6 @@ typedef unsigned int OPJ_BITFIELD; #define OPJ_UNUSED(x) (void)x -#include "opj_inttypes.h" #include "opj_clock.h" #include "opj_malloc.h" #include "event.h" diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_intmath.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_intmath.h index ad135976613..cce7a3cafa7 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_intmath.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_intmath.h @@ -170,7 +170,18 @@ Divide an integer and round upwards static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) { assert(b); - return (a + b - 1) / b; + return (OPJ_UINT32)(((OPJ_UINT64)a + b - 1) / b); +} + +/** +Divide an integer and round upwards +@return Returns a divided by b +*/ +static INLINE OPJ_UINT32 opj_uint64_ceildiv_res_uint32(OPJ_UINT64 a, + OPJ_UINT64 b) +{ + assert(b); + return (OPJ_UINT32)((a + b - 1) / b); } /** @@ -208,6 +219,16 @@ static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b) { return a >> b; } + +/** +Divide an integer by a power of 2 and round downwards +@return Returns a divided by 2^b +*/ +static INLINE OPJ_UINT32 opj_uint_floordivpow2(OPJ_UINT32 a, OPJ_UINT32 b) +{ + return a >> b; +} + /** Get logarithm of an integer and round downwards @return Returns log2(a) @@ -266,6 +287,44 @@ static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b) return (OPJ_INT32)(temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) ; } +/** +Addition two signed integers with a wrap-around behaviour. +Assumes complement-to-two signed integers. +@param a +@param b +@return Returns a + b +*/ +static INLINE OPJ_INT32 opj_int_add_no_overflow(OPJ_INT32 a, OPJ_INT32 b) +{ + void* pa = &a; + void* pb = &b; + OPJ_UINT32* upa = (OPJ_UINT32*)pa; + OPJ_UINT32* upb = (OPJ_UINT32*)pb; + OPJ_UINT32 ures = *upa + *upb; + void* pures = &ures; + OPJ_INT32* ipres = (OPJ_INT32*)pures; + return *ipres; +} + +/** +Subtract two signed integers with a wrap-around behaviour. +Assumes complement-to-two signed integers. +@param a +@param b +@return Returns a - b +*/ +static INLINE OPJ_INT32 opj_int_sub_no_overflow(OPJ_INT32 a, OPJ_INT32 b) +{ + void* pa = &a; + void* pb = &b; + OPJ_UINT32* upa = (OPJ_UINT32*)pa; + OPJ_UINT32* upb = (OPJ_UINT32*)pb; + OPJ_UINT32 ures = *upa - *upb; + void* pures = &ures; + OPJ_INT32* ipres = (OPJ_INT32*)pures; + return *ipres; +} + /* ----------------------------------------------------------------------- */ /*@}*/ diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_stdint.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_stdint.h deleted file mode 100644 index f26c921c253..00000000000 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/opj_stdint.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The copyright in this software is being made available under the 2-clauses - * BSD License, included below. This software may be subject to other third - * party and contributor rights, including patent rights, and no such rights - * are granted under this license. - * - * Copyright (c) 2012, Mathieu Malaterre - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef OPJ_STDINT_H -#define OPJ_STDINT_H - -#include "opj_config.h" -#ifdef OPJ_HAVE_STDINT_H -#include -#else -#if defined(_WIN32) -typedef signed __int8 int8_t; -typedef unsigned __int8 uint8_t; -typedef signed __int16 int16_t; -typedef unsigned __int16 uint16_t; -typedef signed __int32 int32_t; -typedef unsigned __int32 uint32_t; -typedef signed __int64 int64_t; -typedef unsigned __int64 uint64_t; -#else -#error unsupported platform -#endif -#endif - -#endif /* OPJ_STDINT_H */ diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/pi.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/pi.c index 91642ee4eaf..15ac331425d 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/pi.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/pi.c @@ -36,6 +36,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#define OPJ_UINT32_SEMANTICALLY_BUT_INT32 OPJ_UINT32 + #include "opj_includes.h" /** @defgroup PI PI - Implementation of a packet iterator */ @@ -91,10 +93,10 @@ static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi); */ static void opj_pi_update_encode_poc_and_final(opj_cp_t *p_cp, OPJ_UINT32 p_tileno, - OPJ_INT32 p_tx0, - OPJ_INT32 p_tx1, - OPJ_INT32 p_ty0, - OPJ_INT32 p_ty1, + OPJ_UINT32 p_tx0, + OPJ_UINT32 p_tx1, + OPJ_UINT32 p_ty0, + OPJ_UINT32 p_ty1, OPJ_UINT32 p_max_prec, OPJ_UINT32 p_max_res, OPJ_UINT32 p_dx_min, @@ -118,10 +120,10 @@ static void opj_pi_update_encode_poc_and_final(opj_cp_t *p_cp, static void opj_pi_update_encode_not_poc(opj_cp_t *p_cp, OPJ_UINT32 p_num_comps, OPJ_UINT32 p_tileno, - OPJ_INT32 p_tx0, - OPJ_INT32 p_tx1, - OPJ_INT32 p_ty0, - OPJ_INT32 p_ty1, + OPJ_UINT32 p_tx0, + OPJ_UINT32 p_tx1, + OPJ_UINT32 p_ty0, + OPJ_UINT32 p_ty1, OPJ_UINT32 p_max_prec, OPJ_UINT32 p_max_res, OPJ_UINT32 p_dx_min, @@ -144,10 +146,10 @@ static void opj_pi_update_encode_not_poc(opj_cp_t *p_cp, static void opj_get_encoding_parameters(const opj_image_t *p_image, const opj_cp_t *p_cp, OPJ_UINT32 tileno, - OPJ_INT32 * p_tx0, - OPJ_INT32 * p_tx1, - OPJ_INT32 * p_ty0, - OPJ_INT32 * p_ty1, + OPJ_UINT32 * p_tx0, + OPJ_UINT32 * p_tx1, + OPJ_UINT32 * p_ty0, + OPJ_UINT32 * p_ty1, OPJ_UINT32 * p_dx_min, OPJ_UINT32 * p_dy_min, OPJ_UINT32 * p_max_prec, @@ -176,10 +178,10 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image, static void opj_get_all_encoding_parameters(const opj_image_t *p_image, const opj_cp_t *p_cp, OPJ_UINT32 tileno, - OPJ_INT32 * p_tx0, - OPJ_INT32 * p_tx1, - OPJ_INT32 * p_ty0, - OPJ_INT32 * p_ty1, + OPJ_UINT32 * p_tx0, + OPJ_UINT32 * p_tx1, + OPJ_UINT32 * p_ty0, + OPJ_UINT32 * p_ty1, OPJ_UINT32 * p_dx_min, OPJ_UINT32 * p_dy_min, OPJ_UINT32 * p_max_prec, @@ -192,10 +194,12 @@ static void opj_get_all_encoding_parameters(const opj_image_t *p_image, * @param p_image the image used to initialize the packet iterator (in fact only the number of components is relevant. * @param p_cp the coding parameters. * @param tileno the index of the tile from which creating the packet iterator. + * @param manager Event manager */ static opj_pi_iterator_t * opj_pi_create(const opj_image_t *p_image, const opj_cp_t *p_cp, - OPJ_UINT32 tileno); + OPJ_UINT32 tileno, + opj_event_mgr_t* manager); /** * FIXME DOC */ @@ -230,18 +234,19 @@ static OPJ_BOOL opj_pi_check_next_level(OPJ_INT32 pos, ========================================================== */ -static void opj_pi_emit_error(opj_pi_iterator_t * pi, const char* msg) -{ - (void)pi; - (void)msg; -} - static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; + if (pi->poc.compno0 >= pi->numcomps || + pi->poc.compno1 >= pi->numcomps + 1) { + opj_event_msg(pi->manager, EVT_ERROR, + "opj_pi_next_lrcp(): invalid compno0/compno1\n"); + return OPJ_FALSE; + } + if (!pi->first) { comp = &pi->comps[pi->compno]; res = &comp->resolutions[pi->resno]; @@ -272,7 +277,7 @@ static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi) /* include should be resized when a POC arises, or */ /* the POC should be rejected */ if (index >= pi->include_size) { - opj_pi_emit_error(pi, "Invalid access to pi->include"); + opj_event_msg(pi->manager, EVT_ERROR, "Invalid access to pi->include"); return OPJ_FALSE; } if (!pi->include[index]) { @@ -295,6 +300,13 @@ static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi) opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; + if (pi->poc.compno0 >= pi->numcomps || + pi->poc.compno1 >= pi->numcomps + 1) { + opj_event_msg(pi->manager, EVT_ERROR, + "opj_pi_next_rlcp(): invalid compno0/compno1\n"); + return OPJ_FALSE; + } + if (!pi->first) { comp = &pi->comps[pi->compno]; res = &comp->resolutions[pi->resno]; @@ -318,7 +330,7 @@ static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi) index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; if (index >= pi->include_size) { - opj_pi_emit_error(pi, "Invalid access to pi->include"); + opj_event_msg(pi->manager, EVT_ERROR, "Invalid access to pi->include"); return OPJ_FALSE; } if (!pi->include[index]) { @@ -341,6 +353,13 @@ static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; + if (pi->poc.compno0 >= pi->numcomps || + pi->poc.compno1 >= pi->numcomps + 1) { + opj_event_msg(pi->manager, EVT_ERROR, + "opj_pi_next_rpcl(): invalid compno0/compno1\n"); + return OPJ_FALSE; + } + if (!pi->first) { goto LABEL_SKIP; } else { @@ -376,57 +395,53 @@ static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) pi->poc.tx1 = pi->tx1; } for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { - for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; - pi->y += (OPJ_INT32)(pi->dy - (OPJ_UINT32)(pi->y % (OPJ_INT32)pi->dy))) { - for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; - pi->x += (OPJ_INT32)(pi->dx - (OPJ_UINT32)(pi->x % (OPJ_INT32)pi->dx))) { + for (pi->y = (OPJ_UINT32)pi->poc.ty0; pi->y < (OPJ_UINT32)pi->poc.ty1; + pi->y += (pi->dy - (pi->y % pi->dy))) { + for (pi->x = (OPJ_UINT32)pi->poc.tx0; pi->x < (OPJ_UINT32)pi->poc.tx1; + pi->x += (pi->dx - (pi->x % pi->dx))) { for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { OPJ_UINT32 levelno; - OPJ_INT32 trx0, try0; - OPJ_INT32 trx1, try1; + OPJ_UINT32 trx0, try0; + OPJ_UINT32 trx1, try1; OPJ_UINT32 rpx, rpy; - OPJ_INT32 prci, prcj; + OPJ_UINT32 prci, prcj; comp = &pi->comps[pi->compno]; if (pi->resno >= comp->numresolutions) { continue; } res = &comp->resolutions[pi->resno]; levelno = comp->numresolutions - 1 - pi->resno; - /* Avoids division by zero */ - /* Relates to id_000004,sig_06,src_000679,op_arith8,pos_49,val_-17 */ - /* of https://github.com/uclouvain/openjpeg/issues/938 */ - if (levelno >= 32 || - ((comp->dx << levelno) >> levelno) != comp->dx || - ((comp->dy << levelno) >> levelno) != comp->dy) { - continue; - } - if ((comp->dx << levelno) > INT_MAX || - (comp->dy << levelno) > INT_MAX) { + + if ((OPJ_UINT32)(((OPJ_UINT64)comp->dx << levelno) >> levelno) != comp->dx || + (OPJ_UINT32)(((OPJ_UINT64)comp->dy << levelno) >> levelno) != comp->dy) { continue; } - trx0 = opj_int_ceildiv(pi->tx0, (OPJ_INT32)(comp->dx << levelno)); - try0 = opj_int_ceildiv(pi->ty0, (OPJ_INT32)(comp->dy << levelno)); - trx1 = opj_int_ceildiv(pi->tx1, (OPJ_INT32)(comp->dx << levelno)); - try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno)); + + trx0 = opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->tx0, + ((OPJ_UINT64)comp->dx << levelno)); + try0 = opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->ty0, + ((OPJ_UINT64)comp->dy << levelno)); + trx1 = opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->tx1, + ((OPJ_UINT64)comp->dx << levelno)); + try1 = opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->ty1, + ((OPJ_UINT64)comp->dy << levelno)); rpx = res->pdx + levelno; rpy = res->pdy + levelno; - /* To avoid divisions by zero / undefined behaviour on shift */ - /* in below tests */ - /* Fixes reading id:000026,sig:08,src:002419,op:int32,pos:60,val:+32 */ - /* of https://github.com/uclouvain/openjpeg/issues/938 */ - if (rpx >= 31 || ((comp->dx << rpx) >> rpx) != comp->dx || - rpy >= 31 || ((comp->dy << rpy) >> rpy) != comp->dy) { + if ((OPJ_UINT32)(((OPJ_UINT64)comp->dx << rpx) >> rpx) != comp->dx || + (OPJ_UINT32)(((OPJ_UINT64)comp->dy << rpy) >> rpy) != comp->dy) { continue; } /* See ISO-15441. B.12.1.3 Resolution level-position-component-layer progression */ - if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && - ((try0 << levelno) % (1 << rpy))))) { + if (!(((OPJ_UINT64)pi->y % ((OPJ_UINT64)comp->dy << rpy) == 0) || + ((pi->y == pi->ty0) && + (((OPJ_UINT64)try0 << levelno) % ((OPJ_UINT64)1U << rpy))))) { continue; } - if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && - ((trx0 << levelno) % (1 << rpx))))) { + if (!(((OPJ_UINT64)pi->x % ((OPJ_UINT64)comp->dx << rpx) == 0) || + ((pi->x == pi->tx0) && + (((OPJ_UINT64)trx0 << levelno) % ((OPJ_UINT64)1U << rpx))))) { continue; } @@ -438,18 +453,18 @@ static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) continue; } - prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, - (OPJ_INT32)(comp->dx << levelno)), (OPJ_INT32)res->pdx) - - opj_int_floordivpow2(trx0, (OPJ_INT32)res->pdx); - prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, - (OPJ_INT32)(comp->dy << levelno)), (OPJ_INT32)res->pdy) - - opj_int_floordivpow2(try0, (OPJ_INT32)res->pdy); - pi->precno = (OPJ_UINT32)(prci + prcj * (OPJ_INT32)res->pw); + prci = opj_uint_floordivpow2(opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->x, + ((OPJ_UINT64)comp->dx << levelno)), res->pdx) + - opj_uint_floordivpow2(trx0, res->pdx); + prcj = opj_uint_floordivpow2(opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->y, + ((OPJ_UINT64)comp->dy << levelno)), res->pdy) + - opj_uint_floordivpow2(try0, res->pdy); + pi->precno = prci + prcj * res->pw; for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; if (index >= pi->include_size) { - opj_pi_emit_error(pi, "Invalid access to pi->include"); + opj_event_msg(pi->manager, EVT_ERROR, "Invalid access to pi->include"); return OPJ_FALSE; } if (!pi->include[index]) { @@ -473,6 +488,13 @@ static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; + if (pi->poc.compno0 >= pi->numcomps || + pi->poc.compno1 >= pi->numcomps + 1) { + opj_event_msg(pi->manager, EVT_ERROR, + "opj_pi_next_pcrl(): invalid compno0/compno1\n"); + return OPJ_FALSE; + } + if (!pi->first) { comp = &pi->comps[pi->compno]; goto LABEL_SKIP; @@ -508,56 +530,52 @@ static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) pi->poc.ty1 = pi->ty1; pi->poc.tx1 = pi->tx1; } - for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; - pi->y += (OPJ_INT32)(pi->dy - (OPJ_UINT32)(pi->y % (OPJ_INT32)pi->dy))) { - for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; - pi->x += (OPJ_INT32)(pi->dx - (OPJ_UINT32)(pi->x % (OPJ_INT32)pi->dx))) { + for (pi->y = (OPJ_UINT32)pi->poc.ty0; pi->y < (OPJ_UINT32)pi->poc.ty1; + pi->y += (pi->dy - (pi->y % pi->dy))) { + for (pi->x = (OPJ_UINT32)pi->poc.tx0; pi->x < (OPJ_UINT32)pi->poc.tx1; + pi->x += (pi->dx - (pi->x % pi->dx))) { for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { comp = &pi->comps[pi->compno]; for (pi->resno = pi->poc.resno0; pi->resno < opj_uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) { OPJ_UINT32 levelno; - OPJ_INT32 trx0, try0; - OPJ_INT32 trx1, try1; + OPJ_UINT32 trx0, try0; + OPJ_UINT32 trx1, try1; OPJ_UINT32 rpx, rpy; - OPJ_INT32 prci, prcj; + OPJ_UINT32 prci, prcj; res = &comp->resolutions[pi->resno]; levelno = comp->numresolutions - 1 - pi->resno; - /* Avoids division by zero */ - /* Relates to id_000004,sig_06,src_000679,op_arith8,pos_49,val_-17 */ - /* of https://github.com/uclouvain/openjpeg/issues/938 */ - if (levelno >= 32 || - ((comp->dx << levelno) >> levelno) != comp->dx || - ((comp->dy << levelno) >> levelno) != comp->dy) { - continue; - } - if ((comp->dx << levelno) > INT_MAX || - (comp->dy << levelno) > INT_MAX) { + + if ((OPJ_UINT32)(((OPJ_UINT64)comp->dx << levelno) >> levelno) != comp->dx || + (OPJ_UINT32)(((OPJ_UINT64)comp->dy << levelno) >> levelno) != comp->dy) { continue; } - trx0 = opj_int_ceildiv(pi->tx0, (OPJ_INT32)(comp->dx << levelno)); - try0 = opj_int_ceildiv(pi->ty0, (OPJ_INT32)(comp->dy << levelno)); - trx1 = opj_int_ceildiv(pi->tx1, (OPJ_INT32)(comp->dx << levelno)); - try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno)); + + trx0 = opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->tx0, + ((OPJ_UINT64)comp->dx << levelno)); + try0 = opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->ty0, + ((OPJ_UINT64)comp->dy << levelno)); + trx1 = opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->tx1, + ((OPJ_UINT64)comp->dx << levelno)); + try1 = opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->ty1, + ((OPJ_UINT64)comp->dy << levelno)); rpx = res->pdx + levelno; rpy = res->pdy + levelno; - /* To avoid divisions by zero / undefined behaviour on shift */ - /* in below tests */ - /* Relates to id:000019,sig:08,src:001098,op:flip1,pos:49 */ - /* of https://github.com/uclouvain/openjpeg/issues/938 */ - if (rpx >= 31 || ((comp->dx << rpx) >> rpx) != comp->dx || - rpy >= 31 || ((comp->dy << rpy) >> rpy) != comp->dy) { + if ((OPJ_UINT32)(((OPJ_UINT64)comp->dx << rpx) >> rpx) != comp->dx || + (OPJ_UINT32)(((OPJ_UINT64)comp->dy << rpy) >> rpy) != comp->dy) { continue; } /* See ISO-15441. B.12.1.4 Position-component-resolution level-layer progression */ - if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && - ((try0 << levelno) % (1 << rpy))))) { + if (!(((OPJ_UINT64)pi->y % ((OPJ_UINT64)comp->dy << rpy) == 0) || + ((pi->y == pi->ty0) && + (((OPJ_UINT64)try0 << levelno) % ((OPJ_UINT64)1U << rpy))))) { continue; } - if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && - ((trx0 << levelno) % (1 << rpx))))) { + if (!(((OPJ_UINT64)pi->x % ((OPJ_UINT64)comp->dx << rpx) == 0) || + ((pi->x == pi->tx0) && + (((OPJ_UINT64)trx0 << levelno) % ((OPJ_UINT64)1U << rpx))))) { continue; } @@ -569,18 +587,18 @@ static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) continue; } - prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, - (OPJ_INT32)(comp->dx << levelno)), (OPJ_INT32)res->pdx) - - opj_int_floordivpow2(trx0, (OPJ_INT32)res->pdx); - prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, - (OPJ_INT32)(comp->dy << levelno)), (OPJ_INT32)res->pdy) - - opj_int_floordivpow2(try0, (OPJ_INT32)res->pdy); - pi->precno = (OPJ_UINT32)(prci + prcj * (OPJ_INT32)res->pw); + prci = opj_uint_floordivpow2(opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->x, + ((OPJ_UINT64)comp->dx << levelno)), res->pdx) + - opj_uint_floordivpow2(trx0, res->pdx); + prcj = opj_uint_floordivpow2(opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->y, + ((OPJ_UINT64)comp->dy << levelno)), res->pdy) + - opj_uint_floordivpow2(try0, res->pdy); + pi->precno = prci + prcj * res->pw; for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; if (index >= pi->include_size) { - opj_pi_emit_error(pi, "Invalid access to pi->include"); + opj_event_msg(pi->manager, EVT_ERROR, "Invalid access to pi->include"); return OPJ_FALSE; } if (!pi->include[index]) { @@ -604,6 +622,13 @@ static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; + if (pi->poc.compno0 >= pi->numcomps || + pi->poc.compno1 >= pi->numcomps + 1) { + opj_event_msg(pi->manager, EVT_ERROR, + "opj_pi_next_cprl(): invalid compno0/compno1\n"); + return OPJ_FALSE; + } + if (!pi->first) { comp = &pi->comps[pi->compno]; goto LABEL_SKIP; @@ -639,53 +664,50 @@ static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) pi->poc.ty1 = pi->ty1; pi->poc.tx1 = pi->tx1; } - for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; - pi->y += (OPJ_INT32)(pi->dy - (OPJ_UINT32)(pi->y % (OPJ_INT32)pi->dy))) { - for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; - pi->x += (OPJ_INT32)(pi->dx - (OPJ_UINT32)(pi->x % (OPJ_INT32)pi->dx))) { + for (pi->y = (OPJ_UINT32)pi->poc.ty0; pi->y < (OPJ_UINT32)pi->poc.ty1; + pi->y += (pi->dy - (pi->y % pi->dy))) { + for (pi->x = (OPJ_UINT32)pi->poc.tx0; pi->x < (OPJ_UINT32)pi->poc.tx1; + pi->x += (pi->dx - (pi->x % pi->dx))) { for (pi->resno = pi->poc.resno0; pi->resno < opj_uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) { OPJ_UINT32 levelno; - OPJ_INT32 trx0, try0; - OPJ_INT32 trx1, try1; + OPJ_UINT32 trx0, try0; + OPJ_UINT32 trx1, try1; OPJ_UINT32 rpx, rpy; - OPJ_INT32 prci, prcj; + OPJ_UINT32 prci, prcj; res = &comp->resolutions[pi->resno]; levelno = comp->numresolutions - 1 - pi->resno; - /* Avoids division by zero on id_000004,sig_06,src_000679,op_arith8,pos_49,val_-17 */ - /* of https://github.com/uclouvain/openjpeg/issues/938 */ - if (levelno >= 32 || - ((comp->dx << levelno) >> levelno) != comp->dx || - ((comp->dy << levelno) >> levelno) != comp->dy) { - continue; - } - if ((comp->dx << levelno) > INT_MAX || - (comp->dy << levelno) > INT_MAX) { + + if ((OPJ_UINT32)(((OPJ_UINT64)comp->dx << levelno) >> levelno) != comp->dx || + (OPJ_UINT32)(((OPJ_UINT64)comp->dy << levelno) >> levelno) != comp->dy) { continue; } - trx0 = opj_int_ceildiv(pi->tx0, (OPJ_INT32)(comp->dx << levelno)); - try0 = opj_int_ceildiv(pi->ty0, (OPJ_INT32)(comp->dy << levelno)); - trx1 = opj_int_ceildiv(pi->tx1, (OPJ_INT32)(comp->dx << levelno)); - try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno)); + + trx0 = opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->tx0, + ((OPJ_UINT64)comp->dx << levelno)); + try0 = opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->ty0, + ((OPJ_UINT64)comp->dy << levelno)); + trx1 = opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->tx1, + ((OPJ_UINT64)comp->dx << levelno)); + try1 = opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->ty1, + ((OPJ_UINT64)comp->dy << levelno)); rpx = res->pdx + levelno; rpy = res->pdy + levelno; - /* To avoid divisions by zero / undefined behaviour on shift */ - /* in below tests */ - /* Fixes reading id:000019,sig:08,src:001098,op:flip1,pos:49 */ - /* of https://github.com/uclouvain/openjpeg/issues/938 */ - if (rpx >= 31 || ((comp->dx << rpx) >> rpx) != comp->dx || - rpy >= 31 || ((comp->dy << rpy) >> rpy) != comp->dy) { + if ((OPJ_UINT32)(((OPJ_UINT64)comp->dx << rpx) >> rpx) != comp->dx || + (OPJ_UINT32)(((OPJ_UINT64)comp->dy << rpy) >> rpy) != comp->dy) { continue; } /* See ISO-15441. B.12.1.5 Component-position-resolution level-layer progression */ - if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && - ((try0 << levelno) % (1 << rpy))))) { + if (!(((OPJ_UINT64)pi->y % ((OPJ_UINT64)comp->dy << rpy) == 0) || + ((pi->y == pi->ty0) && + (((OPJ_UINT64)try0 << levelno) % ((OPJ_UINT64)1U << rpy))))) { continue; } - if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && - ((trx0 << levelno) % (1 << rpx))))) { + if (!(((OPJ_UINT64)pi->x % ((OPJ_UINT64)comp->dx << rpx) == 0) || + ((pi->x == pi->tx0) && + (((OPJ_UINT64)trx0 << levelno) % ((OPJ_UINT64)1U << rpx))))) { continue; } @@ -697,18 +719,18 @@ static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) continue; } - prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, - (OPJ_INT32)(comp->dx << levelno)), (OPJ_INT32)res->pdx) - - opj_int_floordivpow2(trx0, (OPJ_INT32)res->pdx); - prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, - (OPJ_INT32)(comp->dy << levelno)), (OPJ_INT32)res->pdy) - - opj_int_floordivpow2(try0, (OPJ_INT32)res->pdy); - pi->precno = (OPJ_UINT32)(prci + prcj * (OPJ_INT32)res->pw); + prci = opj_uint_floordivpow2(opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->x, + ((OPJ_UINT64)comp->dx << levelno)), res->pdx) + - opj_uint_floordivpow2(trx0, res->pdx); + prcj = opj_uint_floordivpow2(opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->y, + ((OPJ_UINT64)comp->dy << levelno)), res->pdy) + - opj_uint_floordivpow2(try0, res->pdy); + pi->precno = (OPJ_UINT32)(prci + prcj * res->pw); for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; if (index >= pi->include_size) { - opj_pi_emit_error(pi, "Invalid access to pi->include"); + opj_event_msg(pi->manager, EVT_ERROR, "Invalid access to pi->include"); return OPJ_FALSE; } if (!pi->include[index]) { @@ -729,10 +751,10 @@ static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) static void opj_get_encoding_parameters(const opj_image_t *p_image, const opj_cp_t *p_cp, OPJ_UINT32 p_tileno, - OPJ_INT32 * p_tx0, - OPJ_INT32 * p_tx1, - OPJ_INT32 * p_ty0, - OPJ_INT32 * p_ty1, + OPJ_UINT32 * p_tx0, + OPJ_UINT32 * p_tx1, + OPJ_UINT32 * p_ty0, + OPJ_UINT32 * p_ty1, OPJ_UINT32 * p_dx_min, OPJ_UINT32 * p_dy_min, OPJ_UINT32 * p_max_prec, @@ -748,6 +770,9 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image, /* position in x and y of tile */ OPJ_UINT32 p, q; + /* non-corrected (in regard to image offset) tile offset */ + OPJ_UINT32 l_tx0, l_ty0; + /* preconditions */ assert(p_cp != 00); assert(p_image != 00); @@ -763,14 +788,14 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image, q = p_tileno / p_cp->tw; /* find extent of tile */ - *p_tx0 = opj_int_max((OPJ_INT32)(p_cp->tx0 + p * p_cp->tdx), - (OPJ_INT32)p_image->x0); - *p_tx1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + (p + 1) * p_cp->tdx), - (OPJ_INT32)p_image->x1); - *p_ty0 = opj_int_max((OPJ_INT32)(p_cp->ty0 + q * p_cp->tdy), - (OPJ_INT32)p_image->y0); - *p_ty1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + (q + 1) * p_cp->tdy), - (OPJ_INT32)p_image->y1); + l_tx0 = p_cp->tx0 + p * + p_cp->tdx; /* can't be greater than p_image->x1 so won't overflow */ + *p_tx0 = opj_uint_max(l_tx0, p_image->x0); + *p_tx1 = opj_uint_min(opj_uint_adds(l_tx0, p_cp->tdx), p_image->x1); + l_ty0 = p_cp->ty0 + q * + p_cp->tdy; /* can't be greater than p_image->y1 so won't overflow */ + *p_ty0 = opj_uint_max(l_ty0, p_image->y0); + *p_ty1 = opj_uint_min(opj_uint_adds(l_ty0, p_cp->tdy), p_image->y1); /* max precision is 0 (can only grow) */ *p_max_prec = 0; @@ -783,17 +808,17 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image, for (compno = 0; compno < p_image->numcomps; ++compno) { /* arithmetic variables to calculate */ OPJ_UINT32 l_level_no; - OPJ_INT32 l_rx0, l_ry0, l_rx1, l_ry1; - OPJ_INT32 l_px0, l_py0, l_px1, py1; + OPJ_UINT32 l_rx0, l_ry0, l_rx1, l_ry1; + OPJ_UINT32 l_px0, l_py0, l_px1, py1; OPJ_UINT32 l_pdx, l_pdy; OPJ_UINT32 l_pw, l_ph; OPJ_UINT32 l_product; - OPJ_INT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1; + OPJ_UINT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1; - l_tcx0 = opj_int_ceildiv(*p_tx0, (OPJ_INT32)l_img_comp->dx); - l_tcy0 = opj_int_ceildiv(*p_ty0, (OPJ_INT32)l_img_comp->dy); - l_tcx1 = opj_int_ceildiv(*p_tx1, (OPJ_INT32)l_img_comp->dx); - l_tcy1 = opj_int_ceildiv(*p_ty1, (OPJ_INT32)l_img_comp->dy); + l_tcx0 = opj_uint_ceildiv(*p_tx0, l_img_comp->dx); + l_tcy0 = opj_uint_ceildiv(*p_ty0, l_img_comp->dy); + l_tcx1 = opj_uint_ceildiv(*p_tx1, l_img_comp->dx); + l_tcy1 = opj_uint_ceildiv(*p_ty1, l_img_comp->dy); if (l_tccp->numresolutions > *p_max_res) { *p_max_res = l_tccp->numresolutions; @@ -801,35 +826,41 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image, /* use custom size for precincts */ for (resno = 0; resno < l_tccp->numresolutions; ++resno) { - OPJ_UINT32 l_dx, l_dy; + OPJ_UINT64 l_dx, l_dy; /* precinct width and height */ l_pdx = l_tccp->prcw[resno]; l_pdy = l_tccp->prch[resno]; - l_dx = l_img_comp->dx * (1u << (l_pdx + l_tccp->numresolutions - 1 - resno)); - l_dy = l_img_comp->dy * (1u << (l_pdy + l_tccp->numresolutions - 1 - resno)); + l_dx = l_img_comp->dx * ((OPJ_UINT64)1u << (l_pdx + l_tccp->numresolutions - 1 - + resno)); + l_dy = l_img_comp->dy * ((OPJ_UINT64)1u << (l_pdy + l_tccp->numresolutions - 1 - + resno)); /* take the minimum size for dx for each comp and resolution */ - *p_dx_min = opj_uint_min(*p_dx_min, l_dx); - *p_dy_min = opj_uint_min(*p_dy_min, l_dy); + if (l_dx <= UINT_MAX) { + *p_dx_min = opj_uint_min(*p_dx_min, (OPJ_UINT32)l_dx); + } + if (l_dy <= UINT_MAX) { + *p_dy_min = opj_uint_min(*p_dy_min, (OPJ_UINT32)l_dy); + } /* various calculations of extents */ l_level_no = l_tccp->numresolutions - 1 - resno; - l_rx0 = opj_int_ceildivpow2(l_tcx0, (OPJ_INT32)l_level_no); - l_ry0 = opj_int_ceildivpow2(l_tcy0, (OPJ_INT32)l_level_no); - l_rx1 = opj_int_ceildivpow2(l_tcx1, (OPJ_INT32)l_level_no); - l_ry1 = opj_int_ceildivpow2(l_tcy1, (OPJ_INT32)l_level_no); + l_rx0 = opj_uint_ceildivpow2(l_tcx0, l_level_no); + l_ry0 = opj_uint_ceildivpow2(l_tcy0, l_level_no); + l_rx1 = opj_uint_ceildivpow2(l_tcx1, l_level_no); + l_ry1 = opj_uint_ceildivpow2(l_tcy1, l_level_no); - l_px0 = opj_int_floordivpow2(l_rx0, (OPJ_INT32)l_pdx) << l_pdx; - l_py0 = opj_int_floordivpow2(l_ry0, (OPJ_INT32)l_pdy) << l_pdy; - l_px1 = opj_int_ceildivpow2(l_rx1, (OPJ_INT32)l_pdx) << l_pdx; + l_px0 = opj_uint_floordivpow2(l_rx0, l_pdx) << l_pdx; + l_py0 = opj_uint_floordivpow2(l_ry0, l_pdy) << l_pdy; + l_px1 = opj_uint_ceildivpow2(l_rx1, l_pdx) << l_pdx; - py1 = opj_int_ceildivpow2(l_ry1, (OPJ_INT32)l_pdy) << l_pdy; + py1 = opj_uint_ceildivpow2(l_ry1, l_pdy) << l_pdy; - l_pw = (l_rx0 == l_rx1) ? 0 : (OPJ_UINT32)((l_px1 - l_px0) >> l_pdx); - l_ph = (l_ry0 == l_ry1) ? 0 : (OPJ_UINT32)((py1 - l_py0) >> l_pdy); + l_pw = (l_rx0 == l_rx1) ? 0 : ((l_px1 - l_px0) >> l_pdx); + l_ph = (l_ry0 == l_ry1) ? 0 : ((py1 - l_py0) >> l_pdy); l_product = l_pw * l_ph; @@ -847,10 +878,10 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image, static void opj_get_all_encoding_parameters(const opj_image_t *p_image, const opj_cp_t *p_cp, OPJ_UINT32 tileno, - OPJ_INT32 * p_tx0, - OPJ_INT32 * p_tx1, - OPJ_INT32 * p_ty0, - OPJ_INT32 * p_ty1, + OPJ_UINT32 * p_tx0, + OPJ_UINT32 * p_tx1, + OPJ_UINT32 * p_ty0, + OPJ_UINT32 * p_ty1, OPJ_UINT32 * p_dx_min, OPJ_UINT32 * p_dy_min, OPJ_UINT32 * p_max_prec, @@ -891,12 +922,12 @@ static void opj_get_all_encoding_parameters(const opj_image_t *p_image, /* here calculation of tx0, tx1, ty0, ty1, maxprec, l_dx and l_dy */ l_tx0 = p_cp->tx0 + p * p_cp->tdx; /* can't be greater than p_image->x1 so won't overflow */ - *p_tx0 = (OPJ_INT32)opj_uint_max(l_tx0, p_image->x0); - *p_tx1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_tx0, p_cp->tdx), p_image->x1); + *p_tx0 = opj_uint_max(l_tx0, p_image->x0); + *p_tx1 = opj_uint_min(opj_uint_adds(l_tx0, p_cp->tdx), p_image->x1); l_ty0 = p_cp->ty0 + q * p_cp->tdy; /* can't be greater than p_image->y1 so won't overflow */ - *p_ty0 = (OPJ_INT32)opj_uint_max(l_ty0, p_image->y0); - *p_ty1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_ty0, p_cp->tdy), p_image->y1); + *p_ty0 = opj_uint_max(l_ty0, p_image->y0); + *p_ty1 = opj_uint_min(opj_uint_adds(l_ty0, p_cp->tdy), p_image->y1); /* max precision and resolution is 0 (can only grow)*/ *p_max_prec = 0; @@ -907,20 +938,20 @@ static void opj_get_all_encoding_parameters(const opj_image_t *p_image, *p_dy_min = 0x7fffffff; for (compno = 0; compno < p_image->numcomps; ++compno) { - /* aritmetic variables to calculate*/ + /* arithmetic variables to calculate*/ OPJ_UINT32 l_level_no; - OPJ_INT32 l_rx0, l_ry0, l_rx1, l_ry1; - OPJ_INT32 l_px0, l_py0, l_px1, py1; + OPJ_UINT32 l_rx0, l_ry0, l_rx1, l_ry1; + OPJ_UINT32 l_px0, l_py0, l_px1, py1; OPJ_UINT32 l_product; - OPJ_INT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1; + OPJ_UINT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1; OPJ_UINT32 l_pdx, l_pdy, l_pw, l_ph; - lResolutionPtr = p_resolutions[compno]; + lResolutionPtr = p_resolutions ? p_resolutions[compno] : NULL; - l_tcx0 = opj_int_ceildiv(*p_tx0, (OPJ_INT32)l_img_comp->dx); - l_tcy0 = opj_int_ceildiv(*p_ty0, (OPJ_INT32)l_img_comp->dy); - l_tcx1 = opj_int_ceildiv(*p_tx1, (OPJ_INT32)l_img_comp->dx); - l_tcy1 = opj_int_ceildiv(*p_ty1, (OPJ_INT32)l_img_comp->dy); + l_tcx0 = opj_uint_ceildiv(*p_tx0, l_img_comp->dx); + l_tcy0 = opj_uint_ceildiv(*p_ty0, l_img_comp->dy); + l_tcx1 = opj_uint_ceildiv(*p_tx1, l_img_comp->dx); + l_tcy1 = opj_uint_ceildiv(*p_ty1, l_img_comp->dy); if (l_tccp->numresolutions > *p_max_res) { *p_max_res = l_tccp->numresolutions; @@ -936,33 +967,37 @@ static void opj_get_all_encoding_parameters(const opj_image_t *p_image, /* precinct width and height*/ l_pdx = l_tccp->prcw[resno]; l_pdy = l_tccp->prch[resno]; - *lResolutionPtr++ = l_pdx; - *lResolutionPtr++ = l_pdy; + if (lResolutionPtr) { + *lResolutionPtr++ = l_pdx; + *lResolutionPtr++ = l_pdy; + } if (l_pdx + l_level_no < 32 && l_img_comp->dx <= UINT_MAX / (1u << (l_pdx + l_level_no))) { l_dx = l_img_comp->dx * (1u << (l_pdx + l_level_no)); /* take the minimum size for l_dx for each comp and resolution*/ - *p_dx_min = (OPJ_UINT32)opj_int_min((OPJ_INT32) * p_dx_min, (OPJ_INT32)l_dx); + *p_dx_min = opj_uint_min(*p_dx_min, l_dx); } if (l_pdy + l_level_no < 32 && l_img_comp->dy <= UINT_MAX / (1u << (l_pdy + l_level_no))) { l_dy = l_img_comp->dy * (1u << (l_pdy + l_level_no)); - *p_dy_min = (OPJ_UINT32)opj_int_min((OPJ_INT32) * p_dy_min, (OPJ_INT32)l_dy); + *p_dy_min = opj_uint_min(*p_dy_min, l_dy); } /* various calculations of extents*/ - l_rx0 = opj_int_ceildivpow2(l_tcx0, (OPJ_INT32)l_level_no); - l_ry0 = opj_int_ceildivpow2(l_tcy0, (OPJ_INT32)l_level_no); - l_rx1 = opj_int_ceildivpow2(l_tcx1, (OPJ_INT32)l_level_no); - l_ry1 = opj_int_ceildivpow2(l_tcy1, (OPJ_INT32)l_level_no); - l_px0 = opj_int_floordivpow2(l_rx0, (OPJ_INT32)l_pdx) << l_pdx; - l_py0 = opj_int_floordivpow2(l_ry0, (OPJ_INT32)l_pdy) << l_pdy; - l_px1 = opj_int_ceildivpow2(l_rx1, (OPJ_INT32)l_pdx) << l_pdx; - py1 = opj_int_ceildivpow2(l_ry1, (OPJ_INT32)l_pdy) << l_pdy; - l_pw = (l_rx0 == l_rx1) ? 0 : (OPJ_UINT32)((l_px1 - l_px0) >> l_pdx); - l_ph = (l_ry0 == l_ry1) ? 0 : (OPJ_UINT32)((py1 - l_py0) >> l_pdy); - *lResolutionPtr++ = l_pw; - *lResolutionPtr++ = l_ph; + l_rx0 = opj_uint_ceildivpow2(l_tcx0, l_level_no); + l_ry0 = opj_uint_ceildivpow2(l_tcy0, l_level_no); + l_rx1 = opj_uint_ceildivpow2(l_tcx1, l_level_no); + l_ry1 = opj_uint_ceildivpow2(l_tcy1, l_level_no); + l_px0 = opj_uint_floordivpow2(l_rx0, l_pdx) << l_pdx; + l_py0 = opj_uint_floordivpow2(l_ry0, l_pdy) << l_pdy; + l_px1 = opj_uint_ceildivpow2(l_rx1, l_pdx) << l_pdx; + py1 = opj_uint_ceildivpow2(l_ry1, l_pdy) << l_pdy; + l_pw = (l_rx0 == l_rx1) ? 0 : ((l_px1 - l_px0) >> l_pdx); + l_ph = (l_ry0 == l_ry1) ? 0 : ((py1 - l_py0) >> l_pdy); + if (lResolutionPtr) { + *lResolutionPtr++ = l_pw; + *lResolutionPtr++ = l_ph; + } l_product = l_pw * l_ph; /* update precision*/ @@ -978,7 +1013,8 @@ static void opj_get_all_encoding_parameters(const opj_image_t *p_image, static opj_pi_iterator_t * opj_pi_create(const opj_image_t *image, const opj_cp_t *cp, - OPJ_UINT32 tileno) + OPJ_UINT32 tileno, + opj_event_mgr_t* manager) { /* loop*/ OPJ_UINT32 pino, compno; @@ -1012,6 +1048,8 @@ static opj_pi_iterator_t * opj_pi_create(const opj_image_t *image, l_current_pi = l_pi; for (pino = 0; pino < l_poc_bound ; ++pino) { + l_current_pi->manager = manager; + l_current_pi->comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t)); if (! l_current_pi->comps) { @@ -1042,10 +1080,10 @@ static opj_pi_iterator_t * opj_pi_create(const opj_image_t *image, static void opj_pi_update_encode_poc_and_final(opj_cp_t *p_cp, OPJ_UINT32 p_tileno, - OPJ_INT32 p_tx0, - OPJ_INT32 p_tx1, - OPJ_INT32 p_ty0, - OPJ_INT32 p_ty1, + OPJ_UINT32 p_tx0, + OPJ_UINT32 p_tx1, + OPJ_UINT32 p_ty0, + OPJ_UINT32 p_ty1, OPJ_UINT32 p_max_prec, OPJ_UINT32 p_max_res, OPJ_UINT32 p_dx_min, @@ -1122,10 +1160,10 @@ static void opj_pi_update_encode_poc_and_final(opj_cp_t *p_cp, static void opj_pi_update_encode_not_poc(opj_cp_t *p_cp, OPJ_UINT32 p_num_comps, OPJ_UINT32 p_tileno, - OPJ_INT32 p_tx0, - OPJ_INT32 p_tx1, - OPJ_INT32 p_ty0, - OPJ_INT32 p_ty1, + OPJ_UINT32 p_tx0, + OPJ_UINT32 p_tx1, + OPJ_UINT32 p_ty0, + OPJ_UINT32 p_ty1, OPJ_UINT32 p_max_prec, OPJ_UINT32 p_max_res, OPJ_UINT32 p_dx_min, @@ -1164,10 +1202,10 @@ static void opj_pi_update_encode_not_poc(opj_cp_t *p_cp, l_current_poc->prg = l_tcp->prg; l_current_poc->prcS = 0; l_current_poc->prcE = p_max_prec; - l_current_poc->txS = (OPJ_UINT32)p_tx0; - l_current_poc->txE = (OPJ_UINT32)p_tx1; - l_current_poc->tyS = (OPJ_UINT32)p_ty0; - l_current_poc->tyE = (OPJ_UINT32)p_ty1; + l_current_poc->txS = p_tx0; + l_current_poc->txE = p_tx1; + l_current_poc->tyS = p_ty0; + l_current_poc->tyE = p_ty1; l_current_poc->dx = p_dx_min; l_current_poc->dy = p_dy_min; ++ l_current_poc; @@ -1182,7 +1220,7 @@ static void opj_pi_update_decode_poc(opj_pi_iterator_t * p_pi, /* loop*/ OPJ_UINT32 pino; - /* encoding prameters to set*/ + /* encoding parameters to set*/ OPJ_UINT32 l_bound; opj_pi_iterator_t * l_current_pi = 00; @@ -1229,7 +1267,7 @@ static void opj_pi_update_decode_not_poc(opj_pi_iterator_t * p_pi, /* loop*/ OPJ_UINT32 pino; - /* encoding prameters to set*/ + /* encoding parameters to set*/ OPJ_UINT32 l_bound; opj_pi_iterator_t * l_current_pi = 00; @@ -1269,7 +1307,7 @@ static OPJ_BOOL opj_pi_check_next_level(OPJ_INT32 pos, opj_poc_t *tcp = &tcps->pocs[pino]; if (pos >= 0) { - for (i = pos; pos >= 0; i--) { + for (i = pos; i >= 0; i--) { switch (prog[i]) { case 'R': if (tcp->res_t == tcp->resE) { @@ -1349,7 +1387,8 @@ static OPJ_BOOL opj_pi_check_next_level(OPJ_INT32 pos, */ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image, opj_cp_t *p_cp, - OPJ_UINT32 p_tile_no) + OPJ_UINT32 p_tile_no, + opj_event_mgr_t* manager) { OPJ_UINT32 numcomps = p_image->numcomps; @@ -1357,14 +1396,14 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image, OPJ_UINT32 pino; OPJ_UINT32 compno, resno; - /* to store w, h, dx and dy fro all components and resolutions */ + /* to store w, h, dx and dy for all components and resolutions */ OPJ_UINT32 * l_tmp_data; OPJ_UINT32 ** l_tmp_ptr; - /* encoding prameters to set */ + /* encoding parameters to set */ OPJ_UINT32 l_max_res; OPJ_UINT32 l_max_prec; - OPJ_INT32 l_tx0, l_tx1, l_ty0, l_ty1; + OPJ_UINT32 l_tx0, l_tx1, l_ty0, l_ty1; OPJ_UINT32 l_dx_min, l_dy_min; OPJ_UINT32 l_bound; OPJ_UINT32 l_step_p, l_step_c, l_step_r, l_step_l ; @@ -1404,7 +1443,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image, } /* memory allocation for pi */ - l_pi = opj_pi_create(p_image, p_cp, p_tile_no); + l_pi = opj_pi_create(p_image, p_cp, p_tile_no, manager); if (!l_pi) { opj_free(l_tmp_data); opj_free(l_tmp_ptr); @@ -1545,11 +1584,34 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image, } +OPJ_UINT32 opj_get_encoding_packet_count(const opj_image_t *p_image, + const opj_cp_t *p_cp, + OPJ_UINT32 p_tile_no) +{ + OPJ_UINT32 l_max_res; + OPJ_UINT32 l_max_prec; + OPJ_UINT32 l_tx0, l_tx1, l_ty0, l_ty1; + OPJ_UINT32 l_dx_min, l_dy_min; + + /* preconditions in debug*/ + assert(p_cp != 00); + assert(p_image != 00); + assert(p_tile_no < p_cp->tw * p_cp->th); + + /* get encoding parameters*/ + opj_get_all_encoding_parameters(p_image, p_cp, p_tile_no, &l_tx0, &l_tx1, + &l_ty0, &l_ty1, &l_dx_min, &l_dy_min, &l_max_prec, &l_max_res, NULL); + + return p_cp->tcps[p_tile_no].numlayers * l_max_prec * p_image->numcomps * + l_max_res; +} + opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image, opj_cp_t *p_cp, OPJ_UINT32 p_tile_no, - J2K_T2_MODE p_t2_mode) + J2K_T2_MODE p_t2_mode, + opj_event_mgr_t* manager) { OPJ_UINT32 numcomps = p_image->numcomps; @@ -1557,14 +1619,14 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image, OPJ_UINT32 pino; OPJ_UINT32 compno, resno; - /* to store w, h, dx and dy fro all components and resolutions*/ + /* to store w, h, dx and dy for all components and resolutions*/ OPJ_UINT32 * l_tmp_data; OPJ_UINT32 ** l_tmp_ptr; - /* encoding prameters to set*/ + /* encoding parameters to set*/ OPJ_UINT32 l_max_res; OPJ_UINT32 l_max_prec; - OPJ_INT32 l_tx0, l_tx1, l_ty0, l_ty1; + OPJ_UINT32 l_tx0, l_tx1, l_ty0, l_ty1; OPJ_UINT32 l_dx_min, l_dy_min; OPJ_UINT32 l_bound; OPJ_UINT32 l_step_p, l_step_c, l_step_r, l_step_l ; @@ -1603,7 +1665,7 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image, } /* memory allocation for pi*/ - l_pi = opj_pi_create(p_image, p_cp, p_tile_no); + l_pi = opj_pi_create(p_image, p_cp, p_tile_no, manager); if (!l_pi) { opj_free(l_tmp_data); opj_free(l_tmp_ptr); @@ -1758,7 +1820,8 @@ void opj_pi_create_encode(opj_pi_iterator_t *pi, pi[pino].poc.prg = tcp->prg; if (!(cp->m_specific_param.m_enc.m_tp_on && ((!OPJ_IS_CINEMA(cp->rsiz) && - (t2_mode == FINAL_PASS)) || OPJ_IS_CINEMA(cp->rsiz)))) { + !OPJ_IS_IMF(cp->rsiz) && + (t2_mode == FINAL_PASS)) || OPJ_IS_CINEMA(cp->rsiz) || OPJ_IS_IMF(cp->rsiz)))) { pi[pino].poc.resno0 = tcp->resS; pi[pino].poc.resno1 = tcp->resE; pi[pino].poc.compno0 = tcp->compS; @@ -1767,10 +1830,10 @@ void opj_pi_create_encode(opj_pi_iterator_t *pi, pi[pino].poc.layno1 = tcp->layE; pi[pino].poc.precno0 = tcp->prcS; pi[pino].poc.precno1 = tcp->prcE; - pi[pino].poc.tx0 = (OPJ_INT32)tcp->txS; - pi[pino].poc.ty0 = (OPJ_INT32)tcp->tyS; - pi[pino].poc.tx1 = (OPJ_INT32)tcp->txE; - pi[pino].poc.ty1 = (OPJ_INT32)tcp->tyE; + pi[pino].poc.tx0 = tcp->txS; + pi[pino].poc.ty0 = tcp->tyS; + pi[pino].poc.tx1 = tcp->txE; + pi[pino].poc.ty1 = tcp->tyE; } else { for (i = tppos + 1; i < 4; i++) { switch (prog[i]) { @@ -1794,10 +1857,10 @@ void opj_pi_create_encode(opj_pi_iterator_t *pi, pi[pino].poc.precno1 = tcp->prcE; break; default: - pi[pino].poc.tx0 = (OPJ_INT32)tcp->txS; - pi[pino].poc.ty0 = (OPJ_INT32)tcp->tyS; - pi[pino].poc.tx1 = (OPJ_INT32)tcp->txE; - pi[pino].poc.ty1 = (OPJ_INT32)tcp->tyE; + pi[pino].poc.tx0 = tcp->txS; + pi[pino].poc.ty0 = tcp->tyS; + pi[pino].poc.tx1 = tcp->txE; + pi[pino].poc.ty1 = tcp->tyE; break; } break; @@ -1837,10 +1900,10 @@ void opj_pi_create_encode(opj_pi_iterator_t *pi, default: tcp->tx0_t = tcp->txS; tcp->ty0_t = tcp->tyS; - pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t; - pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx)); - pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t; - pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy)); + pi[pino].poc.tx0 = tcp->tx0_t; + pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx); + pi[pino].poc.ty0 = tcp->ty0_t; + pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; break; @@ -1872,10 +1935,10 @@ void opj_pi_create_encode(opj_pi_iterator_t *pi, pi[pino].poc.precno1 = tcp->prc_t; break; default: - pi[pino].poc.tx0 = (OPJ_INT32)(tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx)); - pi[pino].poc.tx1 = (OPJ_INT32)tcp->tx0_t ; - pi[pino].poc.ty0 = (OPJ_INT32)(tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy)); - pi[pino].poc.ty1 = (OPJ_INT32)tcp->ty0_t ; + pi[pino].poc.tx0 = tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx); + pi[pino].poc.tx1 = tcp->tx0_t ; + pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy); + pi[pino].poc.ty1 = tcp->ty0_t ; break; } break; @@ -1962,8 +2025,8 @@ void opj_pi_create_encode(opj_pi_iterator_t *pi, if (tcp->ty0_t >= tcp->tyE) { if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { tcp->ty0_t = tcp->tyS; - pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t; - pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy)); + pi[pino].poc.ty0 = tcp->ty0_t; + pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; incr_top = 1; resetX = 1; @@ -1972,21 +2035,21 @@ void opj_pi_create_encode(opj_pi_iterator_t *pi, resetX = 0; } } else { - pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t; - pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy)); + pi[pino].poc.ty0 = tcp->ty0_t; + pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; incr_top = 0; resetX = 1; } if (resetX == 1) { tcp->tx0_t = tcp->txS; - pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t; - pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx)); + pi[pino].poc.tx0 = tcp->tx0_t; + pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx); tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; } } else { - pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t; - pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx)); + pi[pino].poc.tx0 = tcp->tx0_t; + pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx); tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; incr_top = 0; } @@ -2039,7 +2102,7 @@ void opj_pi_update_encoding_parameters(const opj_image_t *p_image, /* encoding parameters to set */ OPJ_UINT32 l_max_res; OPJ_UINT32 l_max_prec; - OPJ_INT32 l_tx0, l_tx1, l_ty0, l_ty1; + OPJ_UINT32 l_tx0, l_tx1, l_ty0, l_ty1; OPJ_UINT32 l_dx_min, l_dy_min; /* pointers */ diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/pi.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/pi.h index 8c0dc25c19d..0320523b769 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/pi.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/pi.h @@ -102,11 +102,13 @@ typedef struct opj_pi_iterator { /** Components*/ opj_pi_comp_t *comps; /** FIXME DOC*/ - OPJ_INT32 tx0, ty0, tx1, ty1; + OPJ_UINT32 tx0, ty0, tx1, ty1; /** FIXME DOC*/ - OPJ_INT32 x, y; + OPJ_UINT32 x, y; /** FIXME DOC*/ OPJ_UINT32 dx, dy; + /** event manager */ + opj_event_mgr_t* manager; } opj_pi_iterator_t; /** @name Exported functions */ @@ -119,13 +121,15 @@ typedef struct opj_pi_iterator { * @param cp the coding parameters. * @param tileno index of the tile being encoded. * @param t2_mode the type of pass for generating the packet iterator + * @param manager Event manager * * @return a list of packet iterator that points to the first packet of the tile (not true). */ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *image, opj_cp_t *cp, OPJ_UINT32 tileno, - J2K_T2_MODE t2_mode); + J2K_T2_MODE t2_mode, + opj_event_mgr_t* manager); /** * Updates the encoding parameters of the codec. @@ -161,12 +165,14 @@ Create a packet iterator for Decoder @param image Raw image for which the packets will be listed @param cp Coding parameters @param tileno Number that identifies the tile for which to list the packets +@param manager Event manager @return Returns a packet iterator that points to the first packet of the tile @see opj_pi_destroy */ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t * image, opj_cp_t * cp, - OPJ_UINT32 tileno); + OPJ_UINT32 tileno, + opj_event_mgr_t* manager); /** * Destroys a packet iterator array. * @@ -182,6 +188,17 @@ Modify the packet iterator to point to the next packet @return Returns false if pi pointed to the last packet or else returns true */ OPJ_BOOL opj_pi_next(opj_pi_iterator_t * pi); + +/** + * Return the number of packets in the tile. + * @param image the image being encoded. + * @param cp Coding parameters + * @param tileno Number that identifies the tile. + */ +OPJ_UINT32 opj_get_encoding_packet_count(const opj_image_t *p_image, + const opj_cp_t *p_cp, + OPJ_UINT32 p_tile_no); + /* ----------------------------------------------------------------------- */ /*@}*/ diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/sparse_array.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/sparse_array.c index 73192924edd..50d1a9041a4 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/sparse_array.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/sparse_array.c @@ -69,7 +69,7 @@ opj_sparse_array_int32_t* opj_sparse_array_int32_create(OPJ_UINT32 width, return NULL; } sa->data_blocks = (OPJ_INT32**) opj_calloc(sizeof(OPJ_INT32*), - sa->block_count_hor * sa->block_count_ver); + (size_t) sa->block_count_hor * sa->block_count_ver); if (sa->data_blocks == NULL) { opj_free(sa); return NULL; @@ -235,7 +235,7 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write( } else { if (src_block == NULL) { src_block = (OPJ_INT32*) opj_calloc(1, - sa->block_width * sa->block_height * sizeof(OPJ_INT32)); + (size_t) sa->block_width * sa->block_height * sizeof(OPJ_INT32)); if (src_block == NULL) { return OPJ_FALSE; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1.c index 76744380f76..98dce47f556 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1.c @@ -47,6 +47,9 @@ #ifdef __SSE2__ #include #endif +#if (defined(__AVX2__) || defined(__AVX512F__)) +#include +#endif #if defined(__GNUC__) #pragma GCC poison malloc calloc realloc free @@ -61,6 +64,13 @@ #define opj_t1_setcurctx(curctx, ctxno) curctx = &(mqc)->ctxs[(OPJ_UINT32)(ctxno)] +/* Macros to deal with signed integer with just MSB bit set for + * negative values (smr = signed magnitude representation) */ +#define opj_smr_abs(x) (((OPJ_UINT32)(x)) & 0x7FFFFFFFU) +#define opj_smr_sign(x) (((OPJ_UINT32)(x)) >> 31) +#define opj_to_smr(x) ((x) >= 0 ? (OPJ_UINT32)(x) : ((OPJ_UINT32)(-x) | 0x80000000U)) + + /** @name Local static functions */ /*@{*/ @@ -177,18 +187,18 @@ static OPJ_FLOAT64 opj_t1_getwmsedec( const OPJ_FLOAT64 * mct_norms, OPJ_UINT32 mct_numcomps); -static void opj_t1_encode_cblk(opj_t1_t *t1, - opj_tcd_cblk_enc_t* cblk, - OPJ_UINT32 orient, - OPJ_UINT32 compno, - OPJ_UINT32 level, - OPJ_UINT32 qmfbid, - OPJ_FLOAT64 stepsize, - OPJ_UINT32 cblksty, - OPJ_UINT32 numcomps, - opj_tcd_tile_t * tile, - const OPJ_FLOAT64 * mct_norms, - OPJ_UINT32 mct_numcomps); +/** Return "cumwmsedec" that should be used to increase tile->distotile */ +static double opj_t1_encode_cblk(opj_t1_t *t1, + opj_tcd_cblk_enc_t* cblk, + OPJ_UINT32 orient, + OPJ_UINT32 compno, + OPJ_UINT32 level, + OPJ_UINT32 qmfbid, + OPJ_FLOAT64 stepsize, + OPJ_UINT32 cblksty, + OPJ_UINT32 numcomps, + const OPJ_FLOAT64 * mct_norms, + OPJ_UINT32 mct_numcomps); /** Decode 1 code-block @@ -210,6 +220,27 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, opj_mutex_t* p_manager_mutex, OPJ_BOOL check_pterm); +/** +Decode 1 HT code-block +@param t1 T1 handle +@param cblk Code-block coding parameters +@param orient +@param roishift Region of interest shifting value +@param cblksty Code-block style +@param p_manager the event manager +@param p_manager_mutex mutex for the event manager +@param check_pterm whether PTERM correct termination should be checked +*/ +OPJ_BOOL opj_t1_ht_decode_cblk(opj_t1_t *t1, + opj_tcd_cblk_dec_t* cblk, + OPJ_UINT32 orient, + OPJ_UINT32 roishift, + OPJ_UINT32 cblksty, + opj_event_mgr_t *p_manager, + opj_mutex_t* p_manager_mutex, + OPJ_BOOL check_pterm); + + static OPJ_BOOL opj_t1_allocate_buffers(opj_t1_t *t1, OPJ_UINT32 w, OPJ_UINT32 h); @@ -329,61 +360,53 @@ static INLINE void opj_t1_update_flags(opj_flag_t *flagsp, OPJ_UINT32 ci, /** Encode significant pass */ -static INLINE void opj_t1_enc_sigpass_step(opj_t1_t *t1, - opj_flag_t *flagsp, - OPJ_INT32 *datap, - OPJ_INT32 bpno, - OPJ_INT32 one, - OPJ_INT32 *nmsedec, - OPJ_BYTE type, - OPJ_UINT32 ci, - OPJ_UINT32 vsc) -{ - OPJ_UINT32 v; - - opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ - - OPJ_UINT32 const flags = *flagsp; - - if ((flags & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U))) == 0U && - (flags & (T1_SIGMA_NEIGHBOURS << (ci * 3U))) != 0U) { - OPJ_UINT32 ctxt1 = opj_t1_getctxno_zc(mqc, flags >> (ci * 3U)); - v = (opj_int_abs(*datap) & one) ? 1 : 0; -#ifdef DEBUG_ENC_SIG - fprintf(stderr, " ctxt1=%d\n", ctxt1); -#endif - opj_mqc_setcurctx(mqc, ctxt1); - if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - opj_mqc_bypass_enc(mqc, v); - } else { - opj_mqc_encode(mqc, v); - } - if (v) { - OPJ_UINT32 lu = opj_t1_getctxtno_sc_or_spb_index( - *flagsp, - flagsp[-1], flagsp[1], - ci); - OPJ_UINT32 ctxt2 = opj_t1_getctxno_sc(lu); - v = *datap < 0 ? 1U : 0U; - *nmsedec += opj_t1_getnmsedec_sig((OPJ_UINT32)opj_int_abs(*datap), - (OPJ_UINT32)bpno); -#ifdef DEBUG_ENC_SIG - fprintf(stderr, " ctxt2=%d\n", ctxt2); -#endif - opj_mqc_setcurctx(mqc, ctxt2); - if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - opj_mqc_bypass_enc(mqc, v); - } else { - OPJ_UINT32 spb = opj_t1_getspb(lu); -#ifdef DEBUG_ENC_SIG - fprintf(stderr, " spb=%d\n", spb); -#endif - opj_mqc_encode(mqc, v ^ spb); - } - opj_t1_update_flags(flagsp, ci, v, t1->w + 2, vsc); - } - *flagsp |= T1_PI_THIS << (ci * 3U); - } +#define opj_t1_enc_sigpass_step_macro(mqc, curctx, a, c, ct, flagspIn, datapIn, bpno, one, nmsedec, type, ciIn, vscIn) \ +{ \ + OPJ_UINT32 v; \ + const OPJ_UINT32 ci = (ciIn); \ + const OPJ_UINT32 vsc = (vscIn); \ + const OPJ_INT32* l_datap = (datapIn); \ + opj_flag_t* flagsp = (flagspIn); \ + OPJ_UINT32 const flags = *flagsp; \ + if ((flags & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U))) == 0U && \ + (flags & (T1_SIGMA_NEIGHBOURS << (ci * 3U))) != 0U) { \ + OPJ_UINT32 ctxt1 = opj_t1_getctxno_zc(mqc, flags >> (ci * 3U)); \ + v = (opj_smr_abs(*l_datap) & (OPJ_UINT32)one) ? 1 : 0; \ +/* #ifdef DEBUG_ENC_SIG */ \ +/* fprintf(stderr, " ctxt1=%d\n", ctxt1); */ \ +/* #endif */ \ + opj_t1_setcurctx(curctx, ctxt1); \ + if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ \ + opj_mqc_bypass_enc_macro(mqc, c, ct, v); \ + } else { \ + opj_mqc_encode_macro(mqc, curctx, a, c, ct, v); \ + } \ + if (v) { \ + OPJ_UINT32 lu = opj_t1_getctxtno_sc_or_spb_index( \ + *flagsp, \ + flagsp[-1], flagsp[1], \ + ci); \ + OPJ_UINT32 ctxt2 = opj_t1_getctxno_sc(lu); \ + v = opj_smr_sign(*l_datap); \ + *nmsedec += opj_t1_getnmsedec_sig(opj_smr_abs(*l_datap), \ + (OPJ_UINT32)bpno); \ +/* #ifdef DEBUG_ENC_SIG */ \ +/* fprintf(stderr, " ctxt2=%d\n", ctxt2); */ \ +/* #endif */ \ + opj_t1_setcurctx(curctx, ctxt2); \ + if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ \ + opj_mqc_bypass_enc_macro(mqc, c, ct, v); \ + } else { \ + OPJ_UINT32 spb = opj_t1_getspb(lu); \ +/* #ifdef DEBUG_ENC_SIG */ \ +/* fprintf(stderr, " spb=%d\n", spb); */ \ +/* #endif */ \ + opj_mqc_encode_macro(mqc, curctx, a, c, ct, v ^ spb); \ + } \ + opj_t1_update_flags(flagsp, ci, v, t1->w + 2, vsc); \ + } \ + *flagsp |= T1_PI_THIS << (ci * 3U); \ + } \ } static INLINE void opj_t1_dec_sigpass_step_raw( @@ -464,63 +487,64 @@ static void opj_t1_enc_sigpass(opj_t1_t *t1, OPJ_INT32 const one = 1 << (bpno + T1_NMSEDEC_FRACBITS); opj_flag_t* f = &T1_FLAGS(0, 0); OPJ_UINT32 const extra = 2; + opj_mqc_t* mqc = &(t1->mqc); + DOWNLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); + const OPJ_INT32* datap = t1->data; *nmsedec = 0; #ifdef DEBUG_ENC_SIG fprintf(stderr, "enc_sigpass: bpno=%d\n", bpno); #endif - for (k = 0; k < (t1->h & ~3U); k += 4) { + for (k = 0; k < (t1->h & ~3U); k += 4, f += extra) { + const OPJ_UINT32 w = t1->w; #ifdef DEBUG_ENC_SIG fprintf(stderr, " k=%d\n", k); #endif - for (i = 0; i < t1->w; ++i) { + for (i = 0; i < w; ++i, ++f, datap += 4) { #ifdef DEBUG_ENC_SIG fprintf(stderr, " i=%d\n", i); #endif if (*f == 0U) { /* Nothing to do for any of the 4 data points */ - f++; continue; } - opj_t1_enc_sigpass_step( - t1, + opj_t1_enc_sigpass_step_macro( + mqc, curctx, a, c, ct, f, - &t1->data[((k + 0) * t1->data_stride) + i], + &datap[0], bpno, one, nmsedec, type, 0, cblksty & J2K_CCP_CBLKSTY_VSC); - opj_t1_enc_sigpass_step( - t1, + opj_t1_enc_sigpass_step_macro( + mqc, curctx, a, c, ct, f, - &t1->data[((k + 1) * t1->data_stride) + i], + &datap[1], bpno, one, nmsedec, type, 1, 0); - opj_t1_enc_sigpass_step( - t1, + opj_t1_enc_sigpass_step_macro( + mqc, curctx, a, c, ct, f, - &t1->data[((k + 2) * t1->data_stride) + i], + &datap[2], bpno, one, nmsedec, type, 2, 0); - opj_t1_enc_sigpass_step( - t1, + opj_t1_enc_sigpass_step_macro( + mqc, curctx, a, c, ct, f, - &t1->data[((k + 3) * t1->data_stride) + i], + &datap[3], bpno, one, nmsedec, type, 3, 0); - ++f; } - f += extra; } if (k < t1->h) { @@ -528,20 +552,20 @@ static void opj_t1_enc_sigpass(opj_t1_t *t1, #ifdef DEBUG_ENC_SIG fprintf(stderr, " k=%d\n", k); #endif - for (i = 0; i < t1->w; ++i) { + for (i = 0; i < t1->w; ++i, ++f) { #ifdef DEBUG_ENC_SIG fprintf(stderr, " i=%d\n", i); #endif if (*f == 0U) { /* Nothing to do for any of the 4 data points */ - f++; + datap += (t1->h - k); continue; } - for (j = k; j < t1->h; ++j) { - opj_t1_enc_sigpass_step( - t1, + for (j = k; j < t1->h; ++j, ++datap) { + opj_t1_enc_sigpass_step_macro( + mqc, curctx, a, c, ct, f, - &t1->data[(j * t1->data_stride) + i], + &datap[0], bpno, one, nmsedec, @@ -549,9 +573,10 @@ static void opj_t1_enc_sigpass(opj_t1_t *t1, j - k, (j == k && (cblksty & J2K_CCP_CBLKSTY_VSC) != 0)); } - ++f; } } + + UPLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); } static void opj_t1_dec_sigpass_raw( @@ -626,7 +651,7 @@ static void opj_t1_dec_sigpass_raw( register opj_flag_t *flagsp = &t1->flags[(flags_stride) + 1]; \ const OPJ_UINT32 l_w = w; \ opj_mqc_t* mqc = &(t1->mqc); \ - DOWNLOAD_MQC_VARIABLES(mqc, curctx, c, a, ct); \ + DOWNLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); \ register OPJ_UINT32 v; \ one = 1 << bpno; \ half = one >> 1; \ @@ -651,7 +676,7 @@ static void opj_t1_dec_sigpass_raw( } \ } \ } \ - UPLOAD_MQC_VARIABLES(mqc, curctx, c, a, ct); \ + UPLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); \ if( k < h ) { \ for (i = 0; i < l_w; ++i, ++data, ++flagsp) { \ for (j = 0; j < h - k; ++j) { \ @@ -715,38 +740,27 @@ static void opj_t1_dec_sigpass_mqc( /** Encode refinement pass step */ -static INLINE void opj_t1_enc_refpass_step(opj_t1_t *t1, - opj_flag_t *flagsp, - OPJ_INT32 *datap, - OPJ_INT32 bpno, - OPJ_INT32 one, - OPJ_INT32 *nmsedec, - OPJ_BYTE type, - OPJ_UINT32 ci) -{ - OPJ_UINT32 v; - - opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ - - OPJ_UINT32 const shift_flags = - (*flagsp >> (ci * 3U)); - - if ((shift_flags & (T1_SIGMA_THIS | T1_PI_THIS)) == T1_SIGMA_THIS) { - OPJ_UINT32 ctxt = opj_t1_getctxno_mag(shift_flags); - *nmsedec += opj_t1_getnmsedec_ref((OPJ_UINT32)opj_int_abs(*datap), - (OPJ_UINT32)bpno); - v = (opj_int_abs(*datap) & one) ? 1 : 0; -#ifdef DEBUG_ENC_REF - fprintf(stderr, " ctxt=%d\n", ctxt); -#endif - opj_mqc_setcurctx(mqc, ctxt); - if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - opj_mqc_bypass_enc(mqc, v); - } else { - opj_mqc_encode(mqc, v); - } - *flagsp |= T1_MU_THIS << (ci * 3U); - } +#define opj_t1_enc_refpass_step_macro(mqc, curctx, a, c, ct, flags, flagsUpdated, datap, bpno, one, nmsedec, type, ci) \ +{\ + OPJ_UINT32 v; \ + if ((flags & ((T1_SIGMA_THIS | T1_PI_THIS) << ((ci) * 3U))) == (T1_SIGMA_THIS << ((ci) * 3U))) { \ + const OPJ_UINT32 shift_flags = (flags >> ((ci) * 3U)); \ + OPJ_UINT32 ctxt = opj_t1_getctxno_mag(shift_flags); \ + OPJ_UINT32 abs_data = opj_smr_abs(*datap); \ + *nmsedec += opj_t1_getnmsedec_ref(abs_data, \ + (OPJ_UINT32)bpno); \ + v = ((OPJ_INT32)abs_data & one) ? 1 : 0; \ +/* #ifdef DEBUG_ENC_REF */ \ +/* fprintf(stderr, " ctxt=%d\n", ctxt); */ \ +/* #endif */ \ + opj_t1_setcurctx(curctx, ctxt); \ + if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ \ + opj_mqc_bypass_enc_macro(mqc, c, ct, v); \ + } else { \ + opj_mqc_encode_macro(mqc, curctx, a, c, ct, v); \ + } \ + flagsUpdated |= T1_MU_THIS << ((ci) * 3U); \ + } \ } @@ -807,100 +821,104 @@ static void opj_t1_enc_refpass( const OPJ_INT32 one = 1 << (bpno + T1_NMSEDEC_FRACBITS); opj_flag_t* f = &T1_FLAGS(0, 0); const OPJ_UINT32 extra = 2U; + opj_mqc_t* mqc = &(t1->mqc); + DOWNLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); + const OPJ_INT32* datap = t1->data; *nmsedec = 0; #ifdef DEBUG_ENC_REF fprintf(stderr, "enc_refpass: bpno=%d\n", bpno); #endif - for (k = 0; k < (t1->h & ~3U); k += 4) { + for (k = 0; k < (t1->h & ~3U); k += 4, f += extra) { #ifdef DEBUG_ENC_REF fprintf(stderr, " k=%d\n", k); #endif - for (i = 0; i < t1->w; ++i) { + for (i = 0; i < t1->w; ++i, f++, datap += 4) { + const OPJ_UINT32 flags = *f; + OPJ_UINT32 flagsUpdated = flags; #ifdef DEBUG_ENC_REF fprintf(stderr, " i=%d\n", i); #endif - if ((*f & (T1_SIGMA_4 | T1_SIGMA_7 | T1_SIGMA_10 | T1_SIGMA_13)) == 0) { + if ((flags & (T1_SIGMA_4 | T1_SIGMA_7 | T1_SIGMA_10 | T1_SIGMA_13)) == 0) { /* none significant */ - f++; continue; } - if ((*f & (T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3)) == + if ((flags & (T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3)) == (T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3)) { /* all processed by sigpass */ - f++; continue; } - opj_t1_enc_refpass_step( - t1, - f, - &t1->data[((k + 0) * t1->data_stride) + i], + opj_t1_enc_refpass_step_macro( + mqc, curctx, a, c, ct, + flags, flagsUpdated, + &datap[0], bpno, one, nmsedec, type, 0); - opj_t1_enc_refpass_step( - t1, - f, - &t1->data[((k + 1) * t1->data_stride) + i], + opj_t1_enc_refpass_step_macro( + mqc, curctx, a, c, ct, + flags, flagsUpdated, + &datap[1], bpno, one, nmsedec, type, 1); - opj_t1_enc_refpass_step( - t1, - f, - &t1->data[((k + 2) * t1->data_stride) + i], + opj_t1_enc_refpass_step_macro( + mqc, curctx, a, c, ct, + flags, flagsUpdated, + &datap[2], bpno, one, nmsedec, type, 2); - opj_t1_enc_refpass_step( - t1, - f, - &t1->data[((k + 3) * t1->data_stride) + i], + opj_t1_enc_refpass_step_macro( + mqc, curctx, a, c, ct, + flags, flagsUpdated, + &datap[3], bpno, one, nmsedec, type, 3); - ++f; + *f = flagsUpdated; } - f += extra; } if (k < t1->h) { OPJ_UINT32 j; + const OPJ_UINT32 remaining_lines = t1->h - k; #ifdef DEBUG_ENC_REF fprintf(stderr, " k=%d\n", k); #endif - for (i = 0; i < t1->w; ++i) { + for (i = 0; i < t1->w; ++i, ++f) { #ifdef DEBUG_ENC_REF fprintf(stderr, " i=%d\n", i); #endif if ((*f & (T1_SIGMA_4 | T1_SIGMA_7 | T1_SIGMA_10 | T1_SIGMA_13)) == 0) { /* none significant */ - f++; + datap += remaining_lines; continue; } - for (j = k; j < t1->h; ++j) { - opj_t1_enc_refpass_step( - t1, - f, - &t1->data[(j * t1->data_stride) + i], + for (j = 0; j < remaining_lines; ++j, datap ++) { + opj_t1_enc_refpass_step_macro( + mqc, curctx, a, c, ct, + *f, *f, + &datap[0], bpno, one, nmsedec, type, - j - k); + j); } - ++f; } } + + UPLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); } @@ -968,7 +986,7 @@ static void opj_t1_dec_refpass_raw( register opj_flag_t *flagsp = &t1->flags[flags_stride + 1]; \ const OPJ_UINT32 l_w = w; \ opj_mqc_t* mqc = &(t1->mqc); \ - DOWNLOAD_MQC_VARIABLES(mqc, curctx, c, a, ct); \ + DOWNLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); \ register OPJ_UINT32 v; \ one = 1 << bpno; \ poshalf = one >> 1; \ @@ -992,7 +1010,7 @@ static void opj_t1_dec_refpass_raw( } \ } \ } \ - UPLOAD_MQC_VARIABLES(mqc, curctx, c, a, ct); \ + UPLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); \ if( k < h ) { \ for (i = 0; i < l_w; ++i, ++data, ++flagsp) { \ for (j = 0; j < h - k; ++j) { \ @@ -1030,86 +1048,71 @@ static void opj_t1_dec_refpass_mqc( /** Encode clean-up pass step */ -static void opj_t1_enc_clnpass_step( - opj_t1_t *t1, - opj_flag_t *flagsp, - OPJ_INT32 *datap, - OPJ_INT32 bpno, - OPJ_INT32 one, - OPJ_INT32 *nmsedec, - OPJ_UINT32 agg, - OPJ_UINT32 runlen, - OPJ_UINT32 lim, - OPJ_UINT32 cblksty) -{ - OPJ_UINT32 v; - OPJ_UINT32 ci; - opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ - - const OPJ_UINT32 check = (T1_SIGMA_4 | T1_SIGMA_7 | T1_SIGMA_10 | T1_SIGMA_13 | - T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3); - - if ((*flagsp & check) == check) { - if (runlen == 0) { - *flagsp &= ~(T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3); - } else if (runlen == 1) { - *flagsp &= ~(T1_PI_1 | T1_PI_2 | T1_PI_3); - } else if (runlen == 2) { - *flagsp &= ~(T1_PI_2 | T1_PI_3); - } else if (runlen == 3) { - *flagsp &= ~(T1_PI_3); - } - return; - } - - for (ci = runlen; ci < lim; ++ci) { - OPJ_UINT32 vsc; - opj_flag_t flags; - OPJ_UINT32 ctxt1; - - flags = *flagsp; - - if ((agg != 0) && (ci == runlen)) { - goto LABEL_PARTIAL; - } - - if (!(flags & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U)))) { - ctxt1 = opj_t1_getctxno_zc(mqc, flags >> (ci * 3U)); -#ifdef DEBUG_ENC_CLN - printf(" ctxt1=%d\n", ctxt1); -#endif - opj_mqc_setcurctx(mqc, ctxt1); - v = (opj_int_abs(*datap) & one) ? 1 : 0; - opj_mqc_encode(mqc, v); - if (v) { - OPJ_UINT32 ctxt2, spb; - OPJ_UINT32 lu; -LABEL_PARTIAL: - lu = opj_t1_getctxtno_sc_or_spb_index( - *flagsp, - flagsp[-1], flagsp[1], - ci); - *nmsedec += opj_t1_getnmsedec_sig((OPJ_UINT32)opj_int_abs(*datap), - (OPJ_UINT32)bpno); - ctxt2 = opj_t1_getctxno_sc(lu); -#ifdef DEBUG_ENC_CLN - printf(" ctxt2=%d\n", ctxt2); -#endif - opj_mqc_setcurctx(mqc, ctxt2); - - v = *datap < 0 ? 1U : 0U; - spb = opj_t1_getspb(lu); -#ifdef DEBUG_ENC_CLN - printf(" spb=%d\n", spb); -#endif - opj_mqc_encode(mqc, v ^ spb); - vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (ci == 0)) ? 1 : 0; - opj_t1_update_flags(flagsp, ci, v, t1->w + 2U, vsc); - } - } - *flagsp &= ~(T1_PI_THIS << (3U * ci)); - datap += t1->data_stride; - } +#define opj_t1_enc_clnpass_step_macro(mqc, curctx, a, c, ct, flagspIn, datapIn, bpno, one, nmsedec, agg, runlen, lim, cblksty) \ +{ \ + OPJ_UINT32 v; \ + OPJ_UINT32 ci; \ + opj_flag_t* const flagsp = (flagspIn); \ + const OPJ_INT32* l_datap = (datapIn); \ + const OPJ_UINT32 check = (T1_SIGMA_4 | T1_SIGMA_7 | T1_SIGMA_10 | T1_SIGMA_13 | \ + T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3); \ + \ + if ((*flagsp & check) == check) { \ + if (runlen == 0) { \ + *flagsp &= ~(T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3); \ + } else if (runlen == 1) { \ + *flagsp &= ~(T1_PI_1 | T1_PI_2 | T1_PI_3); \ + } else if (runlen == 2) { \ + *flagsp &= ~(T1_PI_2 | T1_PI_3); \ + } else if (runlen == 3) { \ + *flagsp &= ~(T1_PI_3); \ + } \ + } \ + else \ + for (ci = runlen; ci < lim; ++ci) { \ + OPJ_BOOL goto_PARTIAL = OPJ_FALSE; \ + if ((agg != 0) && (ci == runlen)) { \ + goto_PARTIAL = OPJ_TRUE; \ + } \ + else if (!(*flagsp & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci * 3U)))) { \ + OPJ_UINT32 ctxt1 = opj_t1_getctxno_zc(mqc, *flagsp >> (ci * 3U)); \ +/* #ifdef DEBUG_ENC_CLN */ \ +/* printf(" ctxt1=%d\n", ctxt1); */ \ +/* #endif */ \ + opj_t1_setcurctx(curctx, ctxt1); \ + v = (opj_smr_abs(*l_datap) & (OPJ_UINT32)one) ? 1 : 0; \ + opj_mqc_encode_macro(mqc, curctx, a, c, ct, v); \ + if (v) { \ + goto_PARTIAL = OPJ_TRUE; \ + } \ + } \ + if( goto_PARTIAL ) { \ + OPJ_UINT32 vsc; \ + OPJ_UINT32 ctxt2, spb; \ + OPJ_UINT32 lu = opj_t1_getctxtno_sc_or_spb_index( \ + *flagsp, \ + flagsp[-1], flagsp[1], \ + ci); \ + *nmsedec += opj_t1_getnmsedec_sig(opj_smr_abs(*l_datap), \ + (OPJ_UINT32)bpno); \ + ctxt2 = opj_t1_getctxno_sc(lu); \ +/* #ifdef DEBUG_ENC_CLN */ \ +/* printf(" ctxt2=%d\n", ctxt2); */ \ +/* #endif */ \ + opj_t1_setcurctx(curctx, ctxt2); \ + \ + v = opj_smr_sign(*l_datap); \ + spb = opj_t1_getspb(lu); \ +/* #ifdef DEBUG_ENC_CLN */ \ +/* printf(" spb=%d\n", spb); */\ +/* #endif */ \ + opj_mqc_encode_macro(mqc, curctx, a, c, ct, v ^ spb); \ + vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (ci == 0)) ? 1 : 0; \ + opj_t1_update_flags(flagsp, ci, v, t1->w + 2U, vsc); \ + } \ + *flagsp &= ~(T1_PI_THIS << (3U * ci)); \ + l_datap ++; \ + } \ } #define opj_t1_dec_clnpass_step_macro(check_flags, partial, \ @@ -1165,47 +1168,50 @@ static void opj_t1_enc_clnpass( { OPJ_UINT32 i, k; const OPJ_INT32 one = 1 << (bpno + T1_NMSEDEC_FRACBITS); - OPJ_UINT32 agg, runlen; - - opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ + opj_mqc_t* mqc = &(t1->mqc); + DOWNLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); + const OPJ_INT32* datap = t1->data; + opj_flag_t *f = &T1_FLAGS(0, 0); + const OPJ_UINT32 extra = 2U; *nmsedec = 0; #ifdef DEBUG_ENC_CLN printf("enc_clnpass: bpno=%d\n", bpno); #endif - for (k = 0; k < (t1->h & ~3U); k += 4) { + for (k = 0; k < (t1->h & ~3U); k += 4, f += extra) { #ifdef DEBUG_ENC_CLN printf(" k=%d\n", k); #endif - for (i = 0; i < t1->w; ++i) { + for (i = 0; i < t1->w; ++i, f++) { + OPJ_UINT32 agg, runlen; #ifdef DEBUG_ENC_CLN printf(" i=%d\n", i); #endif - agg = !(T1_FLAGS(i, k)); + agg = !*f; #ifdef DEBUG_ENC_CLN printf(" agg=%d\n", agg); #endif if (agg) { - for (runlen = 0; runlen < 4; ++runlen) { - if (opj_int_abs(t1->data[((k + runlen)*t1->data_stride) + i]) & one) { + for (runlen = 0; runlen < 4; ++runlen, ++datap) { + if (opj_smr_abs(*datap) & (OPJ_UINT32)one) { break; } } - opj_mqc_setcurctx(mqc, T1_CTXNO_AGG); - opj_mqc_encode(mqc, runlen != 4); + opj_t1_setcurctx(curctx, T1_CTXNO_AGG); + opj_mqc_encode_macro(mqc, curctx, a, c, ct, runlen != 4); if (runlen == 4) { continue; } - opj_mqc_setcurctx(mqc, T1_CTXNO_UNI); - opj_mqc_encode(mqc, runlen >> 1); - opj_mqc_encode(mqc, runlen & 1); + opj_t1_setcurctx(curctx, T1_CTXNO_UNI); + opj_mqc_encode_macro(mqc, curctx, a, c, ct, runlen >> 1); + opj_mqc_encode_macro(mqc, curctx, a, c, ct, runlen & 1); } else { runlen = 0; } - opj_t1_enc_clnpass_step( - t1, - &T1_FLAGS(i, k), - &t1->data[((k + runlen) * t1->data_stride) + i], + opj_t1_enc_clnpass_step_macro( + mqc, curctx, a, c, ct, + f, + datap, bpno, one, nmsedec, @@ -1213,23 +1219,24 @@ static void opj_t1_enc_clnpass( runlen, 4U, cblksty); + datap += 4 - runlen; } } if (k < t1->h) { - agg = 0; - runlen = 0; + const OPJ_UINT32 agg = 0; + const OPJ_UINT32 runlen = 0; #ifdef DEBUG_ENC_CLN printf(" k=%d\n", k); #endif - for (i = 0; i < t1->w; ++i) { + for (i = 0; i < t1->w; ++i, f++) { #ifdef DEBUG_ENC_CLN printf(" i=%d\n", i); printf(" agg=%d\n", agg); #endif - opj_t1_enc_clnpass_step( - t1, - &T1_FLAGS(i, k), - &t1->data[((k + runlen) * t1->data_stride) + i], + opj_t1_enc_clnpass_step_macro( + mqc, curctx, a, c, ct, + f, + datap, bpno, one, nmsedec, @@ -1237,8 +1244,11 @@ static void opj_t1_enc_clnpass( runlen, t1->h - k, cblksty); + datap += t1->h - k; } } + + UPLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); } #define opj_t1_dec_clnpass_internal(t1, bpno, vsc, w, h, flags_stride) \ @@ -1250,7 +1260,7 @@ static void opj_t1_enc_clnpass( opj_mqc_t* mqc = &(t1->mqc); \ register OPJ_INT32 *data = t1->data; \ register opj_flag_t *flagsp = &t1->flags[flags_stride + 1]; \ - DOWNLOAD_MQC_VARIABLES(mqc, curctx, c, a, ct); \ + DOWNLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); \ register OPJ_UINT32 v; \ one = 1 << bpno; \ half = one >> 1; \ @@ -1319,7 +1329,7 @@ static void opj_t1_enc_clnpass( *flagsp = flags & ~(T1_PI_0 | T1_PI_1 | T1_PI_2 | T1_PI_3); \ } \ } \ - UPLOAD_MQC_VARIABLES(mqc, curctx, c, a, ct); \ + UPLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); \ if( k < h ) { \ for (i = 0; i < l_w; ++i, ++flagsp, ++data) { \ for (j = 0; j < h - k; ++j) { \ @@ -1403,7 +1413,6 @@ static void opj_t1_dec_clnpass( } -/** mod fixed_quality */ static OPJ_FLOAT64 opj_t1_getwmsedec( OPJ_INT32 nmsedec, OPJ_UINT32 compno, @@ -1426,7 +1435,11 @@ static OPJ_FLOAT64 opj_t1_getwmsedec( if (qmfbid == 1) { w2 = opj_dwt_getnorm(level, orient); } else { /* if (qmfbid == 0) */ + const OPJ_INT32 log2_gain = (orient == 0) ? 0 : + (orient == 3) ? 2 : 1; w2 = opj_dwt_getnorm_real(level, orient); + /* Not sure this is right. But preserves past behaviour */ + stepsize /= (1 << log2_gain); } wmsedec = w1 * w2 * stepsize * (1 << bpno); @@ -1450,7 +1463,7 @@ static OPJ_BOOL opj_t1_allocate_buffers( assert(w * h <= 4096); /* encoder uses tile buffer, so no need to allocate */ - if (!t1->encoder) { + { OPJ_UINT32 datasize = w * h; if (datasize > t1->datasize) { @@ -1560,8 +1573,7 @@ void opj_t1_destroy(opj_t1_t *p_t1) return; } - /* encoder uses tile buffer, so no need to free */ - if (!p_t1->encoder && p_t1->data) { + if (p_t1->data) { opj_aligned_free(p_t1->data); p_t1->data = 00; } @@ -1618,8 +1630,8 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) cblk_w = (OPJ_UINT32)(cblk->x1 - cblk->x0); cblk_h = (OPJ_UINT32)(cblk->y1 - cblk->y0); - cblk->decoded_data = (OPJ_INT32*)opj_aligned_malloc(cblk_w * cblk_h * sizeof( - OPJ_INT32)); + cblk->decoded_data = (OPJ_INT32*)opj_aligned_malloc(sizeof(OPJ_INT32) * + cblk_w * cblk_h); if (cblk->decoded_data == NULL) { if (job->p_manager_mutex) { opj_mutex_lock(job->p_manager_mutex); @@ -1634,7 +1646,7 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) return; } /* Zero-init required */ - memset(cblk->decoded_data, 0, cblk_w * cblk_h * sizeof(OPJ_INT32)); + memset(cblk->decoded_data, 0, sizeof(OPJ_INT32) * cblk_w * cblk_h); } else if (cblk->decoded_data) { /* Not sure if that code path can happen, but better be */ /* safe than sorry */ @@ -1658,22 +1670,52 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) t1 = (opj_t1_t*) opj_tls_get(tls, OPJ_TLS_KEY_T1); if (t1 == NULL) { t1 = opj_t1_create(OPJ_FALSE); - opj_tls_set(tls, OPJ_TLS_KEY_T1, t1, opj_t1_destroy_wrapper); + if (t1 == NULL) { + opj_event_msg(job->p_manager, EVT_ERROR, + "Cannot allocate Tier 1 handle\n"); + *(job->pret) = OPJ_FALSE; + opj_free(job); + return; + } + if (!opj_tls_set(tls, OPJ_TLS_KEY_T1, t1, opj_t1_destroy_wrapper)) { + opj_event_msg(job->p_manager, EVT_ERROR, + "Unable to set t1 handle as TLS\n"); + opj_t1_destroy(t1); + *(job->pret) = OPJ_FALSE; + opj_free(job); + return; + } } t1->mustuse_cblkdatabuffer = job->mustuse_cblkdatabuffer; - if (OPJ_FALSE == opj_t1_decode_cblk( - t1, - cblk, - band->bandno, - (OPJ_UINT32)tccp->roishift, - tccp->cblksty, - job->p_manager, - job->p_manager_mutex, - job->check_pterm)) { - *(job->pret) = OPJ_FALSE; - opj_free(job); - return; + if ((tccp->cblksty & J2K_CCP_CBLKSTY_HT) != 0) { + if (OPJ_FALSE == opj_t1_ht_decode_cblk( + t1, + cblk, + band->bandno, + (OPJ_UINT32)tccp->roishift, + tccp->cblksty, + job->p_manager, + job->p_manager_mutex, + job->check_pterm)) { + *(job->pret) = OPJ_FALSE; + opj_free(job); + return; + } + } else { + if (OPJ_FALSE == opj_t1_decode_cblk( + t1, + cblk, + band->bandno, + (OPJ_UINT32)tccp->roishift, + tccp->cblksty, + job->p_manager, + job->p_manager_mutex, + job->check_pterm)) { + *(job->pret) = OPJ_FALSE; + opj_free(job); + return; + } } x = cblk->x0 - band->x0; @@ -1725,10 +1767,11 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) datap[i] /= 2; } } else { /* if (tccp->qmfbid == 0) */ + const float stepsize = 0.5f * band->stepsize; i = 0; #ifdef __SSE2__ { - const __m128 xmm_stepsize = _mm_set1_ps(band->stepsize); + const __m128 xmm_stepsize = _mm_set1_ps(stepsize); for (; i < (cblk_size & ~15U); i += 16) { __m128 xmm0_data = _mm_cvtepi32_ps(_mm_load_si128((__m128i * const)( datap + 0))); @@ -1747,7 +1790,7 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) } #endif for (; i < cblk_size; ++i) { - OPJ_FLOAT32 tmp = ((OPJ_FLOAT32)(*datap)) * band->stepsize; + OPJ_FLOAT32 tmp = ((OPJ_FLOAT32)(*datap)) * stepsize; memcpy(datap, &tmp, sizeof(tmp)); datap++; } @@ -1756,6 +1799,39 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) OPJ_INT32* OPJ_RESTRICT tiledp = &tilec->data[(OPJ_SIZE_T)y * tile_w + (OPJ_SIZE_T)x]; for (j = 0; j < cblk_h; ++j) { + //positive -> round down aka. (83)/2 = 41.5 -> 41 + //negative -> round up aka. (-83)/2 = -41.5 -> -41 +#if defined(__AVX512F__) + OPJ_INT32* ptr_in = datap + (j * cblk_w); + OPJ_INT32* ptr_out = tiledp + (j * (OPJ_SIZE_T)tile_w); + for (i = 0; i < cblk_w / 16; ++i) { + __m512i in_avx = _mm512_loadu_si512((__m512i*)(ptr_in)); + const __m512i add_avx = _mm512_srli_epi32(in_avx, 31); + in_avx = _mm512_add_epi32(in_avx, add_avx); + _mm512_storeu_si512((__m512i*)(ptr_out), _mm512_srai_epi32(in_avx, 1)); + ptr_in += 16; + ptr_out += 16; + } + + for (i = 0; i < cblk_w % 16; ++i) { + ptr_out[i] = ptr_in[i] / 2; + } +#elif defined(__AVX2__) + OPJ_INT32* ptr_in = datap + (j * cblk_w); + OPJ_INT32* ptr_out = tiledp + (j * (OPJ_SIZE_T)tile_w); + for (i = 0; i < cblk_w / 8; ++i) { + __m256i in_avx = _mm256_loadu_si256((__m256i*)(ptr_in)); + const __m256i add_avx = _mm256_srli_epi32(in_avx, 31); + in_avx = _mm256_add_epi32(in_avx, add_avx); + _mm256_storeu_si256((__m256i*)(ptr_out), _mm256_srai_epi32(in_avx, 1)); + ptr_in += 8; + ptr_out += 8; + } + + for (i = 0; i < cblk_w % 8; ++i) { + ptr_out[i] = ptr_in[i] / 2; + } +#else i = 0; for (; i < (cblk_w & ~(OPJ_UINT32)3U); i += 4U) { OPJ_INT32 tmp0 = datap[(j * cblk_w) + i + 0U]; @@ -1771,14 +1847,16 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) OPJ_INT32 tmp = datap[(j * cblk_w) + i]; ((OPJ_INT32*)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i] = tmp / 2; } +#endif } } else { /* if (tccp->qmfbid == 0) */ + const float stepsize = 0.5f * band->stepsize; OPJ_FLOAT32* OPJ_RESTRICT tiledp = (OPJ_FLOAT32*) &tilec->data[(OPJ_SIZE_T)y * tile_w + (OPJ_SIZE_T)x]; for (j = 0; j < cblk_h; ++j) { OPJ_FLOAT32* OPJ_RESTRICT tiledp2 = tiledp; for (i = 0; i < cblk_w; ++i) { - OPJ_FLOAT32 tmp = (OPJ_FLOAT32) * datap * band->stepsize; + OPJ_FLOAT32 tmp = (OPJ_FLOAT32) * datap * stepsize; *tiledp2 = tmp; datap++; tiledp2++; @@ -1965,10 +2043,16 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, opj_mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); opj_mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); + if (cblk->corrupted) { + assert(cblk->numchunks == 0); + return OPJ_TRUE; + } + /* Even if we have a single chunk, in multi-threaded decoding */ /* the insertion of our synthetic marker might potentially override */ /* valid codestream of other codeblocks decoded in parallel. */ - if (cblk->numchunks > 1 || t1->mustuse_cblkdatabuffer) { + if (cblk->numchunks > 1 || (t1->mustuse_cblkdatabuffer && + cblk->numchunks > 0)) { OPJ_UINT32 i; OPJ_UINT32 cblk_len; @@ -2083,7 +2167,7 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, opj_mutex_lock(p_manager_mutex); } opj_event_msg(p_manager, EVT_WARNING, - "PTERM check failure: %d synthetized 0xFF markers read\n", + "PTERM check failure: %d synthesized 0xFF markers read\n", mqc->end_of_byte_stream_counter); if (p_manager_mutex) { opj_mutex_unlock(p_manager_mutex); @@ -2100,115 +2184,338 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, } +typedef struct { + OPJ_UINT32 compno; + OPJ_UINT32 resno; + opj_tcd_cblk_enc_t* cblk; + opj_tcd_tile_t *tile; + opj_tcd_band_t* band; + opj_tcd_tilecomp_t* tilec; + opj_tccp_t* tccp; + const OPJ_FLOAT64 * mct_norms; + OPJ_UINT32 mct_numcomps; + volatile OPJ_BOOL* pret; + opj_mutex_t* mutex; +} opj_t1_cblk_encode_processing_job_t; + +/** Procedure to deal with a asynchronous code-block encoding job. + * + * @param user_data Pointer to a opj_t1_cblk_encode_processing_job_t* structure + * @param tls TLS handle. + */ +static void opj_t1_cblk_encode_processor(void* user_data, opj_tls_t* tls) +{ + opj_t1_cblk_encode_processing_job_t* job = + (opj_t1_cblk_encode_processing_job_t*)user_data; + opj_tcd_cblk_enc_t* cblk = job->cblk; + const opj_tcd_band_t* band = job->band; + const opj_tcd_tilecomp_t* tilec = job->tilec; + const opj_tccp_t* tccp = job->tccp; + const OPJ_UINT32 resno = job->resno; + opj_t1_t* t1; + const OPJ_UINT32 tile_w = (OPJ_UINT32)(tilec->x1 - tilec->x0); + + OPJ_INT32* OPJ_RESTRICT tiledp; + OPJ_UINT32 cblk_w; + OPJ_UINT32 cblk_h; + OPJ_UINT32 i, j; + + OPJ_INT32 x = cblk->x0 - band->x0; + OPJ_INT32 y = cblk->y0 - band->y0; + + if (!*(job->pret)) { + opj_free(job); + return; + } + + t1 = (opj_t1_t*) opj_tls_get(tls, OPJ_TLS_KEY_T1); + if (t1 == NULL) { + t1 = opj_t1_create(OPJ_TRUE); /* OPJ_TRUE == T1 for encoding */ + opj_tls_set(tls, OPJ_TLS_KEY_T1, t1, opj_t1_destroy_wrapper); + } + + if (band->bandno & 1) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x += pres->x1 - pres->x0; + } + if (band->bandno & 2) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + y += pres->y1 - pres->y0; + } + + if (!opj_t1_allocate_buffers( + t1, + (OPJ_UINT32)(cblk->x1 - cblk->x0), + (OPJ_UINT32)(cblk->y1 - cblk->y0))) { + *(job->pret) = OPJ_FALSE; + opj_free(job); + return; + } + + cblk_w = t1->w; + cblk_h = t1->h; + tiledp = &tilec->data[(OPJ_SIZE_T)y * tile_w + (OPJ_SIZE_T)x]; + + if (tccp->qmfbid == 1) { + /* Do multiplication on unsigned type, even if the + * underlying type is signed, to avoid potential + * int overflow on large value (the output will be + * incorrect in such situation, but whatever...) + * This assumes complement-to-2 signed integer + * representation + * Fixes https://github.com/uclouvain/openjpeg/issues/1053 + */ + OPJ_UINT32* OPJ_RESTRICT tiledp_u = (OPJ_UINT32*) tiledp; + OPJ_UINT32* OPJ_RESTRICT t1data = (OPJ_UINT32*) t1->data; + /* Change from "natural" order to "zigzag" order of T1 passes */ + for (j = 0; j < (cblk_h & ~3U); j += 4) { +#if defined(__AVX512F__) + const __m512i perm1 = _mm512_setr_epi64(2, 3, 10, 11, 4, 5, 12, 13); + const __m512i perm2 = _mm512_setr_epi64(6, 7, 14, 15, 0, 0, 0, 0); + OPJ_UINT32* ptr = tiledp_u; + for (i = 0; i < cblk_w / 16; ++i) { + // INPUT OUTPUT + // 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33 + // 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37 + // 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B + // 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F + __m512i in1 = _mm512_slli_epi32(_mm512_loadu_si512((__m512i*)(ptr + + (j + 0) * tile_w)), T1_NMSEDEC_FRACBITS); + __m512i in2 = _mm512_slli_epi32(_mm512_loadu_si512((__m512i*)(ptr + + (j + 1) * tile_w)), T1_NMSEDEC_FRACBITS); + __m512i in3 = _mm512_slli_epi32(_mm512_loadu_si512((__m512i*)(ptr + + (j + 2) * tile_w)), T1_NMSEDEC_FRACBITS); + __m512i in4 = _mm512_slli_epi32(_mm512_loadu_si512((__m512i*)(ptr + + (j + 3) * tile_w)), T1_NMSEDEC_FRACBITS); + + __m512i tmp1 = _mm512_unpacklo_epi32(in1, in2); + __m512i tmp2 = _mm512_unpacklo_epi32(in3, in4); + __m512i tmp3 = _mm512_unpackhi_epi32(in1, in2); + __m512i tmp4 = _mm512_unpackhi_epi32(in3, in4); + + in1 = _mm512_unpacklo_epi64(tmp1, tmp2); + in2 = _mm512_unpacklo_epi64(tmp3, tmp4); + in3 = _mm512_unpackhi_epi64(tmp1, tmp2); + in4 = _mm512_unpackhi_epi64(tmp3, tmp4); + + _mm_storeu_si128((__m128i*)(t1data + 0), _mm512_castsi512_si128(in1)); + _mm_storeu_si128((__m128i*)(t1data + 4), _mm512_castsi512_si128(in3)); + _mm_storeu_si128((__m128i*)(t1data + 8), _mm512_castsi512_si128(in2)); + _mm_storeu_si128((__m128i*)(t1data + 12), _mm512_castsi512_si128(in4)); + + tmp1 = _mm512_permutex2var_epi64(in1, perm1, in3); + tmp2 = _mm512_permutex2var_epi64(in2, perm1, in4); + + _mm256_storeu_si256((__m256i*)(t1data + 16), _mm512_castsi512_si256(tmp1)); + _mm256_storeu_si256((__m256i*)(t1data + 24), _mm512_castsi512_si256(tmp2)); + _mm256_storeu_si256((__m256i*)(t1data + 32), _mm512_extracti64x4_epi64(tmp1, + 0x1)); + _mm256_storeu_si256((__m256i*)(t1data + 40), _mm512_extracti64x4_epi64(tmp2, + 0x1)); + _mm256_storeu_si256((__m256i*)(t1data + 48), + _mm512_castsi512_si256(_mm512_permutex2var_epi64(in1, perm2, in3))); + _mm256_storeu_si256((__m256i*)(t1data + 56), + _mm512_castsi512_si256(_mm512_permutex2var_epi64(in2, perm2, in4))); + t1data += 64; + ptr += 16; + } + for (i = 0; i < cblk_w % 16; ++i) { + t1data[0] = ptr[(j + 0) * tile_w] << T1_NMSEDEC_FRACBITS; + t1data[1] = ptr[(j + 1) * tile_w] << T1_NMSEDEC_FRACBITS; + t1data[2] = ptr[(j + 2) * tile_w] << T1_NMSEDEC_FRACBITS; + t1data[3] = ptr[(j + 3) * tile_w] << T1_NMSEDEC_FRACBITS; + t1data += 4; + ptr += 1; + } +#elif defined(__AVX2__) + OPJ_UINT32* ptr = tiledp_u; + for (i = 0; i < cblk_w / 8; ++i) { + // INPUT OUTPUT + // 00 01 02 03 04 05 06 07 00 10 20 30 01 11 21 31 + // 10 11 12 13 14 15 16 17 02 12 22 32 03 13 23 33 + // 20 21 22 23 24 25 26 27 04 14 24 34 05 15 25 35 + // 30 31 32 33 34 35 36 37 06 16 26 36 07 17 27 37 + __m256i in1 = _mm256_slli_epi32(_mm256_loadu_si256((__m256i*)(ptr + + (j + 0) * tile_w)), T1_NMSEDEC_FRACBITS); + __m256i in2 = _mm256_slli_epi32(_mm256_loadu_si256((__m256i*)(ptr + + (j + 1) * tile_w)), T1_NMSEDEC_FRACBITS); + __m256i in3 = _mm256_slli_epi32(_mm256_loadu_si256((__m256i*)(ptr + + (j + 2) * tile_w)), T1_NMSEDEC_FRACBITS); + __m256i in4 = _mm256_slli_epi32(_mm256_loadu_si256((__m256i*)(ptr + + (j + 3) * tile_w)), T1_NMSEDEC_FRACBITS); + + __m256i tmp1 = _mm256_unpacklo_epi32(in1, in2); + __m256i tmp2 = _mm256_unpacklo_epi32(in3, in4); + __m256i tmp3 = _mm256_unpackhi_epi32(in1, in2); + __m256i tmp4 = _mm256_unpackhi_epi32(in3, in4); + + in1 = _mm256_unpacklo_epi64(tmp1, tmp2); + in2 = _mm256_unpacklo_epi64(tmp3, tmp4); + in3 = _mm256_unpackhi_epi64(tmp1, tmp2); + in4 = _mm256_unpackhi_epi64(tmp3, tmp4); + + _mm_storeu_si128((__m128i*)(t1data + 0), _mm256_castsi256_si128(in1)); + _mm_storeu_si128((__m128i*)(t1data + 4), _mm256_castsi256_si128(in3)); + _mm_storeu_si128((__m128i*)(t1data + 8), _mm256_castsi256_si128(in2)); + _mm_storeu_si128((__m128i*)(t1data + 12), _mm256_castsi256_si128(in4)); + _mm256_storeu_si256((__m256i*)(t1data + 16), _mm256_permute2x128_si256(in1, in3, + 0x31)); + _mm256_storeu_si256((__m256i*)(t1data + 24), _mm256_permute2x128_si256(in2, in4, + 0x31)); + t1data += 32; + ptr += 8; + } + for (i = 0; i < cblk_w % 8; ++i) { + t1data[0] = ptr[(j + 0) * tile_w] << T1_NMSEDEC_FRACBITS; + t1data[1] = ptr[(j + 1) * tile_w] << T1_NMSEDEC_FRACBITS; + t1data[2] = ptr[(j + 2) * tile_w] << T1_NMSEDEC_FRACBITS; + t1data[3] = ptr[(j + 3) * tile_w] << T1_NMSEDEC_FRACBITS; + t1data += 4; + ptr += 1; + } +#else + for (i = 0; i < cblk_w; ++i) { + t1data[0] = tiledp_u[(j + 0) * tile_w + i] << T1_NMSEDEC_FRACBITS; + t1data[1] = tiledp_u[(j + 1) * tile_w + i] << T1_NMSEDEC_FRACBITS; + t1data[2] = tiledp_u[(j + 2) * tile_w + i] << T1_NMSEDEC_FRACBITS; + t1data[3] = tiledp_u[(j + 3) * tile_w + i] << T1_NMSEDEC_FRACBITS; + t1data += 4; + } +#endif + } + if (j < cblk_h) { + for (i = 0; i < cblk_w; ++i) { + OPJ_UINT32 k; + for (k = j; k < cblk_h; k++) { + t1data[0] = tiledp_u[k * tile_w + i] << T1_NMSEDEC_FRACBITS; + t1data ++; + } + } + } + } else { /* if (tccp->qmfbid == 0) */ + OPJ_FLOAT32* OPJ_RESTRICT tiledp_f = (OPJ_FLOAT32*) tiledp; + OPJ_INT32* OPJ_RESTRICT t1data = t1->data; + /* Change from "natural" order to "zigzag" order of T1 passes */ + for (j = 0; j < (cblk_h & ~3U); j += 4) { + for (i = 0; i < cblk_w; ++i) { + t1data[0] = (OPJ_INT32)opj_lrintf((tiledp_f[(j + 0) * tile_w + i] / + band->stepsize) * (1 << T1_NMSEDEC_FRACBITS)); + t1data[1] = (OPJ_INT32)opj_lrintf((tiledp_f[(j + 1) * tile_w + i] / + band->stepsize) * (1 << T1_NMSEDEC_FRACBITS)); + t1data[2] = (OPJ_INT32)opj_lrintf((tiledp_f[(j + 2) * tile_w + i] / + band->stepsize) * (1 << T1_NMSEDEC_FRACBITS)); + t1data[3] = (OPJ_INT32)opj_lrintf((tiledp_f[(j + 3) * tile_w + i] / + band->stepsize) * (1 << T1_NMSEDEC_FRACBITS)); + t1data += 4; + } + } + if (j < cblk_h) { + for (i = 0; i < cblk_w; ++i) { + OPJ_UINT32 k; + for (k = j; k < cblk_h; k++) { + t1data[0] = (OPJ_INT32)opj_lrintf((tiledp_f[k * tile_w + i] / band->stepsize) + * (1 << T1_NMSEDEC_FRACBITS)); + t1data ++; + } + } + } + } -OPJ_BOOL opj_t1_encode_cblks(opj_t1_t *t1, + { + OPJ_FLOAT64 cumwmsedec = + opj_t1_encode_cblk( + t1, + cblk, + band->bandno, + job->compno, + tilec->numresolutions - 1 - resno, + tccp->qmfbid, + band->stepsize, + tccp->cblksty, + job->tile->numcomps, + job->mct_norms, + job->mct_numcomps); + if (job->mutex) { + opj_mutex_lock(job->mutex); + } + job->tile->distotile += cumwmsedec; + if (job->mutex) { + opj_mutex_unlock(job->mutex); + } + } + + opj_free(job); +} + + +OPJ_BOOL opj_t1_encode_cblks(opj_tcd_t* tcd, opj_tcd_tile_t *tile, opj_tcp_t *tcp, const OPJ_FLOAT64 * mct_norms, OPJ_UINT32 mct_numcomps ) { + volatile OPJ_BOOL ret = OPJ_TRUE; + opj_thread_pool_t* tp = tcd->thread_pool; OPJ_UINT32 compno, resno, bandno, precno, cblkno; + opj_mutex_t* mutex = opj_mutex_create(); - tile->distotile = 0; /* fixed_quality */ + tile->distotile = 0; for (compno = 0; compno < tile->numcomps; ++compno) { opj_tcd_tilecomp_t* tilec = &tile->comps[compno]; opj_tccp_t* tccp = &tcp->tccps[compno]; - OPJ_UINT32 tile_w = (OPJ_UINT32)(tilec->x1 - tilec->x0); for (resno = 0; resno < tilec->numresolutions; ++resno) { opj_tcd_resolution_t *res = &tilec->resolutions[resno]; for (bandno = 0; bandno < res->numbands; ++bandno) { opj_tcd_band_t* OPJ_RESTRICT band = &res->bands[bandno]; - OPJ_INT32 bandconst; /* Skip empty bands */ if (opj_tcd_is_band_empty(band)) { continue; } - - bandconst = 8192 * 8192 / ((OPJ_INT32) floor(band->stepsize * 8192)); for (precno = 0; precno < res->pw * res->ph; ++precno) { opj_tcd_precinct_t *prc = &band->precincts[precno]; for (cblkno = 0; cblkno < prc->cw * prc->ch; ++cblkno) { opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; - OPJ_INT32* OPJ_RESTRICT tiledp; - OPJ_UINT32 cblk_w; - OPJ_UINT32 cblk_h; - OPJ_UINT32 i, j, tileLineAdvance; - OPJ_SIZE_T tileIndex = 0; - - OPJ_INT32 x = cblk->x0 - band->x0; - OPJ_INT32 y = cblk->y0 - band->y0; - if (band->bandno & 1) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x += pres->x1 - pres->x0; - } - if (band->bandno & 2) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - y += pres->y1 - pres->y0; - } - if (!opj_t1_allocate_buffers( - t1, - (OPJ_UINT32)(cblk->x1 - cblk->x0), - (OPJ_UINT32)(cblk->y1 - cblk->y0))) { - return OPJ_FALSE; + opj_t1_cblk_encode_processing_job_t* job = + (opj_t1_cblk_encode_processing_job_t*) opj_calloc(1, + sizeof(opj_t1_cblk_encode_processing_job_t)); + if (!job) { + ret = OPJ_FALSE; + goto end; } - - cblk_w = t1->w; - cblk_h = t1->h; - tileLineAdvance = tile_w - cblk_w; - - tiledp = &tilec->data[(OPJ_SIZE_T)y * tile_w + (OPJ_SIZE_T)x]; - t1->data = tiledp; - t1->data_stride = tile_w; - if (tccp->qmfbid == 1) { - for (j = 0; j < cblk_h; ++j) { - for (i = 0; i < cblk_w; ++i) { - tiledp[tileIndex] *= (1 << T1_NMSEDEC_FRACBITS); - tileIndex++; - } - tileIndex += tileLineAdvance; - } - } else { /* if (tccp->qmfbid == 0) */ - for (j = 0; j < cblk_h; ++j) { - for (i = 0; i < cblk_w; ++i) { - OPJ_INT32 tmp = tiledp[tileIndex]; - tiledp[tileIndex] = - opj_int_fix_mul_t1( - tmp, - bandconst); - tileIndex++; - } - tileIndex += tileLineAdvance; - } - } - - opj_t1_encode_cblk( - t1, - cblk, - band->bandno, - compno, - tilec->numresolutions - 1 - resno, - tccp->qmfbid, - band->stepsize, - tccp->cblksty, - tile->numcomps, - tile, - mct_norms, - mct_numcomps); + job->compno = compno; + job->tile = tile; + job->resno = resno; + job->cblk = cblk; + job->band = band; + job->tilec = tilec; + job->tccp = tccp; + job->mct_norms = mct_norms; + job->mct_numcomps = mct_numcomps; + job->pret = &ret; + job->mutex = mutex; + opj_thread_pool_submit_job(tp, opj_t1_cblk_encode_processor, job); } /* cblkno */ } /* precno */ } /* bandno */ } /* resno */ } /* compno */ - return OPJ_TRUE; + +end: + opj_thread_pool_wait_completion(tcd->thread_pool, 0); + if (mutex) { + opj_mutex_destroy(mutex); + } + + return ret; } /* Returns whether the pass (bpno, passtype) is terminated */ @@ -2242,19 +2549,17 @@ static int opj_t1_enc_is_term_pass(opj_tcd_cblk_enc_t* cblk, } -/** mod fixed_quality */ -static void opj_t1_encode_cblk(opj_t1_t *t1, - opj_tcd_cblk_enc_t* cblk, - OPJ_UINT32 orient, - OPJ_UINT32 compno, - OPJ_UINT32 level, - OPJ_UINT32 qmfbid, - OPJ_FLOAT64 stepsize, - OPJ_UINT32 cblksty, - OPJ_UINT32 numcomps, - opj_tcd_tile_t * tile, - const OPJ_FLOAT64 * mct_norms, - OPJ_UINT32 mct_numcomps) +static OPJ_FLOAT64 opj_t1_encode_cblk(opj_t1_t *t1, + opj_tcd_cblk_enc_t* cblk, + OPJ_UINT32 orient, + OPJ_UINT32 compno, + OPJ_UINT32 level, + OPJ_UINT32 qmfbid, + OPJ_FLOAT64 stepsize, + OPJ_UINT32 cblksty, + OPJ_UINT32 numcomps, + const OPJ_FLOAT64 * mct_norms, + OPJ_UINT32 mct_numcomps) { OPJ_FLOAT64 cumwmsedec = 0.0; @@ -2268,6 +2573,7 @@ static void opj_t1_encode_cblk(opj_t1_t *t1, OPJ_UINT32 i, j; OPJ_BYTE type = T1_TYPE_MQ; OPJ_FLOAT64 tempwmsedec; + OPJ_INT32* datap; #ifdef EXTRA_DEBUG printf("encode_cblk(x=%d,y=%d,x1=%d,y1=%d,orient=%d,compno=%d,level=%d\n", @@ -2277,10 +2583,26 @@ static void opj_t1_encode_cblk(opj_t1_t *t1, mqc->lut_ctxno_zc_orient = lut_ctxno_zc + (orient << 9); max = 0; - for (i = 0; i < t1->w; ++i) { - for (j = 0; j < t1->h; ++j) { - OPJ_INT32 tmp = abs(t1->data[i + j * t1->data_stride]); - max = opj_int_max(max, tmp); + datap = t1->data; + for (j = 0; j < t1->h; ++j) { + const OPJ_UINT32 w = t1->w; + for (i = 0; i < w; ++i, ++datap) { + OPJ_INT32 tmp = *datap; + if (tmp < 0) { + OPJ_UINT32 tmp_unsigned; + if (tmp == INT_MIN) { + /* To avoid undefined behaviour when negating INT_MIN */ + /* but if we go here, it means we have supplied an input */ + /* with more bit depth than we we can really support. */ + /* Cf https://github.com/uclouvain/openjpeg/issues/1432 */ + tmp = INT_MIN + 1; + } + max = opj_int_max(max, -tmp); + tmp_unsigned = opj_to_smr(tmp); + memcpy(datap, &tmp_unsigned, sizeof(OPJ_INT32)); + } else { + max = opj_int_max(max, tmp); + } } } @@ -2288,7 +2610,7 @@ static void opj_t1_encode_cblk(opj_t1_t *t1, T1_NMSEDEC_FRACBITS) : 0; if (cblk->numbps == 0) { cblk->totalpasses = 0; - return; + return cumwmsedec; } bpno = (OPJ_INT32)(cblk->numbps - 1); @@ -2330,11 +2652,9 @@ static void opj_t1_encode_cblk(opj_t1_t *t1, break; } - /* fixed_quality */ tempwmsedec = opj_t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps, mct_norms, mct_numcomps) ; cumwmsedec += tempwmsedec; - tile->distotile += tempwmsedec; pass->distortiondec = cumwmsedec; if (opj_t1_enc_is_term_pass(cblk, cblksty, bpno, passtype)) { @@ -2416,4 +2736,6 @@ static void opj_t1_encode_cblk(opj_t1_t *t1, } } #endif + + return cumwmsedec; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1.h index 171dfb0a7ae..ce43658ba38 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1.h @@ -198,10 +198,9 @@ typedef struct opj_t1 { OPJ_UINT32 h; OPJ_UINT32 datasize; OPJ_UINT32 flagssize; - OPJ_UINT32 data_stride; OPJ_BOOL encoder; - /* Thre 3 variables below are only used by the decoder */ + /* The 3 variables below are only used by the decoder */ /* set to TRUE in multithreaded context */ OPJ_BOOL mustuse_cblkdatabuffer; /* Temporary buffer to concatenate all chunks of a codebock */ @@ -216,13 +215,13 @@ typedef struct opj_t1 { /** Encode the code-blocks of a tile -@param t1 T1 handle +@param tcd TCD handle @param tile The tile to encode @param tcp Tile coding parameters @param mct_norms FIXME DOC @param mct_numcomps Number of components used for MCT */ -OPJ_BOOL opj_t1_encode_cblks(opj_t1_t *t1, +OPJ_BOOL opj_t1_encode_cblks(opj_tcd_t* tcd, opj_tcd_tile_t *tile, opj_tcp_t *tcp, const OPJ_FLOAT64 * mct_norms, diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1_generate_luts.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1_generate_luts.c index 9ad6f200307..99c8c12fd93 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1_generate_luts.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1_generate_luts.c @@ -39,6 +39,12 @@ #include "opj_includes.h" +// defined elsewhere +extern OPJ_BOOL vlc_init_tables(); +extern OPJ_BOOL vlc_tables_initialized; +extern int vlc_tbl0[1024]; +extern int vlc_tbl1[1024]; + static int t1_init_ctxno_zc(OPJ_UINT32 f, OPJ_UINT32 orient) { int h, v, d, n, t, hv; @@ -307,5 +313,11 @@ int main(int argc, char **argv) printf("static const OPJ_INT16 lut_nmsedec_ref0[1U << T1_NMSEDEC_BITS] = {\n "); dump_array16(lut_nmsedec_ref0, 1U << T1_NMSEDEC_BITS); + vlc_tables_initialized = vlc_init_tables(); + printf("static const OPJ_UINT16 vlc_tbl0[1024] = {\n "); + dump_array16(vlc_tbl0, 1024); + printf("static const OPJ_UINT16 vlc_tbl1[1024] = {\n "); + dump_array16(vlc_tbl1, 1024); + return 0; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1_ht_luts.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1_ht_luts.h new file mode 100644 index 00000000000..393a987b029 --- /dev/null +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t1_ht_luts.h @@ -0,0 +1,261 @@ +static const OPJ_UINT16 vlc_tbl0[1024] = { + 0x0023, 0x00a5, 0x0043, 0x0066, 0x0083, 0xa8ee, 0x0014, 0xd8df, + 0x0023, 0x10be, 0x0043, 0xf5ff, 0x0083, 0x207e, 0x0055, 0x515f, + 0x0023, 0x0035, 0x0043, 0x444e, 0x0083, 0xc4ce, 0x0014, 0xcccf, + 0x0023, 0xe2fe, 0x0043, 0x99ff, 0x0083, 0x0096, 0x00c5, 0x313f, + 0x0023, 0x00a5, 0x0043, 0x445e, 0x0083, 0xc8ce, 0x0014, 0x11df, + 0x0023, 0xf4fe, 0x0043, 0xfcff, 0x0083, 0x009e, 0x0055, 0x0077, + 0x0023, 0x0035, 0x0043, 0xf1ff, 0x0083, 0x88ae, 0x0014, 0x00b7, + 0x0023, 0xf8fe, 0x0043, 0xe4ef, 0x0083, 0x888e, 0x00c5, 0x111f, + 0x0023, 0x00a5, 0x0043, 0x0066, 0x0083, 0xa8ee, 0x0014, 0x54df, + 0x0023, 0x10be, 0x0043, 0x22ef, 0x0083, 0x207e, 0x0055, 0x227f, + 0x0023, 0x0035, 0x0043, 0x444e, 0x0083, 0xc4ce, 0x0014, 0x11bf, + 0x0023, 0xe2fe, 0x0043, 0x00f7, 0x0083, 0x0096, 0x00c5, 0x223f, + 0x0023, 0x00a5, 0x0043, 0x445e, 0x0083, 0xc8ce, 0x0014, 0x00d7, + 0x0023, 0xf4fe, 0x0043, 0xbaff, 0x0083, 0x009e, 0x0055, 0x006f, + 0x0023, 0x0035, 0x0043, 0xe6ff, 0x0083, 0x88ae, 0x0014, 0xa2af, + 0x0023, 0xf8fe, 0x0043, 0x00e7, 0x0083, 0x888e, 0x00c5, 0x222f, + 0x0002, 0x00c5, 0x0084, 0x207e, 0x0002, 0xc4ce, 0x0024, 0x00f7, + 0x0002, 0xa2fe, 0x0044, 0x0056, 0x0002, 0x009e, 0x0014, 0x00d7, + 0x0002, 0x10be, 0x0084, 0x0066, 0x0002, 0x88ae, 0x0024, 0x11df, + 0x0002, 0xa8ee, 0x0044, 0x0036, 0x0002, 0x888e, 0x0014, 0x111f, + 0x0002, 0x00c5, 0x0084, 0x006e, 0x0002, 0x88ce, 0x0024, 0x88ff, + 0x0002, 0xb8fe, 0x0044, 0x444e, 0x0002, 0x0096, 0x0014, 0x00b7, + 0x0002, 0xe4fe, 0x0084, 0x445e, 0x0002, 0x00a6, 0x0024, 0x00e7, + 0x0002, 0x54de, 0x0044, 0x222e, 0x0002, 0x003e, 0x0014, 0x0077, + 0x0002, 0x00c5, 0x0084, 0x207e, 0x0002, 0xc4ce, 0x0024, 0xf1ff, + 0x0002, 0xa2fe, 0x0044, 0x0056, 0x0002, 0x009e, 0x0014, 0x11bf, + 0x0002, 0x10be, 0x0084, 0x0066, 0x0002, 0x88ae, 0x0024, 0x22ef, + 0x0002, 0xa8ee, 0x0044, 0x0036, 0x0002, 0x888e, 0x0014, 0x227f, + 0x0002, 0x00c5, 0x0084, 0x006e, 0x0002, 0x88ce, 0x0024, 0xe4ef, + 0x0002, 0xb8fe, 0x0044, 0x444e, 0x0002, 0x0096, 0x0014, 0xa2af, + 0x0002, 0xe4fe, 0x0084, 0x445e, 0x0002, 0x00a6, 0x0024, 0xd8df, + 0x0002, 0x54de, 0x0044, 0x222e, 0x0002, 0x003e, 0x0014, 0x515f, + 0x0002, 0x0055, 0x0084, 0x0066, 0x0002, 0x88de, 0x0024, 0x32ff, + 0x0002, 0x11fe, 0x0044, 0x444e, 0x0002, 0x00ae, 0x0014, 0x00b7, + 0x0002, 0x317e, 0x0084, 0x515e, 0x0002, 0x00c6, 0x0024, 0x00d7, + 0x0002, 0x20ee, 0x0044, 0x111e, 0x0002, 0x009e, 0x0014, 0x0077, + 0x0002, 0x0055, 0x0084, 0x545e, 0x0002, 0x44ce, 0x0024, 0x00e7, + 0x0002, 0xf1fe, 0x0044, 0x0036, 0x0002, 0x00a6, 0x0014, 0x555f, + 0x0002, 0x74fe, 0x0084, 0x113e, 0x0002, 0x20be, 0x0024, 0x747f, + 0x0002, 0xc4de, 0x0044, 0xf8ff, 0x0002, 0x0096, 0x0014, 0x222f, + 0x0002, 0x0055, 0x0084, 0x0066, 0x0002, 0x88de, 0x0024, 0x00f7, + 0x0002, 0x11fe, 0x0044, 0x444e, 0x0002, 0x00ae, 0x0014, 0x888f, + 0x0002, 0x317e, 0x0084, 0x515e, 0x0002, 0x00c6, 0x0024, 0xc8cf, + 0x0002, 0x20ee, 0x0044, 0x111e, 0x0002, 0x009e, 0x0014, 0x006f, + 0x0002, 0x0055, 0x0084, 0x545e, 0x0002, 0x44ce, 0x0024, 0xd1df, + 0x0002, 0xf1fe, 0x0044, 0x0036, 0x0002, 0x00a6, 0x0014, 0x227f, + 0x0002, 0x74fe, 0x0084, 0x113e, 0x0002, 0x20be, 0x0024, 0x22bf, + 0x0002, 0xc4de, 0x0044, 0x22ef, 0x0002, 0x0096, 0x0014, 0x323f, + 0x0003, 0xd4de, 0xf4fd, 0xfcff, 0x0014, 0x113e, 0x0055, 0x888f, + 0x0003, 0x32be, 0x0085, 0x00e7, 0x0025, 0x515e, 0xaafe, 0x727f, + 0x0003, 0x44ce, 0xf8fd, 0x44ef, 0x0014, 0x647e, 0x0045, 0xa2af, + 0x0003, 0x00a6, 0x555d, 0x99df, 0xf1fd, 0x0036, 0xf5fe, 0x626f, + 0x0003, 0xd1de, 0xf4fd, 0xe6ff, 0x0014, 0x717e, 0x0055, 0xb1bf, + 0x0003, 0x88ae, 0x0085, 0xd5df, 0x0025, 0x444e, 0xf2fe, 0x667f, + 0x0003, 0x00c6, 0xf8fd, 0xe2ef, 0x0014, 0x545e, 0x0045, 0x119f, + 0x0003, 0x0096, 0x555d, 0xc8cf, 0xf1fd, 0x111e, 0xc8ee, 0x0067, + 0x0003, 0xd4de, 0xf4fd, 0xf3ff, 0x0014, 0x113e, 0x0055, 0x11bf, + 0x0003, 0x32be, 0x0085, 0xd8df, 0x0025, 0x515e, 0xaafe, 0x222f, + 0x0003, 0x44ce, 0xf8fd, 0x00f7, 0x0014, 0x647e, 0x0045, 0x989f, + 0x0003, 0x00a6, 0x555d, 0x00d7, 0xf1fd, 0x0036, 0xf5fe, 0x446f, + 0x0003, 0xd1de, 0xf4fd, 0xb9ff, 0x0014, 0x717e, 0x0055, 0x00b7, + 0x0003, 0x88ae, 0x0085, 0xdcdf, 0x0025, 0x444e, 0xf2fe, 0x0077, + 0x0003, 0x00c6, 0xf8fd, 0xe4ef, 0x0014, 0x545e, 0x0045, 0x737f, + 0x0003, 0x0096, 0x555d, 0xb8bf, 0xf1fd, 0x111e, 0xc8ee, 0x323f, + 0x0002, 0x00a5, 0x0084, 0x407e, 0x0002, 0x10de, 0x0024, 0x11df, + 0x0002, 0x72fe, 0x0044, 0x0056, 0x0002, 0xa8ae, 0x0014, 0xb2bf, + 0x0002, 0x0096, 0x0084, 0x0066, 0x0002, 0x00c6, 0x0024, 0x00e7, + 0x0002, 0xc8ee, 0x0044, 0x222e, 0x0002, 0x888e, 0x0014, 0x0077, + 0x0002, 0x00a5, 0x0084, 0x006e, 0x0002, 0x88ce, 0x0024, 0x00f7, + 0x0002, 0x91fe, 0x0044, 0x0036, 0x0002, 0xa2ae, 0x0014, 0xaaaf, + 0x0002, 0xb8fe, 0x0084, 0x005e, 0x0002, 0x00be, 0x0024, 0xc4cf, + 0x0002, 0x44ee, 0x0044, 0xf4ff, 0x0002, 0x223e, 0x0014, 0x111f, + 0x0002, 0x00a5, 0x0084, 0x407e, 0x0002, 0x10de, 0x0024, 0x99ff, + 0x0002, 0x72fe, 0x0044, 0x0056, 0x0002, 0xa8ae, 0x0014, 0x00b7, + 0x0002, 0x0096, 0x0084, 0x0066, 0x0002, 0x00c6, 0x0024, 0x00d7, + 0x0002, 0xc8ee, 0x0044, 0x222e, 0x0002, 0x888e, 0x0014, 0x444f, + 0x0002, 0x00a5, 0x0084, 0x006e, 0x0002, 0x88ce, 0x0024, 0xe2ef, + 0x0002, 0x91fe, 0x0044, 0x0036, 0x0002, 0xa2ae, 0x0014, 0x447f, + 0x0002, 0xb8fe, 0x0084, 0x005e, 0x0002, 0x00be, 0x0024, 0x009f, + 0x0002, 0x44ee, 0x0044, 0x76ff, 0x0002, 0x223e, 0x0014, 0x313f, + 0x0003, 0x00c6, 0x0085, 0xd9ff, 0xf2fd, 0x647e, 0xf1fe, 0x99bf, + 0x0003, 0xa2ae, 0x0025, 0x66ef, 0xf4fd, 0x0056, 0xe2ee, 0x737f, + 0x0003, 0x98be, 0x0045, 0x00f7, 0xf8fd, 0x0066, 0x76fe, 0x889f, + 0x0003, 0x888e, 0x0015, 0xd5df, 0x00a5, 0x222e, 0x98de, 0x444f, + 0x0003, 0xb2be, 0x0085, 0xfcff, 0xf2fd, 0x226e, 0x0096, 0x00b7, + 0x0003, 0xaaae, 0x0025, 0xd1df, 0xf4fd, 0x0036, 0xd4de, 0x646f, + 0x0003, 0xa8ae, 0x0045, 0xeaef, 0xf8fd, 0x445e, 0xe8ee, 0x717f, + 0x0003, 0x323e, 0x0015, 0xc4cf, 0x00a5, 0xfaff, 0x88ce, 0x313f, + 0x0003, 0x00c6, 0x0085, 0x77ff, 0xf2fd, 0x647e, 0xf1fe, 0xb3bf, + 0x0003, 0xa2ae, 0x0025, 0x00e7, 0xf4fd, 0x0056, 0xe2ee, 0x0077, + 0x0003, 0x98be, 0x0045, 0xe4ef, 0xf8fd, 0x0066, 0x76fe, 0x667f, + 0x0003, 0x888e, 0x0015, 0x00d7, 0x00a5, 0x222e, 0x98de, 0x333f, + 0x0003, 0xb2be, 0x0085, 0x75ff, 0xf2fd, 0x226e, 0x0096, 0x919f, + 0x0003, 0xaaae, 0x0025, 0x99df, 0xf4fd, 0x0036, 0xd4de, 0x515f, + 0x0003, 0xa8ae, 0x0045, 0xecef, 0xf8fd, 0x445e, 0xe8ee, 0x727f, + 0x0003, 0x323e, 0x0015, 0xb1bf, 0x00a5, 0xf3ff, 0x88ce, 0x111f, + 0x0003, 0x54de, 0xf2fd, 0x111e, 0x0014, 0x647e, 0xf8fe, 0xcccf, + 0x0003, 0x91be, 0x0045, 0x22ef, 0x0025, 0x222e, 0xf3fe, 0x888f, + 0x0003, 0x00c6, 0x0085, 0x00f7, 0x0014, 0x115e, 0xfcfe, 0xa8af, + 0x0003, 0x00a6, 0x0035, 0xc8df, 0xf1fd, 0x313e, 0x66fe, 0x646f, + 0x0003, 0xc8ce, 0xf2fd, 0xf5ff, 0x0014, 0x0066, 0xf4fe, 0xbabf, + 0x0003, 0x22ae, 0x0045, 0x00e7, 0x0025, 0x323e, 0xeafe, 0x737f, + 0x0003, 0xb2be, 0x0085, 0x55df, 0x0014, 0x0056, 0x717e, 0x119f, + 0x0003, 0x0096, 0x0035, 0xc4cf, 0xf1fd, 0x333e, 0xe8ee, 0x444f, + 0x0003, 0x54de, 0xf2fd, 0x111e, 0x0014, 0x647e, 0xf8fe, 0x99bf, + 0x0003, 0x91be, 0x0045, 0xe2ef, 0x0025, 0x222e, 0xf3fe, 0x667f, + 0x0003, 0x00c6, 0x0085, 0xe4ef, 0x0014, 0x115e, 0xfcfe, 0x989f, + 0x0003, 0x00a6, 0x0035, 0x00d7, 0xf1fd, 0x313e, 0x66fe, 0x226f, + 0x0003, 0xc8ce, 0xf2fd, 0xb9ff, 0x0014, 0x0066, 0xf4fe, 0x00b7, + 0x0003, 0x22ae, 0x0045, 0xd1df, 0x0025, 0x323e, 0xeafe, 0x0077, + 0x0003, 0xb2be, 0x0085, 0xecef, 0x0014, 0x0056, 0x717e, 0x727f, + 0x0003, 0x0096, 0x0035, 0xb8bf, 0xf1fd, 0x333e, 0xe8ee, 0x545f, + 0xf1fc, 0xd1de, 0xfafd, 0x00d7, 0xf8fc, 0x0016, 0xfffd, 0x747f, + 0xf4fc, 0x717e, 0xf3fd, 0xb3bf, 0xf2fc, 0xeaef, 0xe8ee, 0x444f, + 0xf1fc, 0x22ae, 0x0005, 0xb8bf, 0xf8fc, 0x00f7, 0xfcfe, 0x0077, + 0xf4fc, 0x115e, 0xf5fd, 0x757f, 0xf2fc, 0xd8df, 0xe2ee, 0x333f, + 0xf1fc, 0xb2be, 0xfafd, 0x88cf, 0xf8fc, 0xfbff, 0xfffd, 0x737f, + 0xf4fc, 0x006e, 0xf3fd, 0x00b7, 0xf2fc, 0x66ef, 0xf9fe, 0x313f, + 0xf1fc, 0x009e, 0x0005, 0xbabf, 0xf8fc, 0xfdff, 0xf6fe, 0x0067, + 0xf4fc, 0x0026, 0xf5fd, 0x888f, 0xf2fc, 0xdcdf, 0xd4de, 0x222f, + 0xf1fc, 0xd1de, 0xfafd, 0xc4cf, 0xf8fc, 0x0016, 0xfffd, 0x727f, + 0xf4fc, 0x717e, 0xf3fd, 0x99bf, 0xf2fc, 0xecef, 0xe8ee, 0x0047, + 0xf1fc, 0x22ae, 0x0005, 0x00a7, 0xf8fc, 0xf7ff, 0xfcfe, 0x0057, + 0xf4fc, 0x115e, 0xf5fd, 0x0097, 0xf2fc, 0xd5df, 0xe2ee, 0x0037, + 0xf1fc, 0xb2be, 0xfafd, 0x00c7, 0xf8fc, 0xfeff, 0xfffd, 0x667f, + 0xf4fc, 0x006e, 0xf3fd, 0xa8af, 0xf2fc, 0x00e7, 0xf9fe, 0x323f, + 0xf1fc, 0x009e, 0x0005, 0xb1bf, 0xf8fc, 0xe4ef, 0xf6fe, 0x545f, + 0xf4fc, 0x0026, 0xf5fd, 0x0087, 0xf2fc, 0x99df, 0xd4de, 0x111f +}; + +static const OPJ_UINT16 vlc_tbl1[1024] = { + 0x0013, 0x0065, 0x0043, 0x00de, 0x0083, 0x888d, 0x0023, 0x444e, + 0x0013, 0x00a5, 0x0043, 0x88ae, 0x0083, 0x0035, 0x0023, 0x00d7, + 0x0013, 0x00c5, 0x0043, 0x009e, 0x0083, 0x0055, 0x0023, 0x222e, + 0x0013, 0x0095, 0x0043, 0x007e, 0x0083, 0x10fe, 0x0023, 0x0077, + 0x0013, 0x0065, 0x0043, 0x88ce, 0x0083, 0x888d, 0x0023, 0x111e, + 0x0013, 0x00a5, 0x0043, 0x005e, 0x0083, 0x0035, 0x0023, 0x00e7, + 0x0013, 0x00c5, 0x0043, 0x00be, 0x0083, 0x0055, 0x0023, 0x11ff, + 0x0013, 0x0095, 0x0043, 0x003e, 0x0083, 0x40ee, 0x0023, 0xa2af, + 0x0013, 0x0065, 0x0043, 0x00de, 0x0083, 0x888d, 0x0023, 0x444e, + 0x0013, 0x00a5, 0x0043, 0x88ae, 0x0083, 0x0035, 0x0023, 0x44ef, + 0x0013, 0x00c5, 0x0043, 0x009e, 0x0083, 0x0055, 0x0023, 0x222e, + 0x0013, 0x0095, 0x0043, 0x007e, 0x0083, 0x10fe, 0x0023, 0x00b7, + 0x0013, 0x0065, 0x0043, 0x88ce, 0x0083, 0x888d, 0x0023, 0x111e, + 0x0013, 0x00a5, 0x0043, 0x005e, 0x0083, 0x0035, 0x0023, 0xc4cf, + 0x0013, 0x00c5, 0x0043, 0x00be, 0x0083, 0x0055, 0x0023, 0x00f7, + 0x0013, 0x0095, 0x0043, 0x003e, 0x0083, 0x40ee, 0x0023, 0x006f, + 0x0001, 0x0084, 0x0001, 0x0056, 0x0001, 0x0014, 0x0001, 0x00d7, + 0x0001, 0x0024, 0x0001, 0x0096, 0x0001, 0x0045, 0x0001, 0x0077, + 0x0001, 0x0084, 0x0001, 0x00c6, 0x0001, 0x0014, 0x0001, 0x888f, + 0x0001, 0x0024, 0x0001, 0x00f7, 0x0001, 0x0035, 0x0001, 0x222f, + 0x0001, 0x0084, 0x0001, 0x40fe, 0x0001, 0x0014, 0x0001, 0x00b7, + 0x0001, 0x0024, 0x0001, 0x00bf, 0x0001, 0x0045, 0x0001, 0x0067, + 0x0001, 0x0084, 0x0001, 0x00a6, 0x0001, 0x0014, 0x0001, 0x444f, + 0x0001, 0x0024, 0x0001, 0x00e7, 0x0001, 0x0035, 0x0001, 0x113f, + 0x0001, 0x0084, 0x0001, 0x0056, 0x0001, 0x0014, 0x0001, 0x00cf, + 0x0001, 0x0024, 0x0001, 0x0096, 0x0001, 0x0045, 0x0001, 0x006f, + 0x0001, 0x0084, 0x0001, 0x00c6, 0x0001, 0x0014, 0x0001, 0x009f, + 0x0001, 0x0024, 0x0001, 0x00ef, 0x0001, 0x0035, 0x0001, 0x323f, + 0x0001, 0x0084, 0x0001, 0x40fe, 0x0001, 0x0014, 0x0001, 0x00af, + 0x0001, 0x0024, 0x0001, 0x44ff, 0x0001, 0x0045, 0x0001, 0x005f, + 0x0001, 0x0084, 0x0001, 0x00a6, 0x0001, 0x0014, 0x0001, 0x007f, + 0x0001, 0x0024, 0x0001, 0x00df, 0x0001, 0x0035, 0x0001, 0x111f, + 0x0001, 0x0024, 0x0001, 0x0056, 0x0001, 0x0085, 0x0001, 0x00bf, + 0x0001, 0x0014, 0x0001, 0x00f7, 0x0001, 0x00c6, 0x0001, 0x0077, + 0x0001, 0x0024, 0x0001, 0xf8ff, 0x0001, 0x0045, 0x0001, 0x007f, + 0x0001, 0x0014, 0x0001, 0x00df, 0x0001, 0x00a6, 0x0001, 0x313f, + 0x0001, 0x0024, 0x0001, 0x222e, 0x0001, 0x0085, 0x0001, 0x00b7, + 0x0001, 0x0014, 0x0001, 0x44ef, 0x0001, 0xa2ae, 0x0001, 0x0067, + 0x0001, 0x0024, 0x0001, 0x51ff, 0x0001, 0x0045, 0x0001, 0x0097, + 0x0001, 0x0014, 0x0001, 0x00cf, 0x0001, 0x0036, 0x0001, 0x223f, + 0x0001, 0x0024, 0x0001, 0x0056, 0x0001, 0x0085, 0x0001, 0xb2bf, + 0x0001, 0x0014, 0x0001, 0x40ef, 0x0001, 0x00c6, 0x0001, 0x006f, + 0x0001, 0x0024, 0x0001, 0x72ff, 0x0001, 0x0045, 0x0001, 0x009f, + 0x0001, 0x0014, 0x0001, 0x00d7, 0x0001, 0x00a6, 0x0001, 0x444f, + 0x0001, 0x0024, 0x0001, 0x222e, 0x0001, 0x0085, 0x0001, 0xa8af, + 0x0001, 0x0014, 0x0001, 0x00e7, 0x0001, 0xa2ae, 0x0001, 0x005f, + 0x0001, 0x0024, 0x0001, 0x44ff, 0x0001, 0x0045, 0x0001, 0x888f, + 0x0001, 0x0014, 0x0001, 0xaaaf, 0x0001, 0x0036, 0x0001, 0x111f, + 0x0002, 0xf8fe, 0x0024, 0x0056, 0x0002, 0x00b6, 0x0085, 0x66ff, + 0x0002, 0x00ce, 0x0014, 0x111e, 0x0002, 0x0096, 0x0035, 0xa8af, + 0x0002, 0x00f6, 0x0024, 0x313e, 0x0002, 0x00a6, 0x0045, 0xb3bf, + 0x0002, 0xb2be, 0x0014, 0xf5ff, 0x0002, 0x0066, 0x517e, 0x545f, + 0x0002, 0xf2fe, 0x0024, 0x222e, 0x0002, 0x22ae, 0x0085, 0x44ef, + 0x0002, 0x00c6, 0x0014, 0xf4ff, 0x0002, 0x0076, 0x0035, 0x447f, + 0x0002, 0x40de, 0x0024, 0x323e, 0x0002, 0x009e, 0x0045, 0x00d7, + 0x0002, 0x88be, 0x0014, 0xfaff, 0x0002, 0x115e, 0xf1fe, 0x444f, + 0x0002, 0xf8fe, 0x0024, 0x0056, 0x0002, 0x00b6, 0x0085, 0xc8ef, + 0x0002, 0x00ce, 0x0014, 0x111e, 0x0002, 0x0096, 0x0035, 0x888f, + 0x0002, 0x00f6, 0x0024, 0x313e, 0x0002, 0x00a6, 0x0045, 0x44df, + 0x0002, 0xb2be, 0x0014, 0xa8ff, 0x0002, 0x0066, 0x517e, 0x006f, + 0x0002, 0xf2fe, 0x0024, 0x222e, 0x0002, 0x22ae, 0x0085, 0x00e7, + 0x0002, 0x00c6, 0x0014, 0xe2ef, 0x0002, 0x0076, 0x0035, 0x727f, + 0x0002, 0x40de, 0x0024, 0x323e, 0x0002, 0x009e, 0x0045, 0xb1bf, + 0x0002, 0x88be, 0x0014, 0x73ff, 0x0002, 0x115e, 0xf1fe, 0x333f, + 0x0001, 0x0084, 0x0001, 0x20ee, 0x0001, 0x00c5, 0x0001, 0xc4cf, + 0x0001, 0x0044, 0x0001, 0x32ff, 0x0001, 0x0015, 0x0001, 0x888f, + 0x0001, 0x0084, 0x0001, 0x0066, 0x0001, 0x0025, 0x0001, 0x00af, + 0x0001, 0x0044, 0x0001, 0x22ef, 0x0001, 0x00a6, 0x0001, 0x005f, + 0x0001, 0x0084, 0x0001, 0x444e, 0x0001, 0x00c5, 0x0001, 0xcccf, + 0x0001, 0x0044, 0x0001, 0x00f7, 0x0001, 0x0015, 0x0001, 0x006f, + 0x0001, 0x0084, 0x0001, 0x0056, 0x0001, 0x0025, 0x0001, 0x009f, + 0x0001, 0x0044, 0x0001, 0x00df, 0x0001, 0x30fe, 0x0001, 0x222f, + 0x0001, 0x0084, 0x0001, 0x20ee, 0x0001, 0x00c5, 0x0001, 0xc8cf, + 0x0001, 0x0044, 0x0001, 0x11ff, 0x0001, 0x0015, 0x0001, 0x0077, + 0x0001, 0x0084, 0x0001, 0x0066, 0x0001, 0x0025, 0x0001, 0x007f, + 0x0001, 0x0044, 0x0001, 0x00e7, 0x0001, 0x00a6, 0x0001, 0x0037, + 0x0001, 0x0084, 0x0001, 0x444e, 0x0001, 0x00c5, 0x0001, 0x00b7, + 0x0001, 0x0044, 0x0001, 0x00bf, 0x0001, 0x0015, 0x0001, 0x003f, + 0x0001, 0x0084, 0x0001, 0x0056, 0x0001, 0x0025, 0x0001, 0x0097, + 0x0001, 0x0044, 0x0001, 0x00d7, 0x0001, 0x30fe, 0x0001, 0x111f, + 0x0002, 0xa8ee, 0x0044, 0x888e, 0x0002, 0x00d6, 0x00c5, 0xf3ff, + 0x0002, 0xfcfe, 0x0025, 0x003e, 0x0002, 0x00b6, 0x0055, 0xd8df, + 0x0002, 0xf8fe, 0x0044, 0x0066, 0x0002, 0x207e, 0x0085, 0x99ff, + 0x0002, 0x00e6, 0x00f5, 0x0036, 0x0002, 0x00a6, 0x0015, 0x009f, + 0x0002, 0xf2fe, 0x0044, 0x0076, 0x0002, 0x44ce, 0x00c5, 0x76ff, + 0x0002, 0xf1fe, 0x0025, 0x444e, 0x0002, 0x00ae, 0x0055, 0xc8cf, + 0x0002, 0xf4fe, 0x0044, 0x445e, 0x0002, 0x10be, 0x0085, 0xe4ef, + 0x0002, 0x54de, 0x00f5, 0x111e, 0x0002, 0x0096, 0x0015, 0x222f, + 0x0002, 0xa8ee, 0x0044, 0x888e, 0x0002, 0x00d6, 0x00c5, 0xfaff, + 0x0002, 0xfcfe, 0x0025, 0x003e, 0x0002, 0x00b6, 0x0055, 0x11bf, + 0x0002, 0xf8fe, 0x0044, 0x0066, 0x0002, 0x207e, 0x0085, 0x22ef, + 0x0002, 0x00e6, 0x00f5, 0x0036, 0x0002, 0x00a6, 0x0015, 0x227f, + 0x0002, 0xf2fe, 0x0044, 0x0076, 0x0002, 0x44ce, 0x00c5, 0xd5ff, + 0x0002, 0xf1fe, 0x0025, 0x444e, 0x0002, 0x00ae, 0x0055, 0x006f, + 0x0002, 0xf4fe, 0x0044, 0x445e, 0x0002, 0x10be, 0x0085, 0x11df, + 0x0002, 0x54de, 0x00f5, 0x111e, 0x0002, 0x0096, 0x0015, 0x515f, + 0x0003, 0x00f6, 0x0014, 0x111e, 0x0044, 0x888e, 0x00a5, 0xd4df, + 0x0003, 0xa2ae, 0x0055, 0x76ff, 0x0024, 0x223e, 0x00b6, 0xaaaf, + 0x0003, 0x00e6, 0x0014, 0xf5ff, 0x0044, 0x0066, 0x0085, 0xcccf, + 0x0003, 0x009e, 0x00c5, 0x44ef, 0x0024, 0x0036, 0xf8fe, 0x317f, + 0x0003, 0xe8ee, 0x0014, 0xf1ff, 0x0044, 0x0076, 0x00a5, 0xc4cf, + 0x0003, 0x227e, 0x0055, 0xd1df, 0x0024, 0x444e, 0xf4fe, 0x515f, + 0x0003, 0x00d6, 0x0014, 0xe2ef, 0x0044, 0x445e, 0x0085, 0x22bf, + 0x0003, 0x0096, 0x00c5, 0xc8df, 0x0024, 0x222e, 0xf2fe, 0x226f, + 0x0003, 0x00f6, 0x0014, 0x111e, 0x0044, 0x888e, 0x00a5, 0xb1bf, + 0x0003, 0xa2ae, 0x0055, 0x33ff, 0x0024, 0x223e, 0x00b6, 0xa8af, + 0x0003, 0x00e6, 0x0014, 0xb9ff, 0x0044, 0x0066, 0x0085, 0xa8bf, + 0x0003, 0x009e, 0x00c5, 0xe4ef, 0x0024, 0x0036, 0xf8fe, 0x646f, + 0x0003, 0xe8ee, 0x0014, 0xfcff, 0x0044, 0x0076, 0x00a5, 0xc8cf, + 0x0003, 0x227e, 0x0055, 0xeaef, 0x0024, 0x444e, 0xf4fe, 0x747f, + 0x0003, 0x00d6, 0x0014, 0xfaff, 0x0044, 0x445e, 0x0085, 0xb2bf, + 0x0003, 0x0096, 0x00c5, 0x44df, 0x0024, 0x222e, 0xf2fe, 0x313f, + 0x00f3, 0xfafe, 0xf1fd, 0x0036, 0x0004, 0x32be, 0x0075, 0x11df, + 0x00f3, 0x54de, 0xf2fd, 0xe4ef, 0x00d5, 0x717e, 0xfcfe, 0x737f, + 0x00f3, 0xf3fe, 0xf8fd, 0x111e, 0x0004, 0x0096, 0x0055, 0xb1bf, + 0x00f3, 0x00ce, 0x00b5, 0xd8df, 0xf4fd, 0x0066, 0xb9fe, 0x545f, + 0x00f3, 0x76fe, 0xf1fd, 0x0026, 0x0004, 0x00a6, 0x0075, 0x009f, + 0x00f3, 0x00ae, 0xf2fd, 0xf7ff, 0x00d5, 0x0046, 0xf5fe, 0x747f, + 0x00f3, 0x00e6, 0xf8fd, 0x0016, 0x0004, 0x0086, 0x0055, 0x888f, + 0x00f3, 0x00c6, 0x00b5, 0xe2ef, 0xf4fd, 0x115e, 0xa8ee, 0x113f, + 0x00f3, 0xfafe, 0xf1fd, 0x0036, 0x0004, 0x32be, 0x0075, 0xd1df, + 0x00f3, 0x54de, 0xf2fd, 0xfbff, 0x00d5, 0x717e, 0xfcfe, 0x447f, + 0x00f3, 0xf3fe, 0xf8fd, 0x111e, 0x0004, 0x0096, 0x0055, 0x727f, + 0x00f3, 0x00ce, 0x00b5, 0x22ef, 0xf4fd, 0x0066, 0xb9fe, 0x444f, + 0x00f3, 0x76fe, 0xf1fd, 0x0026, 0x0004, 0x00a6, 0x0075, 0x11bf, + 0x00f3, 0x00ae, 0xf2fd, 0xffff, 0x00d5, 0x0046, 0xf5fe, 0x323f, + 0x00f3, 0x00e6, 0xf8fd, 0x0016, 0x0004, 0x0086, 0x0055, 0x006f, + 0x00f3, 0x00c6, 0x00b5, 0xb8bf, 0xf4fd, 0x115e, 0xa8ee, 0x222f +}; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t2.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t2.c index 6f956d1c7f6..4e8cf601828 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t2.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t2.c @@ -167,9 +167,9 @@ static OPJ_BOOL opj_t2_init_seg(opj_tcd_cblk_dec_t* cblk, static void opj_t2_putcommacode(opj_bio_t *bio, OPJ_INT32 n) { while (--n >= 0) { - opj_bio_write(bio, 1, 1); + opj_bio_putbit(bio, 1); } - opj_bio_write(bio, 0, 1); + opj_bio_putbit(bio, 0); } static OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio) @@ -184,7 +184,7 @@ static OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio) static void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) { if (n == 1) { - opj_bio_write(bio, 0, 1); + opj_bio_putbit(bio, 0); } else if (n == 2) { opj_bio_write(bio, 2, 2); } else if (n <= 5) { @@ -224,6 +224,7 @@ OPJ_BOOL opj_t2_encode_packets(opj_t2_t* p_t2, OPJ_UINT32 * p_data_written, OPJ_UINT32 p_max_len, opj_codestream_info_t *cstr_info, + opj_tcd_marker_info_t* p_marker_info, OPJ_UINT32 p_tp_num, OPJ_INT32 p_tp_pos, OPJ_UINT32 p_pino, @@ -244,7 +245,7 @@ OPJ_BOOL opj_t2_encode_packets(opj_t2_t* p_t2, l_image->numcomps : 1; OPJ_UINT32 l_nb_pocs = l_tcp->numpocs + 1; - l_pi = opj_pi_initialise_encode(l_image, l_cp, p_tile_no, p_t2_mode); + l_pi = opj_pi_initialise_encode(l_image, l_cp, p_tile_no, p_t2_mode, p_manager); if (!l_pi) { return OPJ_FALSE; } @@ -310,6 +311,20 @@ OPJ_BOOL opj_t2_encode_packets(opj_t2_t* p_t2, opj_pi_destroy(l_pi, l_nb_pocs); return OPJ_FALSE; } + + if (p_marker_info && p_marker_info->need_PLT) { + /* One time use intended */ + assert(p_marker_info->packet_count == 0); + assert(p_marker_info->p_packet_size == NULL); + + p_marker_info->p_packet_size = (OPJ_UINT32*) opj_malloc( + opj_get_encoding_packet_count(l_image, l_cp, p_tile_no) * sizeof(OPJ_UINT32)); + if (p_marker_info->p_packet_size == NULL) { + opj_pi_destroy(l_pi, l_nb_pocs); + return OPJ_FALSE; + } + } + while (opj_pi_next(l_current_pi)) { if (l_current_pi->layno < p_maxlayers) { l_nb_bytes = 0; @@ -326,6 +341,11 @@ OPJ_BOOL opj_t2_encode_packets(opj_t2_t* p_t2, * p_data_written += l_nb_bytes; + if (p_marker_info && p_marker_info->need_PLT) { + p_marker_info->p_packet_size[p_marker_info->packet_count] = l_nb_bytes; + p_marker_info->packet_count ++; + } + /* INDEX >> */ if (cstr_info) { if (cstr_info->index_write) { @@ -405,7 +425,7 @@ OPJ_BOOL opj_t2_decode_packets(opj_tcd_t* tcd, #endif /* create a packet iterator */ - l_pi = opj_pi_create_decode(l_image, l_cp, p_tile_no); + l_pi = opj_pi_create_decode(l_image, l_cp, p_tile_no, p_manager); if (!l_pi) { return OPJ_FALSE; } @@ -482,7 +502,6 @@ OPJ_BOOL opj_t2_decode_packets(opj_tcd_t* tcd, l_current_pi->precno, l_current_pi->layno, skip_packet ? "skipped" : "kept"); */ } - if (!skip_packet) { l_nb_bytes_read = 0; @@ -667,7 +686,19 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, opj_tcd_resolution_t *res = &tilec->resolutions[resno]; opj_bio_t *bio = 00; /* BIO component */ +#ifdef ENABLE_EMPTY_PACKET_OPTIMIZATION OPJ_BOOL packet_empty = OPJ_TRUE; +#else + OPJ_BOOL packet_empty = OPJ_FALSE; +#endif + +#ifdef DEBUG_VERBOSE + if (p_t2_mode == FINAL_PASS) { + fprintf(stderr, + "encode packet compono=%d, resno=%d, precno=%d, layno=%d\n", + compno, resno, precno, layno); + } +#endif /* */ if (tcp->csty & J2K_CP_CSTY_SOP) { @@ -707,6 +738,15 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, continue; } + /* Avoid out of bounds access of https://github.com/uclouvain/openjpeg/issues/1294 */ + /* but likely not a proper fix. */ + if (precno >= res->pw * res->ph) { + opj_event_msg(p_manager, EVT_ERROR, + "opj_t2_encode_packet(): accessing precno=%u >= %u\n", + precno, res->pw * res->ph); + return OPJ_FALSE; + } + prc = &band->precincts[precno]; opj_tgt_reset(prc->incltree); opj_tgt_reset(prc->imsbtree); @@ -728,6 +768,11 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, } opj_bio_init_enc(bio, c, length); +#ifdef ENABLE_EMPTY_PACKET_OPTIMIZATION + /* WARNING: this code branch is disabled, since it has been reported that */ + /* such packets cause decoding issues with cinema J2K hardware */ + /* decoders: https://groups.google.com/forum/#!topic/openjpeg/M7M_fLX_Bco */ + /* Check if the packet is empty */ /* Note: we could also skip that step and always write a packet header */ band = res->bands; @@ -755,9 +800,8 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, break; } } - - opj_bio_write(bio, packet_empty ? 0 : 1, 1); /* Empty header bit */ - +#endif + opj_bio_putbit(bio, packet_empty ? 0 : 1); /* Empty header bit */ /* Writing Packet header */ band = res->bands; @@ -770,6 +814,15 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, continue; } + /* Avoid out of bounds access of https://github.com/uclouvain/openjpeg/issues/1297 */ + /* but likely not a proper fix. */ + if (precno >= res->pw * res->ph) { + opj_event_msg(p_manager, EVT_ERROR, + "opj_t2_encode_packet(): accessing precno=%u >= %u\n", + precno, res->pw * res->ph); + return OPJ_FALSE; + } + prc = &band->precincts[precno]; l_nb_blocks = prc->cw * prc->ch; cblk = prc->cblks.enc; @@ -796,7 +849,7 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, if (!cblk->numpasses) { opj_tgt_encode(bio, prc->incltree, cblkno, (OPJ_INT32)(layno + 1)); } else { - opj_bio_write(bio, layer->numpasses != 0, 1); + opj_bio_putbit(bio, layer->numpasses != 0); } /* if cblk not included, go to the next cblk */ @@ -925,7 +978,9 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, return OPJ_FALSE; } - memcpy(c, layer->data, layer->len); + if (p_t2_mode == FINAL_PASS) { + memcpy(c, layer->data, layer->len); + } cblk->numpasses += layer->numpasses; c += layer->len; length -= layer->len; @@ -1056,6 +1111,7 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, /* SOP markers */ if (p_tcp->csty & J2K_CP_CSTY_SOP) { + /* SOP markers are allowed (i.e. optional), just warn */ if (p_max_length < 6) { opj_event_msg(p_manager, EVT_WARNING, "Not enough space for expected SOP marker\n"); @@ -1070,7 +1126,7 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, /* When the marker PPT/PPM is used the packet header are store in PPT/PPM marker - This part deal with this caracteristic + This part deal with this characteristic step 1: Read packet header in the saved structure step 2: Return to codestream for decoding */ @@ -1108,12 +1164,15 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, /* EPH markers */ if (p_tcp->csty & J2K_CP_CSTY_EPH) { + /* EPH markers are required */ if ((*l_modified_length_ptr - (OPJ_UINT32)(l_header_data - *l_header_data_start)) < 2U) { - opj_event_msg(p_manager, EVT_WARNING, - "Not enough space for expected EPH marker\n"); + opj_event_msg(p_manager, EVT_ERROR, + "Not enough space for required EPH marker\n"); + return OPJ_FALSE; } else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) { - opj_event_msg(p_manager, EVT_WARNING, "Expected EPH marker\n"); + opj_event_msg(p_manager, EVT_ERROR, "Expected EPH marker\n"); + return OPJ_FALSE; } else { l_header_data += 2; } @@ -1174,8 +1233,17 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, (OPJ_INT32)i)) { ++i; } - - l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i; + l_cblk->Mb = (OPJ_UINT32)l_band->numbps; + if ((OPJ_UINT32)l_band->numbps + 1 < i) { + /* Not totally sure what we should do in that situation, + * but that avoids the integer overflow of + * https://github.com/uclouvain/openjpeg/pull/1488 + * while keeping the regression test suite happy. + */ + l_cblk->numbps = (OPJ_UINT32)(l_band->numbps + 1 - (int)i); + } else { + l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i; + } l_cblk->numlenbits = 3; } @@ -1204,34 +1272,63 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, } n = (OPJ_INT32)l_cblk->numnewpasses; - do { - OPJ_UINT32 bit_number; - l_cblk->segs[l_segno].numnewpasses = (OPJ_UINT32)opj_int_min((OPJ_INT32)( - l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses), n); - bit_number = l_cblk->numlenbits + opj_uint_floorlog2( - l_cblk->segs[l_segno].numnewpasses); - if (bit_number > 32) { - opj_event_msg(p_manager, EVT_ERROR, - "Invalid bit number %d in opj_t2_read_packet_header()\n", - bit_number); - opj_bio_destroy(l_bio); - return OPJ_FALSE; - } - l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, bit_number); - JAS_FPRINTF(stderr, "included=%d numnewpasses=%d increment=%d len=%d \n", - l_included, l_cblk->segs[l_segno].numnewpasses, l_increment, - l_cblk->segs[l_segno].newlen); + if ((p_tcp->tccps[p_pi->compno].cblksty & J2K_CCP_CBLKSTY_HT) != 0) + do { + OPJ_UINT32 bit_number; + l_cblk->segs[l_segno].numnewpasses = l_segno == 0 ? 1 : (OPJ_UINT32)n; + bit_number = l_cblk->numlenbits + opj_uint_floorlog2( + l_cblk->segs[l_segno].numnewpasses); + if (bit_number > 32) { + opj_event_msg(p_manager, EVT_ERROR, + "Invalid bit number %d in opj_t2_read_packet_header()\n", + bit_number); + opj_bio_destroy(l_bio); + return OPJ_FALSE; + } + l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, bit_number); + JAS_FPRINTF(stderr, "included=%d numnewpasses=%d increment=%d len=%d \n", + l_included, l_cblk->segs[l_segno].numnewpasses, l_increment, + l_cblk->segs[l_segno].newlen); - n -= (OPJ_INT32)l_cblk->segs[l_segno].numnewpasses; - if (n > 0) { - ++l_segno; + n -= (OPJ_INT32)l_cblk->segs[l_segno].numnewpasses; + if (n > 0) { + ++l_segno; - if (! opj_t2_init_seg(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 0)) { + if (! opj_t2_init_seg(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 0)) { + opj_bio_destroy(l_bio); + return OPJ_FALSE; + } + } + } while (n > 0); + else + do { + OPJ_UINT32 bit_number; + l_cblk->segs[l_segno].numnewpasses = (OPJ_UINT32)opj_int_min((OPJ_INT32)( + l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses), n); + bit_number = l_cblk->numlenbits + opj_uint_floorlog2( + l_cblk->segs[l_segno].numnewpasses); + if (bit_number > 32) { + opj_event_msg(p_manager, EVT_ERROR, + "Invalid bit number %d in opj_t2_read_packet_header()\n", + bit_number); opj_bio_destroy(l_bio); return OPJ_FALSE; } - } - } while (n > 0); + l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, bit_number); + JAS_FPRINTF(stderr, "included=%d numnewpasses=%d increment=%d len=%d \n", + l_included, l_cblk->segs[l_segno].numnewpasses, l_increment, + l_cblk->segs[l_segno].newlen); + + n -= (OPJ_INT32)l_cblk->segs[l_segno].numnewpasses; + if (n > 0) { + ++l_segno; + + if (! opj_t2_init_seg(l_cblk, l_segno, p_tcp->tccps[p_pi->compno].cblksty, 0)) { + opj_bio_destroy(l_bio); + return OPJ_FALSE; + } + } + } while (n > 0); ++l_cblk; } @@ -1247,12 +1344,15 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, /* EPH markers */ if (p_tcp->csty & J2K_CP_CSTY_EPH) { + /* EPH markers are required */ if ((*l_modified_length_ptr - (OPJ_UINT32)(l_header_data - *l_header_data_start)) < 2U) { - opj_event_msg(p_manager, EVT_WARNING, - "Not enough space for expected EPH marker\n"); + opj_event_msg(p_manager, EVT_ERROR, + "Not enough space for required EPH marker\n"); + return OPJ_FALSE; } else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) { - opj_event_msg(p_manager, EVT_WARNING, "Expected EPH marker\n"); + opj_event_msg(p_manager, EVT_ERROR, "Expected EPH marker\n"); + return OPJ_FALSE; } else { l_header_data += 2; } @@ -1260,6 +1360,9 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, l_header_length = (OPJ_UINT32)(l_header_data - *l_header_data_start); JAS_FPRINTF(stderr, "hdrlen=%d \n", l_header_length); + if (!l_header_length) { + return OPJ_FALSE; + } JAS_FPRINTF(stderr, "packet body\n"); *l_modified_length_ptr -= l_header_length; *l_header_data_start += l_header_length; @@ -1294,6 +1397,7 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2, opj_tcd_cblk_dec_t* l_cblk = 00; opj_tcd_resolution_t* l_res = &p_tile->comps[p_pi->compno].resolutions[p_pi->resno]; + OPJ_BOOL partial_buffer = OPJ_FALSE; OPJ_ARG_NOT_USED(p_t2); OPJ_ARG_NOT_USED(pack_info); @@ -1310,12 +1414,21 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2, l_nb_code_blocks = l_prc->cw * l_prc->ch; l_cblk = l_prc->cblks.dec; - for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) { + for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno, ++l_cblk) { opj_tcd_seg_t *l_seg = 00; if (!l_cblk->numnewpasses) { /* nothing to do */ - ++l_cblk; + continue; + } + + if (partial_buffer || l_cblk->corrupted) { + /* if a previous segment in this packet couldn't be decoded, + * or if this code block was corrupted in a previous layer, + * then mark it as corrupted. + */ + l_cblk->numchunks = 0; + l_cblk->corrupted = OPJ_TRUE; continue; } @@ -1335,12 +1448,27 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2, /* Check possible overflow (on l_current_data only, assumes input args already checked) then size */ if ((((OPJ_SIZE_T)l_current_data + (OPJ_SIZE_T)l_seg->newlen) < (OPJ_SIZE_T)l_current_data) || - (l_current_data + l_seg->newlen > p_src_data + p_max_length)) { - opj_event_msg(p_manager, EVT_ERROR, - "read: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", - l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, - p_pi->compno); - return OPJ_FALSE; + (l_current_data + l_seg->newlen > p_src_data + p_max_length) || + (partial_buffer)) { + if (p_t2->cp->strict) { + opj_event_msg(p_manager, EVT_ERROR, + "read: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", + l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, + p_pi->compno); + return OPJ_FALSE; + } else { + opj_event_msg(p_manager, EVT_WARNING, + "read: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", + l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, + p_pi->compno); + /* skip this codeblock (and following ones in this + * packet) since it is a partial read + */ + partial_buffer = OPJ_TRUE; + l_cblk->corrupted = OPJ_TRUE; + l_cblk->numchunks = 0; + break; + } } #ifdef USE_JPWL @@ -1396,14 +1524,18 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2, } while (l_cblk->numnewpasses > 0); l_cblk->real_num_segs = l_cblk->numsegs; - ++l_cblk; + } /* next code_block */ ++l_band; } - *(p_data_read) = (OPJ_UINT32)(l_current_data - p_src_data); - + // return the number of bytes read + if (partial_buffer) { + *(p_data_read) = p_max_length; + } else { + *(p_data_read) = (OPJ_UINT32)(l_current_data - p_src_data); + } return OPJ_TRUE; } @@ -1465,11 +1597,21 @@ static OPJ_BOOL opj_t2_skip_packet_data(opj_t2_t* p_t2, /* Check possible overflow then size */ if (((*p_data_read + l_seg->newlen) < (*p_data_read)) || ((*p_data_read + l_seg->newlen) > p_max_length)) { - opj_event_msg(p_manager, EVT_ERROR, - "skip: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", - l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, - p_pi->compno); - return OPJ_FALSE; + if (p_t2->cp->strict) { + opj_event_msg(p_manager, EVT_ERROR, + "skip: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", + l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, + p_pi->compno); + return OPJ_FALSE; + } else { + opj_event_msg(p_manager, EVT_WARNING, + "skip: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", + l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, + p_pi->compno); + + *p_data_read = p_max_length; + return OPJ_TRUE; + } } #ifdef USE_JPWL diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t2.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t2.h index 66500b16993..becfa91a4de 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t2.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/t2.h @@ -73,6 +73,7 @@ Encode the packets of a tile to a destination buffer @param p_data_written FIXME DOC @param len the length of the destination buffer @param cstr_info Codestream information structure +@param p_marker_info Marker information structure @param tpnum Tile part number of the current tile @param tppos The position of the tile part flag in the progression order @param pino FIXME DOC @@ -87,6 +88,7 @@ OPJ_BOOL opj_t2_encode_packets(opj_t2_t* t2, OPJ_UINT32 * p_data_written, OPJ_UINT32 len, opj_codestream_info_t *cstr_info, + opj_tcd_marker_info_t* p_marker_info, OPJ_UINT32 tpnum, OPJ_INT32 tppos, OPJ_UINT32 pino, diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/tcd.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/tcd.c index dbc17b17629..8ca259b71dc 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/tcd.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/tcd.c @@ -42,6 +42,8 @@ #include "opj_includes.h" #include "opj_common.h" +// #define DEBUG_RATE_ALLOC + /* ----------------------------------------------------------------------- */ /* TODO MSD: */ @@ -112,7 +114,7 @@ void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) * Initializes tile coding/decoding */ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, - OPJ_BOOL isEncoder, OPJ_FLOAT32 fraction, OPJ_SIZE_T sizeof_block, + OPJ_BOOL isEncoder, OPJ_SIZE_T sizeof_block, opj_event_mgr_t* manager); /** @@ -143,6 +145,9 @@ static OPJ_BOOL opj_tcd_code_block_enc_allocate_data(opj_tcd_cblk_enc_t * */ static void opj_tcd_code_block_enc_deallocate(opj_tcd_precinct_t * p_precinct); +static +void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, + OPJ_UINT32 final); /** Free the memory allocated for encoding @@ -182,6 +187,7 @@ static OPJ_BOOL opj_tcd_t2_encode(opj_tcd_t *p_tcd, OPJ_UINT32 * p_data_written, OPJ_UINT32 p_max_dest_size, opj_codestream_info_t *p_cstr_info, + opj_tcd_marker_info_t* p_marker_info, opj_event_mgr_t *p_manager); static OPJ_BOOL opj_tcd_rate_allocate_encode(opj_tcd_t *p_tcd, @@ -223,6 +229,7 @@ opj_tcd_t* opj_tcd_create(OPJ_BOOL p_is_decoder) /* ----------------------------------------------------------------------- */ +static void opj_tcd_rateallocate_fixed(opj_tcd_t *tcd) { OPJ_UINT32 layno; @@ -233,17 +240,23 @@ void opj_tcd_rateallocate_fixed(opj_tcd_t *tcd) } -void opj_tcd_makelayer(opj_tcd_t *tcd, - OPJ_UINT32 layno, - OPJ_FLOAT64 thresh, - OPJ_UINT32 final) +/* ----------------------------------------------------------------------- */ + +/** Returns OPJ_TRUE if the layer allocation is unchanged w.r.t to the previous + * invocation with a different threshold */ +static +OPJ_BOOL opj_tcd_makelayer(opj_tcd_t *tcd, + OPJ_UINT32 layno, + OPJ_FLOAT64 thresh, + OPJ_UINT32 final) { OPJ_UINT32 compno, resno, bandno, precno, cblkno; OPJ_UINT32 passno; opj_tcd_tile_t *tcd_tile = tcd->tcd_image->tiles; + OPJ_BOOL layer_allocation_is_same = OPJ_TRUE; - tcd_tile->distolayer[layno] = 0; /* fixed_quality */ + tcd_tile->distolayer[layno] = 0; for (compno = 0; compno < tcd_tile->numcomps; compno++) { opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; @@ -303,7 +316,10 @@ void opj_tcd_makelayer(opj_tcd_t *tcd, } } - layer->numpasses = n - cblk->numpassesinlayers; + if (layer->numpasses != n - cblk->numpassesinlayers) { + layer_allocation_is_same = OPJ_FALSE; + layer->numpasses = n - cblk->numpassesinlayers; + } if (!layer->numpasses) { layer->disto = 0; @@ -322,7 +338,7 @@ void opj_tcd_makelayer(opj_tcd_t *tcd, cblk->passes[cblk->numpassesinlayers - 1].distortiondec; } - tcd_tile->distolayer[layno] += layer->disto; /* fixed_quality */ + tcd_tile->distolayer[layno] += layer->disto; if (final) { cblk->numpassesinlayers = n; @@ -332,14 +348,17 @@ void opj_tcd_makelayer(opj_tcd_t *tcd, } } } + return layer_allocation_is_same; } +/** For m_quality_layer_alloc_strategy == FIXED_LAYER */ +static void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final) { OPJ_UINT32 compno, resno, bandno, precno, cblkno; OPJ_INT32 value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolutions][3]; */ - OPJ_INT32 matrice[10][10][3]; + OPJ_INT32 matrice[J2K_TCD_MATRIX_MAX_LAYER_COUNT][J2K_TCD_MATRIX_MAX_RESOLUTION_COUNT][3]; OPJ_UINT32 i, j, k; opj_cp_t *cp = tcd->cp; @@ -439,6 +458,11 @@ void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, } } +/** Rate allocation for the following methods: + * - allocation by rate/distortio (m_quality_layer_alloc_strategy == RATE_DISTORTION_RATIO) + * - allocation by fixed quality (m_quality_layer_alloc_strategy == FIXED_DISTORTION_RATIO) + */ +static OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, OPJ_BYTE *dest, OPJ_UINT32 * p_data_written, @@ -449,8 +473,8 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, OPJ_UINT32 compno, resno, bandno, precno, cblkno, layno; OPJ_UINT32 passno; OPJ_FLOAT64 min, max; - OPJ_FLOAT64 cumdisto[100]; /* fixed_quality */ - const OPJ_FLOAT64 K = 1; /* 1.1; fixed_quality */ + OPJ_FLOAT64 cumdisto[100]; + const OPJ_FLOAT64 K = 1; OPJ_FLOAT64 maxSE = 0; opj_cp_t *cp = tcd->cp; @@ -460,7 +484,7 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, min = DBL_MAX; max = 0; - tcd_tile->numpix = 0; /* fixed_quality */ + tcd_tile->numpix = 0; for (compno = 0; compno < tcd_tile->numcomps; compno++) { opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; @@ -510,9 +534,12 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, } } /* passno */ - /* fixed_quality */ - tcd_tile->numpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); - tilec->numpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); + { + const OPJ_SIZE_T cblk_pix_count = (OPJ_SIZE_T)((cblk->x1 - cblk->x0) * + (cblk->y1 - cblk->y0)); + tcd_tile->numpix += cblk_pix_count; + tilec->numpix += cblk_pix_count; + } } /* cbklno */ } /* precno */ } /* bandno */ @@ -526,8 +553,8 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, /* index file */ if (cstr_info) { opj_tile_info_t *tile_info = &cstr_info->tile[tcd->tcd_tileno]; - tile_info->numpix = tcd_tile->numpix; - tile_info->distotile = tcd_tile->distotile; + tile_info->numpix = (int)tcd_tile->numpix; + tile_info->distotile = (int)tcd_tile->distotile; tile_info->thresh = (OPJ_FLOAT64 *) opj_malloc(tcd_tcp->numlayers * sizeof( OPJ_FLOAT64)); if (!tile_info->thresh) { @@ -544,38 +571,58 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, OPJ_FLOAT64 goodthresh = 0; OPJ_FLOAT64 stable_thresh = 0; OPJ_UINT32 i; - OPJ_FLOAT64 distotarget; /* fixed_quality */ + OPJ_FLOAT64 distotarget; - /* fixed_quality */ distotarget = tcd_tile->distotile - ((K * maxSE) / pow((OPJ_FLOAT32)10, tcd_tcp->distoratio[layno] / 10)); /* Don't try to find an optimal threshold but rather take everything not included yet, if - -r xx,yy,zz,0 (disto_alloc == 1 and rates == 0) - -q xx,yy,zz,0 (fixed_quality == 1 and distoratio == 0) + -r xx,yy,zz,0 (m_quality_layer_alloc_strategy == RATE_DISTORTION_RATIO and rates == NULL) + -q xx,yy,zz,0 (m_quality_layer_alloc_strategy == FIXED_DISTORTION_RATIO and distoratio == NULL) ==> possible to have some lossy layers and the last layer for sure lossless */ - if (((cp->m_specific_param.m_enc.m_disto_alloc == 1) && + if (((cp->m_specific_param.m_enc.m_quality_layer_alloc_strategy == + RATE_DISTORTION_RATIO) && (tcd_tcp->rates[layno] > 0.0f)) || - ((cp->m_specific_param.m_enc.m_fixed_quality == 1) && + ((cp->m_specific_param.m_enc.m_quality_layer_alloc_strategy == + FIXED_DISTORTION_RATIO) && (tcd_tcp->distoratio[layno] > 0.0))) { opj_t2_t*t2 = opj_t2_create(tcd->image, cp); OPJ_FLOAT64 thresh = 0; + OPJ_BOOL last_layer_allocation_ok = OPJ_FALSE; if (t2 == 00) { return OPJ_FALSE; } for (i = 0; i < 128; ++i) { - OPJ_FLOAT64 distoachieved = 0; /* fixed_quality */ - - thresh = (lo + hi) / 2; - - opj_tcd_makelayer(tcd, layno, thresh, 0); + OPJ_FLOAT64 distoachieved = 0; + OPJ_BOOL layer_allocation_is_same; + + OPJ_FLOAT64 new_thresh = (lo + hi) / 2; + /* Stop iterating when the threshold has stabilized enough */ + /* 0.5 * 1e-5 is somewhat arbitrary, but has been selected */ + /* so that this doesn't change the results of the regression */ + /* test suite. */ + if (fabs(new_thresh - thresh) <= 0.5 * 1e-5 * thresh) { + break; + } + thresh = new_thresh; +#ifdef DEBUG_RATE_ALLOC + opj_event_msg(p_manager, EVT_INFO, "layno=%u, iter=%u, thresh=%g", + layno, i, new_thresh); +#endif - if (cp->m_specific_param.m_enc.m_fixed_quality) { /* fixed_quality */ - if (OPJ_IS_CINEMA(cp->rsiz)) { + layer_allocation_is_same = opj_tcd_makelayer(tcd, layno, thresh, 0) && i != 0; +#ifdef DEBUG_RATE_ALLOC + opj_event_msg(p_manager, EVT_INFO, "--> layer_allocation_is_same = %d", + layer_allocation_is_same); +#endif + if (cp->m_specific_param.m_enc.m_quality_layer_alloc_strategy == + FIXED_DISTORTION_RATIO) { + if (OPJ_IS_CINEMA(cp->rsiz) || OPJ_IS_IMF(cp->rsiz)) { if (! opj_t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, - p_data_written, maxlen, cstr_info, tcd->cur_tp_num, tcd->tp_pos, tcd->cur_pino, + p_data_written, maxlen, cstr_info, NULL, tcd->cur_tp_num, tcd->tp_pos, + tcd->cur_pino, THRESH_CALC, p_manager)) { lo = thresh; @@ -603,16 +650,41 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, } lo = thresh; } - } else { - if (! opj_t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, - p_data_written, maxlen, cstr_info, tcd->cur_tp_num, tcd->tp_pos, tcd->cur_pino, - THRESH_CALC, p_manager)) { - /* TODO: what to do with l ??? seek / tell ??? */ - /* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */ + } else { /* Disto/rate based optimization */ + /* Check if the layer allocation done by opj_tcd_makelayer() + * is compatible of the maximum rate allocation. If not, + * retry with a higher threshold. + * If OK, try with a lower threshold. + * Call opj_t2_encode_packets() only if opj_tcd_makelayer() + * has resulted in different truncation points since its last + * call. */ + if ((layer_allocation_is_same && !last_layer_allocation_ok) || + (!layer_allocation_is_same && + ! opj_t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, + p_data_written, maxlen, cstr_info, NULL, tcd->cur_tp_num, tcd->tp_pos, + tcd->cur_pino, + THRESH_CALC, p_manager))) { + +#ifdef DEBUG_RATE_ALLOC + if (!layer_allocation_is_same) { + opj_event_msg(p_manager, EVT_INFO, + "--> check rate alloc failed (> maxlen=%u)\n", maxlen); + } +#endif + last_layer_allocation_ok = OPJ_FALSE; lo = thresh; continue; } +#ifdef DEBUG_RATE_ALLOC + if (!layer_allocation_is_same) { + opj_event_msg(p_manager, EVT_INFO, + "--> check rate alloc success (len=%u <= maxlen=%u)\n", *p_data_written, + maxlen); + } +#endif + + last_layer_allocation_ok = OPJ_TRUE; hi = thresh; stable_thresh = thresh; } @@ -632,7 +704,6 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, opj_tcd_makelayer(tcd, layno, goodthresh, 1); - /* fixed_quality */ cumdisto[layno] = (layno == 0) ? tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]); } @@ -718,10 +789,9 @@ OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec) /* ----------------------------------------------------------------------- */ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, - OPJ_BOOL isEncoder, OPJ_FLOAT32 fraction, OPJ_SIZE_T sizeof_block, + OPJ_BOOL isEncoder, OPJ_SIZE_T sizeof_block, opj_event_mgr_t* manager) { - OPJ_UINT32(*l_gain_ptr)(OPJ_UINT32) = 00; OPJ_UINT32 compno, resno, bandno, precno, cblkno; opj_tcp_t * l_tcp = 00; opj_cp_t * l_cp = 00; @@ -737,7 +807,6 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, OPJ_UINT32 p, q; OPJ_UINT32 l_level_no; OPJ_UINT32 l_pdx, l_pdy; - OPJ_UINT32 l_gain; OPJ_INT32 l_x0b, l_y0b; OPJ_UINT32 l_tx0, l_ty0; /* extent of precincts , top left, bottom right**/ @@ -876,11 +945,6 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, l_level_no = l_tilec->numresolutions; l_res = l_tilec->resolutions; l_step_size = l_tccp->stepsizes; - if (l_tccp->qmfbid == 0) { - l_gain_ptr = &opj_dwt_getgain_real; - } else { - l_gain_ptr = &opj_dwt_getgain; - } /*fprintf(stderr, "\tlevel_no=%d\n",l_level_no);*/ for (resno = 0; resno < l_tilec->numresolutions; ++resno) { @@ -905,8 +969,24 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ l_tl_prc_x_start = opj_int_floordivpow2(l_res->x0, (OPJ_INT32)l_pdx) << l_pdx; l_tl_prc_y_start = opj_int_floordivpow2(l_res->y0, (OPJ_INT32)l_pdy) << l_pdy; - l_br_prc_x_end = opj_int_ceildivpow2(l_res->x1, (OPJ_INT32)l_pdx) << l_pdx; - l_br_prc_y_end = opj_int_ceildivpow2(l_res->y1, (OPJ_INT32)l_pdy) << l_pdy; + { + OPJ_UINT32 tmp = ((OPJ_UINT32)opj_int_ceildivpow2(l_res->x1, + (OPJ_INT32)l_pdx)) << l_pdx; + if (tmp > (OPJ_UINT32)INT_MAX) { + opj_event_msg(manager, EVT_ERROR, "Integer overflow\n"); + return OPJ_FALSE; + } + l_br_prc_x_end = (OPJ_INT32)tmp; + } + { + OPJ_UINT32 tmp = ((OPJ_UINT32)opj_int_ceildivpow2(l_res->y1, + (OPJ_INT32)l_pdy)) << l_pdy; + if (tmp > (OPJ_UINT32)INT_MAX) { + opj_event_msg(manager, EVT_ERROR, "Integer overflow\n"); + return OPJ_FALSE; + } + l_br_prc_y_end = (OPJ_INT32)tmp; + } /*fprintf(stderr, "\t\t\tprc_x_start=%d, prc_y_start=%d, br_prc_x_end=%d, br_prc_y_end=%d \n", l_tl_prc_x_start, l_tl_prc_y_start, l_br_prc_x_end ,l_br_prc_y_end );*/ l_res->pw = (l_res->x0 == l_res->x1) ? 0U : (OPJ_UINT32)(( @@ -951,7 +1031,6 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, l_band = l_res->bands; for (bandno = 0; bandno < l_res->numbands; ++bandno, ++l_band, ++l_step_size) { - OPJ_INT32 numbps; /*fprintf(stderr, "\t\t\tband_no=%d/%d\n", bandno, l_res->numbands );*/ if (resno == 0) { @@ -987,11 +1066,24 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, } } - /** avoid an if with storing function pointer */ - l_gain = (*l_gain_ptr)(l_band->bandno); - numbps = (OPJ_INT32)(l_image_comp->prec + l_gain); - l_band->stepsize = (OPJ_FLOAT32)(((1.0 + l_step_size->mant / 2048.0) * pow(2.0, - (OPJ_INT32)(numbps - l_step_size->expn)))) * fraction; + { + /* Table E-1 - Sub-band gains */ + /* BUG_WEIRD_TWO_INVK (look for this identifier in dwt.c): */ + /* the test (!isEncoder && l_tccp->qmfbid == 0) is strongly */ + /* linked to the use of two_invK instead of invK */ + const OPJ_INT32 log2_gain = (!isEncoder && + l_tccp->qmfbid == 0) ? 0 : (l_band->bandno == 0) ? 0 : + (l_band->bandno == 3) ? 2 : 1; + + /* Nominal dynamic range. Equation E-4 */ + const OPJ_INT32 Rb = (OPJ_INT32)l_image_comp->prec + log2_gain; + + /* Delta_b value of Equation E-3 in "E.1 Inverse quantization + * procedure" of the standard */ + l_band->stepsize = (OPJ_FLOAT32)(((1.0 + l_step_size->mant / 2048.0) * pow(2.0, + (OPJ_INT32)(Rb - l_step_size->expn)))); + } + /* Mb value of Equation E-2 in "E.1 Inverse quantization * procedure" of the standard */ l_band->numbps = l_step_size->expn + (OPJ_INT32)l_tccp->numgbits - @@ -1067,6 +1159,12 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, l_nb_code_blocks = l_current_precinct->cw * l_current_precinct->ch; /*fprintf(stderr, "\t\t\t\t precinct_cw = %d x recinct_ch = %d\n",l_current_precinct->cw, l_current_precinct->ch); */ + if ((((OPJ_UINT32) - 1) / (OPJ_UINT32)sizeof_block) < + l_nb_code_blocks) { + opj_event_msg(manager, EVT_ERROR, + "Size of code block data exceeds system limits\n"); + return OPJ_FALSE; + } l_nb_code_blocks_size = l_nb_code_blocks * (OPJ_UINT32)sizeof_block; if (!l_current_precinct->cblks.blocks && (l_nb_code_blocks > 0U)) { @@ -1168,14 +1266,14 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, OPJ_BOOL opj_tcd_init_encode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, opj_event_mgr_t* p_manager) { - return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_TRUE, 1.0F, + return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_TRUE, sizeof(opj_tcd_cblk_enc_t), p_manager); } OPJ_BOOL opj_tcd_init_decode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, opj_event_mgr_t* p_manager) { - return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_FALSE, 0.5F, + return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_FALSE, sizeof(opj_tcd_cblk_dec_t), p_manager); } @@ -1213,10 +1311,16 @@ static OPJ_BOOL opj_tcd_code_block_enc_allocate_data(opj_tcd_cblk_enc_t * /* +1 is needed for https://github.com/uclouvain/openjpeg/issues/835 */ /* and actually +2 required for https://github.com/uclouvain/openjpeg/issues/982 */ + /* and +7 for https://github.com/uclouvain/openjpeg/issues/1283 (-M 3) */ + /* and +26 for https://github.com/uclouvain/openjpeg/issues/1283 (-M 7) */ + /* and +28 for https://github.com/uclouvain/openjpeg/issues/1283 (-M 44) */ + /* and +33 for https://github.com/uclouvain/openjpeg/issues/1283 (-M 4) */ + /* and +63 for https://github.com/uclouvain/openjpeg/issues/1283 (-M 4 -IMF 2K) */ + /* and +74 for https://github.com/uclouvain/openjpeg/issues/1283 (-M 4 -n 8 -s 7,7 -I) */ /* TODO: is there a theoretical upper-bound for the compressed code */ /* block size ? */ - l_data_size = 2 + (OPJ_UINT32)((p_code_block->x1 - p_code_block->x0) * - (p_code_block->y1 - p_code_block->y0) * (OPJ_INT32)sizeof(OPJ_UINT32)); + l_data_size = 74 + (OPJ_UINT32)((p_code_block->x1 - p_code_block->x0) * + (p_code_block->y1 - p_code_block->y0) * (OPJ_INT32)sizeof(OPJ_UINT32)); if (l_data_size > p_code_block->data_size) { if (p_code_block->data) { @@ -1348,6 +1452,7 @@ OPJ_BOOL opj_tcd_encode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 * p_data_written, OPJ_UINT32 p_max_length, opj_codestream_info_t *p_cstr_info, + opj_tcd_marker_info_t* p_marker_info, opj_event_mgr_t *p_manager) { @@ -1427,7 +1532,7 @@ OPJ_BOOL opj_tcd_encode_tile(opj_tcd_t *p_tcd, /* FIXME _ProfStart(PGROUP_T2); */ if (! opj_tcd_t2_encode(p_tcd, p_dest, p_data_written, p_max_length, - p_cstr_info, p_manager)) { + p_cstr_info, p_marker_info, p_manager)) { return OPJ_FALSE; } /* FIXME _ProfStop(PGROUP_T2); */ @@ -2011,7 +2116,8 @@ static OPJ_BOOL opj_tcd_mct_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles; opj_tcp_t * l_tcp = p_tcd->tcp; opj_tcd_tilecomp_t * l_tile_comp = l_tile->comps; - OPJ_UINT32 l_samples, i; + OPJ_SIZE_T l_samples; + OPJ_UINT32 i; if (l_tcp->mct == 0 || p_tcd->used_component != NULL) { return OPJ_TRUE; @@ -2024,8 +2130,8 @@ static OPJ_BOOL opj_tcd_mct_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) /* A bit inefficient: we process more data than needed if */ /* resno_decoded < l_tile_comp->minimum_num_resolutions-1, */ /* but we would need to take into account a stride then */ - l_samples = (OPJ_UINT32)((res_comp0->x1 - res_comp0->x0) * - (res_comp0->y1 - res_comp0->y0)); + l_samples = (OPJ_SIZE_T)(res_comp0->x1 - res_comp0->x0) * + (OPJ_SIZE_T)(res_comp0->y1 - res_comp0->y0); if (l_tile->numcomps >= 3) { if (l_tile_comp->minimum_num_resolutions != l_tile->comps[1].minimum_num_resolutions || @@ -2059,8 +2165,8 @@ static OPJ_BOOL opj_tcd_mct_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) opj_tcd_resolution_t* res_comp0 = l_tile->comps[0].resolutions + p_tcd->image->comps[0].resno_decoded; - l_samples = (res_comp0->win_x1 - res_comp0->win_x0) * - (res_comp0->win_y1 - res_comp0->win_y0); + l_samples = (OPJ_SIZE_T)(res_comp0->win_x1 - res_comp0->win_x0) * + (OPJ_SIZE_T)(res_comp0->win_y1 - res_comp0->win_y0); if (l_tile->numcomps >= 3) { opj_tcd_resolution_t* res_comp1 = l_tile->comps[1].resolutions + p_tcd->image->comps[1].resno_decoded; @@ -2209,6 +2315,9 @@ static OPJ_BOOL opj_tcd_dc_level_shift_decode(opj_tcd_t *p_tcd) l_max = (OPJ_INT32)((1U << l_img_comp->prec) - 1); } + if (l_width == 0 || l_height == 0) { + continue; + } if (l_tccp->qmfbid == 1) { for (j = 0; j < l_height; ++j) { @@ -2226,7 +2335,7 @@ static OPJ_BOOL opj_tcd_dc_level_shift_decode(opj_tcd_t *p_tcd) OPJ_FLOAT32 l_value = *((OPJ_FLOAT32 *) l_current_ptr); if (l_value > (OPJ_FLOAT32)INT_MAX) { *l_current_ptr = l_max; - } else if (l_value < (OPJ_FLOAT32)INT_MIN) { + } else if (l_value < INT_MIN) { *l_current_ptr = l_min; } else { /* Do addition on int64 to avoid overflows */ @@ -2326,7 +2435,7 @@ static void opj_tcd_code_block_enc_deallocate(opj_tcd_precinct_t * p_precinct) } } -OPJ_SIZE_T opj_tcd_get_encoded_tile_size(opj_tcd_t *p_tcd) +OPJ_SIZE_T opj_tcd_get_encoder_input_buffer_size(opj_tcd_t *p_tcd) { OPJ_UINT32 i; OPJ_SIZE_T l_data_size = 0; @@ -2384,7 +2493,8 @@ static OPJ_BOOL opj_tcd_dc_level_shift_encode(opj_tcd_t *p_tcd) } } else { for (i = 0; i < l_nb_elem; ++i) { - *l_current_ptr = (*l_current_ptr - l_tccp->m_dc_level_shift) * (1 << 11); + *((OPJ_FLOAT32 *) l_current_ptr) = (OPJ_FLOAT32)(*l_current_ptr - + l_tccp->m_dc_level_shift); ++l_current_ptr; } } @@ -2442,8 +2552,11 @@ static OPJ_BOOL opj_tcd_mct_encode(opj_tcd_t *p_tcd) opj_free(l_data); } else if (l_tcp->tccps->qmfbid == 0) { - opj_mct_encode_real(l_tile->comps[0].data, l_tile->comps[1].data, - l_tile->comps[2].data, samples); + opj_mct_encode_real( + (OPJ_FLOAT32*)l_tile->comps[0].data, + (OPJ_FLOAT32*)l_tile->comps[1].data, + (OPJ_FLOAT32*)l_tile->comps[2].data, + samples); } else { opj_mct_encode(l_tile->comps[0].data, l_tile->comps[1].data, l_tile->comps[2].data, samples); @@ -2461,11 +2574,11 @@ static OPJ_BOOL opj_tcd_dwt_encode(opj_tcd_t *p_tcd) for (compno = 0; compno < l_tile->numcomps; ++compno) { if (l_tccp->qmfbid == 1) { - if (! opj_dwt_encode(l_tile_comp)) { + if (! opj_dwt_encode(p_tcd, l_tile_comp)) { return OPJ_FALSE; } } else if (l_tccp->qmfbid == 0) { - if (! opj_dwt_encode_real(l_tile_comp)) { + if (! opj_dwt_encode_real(p_tcd, l_tile_comp)) { return OPJ_FALSE; } } @@ -2479,16 +2592,10 @@ static OPJ_BOOL opj_tcd_dwt_encode(opj_tcd_t *p_tcd) static OPJ_BOOL opj_tcd_t1_encode(opj_tcd_t *p_tcd) { - opj_t1_t * l_t1; const OPJ_FLOAT64 * l_mct_norms; OPJ_UINT32 l_mct_numcomps = 0U; opj_tcp_t * l_tcp = p_tcd->tcp; - l_t1 = opj_t1_create(OPJ_TRUE); - if (l_t1 == 00) { - return OPJ_FALSE; - } - if (l_tcp->mct == 1) { l_mct_numcomps = 3U; /* irreversible encoding */ @@ -2502,13 +2609,9 @@ static OPJ_BOOL opj_tcd_t1_encode(opj_tcd_t *p_tcd) l_mct_norms = (const OPJ_FLOAT64 *)(l_tcp->mct_norms); } - if (! opj_t1_encode_cblks(l_t1, p_tcd->tcd_image->tiles, l_tcp, l_mct_norms, - l_mct_numcomps)) { - opj_t1_destroy(l_t1); - return OPJ_FALSE; - } - - opj_t1_destroy(l_t1); + return opj_t1_encode_cblks(p_tcd, + p_tcd->tcd_image->tiles, l_tcp, l_mct_norms, + l_mct_numcomps); return OPJ_TRUE; } @@ -2518,6 +2621,7 @@ static OPJ_BOOL opj_tcd_t2_encode(opj_tcd_t *p_tcd, OPJ_UINT32 * p_data_written, OPJ_UINT32 p_max_dest_size, opj_codestream_info_t *p_cstr_info, + opj_tcd_marker_info_t* p_marker_info, opj_event_mgr_t *p_manager) { opj_t2_t * l_t2; @@ -2536,6 +2640,7 @@ static OPJ_BOOL opj_tcd_t2_encode(opj_tcd_t *p_tcd, p_data_written, p_max_dest_size, p_cstr_info, + p_marker_info, p_tcd->tp_num, p_tcd->tp_pos, p_tcd->cur_pino, @@ -2565,10 +2670,10 @@ static OPJ_BOOL opj_tcd_rate_allocate_encode(opj_tcd_t *p_tcd, p_cstr_info->index_write = 0; } - if (l_cp->m_specific_param.m_enc.m_disto_alloc || - l_cp->m_specific_param.m_enc.m_fixed_quality) { - /* fixed_quality */ - /* Normal Rate/distortion allocation */ + if (l_cp->m_specific_param.m_enc.m_quality_layer_alloc_strategy == + RATE_DISTORTION_RATIO || + l_cp->m_specific_param.m_enc.m_quality_layer_alloc_strategy == + FIXED_DISTORTION_RATIO) { if (! opj_tcd_rateallocate(p_tcd, p_dest_data, &l_nb_written, p_max_dest_size, p_cstr_info, p_manager)) { return OPJ_FALSE; @@ -2594,7 +2699,7 @@ OPJ_BOOL opj_tcd_copy_tile_data(opj_tcd_t *p_tcd, OPJ_UINT32 l_size_comp, l_remaining; OPJ_SIZE_T l_nb_elem; - l_data_size = opj_tcd_get_encoded_tile_size(p_tcd); + l_data_size = opj_tcd_get_encoder_input_buffer_size(p_tcd); if (l_data_size != p_src_length) { return OPJ_FALSE; } @@ -2756,12 +2861,12 @@ OPJ_BOOL opj_tcd_is_subband_area_of_interest(opj_tcd_t *tcd, return intersects; } -/** Returns whether a tile componenent is fully decoded, taking into account +/** Returns whether a tile component is fully decoded, taking into account * p_tcd->win_* members. * * @param p_tcd TCD handle. * @param compno Component number - * @return OPJ_TRUE whether the tile componenent is fully decoded + * @return OPJ_TRUE whether the tile component is fully decoded */ static OPJ_BOOL opj_tcd_is_whole_tilecomp_decoding(opj_tcd_t *p_tcd, OPJ_UINT32 compno) @@ -2796,3 +2901,30 @@ static OPJ_BOOL opj_tcd_is_whole_tilecomp_decoding(opj_tcd_t *p_tcd, (((OPJ_UINT32)tilec->x1 - tcx1) >> shift) == 0 && (((OPJ_UINT32)tilec->y1 - tcy1) >> shift) == 0))); } + +/* ----------------------------------------------------------------------- */ + +opj_tcd_marker_info_t* opj_tcd_marker_info_create(OPJ_BOOL need_PLT) +{ + opj_tcd_marker_info_t *l_tcd_marker_info = + (opj_tcd_marker_info_t*) opj_calloc(1, sizeof(opj_tcd_marker_info_t)); + if (!l_tcd_marker_info) { + return NULL; + } + + l_tcd_marker_info->need_PLT = need_PLT; + + return l_tcd_marker_info; +} + +/* ----------------------------------------------------------------------- */ + +void opj_tcd_marker_info_destroy(opj_tcd_marker_info_t *p_tcd_marker_info) +{ + if (p_tcd_marker_info) { + opj_free(p_tcd_marker_info->p_packet_size); + opj_free(p_tcd_marker_info); + } +} + +/* ----------------------------------------------------------------------- */ diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/tcd.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/tcd.h index e3214c1d982..3371b08cb27 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/tcd.h +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/tcd.h @@ -122,6 +122,11 @@ typedef struct opj_tcd_cblk_dec { opj_tcd_seg_data_chunk_t* chunks; /* Array of chunks */ /* position of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ OPJ_INT32 x0, y0, x1, y1; + /* Mb is The maximum number of bit-planes available for the representation of + coefficients in any sub-band, b, as defined in Equation (E-2). See + Section B.10.5 of the standard */ + OPJ_UINT32 Mb; /* currently used only to check if HT decoding is correct */ + /* numbps is Mb - P as defined in Section B.10.5 of the standard */ OPJ_UINT32 numbps; /* number of bits for len, for the current packet. Transitory value */ OPJ_UINT32 numlenbits; @@ -136,6 +141,7 @@ typedef struct opj_tcd_cblk_dec { OPJ_UINT32 numchunksalloc; /* Number of chunks item allocated */ /* Decoded code-block. Only used for subtile decoding. Otherwise tilec->data is directly updated */ OPJ_INT32* decoded_data; + OPJ_BOOL corrupted; /* whether the code block data is corrupted */ } opj_tcd_cblk_dec_t; /** Precinct structure */ @@ -217,8 +223,8 @@ typedef struct opj_tcd_tilecomp { OPJ_UINT32 win_x1; OPJ_UINT32 win_y1; - /* add fixed_quality */ - OPJ_INT32 numpix; + /* number of pixels */ + OPJ_SIZE_T numpix; } opj_tcd_tilecomp_t; @@ -230,9 +236,9 @@ typedef struct opj_tcd_tile { OPJ_INT32 x0, y0, x1, y1; OPJ_UINT32 numcomps; /* number of components in tile */ opj_tcd_tilecomp_t *comps; /* Components information */ - OPJ_INT32 numpix; /* add fixed_quality */ - OPJ_FLOAT64 distotile; /* add fixed_quality */ - OPJ_FLOAT64 distolayer[100]; /* add fixed_quality */ + OPJ_SIZE_T numpix; /* number of pixels */ + OPJ_FLOAT64 distotile; /* distortion of the tile */ + OPJ_FLOAT64 distolayer[100]; /* distortion per layer */ OPJ_UINT32 packno; /* packet number */ } opj_tcd_tile_t; @@ -284,6 +290,22 @@ typedef struct opj_tcd { OPJ_BOOL* used_component; } opj_tcd_t; +/** + * Structure to hold information needed to generate some markers. + * Used by encoder. + */ +typedef struct opj_tcd_marker_info { + /** In: Whether information to generate PLT markers in needed */ + OPJ_BOOL need_PLT; + + /** OUT: Number of elements in p_packet_size[] array */ + OPJ_UINT32 packet_count; + + /** OUT: Array of size packet_count, such that p_packet_size[i] is + * the size in bytes of the ith packet */ + OPJ_UINT32* p_packet_size; +} opj_tcd_marker_info_t; + /** @name Exported functions */ /*@{*/ /* ----------------------------------------------------------------------- */ @@ -291,7 +313,7 @@ typedef struct opj_tcd { /** Dump the content of a tcd structure */ -/*void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img);*/ /* TODO MSD shoul use the new v2 structures */ +/*void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img);*/ /* TODO MSD should use the new v2 structures */ /** Create a new TCD handle @@ -306,6 +328,21 @@ Destroy a previously created TCD handle */ void opj_tcd_destroy(opj_tcd_t *tcd); + +/** + * Create a new opj_tcd_marker_info_t* structure + * @param need_PLT Whether information is needed to generate PLT markers. + */ +opj_tcd_marker_info_t* opj_tcd_marker_info_create(OPJ_BOOL need_PLT); + + +/** +Destroy a previously created opj_tcd_marker_info_t* structure +@param p_tcd_marker_info Structure to destroy +*/ +void opj_tcd_marker_info_destroy(opj_tcd_marker_info_t *p_tcd_marker_info); + + /** * Initialize the tile coder and may reuse some memory. * @param p_tcd TCD handle. @@ -333,23 +370,6 @@ OPJ_BOOL opj_tcd_init(opj_tcd_t *p_tcd, OPJ_BOOL opj_tcd_init_decode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, opj_event_mgr_t* p_manager); -void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, - OPJ_UINT32 final); - -void opj_tcd_rateallocate_fixed(opj_tcd_t *tcd); - -void opj_tcd_makelayer(opj_tcd_t *tcd, - OPJ_UINT32 layno, - OPJ_FLOAT64 thresh, - OPJ_UINT32 final); - -OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, - OPJ_BYTE *dest, - OPJ_UINT32 * p_data_written, - OPJ_UINT32 len, - opj_codestream_info_t *cstr_info, - opj_event_mgr_t *p_manager); - /** * Gets the maximum tile size that will be taken by the tile once decoded. */ @@ -364,6 +384,7 @@ OPJ_UINT32 opj_tcd_get_decoded_tile_size(opj_tcd_t *p_tcd, * @param p_data_written pointer to an int that is incremented by the number of bytes really written on p_dest * @param p_len Maximum length of the destination buffer * @param p_cstr_info Codestream information structure + * @param p_marker_info Marker information structure * @param p_manager the user event manager * @return true if the coding is successful. */ @@ -373,6 +394,7 @@ OPJ_BOOL opj_tcd_encode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 * p_data_written, OPJ_UINT32 p_len, struct opj_codestream_info *p_cstr_info, + opj_tcd_marker_info_t* p_marker_info, opj_event_mgr_t *p_manager); @@ -415,12 +437,14 @@ OPJ_BOOL opj_tcd_update_tile_data(opj_tcd_t *p_tcd, OPJ_UINT32 p_dest_length); /** - * + * Get the size in bytes of the input buffer provided before encoded. + * This must be the size provided to the p_src_length argument of + * opj_tcd_copy_tile_data() */ -OPJ_SIZE_T opj_tcd_get_encoded_tile_size(opj_tcd_t *p_tcd); +OPJ_SIZE_T opj_tcd_get_encoder_input_buffer_size(opj_tcd_t *p_tcd); /** - * Initialize the tile coder and may reuse some meory. + * Initialize the tile coder and may reuse some memory. * * @param p_tcd TCD handle. * @param p_tile_no current tile index to encode. @@ -433,6 +457,8 @@ OPJ_BOOL opj_tcd_init_encode_tile(opj_tcd_t *p_tcd, /** * Copies tile data from the given memory block onto the system. + * + * p_src_length must be equal to opj_tcd_get_encoder_input_buffer_size() */ OPJ_BOOL opj_tcd_copy_tile_data(opj_tcd_t *p_tcd, OPJ_BYTE * p_src, @@ -466,7 +492,7 @@ void opj_tcd_reinit_segment(opj_tcd_seg_t* seg); * @param y0 Upper left y in subband coordinates * @param x1 Lower right x in subband coordinates * @param y1 Lower right y in subband coordinates - * @return OPJ_TRUE whether the sub-band region contributs to the area of + * @return OPJ_TRUE whether the sub-band region contributes to the area of * interest. */ OPJ_BOOL opj_tcd_is_subband_area_of_interest(opj_tcd_t *tcd, diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/tgt.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/tgt.c index 0cbad12c42e..711d753f46c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/tgt.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/tgt.c @@ -287,12 +287,12 @@ void opj_tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, while (low < threshold) { if (low >= node->value) { if (!node->known) { - opj_bio_write(bio, 1, 1); + opj_bio_putbit(bio, 1); node->known = 1; } break; } - opj_bio_write(bio, 0, 1); + opj_bio_putbit(bio, 0); ++low; } diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/thread.c b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/thread.c index af33c2c8062..240810b1c44 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/thread.c +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmopenjpeg/src/lib/openjp2/thread.c @@ -221,7 +221,7 @@ struct opj_thread_t { HANDLE hThread; }; -unsigned int __stdcall opj_thread_callback_adapter(void *info) +static unsigned int __stdcall opj_thread_callback_adapter(void *info) { opj_thread_t* thread = (opj_thread_t*) info; HANDLE hEvent = NULL; @@ -723,6 +723,8 @@ static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads) tp->worker_threads[i].thread = opj_thread_create(opj_worker_thread_function, &(tp->worker_threads[i])); if (tp->worker_threads[i].thread == NULL) { + opj_mutex_destroy(tp->worker_threads[i].mutex); + opj_cond_destroy(tp->worker_threads[i].cond); tp->worker_threads_count = i; bRet = OPJ_FALSE; break; @@ -732,7 +734,7 @@ static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads) /* Wait all threads to be started */ /* printf("waiting for all threads to be started\n"); */ opj_mutex_lock(tp->mutex); - while (tp->waiting_worker_thread_count < num_threads) { + while (tp->waiting_worker_thread_count < tp->worker_threads_count) { opj_cond_wait(tp->cond, tp->mutex); } opj_mutex_unlock(tp->mutex); diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmrle/io.cxx b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmrle/io.cxx index a3991b4f2da..8cbba82b6e6 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmrle/io.cxx +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmrle/io.cxx @@ -14,6 +14,7 @@ #include "io.h" #include "info.h" +#include #include #include @@ -78,6 +79,7 @@ int source::read_into_segments( char * out, int len, image_info const & ii ) int nvalues = read(out + 0 * llen, llen); assert( nvalues == llen ); (void)nvalues; bool b = seek(pos + 1 * plane); + (void)b; assert(b); nvalues = read(out + 1 * llen, llen); assert( nvalues == llen ); (void)nvalues; diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/README.GDCM.txt b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/README.GDCM.txt deleted file mode 100644 index 36d9195bf0b..00000000000 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/README.GDCM.txt +++ /dev/null @@ -1,17 +0,0 @@ -I was looking for a UTF-8 lightweight library with a license compatible with GDCM. - -I (Mathieu Malaterre) decided to pick utfcpp: -http://sourceforge.net/projects/utfcpp/ - -Version 2.3.4 is included here, with no changes. - -Source: -http://sourceforge.net/projects/utfcpp/files/utf8cpp_2x/Release%202.3.4/utf8_v2_3_4.zip/download - -SHA 256 checksum: -3373cebb25d88c662a2b960c4d585daf9ae7b396031ecd786e7bb31b15d010ef - - -New location is: - -* https://github.com/nemtrif/utfcpp diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/utf8.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/utf8.h deleted file mode 100644 index 82b13f59f98..00000000000 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/utf8.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2006 Nemanja Trifunovic - -/* -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -*/ - - -#ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 -#define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 - -#include "utf8/checked.h" -#include "utf8/unchecked.h" - -#endif // header guard diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/utf8/checked.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/utf8/checked.h deleted file mode 100644 index 13311551381..00000000000 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/utf8/checked.h +++ /dev/null @@ -1,327 +0,0 @@ -// Copyright 2006 Nemanja Trifunovic - -/* -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -*/ - - -#ifndef UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 -#define UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 - -#include "core.h" -#include - -namespace utf8 -{ - // Base for the exceptions that may be thrown from the library - class exception : public ::std::exception { - }; - - // Exceptions that may be thrown from the library functions. - class invalid_code_point : public exception { - uint32_t cp; - public: - invalid_code_point(uint32_t cp) : cp(cp) {} - virtual const char* what() const throw() { return "Invalid code point"; } - uint32_t code_point() const {return cp;} - }; - - class invalid_utf8 : public exception { - uint8_t u8; - public: - invalid_utf8 (uint8_t u) : u8(u) {} - virtual const char* what() const throw() { return "Invalid UTF-8"; } - uint8_t utf8_octet() const {return u8;} - }; - - class invalid_utf16 : public exception { - uint16_t u16; - public: - invalid_utf16 (uint16_t u) : u16(u) {} - virtual const char* what() const throw() { return "Invalid UTF-16"; } - uint16_t utf16_word() const {return u16;} - }; - - class not_enough_room : public exception { - public: - virtual const char* what() const throw() { return "Not enough space"; } - }; - - /// The library API - functions intended to be called by the users - - template - octet_iterator append(uint32_t cp, octet_iterator result) - { - if (!utf8::internal::is_code_point_valid(cp)) - throw invalid_code_point(cp); - - if (cp < 0x80) // one octet - *(result++) = static_cast(cp); - else if (cp < 0x800) { // two octets - *(result++) = static_cast((cp >> 6) | 0xc0); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - else if (cp < 0x10000) { // three octets - *(result++) = static_cast((cp >> 12) | 0xe0); - *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - else { // four octets - *(result++) = static_cast((cp >> 18) | 0xf0); - *(result++) = static_cast(((cp >> 12) & 0x3f) | 0x80); - *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - return result; - } - - template - output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement) - { - while (start != end) { - octet_iterator sequence_start = start; - internal::utf_error err_code = utf8::internal::validate_next(start, end); - switch (err_code) { - case internal::UTF8_OK : - for (octet_iterator it = sequence_start; it != start; ++it) - *out++ = *it; - break; - case internal::NOT_ENOUGH_ROOM: - throw not_enough_room(); - case internal::INVALID_LEAD: - out = utf8::append (replacement, out); - ++start; - break; - case internal::INCOMPLETE_SEQUENCE: - case internal::OVERLONG_SEQUENCE: - case internal::INVALID_CODE_POINT: - out = utf8::append (replacement, out); - ++start; - // just one replacement mark for the sequence - while (start != end && utf8::internal::is_trail(*start)) - ++start; - break; - } - } - return out; - } - - template - inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out) - { - static const uint32_t replacement_marker = utf8::internal::mask16(0xfffd); - return utf8::replace_invalid(start, end, out, replacement_marker); - } - - template - uint32_t next(octet_iterator& it, octet_iterator end) - { - uint32_t cp = 0; - internal::utf_error err_code = utf8::internal::validate_next(it, end, cp); - switch (err_code) { - case internal::UTF8_OK : - break; - case internal::NOT_ENOUGH_ROOM : - throw not_enough_room(); - case internal::INVALID_LEAD : - case internal::INCOMPLETE_SEQUENCE : - case internal::OVERLONG_SEQUENCE : - throw invalid_utf8(*it); - case internal::INVALID_CODE_POINT : - throw invalid_code_point(cp); - } - return cp; - } - - template - uint32_t peek_next(octet_iterator it, octet_iterator end) - { - return utf8::next(it, end); - } - - template - uint32_t prior(octet_iterator& it, octet_iterator start) - { - // can't do much if it == start - if (it == start) - throw not_enough_room(); - - octet_iterator end = it; - // Go back until we hit either a lead octet or start - while (utf8::internal::is_trail(*(--it))) - if (it == start) - throw invalid_utf8(*it); // error - no lead byte in the sequence - return utf8::peek_next(it, end); - } - - /// Deprecated in versions that include "prior" - template - uint32_t previous(octet_iterator& it, octet_iterator pass_start) - { - octet_iterator end = it; - while (utf8::internal::is_trail(*(--it))) - if (it == pass_start) - throw invalid_utf8(*it); // error - no lead byte in the sequence - octet_iterator temp = it; - return utf8::next(temp, end); - } - - template - void advance (octet_iterator& it, distance_type n, octet_iterator end) - { - for (distance_type i = 0; i < n; ++i) - utf8::next(it, end); - } - - template - typename std::iterator_traits::difference_type - distance (octet_iterator first, octet_iterator last) - { - typename std::iterator_traits::difference_type dist; - for (dist = 0; first < last; ++dist) - utf8::next(first, last); - return dist; - } - - template - octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result) - { - while (start != end) { - uint32_t cp = utf8::internal::mask16(*start++); - // Take care of surrogate pairs first - if (utf8::internal::is_lead_surrogate(cp)) { - if (start != end) { - uint32_t trail_surrogate = utf8::internal::mask16(*start++); - if (utf8::internal::is_trail_surrogate(trail_surrogate)) - cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET; - else - throw invalid_utf16(static_cast(trail_surrogate)); - } - else - throw invalid_utf16(static_cast(cp)); - - } - // Lone trail surrogate - else if (utf8::internal::is_trail_surrogate(cp)) - throw invalid_utf16(static_cast(cp)); - - result = utf8::append(cp, result); - } - return result; - } - - template - u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result) - { - while (start != end) { - uint32_t cp = utf8::next(start, end); - if (cp > 0xffff) { //make a surrogate pair - *result++ = static_cast((cp >> 10) + internal::LEAD_OFFSET); - *result++ = static_cast((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN); - } - else - *result++ = static_cast(cp); - } - return result; - } - - template - octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result) - { - while (start != end) - result = utf8::append(*(start++), result); - - return result; - } - - template - u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result) - { - while (start != end) - (*result++) = utf8::next(start, end); - - return result; - } - - // The iterator class - template - class iterator : public std::iterator { - octet_iterator it; - octet_iterator range_start; - octet_iterator range_end; - public: - iterator () {} - explicit iterator (const octet_iterator& octet_it, - const octet_iterator& range_start, - const octet_iterator& range_end) : - it(octet_it), range_start(range_start), range_end(range_end) - { - if (it < range_start || it > range_end) - throw std::out_of_range("Invalid utf-8 iterator position"); - } - // the default "big three" are OK - octet_iterator base () const { return it; } - uint32_t operator * () const - { - octet_iterator temp = it; - return utf8::next(temp, range_end); - } - bool operator == (const iterator& rhs) const - { - if (range_start != rhs.range_start || range_end != rhs.range_end) - throw std::logic_error("Comparing utf-8 iterators defined with different ranges"); - return (it == rhs.it); - } - bool operator != (const iterator& rhs) const - { - return !(operator == (rhs)); - } - iterator& operator ++ () - { - utf8::next(it, range_end); - return *this; - } - iterator operator ++ (int) - { - iterator temp = *this; - utf8::next(it, range_end); - return temp; - } - iterator& operator -- () - { - utf8::prior(it, range_start); - return *this; - } - iterator operator -- (int) - { - iterator temp = *this; - utf8::prior(it, range_start); - return temp; - } - }; // class iterator - -} // namespace utf8 - -#endif //header guard - - diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/utf8/core.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/utf8/core.h deleted file mode 100644 index 693d388c078..00000000000 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/utf8/core.h +++ /dev/null @@ -1,329 +0,0 @@ -// Copyright 2006 Nemanja Trifunovic - -/* -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -*/ - - -#ifndef UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 -#define UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 - -#include - -namespace utf8 -{ - // The typedefs for 8-bit, 16-bit and 32-bit unsigned integers - // You may need to change them to match your system. - // These typedefs have the same names as ones from cstdint, or boost/cstdint - typedef unsigned char uint8_t; - typedef unsigned short uint16_t; - typedef unsigned int uint32_t; - -// Helper code - not intended to be directly called by the library users. May be changed at any time -namespace internal -{ - // Unicode constants - // Leading (high) surrogates: 0xd800 - 0xdbff - // Trailing (low) surrogates: 0xdc00 - 0xdfff - const uint16_t LEAD_SURROGATE_MIN = 0xd800u; - const uint16_t LEAD_SURROGATE_MAX = 0xdbffu; - const uint16_t TRAIL_SURROGATE_MIN = 0xdc00u; - const uint16_t TRAIL_SURROGATE_MAX = 0xdfffu; - const uint16_t LEAD_OFFSET = LEAD_SURROGATE_MIN - (0x10000 >> 10); - const uint32_t SURROGATE_OFFSET = 0x10000u - (LEAD_SURROGATE_MIN << 10) - TRAIL_SURROGATE_MIN; - - // Maximum valid value for a Unicode code point - const uint32_t CODE_POINT_MAX = 0x0010ffffu; - - template - inline uint8_t mask8(octet_type oc) - { - return static_cast(0xff & oc); - } - template - inline uint16_t mask16(u16_type oc) - { - return static_cast(0xffff & oc); - } - template - inline bool is_trail(octet_type oc) - { - return ((utf8::internal::mask8(oc) >> 6) == 0x2); - } - - template - inline bool is_lead_surrogate(u16 cp) - { - return (cp >= LEAD_SURROGATE_MIN && cp <= LEAD_SURROGATE_MAX); - } - - template - inline bool is_trail_surrogate(u16 cp) - { - return (cp >= TRAIL_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX); - } - - template - inline bool is_surrogate(u16 cp) - { - return (cp >= LEAD_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX); - } - - template - inline bool is_code_point_valid(u32 cp) - { - return (cp <= CODE_POINT_MAX && !utf8::internal::is_surrogate(cp)); - } - - template - inline typename std::iterator_traits::difference_type - sequence_length(octet_iterator lead_it) - { - uint8_t lead = utf8::internal::mask8(*lead_it); - if (lead < 0x80) - return 1; - else if ((lead >> 5) == 0x6) - return 2; - else if ((lead >> 4) == 0xe) - return 3; - else if ((lead >> 3) == 0x1e) - return 4; - else - return 0; - } - - template - inline bool is_overlong_sequence(uint32_t cp, octet_difference_type length) - { - if (cp < 0x80) { - if (length != 1) - return true; - } - else if (cp < 0x800) { - if (length != 2) - return true; - } - else if (cp < 0x10000) { - if (length != 3) - return true; - } - - return false; - } - - enum utf_error {UTF8_OK, NOT_ENOUGH_ROOM, INVALID_LEAD, INCOMPLETE_SEQUENCE, OVERLONG_SEQUENCE, INVALID_CODE_POINT}; - - /// Helper for get_sequence_x - template - utf_error increase_safely(octet_iterator& it, octet_iterator end) - { - if (++it == end) - return NOT_ENOUGH_ROOM; - - if (!utf8::internal::is_trail(*it)) - return INCOMPLETE_SEQUENCE; - - return UTF8_OK; - } - - #define UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(IT, END) {utf_error ret = increase_safely(IT, END); if (ret != UTF8_OK) return ret;} - - /// get_sequence_x functions decode utf-8 sequences of the length x - template - utf_error get_sequence_1(octet_iterator& it, octet_iterator end, uint32_t& code_point) - { - if (it == end) - return NOT_ENOUGH_ROOM; - - code_point = utf8::internal::mask8(*it); - - return UTF8_OK; - } - - template - utf_error get_sequence_2(octet_iterator& it, octet_iterator end, uint32_t& code_point) - { - if (it == end) - return NOT_ENOUGH_ROOM; - - code_point = utf8::internal::mask8(*it); - - UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) - - code_point = ((code_point << 6) & 0x7ff) + ((*it) & 0x3f); - - return UTF8_OK; - } - - template - utf_error get_sequence_3(octet_iterator& it, octet_iterator end, uint32_t& code_point) - { - if (it == end) - return NOT_ENOUGH_ROOM; - - code_point = utf8::internal::mask8(*it); - - UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) - - code_point = ((code_point << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff); - - UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) - - code_point += (*it) & 0x3f; - - return UTF8_OK; - } - - template - utf_error get_sequence_4(octet_iterator& it, octet_iterator end, uint32_t& code_point) - { - if (it == end) - return NOT_ENOUGH_ROOM; - - code_point = utf8::internal::mask8(*it); - - UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) - - code_point = ((code_point << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff); - - UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) - - code_point += (utf8::internal::mask8(*it) << 6) & 0xfff; - - UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) - - code_point += (*it) & 0x3f; - - return UTF8_OK; - } - - #undef UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR - - template - utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t& code_point) - { - // Save the original value of it so we can go back in case of failure - // Of course, it does not make much sense with i.e. stream iterators - octet_iterator original_it = it; - - uint32_t cp = 0; - // Determine the sequence length based on the lead octet - typedef typename std::iterator_traits::difference_type octet_difference_type; - const octet_difference_type length = utf8::internal::sequence_length(it); - - // Get trail octets and calculate the code point - utf_error err = UTF8_OK; - switch (length) { - case 0: - return INVALID_LEAD; - case 1: - err = utf8::internal::get_sequence_1(it, end, cp); - break; - case 2: - err = utf8::internal::get_sequence_2(it, end, cp); - break; - case 3: - err = utf8::internal::get_sequence_3(it, end, cp); - break; - case 4: - err = utf8::internal::get_sequence_4(it, end, cp); - break; - } - - if (err == UTF8_OK) { - // Decoding succeeded. Now, security checks... - if (utf8::internal::is_code_point_valid(cp)) { - if (!utf8::internal::is_overlong_sequence(cp, length)){ - // Passed! Return here. - code_point = cp; - ++it; - return UTF8_OK; - } - else - err = OVERLONG_SEQUENCE; - } - else - err = INVALID_CODE_POINT; - } - - // Failure branch - restore the original value of the iterator - it = original_it; - return err; - } - - template - inline utf_error validate_next(octet_iterator& it, octet_iterator end) { - uint32_t ignored; - return utf8::internal::validate_next(it, end, ignored); - } - -} // namespace internal - - /// The library API - functions intended to be called by the users - - // Byte order mark - const uint8_t bom[] = {0xef, 0xbb, 0xbf}; - - template - octet_iterator find_invalid(octet_iterator start, octet_iterator end) - { - octet_iterator result = start; - while (result != end) { - utf8::internal::utf_error err_code = utf8::internal::validate_next(result, end); - if (err_code != internal::UTF8_OK) - return result; - } - return result; - } - - template - inline bool is_valid(octet_iterator start, octet_iterator end) - { - return (utf8::find_invalid(start, end) == end); - } - - template - inline bool starts_with_bom (octet_iterator it, octet_iterator end) - { - return ( - ((it != end) && (utf8::internal::mask8(*it++)) == bom[0]) && - ((it != end) && (utf8::internal::mask8(*it++)) == bom[1]) && - ((it != end) && (utf8::internal::mask8(*it)) == bom[2]) - ); - } - - //Deprecated in release 2.3 - template - inline bool is_bom (octet_iterator it) - { - return ( - (utf8::internal::mask8(*it++)) == bom[0] && - (utf8::internal::mask8(*it++)) == bom[1] && - (utf8::internal::mask8(*it)) == bom[2] - ); - } -} // namespace utf8 - -#endif // header guard - - diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/utf8/unchecked.h b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/utf8/unchecked.h deleted file mode 100644 index cb2427166b1..00000000000 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmutfcpp/utf8/unchecked.h +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright 2006 Nemanja Trifunovic - -/* -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -*/ - - -#ifndef UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 -#define UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 - -#include "core.h" - -namespace utf8 -{ - namespace unchecked - { - template - octet_iterator append(uint32_t cp, octet_iterator result) - { - if (cp < 0x80) // one octet - *(result++) = static_cast(cp); - else if (cp < 0x800) { // two octets - *(result++) = static_cast((cp >> 6) | 0xc0); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - else if (cp < 0x10000) { // three octets - *(result++) = static_cast((cp >> 12) | 0xe0); - *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - else { // four octets - *(result++) = static_cast((cp >> 18) | 0xf0); - *(result++) = static_cast(((cp >> 12) & 0x3f)| 0x80); - *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); - *(result++) = static_cast((cp & 0x3f) | 0x80); - } - return result; - } - - template - uint32_t next(octet_iterator& it) - { - uint32_t cp = utf8::internal::mask8(*it); - typename std::iterator_traits::difference_type length = utf8::internal::sequence_length(it); - switch (length) { - case 1: - break; - case 2: - it++; - cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f); - break; - case 3: - ++it; - cp = ((cp << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff); - ++it; - cp += (*it) & 0x3f; - break; - case 4: - ++it; - cp = ((cp << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff); - ++it; - cp += (utf8::internal::mask8(*it) << 6) & 0xfff; - ++it; - cp += (*it) & 0x3f; - break; - } - ++it; - return cp; - } - - template - uint32_t peek_next(octet_iterator it) - { - return utf8::unchecked::next(it); - } - - template - uint32_t prior(octet_iterator& it) - { - while (utf8::internal::is_trail(*(--it))) ; - octet_iterator temp = it; - return utf8::unchecked::next(temp); - } - - // Deprecated in versions that include prior, but only for the sake of consistency (see utf8::previous) - template - inline uint32_t previous(octet_iterator& it) - { - return utf8::unchecked::prior(it); - } - - template - void advance (octet_iterator& it, distance_type n) - { - for (distance_type i = 0; i < n; ++i) - utf8::unchecked::next(it); - } - - template - typename std::iterator_traits::difference_type - distance (octet_iterator first, octet_iterator last) - { - typename std::iterator_traits::difference_type dist; - for (dist = 0; first < last; ++dist) - utf8::unchecked::next(first); - return dist; - } - - template - octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result) - { - while (start != end) { - uint32_t cp = utf8::internal::mask16(*start++); - // Take care of surrogate pairs first - if (utf8::internal::is_lead_surrogate(cp)) { - uint32_t trail_surrogate = utf8::internal::mask16(*start++); - cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET; - } - result = utf8::unchecked::append(cp, result); - } - return result; - } - - template - u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result) - { - while (start < end) { - uint32_t cp = utf8::unchecked::next(start); - if (cp > 0xffff) { //make a surrogate pair - *result++ = static_cast((cp >> 10) + internal::LEAD_OFFSET); - *result++ = static_cast((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN); - } - else - *result++ = static_cast(cp); - } - return result; - } - - template - octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result) - { - while (start != end) - result = utf8::unchecked::append(*(start++), result); - - return result; - } - - template - u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result) - { - while (start < end) - (*result++) = utf8::unchecked::next(start); - - return result; - } - - // The iterator class - template - class iterator : public std::iterator { - octet_iterator it; - public: - iterator () {} - explicit iterator (const octet_iterator& octet_it): it(octet_it) {} - // the default "big three" are OK - octet_iterator base () const { return it; } - uint32_t operator * () const - { - octet_iterator temp = it; - return utf8::unchecked::next(temp); - } - bool operator == (const iterator& rhs) const - { - return (it == rhs.it); - } - bool operator != (const iterator& rhs) const - { - return !(operator == (rhs)); - } - iterator& operator ++ () - { - ::std::advance(it, utf8::internal::sequence_length(it)); - return *this; - } - iterator operator ++ (int) - { - iterator temp = *this; - ::std::advance(it, utf8::internal::sequence_length(it)); - return temp; - } - iterator& operator -- () - { - utf8::unchecked::prior(it); - return *this; - } - iterator operator -- (int) - { - iterator temp = *this; - utf8::unchecked::prior(it); - return temp; - } - }; // class iterator - - } // namespace utf8::unchecked -} // namespace utf8 - - -#endif // header guard - diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmuuid/CMakeLists.txt b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmuuid/CMakeLists.txt index cd3083bf656..b7427c76fe4 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmuuid/CMakeLists.txt +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmuuid/CMakeLists.txt @@ -1,5 +1,5 @@ if(NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION) - cmake_minimum_required(VERSION 2.8.7) + cmake_minimum_required(VERSION 2.8.7...${GDCM_MAX_VALIDATED_CMAKE_VERSION}) endif() if(NOT UUID_NAMESPACE) diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/socketxx/CMakeLists.txt b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/socketxx/CMakeLists.txt index ce15b8aa4a7..10fd29483ac 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/socketxx/CMakeLists.txt +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/socketxx/CMakeLists.txt @@ -1,17 +1,7 @@ if(NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION) - cmake_minimum_required(VERSION 2.8.7) + cmake_minimum_required(VERSION 2.8.7...${GDCM_MAX_VALIDATED_CMAKE_VERSION}) endif() -foreach(p - CMP0022 - CMP0042 - CMP0063 # CMake 3.3.2 - ) - if(POLICY ${p}) - cmake_policy(SET ${p} NEW) - endif() -endforeach() - # http://www.linuxhacker.at/socketxx if(NOT SOCKETXX_NAMESPACE) set(SOCKETXX_NAMESPACE "SOCKETXX") diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/socketxx/COPYING b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/socketxx/COPYING index 31040c2ae82..84636032759 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/socketxx/COPYING +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/socketxx/COPYING @@ -3,8 +3,8 @@ Copyright Notice: Copyright (C) 1992-1996 Gnanasekaran Swaminathan Permission is granted to use at your own risk and distribute this software -in source and binary forms provided the above copyright notice and this -paragraph are preserved on all copies. This software is provided "as is" +in source and binary forms provided the above copyright notice and this +paragraph are preserved on all copies. This software is provided "as is" with no express or implied warranty. diff --git a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/socketxx/socket++/fork.cpp b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/socketxx/socket++/fork.cpp index 4b580aa1f88..87f7c6e225c 100644 --- a/Modules/ThirdParty/GDCM/src/gdcm/Utilities/socketxx/socket++/fork.cpp +++ b/Modules/ThirdParty/GDCM/src/gdcm/Utilities/socketxx/socket++/fork.cpp @@ -38,9 +38,13 @@ Fork::KillForks::~KillForks () // First, kill all children whose kill_child flag is set. // Second, wait for other children to die. { - for (ForkProcess* cur = Fork::ForkProcess::list; cur; cur = cur->next) - if (cur->kill_child) + ForkProcess* cur = Fork::ForkProcess::list; + while(cur != nullptr){ + ForkProcess* next = cur->next; + if(cur->kill_child) delete cur; + cur = next; + } while (Fork::ForkProcess::list && wait (nullptr) > 0) {} }