// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::Resize(int, int, int)
void R2Image::
Resize(int w, int h, int c)
{
  // Check if empty size
  if ((w == 0) || (h == 0) || (c == 0)) {
    if (pixels) delete [] pixels;
    pixels = NULL;
    width = 0;
    height = 0;
    ncomponents = 0;
    rowsize = 0;
  }
  else {
    // Create output image
    R2Image output(w, h, c);
    if ((width > 0) && (height > 0)) {
      // Compute scale factors
      RNScalar xfactor = (RNScalar) width / (RNScalar) w;
      RNScalar yfactor = (RNScalar) height / (RNScalar) h;

      // Resample original image
      for (int ix = 0; ix < w; ix++) {
        for (int iy = 0; iy < h; iy++) {
          double x = (ix+0.5) * xfactor;
          double y = (iy+0.5) * yfactor;
          if ((x < 0) || (x >= width)) continue;
          if ((y < 0) || (y >= height)) continue;

          // Bilinear interpolation
          int ix1 = (int) x;
          int iy1 = (int) y;
          int ix2 = ix1 + 1;
          int iy2 = iy1 + 1;
          if (ix2 >= width) ix2 = ix1;
          if (iy2 >= height) iy2 = iy1;
          RNScalar dx = x - ix1;
          RNScalar dy = y - iy1;
          RNRgb color11 = PixelRGB(ix1, iy1);
          RNRgb color12 = PixelRGB(ix1, iy2);
          RNRgb color21 = PixelRGB(ix2, iy1);
          RNRgb color22 = PixelRGB(ix2, iy2);
          RNScalar weight11 = (1.0-dx) * (1.0-dy);
          RNScalar weight12 = (1.0-dx) * dy;
          RNScalar weight21 = dx * (1.0-dy);
          RNScalar weight22 = dx * dy;
          RNRgb color(0,0,0);
          RNScalar weight = 0;
          color += weight11 * color11; weight += weight11; 
          color += weight12 * color12; weight += weight12;
          color += weight21 * color21; weight += weight21;
          color += weight22 * color22; weight += weight22;
          if (weight == 0) output.SetPixelRGB(ix, iy, RNblack_rgb);
          else output.SetPixelRGB(ix, iy, color / weight);
        }
      }
    }
    
    // Copy output to this image
    *this = output;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movl %esi, %r14d
movq %rdi, %rbx
testl %esi, %esi
setne %al
testl %edx, %edx
setne %sil
andb %al, %sil
testl %ecx, %ecx
setne %al
testb %al, %sil
jne 0x69270
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x6925b
callq 0xe5b0
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
jmp 0x69676
leaq 0x78(%rsp), %rdi
movl %r14d, %esi
movl %edx, 0xc(%rsp)
callq 0x68c5a
movl 0xc(%rsp), %edx
movl (%rbx), %eax
testl %eax, %eax
jle 0x69657
movl 0x4(%rbx), %ecx
testl %ecx, %ecx
jle 0x69657
testl %r14d, %r14d
jle 0x69657
cvtsi2sd %eax, %xmm1
cvtsi2sd %r14d, %xmm0
cvtsi2sd %ecx, %xmm2
divsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
divsd %xmm0, %xmm2
movl $0x0, 0x8(%rsp)
movsd 0x38d5b(%rip), %xmm1    # 0xa2030
movl %r14d, 0x18(%rsp)
movsd %xmm2, 0x58(%rsp)
testl %edx, %edx
jle 0x6963f
xorps %xmm3, %xmm3
cvtsi2sdl 0x8(%rsp), %xmm3
addsd %xmm1, %xmm3
mulsd 0x50(%rsp), %xmm3
cvttsd2si %xmm3, %ebp
cvttpd2dq %xmm3, %xmm0
leal 0x1(%rbp), %eax
movl %eax, 0x1c(%rsp)
cvtdq2pd %xmm0, %xmm0
movapd %xmm3, %xmm4
subsd %xmm0, %xmm4
movsd 0x38d1a(%rip), %xmm0    # 0xa2038
movapd %xmm4, 0x90(%rsp)
subsd %xmm4, %xmm0
movsd %xmm0, 0x30(%rsp)
xorl %r12d, %r12d
movapd %xmm3, 0x100(%rsp)
movq %rbp, 0x60(%rsp)
xorpd %xmm0, %xmm0
ucomisd %xmm3, %xmm0
xorps %xmm4, %xmm4
cvtsi2sd %r12d, %xmm4
addsd %xmm1, %xmm4
jbe 0x69365
incl %r12d
cmpl %r12d, %edx
jne 0x69342
jmp 0x6963f
movl (%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
ucomisd %xmm0, %xmm3
jae 0x69358
mulsd %xmm2, %xmm4
xorpd %xmm0, %xmm0
ucomisd %xmm4, %xmm0
ja 0x69358
movl 0x4(%rbx), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
ucomisd %xmm0, %xmm4
jae 0x69358
movapd %xmm4, 0x20(%rsp)
cvttsd2si %xmm4, %r13d
movl 0x1c(%rsp), %edx
cmpl %eax, %edx
movl %ebp, %r14d
cmovll %edx, %r14d
leal 0x1(%r13), %r15d
cmpl %ecx, %r15d
cmovgel %r13d, %r15d
leaq 0xe8(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl %r13d, %ecx
callq 0x68ec2
leaq 0xd0(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x68ec2
leaq 0xb8(%rsp), %rdi
movq %rbx, %rsi
movl %r14d, %edx
movl %r13d, %ecx
callq 0x68ec2
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
movl %r14d, %edx
movl %r15d, %ecx
callq 0x68ec2
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
leaq 0x38(%rsp), %rdi
callq 0x6f680
movapd 0x20(%rsp), %xmm1
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
subsd %xmm0, %xmm1
movsd 0x38bfd(%rip), %xmm0    # 0xa2038
movapd %xmm1, 0x20(%rsp)
subsd %xmm1, %xmm0
movsd 0x30(%rsp), %xmm3
movsd %xmm0, 0x10(%rsp)
mulsd %xmm0, %xmm3
movsd 0xe8(%rsp), %xmm0
mulsd %xmm3, %xmm0
movsd 0xf0(%rsp), %xmm1
mulsd %xmm3, %xmm1
movsd 0xf8(%rsp), %xmm2
movsd %xmm3, 0x70(%rsp)
mulsd %xmm3, %xmm2
leaq 0x110(%rsp), %r14
movq %r14, %rdi
callq 0x6f680
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x6f732
movsd 0x30(%rsp), %xmm3
mulsd 0x20(%rsp), %xmm3
movsd 0xd0(%rsp), %xmm0
mulsd %xmm3, %xmm0
movsd 0xd8(%rsp), %xmm1
mulsd %xmm3, %xmm1
movsd 0xe0(%rsp), %xmm2
movsd %xmm3, 0x68(%rsp)
mulsd %xmm3, %xmm2
movq %r14, %rdi
callq 0x6f680
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x6f732
movsd 0x10(%rsp), %xmm3
mulsd 0x90(%rsp), %xmm3
movsd 0xb8(%rsp), %xmm0
mulsd %xmm3, %xmm0
movsd 0xc0(%rsp), %xmm1
mulsd %xmm3, %xmm1
movsd 0xc8(%rsp), %xmm2
movsd %xmm3, 0x10(%rsp)
mulsd %xmm3, %xmm2
movq %r14, %rdi
callq 0x6f680
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x6f732
movapd 0x20(%rsp), %xmm3
mulsd 0x90(%rsp), %xmm3
movsd 0xa0(%rsp), %xmm0
mulsd %xmm3, %xmm0
movsd 0xa8(%rsp), %xmm1
mulsd %xmm3, %xmm1
movsd 0xb0(%rsp), %xmm2
movapd %xmm3, 0x20(%rsp)
mulsd %xmm3, %xmm2
movq %r14, %rdi
callq 0x6f680
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x6f732
xorpd %xmm0, %xmm0
movsd 0x70(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x68(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd 0x10(%rsp), %xmm1
addsd %xmm2, %xmm1
movapd 0x20(%rsp), %xmm3
addsd %xmm1, %xmm3
ucomisd %xmm0, %xmm3
jne 0x695d8
jp 0x695d8
leaq 0x78(%rsp), %rdi
movl 0x8(%rsp), %esi
movl %r12d, %edx
leaq 0x47f14a(%rip), %rcx    # 0x4e8720
jmp 0x69615
movsd 0x38(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
divsd %xmm3, %xmm0
divsd %xmm3, %xmm1
movsd 0x48(%rsp), %xmm2
divsd %xmm3, %xmm2
leaq 0x110(%rsp), %r14
movq %r14, %rdi
callq 0x6f680
leaq 0x78(%rsp), %rdi
movl 0x8(%rsp), %esi
movl %r12d, %edx
movq %r14, %rcx
callq 0x6900a
movsd 0x58(%rsp), %xmm2
movsd 0x38a08(%rip), %xmm1    # 0xa2030
movapd 0x100(%rsp), %xmm3
movq 0x60(%rsp), %rbp
movl 0xc(%rsp), %edx
jmp 0x69358
movl 0x8(%rsp), %eax
incl %eax
movl 0x18(%rsp), %r14d
movl %eax, 0x8(%rsp)
cmpl %r14d, %eax
jne 0x692e0
leaq 0x78(%rsp), %rsi
movq %rbx, %rdi
callq 0x68f52
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x69676
callq 0xe5b0
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6969c
jmp 0x6969c
jmp 0x6969c
jmp 0x6969c
jmp 0x6969c
jmp 0x6969c
jmp 0x6969c
jmp 0x6969c
jmp 0x6969c
jmp 0x6969c
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x696b1
callq 0xe5b0
movq %rbx, %rdi
callq 0xe7e0
nop