[med-svn] [orthanc-wsi] 02/04: New upstream version 0.4+dfsg

Sebastien Jodogne jodogne-guest at moszumanska.debian.org
Wed Mar 1 12:20:59 UTC 2017


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

jodogne-guest pushed a commit to branch master
in repository orthanc-wsi.

commit 963c233fc2d4fbe88fe425070d40f61c29f2fac4
Author: jodogne-guest <s.jodogne at gmail.com>
Date:   Wed Mar 1 13:00:36 2017 +0100

    New upstream version 0.4+dfsg
---
 .hg_archival.txt                                   |   7 +-
 AUTHORS                                            |  11 +-
 Applications/ApplicationToolbox.cpp                |  39 +++++
 Applications/ApplicationToolbox.h                  |   3 +
 Applications/CMakeLists.txt                        |   7 +-
 Applications/DicomToTiff.cpp                       |   2 +
 Applications/Dicomizer.cpp                         | 123 +++++++------
 Framework/Algorithms/PyramidReader.cpp             |   1 +
 Framework/Algorithms/PyramidReader.h               |   1 +
 Framework/Algorithms/ReconstructPyramidCommand.cpp |   1 +
 Framework/Algorithms/ReconstructPyramidCommand.h   |   1 +
 Framework/Algorithms/TranscodeTileCommand.cpp      |   1 +
 Framework/Algorithms/TranscodeTileCommand.h        |   1 +
 Framework/DicomToolbox.cpp                         |  19 +++
 Framework/DicomToolbox.h                           |   5 +
 Framework/DicomizerParameters.cpp                  |  33 ++--
 Framework/DicomizerParameters.h                    |   1 +
 Framework/Enumerations.cpp                         |   1 +
 Framework/Enumerations.h                           |   1 +
 Framework/ImageToolbox.cpp                         |  22 ++-
 Framework/ImageToolbox.h                           |   1 +
 Framework/ImagedVolumeParameters.cpp               |   1 +
 Framework/ImagedVolumeParameters.h                 |   1 +
 Framework/Inputs/DecodedTiledPyramid.cpp           |   1 +
 Framework/Inputs/DecodedTiledPyramid.h             |   1 +
 Framework/Inputs/DicomPyramid.cpp                  |   1 +
 Framework/Inputs/DicomPyramid.h                    |   1 +
 Framework/Inputs/DicomPyramidInstance.cpp          |  56 ++++--
 Framework/Inputs/DicomPyramidInstance.h            |   1 +
 Framework/Inputs/DicomPyramidLevel.cpp             |   1 +
 Framework/Inputs/DicomPyramidLevel.h               |   1 +
 Framework/Inputs/HierarchicalTiff.cpp              |   1 +
 Framework/Inputs/HierarchicalTiff.h                |   1 +
 Framework/Inputs/ITiledPyramid.h                   |   1 +
 Framework/Inputs/OpenSlideLibrary.cpp              |   3 +-
 Framework/Inputs/OpenSlideLibrary.h                |   1 +
 Framework/Inputs/OpenSlidePyramid.cpp              |   1 +
 Framework/Inputs/OpenSlidePyramid.h                |   1 +
 Framework/Inputs/PyramidWithRawTiles.cpp           |   1 +
 Framework/Inputs/PyramidWithRawTiles.h             |   1 +
 Framework/Inputs/SingleLevelDecodedPyramid.cpp     |   1 +
 Framework/Inputs/SingleLevelDecodedPyramid.h       |   1 +
 Framework/Inputs/TiledJpegImage.h                  |   1 +
 Framework/Inputs/TiledPngImage.h                   |   1 +
 Framework/Inputs/TiledPyramidStatistics.cpp        |   1 +
 Framework/Inputs/TiledPyramidStatistics.h          |   1 +
 Framework/Jpeg2000Reader.cpp                       |   1 +
 Framework/Jpeg2000Reader.h                         |   1 +
 Framework/Jpeg2000Writer.cpp                       |   1 +
 Framework/Jpeg2000Writer.h                         |   1 +
 Framework/Outputs/DicomPyramidWriter.cpp           |   8 +-
 Framework/Outputs/DicomPyramidWriter.h             |   1 +
 Framework/Outputs/HierarchicalTiffWriter.cpp       |   1 +
 Framework/Outputs/HierarchicalTiffWriter.h         |   1 +
 Framework/Outputs/IPyramidWriter.h                 |   1 +
 Framework/Outputs/InMemoryTiledImage.cpp           |   1 +
 Framework/Outputs/InMemoryTiledImage.h             |   1 +
 Framework/Outputs/MultiframeDicomWriter.cpp        |   1 +
 Framework/Outputs/MultiframeDicomWriter.h          |   1 +
 Framework/Outputs/PyramidWriterBase.cpp            |   1 +
 Framework/Outputs/PyramidWriterBase.h              |   1 +
 Framework/Outputs/TruncatedPyramidWriter.cpp       |   1 +
 Framework/Outputs/TruncatedPyramidWriter.h         |   1 +
 Framework/PrecompiledHeadersWSI.cpp                |   1 +
 Framework/PrecompiledHeadersWSI.h                  |   1 +
 Framework/Targets/FolderTarget.cpp                 |   1 +
 Framework/Targets/FolderTarget.h                   |   3 +-
 Framework/Targets/IFileTarget.h                    |   1 +
 Framework/Targets/OrthancTarget.cpp                |   1 +
 Framework/Targets/OrthancTarget.h                  |   5 +-
 NEWS                                               |  20 ++-
 Resources/CMake/LibTiffConfiguration.cmake         |   2 +-
 Resources/CMake/OpenJpegConfiguration.cmake        |   2 +-
 Resources/CMake/Version.cmake                      |   2 +-
 .../Orthanc/Core/Cache/LeastRecentlyUsedIndex.h    |   1 +
 Resources/Orthanc/Core/ChunkedBuffer.cpp           |   1 +
 Resources/Orthanc/Core/ChunkedBuffer.h             |   1 +
 Resources/Orthanc/Core/DicomFormat/DicomArray.cpp  |   1 +
 Resources/Orthanc/Core/DicomFormat/DicomArray.h    |   3 +-
 Resources/Orthanc/Core/DicomFormat/DicomElement.h  |   1 +
 Resources/Orthanc/Core/DicomFormat/DicomMap.cpp    |   1 +
 Resources/Orthanc/Core/DicomFormat/DicomMap.h      |   3 +-
 Resources/Orthanc/Core/DicomFormat/DicomTag.cpp    |   1 +
 Resources/Orthanc/Core/DicomFormat/DicomTag.h      |   3 +
 Resources/Orthanc/Core/DicomFormat/DicomValue.cpp  |   1 +
 Resources/Orthanc/Core/DicomFormat/DicomValue.h    |   1 +
 Resources/Orthanc/Core/Endianness.h                |   1 +
 Resources/Orthanc/Core/EnumerationDictionary.h     |   1 +
 Resources/Orthanc/Core/Enumerations.cpp            |  12 +-
 Resources/Orthanc/Core/Enumerations.h              |   1 +
 Resources/Orthanc/Core/HttpClient.cpp              |   5 +-
 Resources/Orthanc/Core/HttpClient.h                |   1 +
 Resources/Orthanc/Core/ICommand.h                  |   1 +
 Resources/Orthanc/Core/IDynamicObject.h            |   1 +
 Resources/Orthanc/Core/Images/IImageWriter.cpp     |   1 +
 Resources/Orthanc/Core/Images/IImageWriter.h       |   1 +
 Resources/Orthanc/Core/Images/Image.cpp            |   1 +
 Resources/Orthanc/Core/Images/Image.h              |   1 +
 Resources/Orthanc/Core/Images/ImageAccessor.cpp    |   1 +
 Resources/Orthanc/Core/Images/ImageAccessor.h      |   1 +
 Resources/Orthanc/Core/Images/ImageBuffer.cpp      |   1 +
 Resources/Orthanc/Core/Images/ImageBuffer.h        |   1 +
 Resources/Orthanc/Core/Images/ImageProcessing.cpp  |  21 +++
 Resources/Orthanc/Core/Images/ImageProcessing.h    |   1 +
 Resources/Orthanc/Core/Images/JpegErrorManager.cpp |   1 +
 Resources/Orthanc/Core/Images/JpegErrorManager.h   |   1 +
 Resources/Orthanc/Core/Images/JpegReader.cpp       |   1 +
 Resources/Orthanc/Core/Images/JpegReader.h         |   1 +
 Resources/Orthanc/Core/Images/JpegWriter.cpp       |   3 +-
 Resources/Orthanc/Core/Images/JpegWriter.h         |   1 +
 Resources/Orthanc/Core/Images/PngReader.cpp        |   1 +
 Resources/Orthanc/Core/Images/PngReader.h          |   1 +
 Resources/Orthanc/Core/Images/PngWriter.cpp        |   1 +
 Resources/Orthanc/Core/Images/PngWriter.h          |   1 +
 Resources/Orthanc/Core/Logging.cpp                 |  70 +++++++-
 Resources/Orthanc/Core/Logging.h                   |  53 +++++-
 Resources/Orthanc/Core/MultiThreading/BagOfTasks.h |   1 +
 .../Core/MultiThreading/BagOfTasksProcessor.cpp    |   1 +
 .../Core/MultiThreading/BagOfTasksProcessor.h      |  11 +-
 .../Orthanc/Core/MultiThreading/Semaphore.cpp      |   1 +
 Resources/Orthanc/Core/MultiThreading/Semaphore.h  |   3 +-
 .../Core/MultiThreading/SharedMessageQueue.cpp     |   1 +
 .../Core/MultiThreading/SharedMessageQueue.h       |   1 +
 Resources/Orthanc/Core/OrthancException.h          |   3 +-
 Resources/Orthanc/Core/PrecompiledHeaders.cpp      |   1 +
 Resources/Orthanc/Core/PrecompiledHeaders.h        |   1 +
 Resources/Orthanc/Core/SystemToolbox.cpp           |  15 +-
 Resources/Orthanc/Core/SystemToolbox.h             |   3 +
 Resources/Orthanc/Core/TemporaryFile.cpp           |   1 +
 Resources/Orthanc/Core/TemporaryFile.h             |   1 +
 Resources/Orthanc/Core/Toolbox.cpp                 |  13 +-
 Resources/Orthanc/Core/Toolbox.h                   |   3 +-
 Resources/Orthanc/Core/WebServiceParameters.cpp    |   2 +-
 Resources/Orthanc/Core/WebServiceParameters.h      |   1 +
 .../Orthanc/OrthancServer/FromDcmtkBridge.cpp      | 122 ++++++++++++-
 Resources/Orthanc/OrthancServer/FromDcmtkBridge.h  |  25 +++
 .../OrthancServer/PrecompiledHeadersServer.h       |   1 +
 .../Orthanc/OrthancServer/ServerEnumerations.cpp   |   3 +
 .../Orthanc/OrthancServer/ServerEnumerations.h     |   5 +-
 Resources/Orthanc/OrthancServer/ToDcmtkBridge.cpp  |  19 +--
 Resources/Orthanc/OrthancServer/ToDcmtkBridge.h    |   3 +-
 Resources/Orthanc/Plugins/Engine/SharedLibrary.cpp |   1 +
 Resources/Orthanc/Plugins/Engine/SharedLibrary.h   |   3 +-
 .../Plugins/Samples/Common/DicomDatasetReader.cpp  |  83 +++++++--
 .../Plugins/Samples/Common/DicomDatasetReader.h    |  25 ++-
 .../Orthanc/Plugins/Samples/Common/DicomPath.cpp   |   5 +-
 .../Orthanc/Plugins/Samples/Common/DicomPath.h     |   1 +
 .../Orthanc/Plugins/Samples/Common/DicomTag.cpp    |   5 +-
 .../Orthanc/Plugins/Samples/Common/DicomTag.h      |  15 +-
 .../Plugins/Samples/Common/FullOrthancDataset.cpp  |  16 +-
 .../Plugins/Samples/Common/FullOrthancDataset.h    |   1 +
 .../Orthanc/Plugins/Samples/Common/IDicomDataset.h |   1 +
 .../Plugins/Samples/Common/IOrthancConnection.cpp  |   5 +-
 .../Plugins/Samples/Common/IOrthancConnection.h    |   1 +
 .../Samples/Common/OrthancHttpConnection.cpp       |   1 +
 .../Plugins/Samples/Common/OrthancHttpConnection.h |   1 +
 .../Samples/Common/OrthancPluginConnection.cpp     |   9 +-
 .../Samples/Common/OrthancPluginConnection.h       |   1 +
 .../Samples/Common/OrthancPluginCppWrapper.cpp     | 190 +++++++++++++++------
 .../Samples/Common/OrthancPluginCppWrapper.h       | 119 +++++++------
 .../Samples/Common/OrthancPluginException.h        | 101 +++++++++++
 .../Samples/Common/SimplifiedOrthancDataset.cpp    |  15 +-
 .../Samples/Common/SimplifiedOrthancDataset.h      |   1 +
 .../Resources/CMake/BoostConfiguration.cmake       |  16 +-
 .../Resources/CMake/DcmtkConfiguration.cmake       |  15 +-
 .../Resources/CMake/JsonCppConfiguration.cmake     |   2 +-
 .../Resources/CMake/LibCurlConfiguration.cmake     |   2 +-
 .../Resources/CMake/LibJpegConfiguration.cmake     |   2 +-
 .../Resources/CMake/LibPngConfiguration.cmake      |   2 +-
 .../Resources/CMake/OpenSslConfiguration.cmake     |   2 +-
 .../Resources/CMake/ZlibConfiguration.cmake        |   2 +-
 Resources/Orthanc/Resources/EmbedResources.py      |   1 +
 .../dcmtk-3.6.0-dulparse-vulnerability.patch       |  29 ++++
 Resources/Orthanc/Resources/WindowsResources.py    |   1 +
 Resources/OrthancWSIClearCache.py                  |   1 +
 Resources/SyncOrthancFolder.py                     |   2 +
 TODO                                               |   3 +-
 ViewerPlugin/CMakeLists.txt                        |   5 +-
 ViewerPlugin/DicomPyramidCache.cpp                 |   1 +
 ViewerPlugin/DicomPyramidCache.h                   |   1 +
 ViewerPlugin/Plugin.cpp                            |   1 +
 ViewerPlugin/viewer.js                             |   1 +
 182 files changed, 1229 insertions(+), 333 deletions(-)

diff --git a/.hg_archival.txt b/.hg_archival.txt
index 2add95f..29d67ff 100644
--- a/.hg_archival.txt
+++ b/.hg_archival.txt
@@ -1,5 +1,6 @@
 repo: 4a7a53257c7df5a97aea39377b8c9a6e815c9763
-node: cafc4728a8577cd9f07e4bbff7a638ba577ceb10
-branch: OrthancWSI-0.2
+node: 84b3128ba48f6f333b4b949794ceac16c3afc820
+branch: OrthancWSI-0.4
 latesttag: null
-latesttagdistance: 76
+latesttagdistance: 102
+changessincelatesttag: 103
diff --git a/AUTHORS b/AUTHORS
index 12a3d37..ad24171 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -6,8 +6,15 @@ Authors
 -------
 
 * Sebastien Jodogne <s.jodogne at gmail.com>
-  Department of Medical Physics
+
+  Overall design and lead developer.
+
+* Department of Medical Physics
   University Hospital of Liege
+  4000 Liege
   Belgium
 
-  Overall design and lead developer.
+* Osimis <info at osimis.io>
+  Rue des Chasseurs Ardennais 3
+  4031 Liege 
+  Belgium
diff --git a/Applications/ApplicationToolbox.cpp b/Applications/ApplicationToolbox.cpp
index 49ebabb..5c9d66d 100644
--- a/Applications/ApplicationToolbox.cpp
+++ b/Applications/ApplicationToolbox.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
@@ -24,10 +25,24 @@
 #include "../Resources/Orthanc/Core/HttpClient.h"
 #include "../Resources/Orthanc/Core/Logging.h"
 #include "../Resources/Orthanc/Core/MultiThreading/BagOfTasksProcessor.h"
+#include "../Resources/Orthanc/Core/SystemToolbox.h"
 #include "../Resources/Orthanc/OrthancServer/FromDcmtkBridge.h"
 
+#include <boost/filesystem.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/regex.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <cassert>
+
+
+static bool DisplayPerformanceWarning()
+{
+  (void) DisplayPerformanceWarning;   // Disable warning about unused function
+  LOG(WARNING) << "Performance warning in whole-slide imaging: "
+               << "Non-release build, runtime debug assertions are turned on";
+  return true;
+}
+
 
 namespace OrthancWSI
 {
@@ -39,6 +54,7 @@ namespace OrthancWSI
       Orthanc::HttpClient::InitializeOpenSsl();
       Orthanc::HttpClient::GlobalInitialize();
       Orthanc::FromDcmtkBridge::InitializeDictionary(false /* don't load private dictionary */);
+      assert(DisplayPerformanceWarning());
     }
 
 
@@ -184,11 +200,34 @@ namespace OrthancWSI
         << path << " " << ORTHANC_WSI_VERSION << std::endl
         << "Copyright (C) 2012-2016 Sebastien Jodogne, "
         << "Medical Physics Department, University Hospital of Liege (Belgium)" << std::endl
+        << "Copyright (C) 2017 Osimis S.A. (Belgium)" << std::endl
         << "Licensing AGPL: GNU AGPL version 3 or later <http://gnu.org/licenses/agpl.html>." << std::endl
         << "This is free software: you are free to change and redistribute it." << std::endl
         << "There is NO WARRANTY, to the extent permitted by law." << std::endl
         << std::endl
         << "Written by Sebastien Jodogne <s.jodogne at gmail.com>" << std::endl;
     }
+
+
+    void ShowVersionInLog(const char* path)
+    {
+      std::string version(ORTHANC_WSI_VERSION);
+
+      if (version == "mainline")
+      {
+        try
+        {
+          boost::filesystem::path exe(Orthanc::SystemToolbox::GetPathToExecutable());
+          std::time_t creation = boost::filesystem::last_write_time(exe);
+          boost::posix_time::ptime converted(boost::posix_time::from_time_t(creation));
+          version += " (" + boost::posix_time::to_iso_string(converted) + ")";
+        }
+        catch (...)
+        {
+        }
+      }
+
+      LOG(WARNING) << "Orthanc WSI version: " << version;
+    }
   }
 }
diff --git a/Applications/ApplicationToolbox.h b/Applications/ApplicationToolbox.h
index 1bfe5ca..ca38528 100644
--- a/Applications/ApplicationToolbox.h
+++ b/Applications/ApplicationToolbox.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
@@ -42,5 +43,7 @@ namespace OrthancWSI
                     const std::string& color);
 
     void PrintVersion(const char* path);
+
+    void ShowVersionInLog(const char* path);
   }
 }
