// File: 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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
leaq 0x109aa(%rip), %rsi     # 0x1c5e8
movq %rsi, -0x98(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x7eb0
movq -0x98(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
leaq -0x60(%rbp), %rdi
callq 0x7eb0
jmp 0xbc66
movq -0x8(%rbp), %rsi
movl -0x38(%rbp), %edx
movl -0x34(%rbp), %ecx
leaq -0x40(%rbp), %rdi
callq 0x7f70
jmp 0xbc7b
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0xbf9c
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x58(%rbp), %eax
jge 0xbf86
cvtsi2sdl -0x34(%rbp), %xmm0
cvtsi2sdl -0x88(%rbp), %xmm1
cvtsi2sdl -0x54(%rbp), %xmm2
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x78(%rbp)
cvtsi2sdl -0x38(%rbp), %xmm0
cvtsi2sdl -0x8c(%rbp), %xmm1
cvtsi2sdl -0x58(%rbp), %xmm2
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x7c(%rbp)
movss -0x78(%rbp), %xmm0
callq 0x1b2d0
movss %xmm0, -0x9c(%rbp)
jmp 0xbd07
movss -0x9c(%rbp), %xmm0
movss %xmm0, -0x70(%rbp)
movss -0x7c(%rbp), %xmm0
callq 0x1b2d0
movss %xmm0, -0xa0(%rbp)
jmp 0xbd28
movss -0xa0(%rbp), %xmm0
movss %xmm0, -0x74(%rbp)
movss -0x7c(%rbp), %xmm0
subss -0x74(%rbp), %xmm0
movss %xmm0, -0x80(%rbp)
movss -0x78(%rbp), %xmm0
subss -0x70(%rbp), %xmm0
movss %xmm0, -0x84(%rbp)
movl $0x0, -0x90(%rbp)
movl -0x90(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0xbf70
movl -0x88(%rbp), %eax
movl %eax, -0xac(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0xa4(%rbp)
cvttss2si -0x70(%rbp), %esi
cvttss2si -0x74(%rbp), %edx
movl -0x90(%rbp), %ecx
leaq -0x40(%rbp), %rdi
callq 0x83b0
cvtsi2sd %eax, %xmm0
movss -0x80(%rbp), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x104a7(%rip), %xmm1    # 0x1c268
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
movss -0x84(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x10483(%rip), %xmm0    # 0x1c268
subsd %xmm1, %xmm0
movsd %xmm0, -0xc8(%rbp)
cvttss2si -0x70(%rbp), %esi
movss 0x107ca(%rip), %xmm0    # 0x1c5c8
addss -0x74(%rbp), %xmm0
cvttss2si %xmm0, %edx
movl -0x90(%rbp), %ecx
leaq -0x40(%rbp), %rdi
callq 0x83b0
movsd -0xd0(%rbp), %xmm0
movsd -0xc8(%rbp), %xmm2
cvtsi2ss %eax, %xmm1
mulss -0x80(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0x84(%rbp), %xmm3
cvtss2sd %xmm3, %xmm4
movsd 0x10421(%rip), %xmm3    # 0x1c268
subsd %xmm4, %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xc0(%rbp)
movss 0x10761(%rip), %xmm0    # 0x1c5c8
addss -0x70(%rbp), %xmm0
cvttss2si %xmm0, %esi
cvttss2si -0x74(%rbp), %edx
movl -0x90(%rbp), %ecx
leaq -0x40(%rbp), %rdi
callq 0x83b0
movsd -0xc0(%rbp), %xmm1
cvtsi2sd %eax, %xmm0
movss -0x80(%rbp), %xmm2
cvtss2sd %xmm2, %xmm3
movsd 0x103c7(%rip), %xmm2    # 0x1c268
subsd %xmm3, %xmm2
mulsd %xmm2, %xmm0
movss -0x84(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movss 0x106fb(%rip), %xmm0    # 0x1c5c8
addss -0x70(%rbp), %xmm0
cvttss2si %xmm0, %esi
movss 0x106ea(%rip), %xmm0    # 0x1c5c8
addss -0x74(%rbp), %xmm0
cvttss2si %xmm0, %edx
movl -0x90(%rbp), %ecx
leaq -0x40(%rbp), %rdi
callq 0x83b0
movsd -0xb8(%rbp), %xmm0
movl -0xac(%rbp), %esi
movl -0xa8(%rbp), %edx
movl -0xa4(%rbp), %ecx
cvtsi2ss %eax, %xmm1
mulss -0x80(%rbp), %xmm1
mulss -0x84(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r8d
leaq -0x60(%rbp), %rdi
callq 0x83f0
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0xbd60
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xbfcc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x1b2c0
jmp 0xbfcc
jmp 0xbf72
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0xbc9e
jmp 0xbf88
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0xbc85
movq -0x10(%rbp), %rsi
movl -0x58(%rbp), %edx
movl -0x54(%rbp), %ecx
leaq -0x60(%rbp), %rdi
callq 0x8150
jmp 0xbfb1
leaq -0x60(%rbp), %rdi
callq 0x1b2c0
leaq -0x40(%rbp), %rdi
callq 0x1b2c0
addq $0xd0, %rsp
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x1b2c0
movq -0x68(%rbp), %rdi
callq 0x2360
nop