// File: kebwi[P]Trifid/src/DebayerProcs.cpp
// Function: hue_constructVerticalRedOrBlueAtGreen(ImageReal&, Image3ChnlReal&, ImageReal&, int, int)
void hue_constructVerticalRedOrBlueAtGreen(
	ImageReal &grayImage, Image3ChnlReal &rgbImage,
	ImageReal &rgbImageRorB, int x, int y)
{
	assert(determineBayerColor(x, y) == G);
	if (&rgbImageRorB == rgbImage[0] && y > 0)
		assert(determineBayerColor(x, y - 1) == R);
	else if (&rgbImageRorB == rgbImage[2] && y > 0)
		assert(determineBayerColor(x, y - 1) == B);
	
	int width = grayImage.width();
	
	Float_t color1L = rgbImage(G, x, y);
	Float_t color2L = 0;
	int divisor = 0;
	
	if (x > 0)
	{
		color2L += (Float_t)grayImage(x, y - 1) /
					(Float_t)rgbImage(G, x, y - 1);
		divisor++;
	}
	if (x < width - 1)
	{
		color2L += (Float_t)grayImage(x, y + 1) /
					(Float_t)rgbImage(G, x, 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 $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
callq 0x380a0
cmpl $0x1, %eax
jne 0x1b15d
jmp 0x1b17c
leaq 0x2f61d(%rip), %rdi     # 0x4a781
leaq 0x2f405(%rip), %rsi     # 0x4a570
movl $0x1fd, %edx            # imm = 0x1FD
leaq 0x2f6d2(%rip), %rcx     # 0x4a849
callq 0x4240
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 0x1b1d7
cmpl $0x0, -0x20(%rbp)
jle 0x1b1d7
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
subl $0x1, %esi
callq 0x380a0
cmpl $0x0, %eax
jne 0x1b1b6
jmp 0x1b1d5
leaq 0x2f6ed(%rip), %rdi     # 0x4a8aa
leaq 0x2f3ac(%rip), %rsi     # 0x4a570
movl $0x1ff, %edx            # imm = 0x1FF
leaq 0x2f679(%rip), %rcx     # 0x4a849
callq 0x4240
jmp 0x1b237
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0xef40
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jne 0x1b235
cmpl $0x0, -0x20(%rbp)
jle 0x1b235
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
subl $0x1, %esi
callq 0x380a0
cmpl $0x2, %eax
jne 0x1b214
jmp 0x1b233
leaq 0x2f6b2(%rip), %rdi     # 0x4a8cd
leaq 0x2f34e(%rip), %rsi     # 0x4a570
movl $0x201, %edx            # imm = 0x201
leaq 0x2f61b(%rip), %rcx     # 0x4a849
callq 0x4240
jmp 0x1b235
jmp 0x1b237
movq -0x8(%rbp), %rdi
callq 0xedd0
movl %eax, -0x24(%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 0x1b2c3
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %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
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 0x1b31e
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %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
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, -0x3c(%rbp)
jle 0x1b326
jmp 0x1b345
leaq 0x2f292(%rip), %rdi     # 0x4a5bf
leaq 0x2f23c(%rip), %rsi     # 0x4a570
movl $0x216, %edx            # imm = 0x216
leaq 0x2f509(%rip), %rcx     # 0x4a849
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, -0x68(%rbp)
movl 0x3f00b(%rip), %esi     # 0x5a378
movl $0x2, %edi
callq 0x1d7f0
movaps %xmm0, %xmm1
movsd -0x68(%rbp), %xmm0
movsd 0x2dc99(%rip), %xmm2    # 0x49020
subsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1b3b2
movl 0x3efe1(%rip), %esi     # 0x5a378
movl $0x2, %edi
callq 0x1d7f0
movsd 0x2dc77(%rip), %xmm1    # 0x49020
subsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x16fd0
movsd -0x70(%rbp), %xmm0
movsd %xmm0, (%rax)
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)