context_ini.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*!
  2. *************************************************************************************
  3. * \file context_ini.c
  4. *
  5. * \brief
  6. * CABAC context initializations
  7. *
  8. * \author
  9. * Main contributors (see contributors.h for copyright, address and affiliation details)
  10. * - Detlev Marpe <[email protected]>
  11. * - Heiko Schwarz <[email protected]>
  12. **************************************************************************************
  13. */
  14. #define CONTEXT_INI_C
  15. #include "defines.h"
  16. #include "global.h"
  17. #include "biaridecod.h"
  18. #include "ctx_tables.h"
  19. #define IBIARI_CTX_INIT2(ii,jj,ctx,tab,num, qp) \
  20. { \
  21. for (i=0; i<ii; ++i) \
  22. for (j=0; j<jj; ++j) \
  23. { \
  24. biari_init_context (qp, &(ctx[i][j]), tab ## _I[num][i][j]); \
  25. } \
  26. }
  27. #define PBIARI_CTX_INIT2(ii,jj,ctx,tab,num, qp) \
  28. { \
  29. for (i=0; i<ii; ++i) \
  30. for (j=0; j<jj; ++j) \
  31. { \
  32. biari_init_context (qp, &(ctx[i][j]), tab ## _P[num][i][j]); \
  33. } \
  34. }
  35. #define IBIARI_CTX_INIT1(jj,ctx,tab,num, qp) \
  36. { \
  37. for (j=0; j<jj; ++j) \
  38. { \
  39. biari_init_context (qp, &(ctx[j]), tab ## _I[num][0][j]); \
  40. } \
  41. }
  42. #define PBIARI_CTX_INIT1(jj,ctx,tab,num, qp) \
  43. { \
  44. { \
  45. for (j=0; j<jj; ++j) \
  46. { \
  47. biari_init_context (qp, &(ctx[j]), tab ## _P[num][0][j]); \
  48. } \
  49. } \
  50. }
  51. void init_contexts (Slice *currSlice)
  52. {
  53. VideoParameters *p_Vid = currSlice->p_Vid;
  54. MotionInfoContexts* mc = currSlice->mot_ctx;
  55. TextureInfoContexts* tc = currSlice->tex_ctx;
  56. int i, j;
  57. int qp = imax(0, p_Vid->qp);
  58. int model_number = currSlice->model_number;
  59. //printf("%d -", p_Vid->currentSlice->model_number);
  60. //--- motion coding contexts ---
  61. if ((currSlice->slice_type == I_SLICE)||(currSlice->slice_type == SI_SLICE))
  62. {
  63. IBIARI_CTX_INIT2 (3, NUM_MB_TYPE_CTX, mc->mb_type_contexts, INIT_MB_TYPE, model_number, qp);
  64. IBIARI_CTX_INIT2 (2, NUM_B8_TYPE_CTX, mc->b8_type_contexts, INIT_B8_TYPE, model_number, qp);
  65. IBIARI_CTX_INIT2 (2, NUM_MV_RES_CTX, mc->mv_res_contexts, INIT_MV_RES, model_number, qp);
  66. IBIARI_CTX_INIT2 (2, NUM_REF_NO_CTX, mc->ref_no_contexts, INIT_REF_NO, model_number, qp);
  67. IBIARI_CTX_INIT1 ( NUM_DELTA_QP_CTX, mc->delta_qp_contexts, INIT_DELTA_QP, model_number, qp);
  68. IBIARI_CTX_INIT1 ( NUM_MB_AFF_CTX, mc->mb_aff_contexts, INIT_MB_AFF, model_number, qp);
  69. //--- texture coding contexts ---
  70. IBIARI_CTX_INIT1 ( NUM_TRANSFORM_SIZE_CTX, tc->transform_size_contexts, INIT_TRANSFORM_SIZE, model_number, qp);
  71. IBIARI_CTX_INIT1 ( NUM_IPR_CTX, tc->ipr_contexts, INIT_IPR, model_number, qp);
  72. IBIARI_CTX_INIT1 ( NUM_CIPR_CTX, tc->cipr_contexts, INIT_CIPR, model_number, qp);
  73. IBIARI_CTX_INIT2 (3, NUM_CBP_CTX, tc->cbp_contexts, INIT_CBP, model_number, qp);
  74. IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_BCBP_CTX, tc->bcbp_contexts, INIT_BCBP, model_number, qp);
  75. IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[0], INIT_MAP, model_number, qp);
  76. #if ENABLE_FIELD_CTX
  77. IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[1], INIT_FLD_MAP, model_number, qp);
  78. IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[1], INIT_FLD_LAST, model_number, qp);
  79. #endif
  80. IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[0], INIT_LAST, model_number, qp);
  81. IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ONE_CTX, tc->one_contexts, INIT_ONE, model_number, qp);
  82. IBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ABS_CTX, tc->abs_contexts, INIT_ABS, model_number, qp);
  83. }
  84. else
  85. {
  86. PBIARI_CTX_INIT2 (3, NUM_MB_TYPE_CTX, mc->mb_type_contexts, INIT_MB_TYPE, model_number, qp);
  87. PBIARI_CTX_INIT2 (2, NUM_B8_TYPE_CTX, mc->b8_type_contexts, INIT_B8_TYPE, model_number, qp);
  88. PBIARI_CTX_INIT2 (2, NUM_MV_RES_CTX, mc->mv_res_contexts, INIT_MV_RES, model_number, qp);
  89. PBIARI_CTX_INIT2 (2, NUM_REF_NO_CTX, mc->ref_no_contexts, INIT_REF_NO, model_number, qp);
  90. PBIARI_CTX_INIT1 ( NUM_DELTA_QP_CTX, mc->delta_qp_contexts, INIT_DELTA_QP, model_number, qp);
  91. PBIARI_CTX_INIT1 ( NUM_MB_AFF_CTX, mc->mb_aff_contexts, INIT_MB_AFF, model_number, qp);
  92. //--- texture coding contexts ---
  93. PBIARI_CTX_INIT1 ( NUM_TRANSFORM_SIZE_CTX, tc->transform_size_contexts, INIT_TRANSFORM_SIZE, model_number, qp);
  94. PBIARI_CTX_INIT1 ( NUM_IPR_CTX, tc->ipr_contexts, INIT_IPR, model_number, qp);
  95. PBIARI_CTX_INIT1 ( NUM_CIPR_CTX, tc->cipr_contexts, INIT_CIPR, model_number, qp);
  96. PBIARI_CTX_INIT2 (3, NUM_CBP_CTX, tc->cbp_contexts, INIT_CBP, model_number, qp);
  97. PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_BCBP_CTX, tc->bcbp_contexts, INIT_BCBP, model_number, qp);
  98. PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[0], INIT_MAP, model_number, qp);
  99. #if ENABLE_FIELD_CTX
  100. PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_MAP_CTX, tc->map_contexts[1], INIT_FLD_MAP, model_number, qp);
  101. PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[1], INIT_FLD_LAST, model_number, qp);
  102. #endif
  103. PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_LAST_CTX, tc->last_contexts[0], INIT_LAST, model_number, qp);
  104. PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ONE_CTX, tc->one_contexts, INIT_ONE, model_number, qp);
  105. PBIARI_CTX_INIT2 (NUM_BLOCK_TYPES, NUM_ABS_CTX, tc->abs_contexts, INIT_ABS, model_number, qp);
  106. }
  107. }