comparison OrthancServer/ParsedDicomFile.cpp @ 1781:5ad4e4d92ecb

AcceptMediaDispatcher bootstrap
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 17 Nov 2015 17:46:32 +0100
parents ec66a16aa398
children 164d78911382
comparison
equal deleted inserted replaced
1780:94990da8710e 1781:5ad4e4d92ecb
82 82
83 #include "ServerToolbox.h" 83 #include "ServerToolbox.h"
84 #include "FromDcmtkBridge.h" 84 #include "FromDcmtkBridge.h"
85 #include "ToDcmtkBridge.h" 85 #include "ToDcmtkBridge.h"
86 #include "Internals/DicomImageDecoder.h" 86 #include "Internals/DicomImageDecoder.h"
87 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h"
88 #include "../Core/Images/ImageBuffer.h"
89 #include "../Core/Images/JpegWriter.h"
90 #include "../Core/Images/JpegReader.h"
91 #include "../Core/Images/PngReader.h"
92 #include "../Core/Images/PngWriter.h"
87 #include "../Core/Logging.h" 93 #include "../Core/Logging.h"
94 #include "../Core/OrthancException.h"
88 #include "../Core/Toolbox.h" 95 #include "../Core/Toolbox.h"
89 #include "../Core/OrthancException.h"
90 #include "../Core/Images/ImageBuffer.h"
91 #include "../Core/Images/PngWriter.h"
92 #include "../Core/Uuid.h" 96 #include "../Core/Uuid.h"
93 #include "../Core/DicomFormat/DicomIntegerPixelAccessor.h"
94 #include "../Core/Images/PngReader.h"
95 97
96 #include <list> 98 #include <list>
97 #include <limits> 99 #include <limits>
98 100
99 #include <boost/lexical_cast.hpp> 101 #include <boost/lexical_cast.hpp>
794 796
795 return DicomInstanceHasher(patientId, studyUid, seriesUid, instanceUid); 797 return DicomInstanceHasher(patientId, studyUid, seriesUid, instanceUid);
796 } 798 }
797 799
798 800
799 template <typename T>
800 static void ExtractPngImageTruncate(std::string& result,
801 DicomIntegerPixelAccessor& accessor,
802 PixelFormat format)
803 {
804 assert(accessor.GetInformation().GetChannelCount() == 1);
805
806 PngWriter w;
807
808 std::vector<T> image(accessor.GetInformation().GetWidth() * accessor.GetInformation().GetHeight(), 0);
809 T* pixel = &image[0];
810 for (unsigned int y = 0; y < accessor.GetInformation().GetHeight(); y++)
811 {
812 for (unsigned int x = 0; x < accessor.GetInformation().GetWidth(); x++, pixel++)
813 {
814 int32_t v = accessor.GetValue(x, y);
815 if (v < static_cast<int32_t>(std::numeric_limits<T>::min()))
816 *pixel = std::numeric_limits<T>::min();
817 else if (v > static_cast<int32_t>(std::numeric_limits<T>::max()))
818 *pixel = std::numeric_limits<T>::max();
819 else
820 *pixel = static_cast<T>(v);
821 }
822 }
823
824 w.WriteToMemory(result, accessor.GetInformation().GetWidth(), accessor.GetInformation().GetHeight(),
825 accessor.GetInformation().GetWidth() * sizeof(T), format, &image[0]);
826 }
827
828
829 void ParsedDicomFile::SaveToMemoryBuffer(std::string& buffer) 801 void ParsedDicomFile::SaveToMemoryBuffer(std::string& buffer)
830 { 802 {
831 FromDcmtkBridge::SaveToMemoryBuffer(buffer, *pimpl_->file_->getDataset()); 803 FromDcmtkBridge::SaveToMemoryBuffer(buffer, *pimpl_->file_->getDataset());
832 } 804 }
833 805
901 { 873 {
902 std::string mime, content; 874 std::string mime, content;
903 Toolbox::DecodeDataUriScheme(mime, content, dataUriScheme); 875 Toolbox::DecodeDataUriScheme(mime, content, dataUriScheme);
904 Toolbox::ToLowerCase(mime); 876 Toolbox::ToLowerCase(mime);
905 877
906 if (mime == "image/png") 878 if (mime == "image/png" ||
879 mime == "image/jpeg")
907 { 880 {
908 EmbedImage(mime, content); 881 EmbedImage(mime, content);
909 } 882 }
910 else if (mime == "application/pdf") 883 else if (mime == "application/pdf")
911 { 884 {
923 const std::string& content) 896 const std::string& content)
924 { 897 {
925 if (mime == "image/png") 898 if (mime == "image/png")
926 { 899 {
927 PngReader reader; 900 PngReader reader;
901 reader.ReadFromMemory(content);
902 EmbedImage(reader);
903 }
904 else if (mime == "image/jpeg")
905 {
906 JpegReader reader;
928 reader.ReadFromMemory(content); 907 reader.ReadFromMemory(content);
929 EmbedImage(reader); 908 EmbedImage(reader);
930 } 909 }
931 else 910 else
932 { 911 {
1098 PngWriter writer; 1077 PngWriter writer;
1099 writer.WriteToMemory(result, accessor); 1078 writer.WriteToMemory(result, accessor);
1100 } 1079 }
1101 1080
1102 1081
1082 void ParsedDicomFile::ExtractJpegImage(std::string& result,
1083 unsigned int frame,
1084 ImageExtractionMode mode,
1085 uint8_t quality)
1086 {
1087 if (mode != ImageExtractionMode_UInt8 &&
1088 mode != ImageExtractionMode_Preview)
1089 {
1090 throw OrthancException(ErrorCode_ParameterOutOfRange);
1091 }
1092
1093 ImageBuffer buffer;
1094 ExtractImage(buffer, frame, mode);
1095
1096 ImageAccessor accessor(buffer.GetConstAccessor());
1097 JpegWriter writer;
1098 writer.SetQuality(quality);
1099 writer.WriteToMemory(result, accessor);
1100 }
1101
1102
1103 Encoding ParsedDicomFile::GetEncoding() const 1103 Encoding ParsedDicomFile::GetEncoding() const
1104 { 1104 {
1105 return FromDcmtkBridge::DetectEncoding(*pimpl_->file_->getDataset()); 1105 return FromDcmtkBridge::DetectEncoding(*pimpl_->file_->getDataset());
1106 } 1106 }
1107 1107