# HG changeset patch # User Sebastien Jodogne # Date 1557417783 -7200 # Node ID afc91cdc5128e5190cd29eb4573b4df3b0304b62 # Parent fb00a8be03e24b1addbbcf773799ab7c4f4ba8a4 decoding of images by oracle diff -r fb00a8be03e2 -r afc91cdc5128 Samples/Sdl/Loader.cpp --- a/Samples/Sdl/Loader.cpp Thu May 09 16:58:35 2019 +0200 +++ b/Samples/Sdl/Loader.cpp Thu May 09 18:03:03 2019 +0200 @@ -28,14 +28,17 @@ #include "../../Framework/Volumes/ImageBuffer3D.h" // From Orthanc framework +#include +#include #include #include -#include -#include #include #include #include #include +#include +#include +#include #include #include #include @@ -304,17 +307,14 @@ private: std::auto_ptr image_; Orthanc::MimeType mime_; - unsigned int quality_; public: SuccessMessage(const DecodeOrthancImageCommand& command, Orthanc::ImageAccessor* image, // Takes ownership - Orthanc::MimeType mime, - unsigned int quality) : + Orthanc::MimeType mime) : OriginMessage(command), image_(image), - mime_(mime), - quality_(quality) + mime_(mime) { if (image == NULL) { @@ -331,11 +331,6 @@ { return mime_; } - - unsigned int GetQuality() const - { - return quality_; - } }; @@ -540,8 +535,6 @@ if (success) { - printf("OK %d\n", answer.size()); - Orthanc::MimeType contentType = Orthanc::MimeType_Binary; Orthanc::HttpCompression contentEncoding = Orthanc::HttpCompression_None; @@ -559,6 +552,7 @@ } else { + // TODO - Emit error message? throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, "Unsupported HTTP Content-Encoding: " + it->second); } @@ -568,8 +562,6 @@ { contentType = Orthanc::StringToMimeType(it->second); } - - printf(" [%s] == [%s]\n", it->first.c_str(), it->second.c_str()); } if (contentEncoding == Orthanc::HttpCompression_Gzip) @@ -581,12 +573,40 @@ compressor.Uncompress(answer, compressed.c_str(), compressed.size()); } - printf("[%s] %d => %d\n", Orthanc::EnumerationToString(contentType), contentEncoding, answer.size()); + std::auto_ptr image; + + switch (contentType) + { + case Orthanc::MimeType_Png: + { + image.reset(new Orthanc::PngReader); + dynamic_cast(*image).ReadFromMemory(answer); + break; + } - + case Orthanc::MimeType_Pam: + { + image.reset(new Orthanc::PamReader); + dynamic_cast(*image).ReadFromMemory(answer); + break; + } - //DecodeOrthancImageCommand::SuccessMessage message(command, answerHeaders, answer); - //emitter_.EmitMessage(receiver, message); + case Orthanc::MimeType_Jpeg: + { + image.reset(new Orthanc::JpegReader); + dynamic_cast(*image).ReadFromMemory(answer); + break; + } + + default: + // TODO - Emit error message? + throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, + "Unsupported HTTP Content-Type for an image: " + + std::string(Orthanc::EnumerationToString(contentType))); + } + + DecodeOrthancImageCommand::SuccessMessage message(command, image.release(), contentType); + emitter_.EmitMessage(receiver, message); } else { @@ -1287,6 +1307,11 @@ printf("ICI [%s]\n", v.toStyledString().c_str()); } + void Handle(const Refactoring::DecodeOrthancImageCommand::SuccessMessage& message) + { + printf("IMAGE %dx%d\n", message.GetImage().GetWidth(), message.GetImage().GetHeight()); + } + void Handle(const Refactoring::OrthancRestApiCommand::FailureMessage& message) { printf("ERROR %d\n", message.GetHttpStatus()); @@ -1299,6 +1324,10 @@ oracle.RegisterObserverCallback (new OrthancStone::Callable (*this, &Toto::Handle)); + + oracle.RegisterObserverCallback + (new OrthancStone::Callable + (*this, &Toto::Handle)); } };