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.

494 lines
17 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. ;// $Header: S:\h26x\src\dec\cx512161.asv
  16. ;//
  17. ;// $Log: S:\h26x\src\dec\cx512161.asv $
  18. ;//
  19. ;// Rev 1.6 18 Mar 1996 09:58:44 bnickers
  20. ;// Make color convertors non-destructive.
  21. ;//
  22. ;// Rev 1.5 05 Mar 1996 15:51:18 BNICKERS
  23. ;// Made this function non-destructive on input. Only works on flat model now.
  24. ;//
  25. ;// Rev 1.4 05 Feb 1996 13:34:34 BNICKERS
  26. ;// Fix RGB16 color flash problem, by allowing different RGB16 formats at oce.
  27. ;//
  28. ;// Rev 1.3 27 Dec 1995 14:35:40 RMCKENZX
  29. ;// Added copyright notice
  30. ;//
  31. ;// Rev 1.2 27 Oct 1995 17:30:50 BNICKERS
  32. ;// Fix RGB16 color convertors.
  33. ;//
  34. ;// Rev 1.1 26 Oct 1995 09:46:20 BNICKERS
  35. ;// Reduce the number of blanks in the "proc" statement because the assembler
  36. ;// sometimes has problems with statements longer than 512 characters long.
  37. ;//
  38. ;// Rev 1.0 25 Oct 1995 17:59:26 BNICKERS
  39. ;// Initial revision.
  40. ;//
  41. ;////////////////////////////////////////////////////////////////////////////
  42. ;
  43. ; +---------- Color convertor.
  44. ; |+--------- For H263 or H261.
  45. ; ||+-------- Version for the Pentium(r) Microprocessor.
  46. ; |||++------ Convert from YUV12.
  47. ; |||||++---- Convert to RGB16.
  48. ; |||||||+--- Zoom by one, i.e. non-zoom.
  49. ; ||||||||
  50. ; cx512161 -- This function performs YUV12-to-RGB16 color conversion for H26x.
  51. ; It is tuned for best performance on the Pentium(r) Microprocessor.
  52. ; It handles any format in which there are three fields, the low
  53. ; order field being B and fully contained in the low order byte, the
  54. ; second field being G and being somewhere in bits 4 through 11,
  55. ; and the high order field being R and fully contained in the high
  56. ; order byte. Formats presently supported: 555, 565, 655, and 664.
  57. ;
  58. ; The YUV12 input is planar, 8 bits per pel. The Y plane may have
  59. ; a pitch of up to 768. It may have a width less than or equal
  60. ; to the pitch. It must be DWORD aligned, and preferably QWORD
  61. ; aligned. Pitch and Width must be a multiple of four. For best
  62. ; performance, Pitch should not be 4 more than a multiple of 32.
  63. ; Height may be any amount, but must be a multiple of two. The U
  64. ; and V planes may have a different pitch than the Y plane, subject
  65. ; to the same limitations.
  66. ;
  67. ; The color convertor is non-destructive; the input Y, U, and V
  68. ; planes will not be clobbered.
  69. OPTION PROLOGUE:None
  70. OPTION EPILOGUE:ReturnAndRelieveEpilogueMacro
  71. include locals.inc
  72. include ccinst.inc
  73. include decconst.inc
  74. .xlist
  75. include memmodel.inc
  76. .list
  77. .DATA
  78. ; any data would go here
  79. .CODE
  80. ASSUME cs : FLAT
  81. ASSUME ds : FLAT
  82. ASSUME es : FLAT
  83. ASSUME fs : FLAT
  84. ASSUME gs : FLAT
  85. ASSUME ss : FLAT
  86. ; void FAR ASM_CALLTYPE YUV12ToRGB16 (U8 * YPlane,
  87. ; U8 * VPlane,
  88. ; U8 * UPlane,
  89. ; UN FrameWidth,
  90. ; UN FrameHeight,
  91. ; UN YPitch,
  92. ; UN VPitch,
  93. ; UN AspectAdjustmentCount,
  94. ; U8 * ColorConvertedFrame,
  95. ; U32 DCIOffset,
  96. ; U32 CCOffsetToLine0,
  97. ; IN CCOPitch,
  98. ; IN CCType)
  99. ;
  100. ; CCOffsetToLine0 is relative to ColorConvertedFrame.
  101. ;
  102. PUBLIC YUV12ToRGB16
  103. ; due to the need for the ebp reg, these parameter declarations aren't used,
  104. ; they are here so the assembler knows how many bytes to relieve from the stack
  105. YUV12ToRGB16 proc DIST LANG AYPlane: DWORD,
  106. AVPlane: DWORD,
  107. AUPlane: DWORD,
  108. AFrameWidth: DWORD,
  109. AFrameHeight: DWORD,
  110. AYPitch: DWORD,
  111. AVPitch: DWORD,
  112. AAspectAdjustmentCnt: DWORD,
  113. AColorConvertedFrame: DWORD,
  114. ADCIOffset: DWORD,
  115. ACCOffsetToLine0: DWORD,
  116. ACCOPitch: DWORD,
  117. ACCType: DWORD
  118. LocalFrameSize = 60+768*2+4
  119. RegisterStorageSize = 16
  120. ; Arguments:
  121. YPlane_arg = RegisterStorageSize + 4
  122. VPlane_arg = RegisterStorageSize + 8
  123. UPlane_arg = RegisterStorageSize + 12
  124. FrameWidth_arg = RegisterStorageSize + 16
  125. FrameHeight = RegisterStorageSize + 20
  126. YPitch = RegisterStorageSize + 24
  127. ChromaPitch_arg = RegisterStorageSize + 28
  128. AspectAdjustmentCount_arg = RegisterStorageSize + 32
  129. ColorConvertedFrame = RegisterStorageSize + 36
  130. DCIOffset = RegisterStorageSize + 40
  131. CCOffsetToLine0 = RegisterStorageSize + 44
  132. CCOPitch = RegisterStorageSize + 48
  133. CCType_arg = RegisterStorageSize + 52
  134. EndOfArgList = RegisterStorageSize + 56
  135. ; Locals (on local stack frame)
  136. CCOCursor EQU [esp+ 0]
  137. CCOSkipDistance EQU [esp+ 4]
  138. ChromaLineLen EQU [esp+ 8]
  139. YSkipDistance EQU [esp+12]
  140. YLimit EQU [esp+16]
  141. YCursor EQU [esp+20]
  142. VCursor EQU [esp+24]
  143. DistanceFromVToU EQU [esp+28]
  144. EndOfChromaLine EQU [esp+32]
  145. AspectCount EQU [esp+36]
  146. CCType EQU [esp+40]
  147. FrameWidth EQU [esp+44]
  148. ChromaPitch EQU [esp+48]
  149. AspectAdjustmentCount EQU [esp+52]
  150. StashESP EQU [esp+56]
  151. ChromaContribution EQU [esp+60]
  152. push esi
  153. push edi
  154. push ebp
  155. push ebx
  156. mov edi,esp
  157. sub esp,LocalFrameSize
  158. and esp,0FFFFF800H
  159. mov eax,[edi+FrameWidth_arg]
  160. mov ebx,[edi+ChromaPitch_arg]
  161. mov ecx,[edi+AspectAdjustmentCount_arg]
  162. mov FrameWidth,eax
  163. mov ChromaPitch,ebx
  164. mov AspectAdjustmentCount,ecx
  165. mov AspectCount,ecx
  166. mov ebx,[edi+VPlane_arg]
  167. mov ecx,[edi+UPlane_arg]
  168. mov eax,[edi+YPlane_arg]
  169. sub ecx,ebx
  170. mov DistanceFromVToU,ecx
  171. mov VCursor,ebx
  172. mov YCursor,eax
  173. mov eax,[edi+ColorConvertedFrame]
  174. add eax,[edi+DCIOffset]
  175. add eax,[edi+CCOffsetToLine0]
  176. mov CCOCursor,eax
  177. mov ebx,[edi+CCType_arg]
  178. mov ecx,0
  179. cmp ebx,CCTYPE_RGB16555
  180. je @f
  181. cmp ebx,CCTYPE_RGB16555DCI
  182. je @f
  183. mov ecx,2048
  184. cmp ebx,CCTYPE_RGB16565
  185. je @f
  186. cmp ebx,CCTYPE_RGB16565DCI
  187. je @f
  188. mov ecx,4096
  189. cmp ebx,CCTYPE_RGB16655
  190. je @f
  191. cmp ebx,CCTYPE_RGB16655DCI
  192. je @f
  193. mov ecx,6144
  194. cmp ebx,CCTYPE_RGB16664DCI
  195. je @f
  196. cmp ebx,CCTYPE_RGB16664
  197. je @f
  198. mov ecx,0DEADBEEFH
  199. @@:
  200. mov CCType,ecx
  201. mov StashESP,edi
  202. mov edx,[edi+FrameHeight]
  203. mov ecx,[edi+YPitch]
  204. imul edx,ecx
  205. mov ebx,FrameWidth
  206. mov eax,[edi+CCOPitch]
  207. sub eax,ebx
  208. sub ecx,ebx
  209. sub eax,ebx
  210. mov YSkipDistance,ecx
  211. sar ebx,1
  212. mov esi,YCursor ; Fetch cursor over luma plane.
  213. add edx,esi
  214. mov ChromaLineLen,ebx
  215. mov CCOSkipDistance,eax
  216. mov YLimit,edx
  217. mov YCursor,esi
  218. mov esi,VCursor
  219. ; Register Usage:
  220. ;
  221. ; edi -- Chroma contribution Line cursor.
  222. ; esi -- Chroma Line cursor.
  223. ; ebp -- V contribution to RGB; sum of U and V contributions.
  224. ; edx -- Distance from V pel to U pel.
  225. ; ecx -- A U pel.
  226. ; ebx -- U contribution to RGB.
  227. ; eax -- A V pel.
  228. PrepareChromaLine:
  229. mov edi,ChromaLineLen
  230. xor eax,eax
  231. mov edx,DistanceFromVToU
  232. mov al,[esi] ; Fetch V.
  233. add edi,esi ; Compute EOL address.
  234. xor ecx,ecx
  235. mov ebp,PD VContrib[eax*8] ; ebp[ 0: 7] -- Zero
  236. ; ; ebp[ 8:15] -- V contrib to G.
  237. ; ; ebp[16:23] -- V contrib to R.
  238. ; ; ebp[24:31] -- Zero.
  239. mov cl,[esi+edx] ; Fetch U.
  240. mov EndOfChromaLine,edi
  241. xor ebx,ebx ; Keep pairing happy.
  242. mov ebx,PD UContrib[ecx*8] ; ebx[ 0: 7] -- U contrib to B.
  243. ; ; ebx[ 8:15] -- U contrib to G.
  244. ; ; ebx[16:23] -- Zero.
  245. mov cl,[esi+edx+1] ; Fetch next U.
  246. lea edi,ChromaContribution
  247. add ebp,ebx ; Chroma contributions to RGB.
  248. NextChromaPel:
  249. mov ebx,PD UContrib[ecx*8] ; See above.
  250. mov al,[esi+1] ; Fetch V.
  251. mov [edi],ebp ; Store contribs to use for even chroma pel.
  252. mov cl,[esi+edx+2] ; Fetch next U.
  253. mov ebp,PD VContrib[eax*8] ; See above.
  254. add edi,8
  255. add ebp,ebx ; Chroma contributions to RGB.
  256. mov al,[esi+2] ; Fetch V.
  257. mov [edi-4],ebp ; Store contribs to use for odd chroma pel.
  258. mov ebx,PD UContrib[ecx*8] ; See above.
  259. mov ebp,PD VContrib[eax*8] ; See above.
  260. mov cl,[esi+edx+3] ; Fetch next U.
  261. add ebp,ebx ; Chroma contributions to RGB.
  262. add esi,2 ; Inc Chroma cursor.
  263. cmp esi,EndOfChromaLine
  264. jne NextChromaPel
  265. xor ecx,ecx
  266. mov ebx,AspectCount
  267. mov [edi],ecx ; Store EOL indicator.
  268. mov eax,CCType
  269. xor edx,edx
  270. mov edi,CCOCursor
  271. dec ebx ; If count is non-zero, we keep the line.
  272. mov esi,YCursor
  273. mov AspectCount,ebx
  274. jne KeepLine0
  275. add esi,FrameWidth
  276. mov ebx,AspectAdjustmentCount
  277. mov AspectCount,ebx
  278. jmp SkipLine0
  279. KeepLine0:
  280. ; Register Usage:
  281. ;
  282. ; esp -- Cursor over the Chroma contribution.
  283. ; edi -- Cursor over the color converted output image.
  284. ; esi -- Cursor over a line of the Y Plane.
  285. ; ebp -- U contribution to B field of RGB value.
  286. ; edx -- V contribution to R field of RGB value.
  287. ; Clamped, positioned G value.
  288. ; ecx -- UV contribution to G field of RGB value.
  289. ; Clamped, positioned G value.
  290. ; ebx -- Construction of two pels of RGB16.
  291. ; al -- Y value (i.e. Y contribution to R, G, and B);
  292. mov al,[esi+1] ; Get Y01.
  293. mov ebp,ChromaContribution ; Get U contribution to B, plus garbage.
  294. shr al,1 ; Reduce to 7 bits.
  295. mov cl,ChromaContribution+1 ; Get UV contribution to G value.
  296. mov dl,ChromaContribution+2 ; Get V contribution to R value.
  297. and ebp,0FFH ; Extract U contribution to B.
  298. sub esp,1536
  299. xor ebx,ebx
  300. DoNext4YPelsOfLine0:
  301. mov bh,PB RValLo[eax+edx] ; Get clamped R value for Pel01.
  302. mov dl,PB GValHi[eax+ecx] ; Get clamped G value for Pel01.
  303. shl edx,4 ; Position G value.
  304. mov bl,PB BValLo[eax+ebp*1] ; Get clamped B value for Pel01.
  305. or ebx,edx ; Combine RGB16 value for Pel01.
  306. mov al,[esi] ; Fetch Y00.
  307. shr al,1 ; Reduce to 7 bits.
  308. xor edx,edx
  309. shl ebx,16 ; Position RGB16 value for Pel01.
  310. mov dl,ChromaContribution+1536+2 ; Reload V contribution to R value.
  311. mov bl,PB BValHi[eax+ebp*1] ; Get clamped R value for Pel00.
  312. mov cl,PB GValLo[eax+ecx] ; Get clamped G value for Pel00.
  313. shl ecx,4 ; Position G value.
  314. mov bh,PB RValHi[eax+edx] ; Get clamped R value for Pel00.
  315. or ebx,ecx ; Combine RGB16 value for Pel00.
  316. mov al,[esi+3] ; Fetch Y03.
  317. xor ecx,ecx
  318. mov ebp,ChromaContribution+1536+4 ; Get U contribution to B, plus garbage.
  319. shr al,1 ; Reduce to 7 bits.
  320. mov cl,ChromaContribution+1536+5 ; Get UV contribution to G value.
  321. mov dl,ChromaContribution+1536+6 ; Get V contribution to R value.
  322. and ebp,0FFH ; Extract U contribution to B.
  323. mov Ze [edi],ebx ; Write the 2 pels to output.
  324. add esi,4 ; Advance Y line cursor
  325. mov bh,PB RValLo[eax+edx] ; Get clamped R value for Pel03.
  326. mov dl,PB GValHi[eax+ecx] ; Get clamped G value for Pel03.
  327. shl edx,4 ; Position G value.
  328. mov bl,PB BValLo[eax+ebp*1] ; Get clamped B value for Pel03.
  329. or ebx,edx ; Combine RGB16 value for Pel03.
  330. mov al,[esi+2-4] ; Fetch Y02.
  331. shr al,1 ; Reduce to 7 bits.
  332. xor edx,edx
  333. shl ebx,16 ; Position RGB16 value for Pel03.
  334. mov dl,ChromaContribution+1536+6 ; Reload V contribution to R value.
  335. mov bl,PB BValHi[eax+ebp*1] ; Get clamped R value for Pel02.
  336. mov cl,PB GValLo[eax+ecx] ; Get clamped G value for Pel02.
  337. shl ecx,4 ; Position G value.
  338. mov bh,PB RValHi[eax+edx] ; Get clamped R value for Pel02.
  339. or ebx,ecx ; Combine RGB16 value for Pel02.
  340. mov al,[esi+5-4] ; Fetch Y05.
  341. xor ecx,ecx
  342. mov ebp,ChromaContribution+1536+8 ; Get next pel's U contrib to B value.
  343. shr al,1 ; Reduce to 7 bits.
  344. mov cl,ChromaContribution+1536+9 ; Get next pel's UV contrib to G value.
  345. mov Ze [edi+4],ebx ; Write the 2 pels to output.
  346. add edi,8 ; Advance color converted output cursor.
  347. mov dl,ChromaContribution+1536+10 ; Get next pel's V contrib to R value.
  348. and ebp,0FFH ; Extract U contribution to G value.
  349. lea esp,[esp+8] ; Advance Chroma contribution cursor.
  350. jne DoNext4YPelsOfLine0
  351. and esp,0FFFFF800H
  352. add esp,0800H
  353. add edi,CCOSkipDistance
  354. SkipLine0:
  355. mov ebp,YSkipDistance
  356. mov ebx,AspectCount
  357. add esi,ebp
  358. dec ebx ; If count is non-zero, we keep the line.
  359. mov AspectCount,ebx
  360. jne KeepLine1
  361. add esi,FrameWidth
  362. mov ebx,AspectAdjustmentCount
  363. mov AspectCount,ebx
  364. jmp SkipLine1
  365. KeepLine1:
  366. mov al,[esi+1] ; Get Y01.
  367. mov ebp,ChromaContribution ; Get U contribution to B, plus garbage.
  368. shr al,1 ; Reduce to 7 bits.
  369. mov cl,ChromaContribution+1 ; Get UV contribution to G value.
  370. mov dl,ChromaContribution+2 ; Get V contribution to R value.
  371. and ebp,0FFH ; Extract U contribution to B.
  372. sub esp,1536
  373. xor ebx,ebx
  374. DoNext4YPelsOfLine1:
  375. mov bh,PB RValHi[eax+edx]
  376. mov dl,PB GValLo[eax+ecx]
  377. shl edx,4
  378. mov bl,PB BValHi[eax+ebp*1]
  379. or ebx,edx
  380. mov al,[esi]
  381. shr al,1
  382. xor edx,edx
  383. shl ebx,16
  384. mov dl,ChromaContribution+1536+2
  385. mov bl,PB BValLo[eax+ebp*1]
  386. mov cl,PB GValHi[eax+ecx]
  387. shl ecx,4
  388. mov bh,PB RValLo[eax+edx]
  389. or ebx,ecx
  390. mov al,[esi+3]
  391. xor ecx,ecx
  392. mov ebp,ChromaContribution+1536+4
  393. shr al,1
  394. mov cl,ChromaContribution+1536+5
  395. mov dl,ChromaContribution+1536+6
  396. and ebp,0FFH
  397. mov Ze [edi],ebx
  398. add esi,4
  399. mov bh,PB RValHi[eax+edx]
  400. mov dl,PB GValLo[eax+ecx]
  401. shl edx,4
  402. mov bl,PB BValHi[eax+ebp*1]
  403. or ebx,edx
  404. mov al,[esi+2-4]
  405. shr al,1
  406. xor edx,edx
  407. shl ebx,16
  408. mov dl,ChromaContribution+1536+6
  409. mov bl,PB BValLo[eax+ebp*1]
  410. mov cl,PB GValHi[eax+ecx]
  411. shl ecx,4
  412. mov bh,PB RValLo[eax+edx]
  413. or ebx,ecx
  414. mov al,[esi+5-4]
  415. xor ecx,ecx
  416. mov ebp,ChromaContribution+1536+8
  417. shr al,1
  418. mov cl,ChromaContribution+1536+9
  419. mov Ze [edi+4],ebx
  420. add edi,8
  421. mov dl,ChromaContribution+1536+10
  422. and ebp,0FFH
  423. lea esp,[esp+8]
  424. jne DoNext4YPelsOfLine1
  425. and esp,0FFFFF800H
  426. add esp,0800H
  427. add edi,CCOSkipDistance
  428. SkipLine1:
  429. mov eax,YSkipDistance ; Inc LumaCursor to next line.
  430. add eax,esi
  431. mov ecx,ChromaPitch
  432. mov CCOCursor,edi
  433. mov YCursor,eax
  434. mov esi,VCursor ; Inc VPlane cursor to next line.
  435. mov ebx,YLimit ; Done with last line?
  436. add esi,ecx
  437. cmp eax,ebx
  438. mov VCursor,esi
  439. jb PrepareChromaLine
  440. mov esp,StashESP
  441. pop ebx
  442. pop ebp
  443. pop edi
  444. pop esi
  445. rturn
  446. YUV12ToRGB16 endp
  447. END