changeset 1086:e56c3ed8d738

Parameter to set the default encoding for DICOM files without SpecificCharacterSet
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Aug 2014 17:57:45 +0200
parents b161593551db
children e07b90fb00eb
files Core/Enumerations.cpp Core/Enumerations.h NEWS OrthancServer/FromDcmtkBridge.cpp Resources/Configuration.json UnitTestsSources/UnitTestsMain.cpp
diffstat 6 files changed, 70 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Enumerations.cpp	Mon Aug 04 12:16:50 2014 +0200
+++ b/Core/Enumerations.cpp	Mon Aug 04 17:57:45 2014 +0200
@@ -261,6 +261,47 @@
   }
 
 
+  const char* EnumerationToString(Encoding encoding)
+  {
+    switch (encoding)
+    {
+      case Encoding_Utf8:
+        return "Utf8";
+
+      case Encoding_Latin1:
+        return "Latin1";
+
+      case Encoding_Ascii:
+        return "Ascii";
+
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+  }
+
+
+  Encoding StringToEncoding(const char* encoding)
+  {
+    std::string s(encoding);
+    Toolbox::ToUpperCase(s);
+
+    if (s == "UTF8")
+    {
+      return Encoding_Utf8;
+    }
+    else if (s == "LATIN1")
+    {
+      return Encoding_Latin1;
+    }
+    else if (s == "ASCII")
+    {
+      return Encoding_Ascii;
+    }
+
+    throw OrthancException(ErrorCode_ParameterOutOfRange);
+  }
+
+
   ResourceType StringToResourceType(const char* type)
   {
     std::string s(type);
--- a/Core/Enumerations.h	Mon Aug 04 12:16:50 2014 +0200
+++ b/Core/Enumerations.h	Mon Aug 04 17:57:45 2014 +0200
@@ -277,6 +277,10 @@
 
   const char* EnumerationToString(ImageFormat format);
 
+  const char* EnumerationToString(Encoding encoding);
+
+  Encoding StringToEncoding(const char* encoding);
+
   ResourceType StringToResourceType(const char* type);
 
   ImageFormat StringToImageFormat(const char* format);
--- a/NEWS	Mon Aug 04 12:16:50 2014 +0200
+++ b/NEWS	Mon Aug 04 17:57:45 2014 +0200
@@ -1,7 +1,7 @@
 Pending changes in the mainline
 ===============================
 
-
+* Parameter to set the default encoding for DICOM files without SpecificCharacterSet
 
 
 Version 0.8.1 (2014/07/29)
--- a/OrthancServer/FromDcmtkBridge.cpp	Mon Aug 04 12:16:50 2014 +0200
+++ b/OrthancServer/FromDcmtkBridge.cpp	Mon Aug 04 17:57:45 2014 +0200
@@ -41,6 +41,7 @@
 
 #include "FromDcmtkBridge.h"
 #include "ToDcmtkBridge.h"
+#include "OrthancInitialization.h"
 #include "../Core/Toolbox.h"
 #include "../Core/OrthancException.h"
 #include "../Core/ImageFormats/PngWriter.h"
@@ -119,8 +120,9 @@
 
   Encoding FromDcmtkBridge::DetectEncoding(DcmDataset& dataset)
   {
-    // By default, assume UTF-8 encoding (as in dcm2xml.cc)
-    Encoding encoding = Encoding_Utf8;
+    // By default, Ascii encoding is assumed (this removes all the special charaters)
+    std::string s = Configuration::GetGlobalStringParameter("DefaultEncoding", "");
+    Encoding encoding = s.empty() ? Encoding_Ascii : StringToEncoding(s.c_str());
 
     OFString tmp;
     if (dataset.findAndGetOFString(DCM_SpecificCharacterSet, tmp).good())
--- a/Resources/Configuration.json	Mon Aug 04 12:16:50 2014 +0200
+++ b/Resources/Configuration.json	Mon Aug 04 17:57:45 2014 +0200
@@ -180,5 +180,10 @@
   // The maximum number of active jobs in the Orthanc scheduler. When
   // this limit is reached, the addition of new jobs is blocked until
   // some job finishes.
-  "LimitJobs" : 10
+  "LimitJobs" : 10,
+
+  // The default encoding that is assumed for DICOM files without
+  // "SpecificCharacterSet" DICOM tag. The allowed values are
+  // currently "Latin1", "Utf8" and "Ascii".
+  "DefaultEncoding" : "Latin1"
 }
--- a/UnitTestsSources/UnitTestsMain.cpp	Mon Aug 04 12:16:50 2014 +0200
+++ b/UnitTestsSources/UnitTestsMain.cpp	Mon Aug 04 17:57:45 2014 +0200
@@ -639,6 +639,20 @@
   ASSERT_EQ("", t[3]);
 }
 
+TEST(Toolbox, Enumerations)
+{
+  ASSERT_EQ(Encoding_Utf8, StringToEncoding(EnumerationToString(Encoding_Utf8)));
+  ASSERT_EQ(Encoding_Ascii, StringToEncoding(EnumerationToString(Encoding_Ascii)));
+  ASSERT_EQ(Encoding_Latin1, StringToEncoding(EnumerationToString(Encoding_Latin1)));
+
+  ASSERT_EQ(ResourceType_Patient, StringToResourceType(EnumerationToString(ResourceType_Patient)));
+  ASSERT_EQ(ResourceType_Study, StringToResourceType(EnumerationToString(ResourceType_Study)));
+  ASSERT_EQ(ResourceType_Series, StringToResourceType(EnumerationToString(ResourceType_Series)));
+  ASSERT_EQ(ResourceType_Instance, StringToResourceType(EnumerationToString(ResourceType_Instance)));
+
+  ASSERT_EQ(ImageFormat_Png, StringToImageFormat(EnumerationToString(ImageFormat_Png)));
+}
+
 
 
 #if defined(__linux)