- int i, j;
- signed int hilbert_walk_mb[4];
-
- int current_fragment = 0;
- int current_width = 0;
- int current_height = 0;
- int right_edge = 0;
- int bottom_edge = 0;
- int superblock_row_inc = 0;
- int mapping_index = 0;
-
- int current_macroblock;
- int c_fragment;
-
- static const signed char travel_width[16] = {
- 1, 1, 0, -1,
- 0, 0, 1, 0,
- 1, 0, 1, 0,
- 0, -1, 0, 1
- };
-
- static const signed char travel_height[16] = {
- 0, 0, 1, 0,
- 1, 1, 0, -1,
- 0, 1, 0, -1,
- -1, 0, -1, 0
- };
-
- static const signed char travel_width_mb[4] = {
- 1, 0, 1, 0
- };
-
- static const signed char travel_height_mb[4] = {
- 0, 1, 0, -1
- };
-
- hilbert_walk_mb[0] = 1;
- hilbert_walk_mb[1] = s->macroblock_width;
- hilbert_walk_mb[2] = 1;
- hilbert_walk_mb[3] = -s->macroblock_width;
-
- /* iterate through each superblock (all planes) and map the fragments */
- for (i = 0; i < s->superblock_count; i++) {
- /* time to re-assign the limits? */
- if (i == 0) {
-
- /* start of Y superblocks */
- right_edge = s->fragment_width;
- bottom_edge = s->fragment_height;
- current_width = -1;
- current_height = 0;
- superblock_row_inc = 3 * s->fragment_width -
- (s->y_superblock_width * 4 - s->fragment_width);
-
- /* the first operation for this variable is to advance by 1 */
- current_fragment = -1;
-
- } else if (i == s->u_superblock_start) {
-
- /* start of U superblocks */
- right_edge = s->fragment_width / 2;
- bottom_edge = s->fragment_height / 2;
- current_width = -1;
- current_height = 0;
- superblock_row_inc = 3 * (s->fragment_width / 2) -
- (s->c_superblock_width * 4 - s->fragment_width / 2);
-
- /* the first operation for this variable is to advance by 1 */
- current_fragment = s->fragment_start[1] - 1;
-
- } else if (i == s->v_superblock_start) {
-
- /* start of V superblocks */
- right_edge = s->fragment_width / 2;
- bottom_edge = s->fragment_height / 2;
- current_width = -1;
- current_height = 0;
- superblock_row_inc = 3 * (s->fragment_width / 2) -
- (s->c_superblock_width * 4 - s->fragment_width / 2);
-
- /* the first operation for this variable is to advance by 1 */
- current_fragment = s->fragment_start[2] - 1;
-
- }
-
- if (current_width >= right_edge - 1) {
- /* reset width and move to next superblock row */
- current_width = -1;
- current_height += 4;
-
- /* 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;
- }