// File: kebwi[P]Trifid/src/DebayerProcs.cpp
// Function: hue_constructRedOrBlueAtBlueOrRed(ImageReal&, Image3ChnlReal&, ImageReal&, int, int)
void hue_constructRedOrBlueAtBlueOrRed(
	ImageReal &grayImage, Image3ChnlReal &rgbImage,
	ImageReal &rgbImageRorB, int x, int y)
{
	if (&rgbImageRorB == rgbImage[0])
		assert(determineBayerColor(x, y) == B);
	else assert(determineBayerColor(x, y) == R);
	
	int width = grayImage.width(), height = grayImage.height();
	
	Float_t color1L = rgbImage(G, x, y);
	Float_t color2L = 0;
	int divisor = 0;
	if (x > 0 && y > 0)
	{
		color2L += (Float_t)grayImage(x - 1, y - 1) /
					(Float_t)rgbImage(G, x - 1, y - 1);
		divisor++;
	}
	if (x < width - 1 && y > 0)
	{
		color2L += (Float_t)grayImage(x + 1, y - 1) /
					(Float_t)rgbImage(G, x + 1, y - 1);
		divisor++;
	}
	if (x < width - 1 && y < height - 1)
	{
		color2L += (Float_t)grayImage(x + 1, y + 1) /
					(Float_t)rgbImage(G, x + 1, y + 1);
		divisor++;
	}
	if (x > 0 && y < height - 1)
	{
		color2L += (Float_t)grayImage(x - 1, y + 1) /
					(Float_t)rgbImage(G, x - 1, y + 1);
		divisor++;
	}
	
	assert(divisor > 0);
	color1L = ((Float_t)color1L / (Float_t)divisor) * color2L;
	if (color1L > pow(2, sBitDepth) - 1)
		color1L = pow(2, sBitDepth) - 1;
	
	rgbImageRorB(x, y) = color1L;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0xef40
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jne 0x1aba0
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
callq 0x380a0
cmpl $0x2, %eax
jne 0x1ab7f
jmp 0x1ab9e
leaq 0x2fb60(%rip), %rdi     # 0x4a6e6
leaq 0x2f9e3(%rip), %rsi     # 0x4a570
movl $0x1ab, %edx            # imm = 0x1AB
leaq 0x2fb6c(%rip), %rcx     # 0x4a705
callq 0x4240
jmp 0x1abd3
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
callq 0x380a0
cmpl $0x0, %eax
jne 0x1abb2
jmp 0x1abd1
leaq 0x2fba9(%rip), %rdi     # 0x4a762
leaq 0x2f9b0(%rip), %rsi     # 0x4a570
movl $0x1ac, %edx            # imm = 0x1AC
leaq 0x2fb39(%rip), %rcx     # 0x4a705
callq 0x4240
jmp 0x1abd3
movq -0x8(%rbp), %rdi
callq 0xedd0
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
callq 0xedf0
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl $0x1, %esi
callq 0x17990
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0x1ac77
cmpl $0x0, -0x20(%rbp)
jle 0x1ac77
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
subl $0x1, %esi
movl -0x20(%rbp), %edx
subl $0x1, %edx
callq 0x16fd0
movsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %edx
subl $0x1, %edx
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
movl $0x1, %esi
callq 0x17990
movsd -0x50(%rbp), %xmm0
divsd (%rax), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x1c(%rbp), %eax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1acde
cmpl $0x0, -0x20(%rbp)
jle 0x1acde
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
addl $0x1, %esi
movl -0x20(%rbp), %edx
subl $0x1, %edx
callq 0x16fd0
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
movl $0x1, %esi
callq 0x17990
movsd -0x58(%rbp), %xmm0
divsd (%rax), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x1c(%rbp), %eax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1ad4c
movl -0x20(%rbp), %eax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1ad4c
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
addl $0x1, %esi
movl -0x20(%rbp), %edx
addl $0x1, %edx
callq 0x16fd0
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movl $0x1, %esi
callq 0x17990
movsd -0x60(%rbp), %xmm0
divsd (%rax), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0x1adb3
movl -0x20(%rbp), %eax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1adb3
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
subl $0x1, %esi
movl -0x20(%rbp), %edx
addl $0x1, %edx
callq 0x16fd0
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %edx
subl $0x1, %edx
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movl $0x1, %esi
callq 0x17990
movsd -0x68(%rbp), %xmm0
divsd (%rax), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jle 0x1adbb
jmp 0x1adda
leaq 0x2f7fd(%rip), %rdi     # 0x4a5bf
leaq 0x2f7a7(%rip), %rsi     # 0x4a570
movl $0x1cc, %edx            # imm = 0x1CC
leaq 0x2f930(%rip), %rcx     # 0x4a705
callq 0x4240
movsd -0x30(%rbp), %xmm0
cvtsi2sdl -0x3c(%rbp), %xmm1
divsd %xmm1, %xmm0
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movl 0x3f576(%rip), %esi     # 0x5a378
movl $0x2, %edi
callq 0x1d7f0
movaps %xmm0, %xmm1
movsd -0x70(%rbp), %xmm0
movsd 0x2e204(%rip), %xmm2    # 0x49020
subsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1ae47
movl 0x3f54c(%rip), %esi     # 0x5a378
movl $0x2, %edi
callq 0x1d7f0
movsd 0x2e1e2(%rip), %xmm1    # 0x49020
subsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x16fd0
movsd -0x78(%rbp), %xmm0
movsd %xmm0, (%rax)
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)