// File: /workspace/github_cpp_makefile_star2_O1/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 0x1e744
movq %rdi, %r15
cmpl $0x0, 0x34(%rdi)
jle 0x1e744
movq %rsi, %rbx
callq 0x4288
movq %rax, 0x1b58a(%rip)     # 0x39bb0
xorl %eax, %eax
movq %rax, 0x1b589(%rip)     # 0x39bb8
movq %rax, 0x1b58a(%rip)     # 0x39bc0
movq %rax, 0x1b56b(%rip)     # 0x39ba8
movq %rax, 0x1b55c(%rip)     # 0x39ba0
movl 0x34(%r15), %ebp
imull 0x30(%r15), %ebp
callq 0x4288
movq %rax, 0x1b567(%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 0x1b53b(%rip), %rax     # 0x39bc0
movq %rax, 0x1b534(%rip)     # 0x39bc0
movl 0x38(%r15), %r12d
testl %r12d, %r12d
jle 0x1e6cb
incl %r12d
leal -0x2(%r12), %esi
cmpb $0x0, 0x48(%r15)
je 0x1e6b4
movq %r15, %rdi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x1df5c
jmp 0x1e6c2
movq %r15, %rdi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x1dc94
decl %r12d
cmpl $0x1, %r12d
jg 0x1e698
testl %ebp, %ebp
jle 0x1e701
movl %ebp, %eax
xorl %ecx, %ecx
movsd 0xc97d(%rip), %xmm0     # 0x2b058
movsd (%rbx,%rcx,8), %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm2, %xmm1
ja 0x1e6f4
ucomisd %xmm0, %xmm2
movapd %xmm0, %xmm1
jbe 0x1e6f9
movsd %xmm1, (%rbx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x1e6db
callq 0x4288
movq %rax, 0x1b4ab(%rip)     # 0x39bb8
movq %r14, %rdi
callq 0x33c0
callq 0x4288
subq 0x1b497(%rip), %rax     # 0x39bb8
movq %rax, 0x1b490(%rip)     # 0x39bb8
callq 0x4288
subq 0x1b47c(%rip), %rax     # 0x39bb0
movq %rax, 0x1b475(%rip)     # 0x39bb0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1091c(%rip), %rdi     # 0x2f067
leaq 0xfb68(%rip), %rsi      # 0x2e2ba
leaq 0x10928(%rip), %rcx     # 0x2f081
movl $0x5a8, %edx            # imm = 0x5A8
callq 0x31c0
nop