// File: /workspace/github_cpp_makefile_star2_O2/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 $0x238, %rsp            # imm = 0x238
movq %rdi, 0x8(%rsp)
callq 0x152c2
xorpd %xmm0, %xmm0
xorl %eax, %eax
leaq 0x1c748(%rip), %rbx     # 0x32b10
cmpq $0x7, %rax
je 0x16405
leaq 0x1c71b(%rip), %rcx     # 0x32af0
movl (%rcx,%rax,4), %ecx
imull %ecx, %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x16400
movq (%rbx,%rax,8), %rsi
movsd (%rsi,%rdx,8), %xmm1
andpd 0xbc1d(%rip), %xmm1     # 0x22010
maxsd %xmm0, %xmm1
incq %rdx
movapd %xmm1, %xmm0
jmp 0x163dd
incq %rax
jmp 0x163c8
movsd 0xed7b(%rip), %xmm1     # 0x25188
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0x18(%rsp), %r15
leaq 0x38(%rsp), %r12
movq 0x19ba5(%rip), %r13     # 0x2ffd0
cmpq $0x7, %r14
je 0x16615
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
callq 0x7fcc
movq (%rbx,%r14,8), %rbx
movq %r14, (%rsp)
movslq %r14d, %rax
leaq 0xed5d(%rip), %rcx      # 0x251b4
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
movq %r15, %rdi
callq 0x3510
movq %r15, %rdi
leaq 0xcd5d(%rip), %rsi      # 0x231cd
callq 0x3510
movq %r12, %rdi
callq 0x34a0
movq 0x18(%rsp), %rsi
movq %r12, %rdi
pushq $0x10
popq %rdx
callq 0x3050
movq (%rsp), %r15
movq 0x38(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x58(%rsp,%rax)
jne 0x16665
movq %r12, %rdi
leaq 0xcc6d(%rip), %rsi      # 0x2311c
callq 0x32c0
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
leaq 0xcd2e(%rip), %rsi      # 0x231f4
callq 0x32c0
movq %rax, %rdi
callq 0x3120
leaq 0x1c616(%rip), %rcx     # 0x32af0
movl (%rcx,%r15,4), %esi
movq %rax, %rdi
callq 0x34b0
movq %rax, %rdi
leaq 0xc3eb(%rip), %rsi      # 0x228db
callq 0x32c0
leaq 0x1c5f4(%rip), %rcx     # 0x32af0
movl (%rcx,%r15,4), %esi
movq %rax, %rdi
callq 0x34b0
movq %rax, %rdi
callq 0x3120
movq %rax, %rdi
movl $0xff, %esi
callq 0x34b0
movq %rax, %rdi
callq 0x3120
movq %r12, %r14
leaq 0x1c5c1(%rip), %rax     # 0x32af0
movl (%rax,%r15,4), %r15d
imull %r15d, %r15d
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x165d2
movsd (%rbx,%r12,8), %xmm0
mulsd 0x10(%rsp), %xmm0
movapd %xmm0, %xmm1
andpd 0xbab5(%rip), %xmm1     # 0x22010
movsd 0xec25(%rip), %xmm2     # 0x25188
ucomisd %xmm1, %xmm2
jb 0x16646
addsd 0xec1b(%rip), %xmm0     # 0x25190
cvttsd2si %xmm0, %ebp
movq (%r13), %rax
movq -0x18(%rax), %rax
movq $0x4, 0x10(%r13,%rax)
movq %r13, %rdi
movl %ebp, %esi
callq 0x34b0
leaq 0x1c555(%rip), %rax     # 0x32af0
movq (%rsp), %rcx
movl (%rax,%rcx,4), %ecx
movl %r12d, %eax
cltd
idivl %ecx
decl %ecx
cmpl %ecx, %edx
jne 0x165b6
movq %r13, %rdi
callq 0x3120
cmpl $0x100, %ebp            # imm = 0x100
jae 0x16627
movsbl %bpl, %esi
movq %r14, %rdi
callq 0x3040
incq %r12
jmp 0x1653a
movq %r13, %rdi
callq 0x3120
movq %r14, %r12
movq %rax, %rdi
callq 0x3120
movq %r12, %rdi
callq 0x33c0
movq %r12, %rdi
callq 0x33e0
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x3548
movq (%rsp), %r14
incq %r14
leaq 0x1c500(%rip), %rbx     # 0x32b10
jmp 0x1642b
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xeef5(%rip), %rdi      # 0x25523
leaq 0xec8d(%rip), %rsi      # 0x252c2
leaq 0xee7d(%rip), %rcx      # 0x254b9
movl $0x1ec, %edx            # imm = 0x1EC
callq 0x31a0
leaq 0xeeb6(%rip), %rdi      # 0x25503
leaq 0xec6e(%rip), %rsi      # 0x252c2
leaq 0xee5e(%rip), %rcx      # 0x254b9
movl $0x1e4, %edx            # imm = 0x1E4
callq 0x31a0
leaq 0xcb66(%rip), %rdi      # 0x231d2
leaq 0xec4f(%rip), %rsi      # 0x252c2
leaq 0xee3f(%rip), %rcx      # 0x254b9
movl $0x1d3, %edx            # imm = 0x1D3
callq 0x31a0
jmp 0x16686
movq %rax, %rbx
jmp 0x1669c
jmp 0x1668f
jmp 0x1668f
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x33e0
leaq 0x18(%rsp), %rdi
callq 0x3548
movq %rbx, %rdi
callq 0x34d0