comparison Framework/Algorithms/PyramidReader.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 0683312e21ba
children
comparison
equal deleted inserted replaced
317:f611fb47d0e8 318:8ad12abde290
41 unsigned int tileX_; 41 unsigned int tileX_;
42 unsigned int tileY_; 42 unsigned int tileY_;
43 bool hasRawTile_; 43 bool hasRawTile_;
44 std::string rawTile_; 44 std::string rawTile_;
45 ImageCompression rawTileCompression_; 45 ImageCompression rawTileCompression_;
46 bool isEmpty_;
46 47
47 std::unique_ptr<Orthanc::ImageAccessor> decoded_; 48 std::unique_ptr<Orthanc::ImageAccessor> decoded_;
48 49
49 bool IsRepaintNeeded() const 50 bool IsRepaintNeeded() const
50 { 51 {
105 if (!that_.parameters_.IsForceReencode() && 106 if (!that_.parameters_.IsForceReencode() &&
106 !IsRepaintNeeded() && 107 !IsRepaintNeeded() &&
107 that_.source_.ReadRawTile(rawTile_, rawTileCompression_, that_.level_, tileX, tileY)) 108 that_.source_.ReadRawTile(rawTile_, rawTileCompression_, that_.level_, tileX, tileY))
108 { 109 {
109 hasRawTile_ = true; 110 hasRawTile_ = true;
111 isEmpty_ = false;
110 } 112 }
111 else 113 else
112 { 114 {
113 hasRawTile_ = false; 115 hasRawTile_ = false;
114 decoded_.reset(that_.source_.DecodeTile(that_.level_, tileX, tileY)); 116
117 decoded_.reset(that_.source_.DecodeTile(isEmpty_, that_.level_, tileX, tileY));
115 if (decoded_.get() == NULL) 118 if (decoded_.get() == NULL)
116 { 119 {
117 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); 120 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
118 } 121 }
119 122
163 166
164 RepaintBackground(); 167 RepaintBackground();
165 } 168 }
166 169
167 return *decoded_; 170 return *decoded_;
171 }
172
173 bool IsEmpty() const
174 {
175 return isEmpty_;
168 } 176 }
169 }; 177 };
170 178
171 179
172 Orthanc::ImageAccessor& PyramidReader::GetOutsideTile() 180 Orthanc::ImageAccessor& PyramidReader::GetOutsideTile()
288 } 296 }
289 } 297 }
290 298
291 299
292 void PyramidReader::GetDecodedTile(Orthanc::ImageAccessor& target, 300 void PyramidReader::GetDecodedTile(Orthanc::ImageAccessor& target,
301 bool& isEmpty,
293 unsigned int tileX, 302 unsigned int tileX,
294 unsigned int tileY) 303 unsigned int tileY)
295 { 304 {
296 if (tileX * targetTileWidth_ >= levelWidth_ || 305 if (tileX * targetTileWidth_ >= levelWidth_ ||
297 tileY * targetTileHeight_ >= levelHeight_) 306 tileY * targetTileHeight_ >= levelHeight_)
298 { 307 {
299 // Accessing a tile out of the source image 308 // Accessing a tile out of the source image
300 GetOutsideTile().GetReadOnlyAccessor(target); 309 GetOutsideTile().GetReadOnlyAccessor(target);
310 isEmpty = true;
301 } 311 }
302 else 312 else
303 { 313 {
304 SourceTile& source = AccessSourceTile(MapTargetToSourceLocation(tileX, tileY)); 314 SourceTile& source = AccessSourceTile(MapTargetToSourceLocation(tileX, tileY));
305 const Orthanc::ImageAccessor& tile = source.GetDecodedTile(); 315 const Orthanc::ImageAccessor& tile = source.GetDecodedTile();
317 GetBytesPerPixel(tile.GetFormat()) * xx * targetTileWidth_; 327 GetBytesPerPixel(tile.GetFormat()) * xx * targetTileWidth_;
318 328
319 target.AssignReadOnly(tile.GetFormat(), 329 target.AssignReadOnly(tile.GetFormat(),
320 targetTileWidth_, 330 targetTileWidth_,
321 targetTileHeight_, 331 targetTileHeight_,
322 tile.GetPitch(), bytes); 332 tile.GetPitch(), bytes);
333 isEmpty = source.IsEmpty();
323 } 334 }
324 } 335 }
325 } 336 }