[med-svn] [dcm2niix] 02/07: New upstream version 1.0.20170724

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun Aug 13 13:37:06 UTC 2017


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/master
in repository dcm2niix.

commit 39d49e6f9a7be4797a137fd9a117c5854745c27b
Author: Ghislain Antony Vaillant <ghisvail at gmail.com>
Date:   Sat Aug 12 15:20:02 2017 +0100

    New upstream version 1.0.20170724
---
 .travis.yml                        |  2 +-
 COMPILE.md                         | 27 +++++++++------
 SuperBuild/External-OPENJPEG.cmake |  2 +-
 SuperBuild/SuperBuild.cmake        | 70 ++++++++++++++++++++++----------------
 console/CMakeLists.txt             | 47 ++++++++++++++-----------
 console/main_console.cpp           |  5 ++-
 console/makefile                   |  2 +-
 console/nii_dicom.cpp              | 46 ++++++++++++++++++++-----
 console/nii_dicom_batch.cpp        | 20 ++++++++---
 9 files changed, 144 insertions(+), 77 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 80f4058..ca2ece9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -17,7 +17,7 @@ before_install:
 script:
   - mkdir build && cd build && cmake -DBATCH_VERSION=ON -DUSE_OPENJPEG=ON .. && make && cd -
   - export PATH=$PWD/build/bin:$PATH
-  - cd dcm_qa; ./batch.sh
+  - cd dcm_qa && ./batch.sh && cd -
 
 before_deploy:
   - export DATE=`date +%-d-%b-%Y`
