// File: /workspace/github_cpp_makefile_star2_O2/rishabh-battulwar[P]imageprocessing/./include/ImageProc.h
// Function: ImageProc::image_resize(char const*, char const*, int, int, int, int)
void ImageProc::image_resize(const char *infile, const char* outfile, int width, int height, int target_width, int target_height)
{
	Image img_orig("color", width, height);
	Image img_resized("color", target_width, target_height);

	img_orig.read_image(infile, img_orig.cols, img_orig.rows);

	float X, Y, x, y, a, b;

	for(int i = 0; i < img_resized.rows; i++)
		for(int j = 0; j < img_resized.cols; j++)
		{
			x = img_orig.rows * (1.0 * i / img_resized.rows);	//Scaling in x direction
			y = img_orig.cols * (1.0 * j / img_resized.cols);	//Scaling in x direction

			X = floor(x);
			Y = floor(y);

			a = y - Y;
			b = x - X;

			for(int k = 0; k < img_resized.channels; k++)
				img_resized.setvalue(i,j,k,((img_orig.getvalue(X  ,Y  ,k)*(1.0-a)*(1.0-b))
				  						   +(img_orig.getvalue(X  ,Y+1,k)*(    a)*(1.0-b))
				  						   +(img_orig.getvalue(X+1,Y  ,k)*(1.0-a)*(    b))
				  						   +(img_orig.getvalue(X+1,Y+1,k)*(    a)*(    b))		//using 4 surrounding co-ordinates
				  						   )
									);															//BILINEAR INTERPOLATION FORMULATION
		}

	img_resized.write_image(outfile, img_resized.cols, img_resized.rows);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %r9d, %ebp
movl %r8d, %r14d
movq %rsi, 0x28(%rsp)
movq %rdi, %r15
leaq 0xa28a(%rip), %r12      # 0x106c8
leaq 0xa8(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x3fd6
leaq 0x88(%rsp), %rdi
movq %r12, %rsi
movl %r14d, %edx
movl %ebp, %ecx
callq 0x3fd6
movl 0x8(%r13), %ebx
cvtsi2sdl 0xc(%r13), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x4032
leaq 0x88(%rsp), %rsi
movl 0xc(%rsi), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x30(%rsp)
movl %ebx, 0x10(%rsp)
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x60(%rsp)
movl 0x8(%rsi), %ecx
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x58(%rsp)
movl 0x10(%rsi), %edx
movq 0x18(%r13), %rbx
movl 0x10(%r13), %r13d
movq 0x18(%rsi), %rsi
movq %rsi, 0x50(%rsp)
xorl %r14d, %r14d
testl %edx, %edx
movl $0x0, %ebp
cmovgl %edx, %ebp
testl %ecx, %ecx
movl $0x0, %esi
cmovgl %ecx, %esi
movq %rsi, 0x80(%rsp)
testl %eax, %eax
cmovlel %r14d, %eax
movl %eax, 0x14(%rsp)
movl %edx, 0x1c(%rsp)
imull %edx, %ecx
movl %ecx, 0xc(%rsp)
xorpd %xmm0, %xmm0
xorl %eax, %eax
cmpl 0x14(%rsp), %eax
je 0x66d4
movl %eax, 0x18(%rsp)
movsd %xmm0, 0x40(%rsp)
divsd 0x30(%rsp), %xmm0
mulsd 0x38(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
callq 0x2090
movss 0x8(%rsp), %xmm4
subss %xmm0, %xmm4
cvttss2si %xmm0, %ecx
movl 0x10(%rsp), %eax
imull %eax, %ecx
movq %rcx, 0x78(%rsp)
cvtss2sd %xmm4, %xmm5
movsd 0x9d34(%rip), %xmm6     # 0x10288
addss 0xa140(%rip), %xmm0     # 0x1069c
cvttss2si %xmm0, %ecx
subsd %xmm5, %xmm6
imull %eax, %ecx
movl %ecx, 0x20(%rsp)
movq %r14, 0x48(%rsp)
movl %r14d, %r15d
xorl %r12d, %r12d
movss %xmm4, 0x8(%rsp)
movsd %xmm5, 0x70(%rsp)
movsd %xmm6, 0x68(%rsp)
cmpq 0x80(%rsp), %r12
je 0x66b1
movslq %r15d, %r14
addq 0x50(%rsp), %r14
cvtsi2sd %r12d, %xmm0
divsd 0x58(%rsp), %xmm0
mulsd 0x60(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rsp)
callq 0x2090
movss 0x24(%rsp), %xmm7
movsd 0x68(%rsp), %xmm6
movsd 0x70(%rsp), %xmm5
movss 0x8(%rsp), %xmm4
cvttss2si %xmm0, %edx
subss %xmm0, %xmm7
movq 0x78(%rsp), %rcx
leal (%rcx,%rdx), %eax
imull %r13d, %eax
cvtss2sd %xmm7, %xmm2
movsd 0x9c92(%rip), %xmm1     # 0x10288
addss 0xa09e(%rip), %xmm0     # 0x1069c
cvttss2si %xmm0, %esi
subsd %xmm2, %xmm1
addl %esi, %ecx
imull %r13d, %ecx
movl 0x20(%rsp), %edi
addl %edi, %edx
imull %r13d, %edx
addl %edi, %esi
imull %r13d, %esi
cltq
movslq %ecx, %rcx
movslq %edx, %rdx
movslq %esi, %rsi
addq %rbx, %rax
addq %rbx, %rcx
addq %rbx, %rdx
addq %rbx, %rsi
xorl %edi, %edi
cmpq %rdi, %rbp
je 0x66a4
movzbl (%rax,%rdi), %r8d
cvtsi2sd %r8d, %xmm0
movzbl (%rcx,%rdi), %r8d
cvtsi2ss %r8d, %xmm2
mulsd %xmm1, %xmm0
mulss %xmm7, %xmm2
cvtss2sd %xmm2, %xmm2
mulsd %xmm6, %xmm2
mulsd %xmm6, %xmm0
movzbl (%rdx,%rdi), %r8d
cvtsi2sd %r8d, %xmm3
addsd %xmm2, %xmm0
mulsd %xmm1, %xmm3
mulsd %xmm5, %xmm3
addsd %xmm0, %xmm3
movzbl (%rsi,%rdi), %r8d
cvtsi2ss %r8d, %xmm0
mulss %xmm7, %xmm0
mulss %xmm4, %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm3, %xmm0
cvttsd2si %xmm0, %r8d
movb %r8b, (%r14,%rdi)
incq %rdi
jmp 0x6635
incq %r12
addl 0x1c(%rsp), %r15d
jmp 0x6588
movsd 0x40(%rsp), %xmm0
addsd 0x9bc9(%rip), %xmm0     # 0x10288
movl 0x18(%rsp), %eax
incl %eax
movq 0x48(%rsp), %r14
addl 0xc(%rsp), %r14d
jmp 0x64ff
leaq 0x88(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x411c
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq