preproc.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /****************************************************************************
  2. *
  3. * Module Title : preproc.h
  4. *
  5. * Description : Content analysis module header
  6. *
  7. * AUTHOR : Paul Wilkins
  8. *
  9. *****************************************************************************
  10. * Revision History
  11. *
  12. * 1.08 PGW 27 Apr 01 Removed code to set Y from UV
  13. * 1.07 PGW 28 Feb 01 Removal of history buffer functionality.
  14. * 1.06 PGW 04 Oct 00 Added CANDIDATE_BLOCK_LOW.
  15. * 1.05 PGW 24 Jul 00 Added Column SAD functions. Deleted BeThreshold.
  16. * 1.04 PGW 13 Jul 00 Added BLOCK_CODED_LOW. Deleted BLOCK_CODED_EXTRA.
  17. * 1.03 PGW 10 Jul 00 Added lookup tables to reduce number of conditionals
  18. * in RowDiffScan(). Removed old "ifdef 0"ed code.
  19. * Added KFIndicator.
  20. * 1.02 JBB 30/05/00 Removed hard coded size limits
  21. * 1.01 YX 06/04/00 Added XMMEnabled for optimizations
  22. * 1.00 PGW 16/06/96 Configuration baseline.
  23. *
  24. *****************************************************************************
  25. */
  26. #include "preprocconf.h"
  27. #include "type_aliases.h"
  28. #include "preprocif.h"
  29. /* Constants. */
  30. #define OUTPUT_BLOCK_HEIGHT 8
  31. #define OUTPUT_BLOCK_WIDTH 8
  32. #define INTERNAL_BLOCK_HEIGHT 8
  33. #define INTERNAL_BLOCK_WIDTH 8
  34. #define FILTER_BLOCK_SIZE (INTERNAL_BLOCK_WIDTH * INTERNAL_BLOCK_HEIGHT)
  35. /* NEW Line search values. */
  36. #define UP 0
  37. #define DOWN 1
  38. #define LEFT 2
  39. #define RIGHT 3
  40. /* Low Pass Filter levels. */
  41. #define NO_LOW_PASS 0
  42. #define VERY_LOW_LOW_PASS 1
  43. #define LOW_LOW_PASS 2
  44. #define MODERATE_LOW_PASS 5
  45. #define HIGH_LOW_PASS 7
  46. #define VERY_HIGH_LOW_PASS 9
  47. #define FIRST_ROW 0
  48. #define NOT_EDGE_ROW 1
  49. #define LAST_ROW 2
  50. #define YDIFF_CB_ROWS (INTERNAL_BLOCK_HEIGHT * 3)
  51. #define CHLOCALS_CB_ROWS (INTERNAL_BLOCK_HEIGHT * 3)
  52. #define PMAP_CB_ROWS (INTERNAL_BLOCK_HEIGHT * 3)
  53. #define FRAG_PIXEL_DIFF_ROWS (INTERNAL_BLOCK_HEIGHT * 3)
  54. #define PSCORE_CB_ROWS (INTERNAL_BLOCK_HEIGHT * 4)
  55. #define PIXEL_SCORES_BUFFER_SIZE SCAN_MAX_LINE_LENGTH * PSCORE_CB_ROWS
  56. #define YUV_DIFFS_CIRC_BUFFER_SIZE (SCAN_MAX_LINE_LENGTH * YDIFF_CB_ROWS)
  57. #define CH_LOCALS_CIRC_BUFFER_SIZE (SCAN_MAX_LINE_LENGTH * CHLOCALS_CB_ROWS)
  58. #define PIXEL_MAP_CIRC_BUFFER_SIZE (SCAN_MAX_LINE_LENGTH * PMAP_CB_ROWS)
  59. // Status values in block coding map
  60. #define CANDIDATE_BLOCK_LOW -2
  61. #define CANDIDATE_BLOCK -1
  62. #define BLOCK_NOT_CODED 0
  63. #define BLOCK_CODED_BAR 3
  64. #define BLOCK_ALREADY_MARKED_FOR_CODING 4
  65. #define BLOCK_CODED_SGC 4
  66. #define BLOCK_CODED_LOW 4
  67. #define BLOCK_CODED 5
  68. #define MAX_PREV_FRAMES 16
  69. #define MAX_SEARCH_LINE_LEN 7
  70. /******************************************************************/
  71. /* Type definitions. */
  72. /******************************************************************/
  73. #define blockCoded(i) (ppi->ScanConfig.FragInfo[(i)*ppi->ScanConfig.FragInfoElementSize]&ppi->ScanConfig.FragInfoCodedMask)
  74. #define setBlockCoded(i) ppi->ScanConfig.FragInfo[(i)*ppi->ScanConfig.FragInfoElementSize]|=ppi->ScanConfig.FragInfoCodedMask;
  75. #define setBlockUncoded(i) ppi->ScanConfig.FragInfo[(i)*ppi->ScanConfig.FragInfoElementSize]&=(~ppi->ScanConfig.FragInfoCodedMask);
  76. typedef struct PP_INSTANCE
  77. {
  78. UINT32 *ScanPixelIndexTableAlloc;
  79. INT8 *ScanDisplayFragmentsAlloc;
  80. UINT32 *FragScoresAlloc; // The individual frame difference ratings.
  81. INT8 *SameGreyDirPixelsAlloc;
  82. INT8 *BarBlockMapAlloc;
  83. // Number of pixels changed by diff threshold in row of a fragment.
  84. UINT8 *FragDiffPixelsAlloc;
  85. UINT8 *PixelScoresAlloc;
  86. UINT8 *PixelChangedMapAlloc;
  87. UINT8 *ChLocalsAlloc;
  88. INT16 *yuv_differencesAlloc;
  89. INT32 *RowChangedPixelsAlloc;
  90. INT8 *TmpCodedMapAlloc;
  91. UINT32 *ScanPixelIndexTable;
  92. INT8 *ScanDisplayFragments;
  93. UINT32 *FragScores; // The individual frame difference ratings.
  94. INT8 *SameGreyDirPixels;
  95. INT8 *BarBlockMap;
  96. // Number of pixels changed by diff threshold in row of a fragment.
  97. UINT8 *FragDiffPixels;
  98. UINT8 *PixelScores;
  99. UINT8 *PixelChangedMap;
  100. UINT8 *ChLocals;
  101. INT16 *yuv_differences;
  102. INT32 *RowChangedPixels;
  103. INT8 *TmpCodedMap;
  104. // Plane pointers and dimension variables
  105. UINT8 * YPlanePtr0;
  106. UINT8 * YPlanePtr1;
  107. UINT8 * UPlanePtr0;
  108. UINT8 * UPlanePtr1;
  109. UINT8 * VPlanePtr0;
  110. UINT8 * VPlanePtr1;
  111. UINT32 VideoYPlaneWidth;
  112. UINT32 VideoYPlaneHeight;
  113. UINT32 VideoUVPlaneWidth;
  114. UINT32 VideoUVPlaneHeight;
  115. UINT32 VideoYPlaneStride;
  116. UINT32 VideoUPlaneStride;
  117. UINT32 VideoVPlaneStride;
  118. /* Scan control variables. */
  119. UINT8 HFragPixels;
  120. UINT8 VFragPixels;
  121. UINT32 ScanFrameFragments;
  122. UINT32 ScanYPlaneFragments;
  123. UINT32 ScanUVPlaneFragments;
  124. UINT32 ScanHFragments;
  125. UINT32 ScanVFragments;
  126. UINT32 YFramePixels;
  127. UINT32 UVFramePixels;
  128. UINT32 TotFramePixels;
  129. BOOL SgcOnOff;
  130. UINT32 SgcThresh;
  131. UINT32 OutputBlocksUpdated;
  132. UINT32 KFIndicator;
  133. BOOL ScanSRF_Enabled;
  134. /* The VCAP scan configuration. */
  135. SCAN_CONFIG_DATA ScanConfig;
  136. BOOL VcapOn;
  137. INT32 SRFGreyThresh;
  138. INT32 SRFColThresh;
  139. INT32 SgcLevelThresh;
  140. INT32 SuvcLevelThresh;
  141. INT32 SRFGreyThreshOffset;
  142. INT32 SRFColThreshOffset;
  143. INT32 SgcLevelThreshOffset;
  144. INT32 SuvcLevelThreshOffset;
  145. UINT32 NoiseSupLevel;
  146. /* Block Thresholds. */
  147. UINT32 PrimaryBlockThreshold;
  148. INT32 SRFLevel;
  149. INT32 SRFLevelOffset;
  150. BOOL PAKEnabled;
  151. BOOL EBO_Enabled;
  152. BOOL CategorisationEnabled;
  153. int LevelThresh;
  154. int NegLevelThresh;
  155. int SrfThresh;
  156. int NegSrfThresh;
  157. int HighChange;
  158. int NegHighChange;
  159. // Threshold lookup tables
  160. UINT8 SrfPakThreshTable[512];
  161. UINT8 * SrfPakThreshTablePtr;
  162. UINT8 SrfThreshTable[512];
  163. UINT8 * SrfThreshTablePtr;
  164. UINT8 SgcThreshTable[512];
  165. UINT8 * SgcThreshTablePtr;
  166. // Variables controlling S.A.D. break outs.
  167. UINT32 GrpLowSadThresh;
  168. UINT32 GrpHighSadThresh;
  169. UINT32 ModifiedGrpLowSadThresh;
  170. UINT32 ModifiedGrpHighSadThresh;
  171. INT32 PlaneHFragments;
  172. INT32 PlaneVFragments;
  173. INT32 PlaneHeight;
  174. INT32 PlaneWidth;
  175. INT32 PlaneStride;
  176. UINT32 BlockThreshold;
  177. UINT32 BlockSgcThresh;
  178. double UVBlockThreshCorrection;
  179. double UVSgcCorrection;
  180. UINT32 SpeedCritical;
  181. // Live test harness specific.
  182. // PC specific variables
  183. BOOL MmxEnabled;
  184. BOOL XmmEnabled;
  185. double YUVPlaneCorrectionFactor;
  186. double AbsDiff_ScoreMultiplierTable[256];
  187. UINT8 NoiseScoreBoostTable[256];
  188. UINT8 MaxLineSearchLen;
  189. INT32 YuvDiffsCircularBufferSize;
  190. INT32 ChLocalsCircularBufferSize;
  191. INT32 PixelMapCircularBufferSize;
  192. // Temp stats variable
  193. UINT32 TotBlocksUpdated;
  194. // Function pointers for mmx switches
  195. UINT32 (*RowSAD)(UINT8 *, UINT8 * );
  196. UINT32 (*ColSAD)(xPP_INST ppi, UINT8 *, UINT8 * );
  197. } PP_INSTANCE;
  198. /******************************************************************/
  199. /* Function prototypes. */
  200. /******************************************************************/
  201. INLINE UINT32 ScanGetFragIndex( PP_INSTANCE *ppi, UINT32 FragmentNo )
  202. {
  203. return ppi->ScanPixelIndexTable[ FragmentNo ];
  204. }
  205. extern void InitScanMapArrays
  206. (
  207. PP_INSTANCE *ppi
  208. );
  209. extern void AnalysePlane
  210. (
  211. PP_INSTANCE *ppi, UINT8 * PlanePtr0, UINT8 * PlanePtr1, UINT32 FragArrayOffset, UINT32 PWidth, UINT32 PHeight, UINT32 PStride
  212. );
  213. extern void ScanCalcPixelIndexTable
  214. (
  215. PP_INSTANCE *ppi
  216. );
  217. extern void CreateOutputDisplayMap
  218. (
  219. PP_INSTANCE *ppi,
  220. INT8 *InternalFragmentsPtr
  221. );
  222. extern void SetVcapLevelOffset
  223. (
  224. PP_INSTANCE *ppi, INT32 LevelOffset
  225. );
  226. // Analysis functions
  227. extern void RowBarEnhBlockMap
  228. (
  229. PP_INSTANCE *ppi,
  230. UINT32 * FragScorePtr,
  231. INT8 * FragSgcPtr,
  232. INT8 * UpdatedBlockMapPtr,
  233. INT8 * BarBlockMapPtr,
  234. UINT32 RowNumber
  235. );
  236. extern void BarCopyBack
  237. (
  238. PP_INSTANCE *ppi,
  239. INT8 * UpdatedBlockMapPtr,
  240. INT8 * BarBlockMapPtr
  241. );
  242. // Secondary filter functions
  243. extern UINT8 ApplyLowPass
  244. (
  245. PP_INSTANCE *ppi, UINT8 * SrcPtr, UINT32 PlaneLineLength, INT32 Level
  246. );
  247. // PC specific functions
  248. extern void MachineSpecificConfig
  249. (
  250. );
  251. extern void ClearMmx
  252. (
  253. PP_INSTANCE *ppi
  254. );
  255. extern UINT32 ScalarRowSAD
  256. (
  257. UINT8 * Src1, UINT8 * Src2
  258. );
  259. extern UINT32 ScalarColSAD
  260. (
  261. PP_INSTANCE *ppi, UINT8 * Src1, UINT8 * Src2
  262. );
  263. extern PP_INSTANCE * CreatePPInstance
  264. (
  265. void
  266. );
  267. extern void DeletePPInstance
  268. (
  269. PP_INSTANCE **ppi
  270. );