Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

357 lines
10 KiB

  1. /* *************************************************************************
  2. ** INTEL Corporation Proprietary Information
  3. **
  4. ** This listing is supplied under the terms of a license
  5. ** agreement with INTEL Corporation and may not be copied
  6. ** nor disclosed except in accordance with the terms of
  7. ** that agreement.
  8. **
  9. ** Copyright (c) 1996 Intel Corporation.
  10. ** All Rights Reserved.
  11. **
  12. ** *************************************************************************
  13. */
  14. /*****************************************************************************
  15. *
  16. * d1bef.cpp
  17. *
  18. * DESCRIPTION: Performs post filter on block edges of decompressed Y Plane.
  19. * This is a 1:2:1 filter.
  20. * Edges are processed in macroblock order across the width.
  21. * That is for FCIF GOB's 1&2 are processed across the width not
  22. * GOB 1 followed by GOB 2.
  23. *
  24. * A series of tests determine if an edge should be filtered.
  25. * Edge of Y Plane edges are not filtered.
  26. * For blocks 1-4:
  27. * if block type == empty
  28. * if MV != 0 && Quant > INTER_QUANT_THRESHOLD
  29. * want to filter
  30. * else if block type == INTRA
  31. * if Quant > INTRA_QUANT_THRESHOLD &&
  32. * total run length < HIGH_FREQ_CUTOFF
  33. * want to filter
  34. * else
  35. * if Quant > INTER_QUANT_THRESHOLD &&
  36. * total run lenght < HIGH_FREQ_CUTOFF
  37. * want to filter
  38. *
  39. * Examine edges in pairs, top and left that is:
  40. *
  41. * -----------------------
  42. * | 1 | 2 | 1 | 2 | to filter top of block 1 edge
  43. * ----------------------- examine block 1 if want filter and
  44. * | 3 | 4 | 3 | 4 | previous row block 3 if want filter
  45. * ----------------------- to filter left of block 1 edge
  46. * | 1 | 2 | 1 | 2 | examine block 1 if want filter and
  47. * ----------------------- previous in current row block 2 if
  48. * | 3 | 4 | 3 | 4 | want filter
  49. * -----------------------
  50. *
  51. * Filter all edges that want to be filtered except Plane
  52. * edges.
  53. *
  54. * Routine: BlockEdgeFilter
  55. *
  56. * Inputs: Pointer to decompressed Y Plane, Y Plane height and width,
  57. * decompressed Y Plane pitch, pointer to block
  58. * action stream.
  59. * Whether an block was under the HIGH_FREQ_CUTOFF was
  60. * determined in d1block (variable length decode) and
  61. * overloaded in Block type field of block action stream.
  62. *
  63. * Notes: Investigate 1:6:1 filter as possible intermediate strength.
  64. *
  65. *****************************************************************************
  66. */
  67. // $Header: S:\h26x\src\dec\d1bef.cpv 1.0 05 Apr 1996 13:25:28 AKASAI $
  68. //
  69. // $Log: S:\h26x\src\dec\d1bef.cpv $
  70. //
  71. // Rev 1.0 05 Apr 1996 13:25:28 AKASAI
  72. // Initial revision.
  73. //
  74. #include "precomp.h"
  75. #define INTER_QUANT_THRESHOLD 18 - 8
  76. #define INTRA_QUANT_THRESHOLD 14 - 6
  77. void BlockEdgeFilter(U8 * YPlane, int height, int width, int Pitch,
  78. T_BlkAction *lpBlockAction)
  79. {
  80. T_BlkAction *fpBlockAction;
  81. I32 Pitch16 = (Pitch<<4);
  82. I32 Pitch8 = (Pitch<<3);
  83. I32 i,j,k;
  84. I8 do_filter_1;
  85. I8 do_filter_2;
  86. I8 do_filter_3;
  87. I8 do_filter_4;
  88. I8 Prev_row_BEF_descr[2*22]; /* 2 Y block * 22 (MB) */
  89. I8 Prev2, Prev4;
  90. U8 *r_2, *r_1, *r, *r1;
  91. U8 *rb_2, *rb_1, *rb, *rb1;
  92. U8 *col, *lcol;
  93. /* horizontal edges */
  94. r = YPlane;
  95. r_2 = r - 2*Pitch;
  96. r_1 = r - Pitch;
  97. r1 = r + Pitch;
  98. rb = r + 8*Pitch;
  99. rb_2 = rb - 2*Pitch;
  100. rb_1 = rb - Pitch;
  101. rb1 = rb + Pitch;
  102. fpBlockAction = lpBlockAction;
  103. col = YPlane;
  104. for (i = 0; i<44; i++)
  105. {
  106. Prev_row_BEF_descr[i] = -1;
  107. }
  108. if (width > 176) {
  109. fpBlockAction += 198; /* predecrement pointer */
  110. }
  111. for (j = 0; j < height; j += 16)
  112. {
  113. Prev2 = -1;
  114. Prev4 = -1;
  115. for (i = 0; i < width; i += 16) /* do left & top of blks 1,2,3,4 */
  116. {
  117. if (width > 176) {
  118. if (i == 0) fpBlockAction -= 198;
  119. else if (i == 176) fpBlockAction +=132;
  120. }
  121. do_filter_1 = 0;
  122. do_filter_2 = 0;
  123. do_filter_3 = 0;
  124. do_filter_4 = 0;
  125. if ((fpBlockAction->u8BlkType & 0x7f) == BT_EMPTY)
  126. {
  127. if ( ((fpBlockAction->i8MVX != 0) ||
  128. (fpBlockAction->i8MVY != 0)) &&
  129. (fpBlockAction->u8Quant > INTER_QUANT_THRESHOLD) )
  130. do_filter_1 = 1;
  131. }
  132. else if ((fpBlockAction->u8BlkType & 0x7f) == BT_INTRA)
  133. {
  134. if ((fpBlockAction->u8Quant > INTRA_QUANT_THRESHOLD) &&
  135. ((fpBlockAction->u8BlkType & 0x80) == 0x80))
  136. do_filter_1 = 1;
  137. }
  138. else /* know inter block */
  139. {
  140. if ((fpBlockAction->u8Quant > INTER_QUANT_THRESHOLD) &&
  141. ((fpBlockAction->u8BlkType & 0x80) == 0x80))
  142. do_filter_1 = 1;
  143. }
  144. if (((fpBlockAction+1)->u8BlkType & 0x7f )== BT_EMPTY)
  145. {
  146. if ( (((fpBlockAction+1)->i8MVX != 0) ||
  147. ((fpBlockAction+1)->i8MVY != 0)) &&
  148. ((fpBlockAction+1)->u8Quant > INTER_QUANT_THRESHOLD) &&
  149. (((fpBlockAction+1)->u8BlkType & 0x80) == 0x80))
  150. do_filter_2 = 1;
  151. }
  152. else if (((fpBlockAction+1)->u8BlkType & 0x7f) == BT_INTRA)
  153. {
  154. if (((fpBlockAction+1)->u8Quant > INTRA_QUANT_THRESHOLD) &&
  155. (((fpBlockAction+1)->u8BlkType & 0x80) == 0x80))
  156. do_filter_2 = 1;
  157. }
  158. else /* know inter block */
  159. {
  160. if (((fpBlockAction+1)->u8Quant > INTER_QUANT_THRESHOLD) &&
  161. (((fpBlockAction+1)->u8BlkType & 0x80) == 0x80))
  162. do_filter_2 = 1;
  163. }
  164. if (((fpBlockAction+2)->u8BlkType & 0x7f) == BT_EMPTY)
  165. {
  166. if ( (((fpBlockAction+2)->i8MVX != 0) ||
  167. ((fpBlockAction+2)->i8MVY != 0)) &&
  168. ((fpBlockAction+2)->u8Quant > INTER_QUANT_THRESHOLD) &&
  169. (((fpBlockAction+2)->u8BlkType & 0x80) == 0x80))
  170. do_filter_3 = 1;
  171. }
  172. else if (((fpBlockAction+2)->u8BlkType & 0x7f) == BT_INTRA)
  173. {
  174. if (((fpBlockAction+2)->u8Quant > INTRA_QUANT_THRESHOLD) &&
  175. (((fpBlockAction+2)->u8BlkType & 0x80) == 0x80))
  176. do_filter_3 = 1;
  177. }
  178. else /* know inter block */
  179. {
  180. if (((fpBlockAction+2)->u8Quant > INTER_QUANT_THRESHOLD) &&
  181. (((fpBlockAction+2)->u8BlkType & 0x80) == 0x80))
  182. do_filter_3 = 1;
  183. }
  184. if (((fpBlockAction+3)->u8BlkType & 0x7f) == BT_EMPTY)
  185. {
  186. if ( (((fpBlockAction+3)->i8MVX != 0) ||
  187. ((fpBlockAction+3)->i8MVY != 0)) &&
  188. ((fpBlockAction+3)->u8Quant > INTER_QUANT_THRESHOLD) &&
  189. (((fpBlockAction+3)->u8BlkType & 0x80) == 0x80))
  190. do_filter_4 = 1;
  191. }
  192. else if (((fpBlockAction+3)->u8BlkType & 0x7f)== BT_INTRA)
  193. {
  194. if (((fpBlockAction+3)->u8Quant > INTRA_QUANT_THRESHOLD) &&
  195. (((fpBlockAction+3)->u8BlkType & 0x80) == 0x80))
  196. do_filter_4 = 1;
  197. }
  198. else /* know inter block */
  199. {
  200. if (((fpBlockAction+3)->u8Quant > INTER_QUANT_THRESHOLD) &&
  201. (((fpBlockAction+3)->u8BlkType & 0x80) == 0x80))
  202. do_filter_4 = 1;
  203. }
  204. /* Process block 1 top */
  205. if (do_filter_1 + Prev_row_BEF_descr[(i>>3)] > 0) {
  206. for (k = i; k < i+8; k++) {
  207. #ifdef BLACK_LINE_H
  208. *(r_1 + k) = 60;
  209. *(r + k) = 10;
  210. #else
  211. *(r_1 + k) = (*(r_2 + k) + ((*(r_1+k))<<1) + *(r + k))>>2;
  212. *(r + k) = (*(r_1 + k) + ((*(r + k))<<1) + *(r1 + k))>>2;
  213. #endif
  214. }
  215. }
  216. lcol = col;
  217. /* Process block 1 left */
  218. if (do_filter_1 + Prev2 > 0) {
  219. for (k = 0; k < 8; k++) {
  220. #ifdef BLACK_LINE_V
  221. *(lcol + i-1 ) = 10;
  222. *(lcol + i ) = 60;
  223. #else
  224. *(lcol + i-1 ) = (*(lcol + i-2) + ((*(lcol + i-1))<<1) + *(lcol + i))>>2;
  225. *(lcol + i ) = (*(lcol + i-1) + ((*(lcol + i))<<1) + *(lcol + i+1))>>2;
  226. #endif
  227. lcol += Pitch;
  228. }
  229. }
  230. /* Process block 2 top */
  231. if (do_filter_2 + Prev_row_BEF_descr[((i+8)>>3)] > 0) {
  232. for (k = i+8; k < i+16; k++) {
  233. #ifdef BLACK_LINE_H
  234. *(r_1 + k) = 60;
  235. *(r + k) = 10;
  236. #else
  237. *(r_1 + k) = (*(r_2 + k) + ((*(r_1+k))<<1) + *(r + k))>>2;
  238. *(r + k) = (*(r_1 + k) + ((*(r + k))<<1) + *(r1 + k))>>2;
  239. #endif
  240. }
  241. }
  242. lcol = col;
  243. /* Process block 2 left */
  244. if (do_filter_2 + do_filter_1 > 0) {
  245. for (k = 0; k < 8; k++) {
  246. #ifdef BLACK_LINE_V
  247. *(lcol + i+8-1 ) = 10;
  248. *(lcol + i+8 ) = 60;
  249. #else
  250. *(lcol + i+8-1 ) = (*(lcol + i+8-2) + ((*(lcol + i+8-1))<<1) + *(lcol + i+8))>>2;
  251. *(lcol + i+8 ) = (*(lcol + i+8-1) + ((*(lcol + i+8))<<1) + *(lcol + i+8+1))>>2;
  252. #endif
  253. lcol += Pitch;
  254. }
  255. }
  256. /* bottom row of blocks in macro block */
  257. if (j+8 < height)
  258. {
  259. /* Process Block 3 top */
  260. if (do_filter_3 + do_filter_1 > 0) {
  261. for (k = i; k < i+8; k++) {
  262. #ifdef BLACK_LINE_H
  263. *(rb_1 + k) = 60;
  264. *(rb + k) = 10;
  265. #else
  266. *(rb_1+k) = (*(rb_2+k) + ((*(rb_1+k))<<1) + *(rb+k))>>2;
  267. *(rb + k) = (*(rb_1 + k) + ((*(rb + k))<<1) + *(rb1 + k))>>2;
  268. #endif
  269. }
  270. }
  271. lcol = col + Pitch8;
  272. /* Process Block 3 left */
  273. if (do_filter_3 + Prev4 > 0) {
  274. for (k = 0; k < 8; k++) {
  275. #ifdef BLACK_LINE_V
  276. *(lcol + i-1 ) = 10;
  277. *(lcol + i ) = 60;
  278. #else
  279. *(lcol + i-1 ) = (*(lcol + i-2) + ((*(lcol + i-1))<<1) + *(lcol + i))>>2;
  280. *(lcol + i ) = (*(lcol + i-1) + ((*(lcol + i))<<1) + *(lcol + i+1))>>2;
  281. #endif
  282. lcol += Pitch;
  283. }
  284. }
  285. /* Process block 4 top */
  286. if (do_filter_4 + do_filter_2 > 0) {
  287. for (k = i+8; k < i+16; k++) {
  288. #ifdef BLACK_LINE_H
  289. *(rb_1 + k) = 60;
  290. *(rb + k) = 10;
  291. #else
  292. *(rb_1 + k) = (*(rb_2 + k) + ((*(rb_1+k))<<1) + *(rb + k))>>2;
  293. *(rb + k) = (*(rb_1 + k) + ((*(rb + k))<<1) + *(rb1 + k))>>2;
  294. #endif
  295. }
  296. }
  297. lcol = col + Pitch8;
  298. /* Process block 4 left */
  299. if (do_filter_4 + do_filter_3 > 0) {
  300. for (k = 0; k < 8; k++) {
  301. #ifdef BLACK_LINE_V
  302. *(lcol + i+8-1 ) = 10;
  303. *(lcol + i+8 ) = 60;
  304. #else
  305. *(lcol + i+8-1 ) = (*(lcol + i+8-2) + ((*(lcol + i+8-1))<<1) + *(lcol + i+8))>>2;
  306. *(lcol + i+8 ) = (*(lcol + i+8-1) + ((*(lcol + i+8))<<1) + *(lcol + i+8+1))>>2;
  307. #endif
  308. lcol += Pitch;
  309. }
  310. }
  311. }
  312. fpBlockAction+=6;
  313. Prev_row_BEF_descr[(i>>3)] = do_filter_1;
  314. Prev_row_BEF_descr[((i+8)>>3)] = do_filter_2;
  315. Prev2 = do_filter_2;
  316. Prev4 = do_filter_4;
  317. }
  318. col += Pitch16;
  319. r += Pitch16;
  320. r1 += Pitch16;
  321. r_1 += Pitch16;
  322. r_2 += Pitch16;
  323. rb += Pitch16;
  324. rb1 += Pitch16;
  325. rb_1 += Pitch16;
  326. rb_2 += Pitch16;
  327. }
  328. return;
  329. }