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 "vpx_config.h"
13#include "vp8_rtcd.h"
14#include "vpx_mem/vpx_mem.h"
15#include "blockd.h"
16
17void vp8_build_intra_predictors_mby_s_c(MACROBLOCKD *x,
18                                          unsigned char * yabove_row,
19                                          unsigned char * yleft,
20                                          int left_stride,
21                                          unsigned char * ypred_ptr,
22                                          int y_stride)
23{
24    unsigned char yleft_col[16];
25    unsigned char ytop_left = yabove_row[-1];
26    int r, c, i;
27
28    for (i = 0; i < 16; i++)
29    {
30        yleft_col[i] = yleft[i* left_stride];
31    }
32
33    /* for Y */
34    switch (x->mode_info_context->mbmi.mode)
35    {
36    case DC_PRED:
37    {
38        int expected_dc;
39        int shift;
40        int average = 0;
41
42
43        if (x->up_available || x->left_available)
44        {
45            if (x->up_available)
46            {
47                for (i = 0; i < 16; i++)
48                {
49                    average += yabove_row[i];
50                }
51            }
52
53            if (x->left_available)
54            {
55
56                for (i = 0; i < 16; i++)
57                {
58                    average += yleft_col[i];
59                }
60
61            }
62
63
64
65            shift = 3 + x->up_available + x->left_available;
66            expected_dc = (average + (1 << (shift - 1))) >> shift;
67        }
68        else
69        {
70            expected_dc = 128;
71        }
72
73        /*vpx_memset(ypred_ptr, expected_dc, 256);*/
74        for (r = 0; r < 16; r++)
75        {
76            vpx_memset(ypred_ptr, expected_dc, 16);
77            ypred_ptr += y_stride;
78        }
79    }
80    break;
81    case V_PRED:
82    {
83
84        for (r = 0; r < 16; r++)
85        {
86
87            ((int *)ypred_ptr)[0] = ((int *)yabove_row)[0];
88            ((int *)ypred_ptr)[1] = ((int *)yabove_row)[1];
89            ((int *)ypred_ptr)[2] = ((int *)yabove_row)[2];
90            ((int *)ypred_ptr)[3] = ((int *)yabove_row)[3];
91            ypred_ptr += y_stride;
92        }
93    }
94    break;
95    case H_PRED:
96    {
97
98        for (r = 0; r < 16; r++)
99        {
100
101            vpx_memset(ypred_ptr, yleft_col[r], 16);
102            ypred_ptr += y_stride;
103        }
104
105    }
106    break;
107    case TM_PRED:
108    {
109
110        for (r = 0; r < 16; r++)
111        {
112            for (c = 0; c < 16; c++)
113            {
114                int pred =  yleft_col[r] + yabove_row[ c] - ytop_left;
115
116                if (pred < 0)
117                    pred = 0;
118
119                if (pred > 255)
120                    pred = 255;
121
122                ypred_ptr[c] = pred;
123            }
124
125            ypred_ptr += y_stride;
126        }
127
128    }
129    break;
130    case B_PRED:
131    case NEARESTMV:
132    case NEARMV:
133    case ZEROMV:
134    case NEWMV:
135    case SPLITMV:
136    case MB_MODE_COUNT:
137        break;
138    }
139}
140
141void vp8_build_intra_predictors_mbuv_s_c(MACROBLOCKD *x,
142                                         unsigned char * uabove_row,
143                                         unsigned char * vabove_row,
144                                         unsigned char * uleft,
145                                         unsigned char * vleft,
146                                         int left_stride,
147                                         unsigned char * upred_ptr,
148                                         unsigned char * vpred_ptr,
149                                         int pred_stride)
150{
151    unsigned char uleft_col[8];
152    unsigned char utop_left = uabove_row[-1];
153    unsigned char vleft_col[8];
154    unsigned char vtop_left = vabove_row[-1];
155
156    int i, j;
157
158    for (i = 0; i < 8; i++)
159    {
160        uleft_col[i] = uleft [i* left_stride];
161        vleft_col[i] = vleft [i* left_stride];
162    }
163
164    switch (x->mode_info_context->mbmi.uv_mode)
165    {
166    case DC_PRED:
167    {
168        int expected_udc;
169        int expected_vdc;
170        int shift;
171        int Uaverage = 0;
172        int Vaverage = 0;
173
174        if (x->up_available)
175        {
176            for (i = 0; i < 8; i++)
177            {
178                Uaverage += uabove_row[i];
179                Vaverage += vabove_row[i];
180            }
181        }
182
183        if (x->left_available)
184        {
185            for (i = 0; i < 8; i++)
186            {
187                Uaverage += uleft_col[i];
188                Vaverage += vleft_col[i];
189            }
190        }
191
192        if (!x->up_available && !x->left_available)
193        {
194            expected_udc = 128;
195            expected_vdc = 128;
196        }
197        else
198        {
199            shift = 2 + x->up_available + x->left_available;
200            expected_udc = (Uaverage + (1 << (shift - 1))) >> shift;
201            expected_vdc = (Vaverage + (1 << (shift - 1))) >> shift;
202        }
203
204
205        /*vpx_memset(upred_ptr,expected_udc,64);*/
206        /*vpx_memset(vpred_ptr,expected_vdc,64);*/
207        for (i = 0; i < 8; i++)
208        {
209            vpx_memset(upred_ptr, expected_udc, 8);
210            vpx_memset(vpred_ptr, expected_vdc, 8);
211            upred_ptr += pred_stride;
212            vpred_ptr += pred_stride;
213        }
214    }
215    break;
216    case V_PRED:
217    {
218        for (i = 0; i < 8; i++)
219        {
220            vpx_memcpy(upred_ptr, uabove_row, 8);
221            vpx_memcpy(vpred_ptr, vabove_row, 8);
222            upred_ptr += pred_stride;
223            vpred_ptr += pred_stride;
224        }
225
226    }
227    break;
228    case H_PRED:
229    {
230        for (i = 0; i < 8; i++)
231        {
232            vpx_memset(upred_ptr, uleft_col[i], 8);
233            vpx_memset(vpred_ptr, vleft_col[i], 8);
234            upred_ptr += pred_stride;
235            vpred_ptr += pred_stride;
236        }
237    }
238
239    break;
240    case TM_PRED:
241    {
242        for (i = 0; i < 8; i++)
243        {
244            for (j = 0; j < 8; j++)
245            {
246                int predu = uleft_col[i] + uabove_row[j] - utop_left;
247                int predv = vleft_col[i] + vabove_row[j] - vtop_left;
248
249                if (predu < 0)
250                    predu = 0;
251
252                if (predu > 255)
253                    predu = 255;
254
255                if (predv < 0)
256                    predv = 0;
257
258                if (predv > 255)
259                    predv = 255;
260
261                upred_ptr[j] = predu;
262                vpred_ptr[j] = predv;
263            }
264
265            upred_ptr += pred_stride;
266            vpred_ptr += pred_stride;
267        }
268
269    }
270    break;
271    case B_PRED:
272    case NEARESTMV:
273    case NEARMV:
274    case ZEROMV:
275    case NEWMV:
276    case SPLITMV:
277    case MB_MODE_COUNT:
278        break;
279    }
280}
281