comparison Plugin/DecodedImageAdapter.cpp @ 230:cce89307af28

replacing GdcmDecoder/OrthancImageWrapper.h by OrthancPluginCppWrapper.h
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 11 May 2020 12:06:33 +0200
parents e4def26f0fd3
children 083d0cbcbac4
comparison
equal deleted inserted replaced
229:967ae255a58f 230:cce89307af28
25 25
26 #include <Core/Images/ImageBuffer.h> 26 #include <Core/Images/ImageBuffer.h>
27 #include <Core/Images/ImageProcessing.h> 27 #include <Core/Images/ImageProcessing.h>
28 #include <Core/OrthancException.h> 28 #include <Core/OrthancException.h>
29 #include <Core/Toolbox.h> 29 #include <Core/Toolbox.h>
30 #include <Plugins/Samples/GdcmDecoder/OrthancImageWrapper.h>
31 30
32 #include <boost/lexical_cast.hpp> 31 #include <boost/lexical_cast.hpp>
33 #include <boost/algorithm/string/predicate.hpp> 32 #include <boost/algorithm/string/predicate.hpp>
34 #include <json/writer.h> 33 #include <json/writer.h>
35 #include <boost/regex.hpp> 34 #include <boost/regex.hpp>
148 !GetJsonFromOrthanc(tags, context_, "/instances/" + instanceId + "/tags")) 147 !GetJsonFromOrthanc(tags, context_, "/instances/" + instanceId + "/tags"))
149 { 148 {
150 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); 149 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource);
151 } 150 }
152 151
153 std::unique_ptr<OrthancImageWrapper> image( 152 std::unique_ptr<OrthancImage> image(
154 new OrthancImageWrapper(context_, OrthancPluginDecodeDicomImage( 153 new OrthancImage(OrthancPluginDecodeDicomImage(
155 context_, dicom.c_str(), dicom.size(), frameIndex))); 154 context_, dicom.c_str(), dicom.size(), frameIndex)));
156 155
157 Json::Value json; 156 Json::Value json;
158 if (GetCornerstoneMetadata(json, tags, *image)) 157 if (GetCornerstoneMetadata(json, tags, *image))
159 { 158 {
160 if (type == CompressionType_Deflate) 159 if (type == CompressionType_Deflate)
189 } 188 }
190 189
191 190
192 bool DecodedImageAdapter::GetCornerstoneMetadata(Json::Value& result, 191 bool DecodedImageAdapter::GetCornerstoneMetadata(Json::Value& result,
193 const Json::Value& tags, 192 const Json::Value& tags,
194 OrthancImageWrapper& image) 193 OrthancImage& image)
195 { 194 {
196 using namespace Orthanc; 195 using namespace Orthanc;
197 196
198 float windowCenter, windowWidth; 197 float windowCenter, windowWidth;
199 198
200 Orthanc::ImageAccessor accessor; 199 Orthanc::ImageAccessor accessor;
201 accessor.AssignReadOnly(OrthancPlugins::Convert(image.GetFormat()), image.GetWidth(), 200 accessor.AssignReadOnly(OrthancPlugins::Convert(image.GetPixelFormat()), image.GetWidth(),
202 image.GetHeight(), image.GetPitch(), image.GetBuffer()); 201 image.GetHeight(), image.GetPitch(), image.GetBuffer());
203 202
204 switch (accessor.GetFormat()) 203 switch (accessor.GetFormat())
205 { 204 {
206 case PixelFormat_Grayscale8: 205 case PixelFormat_Grayscale8:
309 } 308 }
310 } 309 }
311 310
312 311
313 bool DecodedImageAdapter::EncodeUsingDeflate(Json::Value& result, 312 bool DecodedImageAdapter::EncodeUsingDeflate(Json::Value& result,
314 OrthancImageWrapper& image) 313 OrthancImage& image)
315 { 314 {
316 Orthanc::ImageAccessor accessor; 315 Orthanc::ImageAccessor accessor;
317 accessor.AssignReadOnly(OrthancPlugins::Convert(image.GetFormat()), image.GetWidth(), 316 accessor.AssignReadOnly(OrthancPlugins::Convert(image.GetPixelFormat()), image.GetWidth(),
318 image.GetHeight(), image.GetPitch(), image.GetBuffer()); 317 image.GetHeight(), image.GetPitch(), image.GetBuffer());
319 318
320 std::unique_ptr<Orthanc::ImageBuffer> buffer; 319 std::unique_ptr<Orthanc::ImageBuffer> buffer;
321 320
322 Orthanc::ImageAccessor converted; 321 Orthanc::ImageAccessor converted;
361 GetBytesPerPixel(converted.GetFormat())); 360 GetBytesPerPixel(converted.GetFormat()));
362 result["Orthanc"]["Compression"] = "Deflate"; 361 result["Orthanc"]["Compression"] = "Deflate";
363 result["sizeInBytes"] = converted.GetSize(); 362 result["sizeInBytes"] = converted.GetSize();
364 363
365 std::string z; 364 std::string z;
366 CompressUsingDeflate(z, image.GetContext(), converted.GetConstBuffer(), converted.GetSize()); 365 CompressUsingDeflate(z, GetGlobalContext(), converted.GetConstBuffer(), converted.GetSize());
367 366
368 std::string s; 367 std::string s;
369 Orthanc::Toolbox::EncodeBase64(s, z); 368 Orthanc::Toolbox::EncodeBase64(s, z);
370 result["Orthanc"]["PixelData"] = s; 369 result["Orthanc"]["PixelData"] = s;
371 370
420 } 419 }
421 } 420 }
422 421
423 422
424 bool DecodedImageAdapter::EncodeUsingJpeg(Json::Value& result, 423 bool DecodedImageAdapter::EncodeUsingJpeg(Json::Value& result,
425 OrthancImageWrapper& image, 424 OrthancImage& image,
426 uint8_t quality /* between 0 and 100 */) 425 uint8_t quality /* between 0 and 100 */)
427 { 426 {
428 Orthanc::ImageAccessor accessor; 427 Orthanc::ImageAccessor accessor;
429 accessor.AssignReadOnly(OrthancPlugins::Convert(image.GetFormat()), image.GetWidth(), 428 accessor.AssignReadOnly(OrthancPlugins::Convert(image.GetPixelFormat()), image.GetWidth(),
430 image.GetHeight(), image.GetPitch(), image.GetBuffer()); 429 image.GetHeight(), image.GetPitch(), image.GetBuffer());
431 430
432 std::unique_ptr<Orthanc::ImageBuffer> buffer; 431 std::unique_ptr<Orthanc::ImageBuffer> buffer;
433 432
434 Orthanc::ImageAccessor converted; 433 Orthanc::ImageAccessor converted;
483 result["Orthanc"]["IsSigned"] = (accessor.GetFormat() == Orthanc::PixelFormat_SignedGrayscale16); 482 result["Orthanc"]["IsSigned"] = (accessor.GetFormat() == Orthanc::PixelFormat_SignedGrayscale16);
484 result["Orthanc"]["Compression"] = "Jpeg"; 483 result["Orthanc"]["Compression"] = "Jpeg";
485 result["sizeInBytes"] = converted.GetSize(); 484 result["sizeInBytes"] = converted.GetSize();
486 485
487 std::string jpeg; 486 std::string jpeg;
488 WriteJpegToMemory(jpeg, image.GetContext(), converted, quality); 487 WriteJpegToMemory(jpeg, GetGlobalContext(), converted, quality);
489 488
490 std::string s; 489 std::string s;
491 Orthanc::Toolbox::EncodeBase64(s, jpeg); 490 Orthanc::Toolbox::EncodeBase64(s, jpeg);
492 result["Orthanc"]["PixelData"] = s; 491 result["Orthanc"]["PixelData"] = s;
493 492