;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;	UYVYSUP.ASM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
?STD = 1				;Use stdcall calling convention.
?WIN = 0				;No Windows prolog/epilog needed
?386Regs = 1

.xlist
include cmacro32.inc
.list
.386
.model flat

SEGNAME32	equ	ASM_TEXT32

include codec.inc


;__________________________________________________________________________
;
;	========        3 2 - B I T   S E G M E N T        ========
;__________________________________________________________________________
.386
createSeg %SEGNAME32, CodeSeg32, dword, public, CODE

sBegin CodeSeg32


;----------------------------------------------------------------------
;  Copy a yuv422 buffer into a UYVY DCI surface
;
cProc cpYCHtoUYVY <NEAR,STD,PUBLIC>,<EBX,ESI,EDI>
	ParmD	lpYCH
	ParmD	lpUYVY
	ParmD	dwWidth
	ParmD	dwHeight
	ParmD	lNextLine

cBegin
	mov	esi,lpYCH		; esi = source
	mov	edi,lpUYVY		; edi = dest
	mov	ebx,dwWidth		; Width in bytes
	shl	ebx,1			; /
	mov	edx,lNextLine		; Offset to next line from end of current line
	sub	edx,ebx			; /
	shr	ebx,2			; Width in duals
	mov	dwWidth,ebx		; Dual count
	mov	ecx,ebx

	align	4
@@:	mov	eax,[esi]		; V :Yb:U :Ya
	mov	ebx,eax			; V :Yb:U :Ya
	shl	eax,8			; Yb:U :Ya:0
	and	ebx,0FF00FF00h		; V :0 :U :0
	shr	ebx,8			; 0 :V :0 :U
	and	eax,0FF00FF00h		; Yb:0 :Ya:0
	or	eax,ebx			; Yb:V :Ya:U
	add	esi,4			; Next input dual
	mov	[edi],eax		; Output dual
	add	edi,4			; Next output dual
	dec	ecx			; Dual count
	jnz	@B			; Loop
	add	edi,edx			; To next line
	mov	ecx,dwWidth		; Dual count
	dec	dwHeight		; Done?
	jnz	@B			; No
cEnd


;----------------------------------------------------------------------
;  Copy a yuv422 buffer into a UYVY DCI surface and eliminate the chroma
;
cProc cpYCHtoUYVYgrey <NEAR,STD,PUBLIC>,<EBX,ESI,EDI>
	ParmD	lpYCH
	ParmD	lpUYVY
	ParmD	dwWidth
	ParmD	dwHeight
	ParmD	lNextLine

cBegin
	mov	esi,lpYCH		; esi = source
	mov	edi,lpUYVY		; edi = dest
	mov	eax,dwHeight		; Line count
	mov	ebx,dwWidth		; Width in bytes
	shl	ebx,1			; /
	mov	edx,lNextLine		; Offset to next line from end of current line
	sub	edx,ebx			; /
	shr	ebx,2			; Width in duals
	mov	ecx,ebx			; Dual count
	push	ebp			; Use EBP for line counter
	mov	ebp,eax			; /

	align	4
@@:	mov	eax,[esi]		; V:Yb:U:Ya
	shl	eax,8			; Yb:U:Ya:00
	and	eax,0FF00FF00h		; Yb:00:Ya:00
	or	eax,000800080h		; Yb:80:Ya:80
	add	esi,4			; Next input dual
	mov	[edi],eax		; Output grey dual
	add	edi,4			; Next output dual
	dec	ecx			; Dual count
	jnz	@B			; Loop
	add	edi,edx			; To next line
	mov	ecx,ebx			; Dual count
	dec	ebp			; Done?
	jnz	@B			; No

	pop	ebp
cEnd


sEnd
end