diff --git a/Applications/CMakeLists.txt b/Applications/CMakeLists.txt
index 572a651..285ead4 100644
--- a/Applications/CMakeLists.txt
+++ b/Applications/CMakeLists.txt
@@ -78,14 +78,17 @@ include(${ORTHANC_WSI_DIR}/Resources/CMake/OpenJpegConfiguration.cmake)
 include(${ORTHANC_WSI_DIR}/Resources/CMake/LibTiffConfiguration.cmake)
 
 add_definitions(
+  -DORTHANC_BUILD_UNIT_TESTS=0  # For FromDcmtkBridge
   -DORTHANC_ENABLE_BASE64=1
   -DORTHANC_ENABLE_CURL=1
   -DORTHANC_ENABLE_DCMTK=1
+  -DORTHANC_ENABLE_JPEG=0       # Disable DCMTK's support for JPEG
   -DORTHANC_ENABLE_LOGGING=1
+  -DORTHANC_ENABLE_LOGGING_PLUGIN=0
+  -DORTHANC_ENABLE_LUA=0        # For FromDcmtkBridge
   -DORTHANC_ENABLE_MD5=0
-  -DORTHANC_ENABLE_JPEG=0     # Disable DCMTK's support for JPEG
   -DORTHANC_ENABLE_PKCS11=0
-  -DORTHANC_ENABLE_PLUGINS=1  # To enable class Orthanc::SharedLibrary
+  -DORTHANC_ENABLE_PLUGINS=1    # To enable class Orthanc::SharedLibrary
   -DORTHANC_ENABLE_PUGIXML=0
   -DORTHANC_SANDBOXED=0
   -DHAS_ORTHANC_EXCEPTION=1
diff --git a/Applications/DicomToTiff.cpp b/Applications/DicomToTiff.cpp
index cb43de1..1d33c0d 100644
--- a/Applications/DicomToTiff.cpp
+++ b/Applications/DicomToTiff.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
@@ -274,6 +275,7 @@ static void Run(OrthancWSI::ITiledPyramid& source,
 int main(int argc, char* argv[])
 {
   OrthancWSI::ApplicationToolbox::GlobalInitialize();
+  OrthancWSI::ApplicationToolbox::ShowVersionInLog(argv[0]);
 
   int exitStatus = 0;
   boost::program_options::variables_map options;
diff --git a/Applications/Dicomizer.cpp b/Applications/Dicomizer.cpp
index d2de5a6..3073f07 100644
--- a/Applications/Dicomizer.cpp
+++ b/Applications/Dicomizer.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
@@ -260,78 +261,93 @@ static void SetupDimension(DcmDataset& dataset,
                            const OrthancWSI::ITiledPyramid& source,
                            const OrthancWSI::ImagedVolumeParameters& volume)
 {
-  std::string uid;
+  // Extract the identifier of the Dimension Organization, if provided
+  std::string organization;
   DcmItem* previous = OrthancWSI::DicomToolbox::ExtractSingleSequenceItem(dataset, DCM_DimensionOrganizationSequence);
 
-  if (previous != NULL)
+  if (previous != NULL &&
+      previous->tagExists(DCM_DimensionOrganizationUID))
   {
-    const char* tmp = NULL;
-    if (previous->findAndGetString(DCM_DimensionOrganizationUID, tmp).good() &&
-        tmp != NULL)
+    organization = OrthancWSI::DicomToolbox::GetStringTag(*previous, DCM_DimensionOrganizationUID);
+  }
+  else
+  {
+    // No Dimension Organization provided: Generate an unique identifier
+    organization = Orthanc::FromDcmtkBridge::GenerateUniqueIdentifier(Orthanc::ResourceType_Instance);
+  }
+
+
+  {
+    // Construct tag "Dimension Organization Sequence" (0020,9221)
+    std::auto_ptr<DcmItem> item(new DcmItem);
+    OrthancWSI::DicomToolbox::SetStringTag(*item, DCM_DimensionOrganizationUID, organization);
+    
+    std::auto_ptr<DcmSequenceOfItems> sequence(new DcmSequenceOfItems(DCM_DimensionOrganizationSequence));
+
+    if (!sequence->insert(item.release(), false, false).good() ||
+        !dataset.insert(sequence.release(), true /* replace */, false).good())
     {
-      uid.assign(tmp);
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
     }
   }
 
-  if (uid.empty())
+
   {
-    // Generate an unique identifier for the Dimension Organization
-    uid = Orthanc::FromDcmtkBridge::GenerateUniqueIdentifier(Orthanc::ResourceType_Instance);
-  }
+    // Construct tag "Dimension Index Sequence" (0020,9222)
+    std::auto_ptr<DcmItem> item(new DcmItem);
+    OrthancWSI::DicomToolbox::SetStringTag(*item, DCM_DimensionOrganizationUID, organization);
+    OrthancWSI::DicomToolbox::SetAttributeTag(*item, DCM_FunctionalGroupPointer, DCM_PlanePositionSlideSequence);
+    OrthancWSI::DicomToolbox::SetAttributeTag(*item, DCM_DimensionIndexPointer, DCM_ColumnPositionInTotalImagePixelMatrix);
 
-  dataset.remove(DCM_DimensionIndexSequence);
+    std::auto_ptr<DcmItem> item2(new DcmItem);
+    OrthancWSI::DicomToolbox::SetStringTag(*item2, DCM_DimensionOrganizationUID, organization);
+    OrthancWSI::DicomToolbox::SetAttributeTag(*item2, DCM_FunctionalGroupPointer, DCM_PlanePositionSlideSequence);
+    OrthancWSI::DicomToolbox::SetAttributeTag(*item2, DCM_DimensionIndexPointer, DCM_RowPositionInTotalImagePixelMatrix);
 
-  std::auto_ptr<DcmItem> item(new DcmItem);
-  std::auto_ptr<DcmSequenceOfItems> sequence(new DcmSequenceOfItems(DCM_DimensionOrganizationSequence));
+    std::auto_ptr<DcmSequenceOfItems> sequence(new DcmSequenceOfItems(DCM_DimensionIndexSequence));
 
-  if (!item->putAndInsertString(DCM_DimensionOrganizationUID, uid.c_str()).good() ||
-      !sequence->insert(item.release(), false, false).good() ||
-      !dataset.insert(sequence.release(), true, false).good())
-  {
-    throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+    if (!sequence->insert(item.release(), false, false).good() ||
+        !sequence->insert(item2.release(), false, false).good() ||
+        !dataset.insert(sequence.release(), true /* replace */, false).good())
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+    }
   }
 
-  item.reset(new DcmItem);
-  sequence.reset(new DcmSequenceOfItems(DCM_DimensionIndexSequence));
 
-  std::auto_ptr<DcmAttributeTag> a1(new DcmAttributeTag(DCM_FunctionalGroupPointer));
-  std::auto_ptr<DcmAttributeTag> a2(new DcmAttributeTag(DCM_DimensionIndexPointer));
-
-  if (!item->putAndInsertString(DCM_DimensionOrganizationUID, uid.c_str()).good() ||
-      !a1->putTagVal(DCM_FrameContentSequence).good() ||
-      !a2->putTagVal(DCM_DimensionIndexValues).good() ||
-      !item->insert(a1.release()).good() ||
-      !item->insert(a2.release()).good() ||
-      !sequence->insert(item.release(), false, false).good() ||
-      !dataset.insert(sequence.release(), true, false).good())
   {
-    throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
-  }
+    // Construct tag "Shared Functional Groups Sequence" (5200,9229)
 
-  float spacingX = volume.GetWidth() / static_cast<float>(source.GetLevelHeight(0));  // Remember to switch X/Y!
-  float spacingY = volume.GetHeight() / static_cast<float>(source.GetLevelWidth(0));  // Remember to switch X/Y!
-  std::string spacing = (boost::lexical_cast<std::string>(spacingX) + '\\' +
-                         boost::lexical_cast<std::string>(spacingY));
+    // In the 2 lines below, remember to switch X/Y when going from physical to pixel coordinates!
+    float spacingX = volume.GetWidth() / static_cast<float>(source.GetLevelHeight(0));
+    float spacingY = volume.GetHeight() / static_cast<float>(source.GetLevelWidth(0));
 
-  item.reset(new DcmItem);
-  sequence.reset(new DcmSequenceOfItems(DCM_SharedFunctionalGroupsSequence));
-  std::auto_ptr<DcmItem> item2(new DcmItem);
-  std::auto_ptr<DcmItem> item3(new DcmItem);
-  std::auto_ptr<DcmSequenceOfItems> sequence2(new DcmSequenceOfItems(DCM_PixelMeasuresSequence));
-  std::auto_ptr<DcmSequenceOfItems> sequence3(new DcmSequenceOfItems(DCM_OpticalPathIdentificationSequence));
+    std::string spacing = (boost::lexical_cast<std::string>(spacingX) + '\\' +
+                           boost::lexical_cast<std::string>(spacingY));
 
-  OrthancWSI::DicomToolbox::SetStringTag(*item2, DCM_SliceThickness, boost::lexical_cast<std::string>(volume.GetDepth()));
-  OrthancWSI::DicomToolbox::SetStringTag(*item2, DCM_PixelSpacing, spacing);
-  OrthancWSI::DicomToolbox::SetStringTag(*item3, DCM_OpticalPathIdentifier, opticalPathId);
+    std::auto_ptr<DcmItem> item(new DcmItem);
 
-  if (!sequence2->insert(item2.release(), false, false).good() ||
-      !sequence3->insert(item3.release(), false, false).good() ||
-      !item->insert(sequence2.release(), false, false).good() ||
-      !item->insert(sequence3.release(), false, false).good() ||
-      !sequence->insert(item.release(), false, false).good() ||
-      !dataset.insert(sequence.release(), true, false).good())
-  {
-    throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+    std::auto_ptr<DcmItem> item2(new DcmItem);
+    OrthancWSI::DicomToolbox::SetStringTag(*item2, DCM_SliceThickness, 
+                                           boost::lexical_cast<std::string>(volume.GetDepth()));
+    OrthancWSI::DicomToolbox::SetStringTag(*item2, DCM_PixelSpacing, spacing);
+
+    std::auto_ptr<DcmItem> item3(new DcmItem);
+    OrthancWSI::DicomToolbox::SetStringTag(*item3, DCM_OpticalPathIdentifier, opticalPathId);
+
+    std::auto_ptr<DcmSequenceOfItems> sequence(new DcmSequenceOfItems(DCM_SharedFunctionalGroupsSequence));
+    std::auto_ptr<DcmSequenceOfItems> sequence2(new DcmSequenceOfItems(DCM_PixelMeasuresSequence));
+    std::auto_ptr<DcmSequenceOfItems> sequence3(new DcmSequenceOfItems(DCM_OpticalPathIdentificationSequence));
+
+    if (!sequence2->insert(item2.release(), false, false).good() ||
+        !sequence3->insert(item3.release(), false, false).good() ||
+        !item->insert(sequence2.release(), false, false).good() ||
+        !item->insert(sequence3.release(), false, false).good() ||
+        !sequence->insert(item.release(), false, false).good() ||
+        !dataset.insert(sequence.release(), true /* replace */, false).good())
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+    }
   }
 }
 
@@ -861,6 +877,7 @@ OrthancWSI::ITiledPyramid* OpenInputPyramid(OrthancWSI::ImageCompression& source
 int main(int argc, char* argv[])
 {
   OrthancWSI::ApplicationToolbox::GlobalInitialize();
+  OrthancWSI::ApplicationToolbox::ShowVersionInLog(argv[0]);
 
   int exitStatus = 0;
 
diff --git a/Framework/Algorithms/PyramidReader.cpp b/Framework/Algorithms/PyramidReader.cpp
index 0e15d11..4409bd9 100644
--- a/Framework/Algorithms/PyramidReader.cpp
+++ b/Framework/Algorithms/PyramidReader.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Algorithms/PyramidReader.h b/Framework/Algorithms/PyramidReader.h
index 05a5dad..8d8fabf 100644
--- a/Framework/Algorithms/PyramidReader.h
+++ b/Framework/Algorithms/PyramidReader.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Algorithms/ReconstructPyramidCommand.cpp b/Framework/Algorithms/ReconstructPyramidCommand.cpp
index 5c85d4d..79d1484 100644
--- a/Framework/Algorithms/ReconstructPyramidCommand.cpp
+++ b/Framework/Algorithms/ReconstructPyramidCommand.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Algorithms/ReconstructPyramidCommand.h b/Framework/Algorithms/ReconstructPyramidCommand.h
index 2f61c8b..e671ccc 100644
--- a/Framework/Algorithms/ReconstructPyramidCommand.h
+++ b/Framework/Algorithms/ReconstructPyramidCommand.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Algorithms/TranscodeTileCommand.cpp b/Framework/Algorithms/TranscodeTileCommand.cpp
index 0c4f54d..52e0493 100644
--- a/Framework/Algorithms/TranscodeTileCommand.cpp
+++ b/Framework/Algorithms/TranscodeTileCommand.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Algorithms/TranscodeTileCommand.h b/Framework/Algorithms/TranscodeTileCommand.h
index 8e9b7b1..974f706 100644
--- a/Framework/Algorithms/TranscodeTileCommand.h
+++ b/Framework/Algorithms/TranscodeTileCommand.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/DicomToolbox.cpp b/Framework/DicomToolbox.cpp
index c35bc76..3931279 100644
--- a/Framework/DicomToolbox.cpp
+++ b/Framework/DicomToolbox.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
@@ -28,6 +29,7 @@
 #if ORTHANC_ENABLE_DCMTK == 1
 #  include <dcmtk/dcmdata/dcelem.h>
 #  include <dcmtk/dcmdata/dcsequen.h>
+#  include <dcmtk/dcmdata/dcvrat.h>
 #endif
 
 namespace OrthancWSI
@@ -70,6 +72,23 @@ namespace OrthancWSI
     }
 
 
+    void SetAttributeTag(DcmItem& dataset,
+                         const DcmTagKey& key,
+                         const DcmTagKey& value)
+    {
+      if (!dataset.tagExists(key))
+      {
+        std::auto_ptr<DcmAttributeTag> tag(new DcmAttributeTag(key));
+        
+        if (!tag->putTagVal(value).good() ||
+            !dataset.insert(tag.release()).good())
+        {
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+        }
+      }
+    }
+
+
     DcmItem* ExtractSingleSequenceItem(DcmItem& dataset,
                                        const DcmTagKey& key)
     {
diff --git a/Framework/DicomToolbox.h b/Framework/DicomToolbox.h
index 874a8b3..03d158f 100644
--- a/Framework/DicomToolbox.h
+++ b/Framework/DicomToolbox.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
@@ -47,6 +48,10 @@ namespace OrthancWSI
                       const DcmTagKey& key,
                       uint32_t value);
 
+    void SetAttributeTag(DcmItem& dataset,
+                         const DcmTagKey& key,
+                         const DcmTagKey& value);
+
     DcmItem* ExtractSingleSequenceItem(DcmItem& dataset,
                                        const DcmTagKey& key);
 
diff --git a/Framework/DicomizerParameters.cpp b/Framework/DicomizerParameters.cpp
index 5af659a..2918bc5 100644
--- a/Framework/DicomizerParameters.cpp
+++ b/Framework/DicomizerParameters.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
@@ -53,24 +54,26 @@ namespace OrthancWSI
   }
 
 
-  DicomizerParameters::DicomizerParameters()
+  DicomizerParameters::DicomizerParameters() :
+    safetyCheck_(false),
+    repaintBackground_(false),
+    targetCompression_(ImageCompression_Jpeg),
+    hasTargetTileSize_(false),
+    targetTileWidth_(512),
+    targetTileHeight_(512),
+    maxDicomFileSize_(10 * 1024 * 1024),   // 10MB
+    reconstructPyramid_(false),
+    pyramidLevelsCount_(0),
+    pyramidLowerLevelsCount_(0),
+    smooth_(false),
+    jpegQuality_(90),
+    forceReencode_(false),
+    opticalPath_(OpticalPath_Brightfield)
   {
-    safetyCheck_ = false;
-    repaintBackground_ = false;
     backgroundColor_[0] = 255;
     backgroundColor_[1] = 255;
     backgroundColor_[2] = 255;
-    targetCompression_ = ImageCompression_Jpeg;
-    hasTargetTileSize_ = false;
     threadsCount_ = ChooseNumberOfThreads();
-    maxDicomFileSize_ = 10 * 1024 * 1024;   // 10MB
-    reconstructPyramid_ = false;
-    pyramidLevelsCount_ = 0;
-    pyramidLowerLevelsCount_ = 0;
-    smooth_ = false;
-    jpegQuality_ = 90;
-    forceReencode_ = false;
-    opticalPath_ = OpticalPath_Brightfield;
   }
 
 
@@ -146,7 +149,7 @@ namespace OrthancWSI
 
   void DicomizerParameters::SetPyramidLevelsCount(unsigned int count)
   {
-    if (count <= 0)
+    if (count == 0)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
@@ -195,7 +198,7 @@ namespace OrthancWSI
 
   void DicomizerParameters::SetPyramidLowerLevelsCount(unsigned int count)
   {
-    if (count <= 0)
+    if (count == 0)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }
diff --git a/Framework/DicomizerParameters.h b/Framework/DicomizerParameters.h
index 4b5e668..c68b306 100644
--- a/Framework/DicomizerParameters.h
+++ b/Framework/DicomizerParameters.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Enumerations.cpp b/Framework/Enumerations.cpp
index e1ff6b5..8694ffc 100644
--- a/Framework/Enumerations.cpp
+++ b/Framework/Enumerations.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Enumerations.h b/Framework/Enumerations.h
index a4f5715..91f75f2 100644
--- a/Framework/Enumerations.h
+++ b/Framework/Enumerations.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/ImageToolbox.cpp b/Framework/ImageToolbox.cpp
index b72b3cb..419cb80 100644
--- a/Framework/ImageToolbox.cpp
+++ b/Framework/ImageToolbox.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
@@ -221,9 +222,11 @@ namespace OrthancWSI
                                  unsigned int y,
                                  unsigned int channel,
                                  int offsetX,
-                                 int offsetY)
+                                 int offsetY,
+                                 unsigned int bytesPerPixel)
     {
-      assert(channel < source.GetBytesPerPixel());
+      assert(bytesPerPixel == source.GetBytesPerPixel());
+      assert(channel < bytesPerPixel);
       assert(source.GetFormat() == Orthanc::PixelFormat_Grayscale8 ||
              source.GetFormat() == Orthanc::PixelFormat_RGB24 ||
              source.GetFormat() == Orthanc::PixelFormat_RGBA32);  // 16bpp is unsupported
@@ -255,14 +258,15 @@ namespace OrthancWSI
       }
 
       return *(reinterpret_cast<const uint8_t*>(source.GetConstBuffer()) +
-               y * source.GetPitch() + x * source.GetBytesPerPixel() + channel);
+               y * source.GetPitch() + x * bytesPerPixel + channel);
     }
 
 
     static uint8_t SmoothPixelValue(const Orthanc::ImageAccessor& source,
                                     unsigned int x,
                                     unsigned int y,
-                                    unsigned int channel)
+                                    unsigned int channel,
+                                    unsigned int bytesPerPixel)
     {
       static const uint32_t kernel[5] = { 1, 4, 6, 4, 1 };
       static const uint32_t normalization = 2 * (1 + 4 + 6 + 4 + 1);
@@ -272,13 +276,13 @@ namespace OrthancWSI
       // Horizontal smoothing
       for (int offset = -2; offset <= 2; offset++)
       {
-        accumulator += kernel[offset + 2] * GetPixelValue(source, x, y, channel, offset, 0);
+        accumulator += kernel[offset + 2] * GetPixelValue(source, x, y, channel, offset, 0, bytesPerPixel);
       }
 
       // Vertical smoothing
       for (int offset = -2; offset <= 2; offset++)
       {
-        accumulator += kernel[offset + 2] * GetPixelValue(source, x, y, channel, 0, offset);
+        accumulator += kernel[offset + 2] * GetPixelValue(source, x, y, channel, 0, offset, bytesPerPixel);
       }
 
       return static_cast<uint8_t>(accumulator / normalization);
@@ -307,6 +311,8 @@ namespace OrthancWSI
                                                             source.GetWidth() / 2, 
                                                             source.GetHeight() / 2));
 
+      unsigned int bytesPerPixel = source.GetBytesPerPixel();
+
       for (unsigned int y = 0; y < source.GetHeight() / 2; y++)
       {
         uint8_t* q = reinterpret_cast<uint8_t*>(result->GetRow(y));
@@ -317,11 +323,11 @@ namespace OrthancWSI
           {
             if (smooth)
             {
-              q[c] = SmoothPixelValue(source, 2 * x, 2 * y, c);
+              q[c] = SmoothPixelValue(source, 2 * x, 2 * y, c, bytesPerPixel);
             }
             else
             {
-              q[c] = GetPixelValue(source, 2 * x, 2 * y, c, 0, 0);
+              q[c] = GetPixelValue(source, 2 * x, 2 * y, c, 0, 0, bytesPerPixel);
             }
           }
         }
