Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/OrthancSlicesLoader.cpp @ 100:166a555becbf wasm
fix jpeg decoding in wasm
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 30 May 2017 22:22:04 +0200 |
parents | efd9ef2b67f1 |
children | 53025eecbc95 |
comparison
equal
deleted
inserted
replaced
99:efd9ef2b67f1 | 100:166a555becbf |
---|---|
33 #include "../../Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.h" | 33 #include "../../Resources/Orthanc/Plugins/Samples/Common/DicomDatasetReader.h" |
34 #include "../../Resources/Orthanc/Plugins/Samples/Common/FullOrthancDataset.h" | 34 #include "../../Resources/Orthanc/Plugins/Samples/Common/FullOrthancDataset.h" |
35 | 35 |
36 #include <boost/lexical_cast.hpp> | 36 #include <boost/lexical_cast.hpp> |
37 | 37 |
38 | |
39 | |
40 /** | |
41 * TODO This is a SLOW implementation of base64 decoding, because | |
42 * "Orthanc::Toolbox::DecodeBase64()" does not work properly with | |
43 * WASM. UNDERSTAND WHY. | |
44 * https://stackoverflow.com/a/34571089/881731 | |
45 **/ | |
46 static std::string base64_decode(const std::string &in) | |
47 { | |
48 std::string out; | |
49 | |
50 std::vector<int> T(256,-1); | |
51 for (int i=0; i<64; i++) T["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i]] = i; | |
52 | |
53 int val=0, valb=-8; | |
54 for (unsigned char c : in) { | |
55 if (T[c] == -1) break; | |
56 val = (val<<6) + T[c]; | |
57 valb += 6; | |
58 if (valb>=0) { | |
59 out.push_back(char((val>>valb)&0xFF)); | |
60 valb-=8; | |
61 } | |
62 } | |
63 return out; | |
64 } | |
65 | |
66 | |
67 | |
38 namespace OrthancStone | 68 namespace OrthancStone |
39 { | 69 { |
40 class OrthancSlicesLoader::Operation : public Orthanc::IDynamicObject | 70 class OrthancSlicesLoader::Operation : public Orthanc::IDynamicObject |
41 { | 71 { |
42 private: | 72 private: |
346 return; | 376 return; |
347 } | 377 } |
348 } | 378 } |
349 | 379 |
350 NotifySliceImageSuccess(operation, image); | 380 NotifySliceImageSuccess(operation, image); |
351 } | 381 } |
352 | 382 |
353 | 383 |
354 void OrthancSlicesLoader::ParseSliceImageJpeg(const Operation& operation, | 384 void OrthancSlicesLoader::ParseSliceImageJpeg(const Operation& operation, |
355 const void* answer, | 385 const void* answer, |
356 size_t size) | 386 size_t size) |
357 { | 387 { |
358 Json::Value encoded; | 388 Json::Value encoded; |
392 { | 422 { |
393 isSigned = info["IsSigned"].asBool(); | 423 isSigned = info["IsSigned"].asBool(); |
394 } | 424 } |
395 } | 425 } |
396 | 426 |
397 std::string jpeg; | |
398 Orthanc::Toolbox::DecodeBase64(jpeg, info["PixelData"].asString()); | |
399 | |
400 std::auto_ptr<Orthanc::ImageAccessor> reader; | 427 std::auto_ptr<Orthanc::ImageAccessor> reader; |
401 | 428 |
402 try | 429 { |
403 { | 430 std::string jpeg; |
404 reader.reset(new Orthanc::JpegReader); | 431 //Orthanc::Toolbox::DecodeBase64(jpeg, info["PixelData"].asString()); |
405 dynamic_cast<Orthanc::JpegReader&>(*reader).ReadFromMemory(jpeg); | 432 jpeg = base64_decode(info["PixelData"].asString()); |
406 } | 433 |
407 catch (Orthanc::OrthancException&) | 434 try |
408 { | 435 { |
409 NotifySliceImageError(operation); | 436 reader.reset(new Orthanc::JpegReader); |
410 return; | 437 dynamic_cast<Orthanc::JpegReader&>(*reader).ReadFromMemory(jpeg); |
438 } | |
439 catch (Orthanc::OrthancException&) | |
440 { | |
441 NotifySliceImageError(operation); | |
442 return; | |
443 } | |
411 } | 444 } |
412 | 445 |
413 Orthanc::PixelFormat expectedFormat = | 446 Orthanc::PixelFormat expectedFormat = |
414 operation.GetSlice().GetConverter().GetExpectedPixelFormat(); | 447 operation.GetSlice().GetConverter().GetExpectedPixelFormat(); |
415 | 448 |