common.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //*@@@+++@@@@******************************************************************
  2. //
  3. // Copyright © Microsoft Corp.
  4. // All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions are met:
  8. //
  9. // • Redistributions of source code must retain the above copyright notice,
  10. // this list of conditions and the following disclaimer.
  11. // • Redistributions in binary form must reproduce the above copyright notice,
  12. // this list of conditions and the following disclaimer in the documentation
  13. // and/or other materials provided with the distribution.
  14. //
  15. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  19. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. // POSSIBILITY OF SUCH DAMAGE.
  26. //
  27. //*@@@---@@@@******************************************************************
  28. #ifndef WMI_COMMON_H
  29. #define WMI_COMMON_H
  30. /*************************************************************************
  31. // Common typedef's
  32. *************************************************************************/
  33. typedef enum { ENCODER = 0, DECODER = 1 } CODINGMODE;
  34. typedef enum tagBand
  35. {
  36. BAND_HEADER = 0,
  37. BAND_DC = 1,
  38. BAND_LP = 2,
  39. BAND_AC = 3,
  40. BAND_FL = 4
  41. } BAND;
  42. /*************************************************************************
  43. struct / class definitions
  44. *************************************************************************/
  45. //#define SIGNATURE_BYTES 8 // Bytes for GDI+ signature
  46. #define CODEC_VERSION 1
  47. #define CODEC_SUBVERSION 0
  48. #define CODEC_SUBVERSION_NEWSCALING_SOFT_TILES 1
  49. #define CODEC_SUBVERSION_NEWSCALING_HARD_TILES 9
  50. #define CONTEXTX 8
  51. #define CTDC 5
  52. #define NUMVLCTABLES 21 // CONTEXTX * 2 + CTDC
  53. #define AVG_NDIFF 3
  54. #define MAXTOTAL 32767 // 511 should be enough
  55. /** Quantization related defines **/
  56. #define SHIFTZERO 1 /* >= 0 */
  57. #define QPFRACBITS 2 /* or 0 only supported */
  58. /** adaptive huffman encoding / decoding struct **/
  59. typedef struct CAdaptiveHuffman
  60. {
  61. Int m_iNSymbols;
  62. const Int *m_pTable;
  63. const Int *m_pDelta, *m_pDelta1;
  64. Int m_iTableIndex;
  65. const short *m_hufDecTable;
  66. Bool m_bInitialize;
  67. //Char m_pLabel[8]; // for debugging - label attached to constructor
  68. Int m_iDiscriminant, m_iDiscriminant1;
  69. Int m_iUpperBound;
  70. Int m_iLowerBound;
  71. } CAdaptiveHuffman;
  72. /************************************************************************************
  73. Context structures
  74. ************************************************************************************/
  75. typedef struct CAdaptiveModel {
  76. Int m_iFlcState[2];
  77. Int m_iFlcBits[2];
  78. BAND m_band;
  79. } CAdaptiveModel;
  80. typedef struct CCBPModel {
  81. Int m_iCount0[2];
  82. Int m_iCount1[2];
  83. Int m_iState[2];
  84. } CCBPModel;
  85. /*************************************************************************
  86. globals
  87. *************************************************************************/
  88. extern Int grgiZigzagInv4x4_lowpass[];
  89. extern Int grgiZigzagInv4x4H[];
  90. extern Int grgiZigzagInv4x4V[];
  91. extern const Int gSignificantRunBin[];
  92. extern const Int gSignificantRunFixedLength[];
  93. static const Int cblkChromas[] = {0,4,8,16, 16,16,16, 0,0};
  94. /*************************************************************************
  95. function declarations
  96. *************************************************************************/
  97. // common utilities
  98. Void Clean (CAdaptiveHuffman *pAdHuff);
  99. CAdaptiveHuffman *Allocate (Int iNSymbols, CODINGMODE cm);
  100. /* Timing functions */
  101. void reset_timing(double *time);
  102. void report_timing(const char *s, double time);
  103. // static double timeperclock;
  104. /** adaptive model functions **/
  105. Void UpdateModelMB (COLORFORMAT cf, Int iChannels, Int iLaplacianMean[], CAdaptiveModel *m_pModel);
  106. /** adaptive huffman encoder / decoder functions **/
  107. Void Adapt (CAdaptiveHuffman *pAdHuff, Bool bFixedTables);
  108. Void AdaptFixed (CAdaptiveHuffman *pAdHuff);
  109. Void AdaptDiscriminant (CAdaptiveHuffman *pAdHuff);
  110. #ifndef _PREFAST_
  111. #pragma warning(disable:4068)
  112. #endif
  113. #endif // WMI_COMMON_H