LCOV - code coverage report
Current view: top level - media/libvpx/libvpx/vp9/common - vp9_pred_common.c (source / functions) Hit Total Coverage
Test: output.info Lines: 0 180 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : 
       2             : /*
       3             :  *  Copyright (c) 2012 The WebM project authors. All Rights Reserved.
       4             :  *
       5             :  *  Use of this source code is governed by a BSD-style license
       6             :  *  that can be found in the LICENSE file in the root of the source
       7             :  *  tree. An additional intellectual property rights grant can be found
       8             :  *  in the file PATENTS.  All contributing project authors may
       9             :  *  be found in the AUTHORS file in the root of the source tree.
      10             :  */
      11             : 
      12             : #include "vp9/common/vp9_common.h"
      13             : #include "vp9/common/vp9_pred_common.h"
      14             : #include "vp9/common/vp9_seg_common.h"
      15             : 
      16           0 : int vp9_get_reference_mode_context(const VP9_COMMON *cm,
      17             :                                    const MACROBLOCKD *xd) {
      18             :   int ctx;
      19           0 :   const MODE_INFO *const above_mi = xd->above_mi;
      20           0 :   const MODE_INFO *const left_mi = xd->left_mi;
      21           0 :   const int has_above = !!above_mi;
      22           0 :   const int has_left = !!left_mi;
      23             :   // Note:
      24             :   // The mode info data structure has a one element border above and to the
      25             :   // left of the entries corresponding to real macroblocks.
      26             :   // The prediction flags in these dummy entries are initialized to 0.
      27           0 :   if (has_above && has_left) {  // both edges available
      28           0 :     if (!has_second_ref(above_mi) && !has_second_ref(left_mi))
      29             :       // neither edge uses comp pred (0/1)
      30           0 :       ctx = (above_mi->ref_frame[0] == cm->comp_fixed_ref) ^
      31           0 :             (left_mi->ref_frame[0] == cm->comp_fixed_ref);
      32           0 :     else if (!has_second_ref(above_mi))
      33             :       // one of two edges uses comp pred (2/3)
      34           0 :       ctx = 2 + (above_mi->ref_frame[0] == cm->comp_fixed_ref ||
      35           0 :                  !is_inter_block(above_mi));
      36           0 :     else if (!has_second_ref(left_mi))
      37             :       // one of two edges uses comp pred (2/3)
      38           0 :       ctx = 2 + (left_mi->ref_frame[0] == cm->comp_fixed_ref ||
      39           0 :                  !is_inter_block(left_mi));
      40             :     else  // both edges use comp pred (4)
      41           0 :       ctx = 4;
      42           0 :   } else if (has_above || has_left) {  // one edge available
      43           0 :     const MODE_INFO *edge_mi = has_above ? above_mi : left_mi;
      44             : 
      45           0 :     if (!has_second_ref(edge_mi))
      46             :       // edge does not use comp pred (0/1)
      47           0 :       ctx = edge_mi->ref_frame[0] == cm->comp_fixed_ref;
      48             :     else
      49             :       // edge uses comp pred (3)
      50           0 :       ctx = 3;
      51             :   } else {  // no edges available (1)
      52           0 :     ctx = 1;
      53             :   }
      54           0 :   assert(ctx >= 0 && ctx < COMP_INTER_CONTEXTS);
      55           0 :   return ctx;
      56             : }
      57             : 
      58             : // Returns a context number for the given MB prediction signal
      59           0 : int vp9_get_pred_context_comp_ref_p(const VP9_COMMON *cm,
      60             :                                     const MACROBLOCKD *xd) {
      61             :   int pred_context;
      62           0 :   const MODE_INFO *const above_mi = xd->above_mi;
      63           0 :   const MODE_INFO *const left_mi = xd->left_mi;
      64           0 :   const int above_in_image = !!above_mi;
      65           0 :   const int left_in_image = !!left_mi;
      66             : 
      67             :   // Note:
      68             :   // The mode info data structure has a one element border above and to the
      69             :   // left of the entries corresponding to real macroblocks.
      70             :   // The prediction flags in these dummy entries are initialized to 0.
      71           0 :   const int fix_ref_idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref];
      72           0 :   const int var_ref_idx = !fix_ref_idx;
      73             : 
      74           0 :   if (above_in_image && left_in_image) {  // both edges available
      75           0 :     const int above_intra = !is_inter_block(above_mi);
      76           0 :     const int left_intra = !is_inter_block(left_mi);
      77             : 
      78           0 :     if (above_intra && left_intra) {  // intra/intra (2)
      79           0 :       pred_context = 2;
      80           0 :     } else if (above_intra || left_intra) {  // intra/inter
      81           0 :       const MODE_INFO *edge_mi = above_intra ? left_mi : above_mi;
      82             : 
      83           0 :       if (!has_second_ref(edge_mi))  // single pred (1/3)
      84           0 :         pred_context = 1 + 2 * (edge_mi->ref_frame[0] != cm->comp_var_ref[1]);
      85             :       else  // comp pred (1/3)
      86           0 :         pred_context =
      87           0 :             1 + 2 * (edge_mi->ref_frame[var_ref_idx] != cm->comp_var_ref[1]);
      88             :     } else {  // inter/inter
      89           0 :       const int l_sg = !has_second_ref(left_mi);
      90           0 :       const int a_sg = !has_second_ref(above_mi);
      91           0 :       const MV_REFERENCE_FRAME vrfa =
      92             :           a_sg ? above_mi->ref_frame[0] : above_mi->ref_frame[var_ref_idx];
      93           0 :       const MV_REFERENCE_FRAME vrfl =
      94             :           l_sg ? left_mi->ref_frame[0] : left_mi->ref_frame[var_ref_idx];
      95             : 
      96           0 :       if (vrfa == vrfl && cm->comp_var_ref[1] == vrfa) {
      97           0 :         pred_context = 0;
      98           0 :       } else if (l_sg && a_sg) {  // single/single
      99           0 :         if ((vrfa == cm->comp_fixed_ref && vrfl == cm->comp_var_ref[0]) ||
     100           0 :             (vrfl == cm->comp_fixed_ref && vrfa == cm->comp_var_ref[0]))
     101           0 :           pred_context = 4;
     102           0 :         else if (vrfa == vrfl)
     103           0 :           pred_context = 3;
     104             :         else
     105           0 :           pred_context = 1;
     106           0 :       } else if (l_sg || a_sg) {  // single/comp
     107           0 :         const MV_REFERENCE_FRAME vrfc = l_sg ? vrfa : vrfl;
     108           0 :         const MV_REFERENCE_FRAME rfs = a_sg ? vrfa : vrfl;
     109           0 :         if (vrfc == cm->comp_var_ref[1] && rfs != cm->comp_var_ref[1])
     110           0 :           pred_context = 1;
     111           0 :         else if (rfs == cm->comp_var_ref[1] && vrfc != cm->comp_var_ref[1])
     112           0 :           pred_context = 2;
     113             :         else
     114           0 :           pred_context = 4;
     115           0 :       } else if (vrfa == vrfl) {  // comp/comp
     116           0 :         pred_context = 4;
     117             :       } else {
     118           0 :         pred_context = 2;
     119             :       }
     120             :     }
     121           0 :   } else if (above_in_image || left_in_image) {  // one edge available
     122           0 :     const MODE_INFO *edge_mi = above_in_image ? above_mi : left_mi;
     123             : 
     124           0 :     if (!is_inter_block(edge_mi)) {
     125           0 :       pred_context = 2;
     126             :     } else {
     127           0 :       if (has_second_ref(edge_mi))
     128           0 :         pred_context =
     129           0 :             4 * (edge_mi->ref_frame[var_ref_idx] != cm->comp_var_ref[1]);
     130             :       else
     131           0 :         pred_context = 3 * (edge_mi->ref_frame[0] != cm->comp_var_ref[1]);
     132             :     }
     133             :   } else {  // no edges available (2)
     134           0 :     pred_context = 2;
     135             :   }
     136           0 :   assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
     137             : 
     138           0 :   return pred_context;
     139             : }
     140             : 
     141           0 : int vp9_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) {
     142             :   int pred_context;
     143           0 :   const MODE_INFO *const above_mi = xd->above_mi;
     144           0 :   const MODE_INFO *const left_mi = xd->left_mi;
     145           0 :   const int has_above = !!above_mi;
     146           0 :   const int has_left = !!left_mi;
     147             :   // Note:
     148             :   // The mode info data structure has a one element border above and to the
     149             :   // left of the entries corresponding to real macroblocks.
     150             :   // The prediction flags in these dummy entries are initialized to 0.
     151           0 :   if (has_above && has_left) {  // both edges available
     152           0 :     const int above_intra = !is_inter_block(above_mi);
     153           0 :     const int left_intra = !is_inter_block(left_mi);
     154             : 
     155           0 :     if (above_intra && left_intra) {  // intra/intra
     156           0 :       pred_context = 2;
     157           0 :     } else if (above_intra || left_intra) {  // intra/inter or inter/intra
     158           0 :       const MODE_INFO *edge_mi = above_intra ? left_mi : above_mi;
     159           0 :       if (!has_second_ref(edge_mi))
     160           0 :         pred_context = 4 * (edge_mi->ref_frame[0] == LAST_FRAME);
     161             :       else
     162           0 :         pred_context = 1 + (edge_mi->ref_frame[0] == LAST_FRAME ||
     163           0 :                             edge_mi->ref_frame[1] == LAST_FRAME);
     164             :     } else {  // inter/inter
     165           0 :       const int above_has_second = has_second_ref(above_mi);
     166           0 :       const int left_has_second = has_second_ref(left_mi);
     167           0 :       const MV_REFERENCE_FRAME above0 = above_mi->ref_frame[0];
     168           0 :       const MV_REFERENCE_FRAME above1 = above_mi->ref_frame[1];
     169           0 :       const MV_REFERENCE_FRAME left0 = left_mi->ref_frame[0];
     170           0 :       const MV_REFERENCE_FRAME left1 = left_mi->ref_frame[1];
     171             : 
     172           0 :       if (above_has_second && left_has_second) {
     173           0 :         pred_context = 1 + (above0 == LAST_FRAME || above1 == LAST_FRAME ||
     174           0 :                             left0 == LAST_FRAME || left1 == LAST_FRAME);
     175           0 :       } else if (above_has_second || left_has_second) {
     176           0 :         const MV_REFERENCE_FRAME rfs = !above_has_second ? above0 : left0;
     177           0 :         const MV_REFERENCE_FRAME crf1 = above_has_second ? above0 : left0;
     178           0 :         const MV_REFERENCE_FRAME crf2 = above_has_second ? above1 : left1;
     179             : 
     180           0 :         if (rfs == LAST_FRAME)
     181           0 :           pred_context = 3 + (crf1 == LAST_FRAME || crf2 == LAST_FRAME);
     182             :         else
     183           0 :           pred_context = (crf1 == LAST_FRAME || crf2 == LAST_FRAME);
     184             :       } else {
     185           0 :         pred_context = 2 * (above0 == LAST_FRAME) + 2 * (left0 == LAST_FRAME);
     186             :       }
     187             :     }
     188           0 :   } else if (has_above || has_left) {  // one edge available
     189           0 :     const MODE_INFO *edge_mi = has_above ? above_mi : left_mi;
     190           0 :     if (!is_inter_block(edge_mi)) {  // intra
     191           0 :       pred_context = 2;
     192             :     } else {  // inter
     193           0 :       if (!has_second_ref(edge_mi))
     194           0 :         pred_context = 4 * (edge_mi->ref_frame[0] == LAST_FRAME);
     195             :       else
     196           0 :         pred_context = 1 + (edge_mi->ref_frame[0] == LAST_FRAME ||
     197           0 :                             edge_mi->ref_frame[1] == LAST_FRAME);
     198             :     }
     199             :   } else {  // no edges available
     200           0 :     pred_context = 2;
     201             :   }
     202             : 
     203           0 :   assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
     204           0 :   return pred_context;
     205             : }
     206             : 
     207           0 : int vp9_get_pred_context_single_ref_p2(const MACROBLOCKD *xd) {
     208             :   int pred_context;
     209           0 :   const MODE_INFO *const above_mi = xd->above_mi;
     210           0 :   const MODE_INFO *const left_mi = xd->left_mi;
     211           0 :   const int has_above = !!above_mi;
     212           0 :   const int has_left = !!left_mi;
     213             : 
     214             :   // Note:
     215             :   // The mode info data structure has a one element border above and to the
     216             :   // left of the entries corresponding to real macroblocks.
     217             :   // The prediction flags in these dummy entries are initialized to 0.
     218           0 :   if (has_above && has_left) {  // both edges available
     219           0 :     const int above_intra = !is_inter_block(above_mi);
     220           0 :     const int left_intra = !is_inter_block(left_mi);
     221             : 
     222           0 :     if (above_intra && left_intra) {  // intra/intra
     223           0 :       pred_context = 2;
     224           0 :     } else if (above_intra || left_intra) {  // intra/inter or inter/intra
     225           0 :       const MODE_INFO *edge_mi = above_intra ? left_mi : above_mi;
     226           0 :       if (!has_second_ref(edge_mi)) {
     227           0 :         if (edge_mi->ref_frame[0] == LAST_FRAME)
     228           0 :           pred_context = 3;
     229             :         else
     230           0 :           pred_context = 4 * (edge_mi->ref_frame[0] == GOLDEN_FRAME);
     231             :       } else {
     232           0 :         pred_context = 1 +
     233           0 :                        2 * (edge_mi->ref_frame[0] == GOLDEN_FRAME ||
     234           0 :                             edge_mi->ref_frame[1] == GOLDEN_FRAME);
     235             :       }
     236             :     } else {  // inter/inter
     237           0 :       const int above_has_second = has_second_ref(above_mi);
     238           0 :       const int left_has_second = has_second_ref(left_mi);
     239           0 :       const MV_REFERENCE_FRAME above0 = above_mi->ref_frame[0];
     240           0 :       const MV_REFERENCE_FRAME above1 = above_mi->ref_frame[1];
     241           0 :       const MV_REFERENCE_FRAME left0 = left_mi->ref_frame[0];
     242           0 :       const MV_REFERENCE_FRAME left1 = left_mi->ref_frame[1];
     243             : 
     244           0 :       if (above_has_second && left_has_second) {
     245           0 :         if (above0 == left0 && above1 == left1)
     246           0 :           pred_context =
     247           0 :               3 * (above0 == GOLDEN_FRAME || above1 == GOLDEN_FRAME ||
     248           0 :                    left0 == GOLDEN_FRAME || left1 == GOLDEN_FRAME);
     249             :         else
     250           0 :           pred_context = 2;
     251           0 :       } else if (above_has_second || left_has_second) {
     252           0 :         const MV_REFERENCE_FRAME rfs = !above_has_second ? above0 : left0;
     253           0 :         const MV_REFERENCE_FRAME crf1 = above_has_second ? above0 : left0;
     254           0 :         const MV_REFERENCE_FRAME crf2 = above_has_second ? above1 : left1;
     255             : 
     256           0 :         if (rfs == GOLDEN_FRAME)
     257           0 :           pred_context = 3 + (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME);
     258           0 :         else if (rfs == ALTREF_FRAME)
     259           0 :           pred_context = crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME;
     260             :         else
     261           0 :           pred_context = 1 + 2 * (crf1 == GOLDEN_FRAME || crf2 == GOLDEN_FRAME);
     262             :       } else {
     263           0 :         if (above0 == LAST_FRAME && left0 == LAST_FRAME) {
     264           0 :           pred_context = 3;
     265           0 :         } else if (above0 == LAST_FRAME || left0 == LAST_FRAME) {
     266           0 :           const MV_REFERENCE_FRAME edge0 =
     267             :               (above0 == LAST_FRAME) ? left0 : above0;
     268           0 :           pred_context = 4 * (edge0 == GOLDEN_FRAME);
     269             :         } else {
     270           0 :           pred_context =
     271           0 :               2 * (above0 == GOLDEN_FRAME) + 2 * (left0 == GOLDEN_FRAME);
     272             :         }
     273             :       }
     274             :     }
     275           0 :   } else if (has_above || has_left) {  // one edge available
     276           0 :     const MODE_INFO *edge_mi = has_above ? above_mi : left_mi;
     277             : 
     278           0 :     if (!is_inter_block(edge_mi) ||
     279           0 :         (edge_mi->ref_frame[0] == LAST_FRAME && !has_second_ref(edge_mi)))
     280           0 :       pred_context = 2;
     281           0 :     else if (!has_second_ref(edge_mi))
     282           0 :       pred_context = 4 * (edge_mi->ref_frame[0] == GOLDEN_FRAME);
     283             :     else
     284           0 :       pred_context = 3 * (edge_mi->ref_frame[0] == GOLDEN_FRAME ||
     285           0 :                           edge_mi->ref_frame[1] == GOLDEN_FRAME);
     286             :   } else {  // no edges available (2)
     287           0 :     pred_context = 2;
     288             :   }
     289           0 :   assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
     290           0 :   return pred_context;
     291             : }

Generated by: LCOV version 1.13