comparison Framework/Inputs/OpenSlidePyramid.cpp @ 329:ae2d769215d2

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Oct 2024 08:48:53 +0200
parents 0c34b6625c67
children
comparison
equal deleted inserted replaced
328:a57a107b9547 329:ae2d769215d2
33 #include <boost/math/special_functions/round.hpp> 33 #include <boost/math/special_functions/round.hpp>
34 #include <memory> 34 #include <memory>
35 35
36 namespace OrthancWSI 36 namespace OrthancWSI
37 { 37 {
38 // Test whether the full alpha channel (if any) equals 255
39 static bool IsFullyTransparent(const Orthanc::ImageAccessor& source)
40 {
41 if (source.GetFormat() == Orthanc::PixelFormat_BGRA32 ||
42 source.GetFormat() == Orthanc::PixelFormat_RGBA32)
43 {
44 const unsigned int width = source.GetWidth();
45 const unsigned int height = source.GetHeight();
46
47 bool isEmpty = true;
48
49 for (unsigned int yy = 0; yy < height && isEmpty; yy++)
50 {
51 const uint8_t* p = reinterpret_cast<const uint8_t*>(source.GetConstRow(yy));
52 for (unsigned int xx = 0; xx < width && isEmpty; xx++)
53 {
54 if (p[3] != 0)
55 {
56 isEmpty = false;
57 }
58
59 p += 4;
60 }
61 }
62
63 return isEmpty;
64 }
65 else
66 {
67 return false;
68 }
69 }
70
71
38 void OpenSlidePyramid::ReadRegion(Orthanc::ImageAccessor& target, 72 void OpenSlidePyramid::ReadRegion(Orthanc::ImageAccessor& target,
39 bool& isEmpty, 73 bool& isEmpty,
40 unsigned int level, 74 unsigned int level,
41 unsigned int x, 75 unsigned int x,
42 unsigned int y) 76 unsigned int y)
47 target.GetHeight() != source->GetHeight()) 81 target.GetHeight() != source->GetHeight())
48 { 82 {
49 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize); 83 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize);
50 } 84 }
51 85
86 isEmpty = IsFullyTransparent(*source);
87
52 const unsigned int width = source->GetWidth(); 88 const unsigned int width = source->GetWidth();
53 const unsigned int height = source->GetHeight(); 89 const unsigned int height = source->GetHeight();
54
55 if (source->GetFormat() == Orthanc::PixelFormat_BGRA32)
56 {
57 isEmpty = true;
58
59 for (unsigned int yy = 0; yy < height && isEmpty; yy++)
60 {
61 const uint8_t* p = reinterpret_cast<const uint8_t*>(source->GetConstRow(yy));
62 for (unsigned int xx = 0; xx < width && isEmpty; xx++)
63 {
64 if (p[3] != 0)
65 {
66 isEmpty = false;
67 }
68
69 p += 4;
70 }
71 }
72 }
73 else
74 {
75 isEmpty = false;
76 }
77 90
78 if (target.GetFormat() == Orthanc::PixelFormat_RGB24 && 91 if (target.GetFormat() == Orthanc::PixelFormat_RGB24 &&
79 source->GetFormat() == Orthanc::PixelFormat_BGRA32) 92 source->GetFormat() == Orthanc::PixelFormat_BGRA32)
80 { 93 {
81 // Implements alpha blending: https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending 94 // Implements alpha blending: https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending