comparison OrthancServer/ParsedDicomFile.cpp @ 1902:8b0ee8d5e6d0

Refactoring leading to speedups with custom image decoders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 05 Jan 2016 13:26:51 +0100
parents b1291df2f780
children 41e402cd7b3a
comparison
equal deleted inserted replaced
1901:50234539a0dd 1902:8b0ee8d5e6d0
82 82
83 #include "OrthancInitialization.h" 83 #include "OrthancInitialization.h"
84 #include "ServerToolbox.h" 84 #include "ServerToolbox.h"
85 #include "FromDcmtkBridge.h" 85 #include "FromDcmtkBridge.h"
86 #include "ToDcmtkBridge.h" 86 #include "ToDcmtkBridge.h"
87 #include "Internals/DicomImageDecoder.h"
88 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h"
89 #include "../Core/Images/JpegWriter.h"
90 #include "../Core/Images/JpegReader.h" 87 #include "../Core/Images/JpegReader.h"
91 #include "../Core/Images/PngReader.h" 88 #include "../Core/Images/PngReader.h"
92 #include "../Core/Images/PngWriter.h"
93 #include "../Core/Logging.h" 89 #include "../Core/Logging.h"
94 #include "../Core/OrthancException.h" 90 #include "../Core/OrthancException.h"
95 #include "../Core/Toolbox.h" 91 #include "../Core/Toolbox.h"
96 #include "../Core/Uuid.h" 92 #include "../Core/Uuid.h"
97 93
1045 throw OrthancException(ErrorCode_InternalError); 1041 throw OrthancException(ErrorCode_InternalError);
1046 } 1042 }
1047 } 1043 }
1048 1044
1049 1045
1050 ImageAccessor* ParsedDicomFile::ExtractImage(IDicomImageDecoder& decoder,
1051 unsigned int frame)
1052 {
1053 std::auto_ptr<ImageAccessor> decoded(decoder.Decode(*this, frame));
1054
1055 if (decoded.get() == NULL)
1056 {
1057 LOG(ERROR) << "Cannot decode a DICOM image";
1058 throw OrthancException(ErrorCode_BadFileFormat);
1059 }
1060 else
1061 {
1062 return decoded.release();
1063 }
1064 }
1065
1066
1067 ImageAccessor* ParsedDicomFile::ExtractImage(IDicomImageDecoder& decoder,
1068 unsigned int frame,
1069 ImageExtractionMode mode)
1070 {
1071 std::auto_ptr<ImageAccessor> decoded(ExtractImage(decoder, frame));
1072
1073 bool ok = false;
1074
1075 switch (mode)
1076 {
1077 case ImageExtractionMode_UInt8:
1078 ok = DicomImageDecoder::TruncateDecodedImage(decoded, PixelFormat_Grayscale8, false);
1079 break;
1080
1081 case ImageExtractionMode_UInt16:
1082 ok = DicomImageDecoder::TruncateDecodedImage(decoded, PixelFormat_Grayscale16, false);
1083 break;
1084
1085 case ImageExtractionMode_Int16:
1086 ok = DicomImageDecoder::TruncateDecodedImage(decoded, PixelFormat_SignedGrayscale16, false);
1087 break;
1088
1089 case ImageExtractionMode_Preview:
1090 ok = DicomImageDecoder::PreviewDecodedImage(decoded);
1091 break;
1092
1093 default:
1094 throw OrthancException(ErrorCode_ParameterOutOfRange);
1095 }
1096
1097 if (ok)
1098 {
1099 assert(decoded.get() != NULL);
1100 return decoded.release();
1101 }
1102 else
1103 {
1104 throw OrthancException(ErrorCode_NotImplemented);
1105 }
1106 }
1107
1108
1109 void ParsedDicomFile::ExtractPngImage(std::string& result,
1110 IDicomImageDecoder& decoder,
1111 unsigned int frame,
1112 ImageExtractionMode mode)
1113 {
1114 std::auto_ptr<ImageAccessor> decoded(ExtractImage(decoder, frame, mode));
1115 assert(decoded.get() != NULL);
1116
1117 PngWriter writer;
1118 writer.WriteToMemory(result, *decoded);
1119 }
1120
1121
1122 void ParsedDicomFile::ExtractJpegImage(std::string& result,
1123 IDicomImageDecoder& decoder,
1124 unsigned int frame,
1125 ImageExtractionMode mode,
1126 uint8_t quality)
1127 {
1128 if (mode != ImageExtractionMode_UInt8 &&
1129 mode != ImageExtractionMode_Preview)
1130 {
1131 throw OrthancException(ErrorCode_ParameterOutOfRange);
1132 }
1133
1134 std::auto_ptr<ImageAccessor> decoded(ExtractImage(decoder, frame, mode));
1135 assert(decoded.get() != NULL);
1136
1137 JpegWriter writer;
1138 writer.SetQuality(quality);
1139 writer.WriteToMemory(result, *decoded);
1140 }
1141
1142
1143 Encoding ParsedDicomFile::GetEncoding() const 1046 Encoding ParsedDicomFile::GetEncoding() const
1144 { 1047 {
1145 return FromDcmtkBridge::DetectEncoding(*pimpl_->file_->getDataset()); 1048 return FromDcmtkBridge::DetectEncoding(*pimpl_->file_->getDataset());
1146 } 1049 }
1147 1050