// File: /workspace/github_cpp_makefile_star2_O2/matthewarcus[P]mmps/transform.cpp
// Function: Transform::TransformImage(Image const&, Image&, TransformParams const&)
void Transform::TransformImage(const Image& inImage, Image& outImage,
			       const TransformParams& params)
{
  int ow = outImage.Width();
  int oh = outImage.Height();
  double orgx = 0.5 * ow;
  double orgy = 0.5 * oh;
  // Scale so that half width is 1
  double scaleFactor = BasicScale(ow,oh) / params.scale;
  int ox, oy; int outIndex = 0;
  //fprintf(stderr,"Rotation %g %g %g %g\n",
  //        params.rotate, params.xoff, params.yoff, scaleFactor);
  for (oy = 0; oy < oh; oy++) {
    double y = scaleFactor * (orgy - oy - 0.5) + params.yoff;
    if (params.rotate == 0) SetY(y);
    for (ox = 0; ox < ow; ox++, outIndex++) {
      // Really ought to just apply a 3x2 matrix to the point
      double x = scaleFactor * (ox + 0.5 - orgx) + params.xoff;
      double x1 = x;
      double y1 = y;
      if (params.rotate != 0) {
	applyRotation(-params.rotate,x1,y1);
	SetY(y1);
      }
      double x0 = 0.0, y0 = 0.0, z0 = 0.0;
      double phi = 0.0, lambda = 0.0;
      if (Project(params, x1, y1, x0, y0, z0, phi, lambda) &&
	  CheckPoint(params,phi, lambda)) {
	SetData(inImage, outImage, params, x0, y0, z0, phi, lambda, outIndex);
      } else if (!params.noback) {
	outImage.SetRgb(outIndex, params.background);
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, 0x88(%rsp)
movq %rdi, %r12
movl (%rdx), %r15d
movl 0x8(%rdx), %r13d
cvtsi2sd %r15d, %xmm0
movsd 0x6458(%rip), %xmm1     # 0xc3f0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x90(%rsp)
cvtsi2sd %r13d, %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x80(%rsp)
movq (%rdi), %rax
movl %r15d, %esi
movl %r13d, %edx
callq *0x18(%rax)
divsd 0x28(%rbx), %xmm0
movsd %xmm0, 0x58(%rsp)
xorl %ebp, %ebp
testl %r15d, %r15d
cmovlel %ebp, %r15d
movl %r15d, 0x34(%rsp)
testl %r13d, %r13d
cmovlel %ebp, %r13d
movl %r13d, 0x38(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %eax, %eax
cmpl 0x38(%rsp), %eax
je 0x625c
movl %eax, 0x3c(%rsp)
movsd 0x80(%rsp), %xmm1
subsd 0x10(%rsp), %xmm1
addsd 0x63f7(%rip), %xmm1     # 0xc410
mulsd 0x58(%rsp), %xmm1
addsd 0xb8(%rbx), %xmm1
movsd 0x10(%rbx), %xmm0
ucomisd 0x63e4(%rip), %xmm0     # 0xc418
movsd %xmm1, 0x8(%rsp)
jne 0x6051
jp 0x6051
movq (%r12), %rax
movq %r12, %rdi
movapd %xmm1, %xmm0
callq *(%rax)
movsd 0x8(%rsp), %xmm1
movslq %ebp, %rbp
leaq 0x2(,%rbp,2), %r13
addq %rbp, %r13
xorpd %xmm0, %xmm0
movl 0x34(%rsp), %r15d
subl $0x1, %r15d
jb 0x623d
movsd %xmm0, 0xa0(%rsp)
addsd 0x636d(%rip), %xmm0     # 0xc3f0
subsd 0x90(%rsp), %xmm0
mulsd 0x58(%rsp), %xmm0
addsd 0xb0(%rbx), %xmm0
movsd 0x10(%rbx), %xmm2
ucomisd 0x6371(%rip), %xmm2     # 0xc418
jne 0x60af
jnp 0x614b
xorpd 0x5fb9(%rip), %xmm2     # 0xc070
movapd %xmm2, 0x40(%rsp)
movsd %xmm0, 0x60(%rsp)
movapd %xmm2, %xmm0
callq 0x43a0
movsd %xmm0, 0x18(%rsp)
movapd 0x40(%rsp), %xmm0
callq 0x4070
mulsd 0x8(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
mulsd 0x60(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movaps 0x40(%rsp), %xmm0
callq 0x4070
movsd %xmm0, 0x98(%rsp)
movapd 0x40(%rsp), %xmm0
callq 0x43a0
mulsd 0x8(%rsp), %xmm0
movsd 0x98(%rsp), %xmm1
mulsd 0x60(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movq (%r12), %rax
movq %r12, %rdi
callq *(%rax)
movsd 0x40(%rsp), %xmm1
movsd 0x18(%rsp), %xmm0
andq $0x0, 0x78(%rsp)
andq $0x0, 0x70(%rsp)
andq $0x0, 0x68(%rsp)
andq $0x0, 0x28(%rsp)
andq $0x0, 0x20(%rsp)
movq (%r12), %rax
leaq 0x20(%rsp), %rcx
movq %rcx, (%rsp)
movq %r12, %rdi
movq %rbx, %rsi
leaq 0x78(%rsp), %rdx
leaq 0x70(%rsp), %rcx
leaq 0x68(%rsp), %r8
leaq 0x28(%rsp), %r9
callq *0x20(%rax)
testb %al, %al
je 0x61ed
movsd 0x28(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movq (%r12), %rax
movq %r12, %rdi
movq %rbx, %rsi
callq *0x30(%rax)
testb %al, %al
je 0x61ed
movsd 0x78(%rsp), %xmm0
movsd 0x70(%rsp), %xmm1
movsd 0x68(%rsp), %xmm2
movsd 0x28(%rsp), %xmm3
movsd 0x20(%rsp), %xmm4
movq %r12, %rdi
movq 0x88(%rsp), %rsi
movq %r14, %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x5cd6
jmp 0x621a
cmpb $0x0, 0x98(%rbx)
jne 0x621a
movq 0x10(%r14), %rax
movb 0xc0(%rbx), %cl
movb %cl, -0x2(%rax,%r13)
movb 0xc1(%rbx), %cl
movb %cl, -0x1(%rax,%r13)
movb 0xc2(%rbx), %cl
movb %cl, (%rax,%r13)
movsd 0xa0(%rsp), %xmm0
addsd 0x5e1d(%rip), %xmm0     # 0xc048
incq %rbp
addq $0x3, %r13
movsd 0x8(%rsp), %xmm1
jmp 0x6068
movsd 0x10(%rsp), %xmm0
addsd 0x5dfd(%rip), %xmm0     # 0xc048
movsd %xmm0, 0x10(%rsp)
movl 0x3c(%rsp), %eax
incl %eax
jmp 0x5ff4
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq