// File: /workspace/github_cpp_makefile_star2_O1/matthewarcus[P]mmps/transform.cpp
// Function: Transform::SetData(Image const&, Image&, TransformParams const&, double, double, double, double, double, unsigned int)
void Transform::SetData(const Image& inImage, Image& outImage,
			const TransformParams& params,
			double x, double y, double z,
			double phi, double lambda,
			unsigned int outIndex)	     
{
  unsigned int iw = inImage.Width();
  unsigned int ih = inImage.Height();

  double hh = ih * 0.5;
  double hw = iw * 0.5;
  double sh = ih * oneoverpi;
  double sw = iw * oneovertwopi;

  // Use unsigned so we don't have to test for negative indices
  unsigned int sx = unsigned(floor(hw + lambda * sw));
  // Clamp in case of rounding errors
  if (sx >= iw) sx = 0;

  // Use unsigned so we don't have to test for negative indices

  unsigned int sy = unsigned(floor(hh - phi * sh));
  if (sy >= ih) sy = ih-1;

  Rgb rgb;
  unsigned int inIndex = sy * iw + sx;
  inImage.GetRgb(inIndex, rgb);
  if (params.sun) {
    // Is where we are sunny?
    // Compute pi/2 - angle of the x-axis with the normal at the relevant point.
    // This should be asin(...) but we are only interested in small angles
    // so assume sin x = x
    double sunaltitude = sunx * x + suny * y + sunz * z;
#if 1
    if (sunaltitude < sunriseangle) {
      rgb.Dim(nightdim);
    } else {
      rgb.Dim(0.8 + 0.2 * sunaltitude);
    }
#else
    rgb.Dim(0.6 + 0.5 * sunaltitude * sunaltitude);
#endif
  }
  outImage.SetRgb(outIndex, rgb);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r8d, 0x4(%rsp)
movsd %xmm3, 0x28(%rsp)
movsd %xmm2, 0x18(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
movq %rcx, %r12
movq %rdx, 0x30(%rsp)
movq %rsi, %r13
movq %rdi, %r15
movl (%rsi), %ebp
movl 0x8(%rsi), %ebx
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movsd 0x73ba(%rip), %xmm1     # 0xd438
mulsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %rbp, %xmm0
mulsd %xmm1, %xmm0
movq %rbx, 0x48(%rsp)
fildll 0x48(%rsp)
fldt 0x733d(%rip)            # 0xd3e0
fmulp %st, %st(1)
fstpl 0x38(%rsp)
movq %rbp, 0x50(%rsp)
fildll 0x50(%rsp)
fldt 0x7338(%rip)            # 0xd3f0
fmulp %st, %st(1)
fstpl 0x40(%rsp)
mulsd 0x40(%rsp), %xmm4
addsd %xmm4, %xmm0
callq 0x4320
cvttsd2si %xmm0, %rax
xorl %r14d, %r14d
cmpl %ebp, %eax
cmovbl %eax, %r14d
movsd 0x28(%rsp), %xmm0
mulsd 0x38(%rsp), %xmm0
addsd 0x20(%rsp), %xmm0
callq 0x4320
cvttsd2si %xmm0, %rax
leal -0x1(%rbx), %edx
cmpl %ebx, %eax
cmovbl %eax, %edx
imull %ebp, %edx
addl %r14d, %edx
movq 0x10(%r13), %rsi
addq %rdx, %rsi
addq %rdx, %rsi
movb (%rdx,%rsi), %al
movb 0x1(%rdx,%rsi), %cl
movb 0x2(%rdx,%rsi), %dl
cmpb $0x1, 0x78(%r12)
jne 0x61c3
movsd 0x8(%rsp), %xmm1
mulsd 0xb0(%r15), %xmm1
movsd 0x10(%rsp), %xmm0
mulsd 0xa8(%r15), %xmm0
addsd %xmm1, %xmm0
movsd 0x18(%rsp), %xmm1
mulsd 0xb8(%r15), %xmm1
addsd %xmm0, %xmm1
movsd 0x72dd(%rip), %xmm0     # 0xd440
ucomisd %xmm1, %xmm0
jbe 0x617d
movzbl %al, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x72bd(%rip), %xmm1     # 0xd438
jmp 0x6197
mulsd 0x72c3(%rip), %xmm1     # 0xd448
addsd 0x72c3(%rip), %xmm1     # 0xd450
movzbl %al, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movzbl %cl, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movzbl %dl, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movl 0x4(%rsp), %esi
movq 0x30(%rsp), %rdi
movq 0x10(%rdi), %rdi
addq %rsi, %rdi
addq %rsi, %rdi
movb %al, (%rsi,%rdi)
movb %cl, 0x1(%rsi,%rdi)
movb %dl, 0x2(%rsi,%rdi)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq