// File: kebwi[P]Trifid/src/DebayerProcs.cpp
// Function: bayer(Image3ChnlReal, ImageReal&)
void bayer(Image3ChnlReal rgbImage, ImageReal &grayImage)
{
	cout << endl << "Bayerizing..." << endl;
	
	int width = rgbImage.width(), height = rgbImage.height();
	
	if (grayImage.width() != rgbImage.width() || grayImage.height() != rgbImage.height())
		die("Bayer output isn't same size as bayer input");
	
	for (int y = 0; y < height; y++)
		for (int x = 0; x < width; x++)
		{
			Color color = determineBayerColor(x, y);
			switch (color)
			{
				case R:
					grayImage(x, y) = rgbImage(R, x, y);
					break;
				case G:
					grayImage(x, y) = rgbImage(G, x, y);
					break;
				case B:
					grayImage(x, y) = rgbImage(B, x, y);
					break;
			}
		}
	
	grayImage.setFilename(rgbImage.filename());
	grayImage.appendFilename("_b");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x60(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x3cc42(%rip), %rdi     # 0x59fd0
movq 0x3cc23(%rip), %rsi     # 0x59fb8
callq 0x43d0
movq %rax, %rdi
leaq 0x2d79f(%rip), %rsi     # 0x4ab43
callq 0x4390
movq %rax, %rdi
movq 0x3cc05(%rip), %rsi     # 0x59fb8
callq 0x43d0
movq -0x60(%rbp), %rdi
callq 0xedd0
movq -0x60(%rbp), %rdi
movl %eax, -0x14(%rbp)
callq 0xedf0
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0xedd0
movq -0x60(%rbp), %rdi
movl %eax, -0x58(%rbp)
callq 0xedd0
movl %eax, %ecx
movl -0x58(%rbp), %eax
cmpl %ecx, %eax
jne 0x1d40c
movq -0x10(%rbp), %rdi
callq 0xedf0
movq -0x60(%rbp), %rdi
movl %eax, -0x64(%rbp)
callq 0xedf0
movl %eax, %ecx
movl -0x64(%rbp), %eax
cmpl %ecx, %eax
je 0x1d418
leaq 0x2d6ff(%rip), %rdi     # 0x4ab12
callq 0x5360
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x1d52f
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x1d51f
movl -0x20(%rbp), %edi
movl -0x1c(%rbp), %esi
callq 0x380a0
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x68(%rbp)
testl %eax, %eax
je 0x1d46f
jmp 0x1d458
movl -0x68(%rbp), %eax
subl $0x1, %eax
je 0x1d4a3
jmp 0x1d462
movl -0x68(%rbp), %eax
subl $0x2, %eax
je 0x1d4da
jmp 0x1d50f
movq -0x60(%rbp), %rdi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
xorl %esi, %esi
callq 0x17990
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %esi
movl -0x1c(%rbp), %edx
callq 0x16fd0
movsd -0x70(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x1d50f
movq -0x60(%rbp), %rdi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl $0x1, %esi
callq 0x17990
movsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %esi
movl -0x1c(%rbp), %edx
callq 0x16fd0
movsd -0x78(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x1d50f
movq -0x60(%rbp), %rdi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl $0x2, %esi
callq 0x17990
movsd (%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %esi
movl -0x1c(%rbp), %edx
callq 0x16fd0
movsd -0x80(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x1d511
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1d432
jmp 0x1d521
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1d41f
movq -0x60(%rbp), %rsi
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x48(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0xf090
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x154b0
jmp 0x1d563
leaq -0x48(%rbp), %rdi
callq 0x46c8
movq -0x10(%rbp), %rdi
leaq 0x2d5c7(%rip), %rsi     # 0x4ab3e
callq 0xf220
addq $0x90, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x46c8
movq -0x50(%rbp), %rdi
callq 0x4620
nopw %cs:(%rax,%rax)