Mercurial > hg > orthanc
comparison OrthancServer/ParsedDicomFile.cpp @ 1556:b8dc2f855a83
Preview of PDF files encapsulated in DICOM from Orthanc Explorer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 Aug 2015 17:05:05 +0200 |
parents | d6a93e12b1c1 |
children | 124de28b32ed |
comparison
equal
deleted
inserted
replaced
1555:d6a93e12b1c1 | 1556:b8dc2f855a83 |
---|---|
964 const DicomTag& tag) | 964 const DicomTag& tag) |
965 { | 965 { |
966 DcmTagKey k(tag.GetGroup(), tag.GetElement()); | 966 DcmTagKey k(tag.GetGroup(), tag.GetElement()); |
967 DcmDataset& dataset = *pimpl_->file_->getDataset(); | 967 DcmDataset& dataset = *pimpl_->file_->getDataset(); |
968 | 968 |
969 if (FromDcmtkBridge::IsPrivateTag(tag)) | 969 if (FromDcmtkBridge::IsPrivateTag(tag) || |
970 tag == DICOM_TAG_PIXEL_DATA || | |
971 tag == DICOM_TAG_ENCAPSULATED_DOCUMENT) | |
970 { | 972 { |
971 const Uint8* data = NULL; // This is freed in the destructor of the dataset | 973 const Uint8* data = NULL; // This is freed in the destructor of the dataset |
972 long unsigned int count = 0; | 974 long unsigned int count = 0; |
973 | 975 |
974 if (dataset.findAndGetUint8Array(k, data, &count).good()) | 976 if (dataset.findAndGetUint8Array(k, data, &count).good()) |
998 { | 1000 { |
999 return false; | 1001 return false; |
1000 } | 1002 } |
1001 | 1003 |
1002 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(*element, pimpl_->encoding_)); | 1004 std::auto_ptr<DicomValue> v(FromDcmtkBridge::ConvertLeafElement(*element, pimpl_->encoding_)); |
1003 | 1005 |
1004 if (v.get() == NULL) | 1006 if (v.get() == NULL) |
1005 { | 1007 { |
1006 value = ""; | 1008 value = ""; |
1007 } | 1009 } |
1008 else | 1010 else |
1009 { | 1011 { |
1010 value = v->AsString(); | 1012 value = v->AsString(); |
1011 } | 1013 } |
1012 | 1014 |
1013 return true; | 1015 return true; |
1014 } | 1016 } |
1015 } | 1017 } |
1016 | 1018 |
1017 | 1019 |
1469 delete obj; | 1471 delete obj; |
1470 throw OrthancException(ErrorCode_NotEnoughMemory); | 1472 throw OrthancException(ErrorCode_NotEnoughMemory); |
1471 } | 1473 } |
1472 } | 1474 } |
1473 | 1475 |
1476 | |
1477 bool ParsedDicomFile::ExtractPdf(std::string& pdf) | |
1478 { | |
1479 std::string sop, mime; | |
1480 | |
1481 if (!GetTagValue(sop, DICOM_TAG_SOP_CLASS_UID) || | |
1482 !GetTagValue(mime, FromDcmtkBridge::Convert(DCM_MIMETypeOfEncapsulatedDocument)) || | |
1483 sop != UID_EncapsulatedPDFStorage || | |
1484 mime != "application/pdf") | |
1485 { | |
1486 return false; | |
1487 } | |
1488 | |
1489 if (!GetTagValue(pdf, DICOM_TAG_ENCAPSULATED_DOCUMENT)) | |
1490 { | |
1491 return false; | |
1492 } | |
1493 | |
1494 // Strip the possible pad byte at the end of file, because the | |
1495 // encapsulated documents must always have an even length. The PDF | |
1496 // format expects files to end with %%EOF followed by CR/LF. If | |
1497 // the last character of the file is not a CR or LF, we assume it | |
1498 // is a pad byte and remove it. | |
1499 if (pdf.size() > 0) | |
1500 { | |
1501 char last = *pdf.rbegin(); | |
1502 | |
1503 if (last != 10 && last != 13) | |
1504 { | |
1505 pdf.resize(pdf.size() - 1); | |
1506 } | |
1507 } | |
1508 | |
1509 return true; | |
1510 } | |
1474 } | 1511 } |