diff --git a/COMPILE.md b/COMPILE.md
index 46ce378..c5c8e06 100644
--- a/COMPILE.md
+++ b/COMPILE.md
@@ -12,7 +12,7 @@ The text below generally describes how to build dcm2niix using the [GCC](https:/
 You can also build the software without C-make. The easiest way to do this is to run the function "make" from the "console" folder. Note that this only creates the default version of dcm2niix, not the optional batch version described above. The make command simply calls the g++ compiler, and if you want you can tune this for your build. In essence, the make function simply calls
 
 ```
-g++ -dead_strip -O3 -I. main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -o dcm2niix -DmyDisableOpenJPEG -DmyDisableJasper
+g++ -dead_strip -O3 -I. main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -o dcm2niix -DmyDisableOpenJPEG
 ```
 
 The following sub-sections list how you can modify this basic recipe for your needs.
@@ -37,7 +37,7 @@ g++ -O3 -s -DmyDisableOpenJPEG -DmyDisableZLib -I. main_console.cpp nii_dicom.cp
 DICOM images can be stored as either raw data or compressed using one of many formats as described by the [transfer syntaxes](https://www.nitrc.org/plugins/mwiki/index.php/dcm2nii:MainPage#Transfer_Syntaxes_and_Compressed_Images). One of the compressed formats is the lossy classic JPEG format (which is separate from and predates the lossy JPEG 2000 format). This software comes with the [NanoJPEG](http://keyj.emphy.de/nanojpeg/) library to handle these images. However, you can use the `my [...]
 
 ```
-g++ -dead_strip -O3 -I. main_console.cpp nii_dicom.cpp jpg_0XC3.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -o dcm2niix -DmyDisableClassicJPEG -DmyDisableOpenJPEG -DmyDisableJasper
+g++ -dead_strip -O3 -I. main_console.cpp nii_dicom.cpp jpg_0XC3.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -o dcm2niix -DmyDisableClassicJPEG -DmyDisableOpenJPEG
 ```
 
 ##### USING LIBJPEG-TURBO TO DECODE CLASSIC JPEG
@@ -45,14 +45,16 @@ g++ -dead_strip -O3 -I. main_console.cpp nii_dicom.cpp jpg_0XC3.cpp nifti1_io_co
 By default, classic JPEG images will be decoded using the [compact NanoJPEG decoder](http://keyj.emphy.de/nanojpeg/). However, the compiler directive `myTurboJPEG`  will create an executable based on the [libjpeg-turbo](http://www.libjpeg-turbo.org) library. This library is a faster decoder and is the standard for many Linux distributions. On the other hand, the lossy classic JPEG is rarely used for DICOM images, so this compilation has extra dependencies and can result in a larger execu [...]
 
 ```
-g++ -dead_strip -O3 -I. main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -o dcm2niix -DmyDisableOpenJPEG -DmyDisableJasper -DmyTurboJPEG -I/opt/libjpeg-turbo/include /opt/libjpeg-turbo/lib/libturbojpeg.a
+g++ -dead_strip -O3 -I. main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -o dcm2niix -DmyDisableOpenJPEG -DmyTurboJPEG -I/opt/libjpeg-turbo/include /opt/libjpeg-turbo/lib/libturbojpeg.a
 ```
 
 ##### JPEG2000 BUILD
 
- If you want to build this with JPEG2000 decompression support using OpenJPEG. You will need to have the OpenJPEG 2.1 libraries installed (https://code.google.com/p/openjpeg/wiki/Installation). I suggest building static libraries where you would [download the code](https://github.com/uclouvain/openjpeg) and run
+You can compile dcm2niix to convert DICOM images compressed with the JPEG2000 [transfer syntaxes 1.2.840.10008.1.2.4.90 and 1.2.840.10008.1.2.4.91](https://www.nitrc.org/plugins/mwiki/index.php/dcm2nii:MainPage#Transfer_Syntaxes_and_Compressed_Images). This is optional, as JPEG2000 is very rare in DICOMs (usually only created by the proprietary DCMJP2K or OsiriX). Due to the challenges discussed below this is a poor choice for archiving DICOM data. Rather than support conversion with dcm [...]
+
+You can build dcm2niix with JPEG2000 decompression support using OpenJPEG 2.1.0. You will need to have the OpenJPEG library installed (use the package manager of your linux distribution, Homebrew for macOS, or see [here](https://github.com/uclouvain/openjpeg/blob/master/INSTALL.md) if you want to build it yourself). If you want to use a more recent version of OpenJPEG, it must be custom-compiled with `-DOPJ_DISABLE_TPSOT_FIX` compiler flag. I suggest building static libraries where you w [...]
 ```
- cmake -DBUILD_SHARED_LIBS:bool=off .
+ cmake -DBUILD_SHARED_LIBS:bool=off -DOPJ_DISABLE_TPSOT_FIX:bool=on .
  make
  sudo make install
 ```
@@ -62,14 +64,19 @@ You should then be able to run then run:
 g++ -O3 -dead_strip -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp nii_foreign.cpp -o dcm2niix -lopenjp2
 ```
 
-But in my experience this works best if you explicitly tell the software how to find the libraries, so your compile will probably look like one of these two options:
+But in my experience this works best if you explicitly tell the software how to find the libraries, so your compile will probably look like one of these options:
 
 ```
+#for MacOS
 g++ -O3 -dead_strip -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp nii_foreign.cpp -o dcm2niix -I/usr/local/include/openjpeg-2.1 /usr/local/lib/libopenjp2.a
 ```
-
 ```
-g++ -O3 -dead_strip -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp nii_foreign.cpp -o dcm2niix -I/usr/local/lib /usr/local/lib/libopenjp2.a
+#For older Linux
+g++ -O3 -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp nii_foreign.cpp -o dcm2niix -I/usr/local/lib /usr/local/lib/libopenjp2.a
+```
+```
+#For modern Linux
+g++ -O3 -s -I. main_console.cpp nii_dicom.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp jpg_0XC3.cpp ujpeg.cpp nii_foreign.cpp -lpthread -o dcm2niix -I/usr/local/include/openjpeg-2.2 ~/openjpeg-master/build/bin/libopenjp2.a
 ```
 
  If you want to build this with JPEG2000 decompression support using Jasper: You will need to have the Jasper (http://www.ece.uvic.ca/~frodo/jasper/) and libjpeg (http://www.ijg.org) libraries installed which for Linux users may be as easy as running 'sudo apt-get install libjasper-dev' (otherwise, see http://www.ece.uvic.ca/~frodo/jasper/#doc). You can then run:
@@ -84,7 +91,7 @@ This software can be compiled with VisualStudio 2015. This example assumes the c
 
 ```
 vcvarsall amd64
-cl /EHsc main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -DmyDisableOpenJPEG -DmyDisableJasper /odcm2niix
+cl /EHsc main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp nii_foreign.cpp -DmyDisableOpenJPEG /o dcm2niix
 ```
 
 ##### OSX BUILD WITH BOTH 32 AND 64-BIT SUPPORT
@@ -140,4 +147,4 @@ CXXFLAGS = -DmyUseCOut -DWX_PRECOMP ....
  i.) For a full refresh
 rm clipboard
 rm *.o
-make
\ No newline at end of file
+make
diff --git a/SuperBuild/External-OPENJPEG.cmake b/SuperBuild/External-OPENJPEG.cmake
index 5cfdb51..0be3aec 100644
--- a/SuperBuild/External-OPENJPEG.cmake
+++ b/SuperBuild/External-OPENJPEG.cmake
@@ -12,4 +12,4 @@ ExternalProject_Add(openjpeg
         -DCMAKE_INSTALL_PREFIX=${DEP_INSTALL_DIR}
 )
 
-set(OPENJPEG_DIR ${DEP_INSTALL_DIR}/lib/openjpeg-2.1)
+set(OpenJPEG_DIR ${DEP_INSTALL_DIR}/lib/openjpeg-2.1)
diff --git a/SuperBuild/SuperBuild.cmake b/SuperBuild/SuperBuild.cmake
index 4c37373..471a249 100644
--- a/SuperBuild/SuperBuild.cmake
+++ b/SuperBuild/SuperBuild.cmake
@@ -21,10 +21,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
 option(USE_STATIC_RUNTIME "Use static runtime" ON)
 
 option(USE_SYSTEM_ZLIB "Use the system zlib" OFF)
-option(USE_SYSTEM_TURBOJPEG "Use the system TurboJPEG" OFF)
-option(USE_JASPER "Compile with Jasper support" OFF)
+option(USE_TURBOJPEG "Use TurboJPEG to decode classic JPEG" OFF)
+option(USE_JASPER "Build with JPEG2000 support using Jasper" OFF)
 
-option(USE_OPENJPEG "Build with OpenJPEG support" OFF)
+option(USE_OPENJPEG "Build with JPEG2000 support using OpenJPEG" OFF)
 option(BATCH_VERSION "Build dcm2niibatch for multiple conversions" OFF)
 
 include(ExternalProject)
@@ -42,38 +42,48 @@ endif()
 if(USE_OPENJPEG)
     message("-- Build with OpenJPEG: ${USE_OPENJPEG}")
 
-    find_package(PkgConfig)
-    if(PKG_CONFIG_FOUND)
-        pkg_check_modules(OPENJPEG libopenjp2)
-    endif()
-
-    if(OPENJPEG_FOUND)
-        set(OPENJPEG_DIR ${OPENJPEG_LIBDIR}/openjepg-2.1)
-        message("--     Using the system OpenJPEG")
+    if(OpenJPEG_DIR OR OPENJPEG_DIR)
+        set(OpenJPEG_DIR "${OpenJPEG_DIR}${OPENJPEG_DIR}" CACHE PATH "Path to OpenJPEG configuration file"  FORCE)
+        message("--     Using OpenJPEG library from ${OpenJPEG_DIR}")
     else()
-        include(${CMAKE_SOURCE_DIR}/SuperBuild/External-OPENJPEG.cmake)
-        list(APPEND DEPENDENCIES openjpeg)
-        set(BUILD_OPENJPEG TRUE)
-        message("--     Will build OpenJPEG from github")
+        find_package(PkgConfig)
+        if(PKG_CONFIG_FOUND)
+            pkg_check_modules(OPENJPEG libopenjp2)
+        endif()
+
+        if(OPENJPEG_FOUND)
+            set(OpenJPEG_DIR ${OPENJPEG_LIBDIR}/openjepg-2.1 CACHE PATH "Path to OpenJPEG configuration file" FORCE)
+            message("--     Using OpenJPEG library from ${OpenJPEG_DIR}")
+        else()
+            include(${CMAKE_SOURCE_DIR}/SuperBuild/External-OPENJPEG.cmake)
+            list(APPEND DEPENDENCIES openjpeg)
+            set(BUILD_OPENJPEG TRUE)
+            message("--     Will build OpenJPEG library from github")
+        endif()
     endif()
 endif()
 
 if(BATCH_VERSION)
     message("-- Build dcm2niibatch: ${BATCH_VERSION}")
 
-    find_package(PkgConfig)
-    if(PKG_CONFIG_FOUND)
-        pkg_check_modules(YAML-CPP yaml-cpp)
-    endif()
-
-    if(YAML-CPP_FOUND)
-        set(YAML-CPP_DIR ${YAML-CPP_LIBDIR}/cmake/yaml-cpp)
-        message("--     Using the system yaml-cpp")
+    if(YAML-CPP_DIR)
+        set(YAML-CPP_DIR ${YAML-CPP_DIR} CACHE PATH "Path to yaml-cpp configuration file"  FORCE)
+        message("--     Using yaml-cpp library from ${YAML-CPP_DIR}")
     else()
-        include(${CMAKE_SOURCE_DIR}/SuperBuild/External-YAML-CPP.cmake)
-        list(APPEND DEPENDENCIES yaml-cpp)
-        set(BUILD_YAML-CPP TRUE)
-        message("--     Will build yaml-cpp from github")
+        find_package(PkgConfig)
+        if(PKG_CONFIG_FOUND)
+            pkg_check_modules(YAML-CPP yaml-cpp)
+        endif()
+
+        if(YAML-CPP_FOUND)
+            set(YAML-CPP_DIR ${YAML-CPP_LIBDIR}/cmake/yaml-cpp CACHE PATH "Path to yaml-cpp configuration file"  FORCE)
+            message("--     Using yaml-cpp library from ${YAML-CPP_DIR}")
+        else()
+            include(${CMAKE_SOURCE_DIR}/SuperBuild/External-YAML-CPP.cmake)
+            list(APPEND DEPENDENCIES yaml-cpp)
+            set(BUILD_YAML-CPP TRUE)
+            message("--     Will build yaml-cpp library from github")
+        endif()
     endif()
 endif()
 
@@ -89,11 +99,11 @@ ExternalProject_Add(console
         -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}
         -DUSE_STATIC_RUNTIME:BOOL=${USE_STATIC_RUNTIME}
         -DUSE_SYSTEM_ZLIB:BOOL=${USE_SYSTEM_ZLIB}
-        -DUSE_SYSTEM_TURBOJPEG:BOOL=${USE_SYSTEM_TURBOJPEG}
-        -DUSE_SYSTEM_JASPER:BOOL=${USE_SYSTEM_JASPER}
+        -DUSE_TURBOJPEG:BOOL=${USE_TURBOJPEG}
+        -DUSE_JASPER:BOOL=${USE_JASPER}
          # OpenJPEG
         -DUSE_OPENJPEG:BOOL=${USE_OPENJPEG}
-        -DOpenJPEG_DIR:PATH=${OPENJPEG_DIR}
+        -DOpenJPEG_DIR:PATH=${OpenJPEG_DIR}
         # yaml-cpp
         -DBATCH_VERSION:BOOL=${BATCH_VERSION}
         -DYAML-CPP_DIR:PATH=${YAML-CPP_DIR}
diff --git a/console/CMakeLists.txt b/console/CMakeLists.txt
index 54d9749..dcd78d3 100644
--- a/console/CMakeLists.txt
+++ b/console/CMakeLists.txt
@@ -11,15 +11,24 @@ else()
     ucm_set_runtime(DYNAMIC)
 endif()
 
+# Basic CMake build settings
+set(CMAKE_BUILD_TYPE "Release" CACHE STRING
+    "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
+set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS  "Debug;Release;RelWithDebInfo;MinSizeRel")
+
 set(PROGRAMS dcm2niix)
 
 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
     # using Clang
     add_definitions(-Wno-deprecated-register)
+    add_definitions(-fno-caret-diagnostics)
     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip")
 elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
     # using GCC
     add_definitions(-Wno-unused-result)
+    if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 4.7)
+        add_definitions(-fno-diagnostics-show-caret)
+    endif()
 elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
     # using Intel C++
 elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
@@ -56,30 +65,28 @@ if(USE_SYSTEM_ZLIB)
     target_link_libraries(dcm2niix ${ZLIB_LIBRARIES})
 endif()
 
-option(USE_SYSTEM_TURBOJPEG "Use the system TurboJPEG" OFF)
-if(USE_SYSTEM_TURBOJPEG)
+option(USE_TURBOJPEG "Use TurboJPEG to decode classic JPEG" OFF)
+if(USE_TURBOJPEG)
     find_package(PkgConfig REQUIRED)
-    pkg_check_modules(TurboJPEG REQUIRED libturbojpeg)
+    pkg_check_modules(TURBOJPEG REQUIRED libturbojpeg)
     add_definitions(-DmyTurboJPEG)
-    target_include_directories(dcm2niix PRIVATE ${TurboJPEG_INCLUDE_DIRS})
-    target_link_libraries(dcm2niix ${TurboJPEG_LIBRARIES})
+    target_include_directories(dcm2niix PRIVATE ${TURBOJPEG_INCLUDEDIR})
+    target_link_libraries(dcm2niix ${TURBOJPEG_LIBRARIES})
 endif()
 
-option(USE_JASPER "Compile with Jasper support" OFF)
+option(USE_JASPER "Build with JPEG2000 support using Jasper" OFF)
 if(USE_JASPER)
     find_package(Jasper REQUIRED)
     add_definitions(-DmyEnableJasper)
     target_include_directories(dcm2niix PRIVATE ${JASPER_INCLUDE_DIR})
     target_link_libraries(dcm2niix ${JASPER_LIBRARIES})
-else ()
-    add_definitions(-DmyDisableJASPER)
 endif()
 
-option(USE_OPENJPEG "Build with OpenJPEG support" OFF)
+option(USE_OPENJPEG "Build with JPEG2000 support using OpenJPEG" OFF)
 if(USE_OPENJPEG)
-    option(OpenJPEG_DIR "Path to OpenJPEG configuration file" "")
+    set(OpenJPEG_DIR "${OpenJPEG_DIR}${OPENJPEG_DIR}" CACHE PATH "Path to yaml-cpp configuration file" FORCE)
 
-    find_package(OpenJPEG)
+    find_package(OpenJPEG REQUIRED)
 
     if(WIN32)
         if(BUILD_SHARED_LIBS)
@@ -109,29 +116,31 @@ if(BATCH_VERSION)
         nii_ortho.cpp
         nii_dicom_batch.cpp)
 
-    option(YAML-CPP_DIR "Path to yaml-cpp configuration file" "")
+    set(YAML-CPP_DIR ${YAML-CPP_DIR} CACHE PATH "Path to yaml-cpp configuration file" FORCE)
 
-    find_package(YAML-CPP)
+    find_package(YAML-CPP REQUIRED)
     target_include_directories(dcm2niibatch PRIVATE ${YAML_CPP_INCLUDE_DIR})
     target_link_libraries(dcm2niibatch ${YAML_CPP_LIBRARIES})
 
     if(ZLIB_FOUND)
         add_definitions(-DmyDisableMiniZ)
+        target_include_directories(dcm2niibatch PRIVATE ${ZLIB_INCLUDE_DIRS})
         target_link_libraries(dcm2niibatch z)
     endif()
 
-    if(TurboJPEG_FOUND)
-        target_include_directories(dcm2niibatch PRIVATE ${TurboJPEG_INCLUDE_DIRS})
-        target_link_libraries(dcm2niibatch ${TurboJPEG_LIBRARIES})
+    if(TURBOJPEG_FOUND)
+        add_definitions(-DmyTurboJPEG)
+        target_include_directories(dcm2niibatch PRIVATE ${TURBOJPEG_INCLUDEDIR})
+        target_link_libraries(dcm2niibatch ${TURBOJPEG_LIBRARIES})
     endif()
 
     if(JASPER_FOUND)
+        add_definitions(-DmyEnableJasper)
+        target_include_directories(dcm2niibatch PRIVATE ${JASPER_INCLUDE_DIR})
         target_link_libraries(dcm2niibatch ${JASPER_LIBRARIES})
-    else()
-        add_definitions(-DmyDisableJASPER)
     endif()
 
-    if(USE_OPENJPEG)
+    if(OPENJPEG_FOUND)
         target_include_directories(dcm2niibatch PRIVATE ${OPENJPEG_INCLUDE_DIRS})
         target_link_libraries(dcm2niibatch ${OPENJPEG_LIBRARIES})
     else()
diff --git a/console/main_console.cpp b/console/main_console.cpp
index fa65b95..282c461 100644
--- a/console/main_console.cpp
+++ b/console/main_console.cpp
@@ -23,7 +23,7 @@
 
 //Alternatively, windows users with VisualStudio can compile this project
 // vcvarsall amd64
-// cl /EHsc main_console.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp -DmyDisableOpenJPEG -DmyDisableJasper /odcm2niix
+// cl /EHsc main_console.cpp nii_foreign.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp -DmyDisableOpenJPEG /o dcm2niix
 
 
 //#define mydebugtest //automatically process directory specified in main, ignore input arguments
@@ -82,10 +82,9 @@ void showHelp(const char * argv[], struct TDCMopts opts) {
     #else
      #define kQstr ""
     #endif
-    printf("  -f : filename (%%a=antenna  (coil) number, %%c=comments, %%d=description, %%e echo number, %%f=folder name, %%i ID of patient, %%j seriesInstanceUID, %%k studyInstanceUID, %%m=manufacturer, %%n=name of patient, %%p=protocol,%s %%s=series number, %%t=time, %%u=acquisition number, %%x study ID; %%z sequence name; default '%s')\n", kQstr, opts.filename);
+    printf("  -f : filename (%%a=antenna  (coil) number, %%c=comments, %%d=description, %%e echo number, %%f=folder name, %%i ID of patient, %%j seriesInstanceUID, %%k studyInstanceUID, %%m=manufacturer, %%n=name of patient, %%p=protocol,%s %%s=series number, %%t=time, %%u=acquisition number, %%v=vendor, %%x=study ID; %%z sequence name; default '%s')\n", kQstr, opts.filename);
     printf("  -h : show help\n");
     printf("  -i : ignore derived, localizer and 2D images (y/n, default n)\n");
-    printf("  -t : text notes includes private patient details (y/n, default n)\n");
     printf("  -m : merge 2D slices from same series regardless of study time, echo, coil, orientation, etc. (y/n, default n)\n");
     printf("  -o : output directory (omit to save to input folder)\n");
     printf("  -p : Philips precise float (not display) scaling (y/n, default y)\n");
diff --git a/console/makefile b/console/makefile
index f311167..3fe5ea4 100755
--- a/console/makefile
+++ b/console/makefile
@@ -6,4 +6,4 @@ ifneq ($(OS),Windows_NT)
 	endif
 endif
 all:
-	g++ $(CFLAGS) -O3 -I. main_console.cpp nii_foreign.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp  -o dcm2niix -DmyDisableOpenJPEG -DmyDisableJasper
+	g++ $(CFLAGS) -O3 -I. main_console.cpp nii_foreign.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp  -o dcm2niix -DmyDisableOpenJPEG
diff --git a/console/nii_dicom.cpp b/console/nii_dicom.cpp
index 624bf4d..2a017e4 100644
--- a/console/nii_dicom.cpp
+++ b/console/nii_dicom.cpp
@@ -169,15 +169,26 @@ static OPJ_SIZE_T opj_skip_from_buffer(OPJ_SIZE_T p_nb_bytes, BufInfo * p_file)
     return (OPJ_SIZE_T)-1;
 } //opj_skip_from_buffer()
 
+//fix for https://github.com/neurolabusc/dcm_qa/issues/5
 static OPJ_BOOL opj_seek_from_buffer(OPJ_SIZE_T p_nb_bytes, BufInfo * p_file) {
-    if(p_file->cur + p_nb_bytes < p_file->buf + p_file->len ) {
-        p_file->cur += p_nb_bytes;
+    //printf("opj_seek_from_buffer %d + %d -> %d + %d\n", p_file->cur , p_nb_bytes, p_file->buf, p_file->len);
+    if ((p_file->buf + p_nb_bytes < p_file->buf + p_file->len ) && (p_nb_bytes >= 0)){
+        p_file->cur = p_file->buf + p_nb_bytes;
         return OPJ_TRUE;
     }
     p_file->cur = p_file->buf + p_file->len;
     return OPJ_FALSE;
 } //opj_seek_from_buffer()
 
+/*static OPJ_BOOL opj_seek_from_buffer(OPJ_SIZE_T p_nb_bytes, BufInfo * p_file) {
+    if((p_file->cur + p_nb_bytes) < (p_file->buf + p_file->len) ) {
+        p_file->cur += p_nb_bytes;
+        return OPJ_TRUE;
+    }
+    p_file->cur = p_file->buf + p_file->len;
+    return OPJ_FALSE;
+} //opj_seek_from_buffer()*/
+
 opj_stream_t* opj_stream_create_buffer_stream(BufInfo* p_file, OPJ_UINT32 p_size, OPJ_BOOL p_is_read_stream) {
     opj_stream_t* l_stream;
     if(! p_file) return NULL;
@@ -511,7 +522,6 @@ mat44 set_nii_header_x(struct TDICOMdata d, struct TDICOMdata d2, struct nifti_1
         double nRowCol = ceil(sqrt((double) d.CSA.mosaicSlices));
         double lFactorX = (d.xyzDim[1] -(d.xyzDim[1]/nRowCol)   )/2.0;
         double lFactorY = (d.xyzDim[2] -(d.xyzDim[2]/nRowCol)   )/2.0;
-        //printf("%g %g\n", lFactorX, lFactorY);
         Q44.m[0][3] =(float)((Q44.m[0][0]*lFactorX)+(Q44.m[0][1]*lFactorY)+Q44.m[0][3]);
 		Q44.m[1][3] = (float)((Q44.m[1][0] * lFactorX) + (Q44.m[1][1] * lFactorY) + Q44.m[1][3]);
 		Q44.m[2][3] = (float)((Q44.m[2][0] * lFactorX) + (Q44.m[2][1] * lFactorY) + Q44.m[2][3]);
@@ -2249,7 +2259,7 @@ unsigned char * nii_loadImgJPEGC3(char* imgname, struct nifti_1_header hdr, stru
     // https://github.com/chafey/cornerstoneWADOImageLoader
     //I have never seen these segmented images in the wild, so we will simply warn the user if we encounter such a file
     //int Sz = JPEG_SOF_0XC3_sz (imgname, (dcm.imageStart - 4), dcm.isLittleEndian);
-    //printf("Sz %d %d\n", Sz, dcm.imageBytes );
+    //printMessage("Sz %d %d\n", Sz, dcm.imageBytes );
     //This behavior is legal but appears extremely rare
     //ftp://medical.nema.org/medical/dicom/final/cp900_ft.pdf
     if (65536 == dcm.imageBytes)
@@ -2644,7 +2654,7 @@ struct TDICOMdata readDICOMv(char * fname, int isVerbose, int compressFlag, stru
 #define  kImageStartFloat 0x7FE0+(0x0008 << 16 )
 #define  kImageStartDouble 0x7FE0+(0x0009 << 16 )
 #define kNest 0xFFFE +(0xE000 << 16 ) //Item follows SQ
-#define  kUnnest 0xFFFE +(0xE00D << 16 ) //ItemDelimitationItem [length defined] http://www.dabsoft.ch/dicom/5/7.5/
+#define  kUnnest  0xFFFE +(0xE00D << 16 ) //ItemDelimitationItem [length defined] http://www.dabsoft.ch/dicom/5/7.5/
 #define  kUnnest2 0xFFFE +(0xE0DD << 16 )//SequenceDelimitationItem [length undefined]
     int nest = 0;
     double zSpacing = -1.0l; //includes slice thickness plus gap
@@ -2664,6 +2674,9 @@ struct TDICOMdata readDICOMv(char * fname, int isVerbose, int compressFlag, stru
     //float intenScalePhilips = 0.0;
     char acquisitionDateTimeTxt[kDICOMStr] = "";
     bool isEncapsulatedData = false;
+    int encapsulatedDataFragments = 0;
+    int encapsulatedDataFragmentStart = 0; //position of first FFFE,E000 for compressed images
+    int encapsulatedDataImageStart = 0; //position of 7FE0,0010 for compressed images (where actual image start should be start of first fragment)
     bool isOrient = false;
     bool isIconImageSequence = false;
     bool isSwitchToImplicitVR = false;
@@ -2765,13 +2778,18 @@ struct TDICOMdata readDICOMv(char * fname, int isVerbose, int compressFlag, stru
             //printMessage("SQstart %d\n", sqDepth);
         }
         if ((groupElement == kNest) || ((vr[0] == 'S') && (vr[1] == 'Q'))) nest++;
-        if (groupElement == kUnnest) nest--;
+        //if ((groupElement == kUnnest) || (groupElement == kUnnest2)) { // <- ?
+        if (groupElement == kUnnest) {
+        	nest--;
+        }
         //next: look for required tags
         if ((groupElement == kNest)  && (isEncapsulatedData)) {
             d.imageBytes = dcmInt(4,&buffer[lPos-4],d.isLittleEndian);
             //printMessage("compressed data %d-> %ld\n",d.imageBytes, lPos);
             if (d.imageBytes > 128) {
-                d.imageStart = (int)lPos + (int)lFileOffset;
+            	encapsulatedDataFragments++;
+   				if (encapsulatedDataFragmentStart == 0)
+                	encapsulatedDataFragmentStart = (int)lPos + (int)lFileOffset;
             }
         }
         if ((isIconImageSequence) && ((groupElement & 0x0028) == 0x0028 )) groupElement = kUnused; //ignore icon dimensions
@@ -3121,7 +3139,7 @@ struct TDICOMdata readDICOMv(char * fname, int isVerbose, int compressFlag, stru
                 break;
             /*case kStackSliceNumber: { //https://github.com/Kevin-Mattheus-Moerman/GIBBON/blob/master/dicomDict/PMS-R32-dict.txt
             	int stackSliceNumber = dcmInt(lLength,&buffer[lPos],d.isLittleEndian);
-            	printf("%d\n",stackSliceNumber);
+            	printMessage("StackSliceNumber %d\n",stackSliceNumber);
             	break;
 			}*/
             case 	kNumberOfDynamicScans:
@@ -3324,6 +3342,8 @@ struct TDICOMdata readDICOMv(char * fname, int isVerbose, int compressFlag, stru
                 if ((d.compressionScheme != kCompressNone) && (!isIconImageSequence)) {
                     lLength = 0;
                     isEncapsulatedData = true;
+                    encapsulatedDataImageStart = (int)lPos + (int)lFileOffset;
+                    //printWarning("Encapsulated\n");
                 }
 				isIconImageSequence = false;
                 break;
@@ -3365,6 +3385,16 @@ struct TDICOMdata readDICOMv(char * fname, int isVerbose, int compressFlag, stru
         //printMessage("%d\n",d.imageStart);
     } //while d.imageStart == 0
     free (buffer);
+    if (encapsulatedDataFragmentStart > 0) {
+        if (encapsulatedDataFragments > 1)
+        	printError(" Compressed image stored as %d fragments: decompress with Osirix, dcmdjpeg or dcmjp2k\n", encapsulatedDataFragments);
+    	else
+    		d.imageStart = encapsulatedDataFragmentStart;
+    } else if ((isEncapsulatedData) && (d.imageStart < 128)) {
+    	printWarning(" DICOM violation (contact vendor): compressed image without image fragments, assuming image offset defined by 0x7FE0,x0010\n");
+    	d.imageStart = encapsulatedDataImageStart;
+    }
+
     //Recent Philips images include DateTime (0008,002A) but not separate date and time (0008,0022 and 0008,0032)
     #define kYYYYMMDDlen 8 //how many characters to encode year,month,day in "YYYYDDMM" format
     if ((strlen(acquisitionDateTimeTxt) > (kYYYYMMDDlen+5)) && (!isFloatDiff(d.acquisitionTime, 0.0f)) && (!isFloatDiff(d.acquisitionDate, 0.0f)) ) {
diff --git a/console/nii_dicom_batch.cpp b/console/nii_dicom_batch.cpp
index 1c1ea16..5453bdc 100755
--- a/console/nii_dicom_batch.cpp
+++ b/console/nii_dicom_batch.cpp
@@ -207,7 +207,7 @@ void geCorrectBvecs(struct TDICOMdata *d, int sliceDir, struct TDTI *vx){
 		printMessage("Impossible GE slice orientation!");
 	if (sliceDir < 0)
     	flp.v[2] = 1 - flp.v[2];
-    printMessage("Reorienting %s : %d GE DTI vectors: please validate. isCol=%d sliceDir=%d flp=%d %d %d\n", d->protocolName, d->CSA.numDti, col, sliceDir, flp.v[0], flp.v[1],flp.v[2]);
+    printMessage("Saving %d DTI gradients. GE Reorienting %s : please validate. isCol=%d sliceDir=%d flp=%d %d %d\n", d->CSA.numDti, d->protocolName, col, sliceDir, flp.v[0], flp.v[1],flp.v[2]);
 	if (!col)
 		printMessage(" reorienting for ROW phase-encoding untested.\n");
     for (int i = 0; i < d->CSA.numDti; i++) {
@@ -286,11 +286,11 @@ void siemensPhilipsCorrectBvecs(struct TDICOMdata *d, int sliceDir, struct TDTI
             if (vx[i].V[v] == -0.0f) vx[i].V[v] = 0.0f; //remove sign from values that are virtually zero
     } //for each direction
     if (abs(sliceDir) == kSliceOrientMosaicNegativeDeterminant) {
-       printWarning("Please validate DTI vectors (matrix had a negative determinant, perhaps Siemens sagittal).\n");
+       printWarning("Saving %d DTI gradients. Validate vectors (matrix had a negative determinant).\n", d->CSA.numDti); //perhaps Siemens sagittal
     } else if ( d->sliceOrient == kSliceOrientTra) {
-        printMessage("Saving %d DTI gradients. Please validate if you are conducting DTI analyses.\n", d->CSA.numDti);
+        printMessage("Saving %d DTI gradients. Validate vectors.\n", d->CSA.numDti);
     } else {
-        printWarning("DTI gradient directions only tested for axial (transverse) acquisitions. Please validate bvec files.\n");
+        printWarning("Saving %d DTI gradients. Validate vectors (images are not axial slices).\n", d->CSA.numDti);
     }
 }// siemensPhilipsCorrectBvecs()
 
@@ -1080,6 +1080,18 @@ int nii_createFilename(struct TDICOMdata dcm, char * niiFilename, struct TDCMopt
     			printWarning("Ignoring '%%u' in output filename (recompile to segment by acquisition)\n");
     			#endif
 			}
+			if (f == 'V') {
+				if (dcm.manufacturer == kMANUFACTURER_GE)
+					strcat (outname,"GE");
+				else if (dcm.manufacturer == kMANUFACTURER_PHILIPS)
+					strcat (outname,"Philips");
+				else if (dcm.manufacturer == kMANUFACTURER_SIEMENS)
+					strcat (outname,"Siemens");
+				else if (dcm.manufacturer == kMANUFACTURER_TOSHIBA)
+					strcat (outname,"Toshiba");
+				else
+					strcat (outname,"NA");
+			}
 			if (f == 'X')
 				strcat (outname,dcm.studyID);
             if (f == 'Z')

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/dcm2niix.git



More information about the debian-med-commit mailing list