// File: /workspace/github_cpp_makefile_star2_O1/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 0x1f3fe
movq %rsi, %r14
movq %rdi, %r15
movl 0x34(%rdi), %eax
cmpl 0x34(%rsi), %eax
jne 0x1f3fe
movslq 0x38(%r15), %rax
cmpl 0x38(%r14), %eax
jne 0x1f3fe
movq (%rsp), %rdx
movq 0x8(%rdx), %rcx
subq (%rdx), %rcx
sarq $0x3, %rcx
cmpq %rax, %rcx
jne 0x1f41d
cmpl $0x0, 0x38(%r15)
jle 0x1f3ef
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 0xbde3(%rip), %xmm0     # 0x2b070
jne 0x1f295
jnp 0x1f3df
testl %eax, %eax
jle 0x1f3df
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 0x1f31b
movsd (%rcx,%rbx), %xmm1
movsd (%rdx,%rbx), %xmm2
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
ucomisd %xmm1, %xmm3
ja 0x1f316
addsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
movapd %xmm2, %xmm3
jbe 0x1f31b
movsd %xmm3, (%rcx,%rbx)
movsd (%rsi,%rbx), %xmm1
movsd (%rdi,%rbx), %xmm2
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
ucomisd %xmm1, %xmm3
ja 0x1f341
addsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
movapd %xmm2, %xmm3
jbe 0x1f346
movsd %xmm3, (%rsi,%rbx)
movsd (%r8,%rbx), %xmm1
movsd (%r9,%rbx), %xmm2
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
ucomisd %xmm1, %xmm3
ja 0x1f36e
addsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
movapd %xmm2, %xmm3
jbe 0x1f374
movsd %xmm3, (%r8,%rbx)
movsd (%r10,%rbx), %xmm1
movsd (%r11,%rbx), %xmm2
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
ucomisd %xmm1, %xmm3
ja 0x1f39c
addsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
movapd %xmm2, %xmm3
jbe 0x1f3a2
movsd %xmm3, (%r10,%rbx)
movsd (%r13,%rbx), %xmm1
movsd (%rbp,%rbx), %xmm2
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
ucomisd %xmm1, %xmm3
ja 0x1f3cb
addsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
movapd %xmm2, %xmm3
jbe 0x1f3d2
movsd %xmm3, (%r13,%rbx)
addq $0x8, %rbx
cmpq %rbx, %rax
jne 0x1f2eb
incq %r12
movslq 0x38(%r15), %rax
cmpq %rax, %r12
jl 0x1f255
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xfd6f(%rip), %rdi      # 0x2f174
leaq 0xeeae(%rip), %rsi      # 0x2e2ba
leaq 0xfe71(%rip), %rcx      # 0x2f284
movl $0x6bd, %edx            # imm = 0x6BD
callq 0x31c0
leaq 0xfeb3(%rip), %rdi      # 0x2f2d7
leaq 0xee8f(%rip), %rsi      # 0x2e2ba
leaq 0xfe52(%rip), %rcx      # 0x2f284
movl $0x6be, %edx            # imm = 0x6BE
callq 0x31c0