// File: /workspace/github_cpp_makefile_star2_O2/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 0x1851b
movq %rdi, %r15
cmpl $0x0, 0x34(%rdi)
jle 0x1851b
movq %rsi, %rbx
callq 0x3c71
andq $0x0, 0x1a7a1(%rip)     # 0x32ba8
andq $0x0, 0x1a7a1(%rip)     # 0x32bb0
andq $0x0, 0x1a781(%rip)     # 0x32b98
andq $0x0, 0x1a771(%rip)     # 0x32b90
movq %rax, 0x1a77a(%rip)     # 0x32ba0
movl 0x34(%r15), %r12d
imull 0x30(%r15), %r12d
callq 0x3c71
movq %rax, 0x1a775(%rip)     # 0x32bb0
movslq %r12d, %rax
leaq (,%rax,8), %rcx
testl %eax, %eax
pushq $-0x1
popq %rdi
cmovnsq %rcx, %rdi
callq 0x3030
movq %rax, %r14
callq 0x3c71
subq 0x1a74d(%rip), %rax     # 0x32bb0
movq %rax, 0x1a746(%rip)     # 0x32bb0
movl 0x38(%r15), %ebp
testl %ebp, %ebp
jle 0x1849f
decl %ebp
cmpb $0x0, 0x48(%r15)
je 0x1848d
movq %r15, %rdi
movl %ebp, %esi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x17d0c
jmp 0x1846e
movq %r15, %rdi
movl %ebp, %esi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x17a46
jmp 0x1846e
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
movsd 0x9ba8(%rip), %xmm0     # 0x22058
cmpq %rax, %r12
je 0x184d8
movsd (%rbx,%rax,8), %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm2, %xmm1
ja 0x184ce
ucomisd %xmm0, %xmm2
movapd %xmm0, %xmm1
jbe 0x184d3
movsd %xmm1, (%rbx,%rax,8)
incq %rax
jmp 0x184b0
callq 0x3c71
movq %rax, 0x1a6c4(%rip)     # 0x32ba8
movq %r14, %rdi
callq 0x3380
callq 0x3c71
subq 0x1a6b0(%rip), %rax     # 0x32ba8
movq %rax, 0x1a6a9(%rip)     # 0x32ba8
callq 0x3c71
subq 0x1a695(%rip), %rax     # 0x32ba0
movq %rax, 0x1a68e(%rip)     # 0x32ba0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0xdb4d(%rip), %rdi      # 0x2606f
leaq 0xcd99(%rip), %rsi      # 0x252c2
leaq 0xdb59(%rip), %rcx      # 0x26089
movl $0x5a8, %edx            # imm = 0x5A8
callq 0x31a0