Mercurial > hg > orthanc
comparison OrthancServer/ParsedDicomFile.cpp @ 1824:b530c3dfe2a6
refactoring image decoding
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 25 Nov 2015 14:14:32 +0100 |
parents | 1065401501fb |
children | ac5b0b4e2434 |
comparison
equal
deleted
inserted
replaced
1823:0ef4e6e66b56 | 1824:b530c3dfe2a6 |
---|---|
886 { | 886 { |
887 delete pimpl_; | 887 delete pimpl_; |
888 } | 888 } |
889 | 889 |
890 | 890 |
891 DcmFileFormat& ParsedDicomFile::GetDcmtkObject() | 891 DcmFileFormat& ParsedDicomFile::GetDcmtkObject() const |
892 { | 892 { |
893 return *pimpl_->file_.get(); | 893 return *pimpl_->file_.get(); |
894 } | 894 } |
895 | 895 |
896 | 896 |
1047 } | 1047 } |
1048 } | 1048 } |
1049 | 1049 |
1050 | 1050 |
1051 void ParsedDicomFile::ExtractImage(ImageBuffer& result, | 1051 void ParsedDicomFile::ExtractImage(ImageBuffer& result, |
1052 IDicomImageDecoder& decoder, | |
1052 unsigned int frame) | 1053 unsigned int frame) |
1053 { | 1054 { |
1054 DcmDataset& dataset = *pimpl_->file_->getDataset(); | 1055 if (!decoder.Decode(result, *this, frame)) |
1055 | |
1056 if (!DicomImageDecoder::Decode(result, dataset, frame)) | |
1057 { | 1056 { |
1058 throw OrthancException(ErrorCode_BadFileFormat); | 1057 throw OrthancException(ErrorCode_BadFileFormat); |
1059 } | 1058 } |
1060 } | 1059 } |
1061 | 1060 |
1062 | 1061 |
1063 void ParsedDicomFile::ExtractImage(ImageBuffer& result, | 1062 void ParsedDicomFile::ExtractImage(ImageBuffer& result, |
1063 IDicomImageDecoder& decoder, | |
1064 unsigned int frame, | 1064 unsigned int frame, |
1065 ImageExtractionMode mode) | 1065 ImageExtractionMode mode) |
1066 { | 1066 { |
1067 DcmDataset& dataset = *pimpl_->file_->getDataset(); | 1067 ImageBuffer source; |
1068 if (!decoder.Decode(source, *this, frame)) | |
1069 { | |
1070 throw OrthancException(ErrorCode_BadFileFormat); | |
1071 } | |
1068 | 1072 |
1069 bool ok = false; | 1073 bool ok = false; |
1070 | 1074 |
1071 switch (mode) | 1075 switch (mode) |
1072 { | 1076 { |
1073 case ImageExtractionMode_UInt8: | 1077 case ImageExtractionMode_UInt8: |
1074 ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_Grayscale8, false); | 1078 ok = DicomImageDecoder::TruncateDecodedImage(result, source, PixelFormat_Grayscale8, false); |
1075 break; | 1079 break; |
1076 | 1080 |
1077 case ImageExtractionMode_UInt16: | 1081 case ImageExtractionMode_UInt16: |
1078 ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_Grayscale16, false); | 1082 ok = DicomImageDecoder::TruncateDecodedImage(result, source, PixelFormat_Grayscale16, false); |
1079 break; | 1083 break; |
1080 | 1084 |
1081 case ImageExtractionMode_Int16: | 1085 case ImageExtractionMode_Int16: |
1082 ok = DicomImageDecoder::DecodeAndTruncate(result, dataset, frame, PixelFormat_SignedGrayscale16, false); | 1086 ok = DicomImageDecoder::TruncateDecodedImage(result, source, PixelFormat_SignedGrayscale16, false); |
1083 break; | 1087 break; |
1084 | 1088 |
1085 case ImageExtractionMode_Preview: | 1089 case ImageExtractionMode_Preview: |
1086 ok = DicomImageDecoder::DecodePreview(result, dataset, frame); | 1090 ok = DicomImageDecoder::PreviewDecodedImage(result, source); |
1087 break; | 1091 break; |
1088 | 1092 |
1089 default: | 1093 default: |
1090 throw OrthancException(ErrorCode_ParameterOutOfRange); | 1094 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1091 } | 1095 } |
1092 | 1096 |
1093 if (!ok) | 1097 if (!ok) |
1094 { | 1098 { |
1095 throw OrthancException(ErrorCode_BadFileFormat); | 1099 throw OrthancException(ErrorCode_NotImplemented); |
1096 } | 1100 } |
1097 } | 1101 } |
1098 | 1102 |
1099 | 1103 |
1100 void ParsedDicomFile::ExtractPngImage(std::string& result, | 1104 void ParsedDicomFile::ExtractPngImage(std::string& result, |
1105 IDicomImageDecoder& decoder, | |
1101 unsigned int frame, | 1106 unsigned int frame, |
1102 ImageExtractionMode mode) | 1107 ImageExtractionMode mode) |
1103 { | 1108 { |
1104 ImageBuffer buffer; | 1109 ImageBuffer buffer; |
1105 ExtractImage(buffer, frame, mode); | 1110 ExtractImage(buffer, decoder, frame, mode); |
1106 | 1111 |
1107 ImageAccessor accessor(buffer.GetConstAccessor()); | 1112 ImageAccessor accessor(buffer.GetConstAccessor()); |
1108 PngWriter writer; | 1113 PngWriter writer; |
1109 writer.WriteToMemory(result, accessor); | 1114 writer.WriteToMemory(result, accessor); |
1110 } | 1115 } |
1111 | 1116 |
1112 | 1117 |
1113 void ParsedDicomFile::ExtractJpegImage(std::string& result, | 1118 void ParsedDicomFile::ExtractJpegImage(std::string& result, |
1119 IDicomImageDecoder& decoder, | |
1114 unsigned int frame, | 1120 unsigned int frame, |
1115 ImageExtractionMode mode, | 1121 ImageExtractionMode mode, |
1116 uint8_t quality) | 1122 uint8_t quality) |
1117 { | 1123 { |
1118 if (mode != ImageExtractionMode_UInt8 && | 1124 if (mode != ImageExtractionMode_UInt8 && |
1120 { | 1126 { |
1121 throw OrthancException(ErrorCode_ParameterOutOfRange); | 1127 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1122 } | 1128 } |
1123 | 1129 |
1124 ImageBuffer buffer; | 1130 ImageBuffer buffer; |
1125 ExtractImage(buffer, frame, mode); | 1131 ExtractImage(buffer, decoder, frame, mode); |
1126 | 1132 |
1127 ImageAccessor accessor(buffer.GetConstAccessor()); | 1133 ImageAccessor accessor(buffer.GetConstAccessor()); |
1128 JpegWriter writer; | 1134 JpegWriter writer; |
1129 writer.SetQuality(quality); | 1135 writer.SetQuality(quality); |
1130 writer.WriteToMemory(result, accessor); | 1136 writer.WriteToMemory(result, accessor); |