// File: /workspace/github_cpp_makefile_star2_O3/kebwi[P]Trifid/src/SteerablePyramid.cpp
// Function: SteerablePyramid::DoFullWaveletSynthesis(double*)
void SteerablePyramid::DoFullWaveletSynthesis(Float_t* pixelValues)
{
	assert(width_ > 0 && height_ > 0);
	
	gT1 = getCurrentTime_ms();
	gT2 = gT3 = gT4 = gT5 = 0;
	
	int totalPixels = width_ * height_;
	
	//Allocate some scratch storage outside the levels loop so it doesn't have to be allocated each time through the loop
	gT4 = getCurrentTime_ms();
	Float_t *upsampledThumbnail = new Float_t[totalPixels];
	gT4 = getCurrentTime_ms() - gT4;
	
	//It shouldn't be necessary to erase the output image here.
	//memset(pixelValues, 0, totalPixels * sizeof(Float_t));
	
	//cout << "  Performing synthesis with " << numLevels_ << " levels" <<  endl;
	for (int i = numLevels_ - 1; i >= 0; i--)
	{
		//cout << "    Synthesizing level " << i << "..." << endl;
		if (!useFTconvolution_)
			DoOneStepWaveletSynthesis(i, pixelValues, upsampledThumbnail);
		else DoOneStepWaveletSynthesisUsingFT(i, pixelValues, upsampledThumbnail);
	}
	/*
	Float_t minPixel = 999999, maxPixel = -999999;
	for (int i = 0; i < totalPixels; i++)
	{
		if (pixelValues[i] < minPixel)
			minPixel = pixelValues[i];
		if (pixelValues[i] > maxPixel)
			maxPixel = pixelValues[i];
	}
	cout << "Synthesis Min/Max Pixels: " << minPixel << "    " << maxPixel << endl;
	*/
	//cout << "  Clipping image" << endl;
	for (int i = 0; i < totalPixels; i++)
		if (pixelValues[i] < 0)
			pixelValues[i] = 0;
		else if (pixelValues[i] > 1.0)
			pixelValues[i] = 1.0;
	/*
	maxPixel = -999999;
	for (int i = 0; i < totalPixels; i++)
		if (pixelValues[i] > maxPixel)
			maxPixel = pixelValues[i];
	string filename = "aaaUpsampleFilteredFinalClipped.pgm";
	GeneratePGMimage(pixelValues, width_, height_, 255.0 / maxPixel, 0, filename);
	*/
	//cout << "  Cleaning up" << endl;
	gT5 = getCurrentTime_ms();
	delete [] upsampledThumbnail;
	gT5 = getCurrentTime_ms() - gT5;
	
	//cout << "  Done" << endl;
	
	gT1 = getCurrentTime_ms() - gT1;
	Float_t t1Secs = (Float_t)gT1 / CURRENT_TIME_PER_SEC_F;
	Float_t t2Secs = (Float_t)gT2 / CURRENT_TIME_PER_SEC_F;
	Float_t t3Secs = (Float_t)gT3 / CURRENT_TIME_PER_SEC_F;
	Float_t t4Secs = (Float_t)gT4 / CURRENT_TIME_PER_SEC_F;
	Float_t t5Secs = (Float_t)gT5 / CURRENT_TIME_PER_SEC_F;
	Float_t t2Fraction = (Float_t)gT2 / (Float_t)gT1;
	Float_t t3Fraction = (Float_t)gT3 / (Float_t)gT1;
	Float_t t4Fraction = (Float_t)gT4 / (Float_t)gT1;
	Float_t t5Fraction = (Float_t)gT5 / (Float_t)gT1;
	/*
	cout << "  Times:" << endl;
	cout << "    Total: " << t1Secs << endl;
	cout << "    T2: ";
	cout << setw(10) << t2Secs << "   Ratio: ";
	cout << setw(10) << t2Fraction << endl;
	cout << "    T3: ";
	cout << setw(10) << t3Secs << "   Ratio: ";
	cout << setw(10) << t3Fraction << endl;
	cout << "    T4: ";
	cout << setw(10) << t4Secs << "   Ratio: ";
	cout << setw(10) << t4Fraction << endl;
	cout << "    T5: ";
	cout << setw(10) << t5Secs << "   Ratio: ";
	cout << setw(10) << t5Fraction << endl;
	*/
	//cout << "  St2 " << t2Fraction << "  St3 " << t3Fraction << "  ";
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
cmpl $0x0, 0x30(%rdi)
jle 0x1e4be
movq %rdi, %r15
cmpl $0x0, 0x34(%rdi)
jle 0x1e4be
movq %rsi, %rbx
callq 0x4288
movq %rax, 0x1b810(%rip)     # 0x39bb0
xorl %eax, %eax
movq %rax, 0x1b80f(%rip)     # 0x39bb8
movq %rax, 0x1b810(%rip)     # 0x39bc0
movq %rax, 0x1b7f1(%rip)     # 0x39ba8
movq %rax, 0x1b7e2(%rip)     # 0x39ba0
movl 0x34(%r15), %ebp
imull 0x30(%r15), %ebp
callq 0x4288
movq %rax, 0x1b7ed(%rip)     # 0x39bc0
movslq %ebp, %rax
leaq (,%rax,8), %rcx
testl %eax, %eax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x3030
movq %rax, %r14
callq 0x4288
subq 0x1b7c1(%rip), %rax     # 0x39bc0
movq %rax, 0x1b7ba(%rip)     # 0x39bc0
movl 0x38(%r15), %r12d
testl %r12d, %r12d
jle 0x1e445
incl %r12d
leal -0x2(%r12), %esi
cmpb $0x0, 0x48(%r15)
je 0x1e42e
movq %r15, %rdi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x1dc18
jmp 0x1e43c
movq %r15, %rdi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x1d8b8
decl %r12d
cmpl $0x1, %r12d
ja 0x1e412
testl %ebp, %ebp
jle 0x1e47b
movl %ebp, %eax
xorl %ecx, %ecx
movsd 0xbc03(%rip), %xmm0     # 0x2a058
movsd (%rbx,%rcx,8), %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm2, %xmm1
ja 0x1e46e
ucomisd %xmm0, %xmm2
movapd %xmm0, %xmm1
jbe 0x1e473
movsd %xmm1, (%rbx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x1e455
callq 0x4288
movq %rax, 0x1b731(%rip)     # 0x39bb8
movq %r14, %rdi
callq 0x33c0
callq 0x4288
subq 0x1b71d(%rip), %rax     # 0x39bb8
movq %rax, 0x1b716(%rip)     # 0x39bb8
callq 0x4288
subq 0x1b702(%rip), %rax     # 0x39bb0
movq %rax, 0x1b6fb(%rip)     # 0x39bb0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0xfc0a(%rip), %rdi      # 0x2e0cf
leaq 0xee56(%rip), %rsi      # 0x2d322
leaq 0xfc16(%rip), %rcx      # 0x2e0e9
movl $0x5a8, %edx            # imm = 0x5A8
callq 0x31c0
nop