// File: CodyNault[P]Image-Filter-Dataflow/src/filters.cpp
// Function: Blender::Execute()
void Blender::Execute()
{
	TwoInputCheck();
	if(this->factor < 0 || this->factor > 1){
		char msg[1028];
		sprintf(msg, "Invalid factor for Blender: %f", this->factor);
		DataFlowException except("Blender", msg);
		throw except;
	}
	if(inputImg1->GetWidth() != inputImg2->GetWidth()){
		char msg[1028];
		sprintf(msg, "Blender: widths must match: %d, %d", inputImg1->GetWidth(), inputImg2->GetWidth());
		DataFlowException except("Blender", msg);
		throw except;
	}
	if(inputImg1->GetHeight() != inputImg2->GetHeight()){

		char msg[1028];
		sprintf(msg, "Blender: heights must match: %d, %d", inputImg1->GetHeight(), inputImg2->GetHeight());
		DataFlowException except("Blender", msg);
		throw except;
	}
	int width = inputImg1->GetWidth();
	int height = inputImg1->GetHeight();
	Pixel *buffer1 = inputImg1->GetBuffer();
	Pixel *buffer2 = inputImg2->GetBuffer();
	Pixel *combinedBuffer = new Pixel[ width * height];
	float factor2 = 1.0 - factor;
	float red = 0.0, green = 0.0, blue = 0.0;
	for(int i = 0; i < height; i++)
	{
		for(int j = 0; j < width; j++)
		{
			red = buffer1[i * width + j].red * factor + buffer2[ i * width + j].red * factor2; 
			combinedBuffer[i * width + j].red = static_cast<int>(red);
			green = buffer1[i * width + j].green * factor + buffer2[ i * width + j].green * factor2; 
			combinedBuffer[i * width + j].green = static_cast<int>(green);
			blue = buffer1[i * width + j].blue * factor + buffer2[ i * width + j].blue * factor2; 
			combinedBuffer[i * width + j].blue = static_cast<int>(blue);
		}
	}
	outputImg.ResetSize(width, height);
	outputImg.SetBuffer(combinedBuffer);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x18f0, %rsp           # imm = 0x18F0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x1888(%rbp)
addq $0x28, %rdi
callq 0x4070
movq -0x1888(%rbp), %rax
xorps %xmm0, %xmm0
ucomiss 0x40(%rax), %xmm0
ja 0x6750
movq -0x1888(%rbp), %rax
movss 0x40(%rax), %xmm0
movss 0x2a05(%rip), %xmm1     # 0x914c
ucomiss %xmm1, %xmm0
jbe 0x67ff
movq -0x1888(%rbp), %rax
movss 0x40(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x2a4c(%rip), %rsi      # 0x91b3
leaq -0x410(%rbp), %rdi
movq %rdi, -0x18a0(%rbp)
movb $0x1, %al
callq 0x3050
movq -0x18a0(%rbp), %rdx
leaq 0x2a48(%rip), %rsi      # 0x91d2
leaq -0x818(%rbp), %rdi
movq %rdi, -0x1898(%rbp)
callq 0x8420
movl $0x408, %edi            # imm = 0x408
callq 0x30a0
movq -0x1898(%rbp), %rsi
movq %rax, %rdi
movq %rdi, -0x1890(%rbp)
callq 0x4240
movq -0x1890(%rbp), %rdi
leaq 0x60bd(%rip), %rsi      # 0xc888
leaq -0x2542(%rip), %rdx     # 0x4290
callq 0x31c0
jmp 0x6d91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x820(%rbp)
movl %eax, -0x824(%rbp)
leaq -0x818(%rbp), %rdi
callq 0x4290
jmp 0x6d85
movq -0x1888(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3db0
movl %eax, %ecx
movq -0x1888(%rbp), %rax
movl %ecx, -0x18a4(%rbp)
movq 0x38(%rax), %rdi
callq 0x3db0
movl %eax, %ecx
movl -0x18a4(%rbp), %eax
cmpl %ecx, %eax
je 0x6906
movq -0x1888(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3db0
movl %eax, %ecx
movq -0x1888(%rbp), %rax
movl %ecx, -0x18c4(%rbp)
movq 0x38(%rax), %rdi
callq 0x3db0
movl -0x18c4(%rbp), %edx
movl %eax, %ecx
leaq 0x296c(%rip), %rsi      # 0x91da
xorl %eax, %eax
leaq -0xc30(%rbp), %rdi
movq %rdi, -0x18c0(%rbp)
callq 0x3050
movq -0x18c0(%rbp), %rdx
leaq 0x2941(%rip), %rsi      # 0x91d2
leaq -0x1038(%rbp), %rdi
movq %rdi, -0x18b8(%rbp)
callq 0x8420
movl $0x408, %edi            # imm = 0x408
callq 0x30a0
movq -0x18b8(%rbp), %rsi
movq %rax, %rdi
movq %rdi, -0x18b0(%rbp)
callq 0x4240
movq -0x18b0(%rbp), %rdi
leaq 0x5fb6(%rip), %rsi      # 0xc888
leaq -0x2649(%rip), %rdx     # 0x4290
callq 0x31c0
jmp 0x6d91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x820(%rbp)
movl %eax, -0x824(%rbp)
leaq -0x1038(%rbp), %rdi
callq 0x4290
jmp 0x6d85
movq -0x1888(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3dd0
movl %eax, %ecx
movq -0x1888(%rbp), %rax
movl %ecx, -0x18c8(%rbp)
movq 0x38(%rax), %rdi
callq 0x3dd0
movl %eax, %ecx
movl -0x18c8(%rbp), %eax
cmpl %ecx, %eax
je 0x6a0d
movq -0x1888(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3dd0
movl %eax, %ecx
movq -0x1888(%rbp), %rax
movl %ecx, -0x18e4(%rbp)
movq 0x38(%rax), %rdi
callq 0x3dd0
movl -0x18e4(%rbp), %edx
movl %eax, %ecx
leaq 0x2888(%rip), %rsi      # 0x91fd
xorl %eax, %eax
leaq -0x1440(%rbp), %rdi
movq %rdi, -0x18e0(%rbp)
callq 0x3050
movq -0x18e0(%rbp), %rdx
leaq 0x283a(%rip), %rsi      # 0x91d2
leaq -0x1848(%rbp), %rdi
movq %rdi, -0x18d8(%rbp)
callq 0x8420
movl $0x408, %edi            # imm = 0x408
callq 0x30a0
movq -0x18d8(%rbp), %rsi
movq %rax, %rdi
movq %rdi, -0x18d0(%rbp)
callq 0x4240
movq -0x18d0(%rbp), %rdi
leaq 0x5eaf(%rip), %rsi      # 0xc888
leaq -0x2750(%rip), %rdx     # 0x4290
callq 0x31c0
jmp 0x6d91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x820(%rbp)
movl %eax, -0x824(%rbp)
leaq -0x1848(%rbp), %rdi
callq 0x4290
jmp 0x6d85
movq -0x1888(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3db0
movl %eax, %ecx
movq -0x1888(%rbp), %rax
movl %ecx, -0x184c(%rbp)
movq 0x30(%rax), %rdi
callq 0x3dd0
movl %eax, %ecx
movq -0x1888(%rbp), %rax
movl %ecx, -0x1850(%rbp)
movq 0x30(%rax), %rdi
callq 0x3df0
movq %rax, %rcx
movq -0x1888(%rbp), %rax
movq %rcx, -0x1858(%rbp)
movq 0x38(%rax), %rdi
callq 0x3df0
movq %rax, -0x1860(%rbp)
movl -0x184c(%rbp), %eax
imull -0x1850(%rbp), %eax
cltq
movl $0x3, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, %rcx
movq -0x1888(%rbp), %rax
movq %rcx, -0x1868(%rbp)
movss 0x40(%rax), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x2690(%rip), %xmm0     # 0x9150
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x186c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x1870(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x1874(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x1878(%rbp)
movl $0x0, -0x187c(%rbp)
movl -0x187c(%rbp), %eax
cmpl -0x1850(%rbp), %eax
jge 0x6d49
movl $0x0, -0x1880(%rbp)
movl -0x1880(%rbp), %eax
cmpl -0x184c(%rbp), %eax
jge 0x6d33
movq -0x1888(%rbp), %rax
movq -0x1858(%rbp), %rcx
movl -0x187c(%rbp), %edx
imull -0x184c(%rbp), %edx
addl -0x1880(%rbp), %edx
movslq %edx, %rdx
imulq $0x3, %rdx, %rdx
addq %rdx, %rcx
movzbl (%rcx), %ecx
cvtsi2ss %ecx, %xmm0
movss 0x40(%rax), %xmm2
movq -0x1860(%rbp), %rcx
movl -0x187c(%rbp), %edx
imull -0x184c(%rbp), %edx
addl -0x1880(%rbp), %edx
movslq %edx, %rdx
imulq $0x3, %rdx, %rdx
addq %rdx, %rcx
movzbl (%rcx), %ecx
cvtsi2ss %ecx, %xmm1
mulss -0x186c(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x1870(%rbp)
cvttss2si -0x1870(%rbp), %ecx
movb %cl, %dl
movq -0x1868(%rbp), %rcx
movl -0x187c(%rbp), %esi
imull -0x184c(%rbp), %esi
addl -0x1880(%rbp), %esi
movslq %esi, %rsi
imulq $0x3, %rsi, %rsi
addq %rsi, %rcx
movb %dl, (%rcx)
movq -0x1858(%rbp), %rcx
movl -0x187c(%rbp), %edx
imull -0x184c(%rbp), %edx
addl -0x1880(%rbp), %edx
movslq %edx, %rdx
imulq $0x3, %rdx, %rdx
addq %rdx, %rcx
movzbl 0x1(%rcx), %ecx
cvtsi2ss %ecx, %xmm0
movss 0x40(%rax), %xmm2
movq -0x1860(%rbp), %rcx
movl -0x187c(%rbp), %edx
imull -0x184c(%rbp), %edx
addl -0x1880(%rbp), %edx
movslq %edx, %rdx
imulq $0x3, %rdx, %rdx
addq %rdx, %rcx
movzbl 0x1(%rcx), %ecx
cvtsi2ss %ecx, %xmm1
mulss -0x186c(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x1874(%rbp)
cvttss2si -0x1874(%rbp), %ecx
movb %cl, %dl
movq -0x1868(%rbp), %rcx
movl -0x187c(%rbp), %esi
imull -0x184c(%rbp), %esi
addl -0x1880(%rbp), %esi
movslq %esi, %rsi
imulq $0x3, %rsi, %rsi
addq %rsi, %rcx
movb %dl, 0x1(%rcx)
movq -0x1858(%rbp), %rcx
movl -0x187c(%rbp), %edx
imull -0x184c(%rbp), %edx
addl -0x1880(%rbp), %edx
movslq %edx, %rdx
imulq $0x3, %rdx, %rdx
addq %rdx, %rcx
movzbl 0x2(%rcx), %ecx
cvtsi2ss %ecx, %xmm0
movss 0x40(%rax), %xmm2
movq -0x1860(%rbp), %rax
movl -0x187c(%rbp), %ecx
imull -0x184c(%rbp), %ecx
addl -0x1880(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x3, %rcx, %rcx
addq %rcx, %rax
movzbl 0x2(%rax), %eax
cvtsi2ss %eax, %xmm1
mulss -0x186c(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x1878(%rbp)
cvttss2si -0x1878(%rbp), %eax
movb %al, %cl
movq -0x1868(%rbp), %rax
movl -0x187c(%rbp), %edx
imull -0x184c(%rbp), %edx
addl -0x1880(%rbp), %edx
movslq %edx, %rdx
imulq $0x3, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x2(%rax)
movl -0x1880(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1880(%rbp)
jmp 0x6b17
jmp 0x6d35
movl -0x187c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x187c(%rbp)
jmp 0x6afb
movq -0x1888(%rbp), %rdi
addq $0x8, %rdi
movl -0x184c(%rbp), %esi
movl -0x1850(%rbp), %edx
callq 0x3e90
movq -0x1888(%rbp), %rdi
addq $0x8, %rdi
movq -0x1868(%rbp), %rsi
callq 0x3eb0
addq $0x18f0, %rsp           # imm = 0x18F0
popq %rbp
retq
movq -0x820(%rbp), %rdi
callq 0x31d0
nopw %cs:(%rax,%rax)