// File: kebwi[P]Trifid/src/DebayerProcs.cpp
// Function: nn_procOnePixel(ImageReal&, Image3ChnlReal&, int, int)
void nn_procOnePixel(
	ImageReal &grayImage, Image3ChnlReal &rgbImage,
	int x, int y)
{
	Color color = determineBayerColor(x, y);
	int width = grayImage.width(), height = grayImage.height();
	
	Float_t bayerValue = 0, bayerValueRight = 0, bayerValueDown = 0, bayerValueRightDown = 0;
	bool rightEdge = false, bottomEdge = false;
	
	bayerValue = grayImage(x, y);
	if (x + 1 < width)
		bayerValueRight = grayImage(x + 1, y);
	else rightEdge = true;
	if (y + 1 < height)
		bayerValueDown = grayImage(x, y + 1);
	else bottomEdge = true;
	if (x + 1 < width && y + 1 < height)
		bayerValueRightDown = grayImage(x + 1, y + 1);
	
	//Fill in the output
	switch (color)
	{
		case R:
			rgbImage(R, x, y) = bayerValue;
			if (!rightEdge)
			{
				rgbImage(G, x, y) = bayerValueRight;
				if (!bottomEdge)
					rgbImage(B, x, y) = bayerValueRightDown;
			}
			break;
		case G:
			{
				Color colorRight;
				if (x < width - 1)
					colorRight = determineBayerColor(x + 1, y);
				else colorRight = determineBayerColor(x - 1, y);
				assert(colorRight != G);
				if (colorRight == R)
				{
					if (!rightEdge)
						rgbImage(R, x, y) = bayerValueRight;
					rgbImage(G, x, y) = bayerValue;
					if (!bottomEdge)
						rgbImage(B, x, y) = bayerValueDown;
				}
				else //if (colorRight == B)
				{
					if (!bottomEdge)
						rgbImage(R, x, y) = bayerValueDown;
					rgbImage(G, x, y) = bayerValue;
					if (!rightEdge)
						rgbImage(B, x, y) = bayerValueRight;
				}
			}
			break;
		case B:
			if (!rightEdge)
			{
				if (!bottomEdge)
					rgbImage(R, x, y) = bayerValueRightDown;
				rgbImage(G, x, y) = bayerValueRight;
			}
			rgbImage(B, x, y) = bayerValue;
			break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl -0x14(%rbp), %edi
movl -0x18(%rbp), %esi
callq 0x380a0
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
callq 0xedd0
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0xedf0
movl %eax, -0x24(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movb $0x0, -0x49(%rbp)
movb $0x0, -0x4a(%rbp)
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x16fd0
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
cmpl -0x20(%rbp), %eax
jge 0x19827
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
addl $0x1, %esi
movl -0x18(%rbp), %edx
callq 0x16fd0
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x1982b
movb $0x1, -0x49(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
cmpl -0x24(%rbp), %eax
jge 0x19853
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
addl $0x1, %edx
callq 0x16fd0
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x19857
movb $0x1, -0x4a(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
cmpl -0x20(%rbp), %eax
jge 0x1988b
movl -0x18(%rbp), %eax
addl $0x1, %eax
cmpl -0x24(%rbp), %eax
jge 0x1988b
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
addl $0x1, %esi
movl -0x18(%rbp), %edx
addl $0x1, %edx
callq 0x16fd0
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x54(%rbp)
testl %eax, %eax
je 0x198b6
jmp 0x19897
movl -0x54(%rbp), %eax
subl $0x1, %eax
je 0x1993b
jmp 0x198a5
movl -0x54(%rbp), %eax
subl $0x2, %eax
je 0x19abd
jmp 0x19b4d
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
xorl %esi, %esi
callq 0x17990
movsd -0x60(%rbp), %xmm0
movsd %xmm0, (%rax)
testb $0x1, -0x49(%rbp)
jne 0x19936
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movl $0x1, %esi
callq 0x17990
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%rax)
testb $0x1, -0x4a(%rbp)
jne 0x19934
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movl $0x2, %esi
callq 0x17990
movsd -0x70(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x19936
jmp 0x19b4d
movl -0x14(%rbp), %eax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1995b
movl -0x14(%rbp), %edi
addl $0x1, %edi
movl -0x18(%rbp), %esi
callq 0x380a0
movl %eax, -0x50(%rbp)
jmp 0x1996c
movl -0x14(%rbp), %edi
subl $0x1, %edi
movl -0x18(%rbp), %esi
callq 0x380a0
movl %eax, -0x50(%rbp)
cmpl $0x1, -0x50(%rbp)
je 0x19974
jmp 0x19993
leaq 0x30be5(%rip), %rdi     # 0x4a560
leaq 0x30bee(%rip), %rsi     # 0x4a570
movl $0x40, %edx
leaq 0x30bf3(%rip), %rcx     # 0x4a581
callq 0x4240
cmpl $0x0, -0x50(%rbp)
jne 0x19a26
testb $0x1, -0x49(%rbp)
jne 0x199c7
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
xorl %esi, %esi
callq 0x17990
movsd -0x78(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movl $0x1, %esi
callq 0x17990
movsd -0x80(%rbp), %xmm0
movsd %xmm0, (%rax)
testb $0x1, -0x4a(%rbp)
jne 0x19a21
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movl $0x2, %esi
callq 0x17990
movsd -0x88(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x19ab8
testb $0x1, -0x4a(%rbp)
jne 0x19a56
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
xorl %esi, %esi
callq 0x17990
movsd -0x90(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movl $0x1, %esi
callq 0x17990
movsd -0x98(%rbp), %xmm0
movsd %xmm0, (%rax)
testb $0x1, -0x49(%rbp)
jne 0x19ab6
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movl $0x2, %esi
callq 0x17990
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x19ab8
jmp 0x19b4d
testb $0x1, -0x49(%rbp)
jne 0x19b20
testb $0x1, -0x4a(%rbp)
jne 0x19af3
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
xorl %esi, %esi
callq 0x17990
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movl $0x1, %esi
callq 0x17990
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movl $0x2, %esi
callq 0x17990
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, (%rax)
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)