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