// File: /workspace/github_cpp_makefile_star2_O1/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 $0xb8, %rsp
movl %r9d, %ebp
movl %r8d, %r14d
movq %rsi, 0x30(%rsp)
movq %rdi, %r15
leaq 0xa192(%rip), %r12      # 0x1165c
leaq 0x98(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x4c6e
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movl %r14d, %edx
movl %ebp, %ecx
callq 0x4c6e
movl 0x8(%r13), %eax
movl %eax, 0x4(%rsp)
movl 0xc(%r13), %ebp
movq %r13, %rdi
movq %r15, %rsi
callq 0x4cde
movslq 0xc(%rbx), %rcx
movq %rcx, 0x20(%rsp)
testq %rcx, %rcx
jle 0x777c
movl 0x80(%rsp), %eax
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x20(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movl 0x88(%rsp), %r15d
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0xb0(%rsp), %r12
movl 0xa8(%rsp), %r13d
movq 0x90(%rsp), %rcx
movq %rcx, 0x48(%rsp)
movq %rax, 0x28(%rsp)
imull %r15d, %eax
movl %eax, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
cmpl $0x0, 0x28(%rsp)
jle 0x7756
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%rsp), %xmm0
divsd 0x38(%rsp), %xmm0
mulsd 0x40(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rsp)
callq 0x2090
movss (%rsp), %xmm4
subss %xmm0, %xmm4
cvttss2si %xmm0, %ecx
movl 0x4(%rsp), %eax
imull %eax, %ecx
movq %rcx, 0x50(%rsp)
xorps %xmm5, %xmm5
cvtss2sd %xmm4, %xmm5
movsd 0x9c97(%rip), %xmm6     # 0x11288
addss 0xa037(%rip), %xmm0     # 0x11630
cvttss2si %xmm0, %ebx
subsd %xmm5, %xmm6
imull %eax, %ebx
movq 0x10(%rsp), %rax
movl %eax, %r14d
xorl %ebp, %ebp
movss %xmm4, (%rsp)
movsd %xmm5, 0x70(%rsp)
movsd %xmm6, 0x68(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd 0x58(%rsp), %xmm0
mulsd 0x60(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x1c(%rsp)
callq 0x2090
movss 0x1c(%rsp), %xmm7
movsd 0x68(%rsp), %xmm6
movsd 0x70(%rsp), %xmm5
movss (%rsp), %xmm4
testl %r15d, %r15d
jle 0x7745
movslq %r14d, %rax
addq 0x48(%rsp), %rax
cvttss2si %xmm0, %edx
subss %xmm0, %xmm7
movq 0x50(%rsp), %rsi
leal (%rsi,%rdx), %edi
imull %r13d, %edi
xorps %xmm2, %xmm2
cvtss2sd %xmm7, %xmm2
movsd 0x9bfc(%rip), %xmm1     # 0x11288
addss 0x9f9c(%rip), %xmm0     # 0x11630
cvttss2si %xmm0, %ecx
subsd %xmm2, %xmm1
addl %ecx, %esi
imull %r13d, %esi
addl %ebx, %edx
imull %r13d, %edx
addl %ebx, %ecx
imull %r13d, %ecx
movslq %ecx, %rcx
movslq %edx, %rdx
movslq %esi, %rsi
movslq %edi, %rdi
addq %r12, %rdi
addq %r12, %rsi
addq %r12, %rdx
addq %r12, %rcx
xorl %r8d, %r8d
movzbl (%rdi,%r8), %r9d
xorps %xmm0, %xmm0
cvtsi2sd %r9d, %xmm0
mulsd %xmm1, %xmm0
movzbl (%rsi,%r8), %r9d
xorps %xmm2, %xmm2
cvtsi2ss %r9d, %xmm2
mulss %xmm7, %xmm2
cvtss2sd %xmm2, %xmm2
mulsd %xmm6, %xmm2
mulsd %xmm6, %xmm0
addsd %xmm2, %xmm0
movzbl (%rdx,%r8), %r9d
xorps %xmm2, %xmm2
cvtsi2sd %r9d, %xmm2
mulsd %xmm1, %xmm2
movzbl (%rcx,%r8), %r9d
xorps %xmm3, %xmm3
cvtsi2ss %r9d, %xmm3
mulsd %xmm5, %xmm2
addsd %xmm0, %xmm2
mulss %xmm7, %xmm3
mulss %xmm4, %xmm3
xorps %xmm0, %xmm0
cvtss2sd %xmm3, %xmm0
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %r9d
movb %r9b, (%rax,%r8)
incq %r8
cmpq %r8, %r15
jne 0x76c9
incq %rbp
addl %r15d, %r14d
cmpq 0x28(%rsp), %rbp
jne 0x761f
movq 0x8(%rsp), %rcx
incq %rcx
movq 0x10(%rsp), %rax
addl 0x18(%rsp), %eax
movq %rax, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
cmpq 0x20(%rsp), %rcx
jne 0x759b
leaq 0x78(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x4e1a
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop