@@ -261,4 +261,89 @@ SyncGenerator<ProgressionData> PositionComponentResolutionLevelLayerProgressionI
261
261
}
262
262
}
263
263
264
+ ComponentPositionResolutionLevelLayerProgressionIterator::ComponentPositionResolutionLevelLayerProgressionIterator (
265
+ int layer_count, int component_count, Function<int (int resolution_level, int component)> precinct_count,
266
+ Function<int (int component)> XRsiz, Function<int (int component)> YRsiz,
267
+ Function<int (int resolution_level, int component)> PPx, Function<int (int resolution_level, int component)> PPy,
268
+ Function<int (int component)> N_L,
269
+ Function<int (int resolution_level, int component)> num_precincts_wide,
270
+ Gfx::IntRect tile_rect,
271
+ Function<IntRect(int resolution_level, int component)> ll_rect)
272
+ : m_layer_count(layer_count)
273
+ , m_component_count(component_count)
274
+ , m_precinct_count(move(precinct_count))
275
+ , m_XRsiz(move(XRsiz))
276
+ , m_YRsiz(move(YRsiz))
277
+ , m_PPx(move(PPx))
278
+ , m_PPy(move(PPy))
279
+ , m_N_L(move(N_L))
280
+ , m_num_precincts_wide(move(num_precincts_wide))
281
+ , m_tile_rect(tile_rect)
282
+ , m_ll_rect(move(ll_rect))
283
+ , m_generator(generator())
284
+ {
285
+ m_next = m_generator.next ();
286
+ }
287
+
288
+ bool ComponentPositionResolutionLevelLayerProgressionIterator::has_next () const
289
+ {
290
+ return m_next.has_value ();
291
+ }
292
+
293
+ ProgressionData ComponentPositionResolutionLevelLayerProgressionIterator::next ()
294
+ {
295
+ auto result = m_next;
296
+ m_next = m_generator.next ();
297
+ return result.value ();
298
+ }
299
+
300
+ SyncGenerator<ProgressionData> ComponentPositionResolutionLevelLayerProgressionIterator::generator ()
301
+ {
302
+ auto compute_precinct = [&](int x, int y, int r, int i) {
303
+ // (B-20)
304
+ auto const trx0 = m_ll_rect (r, i).left ();
305
+ auto const try0 = m_ll_rect (r, i).top ();
306
+ auto const x_offset = floor_div (ceil_div (x, m_XRsiz (i) * (1 << (m_N_L (i) - r))), 1 << m_PPx (r, i)) - floor_div (trx0, 1 << m_PPx (r, i));
307
+ auto const y_offset = floor_div (ceil_div (y, m_YRsiz (i) * (1 << (m_N_L (i) - r))), 1 << m_PPy (r, i)) - floor_div (try0, 1 << m_PPy (r, i));
308
+ return x_offset + m_num_precincts_wide (r, i) * y_offset;
309
+ };
310
+ // B.12.1.5 Component-position-resolution level-layer progression
311
+ // "for each i = 0,..., Csiz – 1
312
+ // for each y = ty0,..., ty1 – 1,
313
+ // for each x = tx0,..., tx1 – 1,
314
+ // for each r = 0,..., NL where NL is the number of decomposition levels for component i,
315
+ // if ((y divisible by YRsiz(i) * 2 ** (PPy(r, i) + N_L(i) - r) OR
316
+ // ((y == ty0) AND (try0 * 2 ** (N_L(i) - r) NOT divisible by 2 ** (PPy(r, i) + N_L(i) - r))))
317
+ // if ((x divisible by XRsiz(i) * 2 ** (PPx(r, i) + N_L(i) - r) OR
318
+ // ((x == tx0) AND (trx0 * 2 ** (N_L(i) - r) NOT divisible by 2 ** (PPx(r, i) + N_L(i) - r))))
319
+ // for the next precinct, k, if one exists, in the sequence shown in Figure B.8
320
+ // for each l = 0,..., L – 1
321
+ // packet for component i, resolution level r, layer l, and precinct k."
322
+ // The motivation for this loop is to walk corresponding precincts in different resolution levels at the same time,
323
+ // even if the resolution levels have different precinct counts.
324
+ auto const tx0 = m_tile_rect.left ();
325
+ auto const ty0 = m_tile_rect.top ();
326
+ for (int i = 0 ; i < m_component_count; ++i) {
327
+ for (int y = ty0; y < m_tile_rect.bottom (); ++y) {
328
+ for (int x = tx0; x < m_tile_rect.right (); ++x) {
329
+ for (int r = 0 ; r <= m_N_L (i); ++r) {
330
+ auto const trx0 = m_ll_rect (r, i).left ();
331
+ auto const try0 = m_ll_rect (r, i).top ();
332
+ if ((y % (m_YRsiz (i) * (1 << (m_PPy (r, i) + m_N_L (i) - r))) == 0 )
333
+ || ((y == ty0) && (try0 * (1 << (m_N_L (i) - r)) % (1 << (m_PPy (r, i) + m_N_L (i) - r)) != 0 ))) {
334
+ if ((x % (m_XRsiz (i) * (1 << (m_PPx (r, i) + m_N_L (i) - r))) == 0 )
335
+ || ((x == tx0) && (trx0 * (1 << (m_N_L (i) - r)) % (1 << (m_PPx (r, i) + m_N_L (i) - r)) != 0 ))) {
336
+ if (int k = compute_precinct (x, y, r, i); k < m_precinct_count (r, i)) {
337
+ for (int l = 0 ; l < m_layer_count; ++l) {
338
+ co_yield ProgressionData { l, r, i, k };
339
+ }
340
+ }
341
+ }
342
+ }
343
+ }
344
+ }
345
+ }
346
+ }
347
+ }
348
+
264
349
}
0 commit comments