- else
- {
- // Slide right to the beginning of the next mip map block
- index = pow2_ceil(index, level_scale_power);
+
+ // Zoom in, and slide right until we encounter a change,
+ // and repeat until we reach min_level
+ while(1) {
+ assert(_mip_map[level].data);
+
+ const int level_scale_power =
+ (level + 1) * MipMapScalePower;
+ const uint64_t offset =
+ index >> level_scale_power;
+ assert(offset >= 0);
+
+ // Check if we reached the last block at this
+ // level, or if there was a change in this block
+ if(offset >= _mip_map[level].length ||
+ (get_subsample(level, offset) &
+ sig_mask)) {
+ // Zoom in unless we reached the minimum
+ // zoom
+ if(level == min_level)
+ break;
+
+ level--;
+ } else {
+ // Slide right to the beginning of the
+ // next mip map block
+ index = pow2_ceil(index + 1,
+ level_scale_power);
+ }