diff --git a/Framework/ImageToolbox.h b/Framework/ImageToolbox.h
index 91b97a9..3d8bbbb 100644
--- a/Framework/ImageToolbox.h
+++ b/Framework/ImageToolbox.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/ImagedVolumeParameters.cpp b/Framework/ImagedVolumeParameters.cpp
index 1cff542..3464ae1 100644
--- a/Framework/ImagedVolumeParameters.cpp
+++ b/Framework/ImagedVolumeParameters.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/ImagedVolumeParameters.h b/Framework/ImagedVolumeParameters.h
index a27d49e..1a38e74 100644
--- a/Framework/ImagedVolumeParameters.h
+++ b/Framework/ImagedVolumeParameters.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/DecodedTiledPyramid.cpp b/Framework/Inputs/DecodedTiledPyramid.cpp
index a71af8e..d0ac482 100644
--- a/Framework/Inputs/DecodedTiledPyramid.cpp
+++ b/Framework/Inputs/DecodedTiledPyramid.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/DecodedTiledPyramid.h b/Framework/Inputs/DecodedTiledPyramid.h
index ed89878..e02752a 100644
--- a/Framework/Inputs/DecodedTiledPyramid.h
+++ b/Framework/Inputs/DecodedTiledPyramid.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/DicomPyramid.cpp b/Framework/Inputs/DicomPyramid.cpp
index c73e015..eeb681d 100644
--- a/Framework/Inputs/DicomPyramid.cpp
+++ b/Framework/Inputs/DicomPyramid.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/DicomPyramid.h b/Framework/Inputs/DicomPyramid.h
index 0925e09..11010dc 100644
--- a/Framework/Inputs/DicomPyramid.h
+++ b/Framework/Inputs/DicomPyramid.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/DicomPyramidInstance.cpp b/Framework/Inputs/DicomPyramidInstance.cpp
index daf48cb..1ba9103 100644
--- a/Framework/Inputs/DicomPyramidInstance.cpp
+++ b/Framework/Inputs/DicomPyramidInstance.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
@@ -40,8 +41,8 @@ namespace OrthancWSI
   {
     using namespace OrthancPlugins;
 
-    DicomDatasetReader header(new FullOrthancDataset
-                              (orthanc, "/instances/" + instanceId + "/header"));
+    FullOrthancDataset dataset(orthanc, "/instances/" + instanceId + "/header");
+    DicomDatasetReader header(dataset);
 
     std::string s = Orthanc::Toolbox::StripSpaces
       (header.GetMandatoryStringValue(DICOM_TAG_TRANSFER_SYNTAX_UID));
@@ -81,9 +82,16 @@ namespace OrthancWSI
       throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
     }
 
-    unsigned int bitsStored = reader.GetUnsignedIntegerValue(DICOM_TAG_BITS_STORED);
-    unsigned int samplesPerPixel = reader.GetUnsignedIntegerValue(DICOM_TAG_SAMPLES_PER_PIXEL);
-    bool isSigned = (reader.GetUnsignedIntegerValue(DICOM_TAG_PIXEL_REPRESENTATION) != 0);
+    unsigned int bitsStored, samplesPerPixel, tmp;
+
+    if (!reader.GetUnsignedIntegerValue(bitsStored, DICOM_TAG_BITS_STORED) ||
+        !reader.GetUnsignedIntegerValue(samplesPerPixel, DICOM_TAG_SAMPLES_PER_PIXEL) ||
+        !reader.GetUnsignedIntegerValue(tmp, DICOM_TAG_PIXEL_REPRESENTATION))
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag);
+    }
+
+    bool isSigned = (tmp != 0);
 
     if (bitsStored == 8 &&
         samplesPerPixel == 1 &&
@@ -131,7 +139,8 @@ namespace OrthancWSI
   {
     using namespace OrthancPlugins;
 
-    DicomDatasetReader reader(new FullOrthancDataset(orthanc, "/instances/" + instanceId + "/tags"));
+    FullOrthancDataset dataset(orthanc, "/instances/" + instanceId + "/tags");
+    DicomDatasetReader reader(dataset);
 
     if (reader.GetMandatoryStringValue(DICOM_TAG_SOP_CLASS_UID) != "1.2.840.10008.5.1.4.1.1.77.1.6" ||
         reader.GetMandatoryStringValue(DICOM_TAG_MODALITY) != "SM")
@@ -141,10 +150,16 @@ namespace OrthancWSI
 
     hasCompression_ = false;
     format_ = DetectPixelFormat(reader);
-    tileWidth_ = reader.GetUnsignedIntegerValue(DICOM_TAG_COLUMNS);
-    tileHeight_ = reader.GetUnsignedIntegerValue(DICOM_TAG_ROWS);
-    totalWidth_ = reader.GetUnsignedIntegerValue(DICOM_TAG_TOTAL_PIXEL_MATRIX_COLUMNS);
-    totalHeight_ = reader.GetUnsignedIntegerValue(DICOM_TAG_TOTAL_PIXEL_MATRIX_ROWS);
+
+    unsigned int tmp;
+    if (!reader.GetUnsignedIntegerValue(tileWidth_, DICOM_TAG_COLUMNS) ||
+        !reader.GetUnsignedIntegerValue(tileHeight_, DICOM_TAG_ROWS) ||
+        !reader.GetUnsignedIntegerValue(totalWidth_, DICOM_TAG_TOTAL_PIXEL_MATRIX_COLUMNS) ||
+        !reader.GetUnsignedIntegerValue(totalHeight_, DICOM_TAG_TOTAL_PIXEL_MATRIX_ROWS) ||
+        !reader.GetUnsignedIntegerValue(tmp, DICOM_TAG_NUMBER_OF_FRAMES))
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
+    }
 
     size_t countFrames;
     if (!reader.GetDataset().GetSequenceSize(countFrames, DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE))
@@ -152,7 +167,7 @@ namespace OrthancWSI
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
     }
 
-    if (countFrames != reader.GetUnsignedIntegerValue(DICOM_TAG_NUMBER_OF_FRAMES))
+    if (countFrames != tmp)
     {
       LOG(ERROR) << "Mismatch between the number of frames in instance: " << instanceId;
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
@@ -162,13 +177,20 @@ namespace OrthancWSI
 
     for (size_t i = 0; i < countFrames; i++)
     {
-      int xx = reader.GetIntegerValue(DicomPath(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i,
-                                                DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0,
-                                                DICOM_TAG_COLUMN_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX));
+      DicomPath pathX(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i,
+                      DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0,
+                      DICOM_TAG_COLUMN_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX);
+
+      DicomPath pathY(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i,
+                      DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0,
+                      DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX);
 
-      int yy = reader.GetIntegerValue(DicomPath(DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE, i,
-                                                DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE, 0,
-                                                DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX));
+      int xx, yy;
+      if (!reader.GetIntegerValue(xx, pathX) ||
+          !reader.GetIntegerValue(yy, pathY))
+      {
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentTag);
+      }
 
       // "-1", because coordinates are shifted by 1 in DICOM
       xx -= 1;
diff --git a/Framework/Inputs/DicomPyramidInstance.h b/Framework/Inputs/DicomPyramidInstance.h
index 8aced5a..46db6de 100644
--- a/Framework/Inputs/DicomPyramidInstance.h
+++ b/Framework/Inputs/DicomPyramidInstance.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/DicomPyramidLevel.cpp b/Framework/Inputs/DicomPyramidLevel.cpp
index f76e7e8..bf48948 100644
--- a/Framework/Inputs/DicomPyramidLevel.cpp
+++ b/Framework/Inputs/DicomPyramidLevel.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/DicomPyramidLevel.h b/Framework/Inputs/DicomPyramidLevel.h
index a64796f..106b372 100644
--- a/Framework/Inputs/DicomPyramidLevel.h
+++ b/Framework/Inputs/DicomPyramidLevel.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/HierarchicalTiff.cpp b/Framework/Inputs/HierarchicalTiff.cpp
index a8505ec..c632a4c 100644
--- a/Framework/Inputs/HierarchicalTiff.cpp
+++ b/Framework/Inputs/HierarchicalTiff.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/HierarchicalTiff.h b/Framework/Inputs/HierarchicalTiff.h
index 3cf8ef0..90f9e45 100644
--- a/Framework/Inputs/HierarchicalTiff.h
+++ b/Framework/Inputs/HierarchicalTiff.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/ITiledPyramid.h b/Framework/Inputs/ITiledPyramid.h
index 42b277c..3e2bf9c 100644
--- a/Framework/Inputs/ITiledPyramid.h
+++ b/Framework/Inputs/ITiledPyramid.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/OpenSlideLibrary.cpp b/Framework/Inputs/OpenSlideLibrary.cpp
index babdfa9..ca4f27f 100644
--- a/Framework/Inputs/OpenSlideLibrary.cpp
+++ b/Framework/Inputs/OpenSlideLibrary.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
@@ -190,7 +191,7 @@ namespace OrthancWSI
     CheckLevel(level);
 
     // Create a new image, with minimal pitch so as to be compatible with OpenSlide API
-    std::auto_ptr<Orthanc::ImageAccessor> region(new Orthanc::Image(Orthanc::PixelFormat_RGBA32, width, height, true));
+    std::auto_ptr<Orthanc::ImageAccessor> region(new Orthanc::Image(Orthanc::PixelFormat_BGRA32, width, height, true));
 
     if (region->GetWidth() != 0 &&
         region->GetHeight() != 0)
diff --git a/Framework/Inputs/OpenSlideLibrary.h b/Framework/Inputs/OpenSlideLibrary.h
index f48eba9..022e0b0 100644
--- a/Framework/Inputs/OpenSlideLibrary.h
+++ b/Framework/Inputs/OpenSlideLibrary.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/OpenSlidePyramid.cpp b/Framework/Inputs/OpenSlidePyramid.cpp
index a9c95fa..0bd7ec0 100644
--- a/Framework/Inputs/OpenSlidePyramid.cpp
+++ b/Framework/Inputs/OpenSlidePyramid.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/OpenSlidePyramid.h b/Framework/Inputs/OpenSlidePyramid.h
index 999c9a4..7f3af12 100644
--- a/Framework/Inputs/OpenSlidePyramid.h
+++ b/Framework/Inputs/OpenSlidePyramid.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/PyramidWithRawTiles.cpp b/Framework/Inputs/PyramidWithRawTiles.cpp
index 90a9104..0137ee7 100644
--- a/Framework/Inputs/PyramidWithRawTiles.cpp
+++ b/Framework/Inputs/PyramidWithRawTiles.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/PyramidWithRawTiles.h b/Framework/Inputs/PyramidWithRawTiles.h
index 7b7ef49..1ee51c2 100644
--- a/Framework/Inputs/PyramidWithRawTiles.h
+++ b/Framework/Inputs/PyramidWithRawTiles.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/SingleLevelDecodedPyramid.cpp b/Framework/Inputs/SingleLevelDecodedPyramid.cpp
index 6532198..49ff990 100644
--- a/Framework/Inputs/SingleLevelDecodedPyramid.cpp
+++ b/Framework/Inputs/SingleLevelDecodedPyramid.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/SingleLevelDecodedPyramid.h b/Framework/Inputs/SingleLevelDecodedPyramid.h
index ac3654f..3c666a2 100644
--- a/Framework/Inputs/SingleLevelDecodedPyramid.h
+++ b/Framework/Inputs/SingleLevelDecodedPyramid.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/TiledJpegImage.h b/Framework/Inputs/TiledJpegImage.h
index c3585ad..0bf1e27 100644
--- a/Framework/Inputs/TiledJpegImage.h
+++ b/Framework/Inputs/TiledJpegImage.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/TiledPngImage.h b/Framework/Inputs/TiledPngImage.h
index 3d90678..995405c 100644
--- a/Framework/Inputs/TiledPngImage.h
+++ b/Framework/Inputs/TiledPngImage.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/TiledPyramidStatistics.cpp b/Framework/Inputs/TiledPyramidStatistics.cpp
index da2fa29..f090396 100644
--- a/Framework/Inputs/TiledPyramidStatistics.cpp
+++ b/Framework/Inputs/TiledPyramidStatistics.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Inputs/TiledPyramidStatistics.h b/Framework/Inputs/TiledPyramidStatistics.h
index bdecde6..2395e4e 100644
--- a/Framework/Inputs/TiledPyramidStatistics.h
+++ b/Framework/Inputs/TiledPyramidStatistics.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Jpeg2000Reader.cpp b/Framework/Jpeg2000Reader.cpp
index 38579bd..431832f 100644
--- a/Framework/Jpeg2000Reader.cpp
+++ b/Framework/Jpeg2000Reader.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Jpeg2000Reader.h b/Framework/Jpeg2000Reader.h
index beba04f..73a4c38 100644
--- a/Framework/Jpeg2000Reader.h
+++ b/Framework/Jpeg2000Reader.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Jpeg2000Writer.cpp b/Framework/Jpeg2000Writer.cpp
index 0757efc..7eaf35c 100644
--- a/Framework/Jpeg2000Writer.cpp
+++ b/Framework/Jpeg2000Writer.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Jpeg2000Writer.h b/Framework/Jpeg2000Writer.h
index 315f66c..9d7501f 100644
--- a/Framework/Jpeg2000Writer.h
+++ b/Framework/Jpeg2000Writer.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Outputs/DicomPyramidWriter.cpp b/Framework/Outputs/DicomPyramidWriter.cpp
index 53db9b5..7ddbddf 100644
--- a/Framework/Outputs/DicomPyramidWriter.cpp
+++ b/Framework/Outputs/DicomPyramidWriter.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
@@ -61,9 +62,14 @@ namespace OrthancWSI
     std::string tmpX = boost::lexical_cast<std::string>(physicalX);
     std::string tmpY = boost::lexical_cast<std::string>(physicalY);
     std::string tmpZ = boost::lexical_cast<std::string>(physicalZ);
+    
+    // NB: Method DcmItem::putAndInsertUint32Array() should be used at
+    // this point, but it is missing in DCMTK 3.6.0
+    std::string index = (boost::lexical_cast<std::string>(x / GetTileWidth() + 1) + "\\" + 
+                         boost::lexical_cast<std::string>(y / GetTileHeight() + 1));
 
     std::auto_ptr<DcmItem> dimension(new DcmItem);
-    if (!dimension->putAndInsertUint32(DCM_DimensionIndexValues, frame).good())
+    if (!dimension->putAndInsertString(DCM_DimensionIndexValues, index.c_str()).good())
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
     }
diff --git a/Framework/Outputs/DicomPyramidWriter.h b/Framework/Outputs/DicomPyramidWriter.h
index f9fb8ee..2e939db 100644
--- a/Framework/Outputs/DicomPyramidWriter.h
+++ b/Framework/Outputs/DicomPyramidWriter.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Outputs/HierarchicalTiffWriter.cpp b/Framework/Outputs/HierarchicalTiffWriter.cpp
index 5e2e5eb..762ced8 100644
--- a/Framework/Outputs/HierarchicalTiffWriter.cpp
+++ b/Framework/Outputs/HierarchicalTiffWriter.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Outputs/HierarchicalTiffWriter.h b/Framework/Outputs/HierarchicalTiffWriter.h
index 8a920e4..b98fa54 100644
--- a/Framework/Outputs/HierarchicalTiffWriter.h
+++ b/Framework/Outputs/HierarchicalTiffWriter.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Outputs/IPyramidWriter.h b/Framework/Outputs/IPyramidWriter.h
index 04dac0c..ff38bb5 100644
--- a/Framework/Outputs/IPyramidWriter.h
+++ b/Framework/Outputs/IPyramidWriter.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Outputs/InMemoryTiledImage.cpp b/Framework/Outputs/InMemoryTiledImage.cpp
index 283328a..6ca9db2 100644
--- a/Framework/Outputs/InMemoryTiledImage.cpp
+++ b/Framework/Outputs/InMemoryTiledImage.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Outputs/InMemoryTiledImage.h b/Framework/Outputs/InMemoryTiledImage.h
index 2352060..36096a7 100644
--- a/Framework/Outputs/InMemoryTiledImage.h
+++ b/Framework/Outputs/InMemoryTiledImage.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Outputs/MultiframeDicomWriter.cpp b/Framework/Outputs/MultiframeDicomWriter.cpp
index d727d40..2159fdd 100644
--- a/Framework/Outputs/MultiframeDicomWriter.cpp
+++ b/Framework/Outputs/MultiframeDicomWriter.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Outputs/MultiframeDicomWriter.h b/Framework/Outputs/MultiframeDicomWriter.h
index b185e94..cc85cbd 100644
--- a/Framework/Outputs/MultiframeDicomWriter.h
+++ b/Framework/Outputs/MultiframeDicomWriter.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Outputs/PyramidWriterBase.cpp b/Framework/Outputs/PyramidWriterBase.cpp
index 09394dd..c19c819 100644
--- a/Framework/Outputs/PyramidWriterBase.cpp
+++ b/Framework/Outputs/PyramidWriterBase.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Outputs/PyramidWriterBase.h b/Framework/Outputs/PyramidWriterBase.h
index 7d0f218..4bbb705 100644
--- a/Framework/Outputs/PyramidWriterBase.h
+++ b/Framework/Outputs/PyramidWriterBase.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Outputs/TruncatedPyramidWriter.cpp b/Framework/Outputs/TruncatedPyramidWriter.cpp
index 802c2dc..bc39abd 100644
--- a/Framework/Outputs/TruncatedPyramidWriter.cpp
+++ b/Framework/Outputs/TruncatedPyramidWriter.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Outputs/TruncatedPyramidWriter.h b/Framework/Outputs/TruncatedPyramidWriter.h
index ce50cd0..073246a 100644
--- a/Framework/Outputs/TruncatedPyramidWriter.h
+++ b/Framework/Outputs/TruncatedPyramidWriter.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/PrecompiledHeadersWSI.cpp b/Framework/PrecompiledHeadersWSI.cpp
index afef2e6..bdc141c 100644
--- a/Framework/PrecompiledHeadersWSI.cpp
+++ b/Framework/PrecompiledHeadersWSI.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/PrecompiledHeadersWSI.h b/Framework/PrecompiledHeadersWSI.h
index 55d8766..d2f1c0d 100644
--- a/Framework/PrecompiledHeadersWSI.h
+++ b/Framework/PrecompiledHeadersWSI.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Targets/FolderTarget.cpp b/Framework/Targets/FolderTarget.cpp
index 6451e4b..887ce73 100644
--- a/Framework/Targets/FolderTarget.cpp
+++ b/Framework/Targets/FolderTarget.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Targets/FolderTarget.h b/Framework/Targets/FolderTarget.h
index 7feba07..36bb338 100644
--- a/Framework/Targets/FolderTarget.h
+++ b/Framework/Targets/FolderTarget.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
@@ -34,7 +35,7 @@ namespace OrthancWSI
     std::string   pattern_;
 
   public:
