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