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.

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