vp6huffdec.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*------------------------------------------------------------------------------
  2. -- --
  3. -- This software is confidential and proprietary and may be used --
  4. -- only as expressly authorized by a licensing agreement from --
  5. -- --
  6. -- Hantro Products Oy. --
  7. -- --
  8. -- (C) COPYRIGHT 2006 HANTRO PRODUCTS OY --
  9. -- ALL RIGHTS RESERVED --
  10. -- --
  11. -- The entire notice above must be reproduced --
  12. -- on all copies and should not be removed. --
  13. -- --
  14. --------------------------------------------------------------------------------
  15. -
  16. - Description : ...
  17. -
  18. --------------------------------------------------------------------------------
  19. -
  20. - Version control information, please leave untouched.
  21. -
  22. - $RCSfile: vp6huffdec.h,v $
  23. - $Revision: 1.4 $
  24. - $Date: 2008/04/28 13:25:25 $
  25. -
  26. ------------------------------------------------------------------------------*/
  27. #ifndef __VP6HUFFDEC_H__
  28. #define __VP6HUFFDEC_H__
  29. // VP6 hufman table AC bands
  30. #define VP6HWAC_BANDS 6
  31. // Tokens Value Extra Bits (range + sign)
  32. #define ZERO_TOKEN 0 //0 Extra Bits 0+0
  33. #define ONE_TOKEN 1 //1 Extra Bits 0+1
  34. #define TWO_TOKEN 2 //2 Extra Bits 0+1
  35. #define THREE_TOKEN 3 //3 Extra Bits 0+1
  36. #define FOUR_TOKEN 4 //4 Extra Bits 0+1
  37. #define DCT_VAL_CATEGORY1 5 //5-6 Extra Bits 1+1
  38. #define DCT_VAL_CATEGORY2 6 //7-10 Extra Bits 2+1
  39. #define DCT_VAL_CATEGORY3 7 //11-26 Extra Bits 4+1
  40. #define DCT_VAL_CATEGORY4 8 //11-26 Extra Bits 5+1
  41. #define DCT_VAL_CATEGORY5 9 //27-58 Extra Bits 5+1
  42. #define DCT_VAL_CATEGORY6 10 //59+ Extra Bits 11+1
  43. #define DCT_EOB_TOKEN 11 //EOB Extra Bits 0+0
  44. #define MAX_ENTROPY_TOKENS (DCT_EOB_TOKEN + 1)
  45. #define ILLEGAL_TOKEN 255
  46. #define DC_TOKEN_CONTEXTS 3 // 00, 0!0, !0!0
  47. #define CONTEXT_NODES (MAX_ENTROPY_TOKENS-7)
  48. #define PREC_CASES 3
  49. #define ZERO_RUN_PROB_CASES 14
  50. #define DC_PROBABILITY_UPDATE_THRESH 100
  51. #define ZERO_CONTEXT_NODE 0
  52. #define EOB_CONTEXT_NODE 1
  53. #define ONE_CONTEXT_NODE 2
  54. #define LOW_VAL_CONTEXT_NODE 3
  55. #define TWO_CONTEXT_NODE 4
  56. #define THREE_CONTEXT_NODE 5
  57. #define HIGH_LOW_CONTEXT_NODE 6
  58. #define CAT_ONE_CONTEXT_NODE 7
  59. #define CAT_THREEFOUR_CONTEXT_NODE 8
  60. #define CAT_THREE_CONTEXT_NODE 9
  61. #define CAT_FIVE_CONTEXT_NODE 10
  62. #define PROB_UPDATE_BASELINE_COST 7
  63. #define MAX_PROB 254
  64. #define DCT_MAX_VALUE 2048
  65. #define ZRL_BANDS 2
  66. #define ZRL_BAND2 6
  67. #define SCAN_ORDER_BANDS 16
  68. #define SCAN_BAND_UPDATE_BITS 4
  69. #define HUFF_LUT_LEVELS 6
  70. typedef struct _tokenorptr
  71. {
  72. u16 selector:1; // 1 bit selector 0->ptr, 1->token
  73. u16 value:7;
  74. } tokenorptr;
  75. typedef struct _dhuffnode
  76. {
  77. union
  78. {
  79. i8 l;
  80. tokenorptr left;
  81. } leftunion;
  82. union
  83. {
  84. i8 r;
  85. tokenorptr right;
  86. } rightunion;
  87. } HUFF_NODE;
  88. typedef struct _HUFF_TABLE_NODE
  89. {
  90. u16 flag:1; // bit 0: 1-Token, 0-Index
  91. u16 value:5; // value: the value of the Token or the Index to the huffman tree
  92. u16 unused:6; // not used for now
  93. u16 length:4; // Huffman code length of the token
  94. } HUFF_TABLE_NODE;
  95. typedef struct HUFF_INSTANCE
  96. {
  97. /* Huffman code tables for DC, AC & Zero Run Length */
  98. /*u32 DcHuffCode[2][MAX_ENTROPY_TOKENS]; */
  99. /*u8 DcHuffLength[2][MAX_ENTROPY_TOKENS]; */
  100. u32 DcHuffProbs[2][MAX_ENTROPY_TOKENS];
  101. HUFF_NODE DcHuffTree[2][MAX_ENTROPY_TOKENS];
  102. /*u32 AcHuffCode[PREC_CASES][2][VP6HWAC_BANDS][MAX_ENTROPY_TOKENS]; */
  103. /*u8 AcHuffLength[PREC_CASES][2][VP6HWAC_BANDS][MAX_ENTROPY_TOKENS]; */
  104. u32 AcHuffProbs[PREC_CASES][2][VP6HWAC_BANDS][MAX_ENTROPY_TOKENS];
  105. HUFF_NODE AcHuffTree[PREC_CASES][2][VP6HWAC_BANDS][MAX_ENTROPY_TOKENS];
  106. /*u32 ZeroHuffCode[ZRL_BANDS][ZERO_RUN_PROB_CASES]; */
  107. /*u8 ZeroHuffLength[ZRL_BANDS][ZERO_RUN_PROB_CASES]; */
  108. u32 ZeroHuffProbs[ZRL_BANDS][ZERO_RUN_PROB_CASES];
  109. HUFF_NODE ZeroHuffTree[ZRL_BANDS][ZERO_RUN_PROB_CASES];
  110. #if 0
  111. /* FAST look-up-table for huffman Trees */
  112. u16 DcHuffLUT[2][1 << HUFF_LUT_LEVELS];
  113. u16 AcHuffLUT[PREC_CASES][2][VP6HWAC_BANDS][1 << HUFF_LUT_LEVELS];
  114. u16 ZeroHuffLUT[ZRL_BANDS][1 << HUFF_LUT_LEVELS];
  115. /* Counters for runs of zeros at DC & EOB at first AC position in Huffman mode */
  116. i32 CurrentDcRunLen[2];
  117. i32 CurrentAc1RunLen[2];
  118. #endif
  119. u16 DcHuffLUT[2][12];
  120. u16 AcHuffLUT[2][3][/*6*/4][12];
  121. u16 ZeroHuffLUT[2][12];
  122. } HUFF_INSTANCE;
  123. void VP6HW_BoolTreeToHuffCodes(const u8 * BoolTreeProbs, u32 * HuffProbs);
  124. void VP6HW_ZerosBoolTreeToHuffCodes(const u8 * BoolTreeProbs, u32 * HuffProbs);
  125. void VP6HW_BuildHuffTree(HUFF_NODE * hn, u32 * counts, i32 values);
  126. void VP6HW_CreateHuffmanLUT(const HUFF_NODE * hn, u16 * HuffTable, i32 values);
  127. #endif /* __VP6HUFFDEC_H__ */