michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: michael@0: #ifndef __INC_RDOPT_H michael@0: #define __INC_RDOPT_H michael@0: michael@0: #define RDCOST(RM,DM,R,D) ( ((128+(R)*(RM)) >> 8) + (DM)*(D) ) michael@0: michael@0: static void insertsortmv(int arr[], int len) michael@0: { michael@0: int i, j, k; michael@0: michael@0: for ( i = 1 ; i <= len-1 ; i++ ) michael@0: { michael@0: for ( j = 0 ; j < i ; j++ ) michael@0: { michael@0: if ( arr[j] > arr[i] ) michael@0: { michael@0: int temp; michael@0: michael@0: temp = arr[i]; michael@0: michael@0: for ( k = i; k >j; k--) michael@0: arr[k] = arr[k - 1] ; michael@0: michael@0: arr[j] = temp ; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: static void insertsortsad(int arr[],int idx[], int len) michael@0: { michael@0: int i, j, k; michael@0: michael@0: for ( i = 1 ; i <= len-1 ; i++ ) michael@0: { michael@0: for ( j = 0 ; j < i ; j++ ) michael@0: { michael@0: if ( arr[j] > arr[i] ) michael@0: { michael@0: int temp, tempi; michael@0: michael@0: temp = arr[i]; michael@0: tempi = idx[i]; michael@0: michael@0: for ( k = i; k >j; k--) michael@0: { michael@0: arr[k] = arr[k - 1] ; michael@0: idx[k] = idx[k - 1]; michael@0: } michael@0: michael@0: arr[j] = temp ; michael@0: idx[j] = tempi; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: extern void vp8_initialize_rd_consts(VP8_COMP *cpi, MACROBLOCK *x, int Qvalue); michael@0: extern void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset, int *returnrate, int *returndistortion, int *returnintra); michael@0: extern void vp8_rd_pick_intra_mode(MACROBLOCK *x, int *rate); michael@0: michael@0: michael@0: static void get_plane_pointers(const YV12_BUFFER_CONFIG *fb, michael@0: unsigned char *plane[3], michael@0: unsigned int recon_yoffset, michael@0: unsigned int recon_uvoffset) michael@0: { michael@0: plane[0] = fb->y_buffer + recon_yoffset; michael@0: plane[1] = fb->u_buffer + recon_uvoffset; michael@0: plane[2] = fb->v_buffer + recon_uvoffset; michael@0: } michael@0: michael@0: michael@0: static void get_predictor_pointers(const VP8_COMP *cpi, michael@0: unsigned char *plane[4][3], michael@0: unsigned int recon_yoffset, michael@0: unsigned int recon_uvoffset) michael@0: { michael@0: if (cpi->ref_frame_flags & VP8_LAST_FRAME) michael@0: get_plane_pointers(&cpi->common.yv12_fb[cpi->common.lst_fb_idx], michael@0: plane[LAST_FRAME], recon_yoffset, recon_uvoffset); michael@0: michael@0: if (cpi->ref_frame_flags & VP8_GOLD_FRAME) michael@0: get_plane_pointers(&cpi->common.yv12_fb[cpi->common.gld_fb_idx], michael@0: plane[GOLDEN_FRAME], recon_yoffset, recon_uvoffset); michael@0: michael@0: if (cpi->ref_frame_flags & VP8_ALTR_FRAME) michael@0: get_plane_pointers(&cpi->common.yv12_fb[cpi->common.alt_fb_idx], michael@0: plane[ALTREF_FRAME], recon_yoffset, recon_uvoffset); michael@0: } michael@0: michael@0: michael@0: static void get_reference_search_order(const VP8_COMP *cpi, michael@0: int ref_frame_map[4]) michael@0: { michael@0: int i=0; michael@0: michael@0: ref_frame_map[i++] = INTRA_FRAME; michael@0: if (cpi->ref_frame_flags & VP8_LAST_FRAME) michael@0: ref_frame_map[i++] = LAST_FRAME; michael@0: if (cpi->ref_frame_flags & VP8_GOLD_FRAME) michael@0: ref_frame_map[i++] = GOLDEN_FRAME; michael@0: if (cpi->ref_frame_flags & VP8_ALTR_FRAME) michael@0: ref_frame_map[i++] = ALTREF_FRAME; michael@0: for(; i<4; i++) michael@0: ref_frame_map[i] = -1; michael@0: } michael@0: michael@0: michael@0: extern void vp8_mv_pred michael@0: ( michael@0: VP8_COMP *cpi, michael@0: MACROBLOCKD *xd, michael@0: const MODE_INFO *here, michael@0: int_mv *mvp, michael@0: int refframe, michael@0: int *ref_frame_sign_bias, michael@0: int *sr, michael@0: int near_sadidx[] michael@0: ); michael@0: void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffset, int near_sadidx[]); michael@0: michael@0: #endif