# HG changeset patch # User Sebastien Jodogne # Date 1443004985 -7200 # Node ID 4e56b5a206b76dcd484b16730349e00f74d723bd # Parent 48224db51ee7e16de5a57c3fded66f00d6e55509 Support of binary tags encoded using data URI scheme diff -r 48224db51ee7 -r 4e56b5a206b7 Core/Toolbox.cpp --- a/Core/Toolbox.cpp Wed Sep 23 12:02:39 2015 +0200 +++ b/Core/Toolbox.cpp Wed Sep 23 12:43:05 2015 +0200 @@ -1021,7 +1021,7 @@ if (regex_match(source.c_str(), what, pattern)) { mime = what[1]; - content = what[2]; + DecodeBase64(content, what[2]); } else { diff -r 48224db51ee7 -r 4e56b5a206b7 NEWS --- a/NEWS Wed Sep 23 12:02:39 2015 +0200 +++ b/NEWS Wed Sep 23 12:43:05 2015 +0200 @@ -2,6 +2,7 @@ =============================== * Add ".dcm" suffix to files in ZIP archives (cf. URI ".../archive") +* "/tools/create-dicom": Support of binary tags encoded using data URI scheme Maintenance ----------- diff -r 48224db51ee7 -r 4e56b5a206b7 OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Wed Sep 23 12:02:39 2015 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Wed Sep 23 12:43:05 2015 +0200 @@ -40,6 +40,7 @@ #include "../OrthancInitialization.h" #include +#include namespace Orthanc { @@ -485,7 +486,8 @@ static void InjectTags(ParsedDicomFile& dicom, - const Json::Value& tags) + const Json::Value& tags, + bool interpretBinaryTags) { if (tags.type() != Json::objectValue) { @@ -503,8 +505,8 @@ } std::string value = tags[name].asString(); + DicomTag tag = FromDcmtkBridge::ParseTag(name); - DicomTag tag = FromDcmtkBridge::ParseTag(name); if (tag != DICOM_TAG_SPECIFIC_CHARACTER_SET) { if (tag != DICOM_TAG_PATIENT_ID && @@ -527,6 +529,13 @@ { throw OrthancException(ErrorCode_CreateDicomUseContent); } + else if (interpretBinaryTags && + boost::starts_with(value, "data:application/octet-stream;base64,")) + { + std::string mime, binary; + Toolbox::DecodeDataUriScheme(mime, binary, value); + dicom.Replace(tag, binary); + } else { dicom.Replace(tag, Toolbox::ConvertFromUtf8(value, dicom.GetEncoding())); @@ -538,7 +547,8 @@ static void CreateSeries(RestApiPostCall& call, ParsedDicomFile& base /* in */, - const Json::Value& content) + const Json::Value& content, + bool interpretBinaryTags) { assert(content.isArray()); assert(content.size() > 0); @@ -571,7 +581,7 @@ if (content[i].isMember("Tags")) { - InjectTags(*dicom, content[i]["Tags"]); + InjectTags(*dicom, content[i]["Tags"], interpretBinaryTags); } } @@ -744,6 +754,19 @@ } } + + bool interpretBinaryTags = true; + if (request.isMember("InterpretBinaryTags")) + { + const Json::Value& v = request["InterpretBinaryTags"]; + if (v.type() != Json::booleanValue) + { + throw OrthancException(ErrorCode_BadRequest); + } + + interpretBinaryTags = v.asBool(); + } + // Inject time-related information std::string date, time; @@ -771,7 +794,7 @@ } - InjectTags(dicom, request["Tags"]); + InjectTags(dicom, request["Tags"], interpretBinaryTags); // Inject the content (either an image, or a PDF file) @@ -789,7 +812,7 @@ if (content.size() > 0) { // Let's create a series instead of a single instance - CreateSeries(call, dicom, content); + CreateSeries(call, dicom, content, interpretBinaryTags); return; } } diff -r 48224db51ee7 -r 4e56b5a206b7 OrthancServer/ParsedDicomFile.cpp --- a/OrthancServer/ParsedDicomFile.cpp Wed Sep 23 12:02:39 2015 +0200 +++ b/OrthancServer/ParsedDicomFile.cpp Wed Sep 23 12:43:05 2015 +0200 @@ -1139,13 +1139,10 @@ void ParsedDicomFile::EmbedContent(const std::string& dataUriScheme) { - std::string mime, base64; - Toolbox::DecodeDataUriScheme(mime, base64, dataUriScheme); + std::string mime, content; + Toolbox::DecodeDataUriScheme(mime, content, dataUriScheme); Toolbox::ToLowerCase(mime); - std::string content; - Toolbox::DecodeBase64(content, base64); - if (mime == "image/png") { EmbedImage(mime, content); diff -r 48224db51ee7 -r 4e56b5a206b7 UnitTestsSources/FromDcmtkTests.cpp --- a/UnitTestsSources/FromDcmtkTests.cpp Wed Sep 23 12:02:39 2015 +0200 +++ b/UnitTestsSources/FromDcmtkTests.cpp Wed Sep 23 12:43:05 2015 +0200 @@ -145,14 +145,11 @@ // Red dot in http://en.wikipedia.org/wiki/Data_URI_scheme (RGBA image) std::string s = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; - std::string m, c; - Toolbox::DecodeDataUriScheme(m, c, s); + std::string m, cc; + Toolbox::DecodeDataUriScheme(m, cc, s); ASSERT_EQ("image/png", m); - ASSERT_EQ(116u, c.size()); - std::string cc; - Toolbox::DecodeBase64(cc, c); PngReader reader; reader.ReadFromMemory(cc);