Revision a16389c1

View differences:

libavcodec/vp3.c
260 260
 */
261 261
static int init_block_mapping(Vp3DecodeContext *s)
262 262
{
263
    int i, j;
264
    signed int hilbert_walk_mb[4];
265

  
266
    int current_fragment = 0;
267
    int current_width = 0;
268
    int current_height = 0;
269
    int right_edge = 0;
270
    int bottom_edge = 0;
271
    int superblock_row_inc = 0;
272
    int mapping_index = 0;
273

  
274
    static const signed char travel_width[16] = {
275
         1,  1,  0, -1,
276
         0,  0,  1,  0,
277
         1,  0,  1,  0,
278
         0, -1,  0,  1
279
    };
280

  
281
    static const signed char travel_height[16] = {
282
         0,  0,  1,  0,
283
         1,  1,  0, -1,
284
         0,  1,  0, -1,
285
        -1,  0, -1,  0
286
    };
287

  
288
    hilbert_walk_mb[0] = 1;
289
    hilbert_walk_mb[1] = s->macroblock_width;
290
    hilbert_walk_mb[2] = 1;
291
    hilbert_walk_mb[3] = -s->macroblock_width;
292

  
293
    /* iterate through each superblock (all planes) and map the fragments */
294
    for (i = 0; i < s->superblock_count; i++) {
295
        /* time to re-assign the limits? */
296
        if (i == 0) {
297

  
298
            /* start of Y superblocks */
299
            right_edge = s->fragment_width;
300
            bottom_edge = s->fragment_height;
301
            current_width = -1;
302
            current_height = 0;
303
            superblock_row_inc = 3 * s->fragment_width -
304
                (s->y_superblock_width * 4 - s->fragment_width);
305

  
306
            /* the first operation for this variable is to advance by 1 */
307
            current_fragment = -1;
308

  
309
        } else if (i == s->u_superblock_start) {
310

  
311
            /* start of U superblocks */
312
            right_edge = s->fragment_width / 2;
313
            bottom_edge = s->fragment_height / 2;
314
            current_width = -1;
315
            current_height = 0;
316
            superblock_row_inc = 3 * (s->fragment_width / 2) -
317
                (s->c_superblock_width * 4 - s->fragment_width / 2);
318

  
319
            /* the first operation for this variable is to advance by 1 */
320
            current_fragment = s->fragment_start[1] - 1;
321

  
322
        } else if (i == s->v_superblock_start) {
323

  
324
            /* start of V superblocks */
325
            right_edge = s->fragment_width / 2;
326
            bottom_edge = s->fragment_height / 2;
327
            current_width = -1;
328
            current_height = 0;
329
            superblock_row_inc = 3 * (s->fragment_width / 2) -
330
                (s->c_superblock_width * 4 - s->fragment_width / 2);
331

  
332
            /* the first operation for this variable is to advance by 1 */
333
            current_fragment = s->fragment_start[2] - 1;
334

  
335
        }
336

  
337
        if (current_width >= right_edge - 1) {
338
            /* reset width and move to next superblock row */
339
            current_width = -1;
340
            current_height += 4;
341

  
342
            /* fragment is now at the start of a new superblock row */
343
            current_fragment += superblock_row_inc;
344
        }
263
    int sb_x, sb_y, plane;
264
    int x, y, i, j = 0;
345 265

  
346
        /* iterate through all 16 fragments in a superblock */
347
        for (j = 0; j < 16; j++) {
348
            current_fragment += travel_width[j] + right_edge * travel_height[j];
349
            current_width += travel_width[j];
350
            current_height += travel_height[j];
351

  
352
            /* check if the fragment is in bounds */
353
            if ((current_width < right_edge) &&
354
                (current_height < bottom_edge)) {
355
                s->superblock_fragments[mapping_index] = current_fragment;
356
            } else {
357
                s->superblock_fragments[mapping_index] = -1;
358
            }
359

  
360
            mapping_index++;
361
        }
266
    for (plane = 0; plane < 3; plane++) {
267
        int sb_width    = plane ? s->c_superblock_width  : s->y_superblock_width;
268
        int sb_height   = plane ? s->c_superblock_height : s->y_superblock_height;
269
        int frag_width  = s->fragment_width  >> !!plane;
270
        int frag_height = s->fragment_height >> !!plane;
271

  
272
        for (sb_y = 0; sb_y < sb_height; sb_y++)
273
            for (sb_x = 0; sb_x < sb_width; sb_x++)
274
                for (i = 0; i < 16; i++) {
275
                    x = 4*sb_x + hilbert_offset[i][0];
276
                    y = 4*sb_y + hilbert_offset[i][1];
277

  
278
                    if (x < frag_width && y < frag_height)
279
                        s->superblock_fragments[j++] = s->fragment_start[plane] + y*frag_width + x;
280
                    else
281
                        s->superblock_fragments[j++] = -1;
282
                }
362 283
    }
363 284

  
364 285
    return 0;  /* successful path out */

Also available in: Unified diff