comparison Framework/Inputs/OpenSlidePyramid.cpp @ 318:8ad12abde290

sparse re-encoding with OpenSlide (notably for MIRAX format)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 11 Sep 2024 16:11:16 +0200
parents f611fb47d0e8
children 0c34b6625c67
comparison
equal deleted inserted replaced
317:f611fb47d0e8 318:8ad12abde290
34 #include <memory> 34 #include <memory>
35 35
36 namespace OrthancWSI 36 namespace OrthancWSI
37 { 37 {
38 void OpenSlidePyramid::ReadRegion(Orthanc::ImageAccessor& target, 38 void OpenSlidePyramid::ReadRegion(Orthanc::ImageAccessor& target,
39 bool& isEmpty,
39 unsigned int level, 40 unsigned int level,
40 unsigned int x, 41 unsigned int x,
41 unsigned int y) 42 unsigned int y)
42 { 43 {
43 std::unique_ptr<Orthanc::ImageAccessor> source(image_.ReadRegion(level, x, y, target.GetWidth(), target.GetHeight())); 44 std::unique_ptr<Orthanc::ImageAccessor> source(image_.ReadRegion(level, x, y, target.GetWidth(), target.GetHeight()));
48 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize); 49 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize);
49 } 50 }
50 51
51 const unsigned int width = source->GetWidth(); 52 const unsigned int width = source->GetWidth();
52 const unsigned int height = source->GetHeight(); 53 const unsigned int height = source->GetHeight();
54
55 if (source->GetFormat() == Orthanc::PixelFormat_BGRA32)
56 {
57 isEmpty = true;
58
59 for (unsigned int y = 0; y < height && isEmpty; y++)
60 {
61 const uint8_t* p = reinterpret_cast<const uint8_t*>(source->GetConstRow(y));
62 for (unsigned int x = 0; x < width && isEmpty; x++)
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 }
53 77
54 if (target.GetFormat() == Orthanc::PixelFormat_RGB24 && 78 if (target.GetFormat() == Orthanc::PixelFormat_RGB24 &&
55 source->GetFormat() == Orthanc::PixelFormat_BGRA32) 79 source->GetFormat() == Orthanc::PixelFormat_BGRA32)
56 { 80 {
57 // Implements alpha blending: https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending 81 // Implements alpha blending: https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending