// File: /workspace/github_cpp_makefile_star2_O1/kebwi[P]Trifid/src/DebayerProcs.cpp
// Function: hue_deBayer(ImageReal&, Image3ChnlReal&)
void hue_deBayer(ImageReal &grayImage, Image3ChnlReal &rgbImage)
{
	int startX, startY;
	int width = grayImage.width(), height = grayImage.height();
	
	//Transfer the green channel from Bayer to output
	startX = (determineBayerColor(0, 0) == G) ? 0 : 1;
	for (int y = 0; y < height; y++)
		for (int x = (y % 2 == 0 ? startX : (startX + 1) % 2); x < width; x += 2)
			rgbImage(G, x, y) = grayImage(x, y);
	
	//Transfer the red channel from Bayer to output
	determineBlockCoord(R, startX, startY);
	for (int y = startY; y < height; y += 2)
		for (int x = startX; x < width; x += 2)
			rgbImage(R, x, y) = grayImage(x, y);
	
	//Transfer the blue channel from Bayer to output
	determineBlockCoord(B, startX, startY);
	for (int y = startY; y < height; y += 2)
		for (int x = startX; x < width; x += 2)
			rgbImage(B, x, y) = grayImage(x, y);
	
	//Use bilinear or edge-sensitive interpolation to construct the incomplete green channel
	startX = (determineBayerColor(0, 0) == G) ? 1 : 0;
	for (int y = 0; y < height; y++)
		for (int x = (y % 2 == 0 ? startX : (startX + 1) % 2); x < width; x += 2)
			//hue_constructGreenChannel(grayImage, rgbImage, x, y);
			hue_constructGreenChannelEdgeSensitive(grayImage, rgbImage, x, y);
	
	//Treating the completed green channel as a luminance channel,
	//assume the red and blue channels are chrominance channels and construct them.
	
	//Calculate red pixels at Bayer blue locations
	determineBlockCoord(B, startX, startY);
	for (int y = startY; y < height; y += 2)
		for (int x = startX; x < width; x += 2)
			hue_constructRedOrBlueAtBlueOrRed(grayImage, rgbImage, *rgbImage[0], x, y);
	
	//Calculate blue pixels at Bayer red locations
	determineBlockCoord(R, startX, startY);
	for (int y = startY; y < height; y += 2)
		for (int x = startX; x < width; x += 2)
			hue_constructRedOrBlueAtBlueOrRed(grayImage, rgbImage, *rgbImage[2], x, y);
	
	//Calculate red pixels at Bayer green locations
	determineBlockCoord(R, startX, startY);
	startX = ++startX % 2;
	for (int y = startY; y < height; y += 2)
		for (int x = startX; x < width; x += 2)
			hue_constructHorizontalRedOrBlueAtGreen(grayImage, rgbImage, *rgbImage[0], x, y);
	
	determineBlockCoord(R, startX, startY);
	startY = ++startY % 2;
	for (int y = startY; y < height; y += 2)
		for (int x = startX; x < width; x += 2)
			hue_constructVerticalRedOrBlueAtGreen(grayImage, rgbImage, *rgbImage[0], x, y);
	
	//Calculate blue pixels at Bayer green locations
	determineBlockCoord(B, startX, startY);
	startX = ++startX % 2;
	for (int y = startY; y < height; y += 2)
		for (int x = startX; x < width; x += 2)
			hue_constructHorizontalRedOrBlueAtGreen(grayImage, rgbImage, *rgbImage[2], x, y);
	
	determineBlockCoord(B, startX, startY);
	startY = ++startY % 2;
	for (int y = startY; y < height; y += 2)
		for (int x = startX; x < width; x += 2)
			hue_constructVerticalRedOrBlueAtGreen(grayImage, rgbImage, *rgbImage[2], x, y);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl 0x28(%rdi), %r13d
movl 0x2c(%rdi), %r12d
xorl %ebp, %ebp
xorl %edi, %edi
xorl %esi, %esi
callq 0x23404
xorl %ecx, %ecx
cmpl $0x1, %eax
setne %cl
movl %ecx, 0x8(%rsp)
testl %r12d, %r12d
jle 0x10713
movl 0x8(%rsp), %r15d
testb $0x1, %bpl
je 0x10707
movl %r15d, %eax
incl %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %r15d, %ecx
incl %ecx
andl $-0x2, %ecx
subl %ecx, %eax
movl %eax, %r15d
jmp 0x10707
movq 0x38(%r14), %rax
movl 0x28(%r14), %ecx
imull %ebp, %ecx
addl %r15d, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl $0x1, %esi
movl %r15d, %edx
movl %ebp, %ecx
callq 0xe55c
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
addl $0x2, %r15d
cmpl %r13d, %r15d
jl 0x106ce
incl %ebp
cmpl %r12d, %ebp
jne 0x106aa
leaq 0x8(%rsp), %rsi
leaq 0xc(%rsp), %r15
xorl %edi, %edi
movq %r15, %rdx
callq 0x2346a
movl (%r15), %ebp
cmpl %r12d, %ebp
jge 0x10776
movl 0x8(%rsp), %r15d
cmpl %r13d, %r15d
jge 0x10771
movq 0x38(%r14), %rax
movl 0x28(%r14), %ecx
imull %ebp, %ecx
addl %r15d, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movl %r15d, %edx
movl %ebp, %ecx
callq 0xe55c
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
addl $0x2, %r15d
jmp 0x10734
addl $0x2, %ebp
jmp 0x1072a
leaq 0x8(%rsp), %rsi
leaq 0xc(%rsp), %r15
movl $0x2, %edi
movq %r15, %rdx
callq 0x2346a
movl (%r15), %ebp
cmpl %r12d, %ebp
jge 0x107df
movl 0x8(%rsp), %r15d
cmpl %r13d, %r15d
jge 0x107da
movq 0x38(%r14), %rax
movl 0x28(%r14), %ecx
imull %ebp, %ecx
addl %r15d, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl $0x2, %esi
movl %r15d, %edx
movl %ebp, %ecx
callq 0xe55c
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
addl $0x2, %r15d
jmp 0x1079a
addl $0x2, %ebp
jmp 0x10790
xorl %ebp, %ebp
xorl %edi, %edi
xorl %esi, %esi
callq 0x23404
xorl %ecx, %ecx
cmpl $0x1, %eax
sete %cl
movl %ecx, 0x8(%rsp)
testl %r12d, %r12d
jle 0x1083f
movl 0x8(%rsp), %r15d
testb $0x1, %bpl
je 0x10833
movl %r15d, %eax
incl %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %r15d, %ecx
incl %ecx
andl $-0x2, %ecx
subl %ecx, %eax
movl %eax, %r15d
jmp 0x10833
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %edx
movl %ebp, %ecx
callq 0xfe53
addl $0x2, %r15d
cmpl %r13d, %r15d
jl 0x1081f
incl %ebp
cmpl %r12d, %ebp
jne 0x107fb
leaq 0x8(%rsp), %rsi
leaq 0xc(%rsp), %r15
movl $0x2, %edi
movq %r15, %rdx
callq 0x2346a
movl (%r15), %ebp
cmpl %r12d, %ebp
jge 0x1088b
movl 0x8(%rsp), %r15d
cmpl %r13d, %r15d
jge 0x10886
movq 0x38(%rbx), %rax
movq (%rax), %rdx
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %ecx
movl %ebp, %r8d
callq 0xffdd
addl $0x2, %r15d
jmp 0x10863
addl $0x2, %ebp
jmp 0x10859
leaq 0x8(%rsp), %rsi
leaq 0xc(%rsp), %r15
xorl %edi, %edi
movq %r15, %rdx
callq 0x2346a
movl (%r15), %ebp
cmpl %r12d, %ebp
jge 0x108d5
movl 0x8(%rsp), %r15d
cmpl %r13d, %r15d
jge 0x108d0
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rdx
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %ecx
movl %ebp, %r8d
callq 0xffdd
addl $0x2, %r15d
jmp 0x108ac
addl $0x2, %ebp
jmp 0x108a2
leaq 0x8(%rsp), %r15
leaq 0xc(%rsp), %rbp
xorl %edi, %edi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x2346a
movl (%r15), %eax
movl %eax, %ecx
incl %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
incl %ecx
andl $-0x2, %ecx
negl %ecx
addl %ecx, %eax
incl %eax
movl %eax, (%r15)
movl (%rbp), %ebp
cmpl %r12d, %ebp
jge 0x1093b
movl 0x8(%rsp), %r15d
cmpl %r13d, %r15d
jge 0x10936
movq 0x38(%rbx), %rax
movq (%rax), %rdx
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %ecx
movl %ebp, %r8d
callq 0x10283
addl $0x2, %r15d
jmp 0x10913
addl $0x2, %ebp
jmp 0x10909
leaq 0x8(%rsp), %rsi
leaq 0xc(%rsp), %r15
xorl %edi, %edi
movq %r15, %rdx
callq 0x2346a
movl (%r15), %eax
movl %eax, %ecx
incl %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
incl %ecx
andl $-0x2, %ecx
negl %ecx
leal (%rax,%rcx), %ebp
incl %ebp
movl %ebp, (%r15)
cmpl %r12d, %ebp
jge 0x1099c
movl 0x8(%rsp), %r15d
cmpl %r13d, %r15d
jge 0x10997
movq 0x38(%rbx), %rax
movq (%rax), %rdx
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %ecx
movl %ebp, %r8d
callq 0x1047e
addl $0x2, %r15d
jmp 0x10974
addl $0x2, %ebp
jmp 0x1096a
leaq 0x8(%rsp), %r15
leaq 0xc(%rsp), %rbp
movl $0x2, %edi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x2346a
movl (%r15), %eax
movl %eax, %ecx
incl %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
incl %ecx
andl $-0x2, %ecx
negl %ecx
addl %ecx, %eax
incl %eax
movl %eax, (%r15)
movl (%rbp), %ebp
cmpl %r12d, %ebp
jge 0x10a06
movl 0x8(%rsp), %r15d
cmpl %r13d, %r15d
jge 0x10a01
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rdx
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %ecx
movl %ebp, %r8d
callq 0x10283
addl $0x2, %r15d
jmp 0x109dd
addl $0x2, %ebp
jmp 0x109d3
leaq 0x8(%rsp), %rsi
leaq 0xc(%rsp), %r15
movl $0x2, %edi
movq %r15, %rdx
callq 0x2346a
movl (%r15), %eax
movl %eax, %ecx
incl %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
incl %ecx
andl $-0x2, %ecx
negl %ecx
leal (%rax,%rcx), %ebp
incl %ebp
movl %ebp, (%r15)
cmpl %r12d, %ebp
jge 0x10a6b
movl 0x8(%rsp), %r15d
cmpl %r13d, %r15d
jge 0x10a66
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rdx
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %ecx
movl %ebp, %r8d
callq 0x1047e
addl $0x2, %r15d
jmp 0x10a42
addl $0x2, %ebp
jmp 0x10a38
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq