- /* fragment is now at the start of a new superblock row */
- current_fragment += superblock_row_inc;
- }
-
- /* iterate through all 16 fragments in a superblock */
- for (j = 0; j < 16; j++) {
- current_fragment += travel_width[j] + right_edge * travel_height[j];
- current_width += travel_width[j];
- current_height += travel_height[j];
-
- /* check if the fragment is in bounds */
- if ((current_width < right_edge) &&
- (current_height < bottom_edge)) {
- s->superblock_fragments[mapping_index] = current_fragment;
- } else {
- s->superblock_fragments[mapping_index] = -1;
- }
-
- mapping_index++;
- }
- }
-
- /* initialize the superblock <-> macroblock mapping; iterate through
- * all of the Y plane superblocks to build this mapping */
- right_edge = s->macroblock_width;
- bottom_edge = s->macroblock_height;
- current_width = -1;
- current_height = 0;
- superblock_row_inc = s->macroblock_width -
- (s->y_superblock_width * 2 - s->macroblock_width);
- mapping_index = 0;
- current_macroblock = -1;
- for (i = 0; i < s->u_superblock_start; i++) {
-
- if (current_width >= right_edge - 1) {
- /* reset width and move to next superblock row */
- current_width = -1;
- current_height += 2;
-
- /* macroblock is now at the start of a new superblock row */
- current_macroblock += superblock_row_inc;
- }
-
- /* iterate through each potential macroblock in the superblock */
- for (j = 0; j < 4; j++) {
- current_macroblock += hilbert_walk_mb[j];
- current_width += travel_width_mb[j];
- current_height += travel_height_mb[j];
-
- /* check if the macroblock is in bounds */
- if ((current_width < right_edge) &&
- (current_height < bottom_edge)) {
- s->superblock_macroblocks[mapping_index] = current_macroblock;
- } else {
- s->superblock_macroblocks[mapping_index] = -1;
- }
-
- mapping_index++;
- }
- }
-
- /* initialize the macroblock <-> fragment mapping */
- current_fragment = 0;
- current_macroblock = 0;
- mapping_index = 0;
- for (i = 0; i < s->fragment_height; i += 2) {
-
- for (j = 0; j < s->fragment_width; j += 2) {
-
- s->all_fragments[current_fragment].macroblock = current_macroblock;
- s->macroblock_fragments[mapping_index++] = current_fragment;
-
- if (j + 1 < s->fragment_width) {
- s->all_fragments[current_fragment + 1].macroblock = current_macroblock;
- s->macroblock_fragments[mapping_index++] = current_fragment + 1;
- } else
- s->macroblock_fragments[mapping_index++] = -1;
-
- if (i + 1 < s->fragment_height) {
- s->all_fragments[current_fragment + s->fragment_width].macroblock =
- current_macroblock;
- s->macroblock_fragments[mapping_index++] =
- current_fragment + s->fragment_width;
- } else
- s->macroblock_fragments[mapping_index++] = -1;
-
- if ((j + 1 < s->fragment_width) && (i + 1 < s->fragment_height)) {
- s->all_fragments[current_fragment + s->fragment_width + 1].macroblock =
- current_macroblock;
- s->macroblock_fragments[mapping_index++] =
- current_fragment + s->fragment_width + 1;
- } else
- s->macroblock_fragments[mapping_index++] = -1;
-
- /* C planes */
- c_fragment = s->fragment_start[1] +
- (i * s->fragment_width / 4) + (j / 2);
- s->all_fragments[c_fragment].macroblock = s->macroblock_count;
- s->macroblock_fragments[mapping_index++] = c_fragment;
-
- c_fragment = s->fragment_start[2] +
- (i * s->fragment_width / 4) + (j / 2);
- s->all_fragments[c_fragment].macroblock = s->macroblock_count;
- s->macroblock_fragments[mapping_index++] = c_fragment;
-
- if (j + 2 <= s->fragment_width)
- current_fragment += 2;
- else
- current_fragment++;
- current_macroblock++;
- }
-
- current_fragment += s->fragment_width;
+ for (plane = 0; plane < 3; plane++) {
+ int sb_width = plane ? s->c_superblock_width : s->y_superblock_width;
+ int sb_height = plane ? s->c_superblock_height : s->y_superblock_height;
+ int frag_width = s->fragment_width[!!plane];
+ int frag_height = s->fragment_height[!!plane];
+
+ for (sb_y = 0; sb_y < sb_height; sb_y++)
+ for (sb_x = 0; sb_x < sb_width; sb_x++)
+ for (i = 0; i < 16; i++) {
+ x = 4*sb_x + hilbert_offset[i][0];
+ y = 4*sb_y + hilbert_offset[i][1];
+
+ if (x < frag_width && y < frag_height)
+ s->superblock_fragments[j++] = s->fragment_start[plane] + y*frag_width + x;
+ else
+ s->superblock_fragments[j++] = -1;
+ }