Mercurial > hg > orthanc
diff OrthancServer/ParsedDicomFile.cpp @ 2202:9b373b7d6713
Fix handling of encodings in C-FIND requests
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 08 Dec 2016 12:45:06 +0100 |
parents | 5a8840920121 |
children | 6dc3bdb4088b |
line wrap: on
line diff
--- a/OrthancServer/ParsedDicomFile.cpp Tue Dec 06 14:40:46 2016 +0100 +++ b/OrthancServer/ParsedDicomFile.cpp Thu Dec 08 12:45:06 2016 +0100 @@ -872,15 +872,55 @@ } - ParsedDicomFile::ParsedDicomFile(const DicomMap& map) : pimpl_(new PImpl) + void ParsedDicomFile::CreateFromDicomMap(const DicomMap& source, + Encoding defaultEncoding) { - std::auto_ptr<DcmDataset> dataset(ToDcmtkBridge::Convert(map)); + pimpl_->file_.reset(new DcmFileFormat); + + const DicomValue* tmp = source.TestAndGetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET); + if (tmp != NULL) + { + Encoding encoding; + if (tmp->IsNull() || + tmp->IsBinary() || + !GetDicomEncoding(encoding, tmp->GetContent().c_str())) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + else + { + SetEncoding(encoding); + } + } + else + { + SetEncoding(defaultEncoding); + } - // NOTE: This implies an unnecessary memory copy of the dataset, but no way to get around - // http://support.dcmtk.org/redmine/issues/544 - std::auto_ptr<DcmFileFormat> fileFormat(new DcmFileFormat(dataset.get())); + for (DicomMap::Map::const_iterator + it = source.map_.begin(); it != source.map_.end(); ++it) + { + if (it->first != DICOM_TAG_SPECIFIC_CHARACTER_SET && + !it->second->IsNull()) + { + ReplacePlainString(it->first, it->second->GetContent()); + } + } + } + - pimpl_->file_.reset(fileFormat.release()); + ParsedDicomFile::ParsedDicomFile(const DicomMap& map, + Encoding defaultEncoding) : + pimpl_(new PImpl) + { + CreateFromDicomMap(map, defaultEncoding); + } + + + ParsedDicomFile::ParsedDicomFile(const DicomMap& map) : + pimpl_(new PImpl) + { + CreateFromDicomMap(map, Configuration::GetDefaultEncoding()); }