-    FolderTarget(const std::string& pattern) : 
+    explicit FolderTarget(const std::string& pattern) : 
       count_(0),
       pattern_(pattern)
     {
diff --git a/Framework/Targets/IFileTarget.h b/Framework/Targets/IFileTarget.h
index cee7b35..9086206 100644
--- a/Framework/Targets/IFileTarget.h
+++ b/Framework/Targets/IFileTarget.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Targets/OrthancTarget.cpp b/Framework/Targets/OrthancTarget.cpp
index 987af94..65c43e8 100644
--- a/Framework/Targets/OrthancTarget.cpp
+++ b/Framework/Targets/OrthancTarget.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/Framework/Targets/OrthancTarget.h b/Framework/Targets/OrthancTarget.h
index 15d333d..14cf399 100644
--- a/Framework/Targets/OrthancTarget.h
+++ b/Framework/Targets/OrthancTarget.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
@@ -35,9 +36,9 @@ namespace OrthancWSI
     bool  first_;
 
   public:
-    OrthancTarget(const Orthanc::WebServiceParameters& parameters);
+    explicit OrthancTarget(const Orthanc::WebServiceParameters& parameters);
 
-    OrthancTarget(OrthancPlugins::IOrthancConnection* orthanc) :   // Takes ownership
+    explicit OrthancTarget(OrthancPlugins::IOrthancConnection* orthanc) :   // Takes ownership
       orthanc_(orthanc),
       first_(true)
     {
diff --git a/NEWS b/NEWS
index 97f7cbf..940cf63 100644
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,23 @@ Pending changes in the mainline
 ===============================
 
 
-Version 0.2 (2016/11/28)
+Version 0.4 (2017-03-01)
+========================
+
+* Fix issue #30: Bad colorspace if using OpenSlide
+
+
+Version 0.3 (2016-12-23)
+========================
+
+* Thanks to David Clunie's feedback:
+  - Fix generation of tag "Dimension Index Sequence" (0020,9222)
+  - Fix generation of tag "Dimension Index Values" (0020,9157)
+* Improved logging in the viewer plugin
+* Display version of the framework in the logs
+
+
+Version 0.2 (2016-11-28)
 ========================
 
 * Huge speed-up in the whole-slide imaging Web viewer plugin:
@@ -13,7 +29,7 @@ Version 0.2 (2016/11/28)
 * Various refactorings
 
 
-Version 0.1 (2016/10/28)
+Version 0.1 (2016-10-28)
 ========================
 
 * Docker images are available
diff --git a/Resources/CMake/LibTiffConfiguration.cmake b/Resources/CMake/LibTiffConfiguration.cmake
index 77ca942..dab769f 100644
--- a/Resources/CMake/LibTiffConfiguration.cmake
+++ b/Resources/CMake/LibTiffConfiguration.cmake
@@ -1,6 +1,6 @@
 if (STATIC_BUILD OR NOT USE_SYSTEM_LIBTIFF)
   SET(LIBTIFF_SOURCES_DIR ${CMAKE_BINARY_DIR}/tiff-4.0.6)
-  SET(LIBTIFF_URL "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/WSI/tiff-4.0.6.tar.gz")
+  SET(LIBTIFF_URL "http://www.orthanc-server.com/downloads/third-party/WSI/tiff-4.0.6.tar.gz")
   SET(LIBTIFF_MD5 "d1d2e940dea0b5ad435f21f03d96dd72")
 
   DownloadPackage(${LIBTIFF_MD5} ${LIBTIFF_URL} "${LIBTIFF_SOURCES_DIR}")
diff --git a/Resources/CMake/OpenJpegConfiguration.cmake b/Resources/CMake/OpenJpegConfiguration.cmake
index e936559..d58a146 100644
--- a/Resources/CMake/OpenJpegConfiguration.cmake
+++ b/Resources/CMake/OpenJpegConfiguration.cmake
@@ -1,6 +1,6 @@
 if (STATIC_BUILD OR NOT USE_SYSTEM_OPENJPEG)
   SET(OPENJPEG_SOURCES_DIR ${CMAKE_BINARY_DIR}/openjpeg-version.2.1)
-  SET(OPENJPEG_URL "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/openjpeg-2.1.tar.gz")
+  SET(OPENJPEG_URL "http://www.orthanc-server.com/downloads/third-party/openjpeg-2.1.tar.gz")
   SET(OPENJPEG_MD5 "3e1c451c087f8462955426da38aa3b3d")
 
   if (IS_DIRECTORY "${OPENJPEG_SOURCES_DIR}")
diff --git a/Resources/CMake/Version.cmake b/Resources/CMake/Version.cmake
index f491a13..539e182 100644
--- a/Resources/CMake/Version.cmake
+++ b/Resources/CMake/Version.cmake
@@ -1,4 +1,4 @@
-set(ORTHANC_WSI_VERSION "0.2")
+set(ORTHANC_WSI_VERSION "0.4")
 
 add_definitions(
   -DORTHANC_WSI_VERSION="${ORTHANC_WSI_VERSION}"
diff --git a/Resources/Orthanc/Core/Cache/LeastRecentlyUsedIndex.h b/Resources/Orthanc/Core/Cache/LeastRecentlyUsedIndex.h
index a5bf7b2..63ed2d4 100644
--- a/Resources/Orthanc/Core/Cache/LeastRecentlyUsedIndex.h
+++ b/Resources/Orthanc/Core/Cache/LeastRecentlyUsedIndex.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/ChunkedBuffer.cpp b/Resources/Orthanc/Core/ChunkedBuffer.cpp
index 5d2c2c8..22a3c0e 100644
--- a/Resources/Orthanc/Core/ChunkedBuffer.cpp
+++ b/Resources/Orthanc/Core/ChunkedBuffer.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/ChunkedBuffer.h b/Resources/Orthanc/Core/ChunkedBuffer.h
index 552c1ec..05c724e 100644
--- a/Resources/Orthanc/Core/ChunkedBuffer.h
+++ b/Resources/Orthanc/Core/ChunkedBuffer.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/DicomFormat/DicomArray.cpp b/Resources/Orthanc/Core/DicomFormat/DicomArray.cpp
index 4900419..800c4cf 100644
--- a/Resources/Orthanc/Core/DicomFormat/DicomArray.cpp
+++ b/Resources/Orthanc/Core/DicomFormat/DicomArray.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/DicomFormat/DicomArray.h b/Resources/Orthanc/Core/DicomFormat/DicomArray.h
index a223685..5f66f07 100644
--- a/Resources/Orthanc/Core/DicomFormat/DicomArray.h
+++ b/Resources/Orthanc/Core/DicomFormat/DicomArray.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -47,7 +48,7 @@ namespace Orthanc
     Elements  elements_;
 
   public:
-    DicomArray(const DicomMap& map);
+    explicit DicomArray(const DicomMap& map);
 
     ~DicomArray();
 
diff --git a/Resources/Orthanc/Core/DicomFormat/DicomElement.h b/Resources/Orthanc/Core/DicomFormat/DicomElement.h
index c6f47e5..a50d5c3 100644
--- a/Resources/Orthanc/Core/DicomFormat/DicomElement.h
+++ b/Resources/Orthanc/Core/DicomFormat/DicomElement.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/DicomFormat/DicomMap.cpp b/Resources/Orthanc/Core/DicomFormat/DicomMap.cpp
index cd72d09..c11ee82 100644
--- a/Resources/Orthanc/Core/DicomFormat/DicomMap.cpp
+++ b/Resources/Orthanc/Core/DicomFormat/DicomMap.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/DicomFormat/DicomMap.h b/Resources/Orthanc/Core/DicomFormat/DicomMap.h
index 58e50b8..80732ef 100644
--- a/Resources/Orthanc/Core/DicomFormat/DicomMap.h
+++ b/Resources/Orthanc/Core/DicomFormat/DicomMap.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -47,7 +48,7 @@ namespace Orthanc
   private:
     friend class DicomArray;
     friend class FromDcmtkBridge;
-    friend class ToDcmtkBridge;
+    friend class ParsedDicomFile;
 
     typedef std::map<DicomTag, DicomValue*>  Map;
 
diff --git a/Resources/Orthanc/Core/DicomFormat/DicomTag.cpp b/Resources/Orthanc/Core/DicomFormat/DicomTag.cpp
index 12ae7a4..83cc9fe 100644
--- a/Resources/Orthanc/Core/DicomFormat/DicomTag.cpp
+++ b/Resources/Orthanc/Core/DicomFormat/DicomTag.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/DicomFormat/DicomTag.h b/Resources/Orthanc/Core/DicomFormat/DicomTag.h
index 25f4259..6b9ba90 100644
--- a/Resources/Orthanc/Core/DicomFormat/DicomTag.h
+++ b/Resources/Orthanc/Core/DicomFormat/DicomTag.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -100,6 +101,7 @@ namespace Orthanc
   static const DicomTag DICOM_TAG_SERIES_INSTANCE_UID(0x0020, 0x000e);
   static const DicomTag DICOM_TAG_STUDY_INSTANCE_UID(0x0020, 0x000d);
   static const DicomTag DICOM_TAG_PIXEL_DATA(0x7fe0, 0x0010);
+  static const DicomTag DICOM_TAG_TRANSFER_SYNTAX_UID(0x0002, 0x0010);
 
   static const DicomTag DICOM_TAG_IMAGE_INDEX(0x0054, 0x1330);
   static const DicomTag DICOM_TAG_INSTANCE_NUMBER(0x0020, 0x0013);
@@ -127,6 +129,7 @@ namespace Orthanc
   static const DicomTag DICOM_TAG_TEMPORAL_POSITION_IDENTIFIER(0x0020, 0x0100);
 
   // Tags for C-FIND and C-MOVE
+  static const DicomTag DICOM_TAG_MESSAGE_ID(0x0000, 0x0110);
   static const DicomTag DICOM_TAG_SPECIFIC_CHARACTER_SET(0x0008, 0x0005);
   static const DicomTag DICOM_TAG_QUERY_RETRIEVE_LEVEL(0x0008, 0x0052);
   static const DicomTag DICOM_TAG_MODALITIES_IN_STUDY(0x0008, 0x0061);
diff --git a/Resources/Orthanc/Core/DicomFormat/DicomValue.cpp b/Resources/Orthanc/Core/DicomFormat/DicomValue.cpp
index 2a4c2f2..9c8958d 100644
--- a/Resources/Orthanc/Core/DicomFormat/DicomValue.cpp
+++ b/Resources/Orthanc/Core/DicomFormat/DicomValue.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/DicomFormat/DicomValue.h b/Resources/Orthanc/Core/DicomFormat/DicomValue.h
index c4844b7..405cdda 100644
--- a/Resources/Orthanc/Core/DicomFormat/DicomValue.h
+++ b/Resources/Orthanc/Core/DicomFormat/DicomValue.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Endianness.h b/Resources/Orthanc/Core/Endianness.h
index a68fd83..14cbca1 100644
--- a/Resources/Orthanc/Core/Endianness.h
+++ b/Resources/Orthanc/Core/Endianness.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/EnumerationDictionary.h b/Resources/Orthanc/Core/EnumerationDictionary.h
index 9479401..e0a0960 100644
--- a/Resources/Orthanc/Core/EnumerationDictionary.h
+++ b/Resources/Orthanc/Core/EnumerationDictionary.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Enumerations.cpp b/Resources/Orthanc/Core/Enumerations.cpp
index 5a72585..55a918c 100644
--- a/Resources/Orthanc/Core/Enumerations.cpp
+++ b/Resources/Orthanc/Core/Enumerations.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -1083,15 +1084,18 @@ namespace Orthanc
   bool GetDicomEncoding(Encoding& encoding,
                         const char* specificCharacterSet)
   {
-    std::string s = specificCharacterSet;
+    std::string s = Toolbox::StripSpaces(specificCharacterSet);
     Toolbox::ToUpperCase(s);
 
     // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.12.1.1.2
     // https://github.com/dcm4che/dcm4che/blob/master/dcm4che-core/src/main/java/org/dcm4che3/data/SpecificCharacterSet.java
     if (s == "ISO_IR 6" ||
-        s == "ISO_IR 192" ||
         s == "ISO 2022 IR 6")
     {
+      encoding = Encoding_Ascii;
+    }
+    else if (s == "ISO_IR 192")
+    {
       encoding = Encoding_Utf8;
     }
     else if (s == "ISO_IR 100" ||
@@ -1238,8 +1242,10 @@ namespace Orthanc
     // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.12.1.1.2
     switch (encoding)
     {
-      case Encoding_Utf8:
       case Encoding_Ascii:
+        return "ISO_IR 6";
+
+      case Encoding_Utf8:
         return "ISO_IR 192";
 
       case Encoding_Latin1:
diff --git a/Resources/Orthanc/Core/Enumerations.h b/Resources/Orthanc/Core/Enumerations.h
index 9b18661..aaf0c38 100644
--- a/Resources/Orthanc/Core/Enumerations.h
+++ b/Resources/Orthanc/Core/Enumerations.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/HttpClient.cpp b/Resources/Orthanc/Core/HttpClient.cpp
index 0999b84..e9c5d9e 100644
--- a/Resources/Orthanc/Core/HttpClient.cpp
+++ b/Resources/Orthanc/Core/HttpClient.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -318,10 +319,10 @@ namespace Orthanc
     url_ = "";
     method_ = HttpMethod_Get;
     lastStatus_ = HttpStatus_200_Ok;
-    isVerbose_ = false;
+    SetVerbose(false);
     timeout_ = GlobalParameters::GetInstance().GetDefaultTimeout();
     GlobalParameters::GetInstance().GetDefaultProxy(proxy_);
-    GlobalParameters::GetInstance().GetSslConfiguration(verifyPeers_, caCertificates_);
+    GlobalParameters::GetInstance().GetSslConfiguration(verifyPeers_, caCertificates_);    
   }
 
 
diff --git a/Resources/Orthanc/Core/HttpClient.h b/Resources/Orthanc/Core/HttpClient.h
index 1b80f33..65435d0 100644
--- a/Resources/Orthanc/Core/HttpClient.h
+++ b/Resources/Orthanc/Core/HttpClient.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/ICommand.h b/Resources/Orthanc/Core/ICommand.h
index a0805b9..221893e 100644
--- a/Resources/Orthanc/Core/ICommand.h
+++ b/Resources/Orthanc/Core/ICommand.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/IDynamicObject.h b/Resources/Orthanc/Core/IDynamicObject.h
index 8c36617..648acf4 100644
--- a/Resources/Orthanc/Core/IDynamicObject.h
+++ b/Resources/Orthanc/Core/IDynamicObject.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/IImageWriter.cpp b/Resources/Orthanc/Core/Images/IImageWriter.cpp
index b215080..479ee39 100644
--- a/Resources/Orthanc/Core/Images/IImageWriter.cpp
+++ b/Resources/Orthanc/Core/Images/IImageWriter.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/IImageWriter.h b/Resources/Orthanc/Core/Images/IImageWriter.h
index ca27010..d467c7f 100644
--- a/Resources/Orthanc/Core/Images/IImageWriter.h
+++ b/Resources/Orthanc/Core/Images/IImageWriter.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/Image.cpp b/Resources/Orthanc/Core/Images/Image.cpp
index 4212f6d..e60ab07 100644
--- a/Resources/Orthanc/Core/Images/Image.cpp
+++ b/Resources/Orthanc/Core/Images/Image.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/Image.h b/Resources/Orthanc/Core/Images/Image.h
index eba83c7..8d4cdac 100644
--- a/Resources/Orthanc/Core/Images/Image.h
+++ b/Resources/Orthanc/Core/Images/Image.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/ImageAccessor.cpp b/Resources/Orthanc/Core/Images/ImageAccessor.cpp
index eff8623..2c61674 100644
--- a/Resources/Orthanc/Core/Images/ImageAccessor.cpp
+++ b/Resources/Orthanc/Core/Images/ImageAccessor.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/ImageAccessor.h b/Resources/Orthanc/Core/Images/ImageAccessor.h
index 77e79c2..6033ce4 100644
--- a/Resources/Orthanc/Core/Images/ImageAccessor.h
+++ b/Resources/Orthanc/Core/Images/ImageAccessor.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/ImageBuffer.cpp b/Resources/Orthanc/Core/Images/ImageBuffer.cpp
index 71364dc..cfb3459 100644
--- a/Resources/Orthanc/Core/Images/ImageBuffer.cpp
+++ b/Resources/Orthanc/Core/Images/ImageBuffer.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/ImageBuffer.h b/Resources/Orthanc/Core/Images/ImageBuffer.h
index 21b1b15..1c2dbd3 100644
--- a/Resources/Orthanc/Core/Images/ImageBuffer.h
+++ b/Resources/Orthanc/Core/Images/ImageBuffer.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/ImageProcessing.cpp b/Resources/Orthanc/Core/Images/ImageProcessing.cpp
index 23c9fee..19ca021 100644
--- a/Resources/Orthanc/Core/Images/ImageProcessing.cpp
+++ b/Resources/Orthanc/Core/Images/ImageProcessing.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -457,6 +458,26 @@ namespace Orthanc
       return;
     }
 
+    if (target.GetFormat() == PixelFormat_RGB24 &&
+        source.GetFormat() == PixelFormat_BGRA32)
+    {
+      for (unsigned int y = 0; y < source.GetHeight(); y++)
+      {
+        const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(y));
+        uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
+        for (unsigned int x = 0; x < source.GetWidth(); x++)
+        {
+          q[0] = p[2];
+          q[1] = p[1];
+          q[2] = p[0];
+          p += 4;
+          q += 3;
+        }
+      }
+
+      return;
+    }
+
     if (target.GetFormat() == PixelFormat_RGBA32 &&
         source.GetFormat() == PixelFormat_RGB24)
     {
diff --git a/Resources/Orthanc/Core/Images/ImageProcessing.h b/Resources/Orthanc/Core/Images/ImageProcessing.h
index 45176b5..cc78e63 100644
--- a/Resources/Orthanc/Core/Images/ImageProcessing.h
+++ b/Resources/Orthanc/Core/Images/ImageProcessing.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/JpegErrorManager.cpp b/Resources/Orthanc/Core/Images/JpegErrorManager.cpp
index 42c3842..00daea0 100644
--- a/Resources/Orthanc/Core/Images/JpegErrorManager.cpp
+++ b/Resources/Orthanc/Core/Images/JpegErrorManager.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/JpegErrorManager.h b/Resources/Orthanc/Core/Images/JpegErrorManager.h
index 610cd73..f149510 100644
--- a/Resources/Orthanc/Core/Images/JpegErrorManager.h
+++ b/Resources/Orthanc/Core/Images/JpegErrorManager.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/JpegReader.cpp b/Resources/Orthanc/Core/Images/JpegReader.cpp
index 9d6ea08..7d5c7e8 100644
--- a/Resources/Orthanc/Core/Images/JpegReader.cpp
+++ b/Resources/Orthanc/Core/Images/JpegReader.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/JpegReader.h b/Resources/Orthanc/Core/Images/JpegReader.h
index 978058c..105a9b8 100644
--- a/Resources/Orthanc/Core/Images/JpegReader.h
+++ b/Resources/Orthanc/Core/Images/JpegReader.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/JpegWriter.cpp b/Resources/Orthanc/Core/Images/JpegWriter.cpp
index 9f5ae8d..1c62ac2 100644
--- a/Resources/Orthanc/Core/Images/JpegWriter.cpp
+++ b/Resources/Orthanc/Core/Images/JpegWriter.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -105,7 +106,7 @@ namespace Orthanc
 
   void JpegWriter::SetQuality(uint8_t quality)
   {
-    if (quality <= 0 || quality > 100)
+    if (quality == 0 || quality > 100)
     {
       throw OrthancException(ErrorCode_ParameterOutOfRange);
     }
diff --git a/Resources/Orthanc/Core/Images/JpegWriter.h b/Resources/Orthanc/Core/Images/JpegWriter.h
index ffb6098..94341c4 100644
--- a/Resources/Orthanc/Core/Images/JpegWriter.h
+++ b/Resources/Orthanc/Core/Images/JpegWriter.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/PngReader.cpp b/Resources/Orthanc/Core/Images/PngReader.cpp
index 8315ca7..0227875 100644
--- a/Resources/Orthanc/Core/Images/PngReader.cpp
+++ b/Resources/Orthanc/Core/Images/PngReader.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/PngReader.h b/Resources/Orthanc/Core/Images/PngReader.h
index fd18d26..f07013d 100644
--- a/Resources/Orthanc/Core/Images/PngReader.h
+++ b/Resources/Orthanc/Core/Images/PngReader.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/PngWriter.cpp b/Resources/Orthanc/Core/Images/PngWriter.cpp
index 5603bcf..bf04e9a 100644
--- a/Resources/Orthanc/Core/Images/PngWriter.cpp
+++ b/Resources/Orthanc/Core/Images/PngWriter.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Images/PngWriter.h b/Resources/Orthanc/Core/Images/PngWriter.h
index 7d8b87f..691a579 100644
--- a/Resources/Orthanc/Core/Images/PngWriter.h
+++ b/Resources/Orthanc/Core/Images/PngWriter.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Logging.cpp b/Resources/Orthanc/Core/Logging.cpp
index cffdb5b..b2b9ad0 100644
--- a/Resources/Orthanc/Core/Logging.cpp
+++ b/Resources/Orthanc/Core/Logging.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -73,7 +74,74 @@ namespace Orthanc
   }
 }
 
-#else
+
+#elif ORTHANC_ENABLE_LOGGING_PLUGIN == 1
+
+/*********************************************************
+ * Logger compatible with the Orthanc plugin SDK
+ *********************************************************/
+
+#include <boost/lexical_cast.hpp>
+
+namespace Orthanc
+{
+  namespace Logging
+  {
+    static OrthancPluginContext* context_ = NULL;
+
+    void Initialize(OrthancPluginContext* context)
+    {
+      context_ = context_;
+    }
+
+    InternalLogger::InternalLogger(const char* level,
+                                   const char* file  /* ignored */,
+                                   int line  /* ignored */) :
+      level_(level)
+    {
+    }
+
+    InternalLogger::~InternalLogger()
+    {
+      if (context_ != NULL)
+      {
+        if (level_ == "ERROR")
+        {
+          OrthancPluginLogError(context_, message_.c_str());
+        }
+        else if (level_ == "WARNING")
+        {
+          OrthancPluginLogWarning(context_, message_.c_str());
+        }
+        else if (level_ == "INFO")
+        {
+          OrthancPluginLogInfo(context_, message_.c_str());
+        }
+      }
+    }
+
+    InternalLogger& InternalLogger::operator<< (const std::string& message)
+    {
+      message_ += message;
+      return *this;
+    }
+
+    InternalLogger& InternalLogger::operator<< (const char* message)
+    {
+      message_ += std::string(message);
+      return *this;
+    }
+
+    InternalLogger& InternalLogger::operator<< (int message)
+    {
+      message_ += boost::lexical_cast<std::string>(message);
+      return *this;
+    }
+  }
+}
+
+
+#else  /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && ORTHANC_ENABLE_LOGGING == 1 */
 
 /*********************************************************
  * Internal logger of Orthanc, that mimics some
diff --git a/Resources/Orthanc/Core/Logging.h b/Resources/Orthanc/Core/Logging.h
index abec83f..8c419e2 100644
--- a/Resources/Orthanc/Core/Logging.h
+++ b/Resources/Orthanc/Core/Logging.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -38,11 +39,27 @@
 #  error The macro ORTHANC_ENABLE_LOGGING must be defined
 #endif
 
+#if !defined(ORTHANC_ENABLE_LOGGING_PLUGIN)
+#  if ORTHANC_ENABLE_LOGGING == 1
+#    error The macro ORTHANC_ENABLE_LOGGING_PLUGIN must be defined
+#  else
+#    define ORTHANC_ENABLE_LOGGING_PLUGIN 0
+#  endif
+#endif
+
+#if ORTHANC_ENABLE_LOGGING_PLUGIN == 1
+#  include <orthanc/OrthancCPlugin.h>
+#endif
+
 namespace Orthanc
 {
   namespace Logging
   {
+#if ORTHANC_ENABLE_LOGGING_PLUGIN == 1
+    void Initialize(OrthancPluginContext* context);
+#else
     void Initialize();
+#endif
 
     void Finalize();
 
@@ -86,7 +103,41 @@ namespace Orthanc
 #  define LOG(level)   ::Orthanc::Logging::NullStream()
 #  define VLOG(level)  ::Orthanc::Logging::NullStream()
 
-#else  /* ORTHANC_ENABLE_LOGGING == 1 */
+
+#elif ORTHANC_ENABLE_LOGGING_PLUGIN == 1
+
+#  include <boost/noncopyable.hpp>
+#  define LOG(level)  ::Orthanc::Logging::InternalLogger(#level,  __FILE__, __LINE__)
+#  define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__)
+
+namespace Orthanc
+{
+  namespace Logging
+  {
+    class InternalLogger : public boost::noncopyable
+    {
+    private:
+      std::string level_;
+      std::string message_;
+
+    public:
+      InternalLogger(const char* level,
+                     const char* file,
+                     int line);
+
+      ~InternalLogger();
+      
+      InternalLogger& operator<< (const std::string& message);
+
+      InternalLogger& operator<< (const char* message);
+
+      InternalLogger& operator<< (int message);
+    };
+  }
+}
+
+
+#else  /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && ORTHANC_ENABLE_LOGGING == 1 */
 
 #  include <boost/thread/mutex.hpp>
 #  define LOG(level)  ::Orthanc::Logging::InternalLogger(#level,  __FILE__, __LINE__)
diff --git a/Resources/Orthanc/Core/MultiThreading/BagOfTasks.h b/Resources/Orthanc/Core/MultiThreading/BagOfTasks.h
index 7b992f6..20fc8e1 100644
--- a/Resources/Orthanc/Core/MultiThreading/BagOfTasks.h
+++ b/Resources/Orthanc/Core/MultiThreading/BagOfTasks.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/MultiThreading/BagOfTasksProcessor.cpp b/Resources/Orthanc/Core/MultiThreading/BagOfTasksProcessor.cpp
index c409f1c..28fdd30 100644
--- a/Resources/Orthanc/Core/MultiThreading/BagOfTasksProcessor.cpp
+++ b/Resources/Orthanc/Core/MultiThreading/BagOfTasksProcessor.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/MultiThreading/BagOfTasksProcessor.h b/Resources/Orthanc/Core/MultiThreading/BagOfTasksProcessor.h
index 525756e..dc7c2ca 100644
--- a/Resources/Orthanc/Core/MultiThreading/BagOfTasksProcessor.h
+++ b/Resources/Orthanc/Core/MultiThreading/BagOfTasksProcessor.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -64,10 +65,10 @@ namespace Orthanc
       {
       }
 
-      Bag(size_t size) : 
-      size_(size),
-      done_(0),
-      status_(BagStatus_Running)
+      explicit Bag(size_t size) : 
+        size_(size),
+        done_(0),
+        status_(BagStatus_Running)
       {
       }
     };
@@ -140,7 +141,7 @@ namespace Orthanc
     };
   
 
-    BagOfTasksProcessor(size_t countThreads);
+    explicit BagOfTasksProcessor(size_t countThreads);
 
     ~BagOfTasksProcessor();
 
diff --git a/Resources/Orthanc/Core/MultiThreading/Semaphore.cpp b/Resources/Orthanc/Core/MultiThreading/Semaphore.cpp
index 82d5aa5..7d1b0de 100644
--- a/Resources/Orthanc/Core/MultiThreading/Semaphore.cpp
+++ b/Resources/Orthanc/Core/MultiThreading/Semaphore.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/MultiThreading/Semaphore.h b/Resources/Orthanc/Core/MultiThreading/Semaphore.h
index 9d5354c..86cf3c3 100644
--- a/Resources/Orthanc/Core/MultiThreading/Semaphore.h
+++ b/Resources/Orthanc/Core/MultiThreading/Semaphore.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -57,7 +58,7 @@ namespace Orthanc
       Semaphore&  that_;
 
     public:
-      Locker(Semaphore& that) :
+      explicit Locker(Semaphore& that) :
         that_(that)
       {
         that_.Acquire();
diff --git a/Resources/Orthanc/Core/MultiThreading/SharedMessageQueue.cpp b/Resources/Orthanc/Core/MultiThreading/SharedMessageQueue.cpp
index 0c1a727..9920593 100644
--- a/Resources/Orthanc/Core/MultiThreading/SharedMessageQueue.cpp
+++ b/Resources/Orthanc/Core/MultiThreading/SharedMessageQueue.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/MultiThreading/SharedMessageQueue.h b/Resources/Orthanc/Core/MultiThreading/SharedMessageQueue.h
index 211b774..b5bb062 100644
--- a/Resources/Orthanc/Core/MultiThreading/SharedMessageQueue.h
+++ b/Resources/Orthanc/Core/MultiThreading/SharedMessageQueue.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/OrthancException.h b/Resources/Orthanc/Core/OrthancException.h
index 5afa41f..ee9b603 100644
--- a/Resources/Orthanc/Core/OrthancException.h
+++ b/Resources/Orthanc/Core/OrthancException.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -45,7 +46,7 @@ namespace Orthanc
     HttpStatus httpStatus_;
 
   public:
-    OrthancException(ErrorCode errorCode) : 
+    explicit OrthancException(ErrorCode errorCode) : 
       errorCode_(errorCode),
       httpStatus_(ConvertErrorCodeToHttpStatus(errorCode))
     {
diff --git a/Resources/Orthanc/Core/PrecompiledHeaders.cpp b/Resources/Orthanc/Core/PrecompiledHeaders.cpp
index 01ea20f..a18e764 100644
--- a/Resources/Orthanc/Core/PrecompiledHeaders.cpp
+++ b/Resources/Orthanc/Core/PrecompiledHeaders.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/PrecompiledHeaders.h b/Resources/Orthanc/Core/PrecompiledHeaders.h
index 1422e30..4fc6435 100644
--- a/Resources/Orthanc/Core/PrecompiledHeaders.h
+++ b/Resources/Orthanc/Core/PrecompiledHeaders.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/SystemToolbox.cpp b/Resources/Orthanc/Core/SystemToolbox.cpp
index e22a006..3e4e36d 100644
--- a/Resources/Orthanc/Core/SystemToolbox.cpp
+++ b/Resources/Orthanc/Core/SystemToolbox.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -123,7 +124,7 @@ namespace Orthanc
     barrierEvent_ = ServerBarrierEvent_Stop;
     while (!(*stopFlag || finish_))
     {
-      Toolbox::USleep(100 * 1000);
+      SystemToolbox::USleep(100 * 1000);
     }
 
 #if defined(_WIN32)
@@ -152,6 +153,18 @@ namespace Orthanc
   }
 
 
+  void SystemToolbox::USleep(uint64_t microSeconds)
+  {
+#if defined(_WIN32)
+    ::Sleep(static_cast<DWORD>(microSeconds / static_cast<uint64_t>(1000)));
+#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__native_client__)
+    usleep(microSeconds);
+#else
+#error Support your platform here
+#endif
+  }
+
+
   static std::streamsize GetStreamSize(std::istream& f)
   {
     // http://www.cplusplus.com/reference/iostream/istream/tellg/
diff --git a/Resources/Orthanc/Core/SystemToolbox.h b/Resources/Orthanc/Core/SystemToolbox.h
index e62b529..0b3fe3f 100644
--- a/Resources/Orthanc/Core/SystemToolbox.h
+++ b/Resources/Orthanc/Core/SystemToolbox.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -50,6 +51,8 @@ namespace Orthanc
 {
   namespace SystemToolbox
   {
+    void USleep(uint64_t microSeconds);
+
     ServerBarrierEvent ServerBarrier(const bool& stopFlag);
 
     ServerBarrierEvent ServerBarrier();
diff --git a/Resources/Orthanc/Core/TemporaryFile.cpp b/Resources/Orthanc/Core/TemporaryFile.cpp
index 955489b..63f7134 100644
--- a/Resources/Orthanc/Core/TemporaryFile.cpp
+++ b/Resources/Orthanc/Core/TemporaryFile.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/TemporaryFile.h b/Resources/Orthanc/Core/TemporaryFile.h
index 1dd4f73..0482589 100644
--- a/Resources/Orthanc/Core/TemporaryFile.h
+++ b/Resources/Orthanc/Core/TemporaryFile.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Core/Toolbox.cpp b/Resources/Orthanc/Core/Toolbox.cpp
index cb9bcb2..4a67878 100644
--- a/Resources/Orthanc/Core/Toolbox.cpp
+++ b/Resources/Orthanc/Core/Toolbox.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -90,18 +91,6 @@ extern "C"
 
 namespace Orthanc
 {
-  void Toolbox::USleep(uint64_t microSeconds)
-  {
-#if defined(_WIN32)
-    ::Sleep(static_cast<DWORD>(microSeconds / static_cast<uint64_t>(1000)));
-#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__native_client__)
-    usleep(microSeconds);
-#else
-#error Support your platform here
-#endif
-  }
-
-
   void Toolbox::ToUpperCase(std::string& s)
   {
     std::transform(s.begin(), s.end(), s.begin(), toupper);
diff --git a/Resources/Orthanc/Core/Toolbox.h b/Resources/Orthanc/Core/Toolbox.h
index d32777a..d79907b 100644
--- a/Resources/Orthanc/Core/Toolbox.h
+++ b/Resources/Orthanc/Core/Toolbox.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -78,8 +79,6 @@ namespace Orthanc
 
   namespace Toolbox
   {
-    void USleep(uint64_t microSeconds);
-
     void ToUpperCase(std::string& s);  // Inplace version
 
     void ToLowerCase(std::string& s);  // Inplace version
diff --git a/Resources/Orthanc/Core/WebServiceParameters.cpp b/Resources/Orthanc/Core/WebServiceParameters.cpp
index cef2e26..2d44a85 100644
--- a/Resources/Orthanc/Core/WebServiceParameters.cpp
+++ b/Resources/Orthanc/Core/WebServiceParameters.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -34,7 +35,6 @@
 #include "WebServiceParameters.h"
 
 #include "../Core/Logging.h"
-#include "../Core/Toolbox.h"
 #include "../Core/OrthancException.h"
 
 #if ORTHANC_SANDBOXED == 0
diff --git a/Resources/Orthanc/Core/WebServiceParameters.h b/Resources/Orthanc/Core/WebServiceParameters.h
index b6b373f..5249f85 100644
--- a/Resources/Orthanc/Core/WebServiceParameters.h
+++ b/Resources/Orthanc/Core/WebServiceParameters.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/OrthancServer/FromDcmtkBridge.cpp b/Resources/Orthanc/OrthancServer/FromDcmtkBridge.cpp
index 243dcc0..532d850 100644
--- a/Resources/Orthanc/OrthancServer/FromDcmtkBridge.cpp
+++ b/Resources/Orthanc/OrthancServer/FromDcmtkBridge.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -1646,7 +1647,9 @@ namespace Orthanc
 
     if (!ok)
     {
-      throw OrthancException(ErrorCode_InternalError);
+      LOG(ERROR) << "While creating a DICOM instance, tag (" << tag.Format()
+                 << ") has out-of-range value: \"" << *decoded << "\"";
+      throw OrthancException(ErrorCode_BadFileFormat);
     }
   }
 
@@ -1665,6 +1668,11 @@ namespace Orthanc
         FillElementWithString(*element, tag, value.asString(), decodeDataUriScheme, dicomEncoding);
         break;
 
+      case Json::nullValue:
+        element.reset(CreateElementForTag(tag));
+        FillElementWithString(*element, tag, "", decodeDataUriScheme, dicomEncoding);
+        break;
+
       case Json::arrayValue:
       {
         DcmTag key(tag.GetGroup(), tag.GetElement());
@@ -1742,11 +1750,17 @@ namespace Orthanc
       {
         const Json::Value& value = json[tags[i]];
         if (value.type() != Json::stringValue ||
-            !GetDicomEncoding(encoding, value.asCString()))
+            (value.asString().length() != 0 &&
+             !GetDicomEncoding(encoding, value.asCString())))
         {
           LOG(ERROR) << "Unknown encoding while creating DICOM from JSON: " << value;
           throw OrthancException(ErrorCode_BadRequest);
         }
+
+        if (value.asString().length() == 0)
+        {
+          return defaultEncoding;
+        }
       }
     }
 
@@ -1897,4 +1911,108 @@ namespace Orthanc
       target.SetValue(ParseTag(members[i]), value.asString(), false);
     }
   }
+
+
+  void FromDcmtkBridge::ChangeStringEncoding(DcmItem& dataset,
+                                             Encoding source,
+                                             Encoding target)
+  {
+    // Recursive exploration of a dataset to change the encoding of
+    // each string-like element
+
+    if (source == target)
+    {
+      return;
+    }
+
+    for (unsigned long i = 0; i < dataset.card(); i++)
+    {
+      DcmElement* element = dataset.getElement(i);
+      if (element)
+      {
+        if (element->isLeaf())
+        {
+          char *c = NULL;
+          if (element->isaString() &&
+              element->getString(c).good() && 
+              c != NULL)
+          {
+            std::string a = Toolbox::ConvertToUtf8(c, source);
+            std::string b = Toolbox::ConvertFromUtf8(a, target);
+            element->putString(b.c_str());
+          }
+        }
+        else
+        {
+          // "All subclasses of DcmElement except for DcmSequenceOfItems
+          // are leaf nodes, while DcmSequenceOfItems, DcmItem, DcmDataset
+          // etc. are not." The following dynamic_cast is thus OK.
+          DcmSequenceOfItems& sequence = dynamic_cast<DcmSequenceOfItems&>(*element);
+
+          for (unsigned long j = 0; j < sequence.card(); j++)
+          {
+            ChangeStringEncoding(*sequence.getItem(j), source, target);
+          }
+        }
+      }
+    }
+  }
+
+
+  bool FromDcmtkBridge::LookupTransferSyntax(std::string& result,
+                                             DcmFileFormat& dicom)
+  {
+    const char* value = NULL;
+
+    if (dicom.getMetaInfo() != NULL &&
+        dicom.getMetaInfo()->findAndGetString(DCM_TransferSyntaxUID, value).good() &&
+        value != NULL)
+    {
+      result.assign(value);
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+  }
+
+
+#if ORTHANC_ENABLE_LUA == 1
+  void FromDcmtkBridge::ExecuteToDicom(DicomMap& target,
+                                       LuaFunctionCall& call)
+  {
+    Json::Value output;
+    call.ExecuteToJson(output, true /* keep strings */);
+
+    target.Clear();
+
+    if (output.type() == Json::arrayValue &&
+        output.size() == 0)
+    {
+      // This case happens for empty tables
+      return;
+    }
+
+    if (output.type() != Json::objectValue)
+    {
+      LOG(ERROR) << "Lua: IncomingFindRequestFilter must return a table";
+      throw OrthancException(ErrorCode_LuaBadOutput);
+    }
+
+    Json::Value::Members members = output.getMemberNames();
+
+    for (size_t i = 0; i < members.size(); i++)
+    {
+      if (output[members[i]].type() != Json::stringValue)
+      {
+        LOG(ERROR) << "Lua: IncomingFindRequestFilter must return a table mapping names of DICOM tags to strings";
+        throw OrthancException(ErrorCode_LuaBadOutput);
+      }
+
+      DicomTag tag(ParseTag(members[i]));
+      target.SetValue(tag, output[members[i]].asString(), false);
+    }
+  }
+#endif
 }
diff --git a/Resources/Orthanc/OrthancServer/FromDcmtkBridge.h b/Resources/Orthanc/OrthancServer/FromDcmtkBridge.h
index 398f061..9a05d5f 100644
--- a/Resources/Orthanc/OrthancServer/FromDcmtkBridge.h
+++ b/Resources/Orthanc/OrthancServer/FromDcmtkBridge.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -43,10 +44,22 @@
 #include <dcmtk/dcmdata/dcfilefo.h>
 #include <json/json.h>
 
+#if !defined(ORTHANC_BUILD_UNIT_TESTS)
+#  error The macro ORTHANC_BUILD_UNIT_TESTS must be defined
+#endif
+
+#if !defined(ORTHANC_ENABLE_LUA)
+#  error The macro ORTHANC_ENABLE_LUA must be defined
+#endif
+
 #if ORTHANC_BUILD_UNIT_TESTS == 1
 #  include <gtest/gtest_prod.h>
 #endif
 
+#if ORTHANC_ENABLE_LUA == 1
+#  include "../Core/Lua/LuaFunctionCall.h"
+#endif
+
 
 namespace Orthanc
 {
@@ -88,6 +101,10 @@ namespace Orthanc
                                    unsigned int maxStringLength,
                                    Encoding defaultEncoding);
 
+    static void ChangeStringEncoding(DcmItem& dataset,
+                                     Encoding source,
+                                     Encoding target);
+
   public:
     static void InitializeDictionary(bool loadPrivateDictionary);
 
@@ -195,5 +212,13 @@ namespace Orthanc
 
     static void FromJson(DicomMap& values,
                          const Json::Value& result);
+
+    static bool LookupTransferSyntax(std::string& result,
+                                     DcmFileFormat& dicom);
+
+#if ORTHANC_ENABLE_LUA == 1
+    static void ExecuteToDicom(DicomMap& target,
+                               LuaFunctionCall& call);
+#endif
   };
 }
diff --git a/Resources/Orthanc/OrthancServer/PrecompiledHeadersServer.h b/Resources/Orthanc/OrthancServer/PrecompiledHeadersServer.h
index 49e8719..84f7329 100644
--- a/Resources/Orthanc/OrthancServer/PrecompiledHeadersServer.h
+++ b/Resources/Orthanc/OrthancServer/PrecompiledHeadersServer.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/OrthancServer/ServerEnumerations.cpp b/Resources/Orthanc/OrthancServer/ServerEnumerations.cpp
index 8e3fdf3..e614e48 100644
--- a/Resources/Orthanc/OrthancServer/ServerEnumerations.cpp
+++ b/Resources/Orthanc/OrthancServer/ServerEnumerations.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -64,6 +65,8 @@ namespace Orthanc
     dictMetadataType_.Add(MetadataType_AnonymizedFrom, "AnonymizedFrom");
     dictMetadataType_.Add(MetadataType_LastUpdate, "LastUpdate");
     dictMetadataType_.Add(MetadataType_Instance_Origin, "Origin");
+    dictMetadataType_.Add(MetadataType_Instance_TransferSyntax, "TransferSyntax");
+    dictMetadataType_.Add(MetadataType_Instance_SopClassUid, "SopClassUid");
 
     dictContentType_.Add(FileContentType_Dicom, "dicom");
     dictContentType_.Add(FileContentType_DicomAsJson, "dicom-as-json");
diff --git a/Resources/Orthanc/OrthancServer/ServerEnumerations.h b/Resources/Orthanc/OrthancServer/ServerEnumerations.h
index 8765680..9ec65b2 100644
--- a/Resources/Orthanc/OrthancServer/ServerEnumerations.h
+++ b/Resources/Orthanc/OrthancServer/ServerEnumerations.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -157,7 +158,9 @@ namespace Orthanc
     MetadataType_ModifiedFrom = 5,
     MetadataType_AnonymizedFrom = 6,
     MetadataType_LastUpdate = 7,
-    MetadataType_Instance_Origin = 8,   // New in Orthanc 0.9.5
+    MetadataType_Instance_Origin = 8,          // New in Orthanc 0.9.5
+    MetadataType_Instance_TransferSyntax = 9,  // New in Orthanc 1.2.0
+    MetadataType_Instance_SopClassUid = 10,    // New in Orthanc 1.2.0
 
     // Make sure that the value "65535" can be stored into this enumeration
     MetadataType_StartUser = 1024,
diff --git a/Resources/Orthanc/OrthancServer/ToDcmtkBridge.cpp b/Resources/Orthanc/OrthancServer/ToDcmtkBridge.cpp
index 708293a..e848262 100644
--- a/Resources/Orthanc/OrthancServer/ToDcmtkBridge.cpp
+++ b/Resources/Orthanc/OrthancServer/ToDcmtkBridge.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -41,24 +42,6 @@
 
 namespace Orthanc
 {
-  DcmDataset* ToDcmtkBridge::Convert(const DicomMap& map)
-  {
-    std::auto_ptr<DcmDataset> result(new DcmDataset);
-
-    for (DicomMap::Map::const_iterator 
-           it = map.map_.begin(); it != map.map_.end(); ++it)
-    {
-      if (!it->second->IsNull())
-      {
-        std::string s = it->second->GetContent();
-        DU_putStringDOElement(result.get(), Convert(it->first), s.c_str());
-      }
-    }
-
-    return result.release();
-  }
-
-
   DcmEVR ToDcmtkBridge::Convert(ValueRepresentation vr)
   {
     switch (vr)
diff --git a/Resources/Orthanc/OrthancServer/ToDcmtkBridge.h b/Resources/Orthanc/OrthancServer/ToDcmtkBridge.h
index fff8bd4..551640f 100644
--- a/Resources/Orthanc/OrthancServer/ToDcmtkBridge.h
+++ b/Resources/Orthanc/OrthancServer/ToDcmtkBridge.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -45,8 +46,6 @@ namespace Orthanc
       return DcmTagKey(tag.GetGroup(), tag.GetElement());
     }
 
-    static DcmDataset* Convert(const DicomMap& map);
-
     static DcmEVR Convert(ValueRepresentation vr);
   };
 }
diff --git a/Resources/Orthanc/Plugins/Engine/SharedLibrary.cpp b/Resources/Orthanc/Plugins/Engine/SharedLibrary.cpp
index 1adc878..97e231d 100644
--- a/Resources/Orthanc/Plugins/Engine/SharedLibrary.cpp
+++ b/Resources/Orthanc/Plugins/Engine/SharedLibrary.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Plugins/Engine/SharedLibrary.h b/Resources/Orthanc/Plugins/Engine/SharedLibrary.h
index 2bf9a69..b5fc419 100644
--- a/Resources/Orthanc/Plugins/Engine/SharedLibrary.h
+++ b/Resources/Orthanc/Plugins/Engine/SharedLibrary.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -60,7 +61,7 @@ namespace Orthanc
     FunctionPointer GetFunctionInternal(const std::string& name);
 
   public:
-    SharedLibrary(const std::string& path);
+    explicit SharedLibrary(const std::string& path);
 
     ~SharedLibrary();
 
diff --git a/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.cpp b/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.cpp
index b354bb1..6cd8dca 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.cpp
+++ b/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -32,7 +33,7 @@
 
 #include "DicomDatasetReader.h"
 
-#include "OrthancPluginCppWrapper.h"
+#include "OrthancPluginException.h"
 
 #include <boost/lexical_cast.hpp>
 
@@ -68,55 +69,105 @@ namespace OrthancPlugins
   }
 
 
