// File: kylegranger[P]ImageScaling/linear16.cpp
// Function: CLinear16::DrawMonochromeAnaglyph(CLinear16*, CLinear16*)
void CLinear16::DrawMonochromeAnaglyph(CLinear16 *left, CLinear16 *right)
{
	if (left && right)
	{
		assert(left->mWidth == mWidth);
		assert(left->mHeight == mHeight);
		assert(right->mWidth == mWidth);
		assert(right->mHeight == mHeight);
		color_t *src1 = left->mData;
		color_t *src2 = right->mData;
		color_t *dst = mData;
		for (int y = 0; y < mHeight; y++)
		{
			for (int x = 0; x < mWidth; x++)
			{
				int luma1 = src1->r * 2126 + src1->g * 7152 + src1->b * 722 + 5000;
				int luma2 = src2->r * 2126 + src2->g * 7152 + src2->b * 722 + 5000;
				luma1 /= 10000;
				luma2 /= 10000;
				dst->r = luma1;
				dst->g = luma2 * 3 / 4;
				dst->b = luma2;
				dst->a = 0xffff;
				dst++;
			}
		}
	}
	else if (left)
	{
		assert(left->mWidth == mWidth);
		assert(left->mHeight == mHeight);
		color_t *src = left->mData;
		color_t *dst = mData;
		for (int y = 0; y < mHeight; y++)
		{
			for (int x = 0; x < mWidth; x++)
			{
				int luma1 = src->r * 2126 + src->g * 7152 + src->b * 722 + 5000;
				luma1 /= 10000;
				dst->r = luma1;
				dst->a = 0xffff;
				dst++;
				src++;
			}
		}
	}
	else if (right)
	{
		assert(right->mWidth == mWidth);
		assert(right->mHeight == mHeight);
		color_t *src = right->mData;
		color_t *dst = mData;
		for (int y = 0; y < mHeight; y++)
		{
			for (int x = 0; x < mWidth; x++)
			{
				int luma2 = src->r * 2126 + src->g * 7152 + src->b * 722 + 5000;
				luma2 /= 10000;
				dst->g = luma2 * 3 / 4;
				dst->b = luma2;
				dst++;
				src++;
			}
		}
	}
	else
		assert(0);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xb51f
cmpq $0x0, -0x18(%rbp)
je 0xb51f
movq -0x88(%rbp), %rcx
movq -0x10(%rbp), %rax
movl (%rax), %eax
cmpl (%rcx), %eax
jne 0xb31b
jmp 0xb33a
leaq 0x1617b(%rip), %rdi     # 0x2149d
leaq 0x15ee1(%rip), %rsi     # 0x2120a
movl $0x39d, %edx            # imm = 0x39D
leaq 0x1617f(%rip), %rcx     # 0x214b4
callq 0x40f0
movq -0x88(%rbp), %rcx
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
cmpl 0x4(%rcx), %eax
jne 0xb34f
jmp 0xb36e
leaq 0x1619f(%rip), %rdi     # 0x214f5
leaq 0x15ead(%rip), %rsi     # 0x2120a
movl $0x39e, %edx            # imm = 0x39E
leaq 0x1614b(%rip), %rcx     # 0x214b4
callq 0x40f0
movq -0x88(%rbp), %rcx
movq -0x18(%rbp), %rax
movl (%rax), %eax
cmpl (%rcx), %eax
jne 0xb381
jmp 0xb3a0
leaq 0x16186(%rip), %rdi     # 0x2150e
leaq 0x15e7b(%rip), %rsi     # 0x2120a
movl $0x39f, %edx            # imm = 0x39F
leaq 0x16119(%rip), %rcx     # 0x214b4
callq 0x40f0
movq -0x88(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
cmpl 0x4(%rcx), %eax
jne 0xb3b5
jmp 0xb3d4
leaq 0x1616a(%rip), %rdi     # 0x21526
leaq 0x15e47(%rip), %rsi     # 0x2120a
movl $0x3a0, %edx            # imm = 0x3A0
leaq 0x160e5(%rip), %rcx     # 0x214b4
callq 0x40f0
movq -0x88(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq %rcx, -0x28(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x88(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0xb51a
movl $0x0, -0x38(%rbp)
movq -0x88(%rbp), %rcx
movl -0x38(%rbp), %eax
cmpl (%rcx), %eax
jge 0xb50a
movq -0x20(%rbp), %rax
movzwl 0x4(%rax), %eax
imull $0x84e, %eax, %eax      # imm = 0x84E
movq -0x20(%rbp), %rcx
movzwl 0x2(%rcx), %ecx
imull $0x1bf0, %ecx, %ecx     # imm = 0x1BF0
addl %ecx, %eax
movq -0x20(%rbp), %rcx
movzwl (%rcx), %ecx
imull $0x2d2, %ecx, %ecx      # imm = 0x2D2
addl %ecx, %eax
addl $0x1388, %eax           # imm = 0x1388
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movzwl 0x4(%rax), %eax
imull $0x84e, %eax, %eax      # imm = 0x84E
movq -0x28(%rbp), %rcx
movzwl 0x2(%rcx), %ecx
imull $0x1bf0, %ecx, %ecx     # imm = 0x1BF0
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzwl (%rcx), %ecx
imull $0x2d2, %ecx, %ecx      # imm = 0x2D2
addl %ecx, %eax
addl $0x1388, %eax           # imm = 0x1388
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl $0x2710, %ecx           # imm = 0x2710
cltd
idivl %ecx
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
movl $0x2710, %ecx           # imm = 0x2710
cltd
idivl %ecx
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movw %ax, %cx
movq -0x30(%rbp), %rax
movw %cx, 0x4(%rax)
imull $0x3, -0x40(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movw %ax, %cx
movq -0x30(%rbp), %rax
movw %cx, 0x2(%rax)
movl -0x40(%rbp), %eax
movw %ax, %cx
movq -0x30(%rbp), %rax
movw %cx, (%rax)
movq -0x30(%rbp), %rax
movw $0xffff, 0x6(%rax)      # imm = 0xFFFF
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xb41c
jmp 0xb50c
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xb402
jmp 0xb7f5
cmpq $0x0, -0x10(%rbp)
je 0xb674
movq -0x88(%rbp), %rcx
movq -0x10(%rbp), %rax
movl (%rax), %eax
cmpl (%rcx), %eax
jne 0xb53d
jmp 0xb55c
leaq 0x15f59(%rip), %rdi     # 0x2149d
leaq 0x15cbf(%rip), %rsi     # 0x2120a
movl $0x3b6, %edx            # imm = 0x3B6
leaq 0x15f5d(%rip), %rcx     # 0x214b4
callq 0x40f0
movq -0x88(%rbp), %rcx
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
cmpl 0x4(%rcx), %eax
jne 0xb571
jmp 0xb590
leaq 0x15f7d(%rip), %rdi     # 0x214f5
leaq 0x15c8b(%rip), %rsi     # 0x2120a
movl $0x3b7, %edx            # imm = 0x3B7
leaq 0x15f29(%rip), %rcx     # 0x214b4
callq 0x40f0
movq -0x88(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq %rcx, -0x48(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x88(%rbp), %rcx
movl -0x54(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0xb66f
movl $0x0, -0x58(%rbp)
movq -0x88(%rbp), %rcx
movl -0x58(%rbp), %eax
cmpl (%rcx), %eax
jge 0xb65f
movq -0x48(%rbp), %rax
movzwl 0x4(%rax), %eax
imull $0x84e, %eax, %eax      # imm = 0x84E
movq -0x48(%rbp), %rcx
movzwl 0x2(%rcx), %ecx
imull $0x1bf0, %ecx, %ecx     # imm = 0x1BF0
addl %ecx, %eax
movq -0x48(%rbp), %rcx
movzwl (%rcx), %ecx
imull $0x2d2, %ecx, %ecx      # imm = 0x2D2
addl %ecx, %eax
addl $0x1388, %eax           # imm = 0x1388
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl $0x2710, %ecx           # imm = 0x2710
cltd
idivl %ecx
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movw %ax, %cx
movq -0x50(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x50(%rbp), %rax
movw $0xffff, 0x6(%rax)      # imm = 0xFFFF
movq -0x50(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x48(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0xb5cc
jmp 0xb661
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0xb5b2
jmp 0xb7f3
cmpq $0x0, -0x18(%rbp)
je 0xb7d2
movq -0x88(%rbp), %rcx
movq -0x18(%rbp), %rax
movl (%rax), %eax
cmpl (%rcx), %eax
jne 0xb692
jmp 0xb6b1
leaq 0x15e75(%rip), %rdi     # 0x2150e
leaq 0x15b6a(%rip), %rsi     # 0x2120a
movl $0x3c9, %edx            # imm = 0x3C9
leaq 0x15e08(%rip), %rcx     # 0x214b4
callq 0x40f0
movq -0x88(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
cmpl 0x4(%rcx), %eax
jne 0xb6c6
jmp 0xb6e5
leaq 0x15e59(%rip), %rdi     # 0x21526
leaq 0x15b36(%rip), %rsi     # 0x2120a
movl $0x3ca, %edx            # imm = 0x3CA
leaq 0x15dd4(%rip), %rcx     # 0x214b4
callq 0x40f0
movq -0x88(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq %rcx, -0x68(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movq -0x88(%rbp), %rcx
movl -0x74(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0xb7d0
movl $0x0, -0x78(%rbp)
movq -0x88(%rbp), %rcx
movl -0x78(%rbp), %eax
cmpl (%rcx), %eax
jge 0xb7c0
movq -0x68(%rbp), %rax
movzwl 0x4(%rax), %eax
imull $0x84e, %eax, %eax      # imm = 0x84E
movq -0x68(%rbp), %rcx
movzwl 0x2(%rcx), %ecx
imull $0x1bf0, %ecx, %ecx     # imm = 0x1BF0
addl %ecx, %eax
movq -0x68(%rbp), %rcx
movzwl (%rcx), %ecx
imull $0x2d2, %ecx, %ecx      # imm = 0x2D2
addl %ecx, %eax
addl $0x1388, %eax           # imm = 0x1388
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl $0x2710, %ecx           # imm = 0x2710
cltd
idivl %ecx
movl %eax, -0x7c(%rbp)
imull $0x3, -0x7c(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movw %ax, %cx
movq -0x70(%rbp), %rax
movw %cx, 0x2(%rax)
movl -0x7c(%rbp), %eax
movw %ax, %cx
movq -0x70(%rbp), %rax
movw %cx, (%rax)
movq -0x70(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x68(%rbp)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0xb721
jmp 0xb7c2
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0xb707
jmp 0xb7f1
leaq 0x15bde(%rip), %rdi     # 0x213b7
leaq 0x15a2a(%rip), %rsi     # 0x2120a
movl $0x3db, %edx            # imm = 0x3DB
leaq 0x15cc8(%rip), %rcx     # 0x214b4
callq 0x40f0
jmp 0xb7f3
jmp 0xb7f5
addq $0x90, %rsp
popq %rbp
retq
nop