comparison Framework/Inputs/OpenSlidePyramid.cpp @ 317:f611fb47d0e8

reuse base class members in OpenSlidePyramid
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 11 Sep 2024 13:43:39 +0200
parents 072968f00d26
children 8ad12abde290
comparison
equal deleted inserted replaced
316:51ef122c1882 317:f611fb47d0e8
53 53
54 if (target.GetFormat() == Orthanc::PixelFormat_RGB24 && 54 if (target.GetFormat() == Orthanc::PixelFormat_RGB24 &&
55 source->GetFormat() == Orthanc::PixelFormat_BGRA32) 55 source->GetFormat() == Orthanc::PixelFormat_BGRA32)
56 { 56 {
57 // Implements alpha blending: https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending 57 // Implements alpha blending: https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
58
59 uint8_t backgroundRed, backgroundGreen, backgroundBlue;
60 GetBackgroundColor(backgroundRed, backgroundGreen, backgroundBlue);
61
58 for (unsigned int y = 0; y < height; y++) 62 for (unsigned int y = 0; y < height; y++)
59 { 63 {
60 const uint8_t* p = reinterpret_cast<const uint8_t*>(source->GetConstRow(y)); 64 const uint8_t* p = reinterpret_cast<const uint8_t*>(source->GetConstRow(y));
61 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y)); 65 uint8_t* q = reinterpret_cast<uint8_t*>(target.GetRow(y));
62 for (unsigned int x = 0; x < width; x++) 66 for (unsigned int x = 0; x < width; x++)
69 <=> p = ((255 - p[3]) * background + p[3] * value) / 255 73 <=> p = ((255 - p[3]) * background + p[3] * value) / 255
70 74
71 **/ 75 **/
72 76
73 uint16_t alpha = p[3]; 77 uint16_t alpha = p[3];
74 q[0] = static_cast<uint8_t>(((255 - alpha) * backgroundColor_[0] + alpha * p[2]) / 255); 78 q[0] = static_cast<uint8_t>(((255 - alpha) * backgroundRed + alpha * p[2]) / 255);
75 q[1] = static_cast<uint8_t>(((255 - alpha) * backgroundColor_[1] + alpha * p[1]) / 255); 79 q[1] = static_cast<uint8_t>(((255 - alpha) * backgroundGreen + alpha * p[1]) / 255);
76 q[2] = static_cast<uint8_t>(((255 - alpha) * backgroundColor_[2] + alpha * p[0]) / 255); 80 q[2] = static_cast<uint8_t>(((255 - alpha) * backgroundBlue + alpha * p[0]) / 255);
77 81
78 p += 4; 82 p += 4;
79 q += 3; 83 q += 3;
80 } 84 }
81 } 85 }
92 unsigned int tileHeight) : 96 unsigned int tileHeight) :
93 image_(path), 97 image_(path),
94 tileWidth_(tileWidth), 98 tileWidth_(tileWidth),
95 tileHeight_(tileHeight) 99 tileHeight_(tileHeight)
96 { 100 {
97 backgroundColor_[0] = 255;
98 backgroundColor_[1] = 255;
99 backgroundColor_[2] = 255;
100 } 101 }
101 102
102 103
103 bool OpenSlidePyramid::LookupImagedVolumeSize(float& width, 104 bool OpenSlidePyramid::LookupImagedVolumeSize(float& width,
104 float& height) const 105 float& height) const
120 else 121 else
121 { 122 {
122 return false; 123 return false;
123 } 124 }
124 } 125 }
125
126
127 void OpenSlidePyramid::SetBackgroundColor(uint8_t red,
128 uint8_t green,
129 uint8_t blue)
130 {
131 backgroundColor_[0] = red;
132 backgroundColor_[1] = green;
133 backgroundColor_[2] = blue;
134 }
135 } 126 }