-  DicomDatasetReader::DicomDatasetReader(IDicomDataset* dataset) :  // takes ownership
+  DicomDatasetReader::DicomDatasetReader(const IDicomDataset& dataset) :
     dataset_(dataset)
   {
-    if (dataset == NULL)
+  }
+  
+
+  std::string DicomDatasetReader::GetStringValue(const DicomPath& path,
+                                                 const std::string& defaultValue) const
+  {
+    std::string s;
+    if (dataset_.GetStringValue(s, path))
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_ParameterOutOfRange);
+      return s;
+    }
+    else
+    {
+      return defaultValue;
     }
   }
-  
+
 
   std::string DicomDatasetReader::GetMandatoryStringValue(const DicomPath& path) const
   {
     std::string s;
-    if (dataset_->GetStringValue(s, path))
+    if (dataset_.GetStringValue(s, path))
     {
       return s;
     }
     else
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_InexistentTag);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(InexistentTag);
     }
   }
 
 
-  int DicomDatasetReader::GetIntegerValue(const DicomPath& path)
+  template <typename T>
+  static bool GetValueInternal(T& target,
+                               const IDicomDataset& dataset,
+                               const DicomPath& path)
   {
     try
     {
-      std::string s = StripSpaces(GetMandatoryStringValue(path));
-      return boost::lexical_cast<int>(s);
+      std::string s;
+
+      if (dataset.GetStringValue(s, path))
+      {
+        target = boost::lexical_cast<T>(StripSpaces(s));
+        return true;
+      }
+      else
+      {
+        return false;
+      }
     }
     catch (boost::bad_lexical_cast&)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);        
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);        
     }
   }
 
 
