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.

401 lines
15 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. ;// $Header: S:\h26x\src\dec\cx512241.asv
  15. ;//
  16. ;// $Log: S:\h26x\src\dec\cx512241.asv $
  17. ;//
  18. ;// Rev 1.7 27 Mar 1996 18:39:26 RMCKENZX
  19. ;// Corrected bug in line parity which manifests on odd aspects.
  20. ;//
  21. ;// Rev 1.6 27 Mar 1996 14:41:46 RMCKENZX
  22. ;// Changed YSkipDistance to use register ebp, not eax. When
  23. ;// pitch-width was more than 255, the first 4 pels of odd lines
  24. ;// would get erroneous values for blue, due to the presence of
  25. ;// non-zero values in the high order bits of eax. Also cleaned a
  26. ;// few comments.
  27. ;//
  28. ;// Rev 1.5 18 Mar 1996 09:58:46 bnickers
  29. ;// Make color convertors non-destructive.
  30. ;//
  31. ;// Rev 1.4 05 Feb 1996 13:35:34 BNICKERS
  32. ;// Fix RGB16 color flash problem, by allowing different RGB16 formats at oce.
  33. ;//
  34. ;// Rev 1.3 22 Dec 1995 15:40:52 KMILLS
  35. ;//
  36. ;// added new copyright notice
  37. ;//
  38. ;// Rev 1.2 30 Oct 1995 17:15:30 BNICKERS
  39. ;// Fix color shift in RGB24 color convertors.
  40. ;//
  41. ;// Rev 1.1 26 Oct 1995 09:47:22 BNICKERS
  42. ;// Reduce the number of blanks in the "proc" statement because the assembler
  43. ;// sometimes has problems with statements longer than 512 characters long.
  44. ;//
  45. ;// Rev 1.0 25 Oct 1995 17:59:30 BNICKERS
  46. ;// Initial revision.
  47. ;//
  48. ;////////////////////////////////////////////////////////////////////////////
  49. ;
  50. ; +---------- Color convertor.
  51. ; |+--------- For both H261 and H263.
  52. ; ||+-------- Version for the Pentium(r) Microprocessor.
  53. ; |||++------ Convert from YUV12.
  54. ; |||||++---- Convert to RGB24.
  55. ; |||||||+--- Zoom by one, i.e. non-zoom.
  56. ; ||||||||
  57. ; cx512241 -- This function performs YUV12-to-RGB24 color conversion for H26x.
  58. ; It is tuned for best performance on the Pentium(r) Microprocessor.
  59. ; It handles the format in which the low order byte is B, the
  60. ; second byte is G, and the high order byte is R.
  61. ;
  62. ; The YUV12 input is planar, 8 bits per pel. The Y plane may have
  63. ; a pitch of up to 768. It may have a width less than or equal
  64. ; to the pitch. It must be DWORD aligned, and preferably QWORD
  65. ; aligned. Pitch and Width must be a multiple of four. For best
  66. ; performance, Pitch should not be 4 more than a multiple of 32.
  67. ; Height may be any amount, but must be a multiple of two. The U
  68. ; and V planes may have a different pitch than the Y plane, subject
  69. ; to the same limitations.
  70. ;
  71. ; The color convertor is non-destructive; the input Y, U, and V
  72. ; planes will not be clobbered.
  73. OPTION PROLOGUE:None
  74. OPTION EPILOGUE:ReturnAndRelieveEpilogueMacro
  75. include locals.inc
  76. include ccinst.inc
  77. include decconst.inc
  78. .xlist
  79. include memmodel.inc
  80. .list
  81. .DATA
  82. ; any data would go here
  83. .CODE
  84. ASSUME cs : FLAT
  85. ASSUME ds : FLAT
  86. ASSUME es : FLAT
  87. ASSUME fs : FLAT
  88. ASSUME gs : FLAT
  89. ASSUME ss : FLAT
  90. ; void FAR ASM_CALLTYPE YUV12ToRGB24 (U8 * YPlane,
  91. ; U8 * VPlane,
  92. ; U8 * UPlane,
  93. ; UN FrameWidth,
  94. ; UN FrameHeight,
  95. ; UN YPitch,
  96. ; UN VPitch,
  97. ; UN AspectAdjustmentCount,
  98. ; U8 * ColorConvertedFrame,
  99. ; U32 DCIOffset,
  100. ; U32 CCOffsetToLine0,
  101. ; IN CCOPitch,
  102. ; IN CCType)
  103. ;
  104. ; CCOffsetToLine0 is relative to ColorConvertedFrame.
  105. ;
  106. PUBLIC YUV12ToRGB24
  107. ; due to the need for the ebp reg, these parameter declarations aren't used,
  108. ; they are here so the assembler knows how many bytes to relieve from the stack,
  109. ; or, rather, how to mangle the entry name.
  110. YUV12ToRGB24 proc DIST LANG AYPlane: DWORD,
  111. AVPlane: DWORD,
  112. AUPlane: DWORD,
  113. AFrameWidth: DWORD,
  114. AFrameHeight: DWORD,
  115. AYPitch: DWORD,
  116. AVPitch: DWORD,
  117. AAspectAdjustmentCnt: DWORD,
  118. AColorConvertedFrame: DWORD,
  119. ADCIOffset: DWORD,
  120. ACCOffsetToLine0: DWORD,
  121. ACCOPitch: DWORD,
  122. ACCType: DWORD
  123. LocalFrameSize = 60+768*4+16
  124. RegisterStorageSize = 16
  125. ; Arguments:
  126. YPlane_arg = RegisterStorageSize + 4
  127. VPlane_arg = RegisterStorageSize + 8
  128. UPlane_arg = RegisterStorageSize + 12
  129. FrameWidth_arg = RegisterStorageSize + 16
  130. FrameHeight = RegisterStorageSize + 20
  131. YPitch = RegisterStorageSize + 24
  132. ChromaPitch_arg = RegisterStorageSize + 28
  133. AspectAdjustmentCount_arg = RegisterStorageSize + 32
  134. ColorConvertedFrame = RegisterStorageSize + 36
  135. DCIOffset = RegisterStorageSize + 40
  136. CCOffsetToLine0 = RegisterStorageSize + 44
  137. CCOPitch = RegisterStorageSize + 48
  138. CCType_arg = RegisterStorageSize + 52
  139. EndOfArgList = RegisterStorageSize + 56
  140. ; Locals (on local stack frame)
  141. CCOCursor EQU [esp+ 0]
  142. CCOSkipDistance EQU [esp+ 4]
  143. ChromaLineLen EQU [esp+ 8]
  144. YSkipDistance EQU [esp+12]
  145. YLimit EQU [esp+16]
  146. YCursor EQU [esp+20]
  147. VCursor EQU [esp+24]
  148. DistanceFromVToU EQU [esp+28]
  149. EndOfChromaLine EQU [esp+32]
  150. AspectCount EQU [esp+36]
  151. FrameWidth EQU [esp+40]
  152. ChromaPitch EQU [esp+44]
  153. AspectAdjustmentCount EQU [esp+48]
  154. LineParity EQU [esp+52]
  155. StashESP EQU [esp+56]
  156. ChromaContribution EQU [esp+60]
  157. G2B2R1G1 EQU [esp+68]
  158. R3G3B3R2 EQU [esp+72]
  159. push esi
  160. push edi
  161. push ebp
  162. push ebx
  163. mov edi,esp
  164. sub esp,LocalFrameSize
  165. and esp,0FFFFF000H
  166. mov eax,[edi+FrameWidth_arg]
  167. mov ebx,[edi+ChromaPitch_arg]
  168. mov ecx,[edi+AspectAdjustmentCount_arg]
  169. mov FrameWidth,eax
  170. mov ChromaPitch,ebx
  171. mov AspectAdjustmentCount,ecx
  172. mov AspectCount,ecx
  173. mov ebx,[edi+VPlane_arg]
  174. mov ecx,[edi+UPlane_arg]
  175. mov eax,[edi+YPlane_arg]
  176. sub ecx,ebx
  177. mov DistanceFromVToU,ecx
  178. mov VCursor,ebx
  179. mov YCursor,eax
  180. mov eax,[edi+ColorConvertedFrame]
  181. add eax,[edi+DCIOffset]
  182. add eax,[edi+CCOffsetToLine0]
  183. mov CCOCursor,eax
  184. mov StashESP,edi
  185. mov edx,[edi+FrameHeight]
  186. mov ecx,[edi+YPitch]
  187. imul edx,ecx
  188. mov ebx,FrameWidth
  189. mov eax,[edi+CCOPitch]
  190. sub eax,ebx
  191. sub ecx,ebx
  192. sub eax,ebx
  193. mov YSkipDistance,ecx
  194. sub eax,ebx
  195. mov esi,YCursor ; Fetch cursor over luma plane.
  196. sar ebx,1
  197. mov CCOSkipDistance,eax
  198. add edx,esi
  199. mov ChromaLineLen,ebx
  200. mov YLimit,edx
  201. mov YCursor,esi
  202. mov esi,VCursor
  203. xor eax,eax
  204. mov LineParity,eax
  205. ; Register Usage:
  206. ;
  207. ; edi -- Chroma contribution Line cursor.
  208. ; esi -- Chroma Line cursor.
  209. ; ebp -- V contribution to RGB; sum of U and V contributions.
  210. ; edx -- Distance from V pel to U pel.
  211. ; ecx -- A U pel.
  212. ; ebx -- U contribution to RGB.
  213. ; eax -- A V pel.
  214. PrepareChromaLine:
  215. mov edi,ChromaLineLen
  216. xor eax,eax
  217. mov edx,DistanceFromVToU
  218. mov al,[esi] ; Fetch V.
  219. add edi,esi ; Compute EOL address.
  220. xor ecx,ecx
  221. mov ebp,PD V24Contrib[eax*8] ; ebp[24:31] -- Zero (blue).
  222. ; ; ebp[16:24] -- V contrib to G.
  223. ; ; ebp[ 9:15] -- Zero (pad).
  224. ; ; ebp[ 0: 8] -- V contrib to R.
  225. mov cl,[esi+edx] ; Fetch U.
  226. mov EndOfChromaLine,edi
  227. xor ebx,ebx ; Keep pairing happy.
  228. mov ebx,PD U24Contrib[ecx*8] ; ebx[24:31] -- U contrib to B.
  229. ; ; ebx[16:24] -- U contrib to G.
  230. ; ; ebx[ 9:15] -- Zero (pad).
  231. ; ; ebx[ 0: 8] -- Zero (red).
  232. mov cl,[esi+edx+1] ; Fetch next U.
  233. lea edi,ChromaContribution
  234. add ebp,ebx ; Chroma contributions to RGB.
  235. NextChromaPel:
  236. mov ebx,PD U24Contrib[ecx*8] ; See above.
  237. mov al,[esi+1] ; Fetch V.
  238. mov [edi],ebp ; Store contribs to use for even chroma pel.
  239. mov cl,[esi+edx+2] ; Fetch next U.
  240. mov ebp,PD V24Contrib[eax*8] ; See above.
  241. add edi,16
  242. add ebp,ebx ; Chroma contributions to RGB.
  243. mov al,[esi+2] ; Fetch V.
  244. mov [edi-12],ebp ; Store contribs to use for odd chroma pel.
  245. mov ebx,PD U24Contrib[ecx*8] ; See above.
  246. mov ebp,PD V24Contrib[eax*8] ; See above.
  247. mov cl,[esi+edx+3] ; Fetch next U.
  248. add ebp,ebx ; Chroma contributions to RGB.
  249. add esi,2 ; Inc Chroma cursor.
  250. cmp esi,EndOfChromaLine
  251. jne NextChromaPel
  252. xor ecx,ecx
  253. xor ebx,ebx
  254. mov [edi+4],ecx ; Store EOL indicator.
  255. mov edx,AspectCount
  256. mov edi,CCOCursor
  257. dec edx ; If count is non-zero, we keep the line.
  258. mov esi,YCursor
  259. mov AspectCount,edx
  260. jne KeepLine0
  261. add esi,FrameWidth
  262. mov edx,AspectAdjustmentCount
  263. mov AspectCount,edx
  264. jmp SkipLine0
  265. KeepLine0:
  266. KeepLine1:
  267. ; Register Usage:
  268. ;
  269. ; edi -- Cursor over the color converted output image.
  270. ; esi -- Cursor over a line of the Y Plane.
  271. ; ebp -- V contribution to R field of RGB value.
  272. ; edx -- Construction of one and a third pels of RGB24.
  273. ; cl -- Y value (i.e. Y contribution to R, G, and B);
  274. ; bl,al -- UV contrib to G field of RGB val, U contrib to B field of RGB val.
  275. mov cl,[esi+3] ; Get Y03.
  276. mov bl,ChromaContribution+6 ; Get UV contribution to G value.
  277. mov ebp,ChromaContribution+4 ; Get V contribution to R value.
  278. sub esp,3072
  279. and ebp,01FFH ; Extract V contribution to R value.
  280. mov dl,PB G24Value[ecx+ebx] ; Get clamped G value for Pel03.
  281. DoNext4YPelsOfLine0:
  282. mov dh,PB R24Value[ecx+ebp*1] ; Get clamped R value for Pel03.
  283. mov al,ChromaContribution+3072+7 ; Get U contribution to B value.
  284. shl edx,16 ; Position R and G value for Pel03.
  285. mov bl,[esi+2] ; Get Y02.
  286. mov dh,PB B24Value[ecx+eax*2] ; Get clamped B value for Pel03.
  287. mov cl,ChromaContribution+3072+6 ; Reload UV contribution to G value.
  288. mov dl,PB R24Value[ebx+ebp*1] ; Get clamped R value for Pel02.
  289. mov ebp,ChromaContribution+3072 ; Get V contribution to R value.
  290. mov R3G3B3R2+3072,edx ; Stash 1.33 pels.
  291. mov dl,PB B24Value[ebx+eax*2] ; Get clamped B value for Pel02.
  292. mov dh,PB G24Value[ebx+ecx] ; Get clamped G value for Pel02.
  293. mov cl,[esi+1] ; Get Y01.
  294. mov bl,ChromaContribution+3072+2 ; Get UV contribution to G value.
  295. and ebp,01FFH ; Extract V contribution to R value.
  296. shl edx,16 ; Position G and B values for Pel02.
  297. mov al,ChromaContribution+3072+3 ; Get U contribution to B value.
  298. mov dl,PB G24Value[ecx+ebx] ; Get clamped G value for Pel01.
  299. mov bl,[esi] ; Get Y00.
  300. mov dh,PB R24Value[ecx+ebp*1] ; Get clamped R value for Pel01.
  301. add esi,4 ; Advance source stream cursor.
  302. mov G2B2R1G1+3072,edx ; Stash 1.33 pels.
  303. mov dh,PB B24Value[ecx+eax*2] ; Get clamped B value for Pel01.
  304. mov cl,ChromaContribution+3072+2 ; Reload UV contribution to G value.
  305. add edi,12 ; Advance color converted output cursor.
  306. mov dl,PB R24Value[ebx+ebp*1] ; Get clamped R value for Pel00.
  307. mov ebp,ChromaContribution+3072+20 ; Get next V contribution to R value.
  308. shl edx,16 ; Position R for Pel00 and B for Pel01.
  309. and ebp,01FFH ; Extract V contrib to R val. 0 --> EOL.
  310. mov dl,PB B24Value[ebx+eax*2] ; Get clamped B value for Pel00.
  311. mov eax,G2B2R1G1+3072 ; Reload 2nd 1.33 pels.
  312. mov dh,PB G24Value[ebx+ecx] ; Get clamped G value for Pel00.
  313. mov cl,[esi+3] ; Get next Y03.
  314. mov Ze [edi-12],edx ; Write the first 1.33 pels out.
  315. mov bl,ChromaContribution+3072+22 ; Get UV contribution to G value.
  316. mov Ze [edi-8],eax ; Write the second 1.33 pels out.
  317. mov edx,R3G3B3R2+3072
  318. mov Ze [edi-4],edx ; Write the third 1.33 pels out.
  319. mov eax,ebx ; Zero out upper bytes of eax.
  320. mov dl,PB G24Value[ecx+ebx] ; Get clamped G value for Pel03.
  321. lea esp,[esp+16]
  322. jne DoNext4YPelsOfLine0
  323. and esp,0FFFFF000H
  324. add esp,1000H
  325. add edi,CCOSkipDistance
  326. SkipLine0:
  327. mov bl,LineParity
  328. mov ebp,YSkipDistance ; *** change to use ebp *** rgm 3/27/96
  329. xor bl,1
  330. je Line1Done
  331. mov LineParity,bl
  332. mov edx,AspectCount
  333. add esi,ebp ; *** change to use ebp *** rgm 3/27/96
  334. dec edx ; If count is non-zero, we keep the line.
  335. mov AspectCount,edx
  336. jne KeepLine1
  337. add esi,FrameWidth
  338. mov edx,AspectAdjustmentCount
  339. mov AspectCount,edx
  340. xor ebx, ebx ; *** change to advance parity *** rgm
  341. Line1Done:
  342. mov LineParity,bl
  343. add ebp,esi ; *** change to use ebp *** rgm 3/27/96
  344. mov CCOCursor,edi
  345. mov esi,VCursor ; Inc VPlane cursor to next line.
  346. mov ebx,ChromaPitch
  347. mov YCursor,ebp ; *** change to use ebp *** rgm 3/27/96
  348. add esi,ebx
  349. mov ebx,YLimit ; Done with last line?
  350. mov VCursor,esi
  351. cmp ebp,ebx ; *** change to use ebp *** rgm 3/27/96
  352. jb PrepareChromaLine
  353. mov esp,StashESP
  354. pop ebx
  355. pop ebp
  356. pop edi
  357. pop esi
  358. rturn
  359. YUV12ToRGB24 endp
  360. END