changeset 1562:2084b7c20478

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 21 Aug 2015 13:47:22 +0200
parents 307b9ea6c39b
children 9bb416445319
files OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/ParsedDicomFile.cpp OrthancServer/ParsedDicomFile.h UnitTestsSources/FromDcmtkTests.cpp
diffstat 4 files changed, 22 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Fri Aug 21 11:43:24 2015 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Fri Aug 21 13:47:22 2015 +0200
@@ -453,7 +453,7 @@
       DicomTag tag = FromDcmtkBridge::ParseTag(name);
       if (tag == DICOM_TAG_PIXEL_DATA)
       {
-        dicom.EmbedImage(value);
+        dicom.EmbedContent(value);
       }
       else
       {
@@ -647,26 +647,7 @@
         return false;
       }
 
-      std::string mime, base64;
-      Toolbox::DecodeDataUriScheme(mime, base64, request["Content"].asString());
-      Toolbox::ToLowerCase(mime);
-
-      std::string content;
-      Toolbox::DecodeBase64(content, base64);
-
-      if (mime == "image/png")
-      {
-        dicom.EmbedImage(mime, content);
-      }
-      else if (mime == "application/pdf")
-      {
-        dicom.EmbedPdf(content);
-      }
-      else
-      {
-        LOG(ERROR) << "Unsupported MIME type for the content of a new DICOM file";
-        return false;
-      }
+      dicom.EmbedContent(request["Content"].asString());
     }
 
 
--- a/OrthancServer/ParsedDicomFile.cpp	Fri Aug 21 11:43:24 2015 +0200
+++ b/OrthancServer/ParsedDicomFile.cpp	Fri Aug 21 13:47:22 2015 +0200
@@ -1134,15 +1134,28 @@
   }
 
 
-  void ParsedDicomFile::EmbedImage(const std::string& dataUriScheme)
+  void ParsedDicomFile::EmbedContent(const std::string& dataUriScheme)
   {
     std::string mime, base64;
     Toolbox::DecodeDataUriScheme(mime, base64, dataUriScheme);
+    Toolbox::ToLowerCase(mime);
 
     std::string content;
     Toolbox::DecodeBase64(content, base64);
 
-    EmbedImage(mime, content);
+    if (mime == "image/png")
+    {
+      EmbedImage(mime, content);
+    }
+    else if (mime == "application/pdf")
+    {
+      EmbedPdf(content);
+    }
+    else
+    {
+      LOG(ERROR) << "Unsupported MIME type for the content of a new DICOM file";
+      throw OrthancException(ErrorCode_NotImplemented);
+    }
   }
 
 
--- a/OrthancServer/ParsedDicomFile.h	Fri Aug 21 11:43:24 2015 +0200
+++ b/OrthancServer/ParsedDicomFile.h	Fri Aug 21 13:47:22 2015 +0200
@@ -100,9 +100,9 @@
 
     void SaveToFile(const std::string& path);
 
-    void EmbedImage(const ImageAccessor& accessor);
+    void EmbedContent(const std::string& dataUriScheme);
 
-    void EmbedImage(const std::string& dataUriScheme);
+    void EmbedImage(const ImageAccessor& accessor);
 
     void EmbedImage(const std::string& mime,
                     const std::string& content);
--- a/UnitTestsSources/FromDcmtkTests.cpp	Fri Aug 21 11:43:24 2015 +0200
+++ b/UnitTestsSources/FromDcmtkTests.cpp	Fri Aug 21 13:47:22 2015 +0200
@@ -161,17 +161,17 @@
   ASSERT_EQ(PixelFormat_RGBA32, reader.GetFormat());
 
   ParsedDicomFile o;
-  o.EmbedImage(s);
+  o.EmbedContent(s);
   o.SaveToFile("UnitTestsResults/png1.dcm");
 
   // Red dot, without alpha channel
   s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDTcIn2+8BgAAACJJREFUCNdj/P//PwMjIwME/P/P+J8BBTAxEOL/R9Lx/z8AynoKAXOeiV8AAAAASUVORK5CYII=";
-  o.EmbedImage(s);
+  o.EmbedContent(s);
   o.SaveToFile("UnitTestsResults/png2.dcm");
 
   // Check box in Graylevel8
   s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gUGDDcB53FulQAAAElJREFUGNNtj0sSAEEEQ1+U+185s1CtmRkblQ9CZldsKHJDk6DLGLJa6chjh0ooQmpjXMM86zPwydGEj6Ed/UGykkEM8X+p3u8/8LcOJIWLGeMAAAAASUVORK5CYII=";
-  o.EmbedImage(s);
+  o.EmbedContent(s);
   //o.Replace(DICOM_TAG_SOP_CLASS_UID, UID_DigitalXRayImageStorageForProcessing);
   o.SaveToFile("UnitTestsResults/png3.dcm");