// File: /workspace/github_cpp_makefile_star2_O3/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 %rsi, 0x88(%rsp)
movq %rdi, %r12
movl (%rdx), %r14d
movq %rdx, 0x50(%rsp)
movl 0x8(%rdx), %ebp
movq (%rdi), %rax
movl %r14d, %esi
movl %ebp, %edx
callq *0x18(%rax)
movsd %xmm0, 0x10(%rsp)
movl %ebp, 0xc(%rsp)
testl %ebp, %ebp
jle 0x6a16
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd 0x6cc9(%rip), %xmm1     # 0xd428
mulsd %xmm1, %xmm0
movsd %xmm0, 0x90(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0xc(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x10(%rsp), %xmm0
divsd 0x28(%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %r15d, %r15d
xorpd %xmm1, %xmm1
xorl %r13d, %r13d
xorl %ebp, %ebp
movl %r14d, 0x38(%rsp)
movsd 0x80(%rsp), %xmm2
subsd %xmm1, %xmm2
addsd 0x6c8f(%rip), %xmm2     # 0xd448
mulsd 0x10(%rsp), %xmm2
addsd 0xb8(%rbx), %xmm2
movsd 0x10(%rbx), %xmm0
ucomisd 0x6c7c(%rip), %xmm0     # 0xd450
movsd %xmm1, 0x58(%rsp)
movsd %xmm2, 0x18(%rsp)
jne 0x67fd
jp 0x67fd
movq (%r12), %rax
movq %r12, %rdi
movapd %xmm2, %xmm0
callq *(%rax)
movsd 0x18(%rsp), %xmm2
movsd 0x58(%rsp), %xmm1
movl %r13d, 0x3c(%rsp)
testl %r14d, %r14d
jle 0x69f6
movslq %ebp, %rax
leaq (%rax,%rax,2), %r13
addq $0x2, %r13
xorpd %xmm0, %xmm0
movsd %xmm0, 0xa0(%rsp)
addsd 0x6bfd(%rip), %xmm0     # 0xd428
subsd 0x90(%rsp), %xmm0
mulsd 0x10(%rsp), %xmm0
addsd 0xb0(%rbx), %xmm0
movsd 0x10(%rbx), %xmm1
ucomisd 0x6c01(%rip), %xmm1     # 0xd450
jne 0x6857
jnp 0x68f5
xorpd 0x6811(%rip), %xmm1     # 0xd070
movapd %xmm1, 0x40(%rsp)
movsd %xmm0, 0x60(%rsp)
movapd %xmm1, %xmm0
callq 0x4370
movsd %xmm0, 0x20(%rsp)
movapd 0x40(%rsp), %xmm0
callq 0x4070
mulsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
mulsd 0x60(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movaps 0x40(%rsp), %xmm0
callq 0x4070
movsd %xmm0, 0x98(%rsp)
movapd 0x40(%rsp), %xmm0
callq 0x4370
mulsd 0x18(%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 0x20(%rsp), %xmm0
jmp 0x68f9
movapd %xmm2, %xmm1
movq %r15, 0x78(%rsp)
movq %r15, 0x70(%rsp)
movq %r15, 0x68(%rsp)
movq %r15, 0x30(%rsp)
movq %r15, 0x28(%rsp)
movq (%r12), %rax
leaq 0x28(%rsp), %rcx
movq %rcx, (%rsp)
movq %r12, %rdi
movq %rbx, %rsi
leaq 0x78(%rsp), %rdx
leaq 0x70(%rsp), %rcx
leaq 0x68(%rsp), %r8
leaq 0x30(%rsp), %r9
callq *0x20(%rax)
testb %al, %al
je 0x6998
movsd 0x30(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movq (%r12), %rax
movq %r12, %rdi
movq %rbx, %rsi
callq *0x30(%rax)
testb %al, %al
je 0x6998
movsd 0x78(%rsp), %xmm0
movsd 0x70(%rsp), %xmm1
movsd 0x68(%rsp), %xmm2
movsd 0x30(%rsp), %xmm3
movsd 0x28(%rsp), %xmm4
movq %r12, %rdi
movq 0x88(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x633c
jmp 0x69ca
cmpb $0x0, 0x98(%rbx)
jne 0x69ca
movq 0x50(%rsp), %rax
movq 0x10(%rax), %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 0x666d(%rip), %xmm0     # 0xd048
incl %ebp
addq $0x3, %r13
decl %r14d
movsd 0x58(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
jne 0x681a
addsd 0x664a(%rip), %xmm1     # 0xd048
movl 0x3c(%rsp), %r13d
incl %r13d
cmpl 0xc(%rsp), %r13d
movl 0x38(%rsp), %r14d
jne 0x67a4
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq