Mercurial > hg > orthanc
changeset 957:63973b76a51f
detection of encoding
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 25 Jun 2014 21:21:18 +0200 |
parents | 2fd5a163776d |
children | 1fbe89dc18b5 |
files | Core/Toolbox.cpp DarwinCompilation.txt OrthancServer/FromDcmtkBridge.cpp |
diffstat | 3 files changed, 31 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/Toolbox.cpp Wed Jun 25 16:08:47 2014 +0200 +++ b/Core/Toolbox.cpp Wed Jun 25 21:21:18 2014 +0200 @@ -513,7 +513,7 @@ break; default: - throw OrthancException(ErrorCode_ParameterOutOfRange); + throw OrthancException(ErrorCode_NotImplemented); } try
--- a/DarwinCompilation.txt Wed Jun 25 16:08:47 2014 +0200 +++ b/DarwinCompilation.txt Wed Jun 25 21:21:18 2014 +0200 @@ -28,7 +28,7 @@ ---------------------------- # cd ~/OrthancBuild -# cmake -GXcode -DCMAKE_OSX_DEPLOYMENT_TARGET=10.8 -DSTATIC_BUILD=ON -DSTANDALONE_BUILD=ON .. +# cmake -GXcode -DCMAKE_OSX_DEPLOYMENT_TARGET=10.8 -DSTATIC_BUILD=ON -DSTANDALONE_BUILD=ON ~/Orthanc NB: Adapt the value of "CMAKE_OSX_DEPLOYMENT_TARGET" with respect to your version of XCode.
--- a/OrthancServer/FromDcmtkBridge.cpp Wed Jun 25 16:08:47 2014 +0200 +++ b/OrthancServer/FromDcmtkBridge.cpp Wed Jun 25 21:21:18 2014 +0200 @@ -61,6 +61,7 @@ #include <dcmtk/dcmdata/dcistrmb.h> #include <dcmtk/dcmdata/dcuid.h> #include <dcmtk/dcmdata/dcmetinf.h> +#include <dcmtk/dcmdata/dcdeftag.h> #include <dcmtk/dcmdata/dcvrae.h> #include <dcmtk/dcmdata/dcvras.h> @@ -118,8 +119,34 @@ Encoding FromDcmtkBridge::DetectEncoding(DcmDataset& dataset) { - // TODO Implement this! - return Encoding_Latin1; + // By default, assume UTF-8 encoding (as in dcm2xml.cc) + Encoding encoding = Encoding_Utf8; + + OFString tmp; + if (dataset.findAndGetOFString(DCM_SpecificCharacterSet, tmp).good()) + { + std::string characterSet = Toolbox::StripSpaces(std::string(tmp.c_str())); + + // TODO Add more encodings + + if (characterSet == "ISO_IR 6" || + characterSet == "ISO_IR 192") + { + encoding = Encoding_Utf8; + } + else if (characterSet == "ISO_IR 100") + { + encoding = Encoding_Latin1; + } + else if (!characterSet.empty()) + { + LOG(WARNING) << "Value of Specific Character Set (0008,0005) is not supported: " << characterSet; + // Fallback to ASCII (remove all special characters) + encoding = Encoding_Ascii; + } + } + + return encoding; }