// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/GSV/GSVCamera.cpp
// Function: gaps::GSVCamera::UndistortImage(gaps::R2Image const&, gaps::R2Image&) const
int GSVCamera::
UndistortImage(const R2Image& input, R2Image& output) const
{
  // Get convenient variables
  double xscale = (double) output.Width() / (double) input.Width();
  double yscale = (double) output.Height() / (double) input.Height();
  R2Box input_bbox(0, 0, input.Width()-1, input.Height()-1);

  // Create undistorted image (output) from distorted image (input)
  // Removes radial distortion
  for (int x = 0; x < output.Width(); x++) {
    for (int y = 0; y < output.Height(); y++) {
      R2Point output_position(x,y);
      output_position[0] *= xscale;
      output_position[1] *= yscale;
      R2Point input_position = DistortedPosition(output_position);
      if (R2Contains(input_bbox, input_position)) {
        int ix1 = (int) input_position[0];
        int iy1 = (int) input_position[1];
        int ix2 = ix1 + 1;
        int iy2 = iy1 + 1;
        if (ix2 >= input.Width()) ix2 = ix1;
        if (iy2 >= input.Height()) iy2 = iy1;
        double dx = input_position[0] - ix1;
        double dy = input_position[1] - iy1;
        RNRgb pixel1 = (1-dx) * input.PixelRGB(ix1, iy1) + dx * input.PixelRGB(ix2, iy1);
        RNRgb pixel2 = (1-dx) * input.PixelRGB(ix1, iy2) + dx * input.PixelRGB(ix2, iy2);
        RNRgb pixel = (1-dy) * pixel1 + dy * pixel2;
        output.SetPixelRGB(x, y, pixel);
      }
      else {
        output.SetPixelRGB(x, y, RNblack_rgb);
      }
    }
  }

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, 0x50(%rsp)
movq %rdx, 0x10(%rsp)
cvtdq2pd (%rdx), %xmm2
movq %rsi, 0x18(%rsp)
movq (%rsi), %rax
movq %rax, %xmm0
cvtdq2pd %xmm0, %xmm1
divpd %xmm1, %xmm2
movapd %xmm2, 0x90(%rsp)
decl %eax
cvtsi2sd %eax, %xmm2
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %eax
decl %eax
cvtsi2sd %eax, %xmm3
leaq 0xa8(%rsp), %rdi
pxor %xmm0, %xmm0
xorpd %xmm1, %xmm1
callq 0xd8846
xorl %ecx, %ecx
leaq 0x40(%rsp), %rbx
leaq 0x118(%rsp), %r13
movq 0x10(%rsp), %rax
cmpl (%rax), %ecx
jge 0x39f3c
movl %ecx, 0x8(%rsp)
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x58(%rsp)
xorl %ecx, %ecx
movq 0x10(%rsp), %rax
cmpl 0x4(%rax), %ecx
jge 0x39f31
movl %ecx, 0xc(%rsp)
cvtsi2sd %ecx, %xmm1
movq %rbx, %rdi
movsd 0x58(%rsp), %xmm0
callq 0xdb258
movapd 0x40(%rsp), %xmm0
mulpd 0x90(%rsp), %xmm0
movapd %xmm0, 0x40(%rsp)
leaq 0x68(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq %rbx, %rdx
callq 0x39b6a
movl 0xc(%rsp), %ebx
leaq 0xa8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0xc99b8
testl %eax, %eax
je 0x39f0c
movsd 0x68(%rsp), %xmm1
movsd 0x70(%rsp), %xmm0
movapd %xmm1, 0x20(%rsp)
cvttsd2si %xmm1, %r12d
movapd %xmm0, 0x30(%rsp)
cvttsd2si %xmm0, %ebp
leal 0x1(%r12), %ebx
leal 0x1(%rbp), %r15d
movq 0x18(%rsp), %rsi
cmpl (%rsi), %ebx
cmovgel %r12d, %ebx
cmpl 0x4(%rsi), %r15d
cmovgel %ebp, %r15d
leaq 0x78(%rsp), %r14
movq %r14, %rdi
movl %r12d, %edx
movl %ebp, %ecx
callq 0xdc03a
movapd 0x20(%rsp), %xmm1
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
subsd %xmm0, %xmm1
movsd 0xf129f(%rip), %xmm0    # 0x12b070
movapd %xmm1, 0x20(%rsp)
subsd %xmm1, %xmm0
leaq 0xe8(%rsp), %rdi
movq %r14, %rsi
movsd %xmm0, 0x60(%rsp)
callq 0x3a2ca
movq %r13, %rdi
movq 0x18(%rsp), %rsi
movl %ebx, %edx
movl %ebp, %ecx
callq 0xdc03a
leaq 0xe8(%rsp), %r14
leaq 0x130(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movapd 0x20(%rsp), %xmm0
callq 0x3a2ca
leaq 0x100(%rsp), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x3a2a0
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
callq 0xdc03a
leaq 0x78(%rsp), %rdi
movq %rbp, %rsi
movsd 0x60(%rsp), %xmm0
callq 0x3a2ca
leaq 0xd0(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl %ebx, %edx
movl %r15d, %ecx
callq 0xdc03a
movq %r13, %rdi
leaq 0xd0(%rsp), %rsi
movapd 0x20(%rsp), %xmm0
callq 0x3a2ca
movq %r14, %rdi
leaq 0x78(%rsp), %rsi
movq %r13, %rdx
callq 0x3a2a0
movapd 0x30(%rsp), %xmm1
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
subsd %xmm0, %xmm1
movsd 0xf11bd(%rip), %xmm0    # 0x12b070
movapd %xmm1, 0x30(%rsp)
subsd %xmm1, %xmm0
movq %rbp, %rdi
leaq 0x100(%rsp), %rsi
callq 0x3a2ca
movq %r13, %rdi
movq %r14, %rsi
movapd 0x30(%rsp), %xmm0
callq 0x3a2ca
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x3a2a0
movq 0x10(%rsp), %rdi
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
movq %rbx, %rcx
callq 0xdc178
movl 0xc(%rsp), %ebx
jmp 0x39f23
movq 0x10(%rsp), %rdi
movl 0x8(%rsp), %esi
movl %ebx, %edx
leaq 0x58f122(%rip), %rcx    # 0x5c9040
callq 0xdc178
incl %ebx
movl %ebx, %ecx
leaq 0x40(%rsp), %rbx
jmp 0x39cff
movl 0x8(%rsp), %ecx
incl %ecx
jmp 0x39ce2
leaq 0xa8(%rsp), %rdi
callq 0xd8fba
pushq $0x1
popq %rax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x39f6e
jmp 0x39f6e
jmp 0x39f6e
jmp 0x39f6e
jmp 0x39f6e
jmp 0x39f6e
jmp 0x39f6e
jmp 0x39f6e
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0xd8fba
movq %rbx, %rdi
callq 0x28170