-  unsigned int DicomDatasetReader::GetUnsignedIntegerValue(const DicomPath& path)
+  bool DicomDatasetReader::GetIntegerValue(int& target,
+                                           const DicomPath& path) const
   {
-    int value = GetIntegerValue(path);
+    return GetValueInternal<int>(target, dataset_, path);
+  }
+
 
-    if (value >= 0)
+  bool DicomDatasetReader::GetUnsignedIntegerValue(unsigned int& target,
+                                                   const DicomPath& path) const
+  {
+    int value;
+
+    if (!GetIntegerValue(value, path))
+    {
+      return false;
+    }
+    else if (value >= 0)
     {
-      return static_cast<unsigned int>(value);
+      target = static_cast<unsigned int>(value);
+      return true;
     }
     else
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_ParameterOutOfRange);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
   }
+
+
+  bool DicomDatasetReader::GetFloatValue(float& target,
+                                         const DicomPath& path) const
+  {
+    return GetValueInternal<float>(target, dataset_, path);
+  }
+
+
+  bool DicomDatasetReader::GetDoubleValue(double& target,
+                                          const DicomPath& path) const
+  {
+    return GetValueInternal<double>(target, dataset_, path);
+  }
 }
diff --git a/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.h b/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.h
index 0074071..ea60a2a 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.h
+++ b/Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -35,26 +36,38 @@
 #include "IDicomDataset.h"
 
 #include <memory>
+#include <vector>
 
 namespace OrthancPlugins
 {
   class DicomDatasetReader : public boost::noncopyable
   {
   private:
-    std::auto_ptr<IDicomDataset>  dataset_;
+    const IDicomDataset&  dataset_;
 
   public:
-    DicomDatasetReader(IDicomDataset* dataset);  // takes ownership
+    DicomDatasetReader(const IDicomDataset& dataset);
 
-    IDicomDataset& GetDataset() const
+    const IDicomDataset& GetDataset() const
     {
-      return *dataset_;
+      return dataset_;
     }
 
+    std::string GetStringValue(const DicomPath& path,
+                               const std::string& defaultValue) const;
+
     std::string GetMandatoryStringValue(const DicomPath& path) const;
 
-    int GetIntegerValue(const DicomPath& path);
+    bool GetIntegerValue(int& target,
+                         const DicomPath& path) const;
+
+    bool GetUnsignedIntegerValue(unsigned int& target,
+                                 const DicomPath& path) const;
+
+    bool GetFloatValue(float& target,
+                       const DicomPath& path) const;
 
-    unsigned int GetUnsignedIntegerValue(const DicomPath& path);
+    bool GetDoubleValue(double& target,
+                        const DicomPath& path) const;
   };
 }
diff --git a/Resources/Orthanc/Plugins/Samples/Common/DicomPath.cpp b/Resources/Orthanc/Plugins/Samples/Common/DicomPath.cpp
index 3437e60..f0e6c2e 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/DicomPath.cpp
+++ b/Resources/Orthanc/Plugins/Samples/Common/DicomPath.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -32,7 +33,7 @@
 
 #include "DicomPath.h"
 
-#include "OrthancPluginCppWrapper.h"
+#include "OrthancPluginException.h"
 
 namespace OrthancPlugins
 {
@@ -40,7 +41,7 @@ namespace OrthancPlugins
   {
     if (depth >= prefix_.size())
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_ParameterOutOfRange);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
     else
     {
diff --git a/Resources/Orthanc/Plugins/Samples/Common/DicomPath.h b/Resources/Orthanc/Plugins/Samples/Common/DicomPath.h
index f14f051..1ce79ae 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/DicomPath.h
+++ b/Resources/Orthanc/Plugins/Samples/Common/DicomPath.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Plugins/Samples/Common/DicomTag.cpp b/Resources/Orthanc/Plugins/Samples/Common/DicomTag.cpp
index 040d885..2ca18b8 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/DicomTag.cpp
+++ b/Resources/Orthanc/Plugins/Samples/Common/DicomTag.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -32,7 +33,7 @@
 
 #include "DicomTag.h"
 
-#include "OrthancPluginCppWrapper.h"
+#include "OrthancPluginException.h"
 
 namespace OrthancPlugins
 {
@@ -104,7 +105,7 @@ namespace OrthancPlugins
     }
     else
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_NotImplemented);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(NotImplemented);
     }
   }
 }
diff --git a/Resources/Orthanc/Plugins/Samples/Common/DicomTag.h b/Resources/Orthanc/Plugins/Samples/Common/DicomTag.h
index 660d078..51e5901 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/DicomTag.h
+++ b/Resources/Orthanc/Plugins/Samples/Common/DicomTag.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -77,19 +78,27 @@ namespace OrthancPlugins
 
 
   static const DicomTag DICOM_TAG_BITS_STORED(0x0028, 0x0101);
-  static const DicomTag DICOM_TAG_COLUMN_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX(0x0048, 0x021e);
   static const DicomTag DICOM_TAG_COLUMNS(0x0028, 0x0011);
+  static const DicomTag DICOM_TAG_COLUMN_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX(0x0048, 0x021e);
+  static const DicomTag DICOM_TAG_IMAGE_ORIENTATION_PATIENT(0x0020, 0x0037);
+  static const DicomTag DICOM_TAG_IMAGE_POSITION_PATIENT(0x0020, 0x0032);
   static const DicomTag DICOM_TAG_MODALITY(0x0008, 0x0060);
   static const DicomTag DICOM_TAG_NUMBER_OF_FRAMES(0x0028, 0x0008);
   static const DicomTag DICOM_TAG_PER_FRAME_FUNCTIONAL_GROUPS_SEQUENCE(0x5200, 0x9230);
   static const DicomTag DICOM_TAG_PHOTOMETRIC_INTERPRETATION(0x0028, 0x0004);
   static const DicomTag DICOM_TAG_PIXEL_REPRESENTATION(0x0028, 0x0103);
+  static const DicomTag DICOM_TAG_PIXEL_SPACING(0x0028, 0x0030);
   static const DicomTag DICOM_TAG_PLANE_POSITION_SLIDE_SEQUENCE(0x0048, 0x021a);
-  static const DicomTag DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX(0x0048, 0x021f);
+  static const DicomTag DICOM_TAG_RESCALE_INTERCEPT(0x0028, 0x1052);
+  static const DicomTag DICOM_TAG_RESCALE_SLOPE(0x0028, 0x1053);
   static const DicomTag DICOM_TAG_ROWS(0x0028, 0x0010);
-  static const DicomTag DICOM_TAG_SOP_CLASS_UID(0x0008, 0x0016);
+  static const DicomTag DICOM_TAG_ROW_POSITION_IN_TOTAL_IMAGE_PIXEL_MATRIX(0x0048, 0x021f);
   static const DicomTag DICOM_TAG_SAMPLES_PER_PIXEL(0x0028, 0x0002);
+  static const DicomTag DICOM_TAG_SLICE_THICKNESS(0x0018, 0x0050);
+  static const DicomTag DICOM_TAG_SOP_CLASS_UID(0x0008, 0x0016);
   static const DicomTag DICOM_TAG_TOTAL_PIXEL_MATRIX_COLUMNS(0x0048, 0x0006);
   static const DicomTag DICOM_TAG_TOTAL_PIXEL_MATRIX_ROWS(0x0048, 0x0007);
   static const DicomTag DICOM_TAG_TRANSFER_SYNTAX_UID(0x0002, 0x0010);
+  static const DicomTag DICOM_TAG_WINDOW_CENTER(0x0028, 0x1050);
+  static const DicomTag DICOM_TAG_WINDOW_WIDTH(0x0028, 0x1051);
 }
diff --git a/Resources/Orthanc/Plugins/Samples/Common/FullOrthancDataset.cpp b/Resources/Orthanc/Plugins/Samples/Common/FullOrthancDataset.cpp
index 638654b..1ad400b 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/FullOrthancDataset.cpp
+++ b/Resources/Orthanc/Plugins/Samples/Common/FullOrthancDataset.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -32,7 +33,10 @@
 
 #include "FullOrthancDataset.h"
 
-#include "OrthancPluginCppWrapper.h"
+#include "OrthancPluginException.h"
+
+#include <stdio.h>
+#include <cassert>
 
 namespace OrthancPlugins
 {
@@ -41,7 +45,7 @@ namespace OrthancPlugins
   {
     if (dataset.type() != Json::objectValue)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
 
     char name[16];
@@ -60,7 +64,7 @@ namespace OrthancPlugins
         value["Name"].type() != Json::stringValue ||
         value["Type"].type() != Json::stringValue)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
 
     return &value;
@@ -78,7 +82,7 @@ namespace OrthancPlugins
     if (sequence["Type"].asString() != "Sequence" ||
         value.type() != Json::arrayValue)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
     else
     {
@@ -99,7 +103,7 @@ namespace OrthancPlugins
     if (tag["Type"].asString() != "String" ||
         value.type() != Json::stringValue)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
     else
     {
@@ -142,7 +146,7 @@ namespace OrthancPlugins
   {
     if (root_.type() != Json::objectValue)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
   }
 
diff --git a/Resources/Orthanc/Plugins/Samples/Common/FullOrthancDataset.h b/Resources/Orthanc/Plugins/Samples/Common/FullOrthancDataset.h
index 18ab444..a6f379e 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/FullOrthancDataset.h
+++ b/Resources/Orthanc/Plugins/Samples/Common/FullOrthancDataset.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Plugins/Samples/Common/IDicomDataset.h b/Resources/Orthanc/Plugins/Samples/Common/IDicomDataset.h
index 7fc549e..4d439a1 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/IDicomDataset.h
+++ b/Resources/Orthanc/Plugins/Samples/Common/IDicomDataset.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Plugins/Samples/Common/IOrthancConnection.cpp b/Resources/Orthanc/Plugins/Samples/Common/IOrthancConnection.cpp
index 5a66912..4cf1ab4 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/IOrthancConnection.cpp
+++ b/Resources/Orthanc/Plugins/Samples/Common/IOrthancConnection.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -32,7 +33,7 @@
 
 #include "IOrthancConnection.h"
 
-#include "OrthancPluginCppWrapper.h"
+#include "OrthancPluginException.h"
 
 #include <json/reader.h>
 
@@ -45,7 +46,7 @@ namespace OrthancPlugins
     
     if (!reader.parse(content, result))
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
   }
 
diff --git a/Resources/Orthanc/Plugins/Samples/Common/IOrthancConnection.h b/Resources/Orthanc/Plugins/Samples/Common/IOrthancConnection.h
index f64dd5a..c8a1385 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/IOrthancConnection.h
+++ b/Resources/Orthanc/Plugins/Samples/Common/IOrthancConnection.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.cpp b/Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.cpp
index a1f9846..7b96a90 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.cpp
+++ b/Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.h b/Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.h
index c1e69bd..29d92ea 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.h
+++ b/Resources/Orthanc/Plugins/Samples/Common/OrthancHttpConnection.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginConnection.cpp b/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginConnection.cpp
index fb82353..e6eb3c2 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginConnection.cpp
+++ b/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginConnection.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -47,7 +48,7 @@ namespace OrthancPlugins
     }
     else
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_UnknownResource);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource);
     }
   }
 
@@ -64,7 +65,7 @@ namespace OrthancPlugins
     }
     else
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_UnknownResource);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource);
     }
   }
 
@@ -81,7 +82,7 @@ namespace OrthancPlugins
     }
     else
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_UnknownResource);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource);
     }
   }
 
@@ -92,7 +93,7 @@ namespace OrthancPlugins
 
     if (!::OrthancPlugins::RestApiDelete(context_, uri, false))
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_UnknownResource);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource);
     }
   }
 }
diff --git a/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginConnection.h b/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginConnection.h
index f4b06ff..50761df 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginConnection.h
+++ b/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginConnection.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp b/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp
index 4b5650e..a92872c 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp
+++ b/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -38,32 +39,6 @@
 
 namespace OrthancPlugins
 {
-  const char* GetErrorDescription(OrthancPluginContext* context,
-                                  OrthancPluginErrorCode code)
-  {
-    const char* description = OrthancPluginGetErrorDescription(context, code);
-    if (description)
-    {
-      return description;
-    }
-    else
-    {
-      return "No description available";
-    }
-  }
-
-  
-#if HAS_ORTHANC_EXCEPTION == 0
-  void PluginException::Check(OrthancPluginErrorCode code)
-  {
-    if (code != OrthancPluginErrorCode_Success)
-    {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(code);
-    }
-  }
-#endif
-
-
   void MemoryBuffer::Check(OrthancPluginErrorCode code)
   {
     if (code != OrthancPluginErrorCode_Success)
@@ -71,7 +46,7 @@ namespace OrthancPlugins
       // Prevent using garbage information
       buffer_.data = NULL;
       buffer_.size = 0;
-      ORTHANC_PLUGINS_THROW_EXCEPTION(code);
+      ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
     }
   }
 
@@ -125,7 +100,7 @@ namespace OrthancPlugins
     if (buffer_.data == NULL ||
         buffer_.size == 0)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_InternalError);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
 
     const char* tmp = reinterpret_cast<const char*>(buffer_.data);
@@ -134,7 +109,7 @@ namespace OrthancPlugins
     if (!reader.parse(tmp, tmp + buffer_.size, target))
     {
       OrthancPluginLogError(context_, "Cannot convert some memory buffer to JSON");
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
   }
 
@@ -166,7 +141,7 @@ namespace OrthancPlugins
     }
     else
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(error);
+      ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
     }
   }
 
@@ -200,7 +175,7 @@ namespace OrthancPlugins
     }
     else
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(error);
+      ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
     }
   }
 
@@ -234,7 +209,7 @@ namespace OrthancPlugins
     }
     else
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(error);
+      ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
     }
   }
 
@@ -276,11 +251,24 @@ namespace OrthancPlugins
   }
 
 
-  OrthancString::OrthancString(OrthancPluginContext* context,
-                               char* str) :
-    context_(context),
-    str_(str)
+  void MemoryBuffer::GetDicomQuery(const OrthancPluginWorklistQuery* query)
+  {
+    Clear();
+    Check(OrthancPluginWorklistGetDicomQuery(context_, &buffer_, query));
+  }
+
+
+  void OrthancString::Assign(char* str)
   {
+    if (str == NULL)
+    {
+      ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
+    }
+    else
+    {
+      Clear();
+      str_ = str;
+    }
   }
 
 
@@ -312,27 +300,40 @@ namespace OrthancPlugins
     if (str_ == NULL)
     {
       OrthancPluginLogError(context_, "Cannot convert an empty memory buffer to JSON");
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_InternalError);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
 
     Json::Reader reader;
     if (!reader.parse(str_, target))
     {
       OrthancPluginLogError(context_, "Cannot convert some memory buffer to JSON");
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
   }
+
+  
+  void MemoryBuffer::DicomToJson(Json::Value& target,
+                                 OrthancPluginDicomToJsonFormat format,
+                                 OrthancPluginDicomToJsonFlags flags,
+                                 uint32_t maxStringLength)
+  {
+    OrthancString str(context_);
+    str.Assign(OrthancPluginDicomBufferToJson(context_, GetData(), GetSize(), format, flags, maxStringLength));
+    str.ToJson(target);
+  }
+
   
 
   OrthancConfiguration::OrthancConfiguration(OrthancPluginContext* context) : 
     context_(context)
   {
-    OrthancString str(context, OrthancPluginGetConfiguration(context));
+    OrthancString str(context);
+    str.Assign(OrthancPluginGetConfiguration(context));
 
     if (str.GetContent() == NULL)
     {
       OrthancPluginLogError(context, "Cannot access the Orthanc configuration");
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_InternalError);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
 
     str.ToJson(configuration_);
@@ -340,7 +341,7 @@ namespace OrthancPlugins
     if (configuration_.type() != Json::objectValue)
     {
       OrthancPluginLogError(context, "Unable to read the Orthanc configuration");
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_InternalError);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
     }
   }
 
@@ -349,7 +350,7 @@ namespace OrthancPlugins
   {
     if (context_ == NULL)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_Plugin);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin);
     }
     else
     {
@@ -402,7 +403,7 @@ namespace OrthancPlugins
           OrthancPluginLogError(context_, s.c_str());
         }
 
-        ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+        ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
       }
 
       target.configuration_ = configuration_[key];
@@ -428,7 +429,7 @@ namespace OrthancPlugins
         OrthancPluginLogError(context_, s.c_str());
       }
 
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
 
     target = configuration_[key].asString();
@@ -463,7 +464,7 @@ namespace OrthancPlugins
           OrthancPluginLogError(context_, s.c_str());
         }
 
-        ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+        ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
   }
 
@@ -485,7 +486,7 @@ namespace OrthancPlugins
         OrthancPluginLogError(context_, s.c_str());
       }
 
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
     else
     {
@@ -513,7 +514,7 @@ namespace OrthancPlugins
         OrthancPluginLogError(context_, s.c_str());
       }
 
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
 
     target = configuration_[key].asBool();
@@ -552,7 +553,7 @@ namespace OrthancPlugins
           OrthancPluginLogError(context_, s.c_str());
         }
 
-        ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+        ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
   }
 
@@ -647,7 +648,7 @@ namespace OrthancPlugins
     if (image_ == NULL)
     {
       OrthancPluginLogError(context_, "Trying to access a NULL image");
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_ParameterOutOfRange);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
   }
 
@@ -658,7 +659,7 @@ namespace OrthancPlugins
   {
     if (context == NULL)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_ParameterOutOfRange);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
   }
 
@@ -670,7 +671,7 @@ namespace OrthancPlugins
   {
     if (context == NULL)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_ParameterOutOfRange);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
   }
   
@@ -683,7 +684,7 @@ namespace OrthancPlugins
   {
     if (context == NULL)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_ParameterOutOfRange);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
     else
     {
@@ -700,7 +701,7 @@ namespace OrthancPlugins
     if (image_ == NULL)
     {
       OrthancPluginLogError(context_, "Cannot uncompress a PNG image");
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_ParameterOutOfRange);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
   }
 
@@ -713,7 +714,7 @@ namespace OrthancPlugins
     if (image_ == NULL)
     {
       OrthancPluginLogError(context_, "Cannot uncompress a JPEG image");
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_ParameterOutOfRange);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
   }
 
@@ -727,7 +728,7 @@ namespace OrthancPlugins
     if (image_ == NULL)
     {
       OrthancPluginLogError(context_, "Cannot uncompress a DICOM image");
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_ParameterOutOfRange);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
     }
   }
 
@@ -809,6 +810,83 @@ namespace OrthancPlugins
   }
 
 
+
+#if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1
+  FindMatcher::FindMatcher(OrthancPluginContext*              context,
+                           const OrthancPluginWorklistQuery*  worklist) :
+    context_(context),
+    matcher_(NULL),
+    worklist_(worklist)
+  {
+    if (worklist_ == NULL)
+    {
+      ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange);
+    }
+  }
+
+
+  void FindMatcher::SetupDicom(OrthancPluginContext*  context,
+                               const void*            query,
+                               uint32_t               size)
+  {
+    context_ = context;
+    worklist_ = NULL;
+
+    matcher_ = OrthancPluginCreateFindMatcher(context_, query, size);
+    if (matcher_ == NULL)
+    {
+      ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
+    }
+  }
+
+
+  FindMatcher::~FindMatcher()
+  {
+    // The "worklist_" field 
+
+    if (matcher_ != NULL)
+    {
+      OrthancPluginFreeFindMatcher(context_, matcher_);
+    }
+  }
+
+
+
+  bool FindMatcher::IsMatch(const void*  dicom,
+                            uint32_t     size) const
+  {
+    int32_t result;
+
+    if (matcher_ != NULL)
+    {
+      result = OrthancPluginFindMatcherIsMatch(context_, matcher_, dicom, size);
+    }
+    else if (worklist_ != NULL)
+    {
+      result = OrthancPluginWorklistIsMatch(context_, worklist_, dicom, size);
+    }
+    else
+    {
+      ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
+    }
+
+    if (result == 0)
+    {
+      return false;
+    }
+    else if (result == 1)
+    {
+      return true;
+    }
+    else
+    {
+      ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
+    }
+  }
+
+#endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */
+
+
   bool RestApiGet(Json::Value& result,
                   OrthancPluginContext* context,
                   const std::string& uri,
@@ -915,7 +993,7 @@ namespace OrthancPlugins
     }
     else
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(error);
+      ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error);
     }
   }
 
diff --git a/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.h b/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.h
index 8f0bb7a..7738ffd 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.h
+++ b/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -32,21 +33,21 @@
 
 #pragma once
 
+#include "OrthancPluginException.h"
+
 #include <orthanc/OrthancCPlugin.h>
 #include <boost/noncopyable.hpp>
 #include <boost/lexical_cast.hpp>
 #include <json/value.h>
 
-#if !defined(HAS_ORTHANC_EXCEPTION)
-#  error The macro HAS_ORTHANC_EXCEPTION must be defined
-#endif
-
 
-#if HAS_ORTHANC_EXCEPTION == 1
-#  include "../../../Core/OrthancException.h"
-#  define ORTHANC_PLUGINS_THROW_EXCEPTION(code)  throw ::Orthanc::OrthancException(static_cast<Orthanc::ErrorCode>(code))
+#if (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER >= 2 ||   \
+     (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == 1 &&  \
+      ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER >= 2))
+// The "OrthancPluginFindMatcher()" primitive was introduced in Orthanc 1.2.0
+#  define HAS_ORTHANC_PLUGIN_FIND_MATCHER  1
 #else
-#  define ORTHANC_PLUGINS_THROW_EXCEPTION(code)  throw ::OrthancPlugins::PluginException(code)
+#  define HAS_ORTHANC_PLUGIN_FIND_MATCHER  0
 #endif
 
 
@@ -57,35 +58,6 @@ namespace OrthancPlugins
                                 const char* url,
                                 const OrthancPluginHttpRequest* request);
 
-  const char* GetErrorDescription(OrthancPluginContext* context,
-                                  OrthancPluginErrorCode code);
-
-#if HAS_ORTHANC_EXCEPTION == 0
-  class PluginException
-  {
-  private:
-    OrthancPluginErrorCode  code_;
-
-  public:
-    PluginException(OrthancPluginErrorCode code) : code_(code)
-    {
-    }
-
-    OrthancPluginErrorCode GetErrorCode() const
-    {
-      return code_;
-    }
-
-    const char* What(OrthancPluginContext* context) const
-    {
-      return ::OrthancPlugins::GetErrorDescription(context, code_);
-    }
-
-    static void Check(OrthancPluginErrorCode code);
-  };
-#endif
-
-
   class MemoryBuffer : public boost::noncopyable
   {
   private:
@@ -172,6 +144,13 @@ namespace OrthancPlugins
                      OrthancPluginCreateDicomFlags flags);
 
     void ReadFile(const std::string& path);
+
+    void GetDicomQuery(const OrthancPluginWorklistQuery* query);
+
+    void DicomToJson(Json::Value& target,
+                     OrthancPluginDicomToJsonFormat format,
+                     OrthancPluginDicomToJsonFlags flags,
+                     uint32_t maxStringLength);
   };
 
 
@@ -181,16 +160,23 @@ namespace OrthancPlugins
     OrthancPluginContext*  context_;
     char*                  str_;
 
+    void Clear();
+
   public:
-    OrthancString(OrthancPluginContext* context,
-                  char* str);
+    OrthancString(OrthancPluginContext* context) :
+      context_(context),
+      str_(NULL)
+    {
+    }
 
     ~OrthancString()
     {
       Clear();
     }
 
-    void Clear();
+    // This transfers ownership, warning: The string must have been
+    // allocated by the Orthanc core
+    void Assign(char* str);
 
     const char* GetContent() const
     {
@@ -262,7 +248,7 @@ namespace OrthancPlugins
                         float defaultValue) const;
   };
 
-  class OrthancImage
+  class OrthancImage : public boost::noncopyable
   {
   private:
     OrthancPluginContext*  context_;
@@ -320,6 +306,48 @@ namespace OrthancPlugins
   };
 
 
+#if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1
+  class FindMatcher : public boost::noncopyable
+  {
+  private:
+    OrthancPluginContext*              context_;
+    OrthancPluginFindMatcher*          matcher_;
+    const OrthancPluginWorklistQuery*  worklist_;
+
+    void SetupDicom(OrthancPluginContext*  context,
+                    const void*            query,
+                    uint32_t               size);
+
+  public:
+    FindMatcher(OrthancPluginContext*              context,
+                const OrthancPluginWorklistQuery*  worklist);
+
+    FindMatcher(OrthancPluginContext*  context,
+                const void*            query,
+                uint32_t               size)
+    {
+      SetupDicom(context, query, size);
+    }
+
+    FindMatcher(OrthancPluginContext*  context,
+                const MemoryBuffer&    dicom)
+    {
+      SetupDicom(context, dicom.GetData(), dicom.GetSize());
+    }
+
+    ~FindMatcher();
+
+    bool IsMatch(const void*  dicom,
+                 uint32_t     size) const;
+
+    bool IsMatch(const MemoryBuffer& dicom) const
+    {
+      return IsMatch(dicom.GetData(), dicom.GetSize());
+    }
+  };
+#endif
+
+
   bool RestApiGet(Json::Value& result,
                   OrthancPluginContext* context,
                   const std::string& uri,
@@ -420,17 +448,10 @@ namespace OrthancPlugins
         Callback(output, url, request);
         return OrthancPluginErrorCode_Success;
       }
-#if HAS_ORTHANC_EXCEPTION == 1
-      catch (Orthanc::OrthancException& e)
+      catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
       {
         return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
       }
