// File: /workspace/github_cpp_makefile_star2_O3/kebwi[P]Trifid/src/SteerablePyramid.cpp
// Function: SteerablePyramid::CopyCoefficients(SteerablePyramid const&, std::vector<double, std::allocator<double>>)
void SteerablePyramid::CopyCoefficients(const SteerablePyramid& sp, vector<Float_t> thresholds)
{
	assert(width_ == sp.width_ && height_ == sp.height_ && numLevels_ == sp.numLevels_);
	assert(thresholds.size() == numLevels_);
	
	for (int level = 0; level < numLevels_; level++)
	{
		int totalPixels = (width_ * height_) / (int)(pow(4, level));
		Float_t threshold = thresholds[level];
		
		//cout << "Level/Threshold: " << level << "    " << threshold << endl;
		
		//A threshold of -1 is a flag to not copy this level
		if (threshold == -1)
			continue;
		
		//A lower threshold is more likely to cause a change and causes a more drastic change.
		//A threshold of zero changes all coefficients and sets them precisely to sp's coefficients.
		
		//Use threshold as a diff between the two coefficients
		for (int i = 0; i < totalPixels; i++)
		{
			if (level == 0)
			{
				if (h0Coeffs_[i] < sp.h0Coeffs_[i] - threshold)
					h0Coeffs_[i] = sp.h0Coeffs_[i] - threshold;
				else if (h0Coeffs_[i] > sp.h0Coeffs_[i] + threshold)
					h0Coeffs_[i] = sp.h0Coeffs_[i] + threshold;
			}
			
			if (b1Coeffs_[level][i] < sp.b1Coeffs_[level][i] - threshold)
				b1Coeffs_[level][i] = sp.b1Coeffs_[level][i] - threshold;
			else if (b1Coeffs_[level][i] > sp.b1Coeffs_[level][i] + threshold)
				b1Coeffs_[level][i] = sp.b1Coeffs_[level][i] + threshold;
			
			if (b2Coeffs_[level][i] < sp.b2Coeffs_[level][i] - threshold)
				b2Coeffs_[level][i] = sp.b2Coeffs_[level][i] - threshold;
			else if (b2Coeffs_[level][i] > sp.b2Coeffs_[level][i] + threshold)
				b2Coeffs_[level][i] = sp.b2Coeffs_[level][i] + threshold;
			
			if (b3Coeffs_[level][i] < sp.b3Coeffs_[level][i] - threshold)
				b3Coeffs_[level][i] = sp.b3Coeffs_[level][i] - threshold;
			else if (b3Coeffs_[level][i] > sp.b3Coeffs_[level][i] + threshold)
				b3Coeffs_[level][i] = sp.b3Coeffs_[level][i] + threshold;
			
			if (b4Coeffs_[level][i] < sp.b4Coeffs_[level][i] - threshold)
				b4Coeffs_[level][i] = sp.b4Coeffs_[level][i] - threshold;
			else if (b4Coeffs_[level][i] > sp.b4Coeffs_[level][i] + threshold)
				b4Coeffs_[level][i] = sp.b4Coeffs_[level][i] + threshold;
		}
		
		/*
		//Use threshold as a ratio between the two coefficients
		for (int i = 0; i < totalPixels; i++)
		{
			if (level == 0)
				if (fabs(h0Coeffs_[i]) < fabs(sp.h0Coeffs_[i]) * threshold)
					h0Coeffs_[i] = sp.h0Coeffs_[i];
			if (fabs(b1Coeffs_[level][i]) < fabs(sp.b1Coeffs_[level][i]) * threshold)
				b1Coeffs_[level][i] = sp.b1Coeffs_[level][i];
			if (fabs(b2Coeffs_[level][i]) < fabs(sp.b2Coeffs_[level][i]) * threshold)
				b2Coeffs_[level][i] = sp.b2Coeffs_[level][i];
			if (fabs(b3Coeffs_[level][i]) < fabs(sp.b3Coeffs_[level][i]) * threshold)
				b3Coeffs_[level][i] = sp.b3Coeffs_[level][i];
			if (fabs(b4Coeffs_[level][i]) < fabs(sp.b4Coeffs_[level][i]) * threshold)
				b4Coeffs_[level][i] = sp.b4Coeffs_[level][i];
		}
		*/
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, (%rsp)
movl 0x30(%rdi), %eax
cmpl 0x30(%rsi), %eax
jne 0x1f15b
movq %rsi, %r14
movq %rdi, %r15
movl 0x34(%rdi), %eax
cmpl 0x34(%rsi), %eax
jne 0x1f15b
movslq 0x38(%r15), %rax
cmpl 0x38(%r14), %eax
jne 0x1f15b
movq (%rsp), %rdx
movq 0x8(%rdx), %rcx
subq (%rdx), %rcx
sarq $0x3, %rcx
cmpq %rax, %rcx
jne 0x1f17a
testl %eax, %eax
jle 0x1f14c
xorl %r12d, %r12d
movl 0x34(%r15), %ebp
imull 0x30(%r15), %ebp
leal (%r12,%r12), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
callq 0x32a0
cvttsd2si %xmm0, %ecx
movl %ebp, %eax
cltd
idivl %ecx
movq (%rsp), %rcx
movq (%rcx), %rcx
movsd (%rcx,%r12,8), %xmm0
ucomisd 0xb086(%rip), %xmm0     # 0x2a070
jne 0x1eff2
jnp 0x1f13c
testl %eax, %eax
jle 0x1f13c
movq (%r15), %rcx
movq 0x8(%r15), %rsi
movq (%r14), %rdx
movq 0x8(%r14), %rdi
movq (%rsi,%r12,8), %rsi
movq (%rdi,%r12,8), %rdi
movq 0x10(%r15), %r8
movq (%r8,%r12,8), %r8
movq 0x10(%r14), %r9
movq (%r9,%r12,8), %r9
movq 0x18(%r15), %r10
movq (%r10,%r12,8), %r10
movq 0x18(%r14), %r11
movq (%r11,%r12,8), %r11
movq 0x20(%r15), %rbx
movq (%rbx,%r12,8), %r13
movq 0x20(%r14), %rbx
movq (%rbx,%r12,8), %rbp
movl %eax, %eax
shlq $0x3, %rax
xorl %ebx, %ebx
testq %r12, %r12
jne 0x1f078
movsd (%rcx,%rbx), %xmm1
movsd (%rdx,%rbx), %xmm2
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
ucomisd %xmm1, %xmm3
ja 0x1f073
addsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
movapd %xmm2, %xmm3
jbe 0x1f078
movsd %xmm3, (%rcx,%rbx)
movsd (%rsi,%rbx), %xmm1
movsd (%rdi,%rbx), %xmm2
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
ucomisd %xmm1, %xmm3
ja 0x1f09e
addsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
movapd %xmm2, %xmm3
jbe 0x1f0a3
movsd %xmm3, (%rsi,%rbx)
movsd (%r8,%rbx), %xmm1
movsd (%r9,%rbx), %xmm2
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
ucomisd %xmm1, %xmm3
ja 0x1f0cb
addsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
movapd %xmm2, %xmm3
jbe 0x1f0d1
movsd %xmm3, (%r8,%rbx)
movsd (%r10,%rbx), %xmm1
movsd (%r11,%rbx), %xmm2
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
ucomisd %xmm1, %xmm3
ja 0x1f0f9
addsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
movapd %xmm2, %xmm3
jbe 0x1f0ff
movsd %xmm3, (%r10,%rbx)
movsd (%r13,%rbx), %xmm1
movsd (%rbp,%rbx), %xmm2
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
ucomisd %xmm1, %xmm3
ja 0x1f128
addsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
movapd %xmm2, %xmm3
jbe 0x1f12f
movsd %xmm3, (%r13,%rbx)
addq $0x8, %rbx
cmpq %rbx, %rax
jne 0x1f048
incq %r12
movslq 0x38(%r15), %rax
cmpq %rax, %r12
jl 0x1efb2
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf07a(%rip), %rdi      # 0x2e1dc
leaq 0xe1b9(%rip), %rsi      # 0x2d322
leaq 0xf17c(%rip), %rcx      # 0x2e2ec
movl $0x6bd, %edx            # imm = 0x6BD
callq 0x31c0
leaq 0xf1be(%rip), %rdi      # 0x2e33f
leaq 0xe19a(%rip), %rsi      # 0x2d322
leaq 0xf15d(%rip), %rcx      # 0x2e2ec
movl $0x6be, %edx            # imm = 0x6BE
callq 0x31c0
nop