comparison Core/DicomParsing/ParsedDicomFile.cpp @ 2908:9d277f8ad698

new enumeration: MimeType
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Oct 2018 16:16:07 +0100
parents ae20fccdd867
children 83133583183d
comparison
equal deleted inserted replaced
2907:0204af4ece6a 2908:9d277f8ad698
256 return false; 256 return false;
257 } 257 }
258 258
259 virtual std::string GetContentType() 259 virtual std::string GetContentType()
260 { 260 {
261 return ""; 261 return EnumerationToString(MimeType_Binary);
262 } 262 }
263 263
264 virtual uint64_t GetContentLength() 264 virtual uint64_t GetContentLength()
265 { 265 {
266 return length_; 266 return length_;
360 DcmPixelItem* pixelItem = NULL; 360 DcmPixelItem* pixelItem = NULL;
361 if (pixelSequence->getItem(pixelItem, block).good() && pixelItem) 361 if (pixelSequence->getItem(pixelItem, block).good() && pixelItem)
362 { 362 {
363 if (pixelItem->getLength() == 0) 363 if (pixelItem->getLength() == 0)
364 { 364 {
365 output.AnswerBuffer(NULL, 0, MIME_BINARY); 365 output.AnswerBuffer(NULL, 0, MimeType_Binary);
366 return true; 366 return true;
367 } 367 }
368 368
369 Uint8* buffer = NULL; 369 Uint8* buffer = NULL;
370 if (pixelItem->getUint8Array(buffer).good() && buffer) 370 if (pixelItem->getUint8Array(buffer).good() && buffer)
371 { 371 {
372 output.AnswerBuffer(buffer, pixelItem->getLength(), MIME_BINARY); 372 output.AnswerBuffer(buffer, pixelItem->getLength(), MimeType_Binary);
373 return true; 373 return true;
374 } 374 }
375 } 375 }
376 } 376 }
377 } 377 }
823 void ParsedDicomFile::Answer(RestApiOutput& output) 823 void ParsedDicomFile::Answer(RestApiOutput& output)
824 { 824 {
825 std::string serialized; 825 std::string serialized;
826 if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, *pimpl_->file_->getDataset())) 826 if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, *pimpl_->file_->getDataset()))
827 { 827 {
828 output.AnswerBuffer(serialized, MIME_BINARY); 828 output.AnswerBuffer(serialized, MimeType_Binary);
829 } 829 }
830 } 830 }
831 #endif 831 #endif
832 832
833 833
1062 } 1062 }
1063 1063
1064 1064
1065 bool ParsedDicomFile::EmbedContentInternal(const std::string& dataUriScheme) 1065 bool ParsedDicomFile::EmbedContentInternal(const std::string& dataUriScheme)
1066 { 1066 {
1067 std::string mime, content; 1067 std::string mimeString, content;
1068 if (!Toolbox::DecodeDataUriScheme(mime, content, dataUriScheme)) 1068 if (!Toolbox::DecodeDataUriScheme(mimeString, content, dataUriScheme))
1069 { 1069 {
1070 return false; 1070 return false;
1071 } 1071 }
1072 1072
1073 Toolbox::ToLowerCase(mime); 1073 Toolbox::ToLowerCase(mimeString);
1074 1074 MimeType mime = StringToMimeType(mimeString);
1075 if (mime == MIME_PNG) 1075
1076 { 1076 switch (mime)
1077 {
1078 case MimeType_Png:
1077 #if ORTHANC_ENABLE_PNG == 1 1079 #if ORTHANC_ENABLE_PNG == 1
1078 EmbedImage(mime, content); 1080 EmbedImage(mime, content);
1081 break;
1079 #else 1082 #else
1080 LOG(ERROR) << "Orthanc was compiled without support of PNG"; 1083 LOG(ERROR) << "Orthanc was compiled without support of PNG";
1081 throw OrthancException(ErrorCode_NotImplemented); 1084 throw OrthancException(ErrorCode_NotImplemented);
1082 #endif 1085 #endif
1083 } 1086
1084 else if (mime == MIME_JPEG) 1087 case MimeType_Jpeg:
1085 {
1086 #if ORTHANC_ENABLE_JPEG == 1 1088 #if ORTHANC_ENABLE_JPEG == 1
1087 EmbedImage(mime, content); 1089 EmbedImage(mime, content);
1090 break;
1088 #else 1091 #else
1089 LOG(ERROR) << "Orthanc was compiled without support of JPEG"; 1092 LOG(ERROR) << "Orthanc was compiled without support of JPEG";
1090 throw OrthancException(ErrorCode_NotImplemented); 1093 throw OrthancException(ErrorCode_NotImplemented);
1091 #endif 1094 #endif
1092 } 1095
1093 else if (mime == MIME_PAM) 1096 case MimeType_Pam:
1094 { 1097 EmbedImage(mime, content);
1095 EmbedImage(mime, content); 1098 break;
1096 } 1099
1097 else if (mime == MIME_PDF) 1100 case MimeType_Pdf:
1098 { 1101 EmbedPdf(content);
1099 EmbedPdf(content); 1102 break;
1100 } 1103
1101 else 1104 default:
1102 { 1105 LOG(ERROR) << "Unsupported MIME type for the content of a new DICOM file: " << mime;
1103 LOG(ERROR) << "Unsupported MIME type for the content of a new DICOM file: " << mime; 1106 throw OrthancException(ErrorCode_NotImplemented);
1104 throw OrthancException(ErrorCode_NotImplemented);
1105 } 1107 }
1106 1108
1107 return true; 1109 return true;
1108 } 1110 }
1109 1111
1115 throw OrthancException(ErrorCode_BadFileFormat); 1117 throw OrthancException(ErrorCode_BadFileFormat);
1116 } 1118 }
1117 } 1119 }
1118 1120
1119 1121
1120 void ParsedDicomFile::EmbedImage(const std::string& mime, 1122 void ParsedDicomFile::EmbedImage(MimeType mime,
1121 const std::string& content) 1123 const std::string& content)
1122 { 1124 {
1125 switch (mime)
1126 {
1127
1123 #if ORTHANC_ENABLE_JPEG == 1 1128 #if ORTHANC_ENABLE_JPEG == 1
1124 if (mime == MIME_JPEG) 1129 case MimeType_Jpeg:
1125 { 1130 {
1126 JpegReader reader; 1131 JpegReader reader;
1127 reader.ReadFromMemory(content); 1132 reader.ReadFromMemory(content);
1128 EmbedImage(reader); 1133 EmbedImage(reader);
1129 return; 1134 break;
1130 } 1135 }
1131 #endif 1136 #endif
1132 1137
1133 #if ORTHANC_ENABLE_PNG == 1 1138 #if ORTHANC_ENABLE_PNG == 1
1134 if (mime == MIME_PNG) 1139 case MimeType_Png:
1135 { 1140 {
1136 PngReader reader; 1141 PngReader reader;
1137 reader.ReadFromMemory(content); 1142 reader.ReadFromMemory(content);
1138 EmbedImage(reader); 1143 EmbedImage(reader);
1139 return; 1144 break;
1140 } 1145 }
1141 #endif 1146 #endif
1142 1147
1143 if (mime == MIME_PAM) 1148 case MimeType_Pam:
1144 { 1149 {
1145 PamReader reader; 1150 PamReader reader;
1146 reader.ReadFromMemory(content); 1151 reader.ReadFromMemory(content);
1147 EmbedImage(reader); 1152 EmbedImage(reader);
1148 } 1153 break;
1149 else 1154 }
1150 { 1155
1151 throw OrthancException(ErrorCode_NotImplemented); 1156 default:
1157 throw OrthancException(ErrorCode_NotImplemented);
1152 } 1158 }
1153 } 1159 }
1154 1160
1155 1161
1156 void ParsedDicomFile::EmbedImage(const ImageAccessor& accessor) 1162 void ParsedDicomFile::EmbedImage(const ImageAccessor& accessor)
1469 return result.release(); 1475 return result.release();
1470 } 1476 }
1471 1477
1472 1478
1473 void ParsedDicomFile::GetRawFrame(std::string& target, 1479 void ParsedDicomFile::GetRawFrame(std::string& target,
1474 std::string& mime, 1480 MimeType& mime,
1475 unsigned int frameId) 1481 unsigned int frameId)
1476 { 1482 {
1477 if (pimpl_->frameIndex_.get() == NULL) 1483 if (pimpl_->frameIndex_.get() == NULL)
1478 { 1484 {
1479 pimpl_->frameIndex_.reset(new DicomFrameIndex(*pimpl_->file_)); 1485 pimpl_->frameIndex_.reset(new DicomFrameIndex(*pimpl_->file_));
1483 1489
1484 E_TransferSyntax transferSyntax = pimpl_->file_->getDataset()->getOriginalXfer(); 1490 E_TransferSyntax transferSyntax = pimpl_->file_->getDataset()->getOriginalXfer();
1485 switch (transferSyntax) 1491 switch (transferSyntax)
1486 { 1492 {
1487 case EXS_JPEGProcess1: 1493 case EXS_JPEGProcess1:
1488 mime = MIME_JPEG; 1494 mime = MimeType_Jpeg;
1489 break; 1495 break;
1490 1496
1491 case EXS_JPEG2000LosslessOnly: 1497 case EXS_JPEG2000LosslessOnly:
1492 case EXS_JPEG2000: 1498 case EXS_JPEG2000:
1493 mime = MIME_JPEG2000; 1499 mime = MimeType_Jpeg2000;
1494 break; 1500 break;
1495 1501
1496 default: 1502 default:
1497 mime = MIME_BINARY; 1503 mime = MimeType_Binary;
1498 break; 1504 break;
1499 } 1505 }
1500 } 1506 }
1501 1507
1502 1508