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