Home | History | Annotate | Download | only in encoder
      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 #ifndef __INC_RDOPT_H
     13 #define __INC_RDOPT_H
     14 
     15 #define RDCOST(RM,DM,R,D) ( ((128+(R)*(RM)) >> 8) + (DM)*(D) )
     16 
     17 static void insertsortmv(int arr[], int len)
     18 {
     19     int i, j, k;
     20 
     21     for ( i = 1 ; i <= len-1 ; i++ )
     22     {
     23         for ( j = 0 ; j < i ; j++ )
     24         {
     25             if ( arr[j] > arr[i] )
     26             {
     27                 int temp;
     28 
     29                 temp = arr[i];
     30 
     31                 for ( k = i; k >j; k--)
     32                     arr[k] = arr[k - 1] ;
     33 
     34                 arr[j] = temp ;
     35             }
     36         }
     37     }
     38 }
     39 
     40 static void insertsortsad(int arr[],int idx[], int len)
     41 {
     42     int i, j, k;
     43 
     44     for ( i = 1 ; i <= len-1 ; i++ )
     45     {
     46         for ( j = 0 ; j < i ; j++ )
     47         {
     48             if ( arr[j] > arr[i] )
     49             {
     50                 int temp, tempi;
     51 
     52                 temp = arr[i];
     53                 tempi = idx[i];
     54 
     55                 for ( k = i; k >j; k--)
     56                 {
     57                     arr[k] = arr[k - 1] ;
     58                     idx[k] = idx[k - 1];
     59                 }
     60 
     61                 arr[j] = temp ;
     62                 idx[j] = tempi;
     63             }
     64         }
     65     }
     66 }
     67 
     68 extern void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue);
     69 extern void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset, int *returnrate, int *returndistortion, int *returnintra);
     70 extern void vp8_rd_pick_intra_mode(MACROBLOCK *x, int *rate);
     71 
     72 
     73 static void get_plane_pointers(const YV12_BUFFER_CONFIG *fb,
     74                                unsigned char            *plane[3],
     75                                unsigned int              recon_yoffset,
     76                                unsigned int              recon_uvoffset)
     77 {
     78     plane[0] = fb->y_buffer + recon_yoffset;
     79     plane[1] = fb->u_buffer + recon_uvoffset;
     80     plane[2] = fb->v_buffer + recon_uvoffset;
     81 }
     82 
     83 
     84 static void get_predictor_pointers(const VP8_COMP *cpi,
     85                                        unsigned char  *plane[4][3],
     86                                        unsigned int    recon_yoffset,
     87                                        unsigned int    recon_uvoffset)
     88 {
     89     if (cpi->ref_frame_flags & VP8_LAST_FRAME)
     90         get_plane_pointers(&cpi->common.yv12_fb[cpi->common.lst_fb_idx],
     91                            plane[LAST_FRAME], recon_yoffset, recon_uvoffset);
     92 
     93     if (cpi->ref_frame_flags & VP8_GOLD_FRAME)
     94         get_plane_pointers(&cpi->common.yv12_fb[cpi->common.gld_fb_idx],
     95                            plane[GOLDEN_FRAME], recon_yoffset, recon_uvoffset);
     96 
     97     if (cpi->ref_frame_flags & VP8_ALTR_FRAME)
     98         get_plane_pointers(&cpi->common.yv12_fb[cpi->common.alt_fb_idx],
     99                            plane[ALTREF_FRAME], recon_yoffset, recon_uvoffset);
    100 }
    101 
    102 
    103 static void get_reference_search_order(const VP8_COMP *cpi,
    104                                            int             ref_frame_map[4])
    105 {
    106     int i=0;
    107 
    108     ref_frame_map[i++] = INTRA_FRAME;
    109     if (cpi->ref_frame_flags & VP8_LAST_FRAME)
    110         ref_frame_map[i++] = LAST_FRAME;
    111     if (cpi->ref_frame_flags & VP8_GOLD_FRAME)
    112         ref_frame_map[i++] = GOLDEN_FRAME;
    113     if (cpi->ref_frame_flags & VP8_ALTR_FRAME)
    114         ref_frame_map[i++] = ALTREF_FRAME;
    115     for(; i<4; i++)
    116         ref_frame_map[i] = -1;
    117 }
    118 
    119 
    120 extern void vp8_mv_pred
    121 (
    122     VP8_COMP *cpi,
    123     MACROBLOCKD *xd,
    124     const MODE_INFO *here,
    125     int_mv *mvp,
    126     int refframe,
    127     int *ref_frame_sign_bias,
    128     int *sr,
    129     int near_sadidx[]
    130 );
    131 void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffset, int near_sadidx[]);
    132 
    133 #endif
    134