// File: /workspace/github_cpp_makefile_star2_O2/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 0x606ef
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x606dd
callq 0xe5d0
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
jmp 0x60a46
leaq 0x78(%rsp), %rdi
movl %r14d, %esi
movl %edx, %ebp
callq 0x6011e
movl (%rbx), %eax
testl %eax, %eax
jle 0x60a2f
movl 0x4(%rbx), %ecx
testl %ecx, %ecx
jle 0x60a2f
movl %ebp, %edx
cvtsi2sd %eax, %xmm2
cvtsi2sd %r14d, %xmm0
cvtsi2sd %ecx, %xmm3
cvtsi2sd %ebp, %xmm1
xorl %eax, %eax
testl %ebp, %ebp
cmovlel %eax, %edx
divsd %xmm0, %xmm2
movsd %xmm2, 0x38(%rsp)
testl %r14d, %r14d
cmovlel %eax, %r14d
divsd %xmm1, %xmm3
movsd 0x328c6(%rip), %xmm1    # 0x93010
movl %r14d, 0x14(%rsp)
movsd %xmm3, 0x40(%rsp)
movl %edx, 0x18(%rsp)
cmpl %r14d, %eax
je 0x60a2f
movl %eax, 0x4(%rsp)
cvtsi2sd %eax, %xmm2
addsd %xmm1, %xmm2
mulsd 0x38(%rsp), %xmm2
cvttsd2si %xmm2, %ebp
cvttpd2dq %xmm2, %xmm0
leal 0x1(%rbp), %eax
movl %eax, 0x1c(%rsp)
cvtdq2pd %xmm0, %xmm0
movapd %xmm2, %xmm4
subsd %xmm0, %xmm4
movsd 0x32871(%rip), %xmm0    # 0x93008
movapd %xmm4, 0x90(%rsp)
subsd %xmm4, %xmm0
movsd %xmm0, 0x30(%rsp)
xorl %r15d, %r15d
movapd %xmm2, 0xa0(%rsp)
movq %rbp, 0x48(%rsp)
cmpl %r15d, %edx
je 0x60a1f
xorpd %xmm0, %xmm0
ucomisd %xmm2, %xmm0
cvtsi2sd %r15d, %xmm4
addsd %xmm1, %xmm4
jbe 0x607dc
incl %r15d
jmp 0x607bb
movl (%rbx), %eax
cvtsi2sd %eax, %xmm0
ucomisd %xmm0, %xmm2
jae 0x607d7
mulsd %xmm3, %xmm4
xorpd %xmm0, %xmm0
ucomisd %xmm4, %xmm0
ja 0x607d7
movl 0x4(%rbx), %ecx
cvtsi2sd %ecx, %xmm0
ucomisd %xmm0, %xmm4
jae 0x607d7
movapd %xmm4, 0x20(%rsp)
cvttsd2si %xmm4, %r14d
movl 0x1c(%rsp), %edx
cmpl %eax, %edx
movl %ebp, %r13d
cmovll %edx, %r13d
leal 0x1(%r14), %r12d
cmpl %ecx, %r12d
cmovgel %r14d, %r12d
leaq 0x110(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl %r14d, %ecx
callq 0x6036e
leaq 0xf8(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl %r12d, %ecx
callq 0x6036e
leaq 0xe0(%rsp), %rdi
movq %rbx, %rsi
movl %r13d, %edx
movl %r14d, %ecx
callq 0x6036e
leaq 0xc8(%rsp), %rdi
movq %rbx, %rsi
movl %r13d, %edx
movl %r12d, %ecx
callq 0x6036e
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
leaq 0x60(%rsp), %rdi
callq 0x66182
movapd 0x20(%rsp), %xmm1
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
subsd %xmm0, %xmm1
movsd 0x3275c(%rip), %xmm0    # 0x93008
movapd %xmm1, 0x20(%rsp)
subsd %xmm1, %xmm0
movsd 0x30(%rsp), %xmm1
movsd %xmm0, 0x8(%rsp)
mulsd %xmm0, %xmm1
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
leaq 0x110(%rsp), %rsi
movsd %xmm1, 0x58(%rsp)
movapd %xmm1, %xmm0
callq 0x223f6
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x66232
movsd 0x30(%rsp), %xmm0
mulsd 0x20(%rsp), %xmm0
movq %r14, %rdi
leaq 0xf8(%rsp), %rsi
movsd %xmm0, 0x50(%rsp)
callq 0x223f6
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x66232
movsd 0x8(%rsp), %xmm0
mulsd 0x90(%rsp), %xmm0
movq %r14, %rdi
leaq 0xe0(%rsp), %rsi
movsd %xmm0, 0x8(%rsp)
callq 0x223f6
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x66232
movapd 0x20(%rsp), %xmm0
mulsd 0x90(%rsp), %xmm0
movq %r14, %rdi
leaq 0xc8(%rsp), %rsi
movapd %xmm0, 0x20(%rsp)
callq 0x223f6
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x66232
xorpd %xmm1, %xmm1
movsd 0x58(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd 0x50(%rsp), %xmm3
addsd %xmm0, %xmm3
movsd 0x8(%rsp), %xmm2
addsd %xmm3, %xmm2
movapd 0x20(%rsp), %xmm0
addsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jne 0x609d1
jp 0x609d1
leaq 0x78(%rsp), %rdi
movl 0x4(%rsp), %esi
movl %r15d, %edx
leaq 0x47cd61(%rip), %rcx    # 0x4dd730
jmp 0x609f5
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
callq 0x213c7
leaq 0x78(%rsp), %rdi
movl 0x4(%rsp), %esi
movl %r15d, %edx
movq %r14, %rcx
callq 0x604ac
movsd 0x40(%rsp), %xmm3
movsd 0x32608(%rip), %xmm1    # 0x93010
movapd 0xa0(%rsp), %xmm2
movq 0x48(%rsp), %rbp
movl 0x18(%rsp), %edx
jmp 0x607d7
movl 0x4(%rsp), %eax
incl %eax
movl 0x14(%rsp), %r14d
jmp 0x60759
leaq 0x78(%rsp), %rsi
movq %rbx, %rdi
callq 0x603fe
leaq 0x78(%rsp), %rdi
callq 0x60360
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x60a6c
jmp 0x60a6c
jmp 0x60a6c
jmp 0x60a6c
jmp 0x60a6c
jmp 0x60a6c
jmp 0x60a6c
jmp 0x60a6c
jmp 0x60a6c
jmp 0x60a6c
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x60360
movq %rbx, %rdi
callq 0xe810
nop