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.

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