// File: kebwi[P]Trifid/src/SteerablePyramid.cpp
// Function: SteerablePyramid::getFilterFTIndex()
int SteerablePyramid::getFilterFTIndex()
{
	assert(skFilterDims[0] > 0);
	
	//Search the currently defined filter FTs for one with the appropriate dimensions.
	//If one is found, return its index.
	for (int i = 0; i < skFiltersFTs.size(); i++)
		if (skFiltersFTs[i].width_ == width_ && skFiltersFTs[i].height_ == height_)
			return i;
	
	//No filter FT with the appropriate dimensions was found, so add a new one and return its index.
	FilterFT filterFT;
	skFiltersFTs.push_back(filterFT);
	skFiltersFTs.back().resize(width_, height_);
	
	Float_t *shiftBuffer = new Float_t[width_ * height_];
	for (int i = 0; i < 7; i++)
		for (int lvl = 0 ; lvl < numLevels_; lvl++)
		{	
			int filterDim = skFilterDims[i];
			
			int horDim = width_ / pow(2, lvl);
			int verDim = height_ / pow(2, lvl);
			assert(horDim >= filterDim && verDim >= filterDim);
			
			memset(shiftBuffer, 0, horDim * verDim * sizeof(Float_t));
			
			int xOffset = (horDim - filterDim) / 2;
			int yOffset = (verDim - filterDim) / 2;
			
			//By default, an embedded odd-length signal will be positioned such that the center pixel
			//resides at lower right, but I prefer that it be at upper left, so shift it by one.
			assert(filterDim % 2 == 1);	//All the filters should have odd dimensions
			if (filterDim % 2 == 1)
			{
				xOffset++;
				yOffset++;
			}
			
			//Copy the filter to the temp buffer 
			for (int y = 0; y < filterDim; y++)
				for (int x = 0; x < filterDim; x++)
					shiftBuffer[(y + yOffset) * horDim + (x + xOffset)] =
						skFilters[i][y * filterDim + x];
			
			//Shift (with wrap) the center to the corners
			for (int y = 0; y < verDim; y++)
				for (int x = 0; x < horDim; x++)
					skFiltersFTs.back().filtersFTs[i][lvl][y * horDim + x] =
						shiftBuffer[((y + verDim / 2) % verDim) * horDim + (x + horDim / 2) % horDim];
			
			//Do the Fourier analysis
			assert(doFourierAnalysis(skFiltersFTs.back().filtersFTs[i][lvl],
									skFiltersFTs.back().filtersFTs[i][lvl], horDim, verDim));
			
			//Copy the inverse filter to the temp buffer 
			for (int y = 0; y < filterDim; y++)
				for (int x = 0; x < filterDim; x++)
					shiftBuffer[(y + yOffset) * horDim + (x + xOffset)] =
						skFiltersInv[i][y * filterDim + x];
			
			//Shift (with wrap) the center to the corners
			for (int y = 0; y < verDim; y++)
				for (int x = 0; x < horDim; x++)
					skFiltersFTs.back().filtersInvFTs[i][lvl][y * horDim + x] =
						shiftBuffer[((y + verDim / 2) % verDim) * horDim + (x + horDim / 2) % horDim];
			
			//Do the Fourier analysis
			assert(doFourierAnalysis(skFiltersFTs.back().filtersInvFTs[i][lvl],
									skFiltersFTs.back().filtersInvFTs[i][lvl], horDim, verDim));
		}
	delete [] shiftBuffer;
	
	return skFiltersFTs.size() - 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1d0(%rbp)
cmpl $0x0, 0x3221f(%rip)     # 0x5cbd0
jle 0x2a9b5
jmp 0x2a9d4
leaq 0x21a23(%rip), %rdi     # 0x4c3df
leaq 0x21993(%rip), %rsi     # 0x4c356
movl $0x151, %edx            # imm = 0x151
leaq 0x21a24(%rip), %rcx     # 0x4c3f3
callq 0x4240
movl $0x0, -0x14(%rbp)
movslq -0x14(%rbp), %rax
movq %rax, -0x1d8(%rbp)
leaq 0x321ab(%rip), %rdi     # 0x5cb98
callq 0x32ac0
movq %rax, %rcx
movq -0x1d8(%rbp), %rax
cmpq %rcx, %rax
jae 0x2aa56
movslq -0x14(%rbp), %rsi
leaq 0x3218c(%rip), %rdi     # 0x5cb98
callq 0x32af0
movq -0x1d0(%rbp), %rcx
movl (%rax), %eax
cmpl 0x30(%rcx), %eax
jne 0x2aa49
movslq -0x14(%rbp), %rsi
leaq 0x3216e(%rip), %rdi     # 0x5cb98
callq 0x32af0
movq -0x1d0(%rbp), %rcx
movl 0x4(%rax), %eax
cmpl 0x34(%rcx), %eax
jne 0x2aa49
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2b2bd
jmp 0x2aa4b
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2a9db
leaq -0x170(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x32b10
movq -0x1e0(%rbp), %rsi
leaq 0x32121(%rip), %rdi     # 0x5cb98
callq 0x32bb0
jmp 0x2aa7e
leaq 0x32113(%rip), %rdi     # 0x5cb98
callq 0x32c20
movq %rax, %rdi
movq -0x1d0(%rbp), %rax
movl 0x30(%rax), %esi
movl 0x34(%rax), %edx
callq 0x32c60
jmp 0x2aaa1
movq -0x1d0(%rbp), %rcx
movl 0x30(%rcx), %eax
movl 0x34(%rcx), %ecx
imull %ecx, %eax
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x4030
movq %rax, -0x1e8(%rbp)
jmp 0x2aad7
movq -0x1e8(%rbp), %rax
movq %rax, -0x188(%rbp)
movl $0x0, -0x18c(%rbp)
cmpl $0x7, -0x18c(%rbp)
jge 0x2b27e
movl $0x0, -0x190(%rbp)
movq -0x1d0(%rbp), %rcx
movl -0x190(%rbp), %eax
cmpl 0x38(%rcx), %eax
jge 0x2b268
movq -0x1d0(%rbp), %rax
movslq -0x18c(%rbp), %rdx
leaq 0x3209f(%rip), %rcx     # 0x5cbd0
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x194(%rbp)
cvtsi2sdl 0x30(%rax), %xmm0
movsd %xmm0, -0x1f8(%rbp)
movl -0x190(%rbp), %esi
movl $0x2, %edi
callq 0x1d7f0
movsd %xmm0, -0x1f0(%rbp)
jmp 0x2ab61
movq -0x1d0(%rbp), %rax
movsd -0x1f0(%rbp), %xmm1
movsd -0x1f8(%rbp), %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, -0x198(%rbp)
cvtsi2sdl 0x34(%rax), %xmm0
movsd %xmm0, -0x208(%rbp)
movl -0x190(%rbp), %esi
movl $0x2, %edi
callq 0x1d7f0
movsd %xmm0, -0x200(%rbp)
jmp 0x2abad
movsd -0x200(%rbp), %xmm1
movsd -0x208(%rbp), %xmm0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x19c(%rbp)
movl -0x198(%rbp), %ecx
xorl %eax, %eax
cmpl -0x194(%rbp), %ecx
movb %al, -0x209(%rbp)
jl 0x2abf6
movl -0x19c(%rbp), %eax
cmpl -0x194(%rbp), %eax
setge %al
movb %al, -0x209(%rbp)
movb -0x209(%rbp), %al
testb $0x1, %al
jne 0x2ac02
jmp 0x2ac04
jmp 0x2ac46
leaq 0x21811(%rip), %rdi     # 0x4c41c
leaq 0x21744(%rip), %rsi     # 0x4c356
movl $0x166, %edx            # imm = 0x166
leaq 0x217d5(%rip), %rcx     # 0x4c3f3
callq 0x4240
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x178(%rbp)
movl %eax, -0x17c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x32cb0
jmp 0x2b2c9
movq -0x188(%rbp), %rdi
movl -0x198(%rbp), %eax
imull -0x19c(%rbp), %eax
movslq %eax, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x41e0
movl -0x198(%rbp), %eax
subl -0x194(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x1a0(%rbp)
movl -0x19c(%rbp), %eax
subl -0x194(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x1a4(%rbp)
movl -0x194(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x2acb1
jmp 0x2acd0
leaq 0x21705(%rip), %rdi     # 0x4c3bd
leaq 0x21697(%rip), %rsi     # 0x4c356
movl $0x16f, %edx            # imm = 0x16F
leaq 0x21728(%rip), %rcx     # 0x4c3f3
callq 0x4240
movl -0x194(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x2ad01
movl -0x1a0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1a0(%rbp)
movl -0x1a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1a4(%rbp)
movl $0x0, -0x1a8(%rbp)
movl -0x1a8(%rbp), %eax
cmpl -0x194(%rbp), %eax
jge 0x2adb9
movl $0x0, -0x1ac(%rbp)
movl -0x1ac(%rbp), %eax
cmpl -0x194(%rbp), %eax
jge 0x2ada3
movslq -0x18c(%rbp), %rcx
leaq 0x31ead(%rip), %rax     # 0x5cbf0
movq (%rax,%rcx,8), %rax
movl -0x1a8(%rbp), %ecx
imull -0x194(%rbp), %ecx
addl -0x1ac(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x188(%rbp), %rax
movl -0x1a8(%rbp), %ecx
addl -0x1a4(%rbp), %ecx
imull -0x198(%rbp), %ecx
movl -0x1ac(%rbp), %edx
addl -0x1a0(%rbp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x1ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1ac(%rbp)
jmp 0x2ad27
jmp 0x2ada5
movl -0x1a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1a8(%rbp)
jmp 0x2ad0b
movl $0x0, -0x1b0(%rbp)
movl -0x1b0(%rbp), %eax
cmpl -0x19c(%rbp), %eax
jge 0x2aef4
movl $0x0, -0x1b4(%rbp)
movl -0x1b4(%rbp), %eax
cmpl -0x198(%rbp), %eax
jge 0x2aede
movq -0x188(%rbp), %rax
movq %rax, -0x220(%rbp)
movl -0x1b0(%rbp), %eax
movl %eax, -0x228(%rbp)
movl -0x19c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x228(%rbp), %eax
addl %ecx, %eax
cltd
idivl -0x19c(%rbp)
movl %edx, %ecx
imull -0x198(%rbp), %ecx
movl -0x1b4(%rbp), %eax
movl %eax, -0x224(%rbp)
movl -0x198(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movl -0x224(%rbp), %eax
addl %edx, %eax
cltd
idivl -0x198(%rbp)
movq -0x220(%rbp), %rax
addl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x218(%rbp)
leaq 0x31d1a(%rip), %rdi     # 0x5cb98
callq 0x32c20
movq %rax, %rdi
addq $0x8, %rdi
movslq -0x18c(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movslq -0x190(%rbp), %rsi
callq 0x32c90
movsd -0x218(%rbp), %xmm0
movq (%rax), %rax
movl -0x1b0(%rbp), %ecx
imull -0x198(%rbp), %ecx
addl -0x1b4(%rbp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x1b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b4(%rbp)
jmp 0x2addf
jmp 0x2aee0
movl -0x1b0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b0(%rbp)
jmp 0x2adc3
leaq 0x31c9d(%rip), %rdi     # 0x5cb98
movq %rdi, -0x240(%rbp)
callq 0x32c20
movslq -0x18c(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq 0x8(%rax,%rcx,8), %rdi
movslq -0x190(%rbp), %rsi
callq 0x32c90
movq -0x240(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x238(%rbp)
callq 0x32c20
movslq -0x18c(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq 0x8(%rax,%rcx,8), %rdi
movslq -0x190(%rbp), %rsi
callq 0x32c90
movq -0x238(%rbp), %rdi
movq (%rax), %rsi
movl -0x198(%rbp), %edx
movl -0x19c(%rbp), %ecx
callq 0x27750
movb %al, -0x229(%rbp)
jmp 0x2af78
movb -0x229(%rbp), %al
testb $0x1, %al
jne 0x2af84
jmp 0x2af86
jmp 0x2afa5
leaq 0x214ba(%rip), %rdi     # 0x4c447
leaq 0x213c2(%rip), %rsi     # 0x4c356
movl $0x184, %edx            # imm = 0x184
leaq 0x21453(%rip), %rcx     # 0x4c3f3
callq 0x4240
movl $0x0, -0x1b8(%rbp)
movl -0x1b8(%rbp), %eax
cmpl -0x194(%rbp), %eax
jge 0x2b05d
movl $0x0, -0x1bc(%rbp)
movl -0x1bc(%rbp), %eax
cmpl -0x194(%rbp), %eax
jge 0x2b047
movslq -0x18c(%rbp), %rcx
leaq 0x31c49(%rip), %rax     # 0x5cc30
movq (%rax,%rcx,8), %rax
movl -0x1b8(%rbp), %ecx
imull -0x194(%rbp), %ecx
addl -0x1bc(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x188(%rbp), %rax
movl -0x1b8(%rbp), %ecx
addl -0x1a4(%rbp), %ecx
imull -0x198(%rbp), %ecx
movl -0x1bc(%rbp), %edx
addl -0x1a0(%rbp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x1bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1bc(%rbp)
jmp 0x2afcb
jmp 0x2b049
movl -0x1b8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b8(%rbp)
jmp 0x2afaf
movl $0x0, -0x1c0(%rbp)
movl -0x1c0(%rbp), %eax
cmpl -0x19c(%rbp), %eax
jge 0x2b19b
movl $0x0, -0x1c4(%rbp)
movl -0x1c4(%rbp), %eax
cmpl -0x198(%rbp), %eax
jge 0x2b185
movq -0x188(%rbp), %rax
movq %rax, -0x250(%rbp)
movl -0x1c0(%rbp), %eax
movl %eax, -0x258(%rbp)
movl -0x19c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x258(%rbp), %eax
addl %ecx, %eax
cltd
idivl -0x19c(%rbp)
movl %edx, %ecx
imull -0x198(%rbp), %ecx
movl -0x1c4(%rbp), %eax
movl %eax, -0x254(%rbp)
movl -0x198(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movl -0x254(%rbp), %eax
addl %edx, %eax
cltd
idivl -0x198(%rbp)
movq -0x250(%rbp), %rax
addl %edx, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x248(%rbp)
leaq 0x31a76(%rip), %rdi     # 0x5cb98
callq 0x32c20
movq %rax, %rdi
addq $0xb0, %rdi
movslq -0x18c(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movslq -0x190(%rbp), %rsi
callq 0x32c90
movsd -0x248(%rbp), %xmm0
movq (%rax), %rax
movl -0x1c0(%rbp), %ecx
imull -0x198(%rbp), %ecx
addl -0x1c4(%rbp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x1c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c4(%rbp)
jmp 0x2b083
jmp 0x2b187
movl -0x1c0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c0(%rbp)
jmp 0x2b067
leaq 0x319f6(%rip), %rdi     # 0x5cb98
movq %rdi, -0x270(%rbp)
callq 0x32c20
movslq -0x18c(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq 0xb0(%rax,%rcx,8), %rdi
movslq -0x190(%rbp), %rsi
callq 0x32c90
movq -0x270(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x268(%rbp)
callq 0x32c20
movslq -0x18c(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq 0xb0(%rax,%rcx,8), %rdi
movslq -0x190(%rbp), %rsi
callq 0x32c90
movq -0x268(%rbp), %rdi
movq (%rax), %rsi
movl -0x198(%rbp), %edx
movl -0x19c(%rbp), %ecx
callq 0x27750
movb %al, -0x259(%rbp)
jmp 0x2b225
movb -0x259(%rbp), %al
testb $0x1, %al
jne 0x2b231
jmp 0x2b233
jmp 0x2b252
leaq 0x2127f(%rip), %rdi     # 0x4c4b9
leaq 0x21115(%rip), %rsi     # 0x4c356
movl $0x194, %edx            # imm = 0x194
leaq 0x211a6(%rip), %rcx     # 0x4c3f3
callq 0x4240
jmp 0x2b254
movl -0x190(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x190(%rbp)
jmp 0x2ab06
jmp 0x2b26a
movl -0x18c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18c(%rbp)
jmp 0x2aaef
movq -0x188(%rbp), %rax
movq %rax, -0x278(%rbp)
cmpq $0x0, %rax
je 0x2b29e
movq -0x278(%rbp), %rdi
callq 0x44d0
leaq 0x318f3(%rip), %rdi     # 0x5cb98
callq 0x32ac0
subq $0x1, %rax
movl %eax, -0x4(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x32cb0
movl -0x4(%rbp), %eax
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
movq -0x178(%rbp), %rdi
callq 0x4620
nopw %cs:(%rax,%rax)