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.

6064 lines
150 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) 1995 Intel Corporation.
  10. ** All Rights Reserved.
  11. **
  12. ** *************************************************************************
  13. */
  14. ////////////////////////////////////////////////////////////////////////////
  15. //
  16. // $Author: MDUDA $
  17. // $Date: 21 Nov 1996 17:33:56 $
  18. // $Archive: S:\h26x\src\enc\excolcnv.cpv $
  19. // $Header: S:\h26x\src\enc\excolcnv.cpv 1.45 21 Nov 1996 17:33:56 MDUDA $
  20. // $Log: S:\h26x\src\enc\excolcnv.cpv $
  21. //
  22. // Rev 1.45 21 Nov 1996 17:33:56 MDUDA
  23. // Added more non-compressed YUV12 support (RGB16 and RGB24).
  24. // Also rewrote IA_YUV12toEncYUV12 to be more readable.
  25. //
  26. // Rev 1.44 31 Oct 1996 10:05:48 KLILLEVO
  27. // changed from DBOUT to DbgLog
  28. //
  29. // Rev 1.43 22 Oct 1996 16:44:22 MDUDA
  30. // Added IA support for YUY2 input color conversion and cleaned up C version.
  31. // Now using IA version.
  32. //
  33. // Rev 1.42 18 Oct 1996 14:31:32 MDUDA
  34. //
  35. // Added a C-version of YUY2 input color conversion.
  36. //
  37. // Rev 1.41 11 Oct 1996 16:04:50 MDUDA
  38. // Using new RGB to YUV lookup tables.
  39. //
  40. // Rev 1.40 03 Oct 1996 10:43:58 AGUPTA2
  41. // Got rid of segment directives; made tables read-only.
  42. //
  43. // Rev 1.39 13 Sep 1996 13:34:04 MDUDA
  44. // Fixed YVU9 bug where input = output frame size was not colored
  45. // (U and V planes) properly.
  46. //
  47. // Rev 1.38 11 Sep 1996 15:45:06 MDUDA
  48. // Modified RGB look-up tables and added C_H26X_YUV12toEncYUV12 and
  49. // IA_H26X_YUV12toEncYUV12.
  50. //
  51. // Rev 1.37 03 Sep 1996 14:54:46 MDUDA
  52. // Fixed problem causing VC++ 4.1 internal compiler error. Replaced
  53. // inline assembler constructs such as [ebx.biWidth] with
  54. // (LPBITMAPINFOHEADER)[ebx].biWidth.
  55. //
  56. // Rev 1.36 29 Aug 1996 16:31:14 MDUDA
  57. // Added Pentium assembler versions for all RGB conversion routines.
  58. // Also, rewrote YVU9 support to allow input frame sizes other
  59. // than 160x120 and 240x180.
  60. //
  61. // Rev 1.35 16 Aug 1996 12:17:48 MDUDA
  62. // Fixed bug where U and V values in the BGR converters were treated as unsign
  63. // values. Also did some general cleanup of BGR converters in preparation for
  64. // doing Pentium assembler version.
  65. //
  66. // Rev 1.34 13 Aug 1996 10:35:38 MDUDA
  67. // Added support for RGB4. Generalized RGB LUT support for 4-bit and
  68. // and 8-bit pixels into a single routine.
  69. //
  70. // Rev 1.33 09 Aug 1996 09:45:02 MDUDA
  71. // Added support for RGB16 format on input. This is for the color
  72. // Quick Cam. Also, generalized RGB16 for other bit combinations.
  73. // However, these can only be specified under BI_BITFIELDS format.
  74. //
  75. // Rev 1.32 02 Aug 1996 13:44:48 MDUDA
  76. // modified H26X_BGR24toYUV12 to crop and stretch 240x180 and 160x120
  77. // frames
  78. //
  79. // Rev 1.31 01 Aug 1996 14:03:50 MDUDA
  80. //
  81. // Optimized H26X_YVU9toYUV12 by rewriting function in assembler code. Used in
  82. // _asm. Also re-arranged functions so that colorCnvtFrame is at the end of
  83. // the file.
  84. //
  85. // Rev 1.30 22 Jul 1996 13:28:22 BECHOLS
  86. // Added a CLUT8 to YUV12 color convertor (CC). This CC crops and stretches
  87. // either the 240x180 or the 160x120 image size to produce QCIF and SubQCIF
  88. // image sizes respectively.
  89. //
  90. // Rev 1.29 11 Jul 1996 15:47:02 MDUDA
  91. //
  92. // Modified H263_YVU9toYUV12 to create subQCIF and QCIF from
  93. // 160x120 and 240x180 images, respectively. To fit the new
  94. // formats, the original images are cropped and stretched using a
  95. // dither pattern for the color planes.
  96. //
  97. // Rev 1.28 14 May 1996 12:04:08 KLILLEVO
  98. // changed RGB->YUV color conversion to use the inverse
  99. // if the output YUV->RGB conversion instead of the conversion
  100. // "recommended by the CCIR". Compression performance for RGB
  101. // input was significantly improved (33% less bits for same
  102. // fixed QP)
  103. //
  104. // Rev 1.27 04 May 1996 21:55:20 BECHOLS
  105. // For RGB24 to YVU12 conversion, I unrolled the inner loop by 8 and changed
  106. // the writes to DWORD vs. BYTE writes. This resulted in a 30% reduction in
  107. // the execution time.
  108. //
  109. // Rev 1.26 10 Apr 1996 16:44:14 RHAZRA
  110. // Fixed a bug in 320x240 mode for the H26X_YUV12toEncYUV12() function.
  111. // DWORD should be and-ed with 0x7f7f7f7f and not 0x7f7f7f.
  112. //
  113. // Rev 1.25 27 Mar 1996 15:10:08 SCDAY
  114. // Optimized H26X_YUV12toEncYUV12 'C' code to read/write DWORDs
  115. //
  116. // Rev 1.24 08 Jan 1996 17:46:14 unknown
  117. //
  118. // Correct logic on bIs320x240 check
  119. //
  120. // Rev 1.23 05 Jan 1996 17:34:38 RMCKENZX
  121. // corrected chroma pad value to 0x40 to achieve black padding
  122. //
  123. // Rev 1.22 05 Jan 1996 17:29:46 RMCKENZX
  124. // Added code to pad out 320x240 stills to 352x288
  125. // full CIF images.
  126. //
  127. // Rev 1.21 04 Jan 1996 18:37:20 TRGARDOS
  128. // Added code to permit 320x240 input and then set a boolean
  129. // bIs320x240.
  130. //
  131. // Rev 1.20 02 Jan 1996 17:09:04 TRGARDOS
  132. // Moved colorCnvFrame into this file and made the
  133. // color convertor functions static.
  134. //
  135. // Rev 1.19 27 Dec 1995 15:32:56 RMCKENZX
  136. // Added copyright notice
  137. //
  138. // Rev 1.18 06 Dec 1995 09:35:42 TRGARDOS
  139. // Added Brian's fix to the input color convertor to avoid
  140. // overflow of the chars.
  141. //
  142. // Rev 1.17 27 Nov 1995 16:09:04 TRGARDOS
  143. // Removed two unused variables to get rid of compiler warnings.
  144. //
  145. // Rev 1.16 30 Oct 1995 14:34:12 TRGARDOS
  146. // Fixed 240x180 to center clip.
  147. //
  148. // Rev 1.15 30 Oct 1995 12:03:16 TRGARDOS
  149. // Added color convertor support for YUV9 240x180.
  150. //
  151. // Rev 1.14 28 Oct 1995 15:39:28 TRGARDOS
  152. // Fixed color conversion problem from YVU9 to YVU12.
  153. //
  154. // Rev 1.13 12 Oct 1995 17:40:12 TRGARDOS
  155. // Fixed YUV12 input color convertor.
  156. //
  157. // Rev 1.12 12 Oct 1995 12:04:16 TRGARDOS
  158. // Changed some variable names in YUV12 convertor.
  159. //
  160. // Rev 1.11 10 Oct 1995 16:34:12 TRGARDOS
  161. // Added YUV12 input support.
  162. //
  163. // Rev 1.10 28 Sep 1995 17:02:36 DBRUCKS
  164. // fix colorIn to not swap left to right
  165. //
  166. // Rev 1.9 15 Sep 1995 16:37:38 TRGARDOS
  167. //
  168. //
  169. // Rev 1.8 13 Sep 1995 17:09:22 TRGARDOS
  170. //
  171. // Finished adding encoder support for YVU9 160x120 frames.
  172. //
  173. // Rev 1.7 11 Sep 1995 11:14:06 DBRUCKS
  174. // add h261 ifdef
  175. //
  176. // Rev 1.6 07 Sep 1995 09:27:54 TRGARDOS
  177. // Added YVU9 to YVU12 color convertor.
  178. //
  179. // Rev 1.5 05 Sep 1995 15:50:46 TRGARDOS
  180. // Added color back in to convertors.
  181. //
  182. // Rev 1.4 01 Sep 1995 17:51:42 TRGARDOS
  183. // Fixed bugs in color converter.
  184. //
  185. // Rev 1.3 01 Sep 1995 10:13:42 TRGARDOS
  186. // Debugging bit stream errors.
  187. //
  188. // Rev 1.2 30 Aug 1995 12:42:26 TRGARDOS
  189. // Fixed bugs in intra AC coef VLC coding.
  190. //
  191. // Rev 1.1 02 Aug 1995 17:28:06 TRGARDOS
  192. //
  193. // Cleaned up stuff to get stub working under new
  194. // version control system.
  195. //
  196. // Rev 1.0 31 Jul 1995 13:07:10 DBRUCKS
  197. // Initial revision.
  198. //
  199. // Rev 1.0 17 Jul 1995 14:46:16 CZHU
  200. // Initial revision.
  201. //
  202. // Rev 1.0 17 Jul 1995 14:14:22 CZHU
  203. // Initial revision.
  204. ;////////////////////////////////////////////////////////////////////////////
  205. /*
  206. CCIR 601 Specifies a conversion from RGB to YCrCb. For
  207. what we call U and V, they are equivalent as
  208. U = Cb, V = Cr.
  209. From CCIR 601-2 Annex II, we can go from RGB with values
  210. in the range of 0-255, to YUV values in the same range
  211. by the equation:
  212. Y = ( 77*R + 150*G + 29*B ) >> 8;
  213. V = ( 131*R - 110*G - 21*B ) >> 8 + 128; // Cr
  214. U = ( (-44)*R - 87*G + 131*B ) >> 8 + 128; // Cb
  215. Has now changed to the inverse of the YUV->RGB on the
  216. output, since the old version produced way too many bits.
  217. The new version is:
  218. Y = ( 16836*R + 33056*G + 6416*B ) >> 16 + 16;
  219. V = ( 28777*R - 24117*G - 4660*B ) >> 16 + 128; // Cr
  220. U = ( (-9726)*R - 19064*G + 28790*B ) >> 16 + 128; // Cb
  221. */
  222. #include "precomp.h"
  223. #if !defined(H263P) && !defined(USE_BILINEAR_MSH26X) // { H263P
  224. #if defined(_CODEC_STATS)
  225. static const double RDTSC_SHIFT_32 = 4294967296.0;
  226. static double PENTIUM_TIMER()
  227. {
  228. unsigned long int a, b;
  229. double temp1, temp2, result;
  230. __asm
  231. {
  232. _emit 0x0f
  233. _emit 0x31
  234. mov a, eax
  235. mov b, edx
  236. }
  237. temp1 = (double) a;
  238. temp2 = (double) (b & 0xFFFF);
  239. if (RDTSC_CLOCK_FREQ) {
  240. result = (temp1 + temp2 * RDTSC_SHIFT_32) / RDTSC_CLOCK_FREQ;
  241. } else {
  242. result = 0.0;
  243. }
  244. return( result * 1000.0 );
  245. }
  246. #endif
  247. // Set all local functions to "static", and then set it accordingly if
  248. // VTune statistics are to be collected. VTune doesn't recognize static functions
  249. // so we need some way to turn off the static attribute if VTune is to be run
  250. // on the executable. For now, simply use a define of _VTUNE to build the driver.
  251. #if defined(_VTUNE)
  252. #define _STATIC
  253. #else
  254. #define _STATIC static
  255. #endif
  256. // These are the look-up tables for the RGB converters. They are 8 bytes/entry
  257. // to allow addressing via the scale by 8 indexed addressing mode. A pseudo-SIMD
  258. // arrangement is used in these tables. Since all R, G and B contributions to the
  259. // Y value are positive and fit in 15 bits, these are stored in the lower 16-bits
  260. // of the YU word. In some cases, the U contribution is negative so it is placed
  261. // in the upper 16 bits of the YU word. When a Y value is calculated, the U value
  262. // is calculated in parallel. The V contribution is negative in some cases, but it
  263. // gets its own word.
  264. // This is the code that was used to generate the tables.
  265. #if 0
  266. #define YRCoef 16836
  267. #define YGCoef 33056
  268. #define YBCoef 6416
  269. #define URCoef 9726
  270. #define UGCoef 19064
  271. #define UBCoef 28790
  272. #define VRCoef 28777
  273. #define VGCoef 24117
  274. #define VBCoef 4660
  275. #include <stdio.h>
  276. void main() {
  277. int i,j;
  278. printf("struct YUV {\n");
  279. printf(" int YU;\n");
  280. printf(" int V;\n");
  281. printf("};\n\n");
  282. printf("struct YUV RYUV[] = {\n");
  283. for (i = 0; i < 64; i++) {
  284. for (j = 0; j < 4; j += 2) {
  285. printf("{0x%.8x, 0x%.8x}, ",
  286. ((YRCoef*((i*4)+j+1))>>9) |
  287. ((-(((URCoef*((i*4)+j+1)))>>9))<<16),
  288. ((VRCoef*((i*4)+j+1))>>9));
  289. }
  290. printf("\n");
  291. }
  292. printf("};\n");
  293. printf("struct YUV GYUV[] = {\n");
  294. for (i = 0; i < 64; i++) {
  295. for (j = 0; j < 4; j += 2) {
  296. printf("{0x%.8x, 0x%.8x}, ",
  297. ((YGCoef*((i*4)+j+1))>>9) |
  298. ((-(((UGCoef*((i*4)+j+1)))>>9))<<16),
  299. -((VGCoef*((i*4)+j+1))>>9));
  300. }
  301. printf("\n");
  302. }
  303. printf("};\n");
  304. printf("struct YUV BYUV[] = {\n");
  305. for (i = 0; i < 64; i++) {
  306. for (j = 0; j < 4; j += 2) {
  307. printf("{0x%.8x, 0x%.8x}, ",
  308. ((YBCoef*((i*4)+j+1))>>9) |
  309. (((UBCoef*((i*4)+j+1))>>9)<<16),
  310. -((VBCoef*((i*4)+j+1))>>9));
  311. }
  312. printf("\n");
  313. }
  314. printf("};\n");
  315. }
  316. #endif
  317. struct YUV {
  318. int YU;
  319. int V;
  320. };
  321. const struct YUV RYUV[] = {
  322. {0xffee0020, 0x00000038}, {0xffc80062, 0x000000a8},
  323. {0xffa200a4, 0x00000119}, {0xff7c00e6, 0x00000189},
  324. {0xff560127, 0x000001f9}, {0xff300169, 0x0000026a},
  325. {0xff0a01ab, 0x000002da}, {0xfee401ed, 0x0000034b},
  326. {0xfebe022f, 0x000003bb}, {0xfe980270, 0x0000042b},
  327. {0xfe7202b2, 0x0000049c}, {0xfe4c02f4, 0x0000050c},
  328. {0xfe260336, 0x0000057d}, {0xfe000377, 0x000005ed},
  329. {0xfdda03b9, 0x0000065d}, {0xfdb403fb, 0x000006ce},
  330. {0xfd8e043d, 0x0000073e}, {0xfd68047e, 0x000007af},
  331. {0xfd4204c0, 0x0000081f}, {0xfd1c0502, 0x0000088f},
  332. {0xfcf60544, 0x00000900}, {0xfcd00585, 0x00000970},
  333. {0xfcaa05c7, 0x000009e1}, {0xfc840609, 0x00000a51},
  334. {0xfc5e064b, 0x00000ac2}, {0xfc38068d, 0x00000b32},
  335. {0xfc1206ce, 0x00000ba2}, {0xfbec0710, 0x00000c13},
  336. {0xfbc60752, 0x00000c83}, {0xfba00794, 0x00000cf4},
  337. {0xfb7a07d5, 0x00000d64}, {0xfb540817, 0x00000dd4},
  338. {0xfb2e0859, 0x00000e45}, {0xfb08089b, 0x00000eb5},
  339. {0xfae208dc, 0x00000f26}, {0xfabc091e, 0x00000f96},
  340. {0xfa960960, 0x00001006}, {0xfa7009a2, 0x00001077},
  341. {0xfa4a09e3, 0x000010e7}, {0xfa240a25, 0x00001158},
  342. {0xf9fe0a67, 0x000011c8}, {0xf9d80aa9, 0x00001239},
  343. {0xf9b20aeb, 0x000012a9}, {0xf98c0b2c, 0x00001319},
  344. {0xf9660b6e, 0x0000138a}, {0xf9400bb0, 0x000013fa},
  345. {0xf91a0bf2, 0x0000146b}, {0xf8f40c33, 0x000014db},
  346. {0xf8ce0c75, 0x0000154b}, {0xf8a80cb7, 0x000015bc},
  347. {0xf8820cf9, 0x0000162c}, {0xf85c0d3a, 0x0000169d},
  348. {0xf8360d7c, 0x0000170d}, {0xf8100dbe, 0x0000177d},
  349. {0xf7ea0e00, 0x000017ee}, {0xf7c40e41, 0x0000185e},
  350. {0xf79e0e83, 0x000018cf}, {0xf7780ec5, 0x0000193f},
  351. {0xf7520f07, 0x000019af}, {0xf72c0f49, 0x00001a20},
  352. {0xf7060f8a, 0x00001a90}, {0xf6e00fcc, 0x00001b01},
  353. {0xf6ba100e, 0x00001b71}, {0xf6941050, 0x00001be2},
  354. {0xf66e1091, 0x00001c52}, {0xf64810d3, 0x00001cc2},
  355. {0xf6221115, 0x00001d33}, {0xf5fc1157, 0x00001da3},
  356. {0xf5d61198, 0x00001e14}, {0xf5b011da, 0x00001e84},
  357. {0xf58a121c, 0x00001ef4}, {0xf564125e, 0x00001f65},
  358. {0xf53e12a0, 0x00001fd5}, {0xf51812e1, 0x00002046},
  359. {0xf4f21323, 0x000020b6}, {0xf4cc1365, 0x00002126},
  360. {0xf4a613a7, 0x00002197}, {0xf48013e8, 0x00002207},
  361. {0xf45a142a, 0x00002278}, {0xf434146c, 0x000022e8},
  362. {0xf40e14ae, 0x00002359}, {0xf3e814ef, 0x000023c9},
  363. {0xf3c21531, 0x00002439}, {0xf39c1573, 0x000024aa},
  364. {0xf37615b5, 0x0000251a}, {0xf35015f6, 0x0000258b},
  365. {0xf32a1638, 0x000025fb}, {0xf304167a, 0x0000266b},
  366. {0xf2de16bc, 0x000026dc}, {0xf2b816fe, 0x0000274c},
  367. {0xf292173f, 0x000027bd}, {0xf26c1781, 0x0000282d},
  368. {0xf24617c3, 0x0000289d}, {0xf2201805, 0x0000290e},
  369. {0xf1fa1846, 0x0000297e}, {0xf1d41888, 0x000029ef},
  370. {0xf1ae18ca, 0x00002a5f}, {0xf188190c, 0x00002acf},
  371. {0xf162194d, 0x00002b40}, {0xf13c198f, 0x00002bb0},
  372. {0xf11619d1, 0x00002c21}, {0xf0f01a13, 0x00002c91},
  373. {0xf0ca1a54, 0x00002d02}, {0xf0a41a96, 0x00002d72},
  374. {0xf07e1ad8, 0x00002de2}, {0xf0581b1a, 0x00002e53},
  375. {0xf0321b5c, 0x00002ec3}, {0xf00c1b9d, 0x00002f34},
  376. {0xefe61bdf, 0x00002fa4}, {0xefc01c21, 0x00003014},
  377. {0xef9a1c63, 0x00003085}, {0xef741ca4, 0x000030f5},
  378. {0xef4e1ce6, 0x00003166}, {0xef281d28, 0x000031d6},
  379. {0xef021d6a, 0x00003246}, {0xeedc1dab, 0x000032b7},
  380. {0xeeb61ded, 0x00003327}, {0xee901e2f, 0x00003398},
  381. {0xee6a1e71, 0x00003408}, {0xee441eb2, 0x00003479},
  382. {0xee1e1ef4, 0x000034e9}, {0xedf81f36, 0x00003559},
  383. {0xedd21f78, 0x000035ca}, {0xedac1fba, 0x0000363a},
  384. {0xed861ffb, 0x000036ab}, {0xed60203d, 0x0000371b},
  385. {0xed3a207f, 0x0000378b}, {0xed1420c1, 0x000037fc},
  386. };
  387. const struct YUV GYUV[] = {
  388. {0xffdb0040, 0xffffffd1}, {0xff9100c1, 0xffffff73},
  389. {0xff460142, 0xffffff15}, {0xfefc01c3, 0xfffffeb7},
  390. {0xfeb10245, 0xfffffe59}, {0xfe6702c6, 0xfffffdfa},
  391. {0xfe1c0347, 0xfffffd9c}, {0xfdd203c8, 0xfffffd3e},
  392. {0xfd880449, 0xfffffce0}, {0xfd3d04ca, 0xfffffc82},
  393. {0xfcf3054b, 0xfffffc23}, {0xfca805cc, 0xfffffbc5},
  394. {0xfc5e064e, 0xfffffb67}, {0xfc1306cf, 0xfffffb09},
  395. {0xfbc90750, 0xfffffaaa}, {0xfb7e07d1, 0xfffffa4c},
  396. {0xfb340852, 0xfffff9ee}, {0xfae908d3, 0xfffff990},
  397. {0xfa9f0954, 0xfffff932}, {0xfa5409d5, 0xfffff8d3},
  398. {0xfa0a0a57, 0xfffff875}, {0xf9bf0ad8, 0xfffff817},
  399. {0xf9750b59, 0xfffff7b9}, {0xf92a0bda, 0xfffff75b},
  400. {0xf8e00c5b, 0xfffff6fc}, {0xf8960cdc, 0xfffff69e},
  401. {0xf84b0d5d, 0xfffff640}, {0xf8010dde, 0xfffff5e2},
  402. {0xf7b60e60, 0xfffff584}, {0xf76c0ee1, 0xfffff525},
  403. {0xf7210f62, 0xfffff4c7}, {0xf6d70fe3, 0xfffff469},
  404. {0xf68c1064, 0xfffff40b}, {0xf64210e5, 0xfffff3ad},
  405. {0xf5f71166, 0xfffff34e}, {0xf5ad11e7, 0xfffff2f0},
  406. {0xf5621269, 0xfffff292}, {0xf51812ea, 0xfffff234},
  407. {0xf4cd136b, 0xfffff1d6}, {0xf48313ec, 0xfffff177},
  408. {0xf439146d, 0xfffff119}, {0xf3ee14ee, 0xfffff0bb},
  409. {0xf3a4156f, 0xfffff05d}, {0xf35915f0, 0xffffeffe},
  410. {0xf30f1672, 0xffffefa0}, {0xf2c416f3, 0xffffef42},
  411. {0xf27a1774, 0xffffeee4}, {0xf22f17f5, 0xffffee86},
  412. {0xf1e51876, 0xffffee27}, {0xf19a18f7, 0xffffedc9},
  413. {0xf1501978, 0xffffed6b}, {0xf10519f9, 0xffffed0d},
  414. {0xf0bb1a7b, 0xffffecaf}, {0xf0701afc, 0xffffec50},
  415. {0xf0261b7d, 0xffffebf2}, {0xefdb1bfe, 0xffffeb94},
  416. {0xef911c7f, 0xffffeb36}, {0xef471d00, 0xffffead8},
  417. {0xeefc1d81, 0xffffea79}, {0xeeb21e02, 0xffffea1b},
  418. {0xee671e84, 0xffffe9bd}, {0xee1d1f05, 0xffffe95f},
  419. {0xedd21f86, 0xffffe901}, {0xed882007, 0xffffe8a2},
  420. {0xed3d2088, 0xffffe844}, {0xecf32109, 0xffffe7e6},
  421. {0xeca8218a, 0xffffe788}, {0xec5e220b, 0xffffe72a},
  422. {0xec13228d, 0xffffe6cb}, {0xebc9230e, 0xffffe66d},
  423. {0xeb7e238f, 0xffffe60f}, {0xeb342410, 0xffffe5b1},
  424. {0xeaea2491, 0xffffe552}, {0xea9f2512, 0xffffe4f4},
  425. {0xea552593, 0xffffe496}, {0xea0a2614, 0xffffe438},
  426. {0xe9c02696, 0xffffe3da}, {0xe9752717, 0xffffe37b},
  427. {0xe92b2798, 0xffffe31d}, {0xe8e02819, 0xffffe2bf},
  428. {0xe896289a, 0xffffe261}, {0xe84b291b, 0xffffe203},
  429. {0xe801299c, 0xffffe1a4}, {0xe7b62a1d, 0xffffe146},
  430. {0xe76c2a9f, 0xffffe0e8}, {0xe7212b20, 0xffffe08a},
  431. {0xe6d72ba1, 0xffffe02c}, {0xe68c2c22, 0xffffdfcd},
  432. {0xe6422ca3, 0xffffdf6f}, {0xe5f82d24, 0xffffdf11},
  433. {0xe5ad2da5, 0xffffdeb3}, {0xe5632e26, 0xffffde55},
  434. {0xe5182ea8, 0xffffddf6}, {0xe4ce2f29, 0xffffdd98},
  435. {0xe4832faa, 0xffffdd3a}, {0xe439302b, 0xffffdcdc},
  436. {0xe3ee30ac, 0xffffdc7e}, {0xe3a4312d, 0xffffdc1f},
  437. {0xe35931ae, 0xffffdbc1}, {0xe30f322f, 0xffffdb63},
  438. {0xe2c432b1, 0xffffdb05}, {0xe27a3332, 0xffffdaa6},
  439. {0xe22f33b3, 0xffffda48}, {0xe1e53434, 0xffffd9ea},
  440. {0xe19b34b5, 0xffffd98c}, {0xe1503536, 0xffffd92e},
  441. {0xe10635b7, 0xffffd8cf}, {0xe0bb3638, 0xffffd871},
  442. {0xe07136ba, 0xffffd813}, {0xe026373b, 0xffffd7b5},
  443. {0xdfdc37bc, 0xffffd757}, {0xdf91383d, 0xffffd6f8},
  444. {0xdf4738be, 0xffffd69a}, {0xdefc393f, 0xffffd63c},
  445. {0xdeb239c0, 0xffffd5de}, {0xde673a41, 0xffffd580},
  446. {0xde1d3ac3, 0xffffd521}, {0xddd23b44, 0xffffd4c3},
  447. {0xdd883bc5, 0xffffd465}, {0xdd3d3c46, 0xffffd407},
  448. {0xdcf33cc7, 0xffffd3a9}, {0xdca93d48, 0xffffd34a},
  449. {0xdc5e3dc9, 0xffffd2ec}, {0xdc143e4a, 0xffffd28e},
  450. {0xdbc93ecc, 0xffffd230}, {0xdb7f3f4d, 0xffffd1d2},
  451. {0xdb343fce, 0xffffd173}, {0xdaea404f, 0xffffd115},
  452. };
  453. const struct YUV BYUV[] = {
  454. {0x0038000c, 0xfffffff7}, {0x00a80025, 0xffffffe5},
  455. {0x0119003e, 0xffffffd3}, {0x01890057, 0xffffffc1},
  456. {0x01fa0070, 0xffffffaf}, {0x026a0089, 0xffffff9c},
  457. {0x02da00a2, 0xffffff8a}, {0x034b00bb, 0xffffff78},
  458. {0x03bb00d5, 0xffffff66}, {0x042c00ee, 0xffffff54},
  459. {0x049c0107, 0xffffff41}, {0x050d0120, 0xffffff2f},
  460. {0x057d0139, 0xffffff1d}, {0x05ee0152, 0xffffff0b},
  461. {0x065e016b, 0xfffffef9}, {0x06cf0184, 0xfffffee6},
  462. {0x073f019d, 0xfffffed4}, {0x07b001b6, 0xfffffec2},
  463. {0x082001cf, 0xfffffeb0}, {0x089001e8, 0xfffffe9e},
  464. {0x09010201, 0xfffffe8b}, {0x0971021a, 0xfffffe79},
  465. {0x09e20233, 0xfffffe67}, {0x0a52024c, 0xfffffe55},
  466. {0x0ac30266, 0xfffffe43}, {0x0b33027f, 0xfffffe30},
  467. {0x0ba40298, 0xfffffe1e}, {0x0c1402b1, 0xfffffe0c},
  468. {0x0c8502ca, 0xfffffdfa}, {0x0cf502e3, 0xfffffde8},
  469. {0x0d6602fc, 0xfffffdd5}, {0x0dd60315, 0xfffffdc3},
  470. {0x0e46032e, 0xfffffdb1}, {0x0eb70347, 0xfffffd9f},
  471. {0x0f270360, 0xfffffd8c}, {0x0f980379, 0xfffffd7a},
  472. {0x10080392, 0xfffffd68}, {0x107903ab, 0xfffffd56},
  473. {0x10e903c4, 0xfffffd44}, {0x115a03dd, 0xfffffd31},
  474. {0x11ca03f7, 0xfffffd1f}, {0x123b0410, 0xfffffd0d},
  475. {0x12ab0429, 0xfffffcfb}, {0x131c0442, 0xfffffce9},
  476. {0x138c045b, 0xfffffcd6}, {0x13fc0474, 0xfffffcc4},
  477. {0x146d048d, 0xfffffcb2}, {0x14dd04a6, 0xfffffca0},
  478. {0x154e04bf, 0xfffffc8e}, {0x15be04d8, 0xfffffc7b},
  479. {0x162f04f1, 0xfffffc69}, {0x169f050a, 0xfffffc57},
  480. {0x17100523, 0xfffffc45}, {0x1780053c, 0xfffffc33},
  481. {0x17f10555, 0xfffffc20}, {0x1861056e, 0xfffffc0e},
  482. {0x18d20588, 0xfffffbfc}, {0x194205a1, 0xfffffbea},
  483. {0x19b205ba, 0xfffffbd8}, {0x1a2305d3, 0xfffffbc5},
  484. {0x1a9305ec, 0xfffffbb3}, {0x1b040605, 0xfffffba1},
  485. {0x1b74061e, 0xfffffb8f}, {0x1be50637, 0xfffffb7d},
  486. {0x1c550650, 0xfffffb6a}, {0x1cc60669, 0xfffffb58},
  487. {0x1d360682, 0xfffffb46}, {0x1da7069b, 0xfffffb34},
  488. {0x1e1706b4, 0xfffffb22}, {0x1e8806cd, 0xfffffb0f},
  489. {0x1ef806e6, 0xfffffafd}, {0x1f6806ff, 0xfffffaeb},
  490. {0x1fd90719, 0xfffffad9}, {0x20490732, 0xfffffac7},
  491. {0x20ba074b, 0xfffffab4}, {0x212a0764, 0xfffffaa2},
  492. {0x219b077d, 0xfffffa90}, {0x220b0796, 0xfffffa7e},
  493. {0x227c07af, 0xfffffa6c}, {0x22ec07c8, 0xfffffa59},
  494. {0x235d07e1, 0xfffffa47}, {0x23cd07fa, 0xfffffa35},
  495. {0x243e0813, 0xfffffa23}, {0x24ae082c, 0xfffffa11},
  496. {0x251e0845, 0xfffff9fe}, {0x258f085e, 0xfffff9ec},
  497. {0x25ff0877, 0xfffff9da}, {0x26700890, 0xfffff9c8},
  498. {0x26e008aa, 0xfffff9b6}, {0x275108c3, 0xfffff9a3},
  499. {0x27c108dc, 0xfffff991}, {0x283208f5, 0xfffff97f},
  500. {0x28a2090e, 0xfffff96d}, {0x29130927, 0xfffff95b},
  501. {0x29830940, 0xfffff948}, {0x29f40959, 0xfffff936},
  502. {0x2a640972, 0xfffff924}, {0x2ad4098b, 0xfffff912},
  503. {0x2b4509a4, 0xfffff8ff}, {0x2bb509bd, 0xfffff8ed},
  504. {0x2c2609d6, 0xfffff8db}, {0x2c9609ef, 0xfffff8c9},
  505. {0x2d070a08, 0xfffff8b7}, {0x2d770a21, 0xfffff8a4},
  506. {0x2de80a3b, 0xfffff892}, {0x2e580a54, 0xfffff880},
  507. {0x2ec90a6d, 0xfffff86e}, {0x2f390a86, 0xfffff85c},
  508. {0x2faa0a9f, 0xfffff849}, {0x301a0ab8, 0xfffff837},
  509. {0x308a0ad1, 0xfffff825}, {0x30fb0aea, 0xfffff813},
  510. {0x316b0b03, 0xfffff801}, {0x31dc0b1c, 0xfffff7ee},
  511. {0x324c0b35, 0xfffff7dc}, {0x32bd0b4e, 0xfffff7ca},
  512. {0x332d0b67, 0xfffff7b8}, {0x339e0b80, 0xfffff7a6},
  513. {0x340e0b99, 0xfffff793}, {0x347f0bb2, 0xfffff781},
  514. {0x34ef0bcc, 0xfffff76f}, {0x35600be5, 0xfffff75d},
  515. {0x35d00bfe, 0xfffff74b}, {0x36400c17, 0xfffff738},
  516. {0x36b10c30, 0xfffff726}, {0x37210c49, 0xfffff714},
  517. {0x37920c62, 0xfffff702}, {0x38020c7b, 0xfffff6f0},
  518. };
  519. #define COEF_WIDTH 8
  520. #define SHIFT_WIDTH COEF_WIDTH
  521. //
  522. // All of the RGB converters follow the template given below. The converters make
  523. // some assumptions about the frame size. All output frame sizes are assumed to
  524. // have a frame height that is a multiple of 48. Also, the output frame width
  525. // is assumed to be a multiple of 8. If the input frame size is equal
  526. // to the output frame size, no stretching or cropping is done. Otherwise, the
  527. // image is cropped and stretched for an 11:12 aspect ratio.
  528. //
  529. #if 0
  530. void rgb_color_converter() {
  531. for (j = 0; j < LumaIters; j++) {
  532. for (k = 0; k < mark; k++) {
  533. for (i = FrameWidth; i > 0; i -= m, pnext += n) {
  534. compute m Y values using look-up tables
  535. if (0 == (k&1)) {
  536. compute m/2 U,V values using look-up tables
  537. }
  538. }
  539. if ((0 == k) && j) {
  540. for (i = FrameWidth; i > 0; i -= 8 {
  541. t = *pyprev++ & 0xFEFEFEFE;
  542. t += *pynext++ & 0xFEFEFEFE;
  543. *pyspace++ = t;
  544. t = *pyprev++ & 0xFEFEFEFE;
  545. t += *pynext++ & 0xFEFEFEFE;
  546. *pyspace++ = t;
  547. }
  548. }
  549. pnext += iBackTwoLines;
  550. py += ypitch_adj;
  551. if (0 == (k&1)) {
  552. pu += uvpitch_adj;
  553. pv += uvpitch_adj;
  554. }
  555. }
  556. if (stretch) {
  557. pyprev = py - pitch;
  558. pyspace = py;
  559. pynext = py + pitch;
  560. }
  561. }
  562. if (stretch) {
  563. for (i = FrameWidth; i > 0; i -= 4 {
  564. *pyspace++ = *pyprev++;
  565. }
  566. }
  567. }
  568. #endif
  569. //
  570. // For the IA versions, the strategy is to compute the Y value for an odd RGB value
  571. // followed by computing the Y value for the corresponding even RGB value. The registers
  572. // are then set with the proper values to compute U and V values for the even RGB
  573. // value. This avoids repeating the shifting and masking needed to extract the Red,
  574. // Green and Blue components.
  575. //
  576. /*****************************************************************************
  577. *
  578. * H26X_BGR24toYUV12()
  579. *
  580. * Convert from BGR24 to YUV12 (YCrCb 4:2:0) and copy to destination memory
  581. * with pitch defined by the constant PITCH. The input data is stored in
  582. * the order B,G,R,B,G,R...
  583. *
  584. */
  585. #if defined(_CODEC_STATS)
  586. #define NOC_SHIFT_WIDTH 7
  587. void NOC_H26X_BGR24toYUV12(
  588. LPBITMAPINFOHEADER lpbiInput,
  589. U8 * lpInput,
  590. U8 * YPlane,
  591. U8 * UPlane,
  592. U8 * VPlane,
  593. UN FrameWidth,
  594. UN FrameHeight,
  595. const int pitch)
  596. {
  597. U32 *pnext, *pyprev, *pyspace, *pynext;
  598. U32 tm;
  599. int t;
  600. int i, j, k;
  601. int iBackTwoLines;
  602. int stretch, mark, aspect;
  603. int height_adj, width_adj;
  604. int LumaIters = 0;
  605. int ypitch_adj = 0;
  606. int uvpitch_adj = 0;
  607. // This loop is here simply to avoid a divide. LumaIters = (FrameHeight/12).
  608. for (i = FrameHeight; i > 0; i -= 48) {
  609. LumaIters += 4;
  610. }
  611. width_adj = (lpbiInput->biWidth - FrameWidth) >> 1;
  612. width_adj += (width_adj << 1);
  613. aspect = (width_adj ? LumaIters : 0);
  614. height_adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1;
  615. stretch = (height_adj ? 1 : 0);
  616. mark = 12 - stretch;
  617. // The input image is upside down - process the lines in reverse order.
  618. // Move from end of line N to beginning of line N-1
  619. iBackTwoLines = -((lpbiInput->biWidth + (int)FrameWidth) >> 2);
  620. iBackTwoLines += (iBackTwoLines << 1);
  621. // Point to the beginning of the last line.
  622. pnext = (U32 *)
  623. (lpInput +
  624. ((lpbiInput->biWidth + (lpbiInput->biWidth << 1)) *
  625. ((FrameHeight - aspect - 1) + height_adj)) +
  626. width_adj);
  627. for ( j = 0; j < LumaIters; j++) {
  628. for (k = 0; k < mark; k++) {
  629. for (i = FrameWidth; i > 0; i -= 4, pnext += 3) {
  630. tm = pnext[0];
  631. t = BYUV[tm>>25].YU;
  632. tm = pnext[1];
  633. t += (GYUV[(tm>>1)&0x7F].YU +
  634. RYUV[(tm>>9)&0x7F].YU);
  635. *(YPlane+1) = (U8)((t>>NOC_SHIFT_WIDTH)+16);
  636. tm = pnext[0];
  637. t = (BYUV[(tm>>1)&0x7F].YU +
  638. GYUV[(tm>>9)&0x7F].YU +
  639. RYUV[(tm>>17)&0x7F].YU);
  640. *YPlane = (U8)((t>>NOC_SHIFT_WIDTH)+16);
  641. if (0 == (k&1)) {
  642. *UPlane++ = (U8)((t>>23)+128);
  643. t = (RYUV[(tm>>17)&0x7F].V +
  644. GYUV[(tm>>9)&0x7F].V +
  645. BYUV[(tm>>1)&0x7F].V);
  646. *VPlane++ = (U8)((t>>NOC_SHIFT_WIDTH)+128);
  647. }
  648. tm = pnext[2];
  649. t = (BYUV[(tm>>9)&0x7F].YU +
  650. GYUV[(tm>>17)&0x7F].YU +
  651. RYUV[tm>>25].YU);
  652. *(YPlane+3) = (U8)((t>>NOC_SHIFT_WIDTH)+16);
  653. tm = pnext[1];
  654. t = BYUV[(tm>>17)&0x7F].YU + GYUV[tm>>25].YU;
  655. tm = pnext[2];
  656. t += RYUV[(tm>>1)&0x7F].YU;
  657. *(YPlane+2) = (U8)((t>>NOC_SHIFT_WIDTH)+16);
  658. YPlane += 4;
  659. if (0 == (k&1)) {
  660. *UPlane++ = (U8)((t>>23)+128);
  661. t = RYUV[(tm>>1)&0x7F].V;
  662. tm = pnext[1];
  663. t += GYUV[tm>>25].V + BYUV[(tm>>17)&0x7F].V;
  664. *VPlane++ = (U8)((t>>NOC_SHIFT_WIDTH)+128);
  665. }
  666. }
  667. if (stretch && (0 == k) && j) {
  668. for (i = FrameWidth; i > 0; i -= 8) {
  669. tm = ((*pyprev++ & 0xFEFEFEFE) >> 1);
  670. tm += ((*pynext++ & 0xFEFEFEFE) >> 1);
  671. *pyspace++ = tm;
  672. tm = ((*pyprev++ & 0xFEFEFEFE) >> 1);
  673. tm += ((*pynext++ & 0xFEFEFEFE) >> 1);
  674. *pyspace++ = tm;
  675. }
  676. }
  677. pnext += iBackTwoLines;
  678. YPlane += ypitch_adj;
  679. // Increment after even lines.
  680. if(0 == (k&1)) {
  681. UPlane += uvpitch_adj;
  682. VPlane += uvpitch_adj;
  683. }
  684. } // end of for k
  685. if (stretch) {
  686. pyprev = (U32 *)(YPlane - pitch);
  687. pyspace = (U32 *)YPlane;
  688. pynext = (U32 *)(YPlane += pitch);
  689. }
  690. } // end of for j
  691. if (stretch) {
  692. for (i = FrameWidth; i > 0; i -= 4) {
  693. *pyspace++ = *pyprev++;
  694. }
  695. }
  696. } // end of NOC_H26X_BGR24toYUV12()
  697. #endif
  698. #if 0
  699. _STATIC void C_H26X_BGR24toYUV12(
  700. LPBITMAPINFOHEADER lpbiInput,
  701. U8 * lpInput,
  702. U8 * YPlane,
  703. U8 * UPlane,
  704. U8 * VPlane,
  705. UN FrameWidth,
  706. UN FrameHeight,
  707. const int pitch)
  708. {
  709. U32 *pnext, *pyprev, *pyspace, *pynext;
  710. U32 tm;
  711. int t;
  712. int i, j, k;
  713. int iBackTwoLines;
  714. int stretch, mark, aspect;
  715. int height_adj, width_adj;
  716. int LumaIters = 0;
  717. int ypitch_adj = pitch - FrameWidth;
  718. int uvpitch_adj = pitch - (FrameWidth >> 1);
  719. // This loop is here simply to avoid a divide. LumaIters = (FrameHeight/12).
  720. for (i = FrameHeight; i > 0; i -= 48) {
  721. LumaIters += 4;
  722. }
  723. width_adj = (lpbiInput->biWidth - FrameWidth) >> 1;
  724. width_adj += (width_adj << 1);
  725. aspect = (width_adj ? LumaIters : 0);
  726. height_adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1;
  727. stretch = (height_adj ? 1 : 0);
  728. mark = 12 - stretch;
  729. // The input image is upside down - process the lines in reverse order.
  730. // Move from end of line N to beginning of line N-1
  731. iBackTwoLines = -((lpbiInput->biWidth + (int)FrameWidth) >> 2);
  732. iBackTwoLines += (iBackTwoLines << 1);
  733. // Point to the beginning of the last line.
  734. pnext = (U32 *)
  735. (lpInput +
  736. ((lpbiInput->biWidth + (lpbiInput->biWidth << 1)) *
  737. ((FrameHeight - aspect - 1) + height_adj)) +
  738. width_adj);
  739. for ( j = 0; j < LumaIters; j++) {
  740. for (k = 0; k < mark; k++) {
  741. for (i = FrameWidth; i > 0; i -= 4, pnext += 3) {
  742. tm = pnext[0];
  743. t = BYUV[tm>>25].YU;
  744. tm = pnext[1];
  745. t += (GYUV[(tm>>1)&0x7F].YU +
  746. RYUV[(tm>>9)&0x7F].YU);
  747. *(YPlane+1) = (U8)((t>>SHIFT_WIDTH)+8);
  748. tm = pnext[0];
  749. t = (BYUV[(tm>>1)&0x7F].YU +
  750. GYUV[(tm>>9)&0x7F].YU +
  751. RYUV[(tm>>17)&0x7F].YU);
  752. *YPlane = (U8)((t>>SHIFT_WIDTH)+8);
  753. if (0 == (k&1)) {
  754. *UPlane++ = (U8)((t>>24)+64);
  755. t = (RYUV[(tm>>17)&0x7F].V +
  756. GYUV[(tm>>9)&0x7F].V +
  757. BYUV[(tm>>1)&0x7F].V);
  758. *VPlane++ = (U8)((t>>SHIFT_WIDTH)+64);
  759. }
  760. tm = pnext[2];
  761. t = (BYUV[(tm>>9)&0x7F].YU +
  762. GYUV[(tm>>17)&0x7F].YU +
  763. RYUV[tm>>25].YU);
  764. *(YPlane+3) = (U8)((t>>SHIFT_WIDTH)+8);
  765. tm = pnext[1];
  766. t = BYUV[(tm>>17)&0x7F].YU + GYUV[tm>>25].YU;
  767. tm = pnext[2];
  768. t += RYUV[(tm>>1)&0x7F].YU;
  769. *(YPlane+2) = (U8)((t>>SHIFT_WIDTH)+8);
  770. YPlane += 4;
  771. if (0 == (k&1)) {
  772. *UPlane++ = (U8)((t>>24)+64);
  773. t = RYUV[(tm>>1)&0x7F].V;
  774. tm = pnext[1];
  775. t += GYUV[tm>>25].V + BYUV[(tm>>17)&0x7F].V;
  776. *VPlane++ = (U8)((t>>SHIFT_WIDTH)+64);
  777. }
  778. }
  779. if (stretch && (0 == k) && j) {
  780. for (i = FrameWidth; i > 0; i -= 8) {
  781. tm = ((*pyprev++ & 0xFEFEFEFE) >> 1);
  782. tm += ((*pynext++ & 0xFEFEFEFE) >> 1);
  783. *pyspace++ = tm;
  784. tm = ((*pyprev++ & 0xFEFEFEFE) >> 1);
  785. tm += ((*pynext++ & 0xFEFEFEFE) >> 1);
  786. *pyspace++ = tm;
  787. }
  788. }
  789. pnext += iBackTwoLines;
  790. YPlane += ypitch_adj;
  791. // Increment after even lines.
  792. if(0 == (k&1)) {
  793. UPlane += uvpitch_adj;
  794. VPlane += uvpitch_adj;
  795. }
  796. } // end of for k
  797. if (stretch) {
  798. pyprev = (U32 *)(YPlane - pitch);
  799. pyspace = (U32 *)YPlane;
  800. pynext = (U32 *)(YPlane += pitch);
  801. }
  802. } // end of for j
  803. if (stretch) {
  804. for (i = FrameWidth; i > 0; i -= 4) {
  805. *pyspace++ = *pyprev++;
  806. }
  807. }
  808. } // end of C_H26X_BGR24toYUV12()
  809. #endif
  810. __declspec(naked)
  811. _STATIC void IA_H26X_BGR24toYUV12(
  812. LPBITMAPINFOHEADER lpbiInput,
  813. U8 * BGR24Image,
  814. U8 * YPlane,
  815. U8 * UPlane,
  816. U8 * VPlane,
  817. UN FrameWidth,
  818. UN FrameHeight,
  819. const int pitch)
  820. {
  821. // Permanent (callee-save) registers - ebx, esi, edi, ebp
  822. // Temporary (caller-save) registers - eax, ecx, edx
  823. //
  824. // Stack frame layout
  825. // | pitch | + 96
  826. // | FrameHeight | + 92
  827. // | FrameWidth | + 88
  828. // | VPlane | + 84
  829. // | UPlane | + 80
  830. // | YPlane | + 76
  831. // | lpInput | + 72
  832. // | lpbiInput | + 68
  833. // ----------------------------
  834. // | return addr | + 64
  835. // | saved ebp | + 60
  836. // | saved ebx | + 56
  837. // | saved esi | + 52
  838. // | saved edi | + 48
  839. // | pyprev | + 44
  840. // | pyspace | + 40
  841. // | pynext | + 36
  842. // | i | + 32
  843. // | j | + 28
  844. // | k | + 24
  845. // | iBackTwoLines | + 20
  846. // | stretch | + 16
  847. // | mark | + 12
  848. // | LumaIters | + 8
  849. // | ypitch_adj | + 4
  850. // | uvpitch_adj | + 0
  851. #define LOCALSIZE 48
  852. #define PITCH_PARM 96
  853. #define FRAME_HEIGHT 92
  854. #define FRAME_WIDTH 88
  855. #define VPLANE 84
  856. #define UPLANE 80
  857. #define YPLANE 76
  858. #define LP_INPUT 72
  859. #define LPBI_INPUT 68
  860. #define PYPREV 44
  861. #define PYSPACE 40
  862. #define PYNEXT 36
  863. #define LOOP_I 32
  864. #define LOOP_J 28
  865. #define LOOP_K 24
  866. #define BACK_TWO_LINES 20
  867. #define STRETCH 16
  868. #define MARK 12
  869. #define LUMA_ITERS 8
  870. #define YPITCH_ADJ 4
  871. #define UVPITCH_ADJ 0
  872. _asm {
  873. push ebp
  874. push ebx
  875. push esi
  876. push edi
  877. sub esp, LOCALSIZE
  878. // assign (ebx, lpbiInput)
  879. mov ebx, [esp + LPBI_INPUT]
  880. // ypitch_adj = pitch - FrameWidth
  881. // assign (ecx, FrameWidth)
  882. // assign (edx, pitch)
  883. mov ecx, [esp + FRAME_WIDTH]
  884. mov edx, [esp + PITCH_PARM]
  885. mov eax, edx
  886. sub eax, ecx
  887. mov [esp + YPITCH_ADJ], eax
  888. // uvpitch_adj = pitch - (FrameWidth >> 1)
  889. // kill (edx, pitch)
  890. mov ebp, ecx
  891. shr ebp, 1
  892. sub edx, ebp
  893. mov [esp + UVPITCH_ADJ], edx
  894. // for (i = FrameHeight; i > 0; i -= 48) LumaIters += 4
  895. // assign (edx, LumaIters)
  896. xor edx, edx
  897. mov eax, [esp + FRAME_HEIGHT]
  898. L1:
  899. lea edx, [edx + 4]
  900. sub eax, 48
  901. jnz L1
  902. // width_adj = (lpbiInput->biWidth - FrameWidth) >> 1
  903. // width_adj += width_adj << 1
  904. // assign (esi, width_adj)
  905. mov esi, (LPBITMAPINFOHEADER)[ebx].biWidth
  906. sub esi, [esp + FRAME_WIDTH]
  907. mov eax, esi
  908. shr eax, 1
  909. add esi, eax
  910. // aspect = (width_adj ? LumaIters : 0)
  911. // assign (edi, aspect)
  912. // kill (edx, LumaIters)
  913. mov [esp + LUMA_ITERS], edx
  914. xor edi, edi
  915. test esi, esi
  916. jz L2
  917. mov edi, edx
  918. // height _adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1
  919. // assign (edx, height_adj)
  920. L2:
  921. mov edx, (LPBITMAPINFOHEADER)[ebx].biHeight
  922. sub edx, [esp + FRAME_HEIGHT]
  923. add edx, edi
  924. shr edx, 1
  925. // stretch = (height_adj ? 1 : 0)
  926. xor eax, eax
  927. test edx, edx
  928. jz L3
  929. inc eax
  930. L3:
  931. mov [esp + STRETCH], eax
  932. // mark = 12 - stretch
  933. mov ebp, 12
  934. sub ebp, eax
  935. mov [esp + MARK], ebp
  936. // iBackTwoLines = -(lpbiInput->biWidth + FrameWidth)
  937. // iBackTwoLines += (iBackTwoLines << 1)
  938. mov ebp, (LPBITMAPINFOHEADER)[ebx].biWidth
  939. add ebp, [esp + FRAME_WIDTH]
  940. neg ebp
  941. mov eax, ebp
  942. shl eax, 1
  943. add ebp, eax
  944. mov [esp + BACK_TWO_LINES], ebp
  945. // pnext = lpInput +
  946. // ((lpbiInput->biWidth + (lpbiInput->biWidth << 1)) *
  947. // ((FrameHeight - aspect - 1) + height_adj)) +
  948. // width_adj
  949. // kill (ebx, lpbiInput)
  950. // kill (ecx, FrameWidth)
  951. // kill (edx, height_adj)
  952. // kill (esi, width_adj)
  953. // kill (edi, aspect)
  954. // assign (esi, pnext)
  955. mov eax, (LPBITMAPINFOHEADER)[ebx].biWidth
  956. shl eax, 1
  957. add eax, (LPBITMAPINFOHEADER)[ebx].biWidth
  958. mov ebx, [esp + FRAME_HEIGHT]
  959. sub ebx, edi
  960. dec ebx
  961. add ebx, edx
  962. imul ebx
  963. add esi, eax
  964. add esi, [esp + LP_INPUT]
  965. // assign (edi, YPlane)
  966. mov edi, [esp + YPLANE]
  967. // for (j = 0; j < LumaIters; j++)
  968. xor eax, eax
  969. mov [esp + LOOP_J], eax
  970. // for (k = 0; k < mark; k++)
  971. L4:
  972. xor eax, eax
  973. mov [esp + LOOP_K], eax
  974. // for (i = FrameWidth; i > 0; i -= 4, pnext += 12)
  975. L5:
  976. mov eax, [esp + FRAME_WIDTH]
  977. mov [esp + LOOP_I], eax
  978. // This jump is here to make sure the following loop starts in the U pipe
  979. jmp L6
  980. L6:
  981. // ---------------------
  982. // | B2 | R1 | G1 | B1 | pnext[0]
  983. // ---------------------
  984. // | G3 | B3 | R2 | G2 | pnext[1]
  985. // ---------------------
  986. // | R4 | G4 | B4 | R3 | pnext[2]
  987. // ---------------------
  988. // t0 = pnext[0]
  989. // t1 = pnext[1]
  990. // t = ( BYUV[t0>>25].YU +
  991. // GYUV[(t1>> 1)&0x7F].YU +
  992. // RYUV[(t1>> 9)&0x7F].YU )
  993. // *(YPlane+1) = ((t>>8)+8)
  994. // t = ( BYUV[(t0>> 1)&0x7F].YU +
  995. // GYUV[(t0>> 9)&0x7F].YU +
  996. // RYUV[(t0>>17)&0x7F].YU )
  997. // *YPlane = ((t>>8)+8)
  998. // assign(eax: B2,Y1,Y2,U)
  999. // assign(ebx: B1,V)
  1000. // assign(ecx: G2,G1)
  1001. // assign(edx: R2,R1)
  1002. // assign(ebp: B1)
  1003. // 1
  1004. mov eax, [esi]
  1005. mov ecx, [esi + 4]
  1006. // 2
  1007. mov ebx, eax
  1008. mov edx, ecx
  1009. // 3
  1010. shr eax, 25
  1011. and ecx, 0xFE
  1012. // 4
  1013. shr ecx, 1
  1014. and edx, 0xFE00
  1015. // 5
  1016. shr edx, 9
  1017. and ebx, 0xFEFEFE
  1018. // 6
  1019. mov eax, [BYUV+eax*8].YU
  1020. nop
  1021. // 7
  1022. add eax, [GYUV+ecx*8].YU
  1023. mov ecx, ebx
  1024. // 8
  1025. add eax, [RYUV+edx*8].YU
  1026. mov edx, ebx
  1027. // 9
  1028. and ebx, 0xFE
  1029. add eax, 0x800
  1030. // 10
  1031. sar eax, 8
  1032. nop
  1033. // 11
  1034. shr ebx, 1
  1035. nop
  1036. // 12
  1037. shr ecx, 9
  1038. mov [edi + 1], al
  1039. // 13
  1040. shr edx, 17
  1041. and ecx, 0x7F
  1042. // 14
  1043. mov eax, [BYUV+ebx*8].YU
  1044. and edx, 0x7F
  1045. // 15
  1046. add eax, [GYUV+ecx*8].YU
  1047. mov ebp, ebx
  1048. // 16
  1049. add eax, [RYUV+edx*8].YU
  1050. nop
  1051. // 17
  1052. sar eax, 8
  1053. mov ebx, [esp + LOOP_K]
  1054. // 18
  1055. add eax, 8
  1056. and ebx, 1
  1057. // 19
  1058. mov [edi], al
  1059. jnz L9
  1060. // At this point, ebp: B1, ecx: G1, edx: R1
  1061. // t0 = pnext[0]
  1062. // *UPlane++ = ((t>>24)+64)
  1063. // t = ( RYUV[(t0>>17)&0x7F].V +
  1064. // GYUV[(t0>> 9)&0x7F].V +
  1065. // BYUV[(t0>> 1)&0x7F].V )
  1066. // *VPlane++ = ((t>>8)+64)
  1067. // 20
  1068. mov ebx, [RYUV+edx*8].V
  1069. mov edx, [esp + UPLANE]
  1070. // 21
  1071. sar eax, 16
  1072. add ebx, [GYUV+ecx*8].V
  1073. // 22
  1074. add eax, 64
  1075. add ebx, [BYUV+ebp*8].V
  1076. // 23
  1077. mov [edx], al
  1078. inc edx
  1079. // 24
  1080. mov [esp + UPLANE], edx
  1081. mov edx, [esp + VPLANE]
  1082. // 25
  1083. sar ebx, 8
  1084. inc edx
  1085. // 26
  1086. add ebx, 64
  1087. mov [esp + VPLANE], edx
  1088. // 27
  1089. mov [edx - 1], bl
  1090. nop
  1091. L9:
  1092. // ---------------------
  1093. // | B2 | R1 | G1 | B1 | pnext[0]
  1094. // ---------------------
  1095. // | G3 | B3 | R2 | G2 | pnext[1]
  1096. // ---------------------
  1097. // | R4 | G4 | B4 | R3 | pnext[2]
  1098. // ---------------------
  1099. // t1 = pnext[1]
  1100. // t2 = pnext[2]
  1101. // t = ( BYUV[(t2>> 9)&0x7F].YU +
  1102. // GYUV[(t2>>17)&0x7F].YU +
  1103. // RYUV[t2>>25].YR )
  1104. // *(YPlane+3) = ((t>>8)+8)
  1105. // t = ( BYUV[(t1>>17)&0x7F].YU +
  1106. // GYUV[t1>>25].YU +
  1107. // RYUV[(t2>> 1)&0x7F].YU )
  1108. // *(YPlane+2) = ((t>>8)+8)
  1109. // YPlane += 4
  1110. // assign(eax: B4,Y3,Y4,U)
  1111. // assign(ebx: R3,V)
  1112. // assign(ecx: G4,G3)
  1113. // assign(edx: R4/B3)
  1114. // assign(ebp: R3)
  1115. // 28
  1116. mov ebp, [esi + 4]
  1117. mov ebx, [esi + 8]
  1118. // 29
  1119. mov eax, ebx
  1120. mov ecx, ebx
  1121. // 30
  1122. shr eax, 9
  1123. mov edx, ebx
  1124. // 31
  1125. shr ecx, 17
  1126. and eax, 0x7F
  1127. // 32
  1128. shr edx, 25
  1129. and ecx, 0x7F
  1130. // 33
  1131. mov eax, [BYUV+eax*8].YU
  1132. nop
  1133. // 34
  1134. add eax, [GYUV+ecx*8].YU
  1135. and ebx, 0xFE
  1136. // 35
  1137. add eax, [RYUV+edx*8].YU
  1138. mov ecx, ebp
  1139. // 36
  1140. shr ebx, 1
  1141. add eax, 0x800
  1142. // 37
  1143. sar eax, 8
  1144. mov edx, ebp
  1145. // 38
  1146. shr edx, 17
  1147. mov [edi + 3], al
  1148. // 39
  1149. shr ecx, 25
  1150. and edx, 0x7F
  1151. // 40
  1152. mov eax, [RYUV+ebx*8].YU
  1153. mov ebp, ebx
  1154. // 41
  1155. add eax, [GYUV+ecx*8].YU
  1156. nop
  1157. // 42
  1158. add eax, [BYUV+edx*8].YU
  1159. nop
  1160. // 43
  1161. sar eax, 8
  1162. mov ebx, [esp + LOOP_K]
  1163. // 44
  1164. add eax, 8
  1165. and ebx, 1
  1166. // 45
  1167. mov [edi + 2], al
  1168. jnz L16
  1169. // At this point, ebp: R3, ecx: G3, edx: B3
  1170. // t1 = pnext[1]
  1171. // t2 = pnext[2]
  1172. // *UPlane++ = ((t>>16)+64)
  1173. // t = ( RYUV[(t2>> 1)&0x7F].V +
  1174. // GYUV[t1>>25].V +
  1175. // BYUV[(t1>>17)&0x7F].V )
  1176. // *VPlane++ = ((t>>8)+64)
  1177. // 46
  1178. mov ebx, [BYUV+edx*8].V
  1179. mov edx, [esp + UPLANE]
  1180. // 47
  1181. sar eax, 16
  1182. add ebx, [GYUV+ecx*8].V
  1183. // 48
  1184. add eax, 64
  1185. add ebx, [RYUV+ebp*8].V
  1186. // 49
  1187. mov [edx], al
  1188. inc edx
  1189. // 50
  1190. mov [esp + UPLANE], edx
  1191. mov edx, [esp + VPLANE]
  1192. // 51
  1193. sar ebx, 8
  1194. inc edx
  1195. // 52
  1196. add ebx, 64
  1197. mov [esp + VPLANE], edx
  1198. // 53
  1199. mov [edx - 1], bl
  1200. nop
  1201. L16:
  1202. // 54
  1203. mov eax, [esp + LOOP_I]
  1204. lea esi, [esi + 12]
  1205. // 55
  1206. sub eax, 4
  1207. lea edi, [edi + 4]
  1208. // 56
  1209. mov [esp + LOOP_I], eax
  1210. jnz L6
  1211. // if (stretch && (0 == k) && j)
  1212. mov eax, [esp + STRETCH]
  1213. test eax, eax
  1214. jz L21
  1215. mov eax, [esp + LOOP_K]
  1216. test eax, eax
  1217. jnz L21
  1218. mov eax, [esp + LOOP_J]
  1219. test eax, eax
  1220. jz L21
  1221. // spill YPlane ptr
  1222. mov [esp + YPLANE], edi
  1223. nop
  1224. // for (i = FrameWidth; i > 0; i -= 8)
  1225. // assign (ebx, pyprev)
  1226. // assign (ecx, t)
  1227. // assign (edx, pynext)
  1228. // assign (edi, pyspace)
  1229. // assign (ebp, i)
  1230. // make sure offsets are such that there are no bank conflicts here
  1231. mov ebx, [esp + PYPREV]
  1232. mov edi, [esp + PYSPACE]
  1233. mov edx, [esp + PYNEXT]
  1234. mov ebp, [esp + FRAME_WIDTH]
  1235. // t = (*pyprev++ & 0xFEFEFEFE) >> 1
  1236. // t += (*pynext++ & 0xFEFEFEFE) >> 1
  1237. // *pyspace++ = t
  1238. // t = (*pyprev++ & 0xFEFEFEFE) >> 1
  1239. // t += (*pynext++ & 0xFEFEFEFE) >> 1
  1240. // *pyspace++ = t
  1241. L22:
  1242. // 1
  1243. mov eax, [ebx]
  1244. lea ebx, [ebx + 4]
  1245. // 2
  1246. mov ecx, [edx]
  1247. lea edx, [edx + 4]
  1248. // 3
  1249. shr ecx, 1
  1250. and eax, 0xFEFEFEFE
  1251. // 4
  1252. shr eax, 1
  1253. and ecx, 0x7F7F7F7F
  1254. // 5
  1255. add eax, ecx
  1256. mov ecx, [ebx]
  1257. // 6
  1258. shr ecx, 1
  1259. mov [edi], eax
  1260. // 7
  1261. mov eax, [edx]
  1262. and ecx, 0x7F7F7F7F
  1263. // 8
  1264. shr eax, 1
  1265. lea edi, [edi + 4]
  1266. // 9
  1267. and eax, 0x7F7F7F7F
  1268. lea ebx, [ebx + 4]
  1269. // 10
  1270. lea edx, [edx + 4]
  1271. add eax, ecx
  1272. // 11
  1273. mov [edi], eax
  1274. lea edi, [edi + 4]
  1275. // 12
  1276. sub ebp, 8
  1277. jnz L22
  1278. // kill (ebx, pyprev)
  1279. // kill (ecx, t)
  1280. // kill (edx, pynext)
  1281. // kill (edi, pyspace)
  1282. // kill (ebp, i)
  1283. // restore YPlane
  1284. mov edi, [esp + YPLANE]
  1285. // pnext += iBackTwoLines
  1286. L21:
  1287. add esi, [esp + BACK_TWO_LINES]
  1288. // YPlane += ypitch_adj;
  1289. add edi, [esp + YPITCH_ADJ]
  1290. // if(0 == (k&1))
  1291. mov eax, [esp + LOOP_K]
  1292. and eax, 1
  1293. jnz L23
  1294. // UPlane += uvpitch_adj;
  1295. // VPlane += uvpitch_adj;
  1296. mov eax, [esp + UVPITCH_ADJ]
  1297. add [esp + UPLANE], eax
  1298. add [esp + VPLANE], eax
  1299. L23:
  1300. inc DWORD PTR [esp + LOOP_K]
  1301. mov eax, [esp + LOOP_K]
  1302. cmp eax, [esp + MARK]
  1303. jl L5
  1304. // if (stretch)
  1305. cmp DWORD PTR [esp + STRETCH], 0
  1306. je L24
  1307. // pyprev = YPlane - pitch
  1308. mov eax, edi
  1309. sub eax, [esp + PITCH_PARM]
  1310. mov [esp + PYPREV], eax
  1311. // pyspace = YPlane
  1312. mov [esp + PYSPACE], edi
  1313. // pynext = (YPlane += pitch)
  1314. add edi, [esp + PITCH_PARM]
  1315. mov [esp + PYNEXT], edi
  1316. L24:
  1317. inc DWORD PTR [esp + LOOP_J]
  1318. mov eax, [esp + LOOP_J]
  1319. cmp eax, [esp + LUMA_ITERS]
  1320. jl L4
  1321. // kill (esi, pnext)
  1322. // kill (edi, YPlane)
  1323. // if (stretch)
  1324. mov esi, [esp + PYPREV]
  1325. cmp DWORD PTR [esp + STRETCH], 0
  1326. je L26
  1327. // for (i = FrameWidth; i > 0; i -= 4)
  1328. // assign (esi, pyprev)
  1329. // assign (edi, pyspace)
  1330. // assign (ebp, i)
  1331. mov ebp, [esp + FRAME_WIDTH]
  1332. mov edi, [esp + PYSPACE]
  1333. L25:
  1334. mov ecx, [esi]
  1335. lea esi, [esi + 4]
  1336. mov [edi], ecx
  1337. lea edi, [edi + 4]
  1338. sub ebp, 4
  1339. jnz L25
  1340. // kill (esi, pyprev)
  1341. // kill (edi, pyspace)
  1342. // kill (ebp, i)
  1343. L26:
  1344. add esp, LOCALSIZE
  1345. pop edi
  1346. pop esi
  1347. pop ebx
  1348. pop ebp
  1349. ret
  1350. }
  1351. }
  1352. #undef LOCALSIZE
  1353. #undef PITCH_PARM
  1354. #undef FRAME_HEIGHT
  1355. #undef FRAME_WIDTH
  1356. #undef VPLANE
  1357. #undef UPLANE
  1358. #undef YPLANE
  1359. #undef LP_INPUT
  1360. #undef LPBI_INPUT
  1361. #undef PYPREV
  1362. #undef PYSPACE
  1363. #undef PYNEXT
  1364. #undef LOOP_I
  1365. #undef LOOP_J
  1366. #undef LOOP_K
  1367. #undef BACK_TWO_LINES
  1368. #undef STRETCH
  1369. #undef MARK
  1370. #undef LUMA_ITERS
  1371. #undef YPITCH_ADJ
  1372. #undef UVPITCH_ADJ
  1373. #if defined(_CODEC_STATS)
  1374. #define NOC_SHIFT_WIDTH 7
  1375. void NOC_H26X_BGR16toYUV12(
  1376. LPBITMAPINFOHEADER lpbiInput,
  1377. U8 * lpInput,
  1378. U8 * YPlane,
  1379. U8 * UPlane,
  1380. U8 * VPlane,
  1381. UN FrameWidth,
  1382. UN FrameHeight,
  1383. const int pitch)
  1384. {
  1385. U32 *pnext, *pyprev, *pyspace, *pynext;
  1386. U32 tm;
  1387. int t;
  1388. int i, j, k;
  1389. int iBackTwoLines;
  1390. int stretch, mark, aspect;
  1391. int width_adj, height_adj;
  1392. int LumaIters = 0;
  1393. int ypitch_adj = 0;
  1394. int uvpitch_adj = 0;
  1395. // This loop is here simply to avoid a divide. LumaIters = (FrameHeight/12).
  1396. for (i = FrameHeight; i > 0; i -= 48) {
  1397. LumaIters += 4;
  1398. }
  1399. width_adj = lpbiInput->biWidth - FrameWidth;
  1400. aspect = (width_adj ? LumaIters : 0);
  1401. height_adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1;
  1402. stretch = (height_adj ? 1 : 0);
  1403. mark = 12 - stretch;
  1404. // The input image is upside down - process the lines in reverse order.
  1405. // Move from end of line N to beginning of line N-1
  1406. iBackTwoLines = -((lpbiInput->biWidth + (int)FrameWidth) >> 1);
  1407. // Point to the beginning of the last line.
  1408. pnext = (U32 *)(lpInput +
  1409. ((lpbiInput->biWidth << 1) * ((FrameHeight - aspect - 1) + height_adj)) +
  1410. width_adj);
  1411. for ( j = 0; j < LumaIters; j++) {
  1412. for (k = 0; k < mark; k++) {
  1413. for (i = FrameWidth; i > 0; i -= 2, pnext++) {
  1414. tm = *pnext;
  1415. // 555 2, 3, 8 0x7C, 0x7C, 0x7C
  1416. t = (BYUV[(tm>>14)&0x7C].YU +
  1417. GYUV[(tm>>19)&0x7C].YU +
  1418. RYUV[(tm>>24)&0x7C].YU);
  1419. *(YPlane+1) = (U8)((t>>NOC_SHIFT_WIDTH)+16);
  1420. t = (BYUV[(tm<<2)&0x7C].YU +
  1421. GYUV[(tm>>3)&0x7C].YU +
  1422. RYUV[(tm>>8)&0x7C].YU);
  1423. *(YPlane) = (U8)((t>>NOC_SHIFT_WIDTH)+16);
  1424. YPlane += 2;
  1425. if (0 == (k&1)) {
  1426. // 555 2, 3, 8 0x7C, 0x7C, 0x7C
  1427. *UPlane++ = (U8)((t>>23)+128);
  1428. t = (RYUV[(tm>>8)&0x7C].V +
  1429. GYUV[(tm>>3)&0x7C].V +
  1430. BYUV[(tm<<2)&0x7C].V);
  1431. *VPlane++ = (U8)((t>>NOC_SHIFT_WIDTH)+128);
  1432. }
  1433. }
  1434. if (stretch && (0 == k) && j) {
  1435. for (i = FrameWidth; i > 0; i -= 8) {
  1436. tm = ((*pyprev++ & 0xFEFEFEFE) >> 1);
  1437. tm += ((*pynext++ & 0xFEFEFEFE) >> 1);
  1438. *pyspace++ = tm;
  1439. tm = ((*pyprev++ & 0xFEFEFEFE) >> 1);
  1440. tm += ((*pynext++ & 0xFEFEFEFE) >> 1);
  1441. *pyspace++ = tm;
  1442. }
  1443. }
  1444. pnext += iBackTwoLines;
  1445. YPlane += ypitch_adj;
  1446. // Increment after even lines.
  1447. if(0 == (k&1)) {
  1448. UPlane += uvpitch_adj;
  1449. VPlane += uvpitch_adj;
  1450. }
  1451. } // end of for k
  1452. if (stretch) {
  1453. pyprev = (U32 *)(YPlane - pitch);
  1454. pyspace = (U32 *)YPlane;
  1455. pynext = (U32 *)(YPlane += pitch);
  1456. }
  1457. } // end of for j
  1458. if (stretch) {
  1459. for (i = FrameWidth; i > 0; i -= 4) {
  1460. *pyspace++ = *pyprev++;
  1461. }
  1462. }
  1463. } // end of NOC_H26X_BGR16toYUV12
  1464. #endif
  1465. #if 0
  1466. _STATIC void C_H26X_BGR16toYUV12(
  1467. LPBITMAPINFOHEADER lpbiInput,
  1468. U8 * lpInput,
  1469. U8 * YPlane,
  1470. U8 * UPlane,
  1471. U8 * VPlane,
  1472. UN FrameWidth,
  1473. UN FrameHeight,
  1474. UN bitfield,
  1475. const int pitch)
  1476. {
  1477. U32 *pnext, *pyprev, *pyspace, *pynext;
  1478. U32 tm;
  1479. int t;
  1480. int i, j, k;
  1481. int iBackTwoLines;
  1482. int stretch, mark, aspect;
  1483. int width_adj, height_adj;
  1484. int LumaIters = 0;
  1485. int ypitch_adj = pitch - FrameWidth;
  1486. int uvpitch_adj = pitch - (FrameWidth >> 1);
  1487. // This loop is here simply to avoid a divide. LumaIters = (FrameHeight/12).
  1488. for (i = FrameHeight; i > 0; i -= 48) {
  1489. LumaIters += 4;
  1490. }
  1491. width_adj = lpbiInput->biWidth - FrameWidth;
  1492. aspect = (width_adj ? LumaIters : 0);
  1493. height_adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1;
  1494. stretch = (height_adj ? 1 : 0);
  1495. mark = 12 - stretch;
  1496. // The input image is upside down - process the lines in reverse order.
  1497. // Move from end of line N to beginning of line N-1
  1498. iBackTwoLines = -((lpbiInput->biWidth + (int)FrameWidth) >> 1);
  1499. // Point to the beginning of the last line.
  1500. pnext = (U32 *)(lpInput +
  1501. ((lpbiInput->biWidth << 1) * ((FrameHeight - aspect - 1) + height_adj)) +
  1502. width_adj);
  1503. for ( j = 0; j < LumaIters; j++) {
  1504. for (k = 0; k < mark; k++) {
  1505. for (i = FrameWidth; i > 0; i -= 2, pnext++) {
  1506. tm = *pnext;
  1507. switch (bitfield) {
  1508. // 555 2, 3, 8 0x7C, 0x7C, 0x7C
  1509. case 555:
  1510. t = (BYUV[(tm>>14)&0x7C].YU +
  1511. GYUV[(tm>>19)&0x7C].YU +
  1512. RYUV[(tm>>24)&0x7C].YU);
  1513. *(YPlane+1) = (U8)((t>>SHIFT_WIDTH)+8);
  1514. t = (BYUV[(tm<<2)&0x7C].YU +
  1515. GYUV[(tm>>3)&0x7C].YU +
  1516. RYUV[(tm>>8)&0x7C].YU);
  1517. *(YPlane) = (U8)((t>>SHIFT_WIDTH)+8);
  1518. YPlane += 2;
  1519. break;
  1520. #if 0
  1521. // Beware - untested code ahead
  1522. // 664 3, 3, 9 0x78, 0x7E, 0x7E
  1523. case 664:
  1524. t = (BYUV[(tm>>13)&0x78].YU +
  1525. GYUV[(tm>>19)&0x7E].YU +
  1526. RYUV[(tm>>25)&0x7E].YU);
  1527. *(YPlane+1) = (U8)((t>>SHIFT_WIDTH)+8);
  1528. t = (BYUV[(tm<<3)&0x78].YU +
  1529. GYUV[(tm>>3)&0x7E].YU +
  1530. RYUV[(tm>>9)&0x7E].YU);
  1531. *(YPlane) = (U8)((t>>SHIFT_WIDTH)+8);
  1532. YPlane += 2;
  1533. break;
  1534. // 565 2, 4, 9 0x7C, 0x7E, 0x7C
  1535. case 565:
  1536. t = (BYUV[(tm>>14)&0x7C].YU +
  1537. GYUV[(tm>>20)&0x7E].YU +
  1538. RYUV[(tm>>25)&0x7C].YU);
  1539. *(YPlane+1) = (U8)((t>>SHIFT_WIDTH)+8);
  1540. t = (BYUV[(tm<<2)&0x7C].YU +
  1541. GYUV[(tm>>4)&0x7E].YU +
  1542. RYUV[(tm>>9)&0x7C].YU);
  1543. *(YPlane) = (U8)((t>>SHIFT_WIDTH)+8);
  1544. YPlane += 2;
  1545. break;
  1546. // 655 2, 3, 9 0x7C, 0x7C, 0x7E
  1547. case 655:
  1548. t = (BYUV[(tm>>14)&0x7C].YU +
  1549. GYUV[(tm>>19)&0x7C].YU +
  1550. RYUV[(tm>>25)&0x7E].YU);
  1551. *(YPlane+1) = (U8)((t>>SHIFT_WIDTH)+8);
  1552. t = (BYUV[(tm<<2)&0x7C].YU +
  1553. GYUV[(tm>>3)&0x7C].YU +
  1554. RYUV[(tm>>9)&0x7E].YU);
  1555. *(YPlane) = (U8)((t>>SHIFT_WIDTH)+8);
  1556. YPlane += 2;
  1557. break;
  1558. #endif
  1559. }
  1560. if (0 == (k&1)) {
  1561. switch (bitfield) {
  1562. // 555 2, 3, 8 0x7C, 0x7C, 0x7C
  1563. case 555:
  1564. *UPlane++ = (U8)((t>>24)+64);
  1565. t = (RYUV[(tm>>8)&0x7C].V +
  1566. GYUV[(tm>>3)&0x7C].V +
  1567. BYUV[(tm<<2)&0x7C].V);
  1568. *VPlane++ = (U8)((t>>SHIFT_WIDTH)+64);
  1569. break;
  1570. #if 0
  1571. // Beware - untested code ahead
  1572. // 664 3, 3, 9 0x78, 0x7E, 0x7E
  1573. case 664:
  1574. *UPlane++ = (U8)((t>>24)+64);
  1575. t = (RYUV[(tm>>9)&0x7E].V +
  1576. GYUV[(tm>>3)&0x7E].V +
  1577. BYUV[(tm<<3)&0x78].V);
  1578. *VPlane++ = (U8)((t>>SHIFT_WIDTH)+64);
  1579. break;
  1580. // 565 2, 4, 9 0x7C, 0x7E, 0x7C
  1581. case 565:
  1582. *UPlane++ = (U8)((t>>24)+64);
  1583. t = (RYUV[(tm>>9)&0x7C].V +
  1584. GYUV[(tm>>4)&0x7E].V +
  1585. BYUV[(tm<<2)&0x7C].V);
  1586. *VPlane++ = (U8)((t>>SHIFT_WIDTH)+64);
  1587. break;
  1588. // 655 2, 3, 9 0x7C, 0x7C, 0x7E
  1589. case 655:
  1590. *UPlane++ = (U8)((t>>24)+64);
  1591. t = (RYUV[(tm>>9)&0x7E].V +
  1592. GYUV[(tm>>3)&0x7C].V +
  1593. BYUV[(tm<<2)&0x7C].V);
  1594. *VPlane++ = (U8)((t>>SHIFT_WIDTH)+64);
  1595. break;
  1596. #endif
  1597. }
  1598. }
  1599. }
  1600. if (stretch && (0 == k) && j) {
  1601. for (i = FrameWidth; i > 0; i -= 8) {
  1602. tm = ((*pyprev++ & 0xFEFEFEFE) >> 1);
  1603. tm += ((*pynext++ & 0xFEFEFEFE) >> 1);
  1604. *pyspace++ = tm;
  1605. tm = ((*pyprev++ & 0xFEFEFEFE) >> 1);
  1606. tm += ((*pynext++ & 0xFEFEFEFE) >> 1);
  1607. *pyspace++ = tm;
  1608. }
  1609. }
  1610. pnext += iBackTwoLines;
  1611. YPlane += ypitch_adj;
  1612. // Increment after even lines.
  1613. if(0 == (k&1)) {
  1614. UPlane += uvpitch_adj;
  1615. VPlane += uvpitch_adj;
  1616. }
  1617. } // end of for k
  1618. if (stretch) {
  1619. pyprev = (U32 *)(YPlane - pitch);
  1620. pyspace = (U32 *)YPlane;
  1621. pynext = (U32 *)(YPlane += pitch);
  1622. }
  1623. } // end of for j
  1624. if (stretch) {
  1625. for (i = FrameWidth; i > 0; i -= 4) {
  1626. *pyspace++ = *pyprev++;
  1627. }
  1628. }
  1629. } // end of C_H26X_BGR16toYUV12
  1630. #endif
  1631. __declspec(naked)
  1632. _STATIC void IA_H26X_BGR16555toYUV12(
  1633. LPBITMAPINFOHEADER lpbiInput,
  1634. U8 * lpInput,
  1635. U8 * YPlane,
  1636. U8 * UPlane,
  1637. U8 * VPlane,
  1638. UN FrameWidth,
  1639. UN FrameHeight,
  1640. const int pitch)
  1641. {
  1642. // Permanent (callee-save) registers - ebx, esi, edi, ebp
  1643. // Temporary (caller-save) registers - eax, ecx, edx
  1644. //
  1645. // Stack frame layout
  1646. // | pitch | + 96
  1647. // | FrameHeight | + 92
  1648. // | FrameWidth | + 88
  1649. // | VPlane | + 84
  1650. // | UPlane | + 80
  1651. // | YPlane | + 76
  1652. // | lpInput | + 72
  1653. // | lpbiInput | + 68
  1654. // ----------------------------
  1655. // | return addr | + 64
  1656. // | saved ebp | + 60
  1657. // | saved ebx | + 56
  1658. // | saved esi | + 52
  1659. // | saved edi | + 48
  1660. // | pyprev | + 44
  1661. // | pyspace | + 40
  1662. // | pynext | + 36
  1663. // | i | + 32
  1664. // | j | + 28
  1665. // | k | + 24
  1666. // | iBackTwoLines | + 20
  1667. // | stretch | + 16
  1668. // | mark | + 12
  1669. // | LumaIters | + 8
  1670. // | ypitch_adj | + 4
  1671. // | uvpitch_adj | + 0
  1672. #define LOCALSIZE 48
  1673. #define PITCH_PARM 96
  1674. #define FRAME_HEIGHT 92
  1675. #define FRAME_WIDTH 88
  1676. #define VPLANE 84
  1677. #define UPLANE 80
  1678. #define YPLANE 76
  1679. #define LP_INPUT 72
  1680. #define LPBI_INPUT 68
  1681. #define PYPREV 44
  1682. #define PYSPACE 40
  1683. #define PYNEXT 36
  1684. #define LOOP_I 32
  1685. #define LOOP_J 28
  1686. #define LOOP_K 24
  1687. #define BACK_TWO_LINES 20
  1688. #define STRETCH 16
  1689. #define MARK 12
  1690. #define LUMA_ITERS 8
  1691. #define YPITCH_ADJ 4
  1692. #define UVPITCH_ADJ 0
  1693. _asm {
  1694. push ebp
  1695. push ebx
  1696. push esi
  1697. push edi
  1698. sub esp, LOCALSIZE
  1699. // assign (ebx, lpbiInput)
  1700. mov ebx, [esp + LPBI_INPUT]
  1701. // ypitch_adj = pitch - FrameWidth
  1702. // assign (ecx, FrameWidth)
  1703. // assign (edx, pitch)
  1704. mov ecx, [esp + FRAME_WIDTH]
  1705. mov edx, [esp + PITCH_PARM]
  1706. mov eax, edx
  1707. sub eax, ecx
  1708. mov [esp + YPITCH_ADJ], eax
  1709. // uvpitch_adj = pitch - (FrameWidth >> 1)
  1710. // kill (edx, pitch)
  1711. mov ebp, ecx
  1712. shr ebp, 1
  1713. sub edx, ebp
  1714. mov [esp + UVPITCH_ADJ], edx
  1715. // for (i = FrameHeight; i > 0; i -= 48) LumaIters += 4
  1716. // assign (edx, LumaIters)
  1717. xor edx, edx
  1718. mov eax, [esp + FRAME_HEIGHT]
  1719. L1:
  1720. lea edx, [edx + 4]
  1721. sub eax, 48
  1722. jnz L1
  1723. // width_adj = lpbiInput->biWidth - FrameWidth
  1724. // assign (esi, width_adj)
  1725. mov esi, (LPBITMAPINFOHEADER)[ebx].biWidth
  1726. sub esi, [esp + FRAME_WIDTH]
  1727. // aspect = (width_adj ? LumaIters : 0)
  1728. // assign (edi, aspect)
  1729. // kill (edx, LumaIters)
  1730. mov [esp + LUMA_ITERS], edx
  1731. xor edi, edi
  1732. test esi, esi
  1733. jz L2
  1734. mov edi, edx
  1735. // height _adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1
  1736. // assign (edx, height_adj)
  1737. L2:
  1738. mov edx, (LPBITMAPINFOHEADER)[ebx].biHeight
  1739. sub edx, [esp + FRAME_HEIGHT]
  1740. add edx, edi
  1741. shr edx, 1
  1742. // stretch = (height_adj ? 1 : 0)
  1743. xor eax, eax
  1744. test edx, edx
  1745. jz L3
  1746. inc eax
  1747. L3:
  1748. mov [esp + STRETCH], eax
  1749. // mark = 12 - stretch
  1750. mov ebp, 12
  1751. sub ebp, eax
  1752. mov [esp + MARK], ebp
  1753. // iBackTwoLines = -((lpbiInput->biWidth + FrameWidth) << 1)
  1754. mov ebp, (LPBITMAPINFOHEADER)[ebx].biWidth
  1755. add ebp, [esp + FRAME_WIDTH]
  1756. shl ebp, 1
  1757. neg ebp
  1758. mov [esp + BACK_TWO_LINES], ebp
  1759. // pnext = lpInput +
  1760. // ((lpbiInput->biWidth << 1) *
  1761. // ((FrameHeight - aspect - 1) + height_adj)) +
  1762. // width_adj
  1763. // kill (ebx, lpbiInput)
  1764. // kill (ecx, FrameWidth)
  1765. // kill (edx, height_adj)
  1766. // kill (esi, width_adj)
  1767. // kill (edi, aspect)
  1768. // assign (esi, pnext)
  1769. mov eax, (LPBITMAPINFOHEADER)[ebx].biWidth
  1770. shl eax, 1
  1771. mov ebx, [esp + FRAME_HEIGHT]
  1772. sub ebx, edi
  1773. dec ebx
  1774. add ebx, edx
  1775. imul ebx
  1776. add esi, eax
  1777. add esi, [esp + LP_INPUT]
  1778. // assign (edi, YPlane)
  1779. mov edi, [esp + YPLANE]
  1780. // for (j = 0; j < LumaIters; j++)
  1781. xor eax, eax
  1782. mov [esp + LOOP_J], eax
  1783. // for (k = 0; k < mark; k++)
  1784. L4:
  1785. xor eax, eax
  1786. mov [esp + LOOP_K], eax
  1787. // for (i = FrameWidth; i > 0; i -= 2, pnext += 4)
  1788. L5:
  1789. mov eax, [esp + FRAME_WIDTH]
  1790. mov [esp + LOOP_I], eax
  1791. // This jump is here to make sure the following loop starts on the U pipe
  1792. jmp L6
  1793. L6:
  1794. // tm = pnext[0]
  1795. // t = ( BYUV[(tm>>14)&0x7C].YU +
  1796. // GYUV[(tm>>19)&0x7C].YU +
  1797. // RYUV[(tm>>24)&0x7C].YU )
  1798. // *(YPlane+1) = (U8)((t>>8)+8)
  1799. // t = ( BYUV[(tm<< 2)&0x7C].YU +
  1800. // GYUV[(tm>> 8)&0x7C].YU +
  1801. // RYUV[(tm>>13)&0x7C].YU )
  1802. // *YPlane = (U8)((t>>8)+8)
  1803. // YPlane += 2
  1804. // assign(eax: B2/Y1/Y2/U)
  1805. // assign(ebx: B1/V)
  1806. // assign(ecx: G2/G1)
  1807. // assign(edx: R2/R1)
  1808. // assign(ebp: B1)
  1809. // 1
  1810. mov eax, [esi]
  1811. nop
  1812. // 2
  1813. mov ebx, eax
  1814. mov ecx, eax
  1815. // 3
  1816. shr eax, 14
  1817. mov edx, ebx
  1818. // 4
  1819. shr ecx, 19
  1820. and eax, 0x7C
  1821. // 5
  1822. shr edx, 24
  1823. and ecx, 0x7C
  1824. // 6
  1825. mov eax, [BYUV+eax*8].YU
  1826. and edx, 0x7C
  1827. // 7
  1828. add eax, [GYUV+ecx*8].YU
  1829. mov ecx, ebx
  1830. // 8
  1831. add eax, [RYUV+edx*8].YU
  1832. mov edx, ebx
  1833. // 9
  1834. sar eax, 8
  1835. and ebx, 0x1F
  1836. // 10
  1837. shl ebx, 2
  1838. add eax, 8
  1839. // 11
  1840. shr ecx, 3
  1841. mov [edi + 1], al
  1842. // 12
  1843. shr edx, 8
  1844. and ecx, 0x7C
  1845. // 13
  1846. mov eax, [BYUV+ebx*8].YU
  1847. and edx, 0x7C
  1848. // 14
  1849. add eax, [GYUV+ecx*8].YU
  1850. mov ebp, ebx
  1851. // 15
  1852. add eax, [RYUV+edx*8].YU
  1853. nop
  1854. // 16
  1855. sar eax, 8
  1856. mov ebx, [esp + LOOP_K]
  1857. // 17
  1858. add eax, 8
  1859. and ebx, 1
  1860. // 18
  1861. mov [edi], al
  1862. jnz L9
  1863. // At this point, ebp: B1, ecx: G1, edx: R1
  1864. // *UPlane++ = (U8)((t>>24)+64)
  1865. // t = ( VBGR[(t>>13)&0x7C].VR +
  1866. // VBGR[(t>> 8)&0x7C].VG +
  1867. // VBGR[(t<< 2)&0x7C].VB )
  1868. // *VPlane++ = (U8)((t>>8)+64)
  1869. // 19
  1870. mov ebx, [RYUV+edx*8].V
  1871. mov edx, [esp + UPLANE]
  1872. // 20
  1873. sar eax, 16
  1874. add ebx, [GYUV+ecx*8].V
  1875. // 21
  1876. add eax, 64
  1877. add ebx, [BYUV+ebp*8].V
  1878. // 22
  1879. mov [edx], al
  1880. inc edx
  1881. // 23
  1882. mov [esp + UPLANE], edx
  1883. mov edx, [esp + VPLANE]
  1884. // 24
  1885. sar ebx, 8
  1886. inc edx
  1887. // 25
  1888. add ebx, 64
  1889. mov [esp + VPLANE], edx
  1890. // 26
  1891. mov [edx - 1], bl
  1892. nop
  1893. L9:
  1894. // 27
  1895. mov eax, [esp + LOOP_I]
  1896. lea esi, [esi + 4]
  1897. // 28
  1898. sub eax, 2
  1899. lea edi, [edi + 2]
  1900. // 29
  1901. mov [esp + LOOP_I], eax
  1902. jnz L6
  1903. // if (stretch && (0 == k) && j)
  1904. mov eax, [esp + STRETCH]
  1905. test eax, eax
  1906. jz L14
  1907. mov eax, [esp + LOOP_K]
  1908. test eax, eax
  1909. jnz L14
  1910. mov eax, [esp + LOOP_J]
  1911. test eax, eax
  1912. jz L14
  1913. // spill YPlane ptr
  1914. mov [esp + YPLANE], edi
  1915. nop
  1916. // for (i = FrameWidth; i > 0; i -= 8)
  1917. // assign (ebx, pyprev)
  1918. // assign (ecx, t)
  1919. // assign (edx, pynext)
  1920. // assign (edi, pyspace)
  1921. // assign (ebp, i)
  1922. // make sure offsets are such that there are no bank conflicts here
  1923. mov ebx, [esp + PYPREV]
  1924. mov edi, [esp + PYSPACE]
  1925. mov edx, [esp + PYNEXT]
  1926. mov ebp, [esp + FRAME_WIDTH]
  1927. // t = (*pyprev++ & 0xFEFEFEFE) >> 1
  1928. // t += (*pynext++ & 0xFEFEFEFE) >> 1
  1929. // *pyspace++ = t
  1930. // t = (*pyprev++ & 0xFEFEFEFE) >> 1
  1931. // t += (*pynext++ & 0xFEFEFEFE) >> 1
  1932. // *pyspace++ = t
  1933. L15:
  1934. // 1
  1935. mov eax, [ebx]
  1936. lea ebx, [ebx + 4]
  1937. // 2
  1938. mov ecx, [edx]
  1939. lea edx, [edx + 4]
  1940. // 3
  1941. shr ecx, 1
  1942. and eax, 0xFEFEFEFE
  1943. // 4
  1944. shr eax, 1
  1945. and ecx, 0x7F7F7F7F
  1946. // 5
  1947. add eax, ecx
  1948. mov ecx, [ebx]
  1949. // 6
  1950. shr ecx, 1
  1951. mov [edi], eax
  1952. // 7
  1953. mov eax, [edx]
  1954. and ecx, 0x7F7F7F7F
  1955. // 8
  1956. shr eax, 1
  1957. lea edi, [edi + 4]
  1958. // 9
  1959. and eax, 0x7F7F7F7F
  1960. lea ebx, [ebx + 4]
  1961. // 10
  1962. lea edx, [edx + 4]
  1963. add eax, ecx
  1964. // 11
  1965. mov [edi], eax
  1966. lea edi, [edi + 4]
  1967. // 12
  1968. sub ebp, 8
  1969. jnz L15
  1970. // kill (ebx, pyprev)
  1971. // kill (ecx, t)
  1972. // kill (edx, pynext)
  1973. // kill (edi, pyspace)
  1974. // kill (ebp, i)
  1975. // restore YPlane
  1976. mov edi, [esp + YPLANE]
  1977. // pnext += iBackTwoLines
  1978. L14:
  1979. add esi, [esp + BACK_TWO_LINES]
  1980. // YPlane += ypitch_adj;
  1981. add edi, [esp + YPITCH_ADJ]
  1982. // if(0 == (k&1))
  1983. mov eax, [esp + LOOP_K]
  1984. and eax, 1
  1985. jnz L16
  1986. // UPlane += uvpitch_adj;
  1987. // VPlane += uvpitch_adj;
  1988. mov eax, [esp + UVPITCH_ADJ]
  1989. add [esp + UPLANE], eax
  1990. add [esp + VPLANE], eax
  1991. L16:
  1992. inc DWORD PTR [esp + LOOP_K]
  1993. mov eax, [esp + LOOP_K]
  1994. cmp eax, [esp + MARK]
  1995. jl L5
  1996. // if (stretch)
  1997. cmp DWORD PTR [esp + STRETCH], 0
  1998. je L17
  1999. // pyprev = YPlane - pitch
  2000. mov eax, edi
  2001. sub eax, [esp + PITCH_PARM]
  2002. mov [esp + PYPREV], eax
  2003. // pyspace = YPlane
  2004. mov [esp + PYSPACE], edi
  2005. // pynext = (YPlane += pitch)
  2006. add edi, [esp + PITCH_PARM]
  2007. mov [esp + PYNEXT], edi
  2008. L17:
  2009. inc DWORD PTR [esp + LOOP_J]
  2010. mov eax, [esp + LOOP_J]
  2011. cmp eax, [esp + LUMA_ITERS]
  2012. jl L4
  2013. // kill (esi, pnext)
  2014. // kill (edi, YPlane)
  2015. // if (stretch)
  2016. mov esi, [esp + PYPREV]
  2017. cmp DWORD PTR [esp + STRETCH], 0
  2018. je L19
  2019. // for (i = FrameWidth; i > 0; i -= 4)
  2020. // assign (esi, pyprev)
  2021. // assign (edi, pyspace)
  2022. // assign (ebp, i)
  2023. mov ebp, [esp + FRAME_WIDTH]
  2024. mov edi, [esp + PYSPACE]
  2025. L18:
  2026. mov ecx, [esi]
  2027. lea esi, [esi + 4]
  2028. mov [edi], ecx
  2029. lea edi, [edi + 4]
  2030. sub ebp, 4
  2031. jnz L18
  2032. // kill (esi, pyprev)
  2033. // kill (edi, pyspace)
  2034. // kill (ebp, i)
  2035. L19:
  2036. add esp, LOCALSIZE
  2037. pop edi
  2038. pop esi
  2039. pop ebx
  2040. pop ebp
  2041. ret
  2042. }
  2043. }
  2044. #undef LOCALSIZE
  2045. #undef PITCH_PARM
  2046. #undef FRAME_HEIGHT
  2047. #undef FRAME_WIDTH
  2048. #undef VPLANE
  2049. #undef UPLANE
  2050. #undef YPLANE
  2051. #undef LP_INPUT
  2052. #undef LPBI_INPUT
  2053. #undef PYPREV
  2054. #undef PYSPACE
  2055. #undef PYNEXT
  2056. #undef LOOP_I
  2057. #undef LOOP_J
  2058. #undef LOOP_K
  2059. #undef BACK_TWO_LINES
  2060. #undef STRETCH
  2061. #undef MARK
  2062. #undef LUMA_ITERS
  2063. #undef YPITCH_ADJ
  2064. #undef UVPITCH_ADJ
  2065. /*****************************************************************************
  2066. *
  2067. * H26X_CLUTtoYUV12()
  2068. *
  2069. * Convert from CLUT8/CLUT4 to YUV12 (YCrCb 4:2:0) and copy to destination memory
  2070. * with pitch defined by the constant PITCH.
  2071. *
  2072. * This is needed to support the quickcam.
  2073. */
  2074. #if 0
  2075. _STATIC void C_H26X_CLUTtoYUV12(
  2076. LPBITMAPINFOHEADER lpbiInput,
  2077. U8 * lpInput,
  2078. U8 * YPlane,
  2079. U8 * UPlane,
  2080. U8 * VPlane,
  2081. UN FrameWidth,
  2082. UN FrameHeight,
  2083. UN pixel_bits,
  2084. const int pitch)
  2085. {
  2086. U32 *pnext, *pyprev, *pyspace, *pynext;
  2087. U32 tm, tn;
  2088. int t;
  2089. int i, j, k, m, n;
  2090. int iNextLine, iBackTwoLines;
  2091. int stretch, mark, aspect;
  2092. int width_adj, height_adj;
  2093. int yshift, uvshift;
  2094. int pixel_mask, loop_cnt, loop_limit;
  2095. RGBQUAD *lpCEntry, *lpCTable = (RGBQUAD *)((U8 *)lpbiInput + sizeof(BITMAPINFOHEADER));
  2096. int LumaIters = 0;
  2097. int ypitch_adj = (pitch - FrameWidth);
  2098. int uvpitch_adj = (pitch - (FrameWidth >> 1));
  2099. ASSERT((8 == pixel_bits) || (4 == pixel_bits));
  2100. // This loop is here simply to avoid a divide. LumaIters = (FrameHeight/12).
  2101. for (i = FrameHeight; i > 0; i -= 48) {
  2102. LumaIters += 4;
  2103. }
  2104. width_adj = ((lpbiInput->biWidth - FrameWidth) >> 1);
  2105. aspect = (width_adj ? LumaIters : 0);
  2106. height_adj = ((lpbiInput->biHeight - (FrameHeight - aspect)) >> 1);
  2107. stretch = (height_adj ? 1 : 0);
  2108. mark = 12 - stretch;
  2109. iNextLine = lpbiInput->biWidth;
  2110. iBackTwoLines = -((iNextLine + (int)FrameWidth) >> 2);
  2111. if (8 == pixel_bits) {
  2112. yshift = 8;
  2113. uvshift = 16;
  2114. pixel_mask = 0xFF;
  2115. loop_cnt = 2;
  2116. loop_limit = 4;
  2117. } else {
  2118. yshift = 4;
  2119. uvshift = 8;
  2120. pixel_mask = 0xF;
  2121. loop_cnt = 1;
  2122. loop_limit = 8;
  2123. width_adj >>= 1;
  2124. iNextLine >>= 1;
  2125. iBackTwoLines >>= 1;
  2126. }
  2127. // The input image is upside down - process the lines in reverse order.
  2128. // Point to the beginning of the last line.
  2129. pnext = (U32 *)(lpInput +
  2130. (iNextLine * ((FrameHeight - aspect - 1) + height_adj)) + width_adj);
  2131. for (j = 0; j < LumaIters; j++) {
  2132. for (k = 0; k < mark; k++) {
  2133. for (i = FrameWidth; i > 0; i -= 8) {
  2134. for (n = 0; n < loop_cnt; n++) {
  2135. tm = *pnext++;
  2136. tm = ((4 == pixel_bits) ?
  2137. ( ((tm >> 4) & 0x0F0F0F0F) | ((tm << 4) & 0xF0F0F0F0) ) : tm);
  2138. tn = tm;
  2139. for (m = 0; m < loop_limit; m += 4) {
  2140. lpCEntry = &lpCTable[tm&pixel_mask];
  2141. t = ( BYUV[lpCEntry->rgbBlue>>1].YU +
  2142. GYUV[lpCEntry->rgbGreen>>1].YU +
  2143. RYUV[lpCEntry->rgbRed>>1].YU );
  2144. *YPlane++ = (U8)((t>>8)+8);
  2145. tm >>= yshift;
  2146. lpCEntry = &lpCTable[tm&pixel_mask];
  2147. t = ( BYUV[lpCEntry->rgbBlue>>1].YU +
  2148. GYUV[lpCEntry->rgbGreen>>1].YU +
  2149. RYUV[lpCEntry->rgbRed>>1].YU );
  2150. *YPlane++ = (U8)((t>>8)+8);
  2151. tm >>= yshift;
  2152. lpCEntry = &lpCTable[tm&pixel_mask];
  2153. t = ( BYUV[lpCEntry->rgbBlue>>1].YU +
  2154. GYUV[lpCEntry->rgbGreen>>1].YU +
  2155. RYUV[lpCEntry->rgbRed>>1].YU );
  2156. *YPlane++ = (U8)((t>>8)+8);
  2157. tm >>= yshift;
  2158. lpCEntry = &lpCTable[tm&pixel_mask];
  2159. t = ( BYUV[lpCEntry->rgbBlue>>1].YU +
  2160. GYUV[lpCEntry->rgbGreen>>1].YU +
  2161. RYUV[lpCEntry->rgbRed>>1].YU );
  2162. *YPlane++ = (U8)((t>>8)+8);
  2163. tm >>= yshift;
  2164. }
  2165. if (0 == (k&1)) {
  2166. for (m = 0; m < loop_limit; m += 2, tn >>= uvshift) {
  2167. lpCEntry = &lpCTable[tn&pixel_mask];
  2168. t = ( BYUV[lpCEntry->rgbBlue>>1].YU +
  2169. RYUV[lpCEntry->rgbRed>>1].YU +
  2170. GYUV[lpCEntry->rgbGreen>>1].YU );
  2171. *UPlane++ = (U8)((t>>24)+64);
  2172. t = ( RYUV[lpCEntry->rgbRed>>1].V +
  2173. GYUV[lpCEntry->rgbGreen>>1].V +
  2174. BYUV[lpCEntry->rgbBlue>>1].V );
  2175. *VPlane++ = (U8)((t>>8)+64);
  2176. }
  2177. }
  2178. }
  2179. }
  2180. if (stretch && (0 == k) && j) {
  2181. for (i = FrameWidth; i > 0; i -= 8) {
  2182. tm = ((*pyprev++ & 0xFEFEFEFE) >> 1);
  2183. tm += ((*pynext++ & 0xFEFEFEFE) >> 1);
  2184. *pyspace++ = tm;
  2185. tm = ((*pyprev++ & 0xFEFEFEFE) >> 1);
  2186. tm += ((*pynext++ & 0xFEFEFEFE) >> 1);
  2187. *pyspace++ = tm;
  2188. }
  2189. }
  2190. pnext += iBackTwoLines;
  2191. YPlane += ypitch_adj;
  2192. // Increment after even lines.
  2193. if(0 == (k&1)) {
  2194. UPlane += uvpitch_adj;
  2195. VPlane += uvpitch_adj;
  2196. }
  2197. }
  2198. if (stretch) {
  2199. pyprev = (U32 *)(YPlane - pitch);
  2200. pyspace = (U32 *)YPlane;
  2201. pynext = (U32 *)(YPlane += pitch);
  2202. }
  2203. }
  2204. if (stretch) {
  2205. for (i = FrameWidth; i > 0; i -= 4) {
  2206. *pyspace++ = *pyprev++;
  2207. }
  2208. }
  2209. } // end of H26X_CLUTtoYUV12()
  2210. #endif
  2211. __declspec(naked)
  2212. _STATIC void IA_H26X_CLUT8toYUV12(
  2213. LPBITMAPINFOHEADER lpbiInput,
  2214. U8 * lpInput,
  2215. U8 * YPlane,
  2216. U8 * UPlane,
  2217. U8 * VPlane,
  2218. UN FrameWidth,
  2219. UN FrameHeight,
  2220. const int pitch)
  2221. {
  2222. // Permanent (callee-save) registers - ebx, esi, edi, ebp
  2223. // Temporary (caller-save) registers - eax, ecx, edx
  2224. //
  2225. // Stack frame layout
  2226. // | pitch | +100
  2227. // | FrameHeight | + 96
  2228. // | FrameWidth | + 92
  2229. // | VPlane | + 88
  2230. // | UPlane | + 84
  2231. // | YPlane | + 80
  2232. // | lpInput | + 76
  2233. // | lpbiInput | + 72
  2234. // ----------------------------
  2235. // | return addr | + 68
  2236. // | saved ebp | + 64
  2237. // | saved ebx | + 60
  2238. // | saved esi | + 56
  2239. // | saved edi | + 52
  2240. // | pyprev | + 48
  2241. // | pyspace | + 44
  2242. // | pynext | + 40
  2243. // | i | + 36
  2244. // | j | + 32
  2245. // | k | + 28
  2246. // | iBackTwoLines | + 24
  2247. // | stretch | + 20
  2248. // | mark | + 16
  2249. // | lpCEntry | + 12
  2250. // | lpCTable | + 8
  2251. // | ypitch_adj | + 4
  2252. // | uvpitch_adj | + 0
  2253. #define LOCALSIZE 52
  2254. #define PITCH_PARM 100
  2255. #define FRAME_HEIGHT 96
  2256. #define FRAME_WIDTH 92
  2257. #define VPLANE 88
  2258. #define UPLANE 84
  2259. #define YPLANE 80
  2260. #define LP_INPUT 76
  2261. #define LPBI_INPUT 72
  2262. #define PYPREV 48
  2263. #define PYSPACE 44
  2264. #define PYNEXT 40
  2265. #define LOOP_I 36
  2266. #define LOOP_J 32
  2267. #define LOOP_K 28
  2268. #define BACK_TWO_LINES 24
  2269. #define STRETCH 20
  2270. #define MARK 16
  2271. #define LUMA_ITERS 12
  2272. #define LPCTABLE 8
  2273. #define YPITCH_ADJ 4
  2274. #define UVPITCH_ADJ 0
  2275. _asm {
  2276. push ebp
  2277. push ebx
  2278. push esi
  2279. push edi
  2280. sub esp, LOCALSIZE
  2281. // lpCTable = lpbiInput + sizeof(BITMAPINFOHEADER)
  2282. // assign (ebx, lpbiInput)
  2283. mov eax, [esp + LPBI_INPUT]
  2284. mov ebx, eax
  2285. add eax, TYPE BITMAPINFOHEADER
  2286. mov [esp + LPCTABLE], eax
  2287. // ypitch_adj = pitch - FrameWidth
  2288. // assign (ecx, FrameWidth)
  2289. // assign (edx, pitch)
  2290. mov ecx, [esp + FRAME_WIDTH]
  2291. mov edx, [esp + PITCH_PARM]
  2292. mov eax, edx
  2293. sub eax, ecx
  2294. mov [esp + YPITCH_ADJ], eax
  2295. // uvpitch_adj = pitch - (FrameWidth >> 1)
  2296. // kill (ecx, FrameWidth)
  2297. // kill (edx, pitch)
  2298. shr ecx, 1
  2299. sub edx, ecx
  2300. mov [esp + UVPITCH_ADJ], edx
  2301. // for (i = FrameHeight; i > 0; i -= 48) LumaIters += 4
  2302. // assign (ecx, LumaIters)
  2303. xor ecx, ecx
  2304. mov eax, [esp + FRAME_HEIGHT]
  2305. L1:
  2306. lea ecx, [ecx + 4]
  2307. sub eax, 48
  2308. jnz L1
  2309. // width_adj = ((lpbiInput->biWidth - FrameWidth) >> 1
  2310. // assign (edx, width_adj)
  2311. mov edx, (LPBITMAPINFOHEADER)[ebx].biWidth
  2312. sub edx, [esp + FRAME_WIDTH]
  2313. shr edx, 1
  2314. // aspect = (width_adj ? LumaIters : 0)
  2315. // assign (esi, aspect)
  2316. // kill (ecx, LumaIters)
  2317. mov [esp + LUMA_ITERS], ecx
  2318. xor esi, esi
  2319. test edx, edx
  2320. jz L2
  2321. mov esi, ecx
  2322. // height _adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1
  2323. // assign (ecx, height_adj)
  2324. L2:
  2325. mov ecx, (LPBITMAPINFOHEADER)[ebx].biHeight
  2326. sub ecx, [esp + FRAME_HEIGHT]
  2327. add ecx, esi
  2328. shr ecx, 1
  2329. // stretch = (height_adj ? 1 : 0)
  2330. xor eax, eax
  2331. test ecx, ecx
  2332. jz L3
  2333. inc eax
  2334. L3:
  2335. mov [esp + STRETCH], eax
  2336. // mark = 12 - stretch
  2337. mov edi, 12
  2338. sub edi, eax
  2339. mov [esp + MARK], edi
  2340. // iNextLine = lpbiInput->biWidth
  2341. // kill (ebx, lpbiInput)
  2342. // assign (ebx, iNextLine)
  2343. mov ebx, (LPBITMAPINFOHEADER)[ebx].biWidth
  2344. // iBackTwoLines = -(iNextline + FrameWidth)
  2345. mov edi, [esp + FRAME_WIDTH]
  2346. add edi, ebx
  2347. neg edi
  2348. mov [esp + BACK_TWO_LINES], edi
  2349. // pnext = lpInput +
  2350. // (iNextLine*((FrameHeight-aspect-1) + height_adj)) +
  2351. // width_adj
  2352. // kill (ebx, iNextLine)
  2353. // kill (ecx, height_adj)
  2354. // kill (edx, width_adj)
  2355. // kill (esi, aspect)
  2356. // assign (esi, pnext)
  2357. mov eax, [esp + FRAME_HEIGHT]
  2358. sub eax, esi
  2359. dec eax
  2360. add eax, ecx
  2361. mov esi, [esp + LP_INPUT]
  2362. add esi, edx
  2363. imul ebx
  2364. add esi, eax
  2365. // assign (edi, YPlane)
  2366. mov edi, [esp + YPLANE]
  2367. // for (j = 0; j < LumaIters; j++)
  2368. xor eax, eax
  2369. mov [esp + LOOP_J], eax
  2370. // for (k = 0; k < mark; k++)
  2371. L4:
  2372. xor eax, eax
  2373. mov [esp + LOOP_K], eax
  2374. // for (i = FrameWidth; i > 0; i -= 2, pnext += 2)
  2375. L5:
  2376. mov eax, [esp + FRAME_WIDTH]
  2377. mov [esp + LOOP_I], eax
  2378. // This jump is here to make sure the following loop starts on the U pipe
  2379. jmp L6
  2380. L6:
  2381. // lpCEntry = &lpCTable[*(pnext+1)]
  2382. // t = ( BYUV[lpCEntry->rgbBlue>>1].YU +
  2383. // GYUV[lpCEntry->rgbGreen>>1].YU +
  2384. // RYUV[lpCEntry->rgbRed>>1].YU )
  2385. // *(YPlane+1) = (U8)((t>>8)+8)
  2386. // lpCEntry = &lpCTable[*pnext]
  2387. // t = ( BYUV[lpCEntry->rgbBlue>>1].YU +
  2388. // GYUV[lpCEntry->rgbGreen>>1].YU +
  2389. // RYUV[lpCEntry->rgbRed>>1].YU )
  2390. // *YPlane = (U8)((t>>8)+8)
  2391. // YPlane += 2
  2392. // *UPlane++ = (U8)((t>>24)+64)
  2393. // t = ( VBGR[lpCEntry->rgbRed>>1].V +
  2394. // VBGR[lpCEntry->rgbGreen>>1].V +
  2395. // VBGR[lpCEntry->rgbBlue>>1].V )
  2396. // *VPlane++ = (U8)((t>>8)+64)
  2397. // assign (ebp: lpCEntry,B1)
  2398. // assign (eax: P2,B2,Y2,Y1,U)
  2399. // assign (ebx: B1,V)
  2400. // assign (ecx: G2,G1)
  2401. // assign (edx: R2,R1)
  2402. // 1
  2403. xor eax, eax
  2404. mov ebp, [esp + LPCTABLE]
  2405. // 2
  2406. mov al, [esi + 1]
  2407. xor ecx, ecx
  2408. // 3
  2409. lea ebx, [ebp+eax*4]
  2410. xor edx, edx
  2411. // 4
  2412. mov al, (LPRGBQUAD)[ebx].rgbBlue
  2413. nop
  2414. // 5
  2415. mov cl, (LPRGBQUAD)[ebx].rgbGreen
  2416. and al, 0xFE
  2417. // 6
  2418. mov dl, (LPRGBQUAD)[ebx].rgbRed
  2419. and cl, 0xFE
  2420. // 7
  2421. mov eax, [BYUV+eax*4].YU
  2422. and dl, 0xFE
  2423. // 8
  2424. add eax, [GYUV+ecx*4].YU
  2425. xor ebx, ebx
  2426. // 9
  2427. add eax, [RYUV+edx*4].YU
  2428. mov bl, [esi]
  2429. // 10
  2430. sar eax, 8
  2431. lea ebp, [ebp+ebx*4]
  2432. // 11
  2433. add eax, 8
  2434. nop
  2435. // 12
  2436. mov [edi + 1], al
  2437. mov bl, (LPRGBQUAD)[ebp].rgbBlue
  2438. // 13
  2439. mov cl, (LPRGBQUAD)[ebp].rgbGreen
  2440. and bl, 0xFE
  2441. // 14
  2442. mov dl, (LPRGBQUAD)[ebp].rgbRed
  2443. and cl, 0xFE
  2444. // 15
  2445. mov eax, [BYUV+ebx*4].YU
  2446. and dl, 0xFE
  2447. // 16
  2448. add eax, [GYUV+ecx*4].YU
  2449. mov ebp, ebx
  2450. // 17
  2451. add eax, [RYUV+edx*4].YU
  2452. nop
  2453. // 18
  2454. sar eax, 8
  2455. mov ebx, [esp + LOOP_K]
  2456. // 19
  2457. add eax, 8
  2458. and ebx, 1
  2459. // 20
  2460. mov [edi], al
  2461. jnz L9
  2462. // 21
  2463. mov ebx, [RYUV+edx*4].V
  2464. mov edx, [esp + UPLANE]
  2465. // 22
  2466. sar eax, 16
  2467. add ebx, [GYUV+ecx*4].V
  2468. // 23
  2469. add eax, 64
  2470. add ebx, [BYUV+ebp*4].V
  2471. // 24
  2472. mov [edx], al
  2473. inc edx
  2474. // 25
  2475. mov [esp + UPLANE], edx
  2476. mov edx, [esp + VPLANE]
  2477. // 26
  2478. sar ebx, 8
  2479. inc edx
  2480. // 27
  2481. add ebx, 64
  2482. mov [esp + VPLANE], edx
  2483. // 28
  2484. mov [edx - 1], bl
  2485. nop
  2486. L9:
  2487. // 29
  2488. mov eax, [esp + LOOP_I]
  2489. lea esi, [esi + 2]
  2490. // 30
  2491. sub eax, 2
  2492. lea edi, [edi + 2]
  2493. // 31
  2494. mov [esp + LOOP_I], eax
  2495. jnz L6
  2496. // only esi (pnext) is live at this point (after line loop)
  2497. // if (stretch && (0 == k) && j)
  2498. mov eax, [esp + STRETCH]
  2499. test eax, eax
  2500. jz L14
  2501. mov eax, [esp + LOOP_K]
  2502. test eax, eax
  2503. jnz L14
  2504. mov eax, [esp + LOOP_J]
  2505. test eax, eax
  2506. jz L14
  2507. // spill YPlane ptr
  2508. mov [esp + YPLANE], edi
  2509. nop
  2510. // for (i = FrameWidth; i > 0; i -= 8)
  2511. // assign (ebx, pyprev)
  2512. // assign (ecx, t)
  2513. // assign (edx, pynext)
  2514. // assign (edi, pyspace)
  2515. // assign (ebp, i)
  2516. // make sure offsets are such that there are no bank conflicts here
  2517. mov ebx, [esp + PYPREV]
  2518. mov edi, [esp + PYSPACE]
  2519. mov edx, [esp + PYNEXT]
  2520. mov ebp, [esp + FRAME_WIDTH]
  2521. // t = (*pyprev++ & 0xFEFEFEFE) >> 1
  2522. // t += (*pynext++ & 0xFEFEFEFE) >> 1
  2523. // *pyspace++ = t
  2524. // t = (*pyprev++ & 0xFEFEFEFE) >> 1
  2525. // t += (*pynext++ & 0xFEFEFEFE) >> 1
  2526. // *pyspace++ = t
  2527. L15:
  2528. // 1
  2529. mov eax, [ebx]
  2530. lea ebx, [ebx + 4]
  2531. // 2
  2532. mov ecx, [edx]
  2533. lea edx, [edx + 4]
  2534. // 3
  2535. shr ecx, 1
  2536. and eax, 0xFEFEFEFE
  2537. // 4
  2538. shr eax, 1
  2539. and ecx, 0x7F7F7F7F
  2540. // 5
  2541. add eax, ecx
  2542. mov ecx, [ebx]
  2543. // 6
  2544. shr ecx, 1
  2545. mov [edi], eax
  2546. // 7
  2547. mov eax, [edx]
  2548. and ecx, 0x7F7F7F7F
  2549. // 8
  2550. shr eax, 1
  2551. lea edi, [edi + 4]
  2552. // 9
  2553. and eax, 0x7F7F7F7F
  2554. lea ebx, [ebx + 4]
  2555. // 10
  2556. lea edx, [edx + 4]
  2557. add eax, ecx
  2558. // 11
  2559. mov [edi], eax
  2560. lea edi, [edi + 4]
  2561. // 12
  2562. sub ebp, 8
  2563. jnz L15
  2564. // kill (ebx, pyprev)
  2565. // kill (ecx, t)
  2566. // kill (edx, pynext)
  2567. // kill (edi, pyspace)
  2568. // kill (ebp, i)
  2569. // restore YPlane
  2570. mov edi, [esp + YPLANE]
  2571. // pnext += iBackTwoLines
  2572. L14:
  2573. add esi, [esp + BACK_TWO_LINES]
  2574. // YPlane += ypitch_adj;
  2575. add edi, [esp + YPITCH_ADJ]
  2576. // if(0 == (k&1))
  2577. mov eax, [esp + LOOP_K]
  2578. and eax, 1
  2579. jnz L16
  2580. // UPlane += uvpitch_adj;
  2581. // VPlane += uvpitch_adj;
  2582. mov eax, [esp + UVPITCH_ADJ]
  2583. add [esp + UPLANE], eax
  2584. add [esp + VPLANE], eax
  2585. L16:
  2586. inc DWORD PTR [esp + LOOP_K]
  2587. mov eax, [esp + LOOP_K]
  2588. cmp eax, [esp + MARK]
  2589. jl L5
  2590. // if (stretch)
  2591. cmp DWORD PTR [esp + STRETCH], 0
  2592. je L17
  2593. // pyprev = YPlane - pitch
  2594. mov eax, edi
  2595. sub eax, [esp + PITCH_PARM]
  2596. mov [esp + PYPREV], eax
  2597. // pyspace = YPlane
  2598. mov [esp + PYSPACE], edi
  2599. // pynext = (YPlane += pitch)
  2600. add edi, [esp + PITCH_PARM]
  2601. mov [esp + PYNEXT], edi
  2602. L17:
  2603. inc DWORD PTR [esp + LOOP_J]
  2604. mov eax, [esp + LOOP_J]
  2605. cmp eax, [esp + LUMA_ITERS]
  2606. jl L4
  2607. // kill (esi, pnext)
  2608. // kill (edi, YPlane)
  2609. // if (stretch)
  2610. mov esi, [esp + PYPREV]
  2611. cmp DWORD PTR [esp + STRETCH], 0
  2612. je L19
  2613. // for (i = FrameWidth; i > 0; i -= 4)
  2614. // assign (esi, pyprev)
  2615. // assign (edi, pyspace)
  2616. // assign (ebp, i)
  2617. mov ebp, [esp + FRAME_WIDTH]
  2618. mov edi, [esp + PYSPACE]
  2619. L18:
  2620. mov ecx, [esi]
  2621. lea esi, [esi + 4]
  2622. mov [edi], ecx
  2623. lea edi, [edi + 4]
  2624. sub ebp, 4
  2625. jnz L18
  2626. // kill (esi, pyprev)
  2627. // kill (edi, pyspace)
  2628. // kill (ebp, i)
  2629. L19:
  2630. add esp, LOCALSIZE
  2631. pop edi
  2632. pop esi
  2633. pop ebx
  2634. pop ebp
  2635. ret
  2636. }
  2637. }
  2638. #undef LOCALSIZE
  2639. #undef PITCH_PARM
  2640. #undef FRAME_HEIGHT
  2641. #undef FRAME_WIDTH
  2642. #undef VPLANE
  2643. #undef UPLANE
  2644. #undef YPLANE
  2645. #undef LP_INPUT
  2646. #undef LPBI_INPUT
  2647. #undef PYPREV
  2648. #undef PYSPACE
  2649. #undef PYNEXT
  2650. #undef LOOP_I
  2651. #undef LOOP_J
  2652. #undef LOOP_K
  2653. #undef BACK_TWO_LINES
  2654. #undef STRETCH
  2655. #undef MARK
  2656. #undef LUMA_ITERS
  2657. #undef LPCTABLE
  2658. #undef YPITCH_ADJ
  2659. #undef UVPITCH_ADJ
  2660. __declspec(naked)
  2661. _STATIC void IA_H26X_CLUT4toYUV12(
  2662. LPBITMAPINFOHEADER lpbiInput,
  2663. U8 * lpInput,
  2664. U8 * YPlane,
  2665. U8 * UPlane,
  2666. U8 * VPlane,
  2667. UN FrameWidth,
  2668. UN FrameHeight,
  2669. const int pitch)
  2670. {
  2671. // Permanent (callee-save) registers - ebx, esi, edi, ebp
  2672. // Temporary (caller-save) registers - eax, ecx, edx
  2673. //
  2674. // Stack frame layout
  2675. // | pitch | +100
  2676. // | FrameHeight | + 96
  2677. // | FrameWidth | + 92
  2678. // | VPlane | + 88
  2679. // | UPlane | + 84
  2680. // | YPlane | + 80
  2681. // | lpInput | + 76
  2682. // | lpbiInput | + 72
  2683. // ----------------------------
  2684. // | return addr | + 68
  2685. // | saved ebp | + 64
  2686. // | saved ebx | + 60
  2687. // | saved esi | + 56
  2688. // | saved edi | + 52
  2689. // | pyprev | + 48
  2690. // | pyspace | + 44
  2691. // | pynext | + 40
  2692. // | i | + 36
  2693. // | j | + 32
  2694. // | k | + 28
  2695. // | iBackTwoLines | + 24
  2696. // | stretch | + 20
  2697. // | mark | + 16
  2698. // | lpCEntry | + 12
  2699. // | lpCTable | + 8
  2700. // | ypitch_adj | + 4
  2701. // | uvpitch_adj | + 0
  2702. #define LOCALSIZE 52
  2703. #define PITCH_PARM 100
  2704. #define FRAME_HEIGHT 96
  2705. #define FRAME_WIDTH 92
  2706. #define VPLANE 88
  2707. #define UPLANE 84
  2708. #define YPLANE 80
  2709. #define LP_INPUT 76
  2710. #define LPBI_INPUT 72
  2711. #define PYPREV 48
  2712. #define PYSPACE 44
  2713. #define PYNEXT 40
  2714. #define LOOP_I 36
  2715. #define LOOP_J 32
  2716. #define LOOP_K 28
  2717. #define BACK_TWO_LINES 24
  2718. #define STRETCH 20
  2719. #define MARK 16
  2720. #define LUMA_ITERS 12
  2721. #define LPCTABLE 8
  2722. #define YPITCH_ADJ 4
  2723. #define UVPITCH_ADJ 0
  2724. _asm {
  2725. push ebp
  2726. push ebx
  2727. push esi
  2728. push edi
  2729. sub esp, LOCALSIZE
  2730. // lpCTable = lpbiInput + sizeof(BITMAPINFOHEADER)
  2731. // assign (ebx, lpbiInput)
  2732. mov eax, [esp + LPBI_INPUT]
  2733. mov ebx, eax
  2734. add eax, TYPE BITMAPINFOHEADER
  2735. mov [esp + LPCTABLE], eax
  2736. // ypitch_adj = pitch - FrameWidth
  2737. // assign (ecx, FrameWidth)
  2738. // assign (edx, pitch)
  2739. mov ecx, [esp + FRAME_WIDTH]
  2740. mov edx, [esp + PITCH_PARM]
  2741. mov eax, edx
  2742. sub eax, ecx
  2743. mov [esp + YPITCH_ADJ], eax
  2744. // uvpitch_adj = pitch - (FrameWidth >> 1)
  2745. // kill (ecx, FrameWidth)
  2746. // kill (edx, pitch)
  2747. shr ecx, 1
  2748. sub edx, ecx
  2749. mov [esp + UVPITCH_ADJ], edx
  2750. // for (i = FrameHeight; i > 0; i -= 48) LumaIters += 4
  2751. // assign (ecx, LumaIters)
  2752. xor ecx, ecx
  2753. mov eax, [esp + FRAME_HEIGHT]
  2754. L1:
  2755. lea ecx, [ecx + 4]
  2756. sub eax, 48
  2757. jnz L1
  2758. // width_adj = ((lpbiInput->biWidth - FrameWidth) >> 2
  2759. // assign (edx, width_adj)
  2760. mov edx, (LPBITMAPINFOHEADER)[ebx].biWidth
  2761. sub edx, [esp + FRAME_WIDTH]
  2762. shr edx, 2
  2763. // aspect = (width_adj ? LumaIters : 0)
  2764. // assign (esi, aspect)
  2765. // kill (ecx, LumaIters)
  2766. mov [esp + LUMA_ITERS], ecx
  2767. xor esi, esi
  2768. test edx, edx
  2769. jz L2
  2770. mov esi, ecx
  2771. // height _adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1
  2772. // assign (ecx, height_adj)
  2773. L2:
  2774. mov ecx, (LPBITMAPINFOHEADER)[ebx].biHeight
  2775. sub ecx, [esp + FRAME_HEIGHT]
  2776. add ecx, esi
  2777. shr ecx, 1
  2778. // stretch = (height_adj ? 1 : 0)
  2779. xor eax, eax
  2780. test ecx, ecx
  2781. jz L3
  2782. inc eax
  2783. L3:
  2784. mov [esp + STRETCH], eax
  2785. // mark = 12 - stretch
  2786. mov edi, 12
  2787. sub edi, eax
  2788. mov [esp + MARK], edi
  2789. // iNextLine = lpbiInput->biWidth >> 1
  2790. // kill (ebx, lpbiInput)
  2791. // assign (ebx, iNextLine)
  2792. mov ebx, (LPBITMAPINFOHEADER)[ebx].biWidth
  2793. shr ebx, 1
  2794. // iBackTwoLines = -(iNextline + (FrameWidth >> 1))
  2795. mov edi, [esp + FRAME_WIDTH]
  2796. shr edi, 1
  2797. add edi, ebx
  2798. neg edi
  2799. mov [esp + BACK_TWO_LINES], edi
  2800. // pnext = lpInput+(iNextLine*((FrameHeight-aspect-1)+height_adj))+ width_adj
  2801. // kill (ebx, iNextLine)
  2802. // kill (ecx, height_adj)
  2803. // kill (edx, width_adj)
  2804. // kill (esi, aspect)
  2805. // assign (esi, pnext)
  2806. mov eax, [esp + FRAME_HEIGHT]
  2807. sub eax, esi
  2808. dec eax
  2809. add eax, ecx
  2810. mov esi, [esp + LP_INPUT]
  2811. add esi, edx
  2812. imul ebx
  2813. add esi, eax
  2814. // assign (edi, YPlane)
  2815. mov edi, [esp + YPLANE]
  2816. // for (j = 0; j < LumaIters; j++)
  2817. xor eax, eax
  2818. mov [esp + LOOP_J], eax
  2819. // for (k = 0; k < mark; k++)
  2820. L4:
  2821. xor eax, eax
  2822. mov [esp + LOOP_K], eax
  2823. // for (i = FrameWidth; i > 0; i -= 2, pnext++)
  2824. L5:
  2825. mov eax, [esp + FRAME_WIDTH]
  2826. mov [esp + LOOP_I], eax
  2827. // This jump is here to make sure the following loop starts on the U pipe
  2828. jmp L6
  2829. L6:
  2830. // lpCEntry = &lpCTable[*pnext&0xF]
  2831. // t = ( BYUV[lpCEntry->rgbBlue>>1].YU +
  2832. // GYUV[lpCEntry->rgbGreen>>1].YU +
  2833. // RYUV[lpCEntry->rgbRed>>1].YU )
  2834. // *(YPlane+1) = (U8)((t>>8)+8)
  2835. // lpCEntry = &lpCTable[(*pnext>>4)&0xF]
  2836. // t = ( BYUV[lpCEntry->rgbBlue>>1].YU +
  2837. // GYUV[lpCEntry->rgbGreen>>1].YU +
  2838. // RYUV[lpCEntry->rgbRed>>1].YU )
  2839. // *YPlane = (U8)((t>>8)+8)
  2840. // YPlane += 2
  2841. // *UPlane++ = (U8)((t>24)+64)
  2842. // t = ( RYUV[lpCEntry->rgbRed>>1].V +
  2843. // GYUV[lpCEntry->rgbGreen>>1].V +
  2844. // BYUV[lpCEntry->rgbBlue>>1].V )
  2845. // *VPlane++ = (U8)((t>>8)+64)
  2846. // assign (ebp: lpCEntry,B1)
  2847. // assign (eax: P2,B2,Y2,Y1,U)
  2848. // assign (ebx: B1,V)
  2849. // assign (ecx: G2,G1)
  2850. // assign (edx: R2,R1)
  2851. // 1
  2852. mov al, [esi]
  2853. mov ebp, [esp + LPCTABLE]
  2854. // 2
  2855. and eax, 0xF
  2856. xor ecx, ecx
  2857. // 3
  2858. lea ebx, [ebp+eax*4]
  2859. xor edx, edx
  2860. // 4
  2861. mov al, (LPRGBQUAD)[ebx].rgbBlue
  2862. nop
  2863. // 5
  2864. mov cl, (LPRGBQUAD)[ebx].rgbGreen
  2865. and al, 0xFE
  2866. // 6
  2867. mov dl, (LPRGBQUAD)[ebx].rgbRed
  2868. and cl, 0xFE
  2869. // 7
  2870. mov eax, [BYUV+eax*4].YU
  2871. and dl, 0xFE
  2872. // 8
  2873. add eax, [GYUV+ecx*4].YU
  2874. mov bl, [esi]
  2875. // 9
  2876. add eax, [RYUV+edx*4].YU
  2877. and ebx, 0xF0
  2878. //
  2879. shr ebx, 4
  2880. nop
  2881. // 10
  2882. shr eax, 8
  2883. lea ebp, [ebp+ebx*4]
  2884. // 11
  2885. add eax, 8
  2886. nop
  2887. // 12
  2888. mov [edi + 1], al
  2889. mov bl, (LPRGBQUAD)[ebp].rgbBlue
  2890. // 13
  2891. mov cl, (LPRGBQUAD)[ebp].rgbGreen
  2892. and bl, 0xFE
  2893. // 14
  2894. mov dl, (LPRGBQUAD)[ebp].rgbRed
  2895. and cl, 0xFE
  2896. // 15
  2897. mov eax, [BYUV+ebx*4].YU
  2898. and dl, 0xFE
  2899. // 16
  2900. add eax, [GYUV+ecx*4].YU
  2901. mov ebp, ebx
  2902. // 17
  2903. add eax, [RYUV+edx*4].YU
  2904. nop
  2905. // 18
  2906. shr eax, 8
  2907. mov ebx, [esp + LOOP_K]
  2908. // 19
  2909. add eax, 8
  2910. and ebx, 1
  2911. // 20
  2912. mov [edi], al
  2913. jnz L9
  2914. // 21
  2915. mov ebx, [RYUV+edx*4].V
  2916. mov edx, [esp + UPLANE]
  2917. // 22
  2918. sar eax, 16
  2919. add ebx, [GYUV+ecx*4].V
  2920. // 23
  2921. add eax, 64
  2922. add ebx, [BYUV+ebp*4].V
  2923. // 24
  2924. mov [edx], al
  2925. inc edx
  2926. // 25
  2927. mov [esp + UPLANE], edx
  2928. mov edx, [esp + VPLANE]
  2929. // 26
  2930. sar ebx, 8
  2931. inc edx
  2932. // 27
  2933. add ebx, 64
  2934. mov [esp + VPLANE], edx
  2935. // 28
  2936. mov [edx - 1], bl
  2937. nop
  2938. L9:
  2939. // 32
  2940. mov eax, [esp + LOOP_I]
  2941. lea esi, [esi + 1]
  2942. // 33
  2943. sub eax, 2
  2944. lea edi, [edi + 2]
  2945. // 34
  2946. mov [esp + LOOP_I], eax
  2947. jnz L6
  2948. // only esi (pnext) is live at this point (after line loop)
  2949. // if (stretch && (0 == k) && j)
  2950. mov eax, [esp + STRETCH]
  2951. test eax, eax
  2952. jz L14
  2953. mov eax, [esp + LOOP_K]
  2954. test eax, eax
  2955. jnz L14
  2956. mov eax, [esp + LOOP_J]
  2957. test eax, eax
  2958. jz L14
  2959. // spill YPlane ptr
  2960. mov [esp + YPLANE], edi
  2961. nop
  2962. // for (i = FrameWidth; i > 0; i -= 8)
  2963. // assign (ebx, pyprev)
  2964. // assign (ecx, t)
  2965. // assign (edx, pynext)
  2966. // assign (edi, pyspace)
  2967. // assign (ebp, i)
  2968. // make sure offsets are such that there are no bank conflicts here
  2969. mov ebx, [esp + PYPREV]
  2970. mov edi, [esp + PYSPACE]
  2971. mov edx, [esp + PYNEXT]
  2972. mov ebp, [esp + FRAME_WIDTH]
  2973. // t = (*pyprev++ & 0xFEFEFEFE) >> 1
  2974. // t += (*pynext++ & 0xFEFEFEFE) >> 1
  2975. // *pyspace++ = t
  2976. // t = (*pyprev++ & 0xFEFEFEFE) >> 1
  2977. // t += (*pynext++ & 0xFEFEFEFE) >> 1
  2978. // *pyspace++ = t
  2979. L15:
  2980. // 1
  2981. mov eax, [ebx]
  2982. lea ebx, [ebx + 4]
  2983. // 2
  2984. mov ecx, [edx]
  2985. lea edx, [edx + 4]
  2986. // 3
  2987. shr ecx, 1
  2988. and eax, 0xFEFEFEFE
  2989. // 4
  2990. shr eax, 1
  2991. and ecx, 0x7F7F7F7F
  2992. // 5
  2993. add eax, ecx
  2994. mov ecx, [ebx]
  2995. // 6
  2996. shr ecx, 1
  2997. mov [edi], eax
  2998. // 7
  2999. mov eax, [edx]
  3000. and ecx, 0x7F7F7F7F
  3001. // 8
  3002. shr eax, 1
  3003. lea edi, [edi + 4]
  3004. // 9
  3005. and eax, 0x7F7F7F7F
  3006. lea ebx, [ebx + 4]
  3007. // 10
  3008. lea edx, [edx + 4]
  3009. add eax, ecx
  3010. // 11
  3011. mov [edi], eax
  3012. lea edi, [edi + 4]
  3013. // 12
  3014. sub ebp, 8
  3015. jnz L15
  3016. // kill (ebx, pyprev)
  3017. // kill (ecx, t)
  3018. // kill (edx, pynext)
  3019. // kill (edi, pyspace)
  3020. // kill (ebp, i)
  3021. // restore YPlane
  3022. mov edi, [esp + YPLANE]
  3023. // pnext += iBackTwoLines
  3024. L14:
  3025. add esi, [esp + BACK_TWO_LINES]
  3026. // YPlane += ypitch_adj;
  3027. add edi, [esp + YPITCH_ADJ]
  3028. // if(0 == (k&1))
  3029. mov eax, [esp + LOOP_K]
  3030. and eax, 1
  3031. jnz L16
  3032. // UPlane += uvpitch_adj;
  3033. // VPlane += uvpitch_adj;
  3034. mov eax, [esp + UVPITCH_ADJ]
  3035. add [esp + UPLANE], eax
  3036. add [esp + VPLANE], eax
  3037. L16:
  3038. inc DWORD PTR [esp + LOOP_K]
  3039. mov eax, [esp + LOOP_K]
  3040. cmp eax, [esp + MARK]
  3041. jl L5
  3042. // if (stretch)
  3043. cmp DWORD PTR [esp + STRETCH], 0
  3044. je L17
  3045. // pyprev = YPlane - pitch
  3046. mov eax, edi
  3047. sub eax, [esp + PITCH_PARM]
  3048. mov [esp + PYPREV], eax
  3049. // pyspace = YPlane
  3050. mov [esp + PYSPACE], edi
  3051. // pynext = (YPlane += pitch)
  3052. add edi, [esp + PITCH_PARM]
  3053. mov [esp + PYNEXT], edi
  3054. L17:
  3055. inc DWORD PTR [esp + LOOP_J]
  3056. mov eax, [esp + LOOP_J]
  3057. cmp eax, [esp + LUMA_ITERS]
  3058. jl L4
  3059. // kill(esi, pnext)
  3060. // if (stretch)
  3061. mov esi, [esp + PYPREV]
  3062. cmp DWORD PTR [esp + STRETCH], 0
  3063. je L19
  3064. // for (i = FrameWidth; i > 0; i -= 4)
  3065. // assign (esi, pyprev)
  3066. // assign (edi, pyspace)
  3067. // assign (ebp, i)
  3068. mov edi, [esp + PYSPACE]
  3069. mov ebp, [esp + FRAME_WIDTH]
  3070. L18:
  3071. mov ecx, [esi]
  3072. lea esi, [esi + 4]
  3073. mov [edi], ecx
  3074. lea edi, [edi + 4]
  3075. sub ebp, 4
  3076. jnz L18
  3077. // kill (esi, pyprev)
  3078. // kill (edi, pyspace)
  3079. // kill (ebp, i)
  3080. L19:
  3081. add esp, LOCALSIZE
  3082. pop edi
  3083. pop esi
  3084. pop ebx
  3085. pop ebp
  3086. ret
  3087. }
  3088. }
  3089. #undef LOCALSIZE
  3090. #undef PITCH_PARM
  3091. #undef FRAME_HEIGHT
  3092. #undef FRAME_WIDTH
  3093. #undef VPLANE
  3094. #undef UPLANE
  3095. #undef YPLANE
  3096. #undef LP_INPUT
  3097. #undef LPBI_INPUT
  3098. #undef PYPREV
  3099. #undef PYSPACE
  3100. #undef PYNEXT
  3101. #undef LOOP_I
  3102. #undef LOOP_J
  3103. #undef LOOP_K
  3104. #undef BACK_TWO_LINES
  3105. #undef STRETCH
  3106. #undef MARK
  3107. #undef LUMA_ITERS
  3108. #undef LPCTABLE
  3109. #undef YPITCH_ADJ
  3110. #undef UVPITCH_ADJ
  3111. /***************************************************
  3112. * H26X_YVU9toYUV12()
  3113. * Convert from YVU9 to YUV12
  3114. * and copy to destination memory with pitch
  3115. * defined by the constant PITCH.
  3116. *
  3117. * uv_plane_common()
  3118. * Helper function to convert V and U plane information.
  3119. * Since the process is similar for both planes, the
  3120. * conversion code was included in this subroutine.
  3121. *
  3122. ***************************************************/
  3123. #if 0
  3124. #define READ_DWORD_AND_SHIFT(val,src) \
  3125. (((val) = *((unsigned int *)(src))), ((val) &= 0xFEFEFEFE), ((val) >>= 1))
  3126. #define READ_QWORD_AND_SHIFT(val,src) \
  3127. (((val) = *((unsigned __int64 *)(src))), ((val) &= 0xFEFEFEFEFEFEFEFE), ((val) >>= 1))
  3128. #define WRITE_DWORD(dest,val) ((*(unsigned int *)(dest)) = (val))
  3129. #define WRITE_QWORD(dest,val) ((*(unsigned __int64 *)(dest)) = (val))
  3130. #define AVERAGE_DWORDS(out,in1,in2) ((out) = ((((in1) + (in2)) & 0xFEFEFEFE) >> 1))
  3131. #define DUP_LOWER_TWO_BYTES(dest,val) \
  3132. (*((unsigned int *)(dest)) = (((val) & 0x000000FF) | (((val) << 8) & 0x0000FF00) | \
  3133. (((val) << 8) & 0x00FF0000) | (((val) << 16) & 0xFF000000)))
  3134. #define DUP_UPPER_TWO_BYTES(dest,val) \
  3135. (*((unsigned int *)(dest)) = ((((val) >> 16) & 0x000000FF) | (((val) >> 8) & 0x0000FF00) | \
  3136. (((val) >> 8) & 0x00FF0000) | ((val) & 0xFF000000)))
  3137. _STATIC void C_uv_plane_common(
  3138. U8 *psrc,
  3139. U8 *Plane,
  3140. UN pitch,
  3141. UN OutputFrameWidth,
  3142. UN ChromaIters,
  3143. UN spitch_adj) {
  3144. U8* pnext = psrc + (OutputFrameWidth>>1) + spitch_adj;
  3145. U8* pdest_copy = Plane;
  3146. U8* pdest_avg = Plane + pitch;
  3147. int dpitch_adj = pitch - OutputFrameWidth;
  3148. int stretch = (spitch_adj ? 1 : 0);
  3149. int mark = 6 - stretch;
  3150. int flag = stretch;
  3151. int i, j, k;
  3152. UN t1,t2;
  3153. for (j = ChromaIters; j > 0; j--) {
  3154. for (k = mark + (flag & 1); k > 0; k--) {
  3155. if (!stretch && (1 == j) && (1 == k)) {
  3156. pnext = psrc;
  3157. }
  3158. for (i = OutputFrameWidth; i > 0; i -= 8, psrc += 4,
  3159. pnext += 4,
  3160. pdest_copy += 8,
  3161. pdest_avg += 8) {
  3162. READ_DWORD_AND_SHIFT(t1,psrc);
  3163. DUP_LOWER_TWO_BYTES(pdest_copy,t1);
  3164. DUP_UPPER_TWO_BYTES((pdest_copy+4),t1);
  3165. READ_DWORD_AND_SHIFT(t2,pnext);
  3166. AVERAGE_DWORDS(t1,t1,t2);
  3167. DUP_LOWER_TWO_BYTES(pdest_avg,t1);
  3168. DUP_UPPER_TWO_BYTES((pdest_avg+4),t1);
  3169. }
  3170. psrc += spitch_adj;
  3171. pnext += spitch_adj;
  3172. pdest_copy = pdest_avg + dpitch_adj;
  3173. pdest_avg = pdest_copy + pitch;
  3174. }
  3175. if (stretch) {
  3176. psrc -= ((OutputFrameWidth>>1) + spitch_adj);
  3177. pnext -= ((OutputFrameWidth>>1) + spitch_adj);
  3178. pdest_avg = pdest_copy;
  3179. for (i = OutputFrameWidth; i > 0; i -= 8, psrc += 4,
  3180. pnext += 4,
  3181. pdest_avg += 8) {
  3182. READ_DWORD_AND_SHIFT(t1,psrc);
  3183. READ_DWORD_AND_SHIFT(t2,pnext);
  3184. AVERAGE_DWORDS(t1,t1,t2);
  3185. AVERAGE_DWORDS(t1,t1,t2);
  3186. DUP_LOWER_TWO_BYTES(pdest_avg,t1);
  3187. DUP_UPPER_TWO_BYTES((pdest_avg+4),t1);
  3188. }
  3189. psrc += spitch_adj;
  3190. pnext += spitch_adj;
  3191. pdest_copy = pdest_avg + dpitch_adj;
  3192. pdest_avg = pdest_copy + pitch;
  3193. flag++;
  3194. }
  3195. }
  3196. }
  3197. _STATIC void C_H26X_YVU9toYUV12(
  3198. LPBITMAPINFOHEADER lpbiInput,
  3199. U8 *lpInput,
  3200. U8 *YPlane,
  3201. U8 *UPlane,
  3202. U8 *VPlane,
  3203. UN FrameWidth,
  3204. UN FrameHeight,
  3205. const int pitch) {
  3206. U8 *pnext, *plast, *pbn;
  3207. U8 *pvsrc, *pusrc;
  3208. int width_adj, height_adj;
  3209. int stretch, mark, aspect;
  3210. int iNextLine;
  3211. int i, j, k, t;
  3212. int LumaIters = 0;
  3213. int ypitch_adj = pitch - FrameWidth;
  3214. int uvpitch_adj = pitch - (FrameWidth >> 1);
  3215. for (i = FrameHeight; i > 0; i -= 48) {
  3216. LumaIters += 4;
  3217. }
  3218. width_adj = (lpbiInput->biWidth - FrameWidth) >> 1;
  3219. aspect = (width_adj ? LumaIters : 0);
  3220. height_adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1;
  3221. stretch = (height_adj ? 1 : 0);
  3222. mark = 12 - stretch;
  3223. iNextLine = width_adj << 1;
  3224. pnext = lpInput + (lpbiInput->biWidth * height_adj) + width_adj;
  3225. for (j = LumaIters; j > 0; j--) {
  3226. for (k = mark; k > 0; k--) {
  3227. for (i = FrameWidth; i > 0; i -= 4, YPlane += 4, pnext += 4) {
  3228. *(U32 *)YPlane = (*(U32 *)pnext & 0xFEFEFEFE) >> 1;
  3229. }
  3230. pnext += iNextLine;
  3231. YPlane += ypitch_adj;
  3232. }
  3233. if (stretch) {
  3234. plast = pnext - lpbiInput->biWidth;
  3235. pbn = pnext;
  3236. for (i = FrameWidth; i > 0; i -= 4, YPlane += 4, plast += 4, pbn += 4) {
  3237. *(U32 *)YPlane =
  3238. ( ( ((*(U32 *)plast & 0xFEFEFEFE) >> 1) +
  3239. ((*(U32 *)pbn & 0xFEFEFEFE) >> 1) ) & 0xFEFEFEFE ) >> 1;
  3240. }
  3241. YPlane += ypitch_adj;
  3242. }
  3243. }
  3244. pvsrc = lpInput + (lpbiInput->biWidth * lpbiInput->biHeight);
  3245. pusrc = pvsrc + ((lpbiInput->biWidth>>2) * (lpbiInput->biHeight>>2));
  3246. t = ((lpbiInput->biWidth>>2) * (height_adj>>2)) + (width_adj>>2);
  3247. pvsrc += t;
  3248. pusrc += t;
  3249. C_uv_plane_common(pusrc,UPlane,pitch,FrameWidth>>1,LumaIters>>1,width_adj>>1);
  3250. C_uv_plane_common(pvsrc,VPlane,pitch,FrameWidth>>1,LumaIters>>1,width_adj>>1);
  3251. }
  3252. #endif
  3253. __declspec(naked)
  3254. _STATIC void IA_uv_plane_common(
  3255. U8 *psrc,
  3256. U8 *Plane,
  3257. UN pitch,
  3258. UN OutputFrameWidth,
  3259. UN ChromaIters,
  3260. UN spitch_adj)
  3261. {
  3262. // Permanent (callee-save) registers - ebx, esi, edi, ebp
  3263. // Temporary (caller-save) registers - eax, ecx, edx
  3264. //
  3265. // Stack frame layout
  3266. // | spitch_adj | + 64
  3267. // | ChromaIters | + 60
  3268. // | OutputFrameWidth| + 56
  3269. // | pitch | + 52
  3270. // | Plane | + 48
  3271. // | psrc | + 44
  3272. // -----------------------------
  3273. // | return addr | + 40
  3274. // | saved ebp | + 36
  3275. // | saved ebx | + 32
  3276. // | saved esi | + 28
  3277. // | saved edi | + 24
  3278. // | dpitch_adj | + 20
  3279. // | stretch | + 16
  3280. // | mark | + 12
  3281. // | flag | + 8
  3282. // | j | + 4
  3283. // | k | + 0
  3284. #define LOCALSIZE 24
  3285. #define SPITCH_ADJ 64
  3286. #define CHROMA_ITERS 60
  3287. #define OUTPUT_FRAME_WIDTH 56
  3288. #define PITCH_PARM 52
  3289. #define PLANE 48
  3290. #define PSRC 44
  3291. #define DPITCH_ADJ 20
  3292. #define STRETCH 16
  3293. #define MARK 12
  3294. #define FLAG 8
  3295. #define LOOP_J 4
  3296. #define LOOP_K 0
  3297. _asm {
  3298. push ebp
  3299. push ebx
  3300. push esi
  3301. push edi
  3302. sub esp, LOCALSIZE
  3303. // pnext = psrc + (OuputFrameWidth>>1) + uvpitch_adj
  3304. // pdest_copy = Plane
  3305. // pdest_avg = Plane + pitch
  3306. // assign (esi, psrc)
  3307. // assign (ecx, pnext)
  3308. // assign (edi, pdest_copy)
  3309. // assign (edx, pdest_avg)
  3310. // assign (ebp, i)
  3311. mov esi, [esp + PSRC]
  3312. mov ecx, esi
  3313. mov eax, [esp + OUTPUT_FRAME_WIDTH]
  3314. shr eax, 1
  3315. add eax, [esp + SPITCH_ADJ]
  3316. add ecx, eax
  3317. mov edi, [esp + PLANE]
  3318. mov edx, edi
  3319. add edx, [esp + PITCH_PARM]
  3320. // dpitch_adj = pitch - OutputFrameWidth
  3321. mov eax, [esp + PITCH_PARM]
  3322. sub eax, [esp + OUTPUT_FRAME_WIDTH]
  3323. mov [esp + DPITCH_ADJ], eax
  3324. // stretch = (spitch_adj ? 1 : 0)
  3325. xor ebx, ebx
  3326. mov eax, [esp + SPITCH_ADJ]
  3327. test eax, eax
  3328. jz L1
  3329. inc ebx
  3330. L1:
  3331. mov [esp + STRETCH], ebx
  3332. // mark = 6 - stretch
  3333. mov eax, 6
  3334. sub eax, ebx
  3335. mov [esp + MARK], eax
  3336. // flag = stretch
  3337. mov DWORD PTR [esp + FLAG], ebx
  3338. // for (j = ChromaIters; j > 0; j--)
  3339. mov eax, [esp + CHROMA_ITERS]
  3340. mov [esp + LOOP_J], eax
  3341. L2:
  3342. // for (k = mark + (flag & 1); k > 0; k--)
  3343. mov eax, [esp + FLAG]
  3344. and eax, 1
  3345. add eax, [esp + MARK]
  3346. mov [esp + LOOP_K], eax
  3347. L3:
  3348. // if (!stretch && (0 == j) && (0 == k))
  3349. mov eax, [esp + STRETCH]
  3350. test eax, eax
  3351. jnz L4
  3352. mov eax, [esp + LOOP_J]
  3353. cmp eax, 1
  3354. jne L4
  3355. mov eax, [esp + LOOP_K]
  3356. cmp eax, 1
  3357. jne L4
  3358. // pnext = psrc
  3359. mov ecx, esi
  3360. L4:
  3361. // for (i = OutputFrameWidth; i > 0; i -= 8, psrc += 4, pnext += 4,
  3362. // pdest_copy += 8, pdest_avg += 8)
  3363. mov ebp, [esp + OUTPUT_FRAME_WIDTH]
  3364. // Pentium pipeline scheduling has not been performed on the following loop code yet
  3365. L5:
  3366. // READ_DWORD_AND_SHIFT(t1,psrc)
  3367. mov eax, [esi]
  3368. and eax, 0xFEFEFEFE
  3369. shr eax, 1
  3370. // DUP_LOWER_TWO_BYTES(pdest_copy,t1)
  3371. mov bl, ah
  3372. mov bh, ah
  3373. shl ebx, 16
  3374. mov bl, al
  3375. mov bh, al
  3376. mov [edi], ebx
  3377. // DUP_UPPER_TWO_BYTES((pdest_copy+4),t1)
  3378. shr eax, 16
  3379. mov bl, ah
  3380. mov bh, ah
  3381. shl ebx, 16
  3382. mov bl, al
  3383. mov bh, al
  3384. mov [edi+4], ebx
  3385. // READ_DWORD_AND_SHIFT(t2,pnext)
  3386. // AVERAGE_DWORDS(t1,t1,t2)
  3387. mov eax, [esi]
  3388. and eax, 0xFEFEFEFE
  3389. shr eax, 1
  3390. mov ebx, [ecx]
  3391. and ebx, 0xFEFEFEFE
  3392. shr ebx, 1
  3393. add eax, ebx
  3394. and eax, 0xFEFEFEFE
  3395. shr eax, 1
  3396. // DUP_LOWER_TWO_BYTES(pdest_avg,t1)
  3397. mov bl, ah
  3398. mov bh, ah
  3399. shl ebx, 16
  3400. mov bl, al
  3401. mov bh, al
  3402. mov [edx], ebx
  3403. // DUP_UPPER_TWO_BYTES((pdest_avg+4),t1)
  3404. shr eax, 16
  3405. mov bl, ah
  3406. mov bh, ah
  3407. shl ebx, 16
  3408. mov bl, al
  3409. mov bh, al
  3410. mov [edx+4], ebx
  3411. // end of i loop
  3412. lea esi, [esi + 4]
  3413. lea ecx, [ecx + 4]
  3414. lea edi, [edi + 8]
  3415. lea edx, [edx + 8]
  3416. sub ebp, 8
  3417. jnz L5
  3418. // psrc += spitch_adj
  3419. // pnext += spitch_adj
  3420. // pdest_copy = pdest_avg + pitch_adj
  3421. // pdest_avg = pdest_copy + pitch
  3422. add esi, [esp + SPITCH_ADJ]
  3423. add ecx, [esp + SPITCH_ADJ]
  3424. mov eax, edx
  3425. add eax, [esp + DPITCH_ADJ]
  3426. mov edi, eax
  3427. mov edx, edi
  3428. add edx, [esp + PITCH_PARM]
  3429. // end of k loop
  3430. dec DWORD PTR [esp + LOOP_K]
  3431. jnz L3
  3432. // if (stretch)
  3433. cmp DWORD PTR [esp + STRETCH], 0
  3434. jz L6
  3435. // psrc -= ((OutputFrameWidth>>1)+spitch_adj)
  3436. // pnext -= ((OutputFrameWidth>>1)+spitch_adj)
  3437. // pdest_avg = pdest_copy
  3438. mov eax, [esp + OUTPUT_FRAME_WIDTH]
  3439. shr eax, 1
  3440. add eax, [esp + SPITCH_ADJ]
  3441. sub esi, eax
  3442. sub ecx, eax
  3443. mov edx, edi
  3444. // for (i = OutputFrameWidth; i > 0; i -= 8, psrc += 4, pnext += 4, pdest_avg += 8)
  3445. mov ebp, [esp + OUTPUT_FRAME_WIDTH]
  3446. // Pentium pipeline scheduling has not been performed on the following loop code yet
  3447. L7:
  3448. // READ_DWORD_AND_SHIFT(t1,psrc)
  3449. mov eax, [esi]
  3450. and eax, 0xFEFEFEFE
  3451. shr eax, 1
  3452. // READ_DWORD_AND_SHIFT(t2,pnext)
  3453. mov ebx, [ecx]
  3454. and ebx, 0xFEFEFEFE
  3455. shr ebx, 1
  3456. // AVERAGE_DWORDS(t1,t1,t2)
  3457. // AVERAGE_DWORDS(t1,t1,t2)
  3458. add eax, ebx
  3459. and eax, 0xFEFEFEFE
  3460. shr eax, 1
  3461. add eax, ebx
  3462. and eax, 0xFEFEFEFE
  3463. shr eax, 1
  3464. // DUP_LOWER_TWO_BYTES(pdest_avg,t1)
  3465. mov bl, ah
  3466. mov bh, ah
  3467. shl ebx, 16
  3468. mov bl, al
  3469. mov bh, al
  3470. mov [edx], ebx
  3471. // DUP_UPPER_TWO_BYTES((pdest_avg+4),t1)
  3472. shr eax, 16
  3473. mov bl, ah
  3474. mov bh, ah
  3475. shl ebx, 16
  3476. mov bl, al
  3477. mov bh, al
  3478. mov [edx+4], ebx
  3479. // end of i loop
  3480. lea esi, [esi + 4]
  3481. lea ecx, [ecx + 4]
  3482. lea edx, [edx + 8]
  3483. sub ebp, 8
  3484. jnz L7
  3485. // psrc += spitch_adj
  3486. // pnext += spitch_adj
  3487. // pdest_copy = pdest_avg + dpitch_adj
  3488. // pdest_avg = pdest_copy + pitch
  3489. // flag++
  3490. add esi, [esp + SPITCH_ADJ]
  3491. add ecx, [esp + SPITCH_ADJ]
  3492. mov eax, edx
  3493. add eax, [esp + DPITCH_ADJ]
  3494. mov edi, eax
  3495. mov edx, edi
  3496. add edx, [esp + PITCH_PARM]
  3497. inc DWORD PTR [esp + FLAG]
  3498. // end of j loop
  3499. L6:
  3500. dec DWORD PTR [esp + LOOP_J]
  3501. jnz L2
  3502. add esp, LOCALSIZE
  3503. pop edi
  3504. pop esi
  3505. pop ebx
  3506. pop ebp
  3507. ret
  3508. }
  3509. }
  3510. #undef LOCALSIZE
  3511. #undef SPITCH_ADJ
  3512. #undef CHROMA_ITERS
  3513. #undef OUTPUT_FRAME_WIDTH
  3514. #undef PITCH_PARM
  3515. #undef PLANE
  3516. #undef PSRC
  3517. #undef DPITCH_ADJ
  3518. #undef STRETCH
  3519. #undef MARK
  3520. #undef FLAG
  3521. #undef LOOP_J
  3522. #undef LOOP_K
  3523. __declspec(naked)
  3524. _STATIC void IA_H26X_YVU9toYUV12(
  3525. LPBITMAPINFOHEADER lpbiInput,
  3526. U8 *lpInput,
  3527. U8 *YPlane,
  3528. U8 *UPlane,
  3529. U8 *VPlane,
  3530. UN FrameWidth,
  3531. UN FrameHeight,
  3532. const int pitch)
  3533. {
  3534. // Permanent (callee-save) registers - ebx, esi, edi, ebp
  3535. // Temporary (caller-save) registers - eax, ecx, edx
  3536. //
  3537. // Stack frame layout
  3538. // | pitch | + 88
  3539. // | FrameHeight | + 84
  3540. // | FrameWidth | + 80
  3541. // | VPlane | + 76
  3542. // | UPlane | + 72
  3543. // | YPlane | + 68
  3544. // | lpInput | + 64
  3545. // | lpbiInput | + 60
  3546. // -----------------------------
  3547. // | return addr | + 56
  3548. // | saved ebp | + 52
  3549. // | saved ebx | + 48
  3550. // | saved esi | + 44
  3551. // | saved edi | + 40
  3552. // | width_adj | + 36
  3553. // | height_adj | + 32
  3554. // | stretch | + 28
  3555. // | mark | + 24
  3556. // | iNextLine | + 20
  3557. // | j | + 16
  3558. // | k | + 12
  3559. // | LumaIters | + 8
  3560. // | ypitch_adj | + 4
  3561. // | uvpitch_adj | + 0
  3562. #define LOCALSIZE 40
  3563. #define PITCH_PARM 88
  3564. #define FRAME_HEIGHT 84
  3565. #define FRAME_WIDTH 80
  3566. #define VPLANE 76
  3567. #define UPLANE 72
  3568. #define YPLANE 68
  3569. #define LP_INPUT 64
  3570. #define LPBI_INPUT 60
  3571. #define WIDTH_ADJ 36
  3572. #define HEIGHT_ADJ 32
  3573. #define STRETCH 28
  3574. #define MARK 24
  3575. #define NEXT_LINE 20
  3576. #define LOOP_J 16
  3577. #define LOOP_K 12
  3578. #define LUMA_ITERS 8
  3579. #define YPITCH_ADJ 4
  3580. #define UVPITCH_ADJ 0
  3581. _asm {
  3582. push ebp
  3583. push ebx
  3584. push esi
  3585. push edi
  3586. sub esp, LOCALSIZE
  3587. // assign (ebx, lpbiInput)
  3588. mov ebx, [esp + LPBI_INPUT]
  3589. // ypitch_adj = pitch - FrameWidth
  3590. // assign (ecx, FrameWidth)
  3591. // assign (edx, pitch)
  3592. mov ecx, [esp + FRAME_WIDTH]
  3593. mov edx, [esp + PITCH_PARM]
  3594. mov eax, edx
  3595. sub eax, ecx
  3596. mov [esp + YPITCH_ADJ], eax
  3597. // uvpitch_adj = pitch - (FrameWidth >> 1)
  3598. // kill (edx, pitch)
  3599. mov ebp, ecx
  3600. shr ebp, 1
  3601. sub edx, ebp
  3602. mov [esp + UVPITCH_ADJ], edx
  3603. // for (i = FrameHeight; i > 0; i -= 48) LumaIters += 4
  3604. // assign (edx, LumaIters)
  3605. xor edx, edx
  3606. mov eax, [esp + FRAME_HEIGHT]
  3607. L1:
  3608. lea edx, [edx + 4]
  3609. sub eax, 48
  3610. jnz L1
  3611. // width_adj = (lpbiInput->biWidth - FrameWidth) >> 1
  3612. // assign (esi, width_adj)
  3613. mov esi, (LPBITMAPINFOHEADER)[ebx].biWidth
  3614. sub esi, [esp + FRAME_WIDTH]
  3615. shr esi, 1
  3616. mov [esp + WIDTH_ADJ], esi
  3617. // aspect = (width_adj ? LumaIters : 0)
  3618. // assign (edi, aspect)
  3619. // kill (edx, LumaIters)
  3620. mov [esp + LUMA_ITERS], edx
  3621. xor edi, edi
  3622. test esi, esi
  3623. jz L2
  3624. mov edi, edx
  3625. // height _adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1
  3626. // assign (edx, height_adj)
  3627. L2:
  3628. mov edx, (LPBITMAPINFOHEADER)[ebx].biHeight
  3629. sub edx, [esp + FRAME_HEIGHT]
  3630. add edx, edi
  3631. shr edx, 1
  3632. mov [esp + HEIGHT_ADJ], edx
  3633. // stretch = (height_adj ? 1 : 0)
  3634. xor eax, eax
  3635. test edx, edx
  3636. jz L3
  3637. inc eax
  3638. L3:
  3639. mov [esp + STRETCH], eax
  3640. // mark = 12 - stretch
  3641. mov ebp, 12
  3642. sub ebp, eax
  3643. mov [esp + MARK], ebp
  3644. // iNextLine = width_adj << 1
  3645. mov ebp, esi
  3646. shl ebp, 1
  3647. mov [esp + NEXT_LINE], ebp
  3648. // pnext = lpInput + (lpbiInput->biWidth * height_adj) + width_adj
  3649. // kill (ebx, lpbiInput)
  3650. // kill (ecx, FrameWidth)
  3651. // kill (edx, height_adj)
  3652. // kill (esi, width_adj)
  3653. // kill (edi, aspect)
  3654. // assign (esi, pnext)
  3655. mov eax, (LPBITMAPINFOHEADER)[ebx].biWidth
  3656. mov ebx, edx
  3657. imul ebx
  3658. add esi, eax
  3659. add esi, [esp + LP_INPUT]
  3660. // assign (edi, YPlane)
  3661. mov edi, [esp + YPLANE]
  3662. // for (j = LumaIters; j > 0; j--)
  3663. mov eax, [esp + LUMA_ITERS]
  3664. mov [esp + LOOP_J], eax
  3665. // for (k = mark; k > 0; k--)
  3666. L4:
  3667. mov eax, [esp + MARK]
  3668. mov [esp + LOOP_K], eax
  3669. // for (i = FrameWidth; i > 0; i -= 4, YPlane += 4, pnext += 4)
  3670. // assign (ebp, i)
  3671. L5:
  3672. mov ebp, [esp + FRAME_WIDTH]
  3673. // This jump is here to make sure the following loop starts on the U pipe
  3674. jmp L6
  3675. L6:
  3676. // *(U32 *)YPlane = (*(U32 *)pnext & 0xFEFEFEFE) >> 1;
  3677. // 1
  3678. mov eax, [esi]
  3679. lea esi, [esi + 4]
  3680. // 2
  3681. and eax, 0xFEFEFEFE
  3682. lea edi, [edi + 4]
  3683. // 3
  3684. shr eax, 1
  3685. sub ebp, 4
  3686. // 4
  3687. mov [edi - 4], eax
  3688. jnz L6
  3689. // pnext += iNextLine
  3690. // YPlane += ypitch_adj
  3691. add esi, [esp + NEXT_LINE]
  3692. add edi, [esp + YPITCH_ADJ]
  3693. // end of k loop
  3694. mov eax, [esp + LOOP_K]
  3695. sub eax, 1
  3696. mov [esp + LOOP_K], eax
  3697. jnz L5
  3698. // if (stretch)
  3699. mov eax, [esp + STRETCH]
  3700. test eax, eax
  3701. jz L7
  3702. // plast = pnext - lpbiInput->biWidth
  3703. // pn = pnext
  3704. // assign (ecx, plast)
  3705. // assign (edx, pn)
  3706. mov ecx, esi
  3707. mov eax, [esp + LPBI_INPUT]
  3708. sub ecx, (LPBITMAPINFOHEADER)[eax].biWidth
  3709. mov edx, esi
  3710. // for (i = FrameWidth; i > 0; i -= 4, YPlane += 4, pnext += 4)
  3711. // assign (ebp, i)
  3712. mov ebp, [esp + FRAME_WIDTH]
  3713. // This jump is here just to make sure the loop code starts with the U pipe
  3714. jmp L8
  3715. L8:
  3716. // *(U32 *)YPlane =
  3717. // ( ( ((*(U32 *)plast & 0xFEFEFEFE) >> 1) +
  3718. // ((*(U32 *)pbn & 0xFEFEFEFE) >> 1) ) & 0xFEFEFEFE ) >> 1
  3719. // 1
  3720. mov eax, [ecx]
  3721. lea ecx, [ecx + 4]
  3722. // 2
  3723. shr eax, 1
  3724. // 3
  3725. and eax, 0x7F7F7F7F
  3726. mov ebx, [edx]
  3727. // 4
  3728. shr ebx, 1
  3729. lea edi, [edi + 4]
  3730. // 5
  3731. and ebx, 0x7F7F7F7F
  3732. // 6
  3733. add eax, ebx
  3734. // 7
  3735. and eax, 0xFEFEFEFE
  3736. // 8
  3737. shr eax, 1
  3738. // 9
  3739. mov [edi - 4], eax
  3740. sub ebp, 4
  3741. // 10
  3742. lea edx, [edx + 4]
  3743. jnz L8
  3744. // YPlane += ypitch_adj
  3745. add edi, [esp + YPITCH_ADJ]
  3746. L7:
  3747. // end of the LumaIters loop
  3748. dec DWORD PTR [esp + LOOP_J]
  3749. jnz L4
  3750. // pvsrc = lpInput + (lpbiInput->biWidth * lpbiInput->biHeight)
  3751. // assign (esi, pvsrc)
  3752. mov eax, [esp + LPBI_INPUT]
  3753. mov ebx, (LPBITMAPINFOHEADER)[eax].biWidth
  3754. mov eax, (LPBITMAPINFOHEADER)[eax].biHeight
  3755. imul ebx
  3756. add eax, [esp + LP_INPUT]
  3757. mov esi, eax
  3758. // pusrc = pvsrc + ((lpbiInput->biWidth>>2) * (lpbiInput->biHeight)>>2)
  3759. // assign (edi, pusrc)
  3760. mov eax, [esp + LPBI_INPUT]
  3761. mov ecx, (LPBITMAPINFOHEADER)[eax].biWidth
  3762. shr ecx, 2
  3763. mov eax, (LPBITMAPINFOHEADER)[eax].biHeight
  3764. shr eax, 2
  3765. imul ecx
  3766. add eax, esi
  3767. mov edi, eax
  3768. // t = ((lpbiInput->biWidth>>2) * (height>>2)) + (width_adj>>2)
  3769. // assign (eax, t)
  3770. mov eax, [esp + LPBI_INPUT]
  3771. mov eax, (LPBITMAPINFOHEADER)[eax].biWidth
  3772. shr eax, 2
  3773. mov ebx, [esp + HEIGHT_ADJ]
  3774. shr ebx, 2
  3775. imul ebx
  3776. mov ebx, [esp + WIDTH_ADJ]
  3777. shr ebx, 2
  3778. add eax, ebx
  3779. // pvsrc += t
  3780. // pusrc += t
  3781. add esi, eax
  3782. add edi, eax
  3783. // uv_plane_common(pusrc,UPlane,pitch,FrameWidth>>1,LumaIters>>1,width_adj>>1)
  3784. mov ebp, esp
  3785. mov eax, [ebp + WIDTH_ADJ]
  3786. shr eax, 1
  3787. push eax
  3788. mov eax, [ebp + LUMA_ITERS]
  3789. shr eax, 1
  3790. push eax
  3791. mov eax, [ebp + FRAME_WIDTH]
  3792. shr eax, 1
  3793. push eax
  3794. push DWORD PTR [ebp + PITCH_PARM]
  3795. push DWORD PTR [ebp + UPLANE]
  3796. push edi
  3797. call IA_uv_plane_common
  3798. lea esp, [esp + 24]
  3799. // uv_plane_common(pvsrc,VPlane,pitch,FrameWidth>>1,LumaIters>>1,width_adj>>1)
  3800. mov ebp, esp
  3801. mov eax, [ebp + WIDTH_ADJ]
  3802. shr eax, 1
  3803. push eax
  3804. mov eax, [ebp + LUMA_ITERS]
  3805. shr eax, 1
  3806. push eax
  3807. mov eax, [ebp + FRAME_WIDTH]
  3808. shr eax, 1
  3809. push eax
  3810. push DWORD PTR [ebp + PITCH_PARM]
  3811. push DWORD PTR [ebp + VPLANE]
  3812. push esi
  3813. call IA_uv_plane_common
  3814. lea esp, [esp + 24]
  3815. add esp, LOCALSIZE
  3816. pop edi
  3817. pop esi
  3818. pop ebx
  3819. pop ebp
  3820. ret
  3821. }
  3822. }
  3823. #undef LOCALSIZE
  3824. #undef PITCH_PARM
  3825. #undef FRAME_HEIGHT
  3826. #undef FRAME_WIDTH
  3827. #undef VPLANE
  3828. #undef UPLANE
  3829. #undef YPLANE
  3830. #undef LP_INPUT
  3831. #undef LPBI_INPUT
  3832. #undef WIDTH_ADJ
  3833. #undef HEIGHT_ADJ
  3834. #undef STRETCH
  3835. #undef MARK
  3836. #undef NEXT_LINE
  3837. #undef LOOP_J
  3838. #undef LOOP_K
  3839. #undef LUMA_ITERS
  3840. #undef YPITCH_ADJ
  3841. #undef UVPITCH_ADJ
  3842. /***************************************************
  3843. * H26X_YUV12toEncYUV12()
  3844. * Copy YUV12 data to encoder memory at the
  3845. * appropriate location. It is assumed that the input
  3846. * data is stored as rows of Y, followed by rows of U,
  3847. * then rows of V.
  3848. *
  3849. ***************************************************/
  3850. #if 0
  3851. _STATIC void C_H26X_YUV12toEncYUV12(
  3852. LPBITMAPINFOHEADER lpbiInput,
  3853. U8 *lpInput,
  3854. U8 *YPlane,
  3855. U8 *UPlane,
  3856. U8 *VPlane,
  3857. UN FrameWidth,
  3858. UN FrameHeight,
  3859. const int pitch) {
  3860. int i, j;
  3861. U32 *pnext = (U32 *)lpInput;
  3862. int ypitch_adj = pitch - FrameWidth;
  3863. int yinput_height = lpbiInput->biHeight;
  3864. int yinput_width = lpbiInput->biWidth;
  3865. int yheight_diff = FrameHeight - yinput_height;
  3866. int ywidth_diff = FrameWidth - yinput_width;
  3867. int uvpitch_adj = pitch - (FrameWidth >> 1);
  3868. int uvoutput_width = FrameWidth >> 1;
  3869. int uvinput_height = yinput_height >> 1;
  3870. int uvinput_width = yinput_width >> 1;
  3871. int uvheight_diff = yheight_diff >> 1;
  3872. int uvwidth_diff = ywidth_diff >> 1;
  3873. for (j = yinput_height; j > 0; j--, YPlane += ypitch_adj) {
  3874. for (i = yinput_width; i > 0; i -= 8) {
  3875. *(U32 *)YPlane = (*pnext++ >> 1) & 0x7F7F7F7F; YPlane += 4;
  3876. *(U32 *)YPlane = (*pnext++ >> 1) & 0x7F7F7F7F; YPlane += 4;
  3877. }
  3878. for (i = ywidth_diff; i > 0; i -= 8) {
  3879. *(U32 *)YPlane = 0; YPlane += 4;
  3880. *(U32 *)YPlane = 0; YPlane += 4;
  3881. }
  3882. }
  3883. for (j = yheight_diff; j > 0; j--, YPlane += ypitch_adj) {
  3884. for (i = FrameWidth; i > 0; i -= 8) {
  3885. *(U32 *)YPlane = 0; YPlane += 4;
  3886. *(U32 *)YPlane = 0; YPlane += 4;
  3887. }
  3888. }
  3889. for (j = uvinput_height; j > 0; j--, UPlane += uvpitch_adj) {
  3890. for (i = uvinput_width; i > 0; i -= 8) {
  3891. *(U32 *)UPlane = (*pnext++ >> 1) & 0x7F7F7F7F; UPlane += 4;
  3892. *(U32 *)UPlane = (*pnext++ >> 1) & 0x7F7F7F7F; UPlane += 4;
  3893. }
  3894. for (i = uvwidth_diff; i > 0; i -= 8) {
  3895. *(U32 *)UPlane = 0x40404040; UPlane += 4;
  3896. *(U32 *)UPlane = 0x40404040; UPlane += 4;
  3897. }
  3898. }
  3899. for (j = uvheight_diff; j > 0; j--, UPlane += uvpitch_adj) {
  3900. for (i = uvoutput_width; i > 0; i -= 8) {
  3901. *(U32 *)UPlane = 0x40404040; UPlane += 4;
  3902. *(U32 *)UPlane = 0x40404040; UPlane += 4;
  3903. }
  3904. }
  3905. for (j = uvinput_height; j > 0; j--, VPlane += uvpitch_adj) {
  3906. for (i = uvinput_width; i > 0; i -= 8) {
  3907. *(U32 *)VPlane = (*pnext++ >> 1) & 0x7F7F7F7F; VPlane += 4;
  3908. *(U32 *)VPlane = (*pnext++ >> 1) & 0x7F7F7F7F; VPlane += 4;
  3909. }
  3910. for (i = uvwidth_diff; i > 0; i -= 8) {
  3911. *(U32 *)VPlane = 0x40404040; VPlane += 4;
  3912. *(U32 *)VPlane = 0x40404040; VPlane += 4;
  3913. }
  3914. }
  3915. for (j = uvheight_diff; j > 0; j--, VPlane += uvpitch_adj) {
  3916. for (i = uvoutput_width; i > 0; i -= 8) {
  3917. *(U32 *)VPlane = 0x40404040; VPlane += 4;
  3918. *(U32 *)VPlane = 0x40404040; VPlane += 4;
  3919. }
  3920. }
  3921. }
  3922. #endif
  3923. __declspec(naked)
  3924. _STATIC void IA_H26X_YUV12toEncYUV12(
  3925. LPBITMAPINFOHEADER lpbiInput,
  3926. U8 *lpInput,
  3927. U8 *YPlane,
  3928. U8 *UPlane,
  3929. U8 *VPlane,
  3930. UN FrameWidth,
  3931. UN FrameHeight,
  3932. const int pitch)
  3933. {
  3934. // Permanent (callee-save) registers - ebx, esi, edi, ebp
  3935. // Temporary (caller-save) registers - eax, ecx, edx
  3936. //
  3937. // Stack frame layout
  3938. // | pitch | + 92
  3939. // | FrameHeight | + 88
  3940. // | FrameWidth | + 84
  3941. // | VPlane | + 80
  3942. // | UPlane | + 76
  3943. // | YPlane | + 72
  3944. // | lpInput | + 68
  3945. // | lpbiInput | + 64
  3946. // -----------------------------
  3947. // | return addr | + 60
  3948. // | saved ebp | + 56
  3949. // | saved ebx | + 52
  3950. // | saved esi | + 48
  3951. // | saved edi | + 44
  3952. // | ypitch_adj | + 40
  3953. // | yinput_height | + 36
  3954. // | yinput_width | + 32
  3955. // | yheight_diff | + 28
  3956. // | ywidth_diff | + 24
  3957. // | uvpitch_adj | + 20
  3958. // | uvoutput_width | + 16
  3959. // | uvinput_height | + 12
  3960. // | uvinput_width | + 8
  3961. // | uvheight_diff | + 4
  3962. // | uvwidth_diff | + 0
  3963. #define LOCALSIZE 44
  3964. #define PITCH_PARM 92
  3965. #define FRAME_HEIGHT 88
  3966. #define FRAME_WIDTH 84
  3967. #define VPLANE 80
  3968. #define UPLANE 76
  3969. #define YPLANE 72
  3970. #define LP_INPUT 68
  3971. #define LPBI_INPUT 64
  3972. #define YPITCH_ADJ 40
  3973. #define YINPUT_HEIGHT 36
  3974. #define YINPUT_WIDTH 32
  3975. #define YHEIGHT_DIFF 28
  3976. #define YWIDTH_DIFF 24
  3977. #define UVPITCH_ADJ 20
  3978. #define UVOUTPUT_WIDTH 16
  3979. #define UVINPUT_HEIGHT 12
  3980. #define UVINPUT_WIDTH 8
  3981. #define UVHEIGHT_DIFF 4
  3982. #define UVWIDTH_DIFF 0
  3983. _asm {
  3984. push ebp
  3985. push ebx
  3986. push esi
  3987. push edi
  3988. sub esp, LOCALSIZE
  3989. mov ebx, [esp + FRAME_HEIGHT]
  3990. mov ecx, [esp + FRAME_WIDTH]
  3991. mov edx, [esp + PITCH_PARM]
  3992. // ypitch_adj = pitch - FrameWidth
  3993. mov eax, edx
  3994. sub eax, ecx
  3995. mov [esp + YPITCH_ADJ], eax
  3996. // uvoutput_width = FrameWidth >> 1
  3997. mov ebp, ecx
  3998. shr ebp, 1
  3999. mov [esp + UVOUTPUT_WIDTH], ebp
  4000. // uvpitch_adj = pitch - (FrameWidth >> 1)
  4001. sub edx, ebp
  4002. mov [esp + UVPITCH_ADJ], edx
  4003. // yinput_height = lpbiInput->biHeight
  4004. // uvinput_height = yinput_height >> 1
  4005. // yinput_width = lpbiInput->biWidth
  4006. // uvinput_width = yinput_width >> 1
  4007. mov ebx, [esp + LPBI_INPUT]
  4008. mov eax, (LPBITMAPINFOHEADER)[ebx].biHeight
  4009. mov [esp + YINPUT_HEIGHT], eax
  4010. shr eax, 1
  4011. mov [esp + UVINPUT_HEIGHT], eax
  4012. mov eax, (LPBITMAPINFOHEADER)[ebx].biWidth
  4013. mov [esp + YINPUT_WIDTH], eax
  4014. shr eax, 1
  4015. mov [esp + UVINPUT_WIDTH], eax
  4016. // yheight_diff = FrameHeight - yinput_height
  4017. // uvheight_diff = yheight_diff >> 1;
  4018. mov eax, [esp + FRAME_HEIGHT]
  4019. mov ebx, eax
  4020. sub eax, [esp + YINPUT_HEIGHT]
  4021. jns NoCrop0
  4022. xor eax, eax
  4023. mov [esp + YINPUT_HEIGHT], ebx
  4024. shr ebx, 1
  4025. mov [esp + UVINPUT_HEIGHT], ebx
  4026. NoCrop0:
  4027. mov [esp + YHEIGHT_DIFF], eax
  4028. shr eax, 1
  4029. mov [esp + UVHEIGHT_DIFF], eax
  4030. // ywidth_diff = FrameWidth - yinput_width
  4031. // uvwidth_diff = ywidth_diff >> 1;
  4032. mov eax, [esp + FRAME_WIDTH]
  4033. xor ebx, ebx
  4034. sub eax, [esp + YINPUT_WIDTH]
  4035. jns NoCrop1
  4036. mov eax, [esp + FRAME_WIDTH]
  4037. mov ebx, [esp + YINPUT_WIDTH]
  4038. sub ebx, eax
  4039. mov [esp + YINPUT_WIDTH], eax
  4040. shr eax, 1
  4041. mov [esp + UVINPUT_WIDTH], eax
  4042. xor eax, eax
  4043. NoCrop1:
  4044. mov [esp + YWIDTH_DIFF], eax
  4045. shr eax, 1
  4046. mov [esp + UVWIDTH_DIFF], eax
  4047. // assign (esi, lpInput)
  4048. mov esi, [esp + LP_INPUT]
  4049. // assign (edi, YPlane)
  4050. mov edi, [esp + YPLANE]
  4051. // for (j = yinput_height; j > 0; j--, YPlane += ypitch_adj)
  4052. // assign (ecx, j)
  4053. mov ecx, [esp + YINPUT_HEIGHT]
  4054. L1:
  4055. // for (i = yinput_width; i > 0; i -= 8)
  4056. // assign (ebp, i)
  4057. mov ebp, [esp + YINPUT_WIDTH]
  4058. L2:
  4059. // *(U32 *)YPlane = (*pnext++ >> 1) & 0x7F7F7F7F; YPlane += 4
  4060. // *(U32 *)YPlane = (*pnext++ >> 1) & 0x7F7F7F7F; YPlane += 4
  4061. // 1
  4062. mov eax, [esi]
  4063. mov edx, [esi + 4]
  4064. // 2
  4065. shr eax, 1
  4066. and edx, 0xFEFEFEFE
  4067. // 3
  4068. shr edx, 1
  4069. and eax, 0x7F7F7F7F
  4070. // 4
  4071. lea esi, [esi + 8]
  4072. mov [edi], eax
  4073. // 5
  4074. sub ebp, 8
  4075. mov [edi + 4], edx
  4076. // 6
  4077. lea edi, [edi + 8]
  4078. jnz L2
  4079. // for (i = ywidth_diff; i > 0; i -= 8)
  4080. // *(U32 *)YPlane = 0; YPlane += 4;
  4081. // *(U32 *)YPlane = 0; YPlane += 4;
  4082. // assign (ebp, i)
  4083. mov ebp, [esp + YWIDTH_DIFF]
  4084. test ebp, ebp
  4085. jz L3
  4086. L4:
  4087. // 1
  4088. xor eax, eax
  4089. sub ebp, 8
  4090. // 2
  4091. mov [edi], eax
  4092. mov [edi + 4], eax
  4093. // 3
  4094. lea edi, [edi + 8]
  4095. jnz L4
  4096. // j--, YPlane += ypitch_adj
  4097. L3:
  4098. mov eax, [esp + YPITCH_ADJ]
  4099. add edi, eax
  4100. add esi, ebx
  4101. dec ecx
  4102. jnz L1
  4103. // for (j = yheight_diff; j > 0; j--, YPlane += ypitch_adj)
  4104. // assign (ecx, j)
  4105. mov ecx, [esp + YHEIGHT_DIFF]
  4106. test ecx, ecx
  4107. jz L7
  4108. L5:
  4109. // for (i = FrameWidth; i > 0; i -= 8)
  4110. // *(U32 *)YPlane = 0; YPlane += 4;
  4111. // *(U32 *)YPlane = 0; YPlane += 4;
  4112. // assign (ebp, i)
  4113. mov ebp, [esp + FRAME_WIDTH]
  4114. L6:
  4115. // 1
  4116. xor eax, eax
  4117. sub ebp, 8
  4118. // 2
  4119. mov [edi], eax
  4120. mov [edi + 4], eax
  4121. // 3
  4122. lea edi, [edi + 8]
  4123. jnz L6
  4124. // j--, YPlane += ypitch_adj
  4125. mov eax, [esp + YPITCH_ADJ]
  4126. add edi, eax
  4127. dec ecx
  4128. jnz L5
  4129. L7:
  4130. // recompute start of input U plane
  4131. mov edx, [esp + LPBI_INPUT]
  4132. mov eax, (LPBITMAPINFOHEADER)[edx].biHeight
  4133. mov ecx, (LPBITMAPINFOHEADER)[edx].biWidth
  4134. imul eax, ecx
  4135. // assign (esi, lpInput)
  4136. mov esi, [esp + LP_INPUT]
  4137. add esi, eax
  4138. // assign (edi, UPlane)
  4139. mov edi, [esp + UPLANE]
  4140. shr ebx, 1
  4141. // for (j = uvinput_height; j > 0; j--, UPlane += ypitch_adj)
  4142. // assign (ecx, j)
  4143. mov ecx, [esp + UVINPUT_HEIGHT]
  4144. L8:
  4145. // for (i = uvinput_width; i > 0; i -= 8)
  4146. // assign (ebp, i)
  4147. mov ebp, [esp + UVINPUT_WIDTH]
  4148. L9:
  4149. // *(U32 *)UPlane = (*pnext++ >> 1) & 0x7F7F7F7F; UPlane += 4
  4150. // *(U32 *)UPlane = (*pnext++ >> 1) & 0x7F7F7F7F; UPlane += 4
  4151. // 1
  4152. mov eax, [esi]
  4153. mov edx, [esi + 4]
  4154. // 2
  4155. shr eax, 1
  4156. and edx, 0xFEFEFEFE
  4157. // 3
  4158. shr edx, 1
  4159. and eax, 0x7F7F7F7F
  4160. // 4
  4161. lea esi, [esi + 8]
  4162. mov [edi], eax
  4163. // 5
  4164. sub ebp, 8
  4165. mov [edi + 4], edx
  4166. // 6
  4167. lea edi, [edi + 8]
  4168. jnz L9
  4169. // for (i = uvwidth_diff; i > 0; i -= 8)
  4170. // *(U32 *)UPlane = 0x40404040; UPlane += 4;
  4171. // *(U32 *)UPlane = 0x40404040; UPlane += 4;
  4172. // assign (ebp, i)
  4173. mov ebp, [esp + UVWIDTH_DIFF]
  4174. test ebp, ebp
  4175. jz L11
  4176. L10:
  4177. // 1
  4178. mov eax, 040404040H
  4179. sub ebp, 8
  4180. // 2
  4181. mov [edi], eax
  4182. mov [edi + 4], eax
  4183. // 3
  4184. lea edi, [edi + 8]
  4185. jnz L10
  4186. // j--, UPlane += uvpitch_adj
  4187. L11:
  4188. mov eax, [esp + UVPITCH_ADJ]
  4189. add edi, eax
  4190. add esi, ebx
  4191. dec ecx
  4192. jnz L8
  4193. // for (j = uvheight_diff; j > 0; j--, UPlane += uvpitch_adj)
  4194. // assign (ecx, j)
  4195. mov ecx, [esp + UVHEIGHT_DIFF]
  4196. test ecx, ecx
  4197. jz L14
  4198. L12:
  4199. // for (i = uvoutput_width; i > 0; i -= 8)
  4200. // *(U32 *)UPlane = 0x40404040; UPlane += 4;
  4201. // *(U32 *)UPlane = 0x40404040; UPlane += 4;
  4202. // assign (ebp, i)
  4203. mov ebp, [esp + UVOUTPUT_WIDTH]
  4204. L13:
  4205. // 1
  4206. mov eax, 040404040H
  4207. sub ebp, 8
  4208. // 2
  4209. mov [edi], eax
  4210. mov [edi + 4], eax
  4211. // 3
  4212. lea edi, [edi + 8]
  4213. jnz L13
  4214. // j--, UPlane += uvpitch_adj
  4215. mov eax, [esp + UVPITCH_ADJ]
  4216. add edi, eax
  4217. dec ecx
  4218. jnz L12
  4219. L14:
  4220. // recompute start of input V plane
  4221. mov edx, [esp + LPBI_INPUT]
  4222. mov eax, (LPBITMAPINFOHEADER)[edx].biHeight
  4223. mov ecx, (LPBITMAPINFOHEADER)[edx].biWidth
  4224. imul eax, ecx
  4225. // assign (esi, lpInput)
  4226. mov esi, [esp + LP_INPUT]
  4227. add esi, eax
  4228. shr eax, 2
  4229. add esi, eax
  4230. // assign (edi, VPlane)
  4231. mov edi, [esp + VPLANE]
  4232. // for (j = uvinput_height; j > 0; j--, VPlane += ypitch_adj)
  4233. // assign (ecx, j)
  4234. mov ecx, [esp + UVINPUT_HEIGHT]
  4235. L15:
  4236. // for (i = uvinput_width; i > 0; i -= 8)
  4237. // assign (ebp, i)
  4238. mov ebp, [esp + UVINPUT_WIDTH]
  4239. L16:
  4240. // *(U32 *)VPlane = (*pnext++ >> 1) & 0x7F7F7F7F; VPlane += 4
  4241. // *(U32 *)VPlane = (*pnext++ >> 1) & 0x7F7F7F7F; VPlane += 4
  4242. // 1
  4243. mov eax, [esi]
  4244. mov edx, [esi + 4]
  4245. // 2
  4246. shr eax, 1
  4247. and edx, 0xFEFEFEFE
  4248. // 3
  4249. shr edx, 1
  4250. and eax, 0x7F7F7F7F
  4251. // 4
  4252. lea esi, [esi + 8]
  4253. mov [edi], eax
  4254. // 5
  4255. sub ebp, 8
  4256. mov [edi + 4], edx
  4257. // 6
  4258. lea edi, [edi + 8]
  4259. jnz L16
  4260. // for (i = uvwidth_diff; i > 0; i -= 8)
  4261. // *(U32 *)VPlane = 0x40404040; VPlane += 4;
  4262. // *(U32 *)VPlane = 0x40404040; VPlane += 4;
  4263. // assign (ebp, i)
  4264. mov ebp, [esp + UVWIDTH_DIFF]
  4265. test ebp, ebp
  4266. jz L18
  4267. L17:
  4268. // 1
  4269. mov eax, 040404040H
  4270. sub ebp, 8
  4271. // 2
  4272. mov [edi], eax
  4273. mov [edi + 4], eax
  4274. // 3
  4275. lea edi, [edi + 8]
  4276. jnz L17
  4277. // j--, VPlane += uvpitch_adj
  4278. L18:
  4279. mov eax, [esp + UVPITCH_ADJ]
  4280. add edi, eax
  4281. add esi, ebx
  4282. dec ecx
  4283. jnz L15
  4284. // for (j = uvheight_diff; j > 0; j--, VPlane += uvpitch_adj)
  4285. // assign (ecx, j)
  4286. mov ecx, [esp + UVHEIGHT_DIFF]
  4287. test ecx, ecx
  4288. jz L21
  4289. L19:
  4290. // for (i = uvoutput_width; i > 0; i -= 8)
  4291. // *(U32 *)VPlane = 0x40404040; VPlane += 4;
  4292. // *(U32 *)VPlane = 0x40404040; VPlane += 4;
  4293. // assign (ebp, i)
  4294. mov ebp, [esp + UVOUTPUT_WIDTH]
  4295. L20:
  4296. // 1
  4297. mov eax, 040404040H
  4298. sub ebp, 8
  4299. // 2
  4300. mov [edi], eax
  4301. mov [edi + 4], eax
  4302. // 3
  4303. lea edi, [edi + 8]
  4304. jnz L20
  4305. // j--, VPlane += uvpitch_adj
  4306. mov eax, [esp + UVPITCH_ADJ]
  4307. add edi, eax
  4308. dec ecx
  4309. jnz L19
  4310. L21:
  4311. add esp, LOCALSIZE
  4312. pop edi
  4313. pop esi
  4314. pop ebx
  4315. pop ebp
  4316. ret
  4317. }
  4318. }
  4319. #undef LOCALSIZE
  4320. #undef PITCH_PARM
  4321. #undef FRAME_HEIGHT
  4322. #undef FRAME_WIDTH
  4323. #undef VPLANE
  4324. #undef UPLANE
  4325. #undef YPLANE
  4326. #undef LP_INPUT
  4327. #undef LPBI_INPUT
  4328. #undef YPITCH_ADJ
  4329. #undef YINPUT_HEIGHT
  4330. #undef YINPUT_WIDTH
  4331. #undef YHEIGHT_DIFF
  4332. #undef YWIDTH_DIFF
  4333. #undef UVPITCH_ADJ
  4334. #undef UVOUTPUT_WIDTH
  4335. #undef UVINPUT_HEIGHT
  4336. #undef UVINPUT_WIDTH
  4337. #undef UVHEIGHT_DIFF
  4338. #undef UVWIDTH_DIFF
  4339. #if defined(_CODEC_STATS)
  4340. void NOC_H26X_YUY2toYUV12(
  4341. LPBITMAPINFOHEADER lpbiInput,
  4342. U8 *lpInput,
  4343. U8 *YPlane,
  4344. U8 *UPlane,
  4345. U8 *VPlane,
  4346. UN FrameWidth,
  4347. UN FrameHeight,
  4348. const int pitch) {
  4349. U8 *pnext, *plast, *pbn, *peol;
  4350. int width_adj, height_adj;
  4351. int stretch, mark, aspect;
  4352. int iBackTwoLines;
  4353. int j, k;
  4354. int LumaIters = 0;
  4355. int ypitch_adj = 0;
  4356. int uvpitch_adj = 0;
  4357. int nextline = -(lpbiInput->biWidth << 1);
  4358. for (j = FrameHeight; j > 0; j -= 48) {
  4359. LumaIters += 4;
  4360. }
  4361. width_adj = lpbiInput->biWidth - FrameWidth;
  4362. aspect = (width_adj ? LumaIters : 0);
  4363. height_adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1;
  4364. stretch = (height_adj ? 1 : 0);
  4365. mark = 12 - stretch;
  4366. // Move from end of line N to beginning of line N-1
  4367. iBackTwoLines = -((lpbiInput->biWidth + (int)FrameWidth) << 1);
  4368. // Point to the beginning of the last line.
  4369. pnext = lpInput + ((lpbiInput->biWidth << 1) * ((FrameHeight - aspect - 1) + height_adj))
  4370. + width_adj;
  4371. for (j = LumaIters; j > 0; j--) {
  4372. for (k = 0; k < mark; k++) {
  4373. for ( peol = pnext + (FrameWidth << 1); pnext < peol; pnext += 16, YPlane += 8) {
  4374. if (0 == (k & 1)) {
  4375. *(YPlane+0) = *(pnext+ 0); *(YPlane+1) = *(pnext+ 2);
  4376. *(YPlane+2) = *(pnext+ 4); *(YPlane+3) = *(pnext+ 6);
  4377. *(YPlane+4) = *(pnext+ 8); *(YPlane+5) = *(pnext+10);
  4378. *(YPlane+6) = *(pnext+12); *(YPlane+7) = *(pnext+14);
  4379. *(UPlane+0) = ((*(pnext+ 1)>>1) + (*(pnext+ 1+nextline)>>1));
  4380. *(UPlane+1) = ((*(pnext+ 5)>>1) + (*(pnext+ 5+nextline)>>1));
  4381. *(UPlane+2) = ((*(pnext+ 9)>>1) + (*(pnext+ 9+nextline)>>1));
  4382. *(UPlane+3) = ((*(pnext+13)>>1) + (*(pnext+13+nextline)>>1));
  4383. *(VPlane+0) = ((*(pnext+ 3)>>1) + (*(pnext+ 3+nextline)>>1));
  4384. *(VPlane+1) = ((*(pnext+ 7)>>1) + (*(pnext+ 7+nextline)>>1));
  4385. *(VPlane+2) = ((*(pnext+11)>>1) + (*(pnext+11+nextline)>>1));
  4386. *(VPlane+3) = ((*(pnext+15)>>1) + (*(pnext+15+nextline)>>1));
  4387. UPlane += 4; VPlane += 4;
  4388. } else {
  4389. *(YPlane+0) = *(pnext+ 0); *(YPlane+1) = *(pnext+ 2);
  4390. *(YPlane+2) = *(pnext+ 4); *(YPlane+3) = *(pnext+ 6);
  4391. *(YPlane+4) = *(pnext+ 8); *(YPlane+5) = *(pnext+10);
  4392. *(YPlane+6) = *(pnext+12); *(YPlane+7) = *(pnext+14);
  4393. }
  4394. }
  4395. pnext += iBackTwoLines;
  4396. YPlane += ypitch_adj;
  4397. if (0 == (k & 1)) {
  4398. UPlane += uvpitch_adj;
  4399. VPlane += uvpitch_adj;
  4400. }
  4401. }
  4402. if (stretch) {
  4403. plast = pnext - (lpbiInput->biWidth << 1);
  4404. pbn = pnext;
  4405. for ( peol = pbn + (FrameWidth << 1); pbn < peol; YPlane += 4,
  4406. plast += 8,
  4407. pbn += 8) {
  4408. *(YPlane+0) = ((*(plast+0) >> 1) + (*(pbn+0) >> 1));
  4409. *(YPlane+1) = ((*(plast+2) >> 1) + (*(pbn+2) >> 1));
  4410. *(YPlane+2) = ((*(plast+4) >> 1) + (*(pbn+4) >> 1));
  4411. *(YPlane+3) = ((*(plast+6) >> 1) + (*(pbn+6) >> 1));
  4412. }
  4413. YPlane += ypitch_adj;
  4414. }
  4415. }
  4416. }
  4417. #endif
  4418. #if 0
  4419. void C_H26X_YUY2toYUV12(
  4420. LPBITMAPINFOHEADER lpbiInput,
  4421. U8 *lpInput,
  4422. U8 *YPlane,
  4423. U8 *UPlane,
  4424. U8 *VPlane,
  4425. UN FrameWidth,
  4426. UN FrameHeight,
  4427. const int pitch) {
  4428. U8 *pnext, *plast, *pbn, *peol;
  4429. int width_adj, height_adj;
  4430. int stretch, mark, aspect;
  4431. int iBackTwoLines;
  4432. int j, k;
  4433. int LumaIters = 0;
  4434. int ypitch_adj = pitch - FrameWidth;
  4435. int uvpitch_adj = pitch - (FrameWidth >> 1);
  4436. int nextline = -(lpbiInput->biWidth << 1);
  4437. for (j = FrameHeight; j > 0; j -= 48) {
  4438. LumaIters += 4;
  4439. }
  4440. width_adj = lpbiInput->biWidth - FrameWidth;
  4441. aspect = (width_adj ? LumaIters : 0);
  4442. height_adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1;
  4443. stretch = (height_adj ? 1 : 0);
  4444. mark = 12 - stretch;
  4445. // Move from end of line N to beginning of line N-1
  4446. iBackTwoLines = -((lpbiInput->biWidth + (int)FrameWidth) << 1);
  4447. // Point to the beginning of the last line.
  4448. pnext = lpInput + ((lpbiInput->biWidth << 1) * ((FrameHeight - aspect - 1) + height_adj))
  4449. + width_adj;
  4450. for (j = LumaIters; j > 0; j--) {
  4451. for (k = 0; k < mark; k++) {
  4452. for ( peol = pnext + (FrameWidth << 1); pnext < peol; pnext += 16, YPlane += 8) {
  4453. if (0 == (k & 1)) {
  4454. *(YPlane+0) = *(pnext+ 0) >> 1; *(YPlane+1) = *(pnext+ 2) >> 1;
  4455. *(YPlane+2) = *(pnext+ 4) >> 1; *(YPlane+3) = *(pnext+ 6) >> 1;
  4456. *(YPlane+4) = *(pnext+ 8) >> 1; *(YPlane+5) = *(pnext+10) >> 1;
  4457. *(YPlane+6) = *(pnext+12) >> 1; *(YPlane+7) = *(pnext+14) >> 1;
  4458. *(UPlane+0) = ((*(pnext+ 1)>>1) + (*(pnext+ 1+nextline)>>1)) >> 1;
  4459. *(UPlane+1) = ((*(pnext+ 5)>>1) + (*(pnext+ 5+nextline)>>1)) >> 1;
  4460. *(UPlane+2) = ((*(pnext+ 9)>>1) + (*(pnext+ 9+nextline)>>1)) >> 1;
  4461. *(UPlane+3) = ((*(pnext+13)>>1) + (*(pnext+13+nextline)>>1)) >> 1;
  4462. *(VPlane+0) = ((*(pnext+ 3)>>1) + (*(pnext+ 3+nextline)>>1)) >> 1;
  4463. *(VPlane+1) = ((*(pnext+ 7)>>1) + (*(pnext+ 7+nextline)>>1)) >> 1;
  4464. *(VPlane+2) = ((*(pnext+11)>>1) + (*(pnext+11+nextline)>>1)) >> 1;
  4465. *(VPlane+3) = ((*(pnext+15)>>1) + (*(pnext+15+nextline)>>1)) >> 1;
  4466. UPlane += 4; VPlane += 4;
  4467. } else {
  4468. *(YPlane+0) = *(pnext+ 0) >> 1; *(YPlane+1) = *(pnext+ 2) >> 1;
  4469. *(YPlane+2) = *(pnext+ 4) >> 1; *(YPlane+3) = *(pnext+ 6) >> 1;
  4470. *(YPlane+4) = *(pnext+ 8) >> 1; *(YPlane+5) = *(pnext+10) >> 1;
  4471. *(YPlane+6) = *(pnext+12) >> 1; *(YPlane+7) = *(pnext+14) >> 1;
  4472. }
  4473. }
  4474. pnext += iBackTwoLines;
  4475. YPlane += ypitch_adj;
  4476. if (0 == (k & 1)) {
  4477. UPlane += uvpitch_adj;
  4478. VPlane += uvpitch_adj;
  4479. }
  4480. }
  4481. if (stretch) {
  4482. plast = pnext - (lpbiInput->biWidth << 1);
  4483. pbn = pnext;
  4484. for ( peol = pbn + (FrameWidth << 1); pbn < peol; YPlane += 4,
  4485. plast += 8,
  4486. pbn += 8) {
  4487. *(YPlane+0) = ((*(plast+0) >> 1) + (*(pbn+0) >> 1)) >> 1;
  4488. *(YPlane+1) = ((*(plast+2) >> 1) + (*(pbn+2) >> 1)) >> 1;
  4489. *(YPlane+2) = ((*(plast+4) >> 1) + (*(pbn+4) >> 1)) >> 1;
  4490. *(YPlane+3) = ((*(plast+6) >> 1) + (*(pbn+6) >> 1)) >> 1;
  4491. }
  4492. YPlane += ypitch_adj;
  4493. }
  4494. }
  4495. }
  4496. #endif
  4497. __declspec(naked)
  4498. _STATIC void IA_H26X_YUY2toYUV12(
  4499. LPBITMAPINFOHEADER lpbiInput,
  4500. U8 * BGR24Image,
  4501. U8 * YPlane,
  4502. U8 * UPlane,
  4503. U8 * VPlane,
  4504. UN FrameWidth,
  4505. UN FrameHeight,
  4506. const int pitch)
  4507. {
  4508. // Permanent (callee-save) registers - ebx, esi, edi, ebp
  4509. // Temporary (caller-save) registers - eax, ecx, edx
  4510. //
  4511. // Stack frame layout
  4512. // | pitch | + 96
  4513. // | FrameHeight | + 92
  4514. // | FrameWidth | + 88
  4515. // | VPlane | + 84
  4516. // | UPlane | + 80
  4517. // | YPlane | + 76
  4518. // | lpInput | + 72
  4519. // | lpbiInput | + 68
  4520. // ----------------------------
  4521. // | return addr | + 64
  4522. // | saved ebp | + 60
  4523. // | saved ebx | + 56
  4524. // | saved esi | + 52
  4525. // | saved edi | + 48
  4526. // | pyprev | + 44
  4527. // | pyspace | + 40
  4528. // | pynext | + 36
  4529. // | peol | + 32
  4530. // | j | + 28
  4531. // | k | + 24
  4532. // | iBackTwoLines | + 20
  4533. // | stretch | + 16
  4534. // | mark | + 12
  4535. // | LumaIters | + 8
  4536. // | ypitch_adj | + 4
  4537. // | uvpitch_adj | + 0
  4538. #define LOCALSIZE 48
  4539. #define PITCH_PARM 96
  4540. #define FRAME_HEIGHT 92
  4541. #define FRAME_WIDTH 88
  4542. #define VPLANE 84
  4543. #define UPLANE 80
  4544. #define YPLANE 76
  4545. #define LP_INPUT 72
  4546. #define LPBI_INPUT 68
  4547. #define PYPREV 44
  4548. #define PYSPACE 40
  4549. #define PYNEXT 36
  4550. #define PEOL 32
  4551. #define LOOP_J 28
  4552. #define LOOP_K 24
  4553. #define BACK_TWO_LINES 20
  4554. #define STRETCH 16
  4555. #define MARK 12
  4556. #define LUMA_ITERS 8
  4557. #define YPITCH_ADJ 4
  4558. #define UVPITCH_ADJ 0
  4559. _asm {
  4560. push ebp
  4561. push ebx
  4562. push esi
  4563. push edi
  4564. sub esp, LOCALSIZE
  4565. // assign (ebx, lpbiInput)
  4566. mov ebx, [esp + LPBI_INPUT]
  4567. // ypitch_adj = pitch - FrameWidth
  4568. // assign (ecx, FrameWidth)
  4569. // assign (edx, pitch)
  4570. mov ecx, [esp + FRAME_WIDTH]
  4571. mov edx, [esp + PITCH_PARM]
  4572. mov eax, edx
  4573. sub eax, ecx
  4574. mov [esp + YPITCH_ADJ], eax
  4575. // uvpitch_adj = pitch - (FrameWidth >> 1)
  4576. // kill (edx, pitch)
  4577. mov ebp, ecx
  4578. shr ebp, 1
  4579. sub edx, ebp
  4580. mov [esp + UVPITCH_ADJ], edx
  4581. // for (i = FrameHeight; i > 0; i -= 48) LumaIters += 4
  4582. // assign (edx, LumaIters)
  4583. xor edx, edx
  4584. mov eax, [esp + FRAME_HEIGHT]
  4585. L1:
  4586. lea edx, [edx + 4]
  4587. sub eax, 48
  4588. jnz L1
  4589. // width_adj = lpbiInput->biWidth - FrameWidth;
  4590. // assign (esi, width_adj)
  4591. mov esi, (LPBITMAPINFOHEADER)[ebx].biWidth
  4592. sub esi, [esp + FRAME_WIDTH]
  4593. // aspect = (width_adj ? LumaIters : 0)
  4594. // assign (edi, aspect)
  4595. // kill (edx, LumaIters)
  4596. mov [esp + LUMA_ITERS], edx
  4597. xor edi, edi
  4598. test esi, esi
  4599. jz L2
  4600. mov edi, edx
  4601. // height _adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1
  4602. // assign (edx, height_adj)
  4603. L2:
  4604. mov edx, (LPBITMAPINFOHEADER)[ebx].biHeight
  4605. sub edx, [esp + FRAME_HEIGHT]
  4606. add edx, edi
  4607. shr edx, 1
  4608. // stretch = (height_adj ? 1 : 0)
  4609. xor eax, eax
  4610. test edx, edx
  4611. jz L3
  4612. inc eax
  4613. L3:
  4614. mov [esp + STRETCH], eax
  4615. // mark = 12 - stretch
  4616. mov ebp, 12
  4617. sub ebp, eax
  4618. mov [esp + MARK], ebp
  4619. // iBackTwoLines = -((lpbiInput->biWidth + FrameWidth) << 1)
  4620. mov ebp, (LPBITMAPINFOHEADER)[ebx].biWidth
  4621. add ebp, [esp + FRAME_WIDTH]
  4622. shl ebp, 1
  4623. neg ebp
  4624. mov [esp + BACK_TWO_LINES], ebp
  4625. // pnext = lpInput +
  4626. // ((lpbiInput->biWidth << 1) *
  4627. // ((FrameHeight - aspect - 1) + height_adj)) +
  4628. // width_adj
  4629. // kill (ebx, lpbiInput)
  4630. // kill (ecx, FrameWidth)
  4631. // kill (edx, height_adj)
  4632. // kill (esi, width_adj)
  4633. // kill (edi, aspect)
  4634. // assign (esi, pnext)
  4635. mov eax, (LPBITMAPINFOHEADER)[ebx].biWidth
  4636. shl eax, 1
  4637. mov ebx, [esp + FRAME_HEIGHT]
  4638. sub ebx, edi
  4639. dec ebx
  4640. add ebx, edx
  4641. imul ebx
  4642. add esi, eax
  4643. add esi, [esp + LP_INPUT]
  4644. // assign (edi, YPlane)
  4645. // assign (edx, UPlane)
  4646. // assign (ebp, VPlane)
  4647. mov edi, [esp + YPLANE]
  4648. mov edx, [esp + UPLANE]
  4649. mov ebp, [esp + VPLANE]
  4650. // for (j = 0; j < LumaIters; j++)
  4651. xor eax, eax
  4652. mov [esp + LOOP_J], eax
  4653. L4:
  4654. // for (k = 0; k < mark; k++)
  4655. xor eax, eax
  4656. mov [esp + LOOP_K], eax
  4657. L5:
  4658. // for ( peol = pnext + (FrameWidth << 1); pnext < peol; pnext += 16, YPlane += 8)
  4659. mov ecx, [esp + FRAME_WIDTH]
  4660. shl ecx, 1
  4661. add ecx, esi
  4662. mov [esp + PEOL], ecx
  4663. // if (0 == (k & 1)) {
  4664. mov eax, [esp + LOOP_K]
  4665. test eax, 1
  4666. jnz L6
  4667. // *(YPlane+0) = *(pnext+ 0) >> 1; *(YPlane+1) = *(pnext+ 2) >> 1
  4668. // *(YPlane+2) = *(pnext+ 4) >> 1; *(YPlane+3) = *(pnext+ 6) >> 1
  4669. // *(YPlane+4) = *(pnext+ 8) >> 1; *(YPlane+5) = *(pnext+10) >> 1
  4670. // *(YPlane+6) = *(pnext+12) >> 1; *(YPlane+7) = *(pnext+14) >> 1
  4671. // *(UPlane+0) = *(pnext+ 1) >> 1; *(UPlane+1) = *(pnext+ 5) >> 1
  4672. // *(UPlane+2) = *(pnext+ 9) >> 1; *(UPlane+3) = *(pnext+13) >> 1
  4673. // *(VPlane+0) = *(pnext+ 3) >> 1; *(VPlane+1) = *(pnext+ 7) >> 1
  4674. // *(VPlane+2) = *(pnext+11) >> 1; *(VPlane+3) = *(pnext+15) >> 1
  4675. // or graphically
  4676. // *************************************************************************************************
  4677. // Values * Y 0 * U 0 * Y 1 * V 0 * Y 2 * U 1 * Y 3 * V 1 * Y 4 * U 2 * Y 5 * V 2 * Y 6 * U 3 * Y 7 * V 3 *
  4678. // *************************************************************************************************
  4679. // Y Offsets 0 2 4 6 8 10 12 14
  4680. // U Offsets 1 5 9 13
  4681. // Y Offsets 3 7 11 15
  4682. // Register usage:
  4683. // eax - accumulate Y values
  4684. // ebx - accumulate U values
  4685. // ecx - accumulate V values
  4686. // esi - ptr to interlaced (VYUY) input
  4687. // edi - ptr for writing Y values
  4688. // edx - ptr for writing U values
  4689. // ebp - ptr for writing V values
  4690. L7:
  4691. ; 1
  4692. mov al, [esi+4] ; Y2
  4693. mov bl, [esi+9] ; U2
  4694. ; 2
  4695. mov ah, [esi+6] ; Y3
  4696. mov bh, [esi+13] ; U3
  4697. ; 3
  4698. shl eax, 16
  4699. mov cl, [esi+11] ; V2
  4700. ; 4
  4701. shl ebx, 16
  4702. mov ch, [esi+15] ; V3
  4703. ; 5
  4704. shl ecx, 16
  4705. mov al, [esi] ; Y0
  4706. ; 6
  4707. mov bh, [esi+5] ; U1
  4708. mov ah, [esi+2] ; Y1
  4709. ; 7
  4710. shr eax, 1
  4711. mov bl, [esi+1] ; U0
  4712. ; 8
  4713. shr ebx, 1
  4714. mov ch, [esi+7] ; V1
  4715. ; 9
  4716. and eax, 07F7F7F7FH
  4717. mov cl, [esi+3] ; V0
  4718. ; 10
  4719. shr ecx, 1
  4720. and ebx, 07F7F7F7FH
  4721. ; 11
  4722. mov [edi], eax
  4723. and ecx, 07F7F7F7FH
  4724. ; 12
  4725. mov al, [esi+12] ; Y6
  4726. mov [edx], ebx
  4727. ; 13
  4728. mov ah, [esi+14] ; Y7
  4729. mov [ebp], ecx
  4730. ; 14
  4731. shl eax, 16
  4732. mov ecx, [esp + PEOL]
  4733. ; 15
  4734. mov al, [esi+8] ; Y4
  4735. lea edi, [edi+8]
  4736. ; 16
  4737. mov ah, [esi+10] ; Y5
  4738. lea edx, [edx+4]
  4739. ; 17
  4740. shr eax, 1
  4741. lea ebp, [ebp+4]
  4742. ; 18
  4743. and eax, 07F7F7F7FH
  4744. lea esi, [esi+16]
  4745. ; 19
  4746. mov [edi-4], eax
  4747. cmp esi, ecx
  4748. ; 20
  4749. jl L7
  4750. jmp L8
  4751. // } else {
  4752. // *(YPlane+0) = *(pnext+ 0) >> 1; *(YPlane+1) = *(pnext+ 2) >> 1
  4753. // *(YPlane+2) = *(pnext+ 4) >> 1; *(YPlane+3) = *(pnext+ 6) >> 1
  4754. // *(YPlane+4) = *(pnext+ 8) >> 1; *(YPlane+5) = *(pnext+10) >> 1
  4755. // *(YPlane+6) = *(pnext+12) >> 1; *(YPlane+7) = *(pnext+14) >> 1
  4756. // }
  4757. // Register usage:
  4758. // eax, ebx - accumulate Y values
  4759. // ecx - peol
  4760. // esi - ptr to interlaced (VYUY) input
  4761. // edi - ptr for writing Y values
  4762. L6:
  4763. ; 1
  4764. mov al, [esi+4] ; Y2
  4765. mov bl, [esi+12] ; Y6
  4766. ; 2
  4767. mov ah, [esi+6] ; Y3
  4768. mov bh, [esi+14] ; Y7
  4769. ; 3
  4770. shl eax, 16
  4771. lea edi, [edi+8]
  4772. ; 4
  4773. shl ebx, 16
  4774. mov al, [esi] ; Y0
  4775. ; 5
  4776. mov ah, [esi+2] ; Y1
  4777. mov bh, [esi+10] ; Y5
  4778. ; 6
  4779. shr eax, 1
  4780. mov bl, [esi+8] ; Y4
  4781. ; 7
  4782. shr ebx, 1
  4783. and eax, 07F7F7F7FH
  4784. ; 8
  4785. mov [edi-8], eax
  4786. and ebx, 07F7F7F7FH
  4787. ; 9
  4788. mov [edi-8+4], ebx
  4789. lea esi, [esi+16]
  4790. ; 10
  4791. cmp esi, ecx
  4792. jl L6
  4793. L8:
  4794. // pnext += iBackTwoLines
  4795. add esi, [esp + BACK_TWO_LINES]
  4796. // YPlane += ypitch_adj
  4797. add edi, [esp + YPITCH_ADJ]
  4798. // if (0 == (k&1))
  4799. mov eax, [esp + LOOP_K]
  4800. test eax, 1
  4801. jnz L9
  4802. // UPlane += uvpitch_adj
  4803. add edx, [esp + UVPITCH_ADJ]
  4804. // VPlane += uvpitch_adj
  4805. add ebp, [esp + UVPITCH_ADJ]
  4806. L9:
  4807. mov eax, [esp + LOOP_K]
  4808. inc eax
  4809. mov [esp + LOOP_K], eax
  4810. cmp eax, [esp + MARK]
  4811. jl L5
  4812. // if (stretch)
  4813. mov eax, [esp + STRETCH]
  4814. test eax, eax
  4815. jz L10
  4816. // Save ptrs to UPlane and VPlane, use edx and ebp to do the stretch average.
  4817. mov [esp + UPLANE], edx
  4818. mov [esp + VPLANE], ebp
  4819. // plast = pnext - (lpbiInput->biWidth << 1)
  4820. // assign (plast, edx)
  4821. mov edx, esi
  4822. mov eax, [esp + LPBI_INPUT]
  4823. mov eax, (LPBITMAPINFOHEADER)[eax].biWidth
  4824. shl eax, 1
  4825. sub edx, eax
  4826. // pbn = pnext
  4827. // assign (pbn, ebp)
  4828. mov ebp, esi
  4829. // for ( peol = pbn + (FrameWidth << 1); pbn < peol; YPlane += 4, plast += 8, pbn += 8)
  4830. mov ecx, [esp + FRAME_WIDTH]
  4831. shl ecx, 1
  4832. add ecx, ebp
  4833. // *(YPlane+0) = ((*(plast+0) >> 1) + (*(pbn+0) >> 1)) >> 1
  4834. // *(YPlane+1) = ((*(plast+2) >> 1) + (*(pbn+2) >> 1)) >> 1
  4835. // *(YPlane+2) = ((*(plast+4) >> 1) + (*(pbn+4) >> 1)) >> 1
  4836. // *(YPlane+3) = ((*(plast+6) >> 1) + (*(pbn+6) >> 1)) >> 1
  4837. mov al, [edx+4]
  4838. mov bl, [ebp+4]
  4839. mov bh, [ebp+6]
  4840. shl ebx, 16
  4841. L11:
  4842. ; 1
  4843. mov ah, [edx+6]
  4844. mov bl, [ebp]
  4845. ; 2
  4846. shl eax, 16
  4847. mov bh, [ebp+2]
  4848. ; 3
  4849. mov al, [edx]
  4850. lea edi, [edi+4]
  4851. ; 4
  4852. mov ah, [edx+2]
  4853. lea edx, [edx+8]
  4854. ; 5
  4855. and eax, 0xFEFEFEFE
  4856. lea ebp, [ebp+8]
  4857. ; 6
  4858. shr eax, 1
  4859. and ebx, 0xFEFEFEFE
  4860. ; 7
  4861. shr ebx, 1
  4862. nop
  4863. ; 8
  4864. add eax, ebx
  4865. mov bl, [ebp+4]
  4866. ; 9
  4867. shr eax, 1
  4868. mov bh, [ebp+6]
  4869. ; 10
  4870. shl ebx, 16
  4871. and eax, 0x7F7F7F7F
  4872. ; 11
  4873. mov [edi-4], eax
  4874. mov al, [edx+4]
  4875. ; 12
  4876. cmp ebp, ecx
  4877. jl L11
  4878. // YPlane += ypitch_adj;
  4879. add edi, [esp + YPITCH_ADJ]
  4880. // Recover pts to UPlane and VPlane
  4881. mov edx, [esp + UPLANE]
  4882. mov ebp, [esp + VPLANE]
  4883. L10:
  4884. mov eax, [esp + LOOP_J]
  4885. inc eax
  4886. mov [esp + LOOP_J], eax
  4887. cmp eax, [esp + LUMA_ITERS]
  4888. jl L4
  4889. add esp, LOCALSIZE
  4890. pop edi
  4891. pop esi
  4892. pop ebx
  4893. pop ebp
  4894. ret
  4895. }
  4896. }
  4897. bool UYVY_to_YUV12_Flip(
  4898. LPBITMAPINFOHEADER lpbiInput,
  4899. U8 * pImage,
  4900. U8 * YPlane,
  4901. U8 * UPlane,
  4902. U8 * VPlane,
  4903. UN FrameWidth,
  4904. UN FrameHeight,
  4905. const int pitch)
  4906. {
  4907. DWORD dwFrameWidthHalf, dwFrameHeightHalf;
  4908. BYTE *pRowStartY, *pRowStartSrc, *pRowStartU, *pRowStartV;
  4909. int offset;
  4910. int nRowsToSkip=0, nColsToSkip=0, nRowSkipDelta=0xffffff, nColSkipDelta=0xffffff;
  4911. int nSrcRowIndex, nDstRowIndex, nSrcColIndex, nDstColIndex, COLUMNSTOSKIP=0, ROWSTOSKIP=0;
  4912. if ((FrameWidth != (DWORD)(lpbiInput->biWidth)) || (FrameHeight != (DWORD)(lpbiInput->biHeight)))
  4913. {
  4914. nColsToSkip = COLUMNSTOSKIP = lpbiInput->biWidth - FrameWidth;
  4915. nRowsToSkip = ROWSTOSKIP = lpbiInput->biHeight - FrameHeight;
  4916. if ((nColsToSkip < 0) || (nRowsToSkip < 0))
  4917. {
  4918. return false;
  4919. }
  4920. // nXXXSkipDelta dictate how often we "skip" a row or col
  4921. if (nRowsToSkip)
  4922. {
  4923. nRowSkipDelta = (lpbiInput->biHeight + (nRowsToSkip - 1)) / nRowsToSkip;
  4924. }
  4925. if (nColsToSkip)
  4926. {
  4927. nColSkipDelta = (lpbiInput->biWidth + (nColsToSkip - 1)) / nColsToSkip;
  4928. }
  4929. }
  4930. // quick check to make sure we're processing CIF, QCIF, or SQCIF
  4931. if ((FrameWidth % 4) || (FrameHeight % 4))
  4932. {
  4933. return false;
  4934. }
  4935. dwFrameWidthHalf = FrameWidth / 2;
  4936. dwFrameHeightHalf = FrameHeight / 2;
  4937. nSrcRowIndex = 0;
  4938. nDstRowIndex = 0;
  4939. // step 1, convert the Y values over
  4940. while ((DWORD)nDstRowIndex < FrameHeight)
  4941. {
  4942. // ASSERT(nSrcRowIndex < lpbiInput->biHeight);
  4943. pRowStartY = YPlane + (pitch * nDstRowIndex);
  4944. pRowStartSrc = pImage + (lpbiInput->biWidth * nSrcRowIndex * 2) + 1;
  4945. // do we need to skip this row ?
  4946. if ((nRowsToSkip > 0) && ((nSrcRowIndex % nRowSkipDelta) == 0))
  4947. {
  4948. nRowsToSkip--;
  4949. nSrcRowIndex++;
  4950. continue;
  4951. }
  4952. // Copy the Y values of the input row into the destination row
  4953. nSrcColIndex = 0;
  4954. nDstColIndex = 0;
  4955. nColsToSkip = COLUMNSTOSKIP;
  4956. while ((DWORD)nDstColIndex < FrameWidth)
  4957. {
  4958. // ASSERT(nSrcColIndex < lpbiInput->biWidth);
  4959. // do we need to skip this column ?
  4960. if ((nColsToSkip > 0) && ((nSrcColIndex % nColSkipDelta) == 0))
  4961. {
  4962. nColsToSkip--;
  4963. nSrcColIndex++;
  4964. continue;
  4965. }
  4966. pRowStartY[nDstColIndex] = pRowStartSrc[nSrcColIndex * 2] >> 1;
  4967. nSrcColIndex++;
  4968. nDstColIndex++;
  4969. }
  4970. nSrcRowIndex++;
  4971. nDstRowIndex++;
  4972. }
  4973. nSrcRowIndex = 0;
  4974. nDstRowIndex = 0;
  4975. nRowsToSkip = ROWSTOSKIP;
  4976. // step 2, process U and V values
  4977. while ((DWORD)nDstRowIndex < dwFrameHeightHalf) // dest is only half as many rows as src
  4978. {
  4979. // ASSERT(nSrcRowIndex < lpbiInput->biHeight);
  4980. // don't process odd numbered rows
  4981. if (nSrcRowIndex % 2)
  4982. {
  4983. // if we were supposed to skip this src row anyway, make sure
  4984. // we update our decrement
  4985. if ((nRowsToSkip > 0) && ((nSrcRowIndex % nRowSkipDelta) == 0))
  4986. {
  4987. nRowsToSkip--;
  4988. }
  4989. nSrcRowIndex++;
  4990. continue;
  4991. }
  4992. // do we need to skip this row ?
  4993. if ((nRowsToSkip > 0) && ((nSrcRowIndex % nRowSkipDelta) == 0))
  4994. {
  4995. nRowsToSkip--;
  4996. nSrcRowIndex++;
  4997. continue;
  4998. }
  4999. pRowStartU = UPlane + (pitch * nDstRowIndex);
  5000. pRowStartV = VPlane + (pitch * nDstRowIndex);
  5001. pRowStartSrc = pImage + (lpbiInput->biWidth * nSrcRowIndex * 2) + 0;
  5002. // Copy the U and V values of the input row into the destination row
  5003. nSrcColIndex = 0;
  5004. nDstColIndex = 0;
  5005. nColsToSkip = COLUMNSTOSKIP; // reset column skip count
  5006. while ((DWORD)nDstColIndex < dwFrameWidthHalf)
  5007. {
  5008. // ASSERT(nSrcColIndex < lpbiInput->biWidth);
  5009. // skip odd numbered columns
  5010. if (nSrcColIndex % 2)
  5011. {
  5012. // if we were supposed to skip this src row anyway, make sure
  5013. // we update our decrement
  5014. if ((nColsToSkip > 0) && ((nSrcColIndex % nColSkipDelta) == 0))
  5015. {
  5016. nColsToSkip--;
  5017. }
  5018. nSrcColIndex++;
  5019. continue;
  5020. }
  5021. // do we need to skip this column ?
  5022. if ((nColsToSkip > 0) && ((nSrcColIndex % nColSkipDelta) == 0))
  5023. {
  5024. nSrcColIndex++;
  5025. nColsToSkip--;
  5026. continue;
  5027. }
  5028. offset = nSrcColIndex * 2;
  5029. pRowStartU[nDstColIndex] = pRowStartSrc[offset] >> 1;
  5030. pRowStartV[nDstColIndex] = pRowStartSrc[offset+2] >> 1;
  5031. nSrcColIndex++;
  5032. nDstColIndex++;
  5033. }
  5034. nSrcRowIndex++;
  5035. nDstRowIndex++;
  5036. }
  5037. // and we are done!
  5038. return true;
  5039. }
  5040. __declspec(naked)
  5041. _STATIC void IA_H26X_UYVYtoYUV12(
  5042. LPBITMAPINFOHEADER lpbiInput,
  5043. U8 * BGR24Image,
  5044. U8 * YPlane,
  5045. U8 * UPlane,
  5046. U8 * VPlane,
  5047. UN FrameWidth,
  5048. UN FrameHeight,
  5049. const int pitch)
  5050. {
  5051. // Permanent (callee-save) registers - ebx, esi, edi, ebp
  5052. // Temporary (caller-save) registers - eax, ecx, edx
  5053. //
  5054. // Stack frame layout
  5055. // | pitch | + 96
  5056. // | FrameHeight | + 92
  5057. // | FrameWidth | + 88
  5058. // | VPlane | + 84
  5059. // | UPlane | + 80
  5060. // | YPlane | + 76
  5061. // | lpInput | + 72
  5062. // | lpbiInput | + 68
  5063. // ----------------------------
  5064. // | return addr | + 64
  5065. // | saved ebp | + 60
  5066. // | saved ebx | + 56
  5067. // | saved esi | + 52
  5068. // | saved edi | + 48
  5069. // | pyprev | + 44
  5070. // | pyspace | + 40
  5071. // | pynext | + 36
  5072. // | peol | + 32
  5073. // | j | + 28
  5074. // | k | + 24
  5075. // | iBackTwoLines | + 20
  5076. // | stretch | + 16
  5077. // | mark | + 12
  5078. // | LumaIters | + 8
  5079. // | ypitch_adj | + 4
  5080. // | uvpitch_adj | + 0
  5081. _asm {
  5082. push ebp
  5083. push ebx
  5084. push esi
  5085. push edi
  5086. sub esp, LOCALSIZE
  5087. // assign (ebx, lpbiInput)
  5088. mov ebx, [esp + LPBI_INPUT]
  5089. // ypitch_adj = pitch - FrameWidth
  5090. // assign (ecx, FrameWidth)
  5091. // assign (edx, pitch)
  5092. mov ecx, [esp + FRAME_WIDTH]
  5093. mov edx, [esp + PITCH_PARM]
  5094. mov eax, edx
  5095. sub eax, ecx
  5096. mov [esp + YPITCH_ADJ], eax
  5097. // uvpitch_adj = pitch - (FrameWidth >> 1)
  5098. // kill (edx, pitch)
  5099. mov ebp, ecx
  5100. shr ebp, 1
  5101. sub edx, ebp
  5102. mov [esp + UVPITCH_ADJ], edx
  5103. // for (i = FrameHeight; i > 0; i -= 48) LumaIters += 4
  5104. // assign (edx, LumaIters)
  5105. xor edx, edx
  5106. mov eax, [esp + FRAME_HEIGHT]
  5107. L1:
  5108. lea edx, [edx + 4]
  5109. sub eax, 48
  5110. jnz L1
  5111. // width_adj = lpbiInput->biWidth - FrameWidth;
  5112. // assign (esi, width_adj)
  5113. mov esi, (LPBITMAPINFOHEADER)[ebx].biWidth
  5114. sub esi, [esp + FRAME_WIDTH]
  5115. // aspect = (width_adj ? LumaIters : 0)
  5116. // assign (edi, aspect)
  5117. // kill (edx, LumaIters)
  5118. mov [esp + LUMA_ITERS], edx
  5119. xor edi, edi
  5120. test esi, esi
  5121. jz L2
  5122. mov edi, edx
  5123. // height _adj = (lpbiInput->biHeight - (FrameHeight - aspect)) >> 1
  5124. // assign (edx, height_adj)
  5125. L2:
  5126. mov edx, (LPBITMAPINFOHEADER)[ebx].biHeight
  5127. sub edx, [esp + FRAME_HEIGHT]
  5128. add edx, edi
  5129. shr edx, 1
  5130. // stretch = (height_adj ? 1 : 0)
  5131. xor eax, eax
  5132. test edx, edx
  5133. jz L3
  5134. inc eax
  5135. L3:
  5136. mov [esp + STRETCH], eax
  5137. // mark = 12 - stretch
  5138. mov ebp, 12
  5139. sub ebp, eax
  5140. mov [esp + MARK], ebp
  5141. // iBackTwoLines = -((lpbiInput->biWidth + FrameWidth) << 1)
  5142. mov ebp, (LPBITMAPINFOHEADER)[ebx].biWidth
  5143. add ebp, [esp + FRAME_WIDTH]
  5144. shl ebp, 1
  5145. neg ebp
  5146. mov [esp + BACK_TWO_LINES], ebp
  5147. // pnext = lpInput +
  5148. // ((lpbiInput->biWidth << 1) *
  5149. // ((FrameHeight - aspect - 1) + height_adj)) +
  5150. // width_adj
  5151. // kill (ebx, lpbiInput)
  5152. // kill (ecx, FrameWidth)
  5153. // kill (edx, height_adj)
  5154. // kill (esi, width_adj)
  5155. // kill (edi, aspect)
  5156. // assign (esi, pnext)
  5157. mov eax, (LPBITMAPINFOHEADER)[ebx].biWidth
  5158. shl eax, 1
  5159. mov ebx, [esp + FRAME_HEIGHT]
  5160. sub ebx, edi
  5161. dec ebx
  5162. add ebx, edx
  5163. imul ebx
  5164. add esi, eax
  5165. add esi, [esp + LP_INPUT]
  5166. // assign (edi, YPlane)
  5167. // assign (edx, UPlane)
  5168. // assign (ebp, VPlane)
  5169. mov edi, [esp + YPLANE]
  5170. mov edx, [esp + UPLANE]
  5171. mov ebp, [esp + VPLANE]
  5172. // for (j = 0; j < LumaIters; j++)
  5173. xor eax, eax
  5174. mov [esp + LOOP_J], eax
  5175. L4:
  5176. // for (k = 0; k < mark; k++)
  5177. xor eax, eax
  5178. mov [esp + LOOP_K], eax
  5179. L5:
  5180. // for ( peol = pnext + (FrameWidth << 1); pnext < peol; pnext += 16, YPlane += 8)
  5181. mov ecx, [esp + FRAME_WIDTH]
  5182. shl ecx, 1
  5183. add ecx, esi
  5184. mov [esp + PEOL], ecx
  5185. // if (0 == (k & 1)) {
  5186. mov eax, [esp + LOOP_K]
  5187. test eax, 1
  5188. jnz L6
  5189. // *(YPlane+0) = *(pnext+ 0) >> 1; *(YPlane+1) = *(pnext+ 2) >> 1
  5190. // *(YPlane+2) = *(pnext+ 4) >> 1; *(YPlane+3) = *(pnext+ 6) >> 1
  5191. // *(YPlane+4) = *(pnext+ 8) >> 1; *(YPlane+5) = *(pnext+10) >> 1
  5192. // *(YPlane+6) = *(pnext+12) >> 1; *(YPlane+7) = *(pnext+14) >> 1
  5193. // *(UPlane+0) = *(pnext+ 1) >> 1; *(UPlane+1) = *(pnext+ 5) >> 1
  5194. // *(UPlane+2) = *(pnext+ 9) >> 1; *(UPlane+3) = *(pnext+13) >> 1
  5195. // *(VPlane+0) = *(pnext+ 3) >> 1; *(VPlane+1) = *(pnext+ 7) >> 1
  5196. // *(VPlane+2) = *(pnext+11) >> 1; *(VPlane+3) = *(pnext+15) >> 1
  5197. // or graphically
  5198. // *************************************************************************************************
  5199. // Values * U 0 * Y 0 * V 0 * Y 1 * U 1 * Y 2 * V 1 * Y 3 * U 2 * Y 4 * V 2 * Y 5 * U 3 * Y 6 * V 3 * Y 7 *
  5200. // *************************************************************************************************
  5201. // Y Offsets 1 3 5 7 9 11 13 15
  5202. // U Offsets 0 4 8 12
  5203. // Y Offsets 2 6 10 14
  5204. // Register usage:
  5205. // eax - accumulate Y values
  5206. // ebx - accumulate U values
  5207. // ecx - accumulate V values
  5208. // esi - ptr to interlaced (VYUY) input
  5209. // edi - ptr for writing Y values
  5210. // edx - ptr for writing U values
  5211. // ebp - ptr for writing V values
  5212. L7:
  5213. ; 1
  5214. mov al, [esi+5] ; Y2
  5215. mov bl, [esi+8] ; U2
  5216. ; 2
  5217. mov ah, [esi+7] ; Y3
  5218. mov bh, [esi+12] ; U3
  5219. ; 3
  5220. shl eax, 16
  5221. mov cl, [esi+10] ; V2
  5222. ; 4
  5223. shl ebx, 16
  5224. mov ch, [esi+14] ; V3
  5225. ; 5
  5226. shl ecx, 16
  5227. mov al, [esi+1] ; Y0
  5228. ; 6
  5229. mov bh, [esi+4] ; U1
  5230. mov ah, [esi+3] ; Y1
  5231. ; 7
  5232. shr eax, 1
  5233. mov bl, [esi] ; U0
  5234. ; 8
  5235. shr ebx, 1
  5236. mov ch, [esi+6] ; V1
  5237. ; 9
  5238. and eax, 07F7F7F7FH
  5239. mov cl, [esi+2] ; V0
  5240. ; 10
  5241. shr ecx, 1
  5242. and ebx, 07F7F7F7FH
  5243. ; 11
  5244. mov [edi], eax
  5245. and ecx, 07F7F7F7FH
  5246. ; 12
  5247. mov al, [esi+13] ; Y6
  5248. mov [edx], ebx
  5249. ; 13
  5250. mov ah, [esi+15] ; Y7
  5251. mov [ebp], ecx
  5252. ; 14
  5253. shl eax, 16
  5254. mov ecx, [esp + PEOL]
  5255. ; 15
  5256. mov al, [esi+9] ; Y4
  5257. lea edi, [edi+8]
  5258. ; 16
  5259. mov ah, [esi+11] ; Y5
  5260. lea edx, [edx+4]
  5261. ; 17
  5262. shr eax, 1
  5263. lea ebp, [ebp+4]
  5264. ; 18
  5265. and eax, 07F7F7F7FH
  5266. lea esi, [esi+16]
  5267. ; 19
  5268. mov [edi-4], eax
  5269. cmp esi, ecx
  5270. ; 20
  5271. jl L7
  5272. jmp L8
  5273. // } else {
  5274. // *(YPlane+0) = *(pnext+ 0) >> 1; *(YPlane+1) = *(pnext+ 2) >> 1
  5275. // *(YPlane+2) = *(pnext+ 4) >> 1; *(YPlane+3) = *(pnext+ 6) >> 1
  5276. // *(YPlane+4) = *(pnext+ 8) >> 1; *(YPlane+5) = *(pnext+10) >> 1
  5277. // *(YPlane+6) = *(pnext+12) >> 1; *(YPlane+7) = *(pnext+14) >> 1
  5278. // }
  5279. // Register usage:
  5280. // eax, ebx - accumulate Y values
  5281. // ecx - peol
  5282. // esi - ptr to interlaced (VYUY) input
  5283. // edi - ptr for writing Y values
  5284. L6:
  5285. ; 1
  5286. mov al, [esi+5] ; Y2
  5287. mov bl, [esi+13] ; Y6
  5288. ; 2
  5289. mov ah, [esi+7] ; Y3
  5290. mov bh, [esi+15] ; Y7
  5291. ; 3
  5292. shl eax, 16
  5293. lea edi, [edi+8]
  5294. ; 4
  5295. shl ebx, 16
  5296. mov al, [esi+1] ; Y0
  5297. ; 5
  5298. mov ah, [esi+3] ; Y1
  5299. mov bh, [esi+11] ; Y5
  5300. ; 6
  5301. shr eax, 1
  5302. mov bl, [esi+9] ; Y4
  5303. ; 7
  5304. shr ebx, 1
  5305. and eax, 07F7F7F7FH
  5306. ; 8
  5307. mov [edi-8], eax
  5308. and ebx, 07F7F7F7FH
  5309. ; 9
  5310. mov [edi-8+4], ebx
  5311. lea esi, [esi+16]
  5312. ; 10
  5313. cmp esi, ecx
  5314. jl L6
  5315. L8:
  5316. // pnext += iBackTwoLines
  5317. add esi, [esp + BACK_TWO_LINES]
  5318. // YPlane += ypitch_adj
  5319. add edi, [esp + YPITCH_ADJ]
  5320. // if (0 == (k&1))
  5321. mov eax, [esp + LOOP_K]
  5322. test eax, 1
  5323. jnz L9
  5324. // UPlane += uvpitch_adj
  5325. add edx, [esp + UVPITCH_ADJ]
  5326. // VPlane += uvpitch_adj
  5327. add ebp, [esp + UVPITCH_ADJ]
  5328. L9:
  5329. mov eax, [esp + LOOP_K]
  5330. inc eax
  5331. mov [esp + LOOP_K], eax
  5332. cmp eax, [esp + MARK]
  5333. jl L5
  5334. // if (stretch)
  5335. mov eax, [esp + STRETCH]
  5336. test eax, eax
  5337. jz L10
  5338. // Save ptrs to UPlane and VPlane, use edx and ebp to do the stretch average.
  5339. mov [esp + UPLANE], edx
  5340. mov [esp + VPLANE], ebp
  5341. // plast = pnext - (lpbiInput->biWidth << 1)
  5342. // assign (plast, edx)
  5343. mov edx, esi
  5344. mov eax, [esp + LPBI_INPUT]
  5345. mov eax, (LPBITMAPINFOHEADER)[eax].biWidth
  5346. shl eax, 1
  5347. sub edx, eax
  5348. // pbn = pnext
  5349. // assign (pbn, ebp)
  5350. mov ebp, esi
  5351. // for ( peol = pbn + (FrameWidth << 1); pbn < peol; YPlane += 4, plast += 8, pbn += 8)
  5352. mov ecx, [esp + FRAME_WIDTH]
  5353. shl ecx, 1
  5354. add ecx, ebp
  5355. // *(YPlane+0) = ((*(plast+0) >> 1) + (*(pbn+0) >> 1)) >> 1
  5356. // *(YPlane+1) = ((*(plast+2) >> 1) + (*(pbn+2) >> 1)) >> 1
  5357. // *(YPlane+2) = ((*(plast+4) >> 1) + (*(pbn+4) >> 1)) >> 1
  5358. // *(YPlane+3) = ((*(plast+6) >> 1) + (*(pbn+6) >> 1)) >> 1
  5359. mov al, [edx+5]
  5360. mov bl, [ebp+5]
  5361. mov bh, [ebp+7]
  5362. shl ebx, 16
  5363. L11:
  5364. ; 1
  5365. mov ah, [edx+7]
  5366. mov bl, [ebp+1]
  5367. ; 2
  5368. shl eax, 16
  5369. mov bh, [ebp+3]
  5370. ; 3
  5371. mov al, [edx+1]
  5372. lea edi, [edi+4]
  5373. ; 4
  5374. mov ah, [edx+3]
  5375. lea edx, [edx+8]
  5376. ; 5
  5377. and eax, 0xFEFEFEFE
  5378. lea ebp, [ebp+8]
  5379. ; 6
  5380. shr eax, 1
  5381. and ebx, 0xFEFEFEFE
  5382. ; 7
  5383. shr ebx, 1
  5384. nop
  5385. ; 8
  5386. add eax, ebx
  5387. mov bl, [ebp+5]
  5388. ; 9
  5389. shr eax, 1
  5390. mov bh, [ebp+7]
  5391. ; 10
  5392. shl ebx, 16
  5393. and eax, 0x7F7F7F7F
  5394. ; 11
  5395. mov [edi-4], eax
  5396. mov al, [edx+5]
  5397. ; 12
  5398. cmp ebp, ecx
  5399. jl L11
  5400. // YPlane += ypitch_adj;
  5401. add edi, [esp + YPITCH_ADJ]
  5402. // Recover pts to UPlane and VPlane
  5403. mov edx, [esp + UPLANE]
  5404. mov ebp, [esp + VPLANE]
  5405. L10:
  5406. mov eax, [esp + LOOP_J]
  5407. inc eax
  5408. mov [esp + LOOP_J], eax
  5409. cmp eax, [esp + LUMA_ITERS]
  5410. jl L4
  5411. add esp, LOCALSIZE
  5412. pop edi
  5413. pop esi
  5414. pop ebx
  5415. pop ebp
  5416. ret
  5417. }
  5418. }
  5419. #undef LOCALSIZE
  5420. #undef PITCH_PARM
  5421. #undef FRAME_HEIGHT
  5422. #undef FRAME_WIDTH
  5423. #undef VPLANE
  5424. #undef UPLANE
  5425. #undef YPLANE
  5426. #undef LP_INPUT
  5427. #undef LPBI_INPUT
  5428. #undef PYPREV
  5429. #undef PYSPACE
  5430. #undef PYNEXT
  5431. #undef PEOL
  5432. #undef LOOP_J
  5433. #undef LOOP_K
  5434. #undef BACK_TWO_LINES
  5435. #undef STRETCH
  5436. #undef MARK
  5437. #undef LUMA_ITERS
  5438. #undef YPITCH_ADJ
  5439. #undef UVPITCH_ADJ
  5440. /*************************************************************
  5441. * Name: colorCnvtFrame
  5442. * Description: Color convert and copy input frame.
  5443. ************************************************************/
  5444. void colorCnvtFrame(
  5445. T_H263EncoderCatalog * EC,
  5446. LPCODINST lpCompInst,
  5447. ICCOMPRESS * lpicComp,
  5448. U8 * YPlane,
  5449. U8 * UPlane,
  5450. U8 * VPlane
  5451. )
  5452. {
  5453. U8 *RGBCursor = (U8 *) lpicComp->lpInput;
  5454. LPBITMAPINFOHEADER lpbiInput = lpicComp->lpbiInput;
  5455. bool bRet;
  5456. FX_ENTRY("colorCnvtFrame")
  5457. /* The Connectix Quick Cam requires RGB to YUV12 conversion.
  5458. * The B/W camera generates palette versions (8 and 4 bit).
  5459. * The color camera generates RGB24 for million colors and
  5460. * RGB16555 for thousands colors.
  5461. */
  5462. if (BI_RGB == lpicComp->lpbiInput->biCompression)
  5463. {
  5464. if (24 == lpicComp->lpbiInput->biBitCount) {
  5465. #if 0
  5466. if ((128 == lpbiInput->biWidth) && (96 == lpbiInput->biHeight)) {
  5467. U8 YTest[12288];
  5468. U8 UTest[6144];
  5469. U8 VTest[6144];
  5470. int i, j, k;
  5471. U8 R,G,B;
  5472. C_H26X_BGR24toYUV12(lpbiInput, RGBCursor, YTest, UTest, VTest,
  5473. EC->FrameWidth, EC->FrameHeight, 128);
  5474. for (i = 0; i < 96; i++) {
  5475. for (j = 0; j < 128; j++) {
  5476. k = (i*128)+j;
  5477. if (1 < abs(YPlane[(i*384)+j]-YTest[(i*128)+j])) {
  5478. B = RGBCursor[(((95-i)*128)+j)*3];
  5479. G = RGBCursor[(((95-i)*128)+j)*3+1];
  5480. R = RGBCursor[(((95-i)*128)+j)*3+2];
  5481. }
  5482. if ((0 == (i%2)) && (0 == (j%2))) {
  5483. k = ((i>>1)*128)+(j>>1);
  5484. if (1 < abs(UPlane[((i>>1)*384)+(j>>1)]-UTest[((i>>1)*128)+(j>>1)])) {
  5485. B = RGBCursor[(((95-i)*128)+j)*3];
  5486. G = RGBCursor[(((95-i)*128)+j)*3+1];
  5487. R = RGBCursor[(((95-i)*128)+j)*3+2];
  5488. }
  5489. if (1 < abs(VPlane[((i>>1)*384)+(j>>1)] != VTest[((i>>1)*128)+(j>>1)])) {
  5490. B = RGBCursor[(((95-i)*128)+j)*3];
  5491. G = RGBCursor[(((95-i)*128)+j)*3+1];
  5492. R = RGBCursor[(((95-i)*128)+j)*3+2];
  5493. }
  5494. }
  5495. }
  5496. }
  5497. }
  5498. #endif
  5499. #if defined(_CODEC_STATS)
  5500. if (pEncoderStats) {
  5501. pEncoderStats->color_convertor_time = PENTIUM_TIMER();
  5502. }
  5503. #endif
  5504. #if 0
  5505. C_H26X_BGR24toYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5506. EC->FrameWidth, EC->FrameHeight, PITCH);
  5507. #else
  5508. IA_H26X_BGR24toYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5509. EC->FrameWidth, EC->FrameHeight, PITCH);
  5510. #endif
  5511. #if defined(_CODEC_STATS)
  5512. if (pEncoderStats) {
  5513. pEncoderStats->color_convertor_time =
  5514. PENTIUM_TIMER() - pEncoderStats->color_convertor_time;
  5515. }
  5516. #endif
  5517. }
  5518. else if(16 == lpicComp->lpbiInput->biBitCount)
  5519. {
  5520. // To use a common routine for all possible combinations of RGB16,
  5521. // a bitfield number is passed. This number identifies the proper bit shift
  5522. // and masking values to extract the color information
  5523. // from the 16-bit pixel words.
  5524. //
  5525. // number shift mask
  5526. // B, G, R
  5527. // ------ ----------- ----------------
  5528. // 555 2, 3, 8 0x7C, 0x7C, 0x7C
  5529. // 664 3, 3, 9 0x78, 0x7E, 0x7E
  5530. // 565 2, 4, 9 0x7C, 0x7E, 0x7C
  5531. // 655 2, 3, 9 0x7C, 0x7C, 0x7E
  5532. //
  5533. // Only 555 falls under BI_RGB. The others are specified using the
  5534. // BI_BITFIELDS compression specification. For BI_BITFIELDS, call
  5535. // Build16bitModeID to get the actual bitfield number. This routine requires the
  5536. // three array elements in the bmiColors field of a BITMAPINFO object.
  5537. //
  5538. #if defined(_CODEC_STATS)
  5539. if (pEncoderStats) {
  5540. pEncoderStats->color_convertor_time = PENTIUM_TIMER();
  5541. }
  5542. #endif
  5543. #if 0
  5544. C_H26X_BGR16toYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5545. EC->FrameWidth, EC->FrameHeight, 555, PITCH);
  5546. #else
  5547. IA_H26X_BGR16555toYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5548. EC->FrameWidth, EC->FrameHeight, PITCH);
  5549. #endif
  5550. #if defined(_CODEC_STATS)
  5551. if (pEncoderStats) {
  5552. pEncoderStats->color_convertor_time =
  5553. PENTIUM_TIMER() - pEncoderStats->color_convertor_time;
  5554. }
  5555. #endif
  5556. }
  5557. else if(8 == lpicComp->lpbiInput->biBitCount)
  5558. {
  5559. #if defined(_CODEC_STATS)
  5560. if (pEncoderStats) {
  5561. pEncoderStats->color_convertor_time = PENTIUM_TIMER();
  5562. }
  5563. #endif
  5564. #if 0
  5565. C_H26X_CLUTtoYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5566. EC->FrameWidth, EC->FrameHeight, 8, PITCH);
  5567. #else
  5568. IA_H26X_CLUT8toYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5569. EC->FrameWidth, EC->FrameHeight, PITCH);
  5570. #endif
  5571. #if defined(_CODEC_STATS)
  5572. if (pEncoderStats) {
  5573. pEncoderStats->color_convertor_time =
  5574. PENTIUM_TIMER() - pEncoderStats->color_convertor_time;
  5575. }
  5576. #endif
  5577. }
  5578. else if(4 == lpicComp->lpbiInput->biBitCount)
  5579. {
  5580. #if defined(_CODEC_STATS)
  5581. if (pEncoderStats) {
  5582. pEncoderStats->color_convertor_time = PENTIUM_TIMER();
  5583. }
  5584. #endif
  5585. #if 0
  5586. C_H26X_CLUTtoYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5587. EC->FrameWidth, EC->FrameHeight, 4, PITCH);
  5588. #else
  5589. IA_H26X_CLUT4toYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5590. EC->FrameWidth, EC->FrameHeight, PITCH);
  5591. #endif
  5592. #if defined(_CODEC_STATS)
  5593. if (pEncoderStats) {
  5594. pEncoderStats->color_convertor_time =
  5595. PENTIUM_TIMER() - pEncoderStats->color_convertor_time;
  5596. }
  5597. #endif
  5598. }
  5599. else
  5600. {
  5601. ERRORMESSAGE(("%s: Unexpected input format detected\r\n", _fx_));
  5602. }
  5603. }
  5604. else if (FOURCC_YVU9 == lpicComp->lpbiInput->biCompression)
  5605. {
  5606. #if defined(_CODEC_STATS)
  5607. if (pEncoderStats) {
  5608. pEncoderStats->color_convertor_time = PENTIUM_TIMER();
  5609. }
  5610. #endif
  5611. #if 0
  5612. C_H26X_YVU9toYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5613. EC->FrameWidth, EC->FrameHeight, PITCH);
  5614. #else
  5615. IA_H26X_YVU9toYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5616. EC->FrameWidth, EC->FrameHeight, PITCH);
  5617. #endif
  5618. #if defined(_CODEC_STATS)
  5619. if (pEncoderStats) {
  5620. pEncoderStats->color_convertor_time =
  5621. PENTIUM_TIMER() - pEncoderStats->color_convertor_time;
  5622. }
  5623. #endif
  5624. }
  5625. else if ((FOURCC_YUV12 == lpicComp->lpbiInput->biCompression) || (FOURCC_IYUV == lpicComp->lpbiInput->biCompression))
  5626. {
  5627. #if defined(_CODEC_STATS)
  5628. if (pEncoderStats) {
  5629. pEncoderStats->color_convertor_time = PENTIUM_TIMER();
  5630. }
  5631. #endif
  5632. #if 0
  5633. C_H26X_YUV12toEncYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5634. EC->FrameWidth, EC->FrameHeight, PITCH);
  5635. #else
  5636. IA_H26X_YUV12toEncYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5637. EC->FrameWidth, EC->FrameHeight, PITCH);
  5638. #endif
  5639. #if defined(_CODEC_STATS)
  5640. if (pEncoderStats) {
  5641. pEncoderStats->color_convertor_time =
  5642. PENTIUM_TIMER() - pEncoderStats->color_convertor_time;
  5643. }
  5644. #endif
  5645. }
  5646. else if (FOURCC_YUY2 == lpicComp->lpbiInput->biCompression)
  5647. {
  5648. #if defined(_CODEC_STATS)
  5649. if (pEncoderStats) {
  5650. pEncoderStats->color_convertor_time = PENTIUM_TIMER();
  5651. }
  5652. #endif
  5653. #if 0
  5654. C_H26X_YUY2toYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5655. EC->FrameWidth, EC->FrameHeight, PITCH);
  5656. #else
  5657. IA_H26X_YUY2toYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5658. EC->FrameWidth, EC->FrameHeight, PITCH);
  5659. #endif
  5660. #if defined(_CODEC_STATS)
  5661. if (pEncoderStats) {
  5662. pEncoderStats->color_convertor_time =
  5663. PENTIUM_TIMER() - pEncoderStats->color_convertor_time;
  5664. }
  5665. #endif
  5666. }
  5667. else if (FOURCC_UYVY == lpicComp->lpbiInput->biCompression)
  5668. {
  5669. #if defined(_CODEC_STATS)
  5670. if (pEncoderStats) {
  5671. pEncoderStats->color_convertor_time = PENTIUM_TIMER();
  5672. }
  5673. #endif
  5674. // UYVY images are upside-down in relation to I420
  5675. // call the "flipped" version of the UYVY-I420 translator.
  5676. bRet = UYVY_to_YUV12_Flip(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5677. EC->FrameWidth, EC->FrameHeight, PITCH);
  5678. // IA_H26X_UYVYtoYUV12(lpbiInput, RGBCursor, YPlane, UPlane, VPlane,
  5679. // EC->FrameWidth, EC->FrameHeight, PITCH);
  5680. #if defined(_CODEC_STATS)
  5681. if (pEncoderStats) {
  5682. pEncoderStats->color_convertor_time =
  5683. PENTIUM_TIMER() - pEncoderStats->color_convertor_time;
  5684. }
  5685. #endif
  5686. }
  5687. else
  5688. {
  5689. ERRORMESSAGE(("%s: Unexpected input format detected\r\n", _fx_));
  5690. }
  5691. }
  5692. #endif // } H263P