rdopt.h 4.0 KB

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