-#else
-      catch (OrthancPlugins::PluginException& e)
-      {
-        return e.GetErrorCode();
-      }
-#endif
       catch (boost::bad_lexical_cast&)
       {
         return OrthancPluginErrorCode_BadFileFormat;
diff --git a/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginException.h b/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginException.h
new file mode 100644
index 0000000..e549a26
--- /dev/null
+++ b/Resources/Orthanc/Plugins/Samples/Common/OrthancPluginException.h
@@ -0,0 +1,101 @@
+/**
+ * Orthanc - A Lightweight, RESTful DICOM Store
+ * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
+ * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * In addition, as a special exception, the copyright holders of this
+ * program give permission to link the code of its release with the
+ * OpenSSL project's "OpenSSL" library (or with modified versions of it
+ * that use the same license as the "OpenSSL" library), and distribute
+ * the linked executables. You must obey the GNU General Public License
+ * in all respects for all of the code used other than "OpenSSL". If you
+ * modify file(s) with this exception, you may extend this exception to
+ * your version of the file(s), but you are not obligated to do so. If
+ * you do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source files
+ * in the program, then also delete it here.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#pragma once
+
+#if !defined(HAS_ORTHANC_EXCEPTION)
+#  error The macro HAS_ORTHANC_EXCEPTION must be defined
+#endif
+
+
+#if HAS_ORTHANC_EXCEPTION == 1
+#  include "../../../Core/OrthancException.h"
+#  define ORTHANC_PLUGINS_ERROR_ENUMERATION     ::Orthanc::ErrorCode
+#  define ORTHANC_PLUGINS_EXCEPTION_CLASS       ::Orthanc::OrthancException
+#  define ORTHANC_PLUGINS_GET_ERROR_CODE(code)  ::Orthanc::ErrorCode_ ## code
+#else
+#  include <orthanc/OrthancCPlugin.h>
+#  define ORTHANC_PLUGINS_ERROR_ENUMERATION     ::OrthancPluginErrorCode
+#  define ORTHANC_PLUGINS_EXCEPTION_CLASS       ::OrthancPlugins::PluginException
+#  define ORTHANC_PLUGINS_GET_ERROR_CODE(code)  ::OrthancPluginErrorCode_ ## code
+#endif
+
+
+#define ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code)                   \
+  throw ORTHANC_PLUGINS_EXCEPTION_CLASS(static_cast<ORTHANC_PLUGINS_ERROR_ENUMERATION>(code));
+
+
+#define ORTHANC_PLUGINS_THROW_EXCEPTION(code)                           \
+  throw ORTHANC_PLUGINS_EXCEPTION_CLASS(ORTHANC_PLUGINS_GET_ERROR_CODE(code));
+                                                  
+
+#define ORTHANC_PLUGINS_CHECK_ERROR(code)                           \
+  if (code != ORTHANC_PLUGINS_GET_ERROR_CODE(Success))              \
+  {                                                                 \
+    ORTHANC_PLUGINS_THROW_EXCEPTION(code);                          \
+  }
+
+
+namespace OrthancPlugins
+{
+#if HAS_ORTHANC_EXCEPTION == 0
+  class PluginException
+  {
+  private:
+    OrthancPluginErrorCode  code_;
+
+  public:
+    explicit PluginException(OrthancPluginErrorCode code) : code_(code)
+    {
+    }
+
+    OrthancPluginErrorCode GetErrorCode() const
+    {
+      return code_;
+    }
+
+    const char* What(OrthancPluginContext* context) const
+    {
+      const char* description = OrthancPluginGetErrorDescription(context, code_);
+      if (description)
+      {
+        return description;
+      }
+      else
+      {
+        return "No description available";
+      }
+    }
+  };
+#endif
+}
diff --git a/Resources/Orthanc/Plugins/Samples/Common/SimplifiedOrthancDataset.cpp b/Resources/Orthanc/Plugins/Samples/Common/SimplifiedOrthancDataset.cpp
index 1fa2bea..d7c79ee 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/SimplifiedOrthancDataset.cpp
+++ b/Resources/Orthanc/Plugins/Samples/Common/SimplifiedOrthancDataset.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -32,7 +33,7 @@
 
 #include "SimplifiedOrthancDataset.h"
 
-#include "OrthancPluginCppWrapper.h"
+#include "OrthancPluginException.h"
 
 namespace OrthancPlugins
 {
@@ -45,7 +46,7 @@ namespace OrthancPlugins
       const char* name = path.GetPrefixTag(depth).GetName();
       if (content->type() != Json::objectValue)
       {
-        ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+        ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
       }
 
       if (!content->isMember(name))
@@ -56,7 +57,7 @@ namespace OrthancPlugins
       const Json::Value& sequence = (*content) [name];
       if (sequence.type() != Json::arrayValue)
       {
-        ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+        ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
       }
 
       size_t index = path.GetPrefixIndex(depth);
@@ -74,7 +75,7 @@ namespace OrthancPlugins
 
     if (content->type() != Json::objectValue)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
     if (!content->isMember(name))
     {
@@ -91,7 +92,7 @@ namespace OrthancPlugins
   {
     if (root_.type() != Json::objectValue)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
   }
 
@@ -122,7 +123,7 @@ namespace OrthancPlugins
     }
     else if (value->type() != Json::stringValue)
     {
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
     else
     {
@@ -145,7 +146,7 @@ namespace OrthancPlugins
     else if (sequence->type() != Json::arrayValue)
     {
       // Not a sequence
-      ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
+      ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
     }
     else
     {
diff --git a/Resources/Orthanc/Plugins/Samples/Common/SimplifiedOrthancDataset.h b/Resources/Orthanc/Plugins/Samples/Common/SimplifiedOrthancDataset.h
index a71e1e0..a757e66 100644
--- a/Resources/Orthanc/Plugins/Samples/Common/SimplifiedOrthancDataset.h
+++ b/Resources/Orthanc/Plugins/Samples/Common/SimplifiedOrthancDataset.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Resources/CMake/BoostConfiguration.cmake b/Resources/Orthanc/Resources/CMake/BoostConfiguration.cmake
index 3596427..f7c9287 100644
--- a/Resources/Orthanc/Resources/CMake/BoostConfiguration.cmake
+++ b/Resources/Orthanc/Resources/CMake/BoostConfiguration.cmake
@@ -43,7 +43,7 @@ if (BOOST_STATIC)
   set(BOOST_NAME boost_1_60_0)
   set(BOOST_BCP_SUFFIX bcpdigest-1.0.1)
   set(BOOST_MD5 "a789f8ec2056ad1c2d5f0cb64687cc7b")
-  set(BOOST_URL "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/${BOOST_NAME}_${BOOST_BCP_SUFFIX}.tar.gz")
+  set(BOOST_URL "http://www.orthanc-server.com/downloads/third-party/${BOOST_NAME}_${BOOST_BCP_SUFFIX}.tar.gz")
   set(BOOST_FILESYSTEM_SOURCES_DIR "${BOOST_NAME}/libs/filesystem/src") 
   set(BOOST_SOURCES_DIR ${CMAKE_BINARY_DIR}/${BOOST_NAME})
 
@@ -99,6 +99,13 @@ if (BOOST_STATIC)
       -DBOOST_LOCALE_NO_POSIX_BACKEND=1
       -DBOOST_LOCALE_NO_STD_BACKEND=1
       )
+
+  elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
+    add_definitions(
+      -DBOOST_LOCALE_NO_POSIX_BACKEND=1
+      -DBOOST_LOCALE_NO_STD_BACKEND=1
+      )
+
   else()
     message(FATAL_ERROR "Support your platform here")
   endif()
@@ -114,10 +121,15 @@ if (BOOST_STATIC)
   list(APPEND BOOST_SOURCES
     ${BOOST_REGEX_SOURCES}
     ${BOOST_SOURCES_DIR}/libs/date_time/src/gregorian/greg_month.cpp
-    ${BOOST_SOURCES_DIR}/libs/locale/src/encoding/codepage.cpp
     ${BOOST_SOURCES_DIR}/libs/system/src/error_code.cpp
     )
 
+  if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
+    list(APPEND BOOST_SOURCES
+      ${BOOST_SOURCES_DIR}/libs/locale/src/encoding/codepage.cpp
+      )
+  endif()
+
   if (${CMAKE_SYSTEM_NAME} STREQUAL "PNaCl" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "NaCl32" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "NaCl64")
diff --git a/Resources/Orthanc/Resources/CMake/DcmtkConfiguration.cmake b/Resources/Orthanc/Resources/CMake/DcmtkConfiguration.cmake
index 96d07cb..8534a93 100644
--- a/Resources/Orthanc/Resources/CMake/DcmtkConfiguration.cmake
+++ b/Resources/Orthanc/Resources/CMake/DcmtkConfiguration.cmake
@@ -7,7 +7,7 @@ if (STATIC_BUILD OR NOT USE_SYSTEM_DCMTK)
     SET(DCMTK_VERSION_NUMBER 361)
     SET(DCMTK_PACKAGE_VERSION "3.6.1")
     SET(DCMTK_SOURCES_DIR ${CMAKE_BINARY_DIR}/dcmtk-3.6.1_20160216)
-    SET(DCMTK_URL "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/dcmtk-3.6.1_20160216.tar.gz")
+    SET(DCMTK_URL "http://www.orthanc-server.com/downloads/third-party/dcmtk-3.6.1_20160216.tar.gz")
     SET(DCMTK_MD5 "273c8a544b9fe09b8a4fb4eb51df8e52")
     SET(DCMTK_PATCH_SPEED "${ORTHANC_ROOT}/Resources/Patches/dcmtk-3.6.1-speed.patch")
 
@@ -21,7 +21,7 @@ if (STATIC_BUILD OR NOT USE_SYSTEM_DCMTK)
     SET(DCMTK_VERSION_NUMBER 360)
     SET(DCMTK_PACKAGE_VERSION "3.6.0")
     SET(DCMTK_SOURCES_DIR ${CMAKE_BINARY_DIR}/dcmtk-3.6.0)
-    SET(DCMTK_URL "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/dcmtk-3.6.0.zip")
+    SET(DCMTK_URL "http://www.orthanc-server.com/downloads/third-party/dcmtk-3.6.0.zip")
     SET(DCMTK_MD5 "219ad631b82031806147e4abbfba4fa4")
     SET(DCMTK_PATCH_SPEED "${ORTHANC_ROOT}/Resources/Patches/dcmtk-3.6.0-speed.patch")
     SET(DCMTK_PATCH_MINGW64 "${ORTHANC_ROOT}/Resources/Patches/dcmtk-3.6.0-mingw64.patch")
@@ -50,6 +50,17 @@ if (STATIC_BUILD OR NOT USE_SYSTEM_DCMTK)
     else()
       message("Using the dictionary of private tags from DCMTK 3.6.0")
     endif()
+
+    # Patches specific to DCMTK 3.6.0
+    execute_process(
+      COMMAND ${PATCH_EXECUTABLE} -p0 -N -i ${ORTHANC_ROOT}/Resources/Patches/dcmtk-3.6.0-dulparse-vulnerability.patch
+      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+      RESULT_VARIABLE Failure
+      )
+
+    if (Failure)
+      message(FATAL_ERROR "Error while patching a file")
+    endif()
   endif()
 
 
diff --git a/Resources/Orthanc/Resources/CMake/JsonCppConfiguration.cmake b/Resources/Orthanc/Resources/CMake/JsonCppConfiguration.cmake
index bad61b8..1532a81 100644
--- a/Resources/Orthanc/Resources/CMake/JsonCppConfiguration.cmake
+++ b/Resources/Orthanc/Resources/CMake/JsonCppConfiguration.cmake
@@ -1,6 +1,6 @@
 if (STATIC_BUILD OR NOT USE_SYSTEM_JSONCPP)
   set(JSONCPP_SOURCES_DIR ${CMAKE_BINARY_DIR}/jsoncpp-0.10.5)
-  set(JSONCPP_URL "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/jsoncpp-0.10.5.tar.gz")
+  set(JSONCPP_URL "http://www.orthanc-server.com/downloads/third-party/jsoncpp-0.10.5.tar.gz")
   set(JSONCPP_MD5 "db146bac5a126ded9bd728ab7b61ed6b")
 
   DownloadPackage(${JSONCPP_MD5} ${JSONCPP_URL} "${JSONCPP_SOURCES_DIR}")
diff --git a/Resources/Orthanc/Resources/CMake/LibCurlConfiguration.cmake b/Resources/Orthanc/Resources/CMake/LibCurlConfiguration.cmake
index 1e164c9..390a1a7 100644
--- a/Resources/Orthanc/Resources/CMake/LibCurlConfiguration.cmake
+++ b/Resources/Orthanc/Resources/CMake/LibCurlConfiguration.cmake
@@ -1,6 +1,6 @@
 if (STATIC_BUILD OR NOT USE_SYSTEM_CURL)
   SET(CURL_SOURCES_DIR ${CMAKE_BINARY_DIR}/curl-7.50.3)
-  SET(CURL_URL "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/curl-7.50.3.tar.gz")
+  SET(CURL_URL "http://www.orthanc-server.com/downloads/third-party/curl-7.50.3.tar.gz")
   SET(CURL_MD5 "870e16fd88a88b52e26a4f04dfc161db")
 
   DownloadPackage(${CURL_MD5} ${CURL_URL} "${CURL_SOURCES_DIR}")
diff --git a/Resources/Orthanc/Resources/CMake/LibJpegConfiguration.cmake b/Resources/Orthanc/Resources/CMake/LibJpegConfiguration.cmake
index 22f8919..dcc4149 100644
--- a/Resources/Orthanc/Resources/CMake/LibJpegConfiguration.cmake
+++ b/Resources/Orthanc/Resources/CMake/LibJpegConfiguration.cmake
@@ -2,7 +2,7 @@ if (STATIC_BUILD OR NOT USE_SYSTEM_LIBJPEG)
   set(LIBJPEG_SOURCES_DIR ${CMAKE_BINARY_DIR}/jpeg-9a)
   DownloadPackage(
     "3353992aecaee1805ef4109aadd433e7"
-    "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/jpegsrc.v9a.tar.gz"
+    "http://www.orthanc-server.com/downloads/third-party/jpegsrc.v9a.tar.gz"
     "${LIBJPEG_SOURCES_DIR}")
 
   include_directories(
diff --git a/Resources/Orthanc/Resources/CMake/LibPngConfiguration.cmake b/Resources/Orthanc/Resources/CMake/LibPngConfiguration.cmake
index df09dd6..bf9820c 100644
--- a/Resources/Orthanc/Resources/CMake/LibPngConfiguration.cmake
+++ b/Resources/Orthanc/Resources/CMake/LibPngConfiguration.cmake
@@ -1,6 +1,6 @@
 if (STATIC_BUILD OR NOT USE_SYSTEM_LIBPNG)
   SET(LIBPNG_SOURCES_DIR ${CMAKE_BINARY_DIR}/libpng-1.5.12)
-  SET(LIBPNG_URL "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/libpng-1.5.12.tar.gz")
+  SET(LIBPNG_URL "http://www.orthanc-server.com/downloads/third-party/libpng-1.5.12.tar.gz")
   SET(LIBPNG_MD5 "8ea7f60347a306c5faf70b977fa80e28")
 
   DownloadPackage(${LIBPNG_MD5} ${LIBPNG_URL} "${LIBPNG_SOURCES_DIR}")
diff --git a/Resources/Orthanc/Resources/CMake/OpenSslConfiguration.cmake b/Resources/Orthanc/Resources/CMake/OpenSslConfiguration.cmake
index 43432b6..5652e59 100644
--- a/Resources/Orthanc/Resources/CMake/OpenSslConfiguration.cmake
+++ b/Resources/Orthanc/Resources/CMake/OpenSslConfiguration.cmake
@@ -4,7 +4,7 @@ if (STATIC_BUILD OR NOT USE_SYSTEM_OPENSSL)
   # not always properly handled when uncompressing on Windows.
 
   SET(OPENSSL_SOURCES_DIR ${CMAKE_BINARY_DIR}/openssl-1.0.2d)
-  SET(OPENSSL_URL "www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/openssl-1.0.2d.zip")
+  SET(OPENSSL_URL "http://www.orthanc-server.com/downloads/third-party/openssl-1.0.2d.zip")
   SET(OPENSSL_MD5 "4b2ac15fc6db17f3dadc54482d3eee85")
 
   if (IS_DIRECTORY "${OPENSSL_SOURCES_DIR}")
diff --git a/Resources/Orthanc/Resources/CMake/ZlibConfiguration.cmake b/Resources/Orthanc/Resources/CMake/ZlibConfiguration.cmake
index 29ae103..4487c1e 100644
--- a/Resources/Orthanc/Resources/CMake/ZlibConfiguration.cmake
+++ b/Resources/Orthanc/Resources/CMake/ZlibConfiguration.cmake
@@ -1,6 +1,6 @@
 if (STATIC_BUILD OR NOT USE_SYSTEM_ZLIB)
   SET(ZLIB_SOURCES_DIR ${CMAKE_BINARY_DIR}/zlib-1.2.7)
-  SET(ZLIB_URL "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/zlib-1.2.7.tar.gz")
+  SET(ZLIB_URL "http://www.orthanc-server.com/downloads/third-party/zlib-1.2.7.tar.gz")
   SET(ZLIB_MD5 "60df6a37c56e7c1366cca812414f7b85")
 
   DownloadPackage(${ZLIB_MD5} ${ZLIB_URL} "${ZLIB_SOURCES_DIR}")
diff --git a/Resources/Orthanc/Resources/EmbedResources.py b/Resources/Orthanc/Resources/EmbedResources.py
index ad5cf61..a528468 100755
--- a/Resources/Orthanc/Resources/EmbedResources.py
+++ b/Resources/Orthanc/Resources/EmbedResources.py
@@ -3,6 +3,7 @@
 # Orthanc - A Lightweight, RESTful DICOM Store
 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
 # Department, University Hospital of Liege, Belgium
+# Copyright (C) 2017 Osimis, Belgium
 #
 # This program is free software: you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
diff --git a/Resources/Orthanc/Resources/Patches/dcmtk-3.6.0-dulparse-vulnerability.patch b/Resources/Orthanc/Resources/Patches/dcmtk-3.6.0-dulparse-vulnerability.patch
new file mode 100644
index 0000000..321f810
--- /dev/null
+++ b/Resources/Orthanc/Resources/Patches/dcmtk-3.6.0-dulparse-vulnerability.patch
@@ -0,0 +1,29 @@
+diff -urEb dcmtk-3.6.0.orig/dcmnet/libsrc/dulparse.cc dcmtk-3.6.0/dcmnet/libsrc/dulparse.cc
+--- dcmtk-3.6.0.orig/dcmnet/libsrc/dulparse.cc	2010-12-01 09:26:36.000000000 +0100
++++ dcmtk-3.6.0/dcmnet/libsrc/dulparse.cc	2016-12-02 15:58:49.930540033 +0100
+@@ -393,6 +393,8 @@
+                     return cond;
+ 
+                 buf += length;
++                if (presentationLength < length)
++                  return EC_MemoryExhausted;
+                 presentationLength -= length;
+                 DCMNET_TRACE("Successfully parsed Abstract Syntax");
+                 break;
+@@ -404,12 +406,16 @@
+                 cond = LST_Enqueue(&context->transferSyntaxList, (LST_NODE*)subItem);
+                 if (cond.bad()) return cond;
+                 buf += length;
++                if (presentationLength < length)
++                  return EC_MemoryExhausted;
+                 presentationLength -= length;
+                 DCMNET_TRACE("Successfully parsed Transfer Syntax");
+                 break;
+             default:
+                 cond = parseDummy(buf, &length, presentationLength);
+                 buf += length;
++                if (presentationLength < length)
++                  return EC_MemoryExhausted;
+                 presentationLength -= length;
+                 break;
+             }
diff --git a/Resources/Orthanc/Resources/WindowsResources.py b/Resources/Orthanc/Resources/WindowsResources.py
index c56733b..b59e77a 100755
--- a/Resources/Orthanc/Resources/WindowsResources.py
+++ b/Resources/Orthanc/Resources/WindowsResources.py
@@ -3,6 +3,7 @@
 # Orthanc - A Lightweight, RESTful DICOM Store
 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
 # Department, University Hospital of Liege, Belgium
+# Copyright (C) 2017 Osimis, Belgium
 #
 # This program is free software: you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
diff --git a/Resources/OrthancWSIClearCache.py b/Resources/OrthancWSIClearCache.py
index b7e3591..f55f93d 100755
--- a/Resources/OrthancWSIClearCache.py
+++ b/Resources/OrthancWSIClearCache.py
@@ -3,6 +3,7 @@
 # Orthanc - A Lightweight, RESTful DICOM Store
 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
 # Department, University Hospital of Liege, Belgium
+# Copyright (C) 2017 Osimis, Belgium
 #
 # This program is free software: you can redistribute it and/or
 # modify it under the terms of the GNU Affero General Public License
diff --git a/Resources/SyncOrthancFolder.py b/Resources/SyncOrthancFolder.py
index 528206e..c4afb49 100755
--- a/Resources/SyncOrthancFolder.py
+++ b/Resources/SyncOrthancFolder.py
@@ -87,6 +87,7 @@ FILES = [
     'Plugins/Samples/Common/ExportedSymbols.list',
     'Plugins/Samples/Common/OrthancPluginCppWrapper.cpp',
     'Plugins/Samples/Common/OrthancPluginCppWrapper.h',
+    'Plugins/Samples/Common/OrthancPluginException.h',
     'Plugins/Samples/Common/VersionScript.map',
     'Plugins/Samples/Common/DicomDatasetReader.cpp',
     'Plugins/Samples/Common/DicomDatasetReader.h',
@@ -121,6 +122,7 @@ FILES = [
     'Resources/MinGW-W64-Toolchain32.cmake',
     'Resources/MinGW-W64-Toolchain64.cmake',
     'Resources/MinGWToolchain.cmake',
+    'Resources/Patches/dcmtk-3.6.0-dulparse-vulnerability.patch',
     'Resources/Patches/dcmtk-3.6.0-mingw64.patch',
     'Resources/Patches/dcmtk-3.6.0-speed.patch',
     'Resources/Patches/dcmtk-3.6.1-speed.patch',
diff --git a/TODO b/TODO
index c4af315..fefc1dd 100644
--- a/TODO
+++ b/TODO
@@ -6,6 +6,7 @@ Orthanc for Whole-Slide Imaging
 General
 -------
 
+* Command-line tool to extract a subregion of a WSI as a PNG/JPEG image
 * Thoroughly test sparse tiling (both in encoder and decoder)
 * Display physical scale in Web viewer
 * Viewer: Configure how missing tiles are displayed for sparse tiling
@@ -16,6 +17,7 @@ Performance
 -----------
 
 * Check out rapidjson: https://github.com/miloyip/nativejson-benchmark
+* Optimize ImageToolbox::Set() and ImageToolbox::Halve()
 
 
 -------------
@@ -30,4 +32,3 @@ Documentation
 Packaging
 ---------
 
-* Debian: Rename "Framework/Orthanc/" as "Resources/Orthanc/" in "debian/copyright"
diff --git a/ViewerPlugin/CMakeLists.txt b/ViewerPlugin/CMakeLists.txt
index 6f8ce3f..2b0a7c0 100644
--- a/ViewerPlugin/CMakeLists.txt
+++ b/ViewerPlugin/CMakeLists.txt
@@ -61,7 +61,8 @@ add_definitions(
   -DORTHANC_ENABLE_BASE64=0
   -DORTHANC_ENABLE_CURL=0
   -DORTHANC_ENABLE_DCMTK=0
-  -DORTHANC_ENABLE_LOGGING=0
+  -DORTHANC_ENABLE_LOGGING=1
+  -DORTHANC_ENABLE_LOGGING_PLUGIN=1
   -DORTHANC_ENABLE_MD5=0
   -DORTHANC_ENABLE_PUGIXML=0
   -DORTHANC_SANDBOXED=0
@@ -121,7 +122,7 @@ endif()
 if (STATIC_BUILD OR NOT USE_SYSTEM_OPENLAYERS)
   DownloadPackage(
     "77e57aad873c2d4deea8bb1446e9b87a"
-    "http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/WSI/openlayers-3.19.0-dist.zip"
+    "http://www.orthanc-server.com/downloads/third-party/WSI/openlayers-3.19.0-dist.zip"
     "v3.19.0-dist")
   
   set(OPENLAYERS_RESOURCES
diff --git a/ViewerPlugin/DicomPyramidCache.cpp b/ViewerPlugin/DicomPyramidCache.cpp
index 16509f4..dc785dd 100644
--- a/ViewerPlugin/DicomPyramidCache.cpp
+++ b/ViewerPlugin/DicomPyramidCache.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/ViewerPlugin/DicomPyramidCache.h b/ViewerPlugin/DicomPyramidCache.h
index 0c0fbaa..8426b55 100644
--- a/ViewerPlugin/DicomPyramidCache.h
+++ b/ViewerPlugin/DicomPyramidCache.h
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/ViewerPlugin/Plugin.cpp b/ViewerPlugin/Plugin.cpp
index 3eed2a9..9c1d7c6 100644
--- a/ViewerPlugin/Plugin.cpp
+++ b/ViewerPlugin/Plugin.cpp
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License
diff --git a/ViewerPlugin/viewer.js b/ViewerPlugin/viewer.js
index 99787b8..fdcac4d 100644
--- a/ViewerPlugin/viewer.js
+++ b/ViewerPlugin/viewer.js
@@ -2,6 +2,7 @@
  * Orthanc - A Lightweight, RESTful DICOM Store
  * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
  * Department, University Hospital of Liege, Belgium
+ * Copyright (C) 2017 Osimis, Belgium
  *
  * This program is free software: you can redistribute it and/or
  * modify it under the terms of the GNU Affero General Public License

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



More information about the debian-med-commit mailing list