1/*
2 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11
12#include "blockd.h"
13
14typedef enum
15{
16    PRED = 0,
17    DEST = 1
18} BLOCKSET;
19
20static void setup_block
21(
22    BLOCKD *b,
23    int mv_stride,
24    unsigned char **base,
25    int Stride,
26    int offset,
27    BLOCKSET bs
28)
29{
30
31    if (bs == DEST)
32    {
33        b->dst_stride = Stride;
34        b->dst = offset;
35        b->base_dst = base;
36    }
37    else
38    {
39        b->pre_stride = Stride;
40        b->pre = offset;
41        b->base_pre = base;
42    }
43
44}
45
46
47static void setup_macroblock(MACROBLOCKD *x, BLOCKSET bs)
48{
49    int block;
50
51    unsigned char **y, **u, **v;
52
53    if (bs == DEST)
54    {
55        y = &x->dst.y_buffer;
56        u = &x->dst.u_buffer;
57        v = &x->dst.v_buffer;
58    }
59    else
60    {
61        y = &x->pre.y_buffer;
62        u = &x->pre.u_buffer;
63        v = &x->pre.v_buffer;
64    }
65
66    for (block = 0; block < 16; block++) /* y blocks */
67    {
68        setup_block(&x->block[block], x->dst.y_stride, y, x->dst.y_stride,
69                        (block >> 2) * 4 * x->dst.y_stride + (block & 3) * 4, bs);
70    }
71
72    for (block = 16; block < 20; block++) /* U and V blocks */
73    {
74        setup_block(&x->block[block], x->dst.uv_stride, u, x->dst.uv_stride,
75                        ((block - 16) >> 1) * 4 * x->dst.uv_stride + (block & 1) * 4, bs);
76
77        setup_block(&x->block[block+4], x->dst.uv_stride, v, x->dst.uv_stride,
78                        ((block - 16) >> 1) * 4 * x->dst.uv_stride + (block & 1) * 4, bs);
79    }
80}
81
82void vp8_setup_block_dptrs(MACROBLOCKD *x)
83{
84    int r, c;
85
86    for (r = 0; r < 4; r++)
87    {
88        for (c = 0; c < 4; c++)
89        {
90            x->block[r*4+c].diff      = &x->diff[r * 4 * 16 + c * 4];
91            x->block[r*4+c].predictor = x->predictor + r * 4 * 16 + c * 4;
92        }
93    }
94
95    for (r = 0; r < 2; r++)
96    {
97        for (c = 0; c < 2; c++)
98        {
99            x->block[16+r*2+c].diff      = &x->diff[256 + r * 4 * 8 + c * 4];
100            x->block[16+r*2+c].predictor = x->predictor + 256 + r * 4 * 8 + c * 4;
101
102        }
103    }
104
105    for (r = 0; r < 2; r++)
106    {
107        for (c = 0; c < 2; c++)
108        {
109            x->block[20+r*2+c].diff      = &x->diff[320+ r * 4 * 8 + c * 4];
110            x->block[20+r*2+c].predictor = x->predictor + 320 + r * 4 * 8 + c * 4;
111
112        }
113    }
114
115    x->block[24].diff = &x->diff[384];
116
117    for (r = 0; r < 25; r++)
118    {
119        x->block[r].qcoeff  = x->qcoeff  + r * 16;
120        x->block[r].dqcoeff = x->dqcoeff + r * 16;
121    }
122}
123
124void vp8_build_block_doffsets(MACROBLOCKD *x)
125{
126
127    /* handle the destination pitch features */
128    setup_macroblock(x, DEST);
129    setup_macroblock(x, PRED);
130}
131