encodeintra.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #include "vpx_config.h"
  11. #include "vp8_rtcd.h"
  12. #include "./vpx_dsp_rtcd.h"
  13. #include "vp8/encoder/quantize.h"
  14. #include "vp8/common/reconintra.h"
  15. #include "vp8/common/reconintra4x4.h"
  16. #include "encodemb.h"
  17. #include "vp8/common/invtrans.h"
  18. #include "encodeintra.h"
  19. int vp8_encode_intra(VP8_COMP *cpi, MACROBLOCK *x, int use_dc_pred) {
  20. int i;
  21. int intra_pred_var = 0;
  22. (void)cpi;
  23. if (use_dc_pred) {
  24. x->e_mbd.mode_info_context->mbmi.mode = DC_PRED;
  25. x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
  26. x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME;
  27. vp8_encode_intra16x16mby(x);
  28. vp8_inverse_transform_mby(&x->e_mbd);
  29. } else {
  30. for (i = 0; i < 16; ++i) {
  31. x->e_mbd.block[i].bmi.as_mode = B_DC_PRED;
  32. vp8_encode_intra4x4block(x, i);
  33. }
  34. }
  35. intra_pred_var = vpx_get_mb_ss(x->src_diff);
  36. return intra_pred_var;
  37. }
  38. void vp8_encode_intra4x4block(MACROBLOCK *x, int ib) {
  39. BLOCKD *b = &x->e_mbd.block[ib];
  40. BLOCK *be = &x->block[ib];
  41. int dst_stride = x->e_mbd.dst.y_stride;
  42. unsigned char *dst = x->e_mbd.dst.y_buffer + b->offset;
  43. unsigned char *Above = dst - dst_stride;
  44. unsigned char *yleft = dst - 1;
  45. unsigned char top_left = Above[-1];
  46. vp8_intra4x4_predict(Above, yleft, dst_stride, b->bmi.as_mode, b->predictor,
  47. 16, top_left);
  48. vp8_subtract_b(be, b, 16);
  49. x->short_fdct4x4(be->src_diff, be->coeff, 32);
  50. x->quantize_b(be, b);
  51. if (*b->eob > 1) {
  52. vp8_short_idct4x4llm(b->dqcoeff, b->predictor, 16, dst, dst_stride);
  53. } else {
  54. vp8_dc_only_idct_add(b->dqcoeff[0], b->predictor, 16, dst, dst_stride);
  55. }
  56. }
  57. void vp8_encode_intra4x4mby(MACROBLOCK *mb) {
  58. int i;
  59. MACROBLOCKD *xd = &mb->e_mbd;
  60. intra_prediction_down_copy(xd, xd->dst.y_buffer - xd->dst.y_stride + 16);
  61. for (i = 0; i < 16; ++i) vp8_encode_intra4x4block(mb, i);
  62. return;
  63. }
  64. void vp8_encode_intra16x16mby(MACROBLOCK *x) {
  65. BLOCK *b = &x->block[0];
  66. MACROBLOCKD *xd = &x->e_mbd;
  67. vp8_build_intra_predictors_mby_s(xd, xd->dst.y_buffer - xd->dst.y_stride,
  68. xd->dst.y_buffer - 1, xd->dst.y_stride,
  69. xd->dst.y_buffer, xd->dst.y_stride);
  70. vp8_subtract_mby(x->src_diff, *(b->base_src), b->src_stride, xd->dst.y_buffer,
  71. xd->dst.y_stride);
  72. vp8_transform_intra_mby(x);
  73. vp8_quantize_mby(x);
  74. if (x->optimize) vp8_optimize_mby(x);
  75. }
  76. void vp8_encode_intra16x16mbuv(MACROBLOCK *x) {
  77. MACROBLOCKD *xd = &x->e_mbd;
  78. vp8_build_intra_predictors_mbuv_s(xd, xd->dst.u_buffer - xd->dst.uv_stride,
  79. xd->dst.v_buffer - xd->dst.uv_stride,
  80. xd->dst.u_buffer - 1, xd->dst.v_buffer - 1,
  81. xd->dst.uv_stride, xd->dst.u_buffer,
  82. xd->dst.v_buffer, xd->dst.uv_stride);
  83. vp8_subtract_mbuv(x->src_diff, x->src.u_buffer, x->src.v_buffer,
  84. x->src.uv_stride, xd->dst.u_buffer, xd->dst.v_buffer,
  85. xd->dst.uv_stride);
  86. vp8_transform_mbuv(x);
  87. vp8_quantize_mbuv(x);
  88. if (x->optimize) vp8_optimize_mbuv(x);
  89. }