// File: kebwi[P]Trifid/src/SteerablePyramid.cpp
// Function: SteerablePyramid::GenerateFilterPGMimages(char const*, bool)
void SteerablePyramid::GenerateFilterPGMimages(const char* filenameHeader, bool plotLog)
{
	InitFilters();
	
	Float_t maxAbsTap = 0;
	for (int i = 0; i < 7; i++)
	{
		int numTaps = skFilterDims[i] * skFilterDims[i];
		for (int j = 0; j < numTaps; j++)
			if (fabs(skFilters[i][j]) > maxAbsTap)
				maxAbsTap = fabs(skFilters[i][j]);
	}
	Float_t scalar = 127.0 / maxAbsTap;
	//Float_t scalar = 127.0 / (plotLog ? log(5896.0) : 5896.0);
	
	for (int i = 0; i < 7; i++)
	{
		string filename(filenameHeader);
		
		Float_t *filter = skFilters[i];
		switch (i)
		{
			case 0: filename += "_H0"; break;
			case 1: filename += "_L0"; break;
			case 2: filename += "_L1"; break;
			case 3: filename += "_B1"; break;
			case 4: filename += "_B2"; break;
			case 5: filename += "_B3"; break;
			case 6: filename += "_B4"; break;
		}
		
		filename += ".pgm";
		
		ofstream ofs;;
		ofs.open(filename.c_str());
		assert(ofs);
		
		//Write pgm header
		ofs << "P5" << endl
			<< "#." << endl
			<< skFilterDims[i] << " " << skFilterDims[i] << endl
			<< 255 << endl;
		
		Float_t pixelF;
		int pixel;
		unsigned char pixelUC;
		int numTaps = skFilterDims[i] * skFilterDims[i];
		for (int j = 0; j < numTaps; j++)
		{
			Float_t tap = filter[j];
			
			pixelF = tap * scalar;
			assert(pixelF >= -127 && pixelF <= 127);
			pixelF += 128;
			pixel = pixelF;
			
			cout << setw(4) << pixel;
			if (j % skFilterDims[i] == skFilterDims[i] - 1)
				cout << endl;
			
			assert(pixel >= 0 && pixel <= 255);
			
			pixelUC = pixel;
			ofs.put(pixelUC);
		}
		cout << endl << endl;
		
		ofs.close();
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x330, %rsp            # imm = 0x330
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
callq 0x29430
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x7, -0x1c(%rbp)
jge 0x2b3b3
movslq -0x1c(%rbp), %rcx
leaq 0x318b0(%rip), %rax     # 0x5cbd0
movl (%rax,%rcx,4), %eax
movslq -0x1c(%rbp), %rdx
leaq 0x318a2(%rip), %rcx     # 0x5cbd0
imull (%rcx,%rdx,4), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x2b3a3
movslq -0x1c(%rbp), %rcx
leaq 0x318a1(%rip), %rax     # 0x5cbf0
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movaps 0x1dcdd(%rip), %xmm1    # 0x49040
pand %xmm1, %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x2b396
movslq -0x1c(%rbp), %rcx
leaq 0x31877(%rip), %rax     # 0x5cbf0
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movaps 0x1dcb3(%rip), %xmm1    # 0x49040
pand %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x2b398
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2b33c
jmp 0x2b3a5
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2b30b
movsd 0x20e6d(%rip), %xmm0    # 0x4c228
divsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x7, -0x34(%rbp)
jge 0x2b94e
movq -0x8(%rbp), %rax
movq %rax, -0x2b0(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x4630
movq -0x2b0(%rbp), %rsi
movq -0x2a8(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0xe110
jmp 0x2b40a
leaq -0x59(%rbp), %rdi
callq 0x43f0
movslq -0x34(%rbp), %rcx
leaq 0x317d2(%rip), %rax     # 0x5cbf0
movq (%rax,%rcx,8), %rax
movq %rax, -0x78(%rbp)
movl -0x34(%rbp), %eax
movq %rax, -0x2b8(%rbp)
subq $0x6, %rax
ja 0x2b50b
movq -0x2b8(%rbp), %rax
leaq 0x20e00(%rip), %rcx     # 0x4c248
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x43f0
jmp 0x2b957
leaq 0x21102(%rip), %rsi     # 0x4c574
leaq -0x58(%rbp), %rdi
callq 0x4360
jmp 0x2b47d
jmp 0x2b50b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x2b943
leaq 0x210de(%rip), %rsi     # 0x4c578
leaq -0x58(%rbp), %rdi
callq 0x4360
jmp 0x2b4a5
jmp 0x2b50b
leaq 0x210ce(%rip), %rsi     # 0x4c57c
leaq -0x58(%rbp), %rdi
callq 0x4360
jmp 0x2b4b9
jmp 0x2b50b
leaq 0x210be(%rip), %rsi     # 0x4c580
leaq -0x58(%rbp), %rdi
callq 0x4360
jmp 0x2b4cd
jmp 0x2b50b
leaq 0x210ae(%rip), %rsi     # 0x4c584
leaq -0x58(%rbp), %rdi
callq 0x4360
jmp 0x2b4e1
jmp 0x2b50b
leaq 0x2109e(%rip), %rsi     # 0x4c588
leaq -0x58(%rbp), %rdi
callq 0x4360
jmp 0x2b4f5
jmp 0x2b50b
leaq 0x2108e(%rip), %rsi     # 0x4c58c
leaq -0x58(%rbp), %rdi
callq 0x4360
jmp 0x2b509
jmp 0x2b50b
leaq 0x1eda3(%rip), %rsi     # 0x4a2b5
leaq -0x58(%rbp), %rdi
callq 0x4360
jmp 0x2b51d
leaq -0x278(%rbp), %rdi
callq 0x45e0
jmp 0x2b52b
leaq -0x58(%rbp), %rdi
callq 0x4160
movq %rax, %rsi
leaq -0x278(%rbp), %rdi
movl $0x10, %edx
callq 0x4070
jmp 0x2b54a
movq -0x278(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x278(%rbp,%rax), %rdi
callq 0x44a0
movb %al, -0x2b9(%rbp)
jmp 0x2b56a
movb -0x2b9(%rbp), %al
testb $0x1, %al
jne 0x2b576
jmp 0x2b578
jmp 0x2b5b4
leaq 0x1ed3b(%rip), %rdi     # 0x4a2ba
leaq 0x20dd0(%rip), %rsi     # 0x4c356
movl $0x1d3, %edx            # imm = 0x1D3
leaq 0x20ffe(%rip), %rcx     # 0x4c590
callq 0x4240
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x4540
jmp 0x2b943
leaq 0x1ec49(%rip), %rsi     # 0x4a204
leaq -0x278(%rbp), %rdi
callq 0x4390
movq %rax, -0x2c8(%rbp)
jmp 0x2b5d0
movq -0x2c8(%rbp), %rdi
movq 0x2e9da(%rip), %rsi     # 0x59fb8
callq 0x43d0
movq %rax, -0x2d0(%rbp)
jmp 0x2b5ec
movq -0x2d0(%rbp), %rdi
leaq 0x1ece2(%rip), %rsi     # 0x4a2dc
callq 0x4390
movq %rax, -0x2d8(%rbp)
jmp 0x2b608
movq -0x2d8(%rbp), %rdi
movq 0x2e9a2(%rip), %rsi     # 0x59fb8
callq 0x43d0
movq %rax, -0x2e0(%rbp)
jmp 0x2b624
movq -0x2e0(%rbp), %rdi
movslq -0x34(%rbp), %rcx
leaq 0x3159a(%rip), %rax     # 0x5cbd0
movl (%rax,%rcx,4), %esi
callq 0x4600
movq %rax, -0x2e8(%rbp)
jmp 0x2b647
movq -0x2e8(%rbp), %rdi
leaq 0x1e359(%rip), %rsi     # 0x499ae
callq 0x4390
movq %rax, -0x2f0(%rbp)
jmp 0x2b663
movq -0x2f0(%rbp), %rdi
movslq -0x34(%rbp), %rcx
leaq 0x3155b(%rip), %rax     # 0x5cbd0
movl (%rax,%rcx,4), %esi
callq 0x4600
movq %rax, -0x2f8(%rbp)
jmp 0x2b686
movq -0x2f8(%rbp), %rdi
movq 0x2e924(%rip), %rsi     # 0x59fb8
callq 0x43d0
movq %rax, -0x300(%rbp)
jmp 0x2b6a2
movq -0x300(%rbp), %rdi
movl $0xff, %esi
callq 0x4600
movq %rax, -0x308(%rbp)
jmp 0x2b6bc
movq -0x308(%rbp), %rdi
movq 0x2e8ee(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x2b6d1
movslq -0x34(%rbp), %rcx
leaq 0x314f4(%rip), %rax     # 0x5cbd0
movl (%rax,%rcx,4), %eax
movslq -0x34(%rbp), %rdx
leaq 0x314e6(%rip), %rcx     # 0x5cbd0
imull (%rcx,%rdx,4), %eax
movl %eax, -0x28c(%rbp)
movl $0x0, -0x290(%rbp)
movl -0x290(%rbp), %eax
cmpl -0x28c(%rbp), %eax
jge 0x2b8e1
movq -0x78(%rbp), %rax
movslq -0x290(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x298(%rbp)
movsd -0x298(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x280(%rbp)
movsd -0x280(%rbp), %xmm0
xorl %eax, %eax
movsd 0x20ae1(%rip), %xmm1    # 0x4c230
ucomisd %xmm1, %xmm0
movb %al, -0x309(%rbp)
jb 0x2b774
movsd 0x20ac5(%rip), %xmm0    # 0x4c228
ucomisd -0x280(%rbp), %xmm0
setae %al
movb %al, -0x309(%rbp)
movb -0x309(%rbp), %al
testb $0x1, %al
jne 0x2b780
jmp 0x2b782
jmp 0x2b7a1
leaq 0x20e51(%rip), %rdi     # 0x4c5da
leaq 0x20bc6(%rip), %rsi     # 0x4c356
movl $0x1e4, %edx            # imm = 0x1E4
leaq 0x20df4(%rip), %rcx     # 0x4c590
callq 0x4240
movsd -0x280(%rbp), %xmm0
movsd 0x20a87(%rip), %xmm1    # 0x4c238
addsd %xmm1, %xmm0
movsd %xmm0, -0x280(%rbp)
cvttsd2si -0x280(%rbp), %eax
movl %eax, -0x284(%rbp)
movl $0x4, %edi
callq 0xe410
movl %eax, -0x310(%rbp)
jmp 0x2b7dd
movl -0x310(%rbp), %eax
movl %eax, -0x29c(%rbp)
movl -0x29c(%rbp), %esi
movq 0x2e7da(%rip), %rdi     # 0x59fd0
callq 0x4430
movq %rax, -0x318(%rbp)
jmp 0x2b804
movq -0x318(%rbp), %rdi
movl -0x284(%rbp), %esi
callq 0x4600
jmp 0x2b818
movl -0x290(%rbp), %eax
movslq -0x34(%rbp), %rsi
leaq 0x313a7(%rip), %rcx     # 0x5cbd0
cltd
idivl (%rcx,%rsi,4)
movslq -0x34(%rbp), %rcx
leaq 0x31398(%rip), %rax     # 0x5cbd0
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
cmpl %eax, %edx
jne 0x2b859
movq 0x2e787(%rip), %rdi     # 0x59fd0
movq 0x2e768(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x2b857
jmp 0x2b859
xorl %eax, %eax
cmpl $0x0, -0x284(%rbp)
movb %al, -0x319(%rbp)
jl 0x2b87d
cmpl $0xff, -0x284(%rbp)
setle %al
movb %al, -0x319(%rbp)
movb -0x319(%rbp), %al
testb $0x1, %al
jne 0x2b889
jmp 0x2b88b
jmp 0x2b8aa
leaq 0x20d68(%rip), %rdi     # 0x4c5fa
leaq 0x20abd(%rip), %rsi     # 0x4c356
movl $0x1ec, %edx            # imm = 0x1EC
leaq 0x20ceb(%rip), %rcx     # 0x4c590
callq 0x4240
movb -0x284(%rbp), %al
movb %al, -0x285(%rbp)
movsbl -0x285(%rbp), %esi
leaq -0x278(%rbp), %rdi
callq 0x4050
jmp 0x2b8cb
jmp 0x2b8cd
movl -0x290(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x290(%rbp)
jmp 0x2b6fe
movq 0x2e6e8(%rip), %rdi     # 0x59fd0
movq 0x2e6c9(%rip), %rsi     # 0x59fb8
callq 0x43d0
movq %rax, -0x328(%rbp)
jmp 0x2b8fd
movq -0x328(%rbp), %rdi
movq 0x2e6ad(%rip), %rsi     # 0x59fb8
callq 0x43d0
jmp 0x2b912
leaq -0x278(%rbp), %rdi
callq 0x4520
jmp 0x2b920
leaq -0x278(%rbp), %rdi
callq 0x4540
leaq -0x58(%rbp), %rdi
callq 0x46c8
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2b3cc
leaq -0x58(%rbp), %rdi
callq 0x46c8
jmp 0x2b957
addq $0x330, %rsp            # imm = 0x330
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x4620