changeset 1558:124de28b32ed

fix encodings of newly created dicom files
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 20 Aug 2015 17:40:07 +0200
parents ad1e127b4ed5
children 1e6fbb2dcc6f
files Core/Toolbox.cpp Core/Toolbox.h OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/ParsedDicomFile.cpp
diffstat 4 files changed, 83 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Toolbox.cpp	Thu Aug 20 17:29:42 2015 +0200
+++ b/Core/Toolbox.cpp	Thu Aug 20 17:40:07 2015 +0200
@@ -1335,5 +1335,56 @@
     return static_cast<int>(getpid());
 #endif
   }
+
+
+  const char* Toolbox::GetDicomSpecificCharacterSet(Encoding encoding)
+  {
+    // http://www.dabsoft.ch/dicom/3/C.12.1.1.2/
+    switch (encoding)
+    {
+      case Encoding_Utf8:
+      case Encoding_Ascii:
+        return "ISO_IR 192";
+
+      case Encoding_Latin1:
+        return "ISO_IR 100";
+
+      case Encoding_Latin2:
+        return "ISO_IR 101";
+
+      case Encoding_Latin3:
+        return "ISO_IR 109";
+
+      case Encoding_Latin4:
+        return "ISO_IR 110";
+
+      case Encoding_Latin5:
+        return "ISO_IR 148";
+
+      case Encoding_Cyrillic:
+        return "ISO_IR 144";
+
+      case Encoding_Arabic:
+        return "ISO_IR 127";
+
+      case Encoding_Greek:
+        return "ISO_IR 126";
+
+      case Encoding_Hebrew:
+        return "ISO_IR 138";
+
+      case Encoding_Japanese:
+        return "ISO_IR 13";
+
+      case Encoding_Chinese:
+        return "GB18030";
+
+      case Encoding_Thai:
+        return "ISO_IR 166";
+
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+  }
 }
 
--- a/Core/Toolbox.h	Thu Aug 20 17:29:42 2015 +0200
+++ b/Core/Toolbox.h	Thu Aug 20 17:40:07 2015 +0200
@@ -178,5 +178,7 @@
                     const std::string& prefix);
 
     int GetProcessId();
+
+    const char* GetDicomSpecificCharacterSet(Encoding encoding);
   }
 }
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Thu Aug 20 17:29:42 2015 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Thu Aug 20 17:40:07 2015 +0200
@@ -477,17 +477,23 @@
       return false;
     }
 
-    std::string tmp;
+    Encoding encoding;
+
     if (request["Tags"].isMember("SpecificCharacterSet"))
     {
-      tmp = request["Tags"]["SpecificCharacterSet"].asString();
+      const char* tmp = request["Tags"]["SpecificCharacterSet"].asCString();
+      if (!GetDicomEncoding(encoding, tmp))
+      {
+        LOG(ERROR) << "Unknown specific character set: " << tmp;
+        return false;
+      }
     }
     else
     {
-      tmp = Configuration::GetGlobalStringParameter("DefaultEncoding", "Latin1");
+      std::string tmp = Configuration::GetGlobalStringParameter("DefaultEncoding", "Latin1");
+      encoding = StringToEncoding(tmp.c_str());
     }
 
-    Encoding encoding = StringToEncoding(tmp.c_str());
     dicom.SetEncoding(encoding);
 
     ResourceType parentType = ResourceType_Instance;
@@ -611,20 +617,23 @@
       std::string value = request["Tags"][name].asString();
 
       DicomTag tag = FromDcmtkBridge::ParseTag(name);
-      if (dicom.HasTag(tag))
+      if (tag != DICOM_TAG_SPECIFIC_CHARACTER_SET)
       {
-        LOG(ERROR) << "Trying to override a value inherited from a parent module";
-        return false;
-      }
+        if (dicom.HasTag(tag))
+        {
+          LOG(ERROR) << "Trying to override a value inherited from a parent module";
+          return false;
+        }
 
-      if (tag == DICOM_TAG_PIXEL_DATA)
-      {
-        LOG(ERROR) << "Use \"Content\" to inject an image into a new DICOM instance";
-        return false;
-      }
-      else
-      {
-        dicom.Replace(tag, Toolbox::ConvertFromUtf8(value, encoding));
+        if (tag == DICOM_TAG_PIXEL_DATA)
+        {
+          LOG(ERROR) << "Use \"Content\" to inject an image into a new DICOM instance";
+          return false;
+        }
+        else
+        {
+          dicom.Replace(tag, Toolbox::ConvertFromUtf8(value, encoding));
+        }
       }
     }
 
--- a/OrthancServer/ParsedDicomFile.cpp	Thu Aug 20 17:29:42 2015 +0200
+++ b/OrthancServer/ParsedDicomFile.cpp	Thu Aug 20 17:40:07 2015 +0200
@@ -1335,73 +1335,14 @@
 
   void ParsedDicomFile::SetEncoding(Encoding encoding)
   {
-    std::string s;
-
-    // http://www.dabsoft.ch/dicom/3/C.12.1.1.2/
-    switch (encoding)
+    if (encoding == Encoding_Windows1251)
     {
-      case Encoding_Utf8:
-      case Encoding_Ascii:
-        s = "ISO_IR 192";
-        break;
-
-      case Encoding_Windows1251:
-        // This Cyrillic codepage is not officially supported by the
-        // DICOM standard. Do not set the SpecificCharacterSet tag.
-        return;
-
-      case Encoding_Latin1:
-        s = "ISO_IR 100";
-        break;
-
-      case Encoding_Latin2:
-        s = "ISO_IR 101";
-        break;
-
-      case Encoding_Latin3:
-        s = "ISO_IR 109";
-        break;
-
-      case Encoding_Latin4:
-        s = "ISO_IR 110";
-        break;
-
-      case Encoding_Latin5:
-        s = "ISO_IR 148";
-        break;
-
-      case Encoding_Cyrillic:
-        s = "ISO_IR 144";
-        break;
-
-      case Encoding_Arabic:
-        s = "ISO_IR 127";
-        break;
-
-      case Encoding_Greek:
-        s = "ISO_IR 126";
-        break;
-
-      case Encoding_Hebrew:
-        s = "ISO_IR 138";
-        break;
-
-      case Encoding_Japanese:
-        s = "ISO_IR 13";
-        break;
-
-      case Encoding_Chinese:
-        s = "GB18030";
-        break;
-
-      case Encoding_Thai:
-        s = "ISO_IR 166";
-        break;
-
-      default:
-        throw OrthancException(ErrorCode_ParameterOutOfRange);
+      // This Cyrillic codepage is not officially supported by the
+      // DICOM standard. Do not set the SpecificCharacterSet tag.
+      return;
     }
 
+    std::string s = Toolbox::GetDicomSpecificCharacterSet(encoding);
     Replace(DICOM_TAG_SPECIFIC_CHARACTER_SET, s, DicomReplaceMode_InsertIfAbsent);
   }