// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rdi, 0x38(%rsp)
callq 0x1aff0
xorpd %xmm0, %xmm0
xorl %eax, %eax
movapd 0xece9(%rip), %xmm2     # 0x2b010
leaq 0x1d7d2(%rip), %rcx     # 0x39b00
movl (%rcx,%rax,4), %ecx
testl %ecx, %ecx
je 0x1c368
imull %ecx, %ecx
leaq 0x1d7e1(%rip), %rdx     # 0x39b20
movq (%rdx,%rax,8), %rdx
cmpl $0x1, %ecx
adcl $0x0, %ecx
xorl %esi, %esi
movapd %xmm0, %xmm1
movsd (%rdx,%rsi,8), %xmm0
andpd %xmm2, %xmm0
maxsd %xmm1, %xmm0
incq %rsi
movapd %xmm0, %xmm1
cmpq %rsi, %rcx
jne 0x1c34f
incq %rax
cmpq $0x7, %rax
jne 0x1c327
movsd 0x11e07(%rip), %xmm1    # 0x2e180
divsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
movq 0x1ac3e(%rip), %rax     # 0x36fc8
movq (%rax), %rcx
movq %rcx, 0x30(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x28(%rsp)
xorl %r12d, %r12d
leaq 0x8(%rsp), %r13
movq 0x1ac26(%rip), %r14     # 0x36fd0
movq %r13, %rdi
movq 0x38(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x9f34
leaq 0x1d75d(%rip), %rax     # 0x39b20
movq (%rax,%r12,8), %rbx
cmpq $0x7, %r12
jae 0x1c3e3
leaq 0x11dd8(%rip), %rax     # 0x2e1ac
movslq (%rax,%r12,4), %rsi
addq %rax, %rsi
movq %r13, %rdi
callq 0x3540
movq %r13, %rdi
leaq 0xfe18(%rip), %rsi      # 0x2c205
callq 0x3540
leaq 0x48(%rsp), %r15
movq %r15, %rdi
callq 0x34d0
movq 0x8(%rsp), %rsi
movq %r15, %rdi
movl $0x10, %edx
callq 0x3050
movq 0x48(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x68(%rsp,%rax)
jne 0x1c71d
movl $0x2, %edx
movq %r15, %rdi
leaq 0xfd20(%rip), %rsi      # 0x2c154
callq 0x3360
movq 0x48(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
leaq 0xfdb8(%rip), %rsi      # 0x2c22c
callq 0x3360
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x1d659(%rip), %rcx     # 0x39b00
movl (%rcx,%r12,4), %esi
movq %rax, %rdi
callq 0x34e0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0xf44c(%rip), %rsi      # 0x2b911
callq 0x3360
leaq 0x1d62f(%rip), %rax     # 0x39b00
movl (%rax,%r12,4), %esi
movq %r15, %rdi
callq 0x34e0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
movq %rax, %rdi
movl $0xff, %esi
callq 0x34e0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x1d5bb(%rip), %rax     # 0x39b00
movl (%rax,%r12,4), %r13d
testl %r13d, %r13d
je 0x1c615
imull %r13d, %r13d
cmpl $0x1, %r13d
adcl $0x0, %r13d
xorl %r15d, %r15d
movsd (%rbx,%r15,8), %xmm0
mulsd 0x40(%rsp), %xmm0
movapd %xmm0, %xmm1
andpd 0xea97(%rip), %xmm1     # 0x2b010
movsd 0x11bff(%rip), %xmm2    # 0x2e180
ucomisd %xmm1, %xmm2
jb 0x1c6df
addsd 0x11bf5(%rip), %xmm0    # 0x2e188
cvttsd2si %xmm0, %ebp
movq (%r14), %rax
movq -0x18(%rax), %rax
movq $0x4, 0x10(%r14,%rax)
movq %r14, %rdi
movl %ebp, %esi
callq 0x34e0
leaq 0x1d548(%rip), %rax     # 0x39b00
movl (%rax,%r12,4), %ecx
movl %r15d, %eax
cltd
idivl %ecx
decl %ecx
cmpl %ecx, %edx
jne 0x1c5ef
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
cmpl $0x100, %ebp            # imm = 0x100
jae 0x1c6fe
movsbl %bpl, %esi
leaq 0x48(%rsp), %rdi
callq 0x3040
incq %r15
cmpq %r15, %r13
jne 0x1c561
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32e0
leaq 0x8(%rsp), %r13
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x48(%rsp), %rdi
callq 0x33e0
movq 0x30(%rsp), %rax
movq %rax, 0x48(%rsp)
movq -0x18(%rax), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0x48(%rsp,%rax)
leaq 0x50(%rsp), %rdi
callq 0x3270
leaq 0x140(%rsp), %rdi
callq 0x30e0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1c6c0
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3310
incq %r12
cmpq $0x7, %r12
jne 0x1c3aa
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11e15(%rip), %rdi     # 0x2e4fb
leaq 0x11bcd(%rip), %rsi     # 0x2e2ba
leaq 0x11dbd(%rip), %rcx     # 0x2e4b1
movl $0x1e4, %edx            # imm = 0x1E4
callq 0x31c0
leaq 0x11e16(%rip), %rdi     # 0x2e51b
leaq 0x11bae(%rip), %rsi     # 0x2e2ba
leaq 0x11d9e(%rip), %rcx     # 0x2e4b1
movl $0x1ec, %edx            # imm = 0x1EC
callq 0x31c0
leaq 0xfae6(%rip), %rdi      # 0x2c20a
leaq 0x11b8f(%rip), %rsi     # 0x2e2ba
leaq 0x11d7f(%rip), %rcx     # 0x2e4b1
movl $0x1d3, %edx            # imm = 0x1D3
callq 0x31c0
jmp 0x1c73e
movq %rax, %rbx
jmp 0x1c754
jmp 0x1c747
jmp 0x1c747
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3400
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1c770
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3310
movq %rbx, %rdi
callq 0x3500