comparison Framework/Algorithms/PyramidReader.cpp @ 57:91fc9583b2de

big refactoring to support sparse tiling
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Nov 2016 17:48:24 +0100
parents 7a88c614be04
children 7a3853d51c45
comparison
equal deleted inserted replaced
56:83cd735c885d 57:91fc9583b2de
30 namespace OrthancWSI 30 namespace OrthancWSI
31 { 31 {
32 class PyramidReader::SourceTile : public boost::noncopyable 32 class PyramidReader::SourceTile : public boost::noncopyable
33 { 33 {
34 private: 34 private:
35 PyramidReader& that_; 35 PyramidReader& that_;
36 unsigned int tileX_; 36 unsigned int tileX_;
37 unsigned int tileY_; 37 unsigned int tileY_;
38 bool hasRawTile_; 38 bool hasRawTile_;
39 std::string rawTile_; 39 std::string rawTile_;
40 ImageCompression rawTileCompression_;
40 41
41 std::auto_ptr<Orthanc::ImageAccessor> decoded_; 42 std::auto_ptr<Orthanc::ImageAccessor> decoded_;
42 43
43 bool IsRepaintNeeded() const 44 bool IsRepaintNeeded() const
44 { 45 {
94 tileX_(tileX), 95 tileX_(tileX),
95 tileY_(tileY) 96 tileY_(tileY)
96 { 97 {
97 if (!that_.parameters_.IsForceReencode() && 98 if (!that_.parameters_.IsForceReencode() &&
98 !IsRepaintNeeded() && 99 !IsRepaintNeeded() &&
99 that_.source_.ReadRawTile(rawTile_, that_.level_, tileX, tileY)) 100 that_.source_.ReadRawTile(rawTile_, rawTileCompression_, that_.level_, tileX, tileY))
100 { 101 {
101 hasRawTile_ = true; 102 hasRawTile_ = true;
102 } 103 }
103 else 104 else
104 { 105 {
111 112
112 RepaintBackground(); 113 RepaintBackground();
113 } 114 }
114 } 115 }
115 116
116 bool HasRawTile() const 117 bool HasRawTile(ImageCompression& compression) const
117 { 118 {
118 return hasRawTile_; 119 if (hasRawTile_)
120 {
121 compression = rawTileCompression_;
122 return true;
123 }
124 else
125 {
126 return false;
127 }
119 } 128 }
120 129
121 const std::string& GetRawTile() const 130 const std::string& GetRawTile() const
122 { 131 {
123 if (hasRawTile_) 132 if (hasRawTile_)
137 if (!hasRawTile_) 146 if (!hasRawTile_)
138 { 147 {
139 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); 148 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
140 } 149 }
141 150
142 decoded_.reset(ImageToolbox::DecodeTile(rawTile_, that_.source_.GetImageCompression())); 151 decoded_.reset(ImageToolbox::DecodeTile(rawTile_, rawTileCompression_));
143 if (decoded_.get() == NULL) 152 if (decoded_.get() == NULL)
144 { 153 {
145 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); 154 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
146 } 155 }
147 156
178 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize); 187 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize);
179 } 188 }
180 } 189 }
181 190
182 191
183 void PyramidReader::CheckTileSize(const std::string& tile) const 192 void PyramidReader::CheckTileSize(const std::string& tile,
193 ImageCompression compression) const
184 { 194 {
185 if (parameters_.IsSafetyCheck()) 195 if (parameters_.IsSafetyCheck())
186 { 196 {
187 std::auto_ptr<Orthanc::ImageAccessor> decoded(ImageToolbox::DecodeTile(tile, source_.GetImageCompression())); 197 std::auto_ptr<Orthanc::ImageAccessor> decoded(ImageToolbox::DecodeTile(tile, compression));
188 CheckTileSize(*decoded); 198 CheckTileSize(*decoded);
189 } 199 }
190 } 200 }
191 201
192 202
223 level_(level), 233 level_(level),
224 levelWidth_(source.GetLevelWidth(level)), 234 levelWidth_(source.GetLevelWidth(level)),
225 levelHeight_(source.GetLevelHeight(level)), 235 levelHeight_(source.GetLevelHeight(level)),
226 sourceTileWidth_(source.GetTileWidth()), 236 sourceTileWidth_(source.GetTileWidth()),
227 sourceTileHeight_(source.GetTileHeight()), 237 sourceTileHeight_(source.GetTileHeight()),
228 targetTileWidth_(targetTileWidth), 238 targetTileWidth_(targetTileWidth),
229 targetTileHeight_(targetTileHeight), 239 targetTileHeight_(targetTileHeight),
230 parameters_(parameters) 240 parameters_(parameters)
231 { 241 {
232 if (sourceTileWidth_ % targetTileWidth_ != 0 || 242 if (sourceTileWidth_ % targetTileWidth_ != 0 ||
233 sourceTileHeight_ % targetTileHeight_ != 0) 243 sourceTileHeight_ % targetTileHeight_ != 0)
234 { 244 {
235 LOG(ERROR) << "When resampling the tile size, it must be a integer divisor of the original tile size"; 245 LOG(ERROR) << "When resampling the tile size, it must be a integer divisor of the original tile size";
246 delete it->second; 256 delete it->second;
247 } 257 }
248 } 258 }
249 259
250 260
251 const std::string* PyramidReader::GetRawTile(unsigned int tileX, 261 const std::string* PyramidReader::GetRawTile(ImageCompression& compression,
262 unsigned int tileX,
252 unsigned int tileY) 263 unsigned int tileY)
253 { 264 {
254 if (sourceTileWidth_ != targetTileWidth_ || 265 if (sourceTileWidth_ != targetTileWidth_ ||
255 sourceTileHeight_ != targetTileHeight_) 266 sourceTileHeight_ != targetTileHeight_)
256 { 267 {
257 return NULL; 268 return NULL;
258 } 269 }
259 270
260 SourceTile& source = AccessSourceTile(MapTargetToSourceLocation(tileX, tileY)); 271 SourceTile& source = AccessSourceTile(MapTargetToSourceLocation(tileX, tileY));
261 if (source.HasRawTile()) 272
262 { 273 if (source.HasRawTile(compression))
263 CheckTileSize(source.GetRawTile()); 274 {
275 CheckTileSize(source.GetRawTile(), compression);
264 return &source.GetRawTile(); 276 return &source.GetRawTile();
265 } 277 }
266 else 278 else
267 { 279 {
268 return NULL; 280 return NULL;