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