quant_matrix.c
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:4k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. #include "quant_matrix.h"
  2. #define FIX(X) (1 << 16) / (X) + 1
  3. uint8_t custom_intra_matrix = 0;
  4. uint8_t custom_inter_matrix = 0;
  5. uint8_t default_intra_matrix[64] = {
  6.      8,17,18,19,21,23,25,27,
  7.     17,18,19,21,23,25,27,28,
  8.     20,21,22,23,24,26,28,30,
  9.     21,22,23,24,26,28,30,32,
  10.     22,23,24,26,28,30,32,35,
  11.     23,24,26,28,30,32,35,38,
  12.     25,26,28,30,32,35,38,41,
  13.     27,28,30,32,35,38,41,45
  14. };
  15. int16_t intra_matrix[64] = {
  16.      8,17,18,19,21,23,25,27,
  17.     17,18,19,21,23,25,27,28,
  18.     20,21,22,23,24,26,28,30,
  19.     21,22,23,24,26,28,30,32,
  20.     22,23,24,26,28,30,32,35,
  21.     23,24,26,28,30,32,35,38,
  22.     25,26,28,30,32,35,38,41,
  23.     27,28,30,32,35,38,41,45
  24. };
  25. int16_t intra_matrix_fix[64] = {
  26.      FIX(8),FIX(17),FIX(18),FIX(19),FIX(21),FIX(23),FIX(25),FIX(27),
  27.     FIX(17),FIX(18),FIX(19),FIX(21),FIX(23),FIX(25),FIX(27),FIX(28),
  28.     FIX(20),FIX(21),FIX(22),FIX(23),FIX(24),FIX(26),FIX(28),FIX(30),
  29.     FIX(21),FIX(22),FIX(23),FIX(24),FIX(26),FIX(28),FIX(30),FIX(32),
  30.     FIX(22),FIX(23),FIX(24),FIX(26),FIX(28),FIX(30),FIX(32),FIX(35),
  31.     FIX(23),FIX(24),FIX(26),FIX(28),FIX(30),FIX(32),FIX(35),FIX(38),
  32.     FIX(25),FIX(26),FIX(28),FIX(30),FIX(32),FIX(35),FIX(38),FIX(41),
  33.     FIX(27),FIX(28),FIX(30),FIX(32),FIX(35),FIX(38),FIX(41),FIX(45)
  34. };
  35. uint8_t default_inter_matrix[64] = {
  36.     16,17,18,19,20,21,22,23,
  37.     17,18,19,20,21,22,23,24,
  38.     18,19,20,21,22,23,24,25,
  39.     19,20,21,22,23,24,26,27,
  40.     20,21,22,23,25,26,27,28,
  41.     21,22,23,24,26,27,28,30,
  42.     22,23,24,26,27,28,30,31,
  43.     23,24,25,27,28,30,31,33
  44. };
  45. int16_t inter_matrix[64] = {
  46.     16,17,18,19,20,21,22,23,
  47.     17,18,19,20,21,22,23,24,
  48.     18,19,20,21,22,23,24,25,
  49.     19,20,21,22,23,24,26,27,
  50.     20,21,22,23,25,26,27,28,
  51.     21,22,23,24,26,27,28,30,
  52.     22,23,24,26,27,28,30,31,
  53.     23,24,25,27,28,30,31,33
  54. };
  55. int16_t inter_matrix_fix[64] = {
  56.     FIX(16),FIX(17),FIX(18),FIX(19),FIX(20),FIX(21),FIX(22),FIX(23),
  57.     FIX(17),FIX(18),FIX(19),FIX(20),FIX(21),FIX(22),FIX(23),FIX(24),
  58.     FIX(18),FIX(19),FIX(20),FIX(21),FIX(22),FIX(23),FIX(24),FIX(25),
  59.     FIX(19),FIX(20),FIX(21),FIX(22),FIX(23),FIX(24),FIX(26),FIX(27),
  60.     FIX(20),FIX(21),FIX(22),FIX(23),FIX(25),FIX(26),FIX(27),FIX(28),
  61.     FIX(21),FIX(22),FIX(23),FIX(24),FIX(26),FIX(27),FIX(28),FIX(30),
  62.     FIX(22),FIX(23),FIX(24),FIX(26),FIX(27),FIX(28),FIX(30),FIX(31),
  63.     FIX(23),FIX(24),FIX(25),FIX(27),FIX(28),FIX(30),FIX(31),FIX(33)
  64. };
  65. uint8_t get_intra_matrix_status(void) {
  66. return custom_intra_matrix;
  67. }
  68. uint8_t get_inter_matrix_status(void) {
  69. return custom_inter_matrix;
  70. }
  71. void set_intra_matrix_status(uint8_t status) {
  72. custom_intra_matrix = status;
  73. }
  74. void set_inter_matrix_status(uint8_t status) {
  75. custom_inter_matrix = status;
  76. }
  77. int16_t *get_intra_matrix(void) {
  78. return intra_matrix;
  79. }
  80. int16_t *get_inter_matrix(void) {
  81. return inter_matrix;
  82. }
  83. uint8_t *get_default_intra_matrix(void) {
  84. return default_intra_matrix;
  85. }
  86. uint8_t *get_default_inter_matrix(void) {
  87. return default_inter_matrix;
  88. }
  89. uint8_t set_intra_matrix(uint8_t *matrix)
  90. {
  91. int i, change = 0;
  92. custom_intra_matrix = 0;
  93. for(i = 0; i < 64; i++) {
  94. if((int16_t) default_intra_matrix[i] != matrix[i])
  95. custom_intra_matrix = 1;
  96. if(intra_matrix[i] != matrix[i])
  97. change = 1;
  98. intra_matrix[i] = (int16_t) matrix[i];
  99. intra_matrix_fix[i] = FIX(intra_matrix[i]);
  100. }
  101. return custom_intra_matrix | change;
  102. }
  103. uint8_t set_inter_matrix(uint8_t *matrix)
  104. {
  105. int i, change = 0;
  106. custom_inter_matrix = 0;
  107. for(i = 0; i < 64; i++) {
  108. if((int16_t) default_inter_matrix[i] != matrix[i])
  109. custom_inter_matrix = 1;
  110. if(inter_matrix[i] != matrix[i])
  111. change = 1;
  112. inter_matrix[i] = (int16_t) matrix[i];
  113. inter_matrix_fix[i] = FIX(inter_matrix[i]);
  114. }
  115. return custom_inter_matrix | change;
  116. }