// File: /workspace/github_cpp_makefile_star2_O3/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 0x1ab64
xorpd %xmm0, %xmm0
xorl %eax, %eax
movapd 0xe1e5(%rip), %xmm2     # 0x2a010
leaq 0x1dcce(%rip), %rcx     # 0x39b00
movl (%rcx,%rax,4), %ecx
testl %ecx, %ecx
je 0x1be6c
imull %ecx, %ecx
leaq 0x1dcdd(%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 0x1be53
incq %rax
cmpq $0x7, %rax
jne 0x1be2b
movsd 0x1133b(%rip), %xmm1    # 0x2d1b8
divsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
movq 0x1b13a(%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 0x1b122(%rip), %r14     # 0x36fd0
movq %r13, %rdi
movq 0x38(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x9ee4
leaq 0x1dc59(%rip), %rax     # 0x39b20
movq (%rax,%r12,8), %rbx
movslq %r12d, %rax
leaq 0x1133f(%rip), %rcx     # 0x2d214
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
movq %r13, %rdi
callq 0x3540
movq %r13, %rdi
leaq 0xf2ef(%rip), %rsi      # 0x2b1dd
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 0x1c21e
movl $0x2, %edx
movq %r15, %rdi
leaq 0xf1f7(%rip), %rsi      # 0x2b12c
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 0xf28f(%rip), %rsi      # 0x2b204
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 0x1db58(%rip), %rcx     # 0x39b00
movl (%rcx,%r12,4), %esi
movq %rax, %rdi
callq 0x34e0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0xe929(%rip), %rsi      # 0x2a8ef
callq 0x3360
leaq 0x1db2e(%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 0x1daba(%rip), %rax     # 0x39b00
movl (%rax,%r12,4), %r13d
testl %r13d, %r13d
je 0x1c116
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 0xdf96(%rip), %xmm1     # 0x2a010
movsd 0x11136(%rip), %xmm2    # 0x2d1b8
ucomisd %xmm1, %xmm2
jb 0x1c1e0
addsd 0x1112c(%rip), %xmm0    # 0x2d1c0
cvttsd2si %xmm0, %ebp
movq (%r14), %rax
movq -0x18(%rax), %rax
movq $0x4, 0x10(%r14,%rax)
movq %r14, %rdi
movl %ebp, %esi
callq 0x34e0
leaq 0x1da47(%rip), %rax     # 0x39b00
movl (%rax,%r12,4), %ecx
movl %r15d, %eax
cltd
idivl %ecx
decl %ecx
cmpl %ecx, %edx
jne 0x1c0f0
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 0x1c1ff
movsbl %bpl, %esi
leaq 0x48(%rsp), %rdi
callq 0x3040
incq %r15
cmpq %r15, %r13
jne 0x1c062
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 0x1c1c1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3310
incq %r12
cmpq $0x7, %r12
jne 0x1beae
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1137c(%rip), %rdi     # 0x2d563
leaq 0x11134(%rip), %rsi     # 0x2d322
leaq 0x11324(%rip), %rcx     # 0x2d519
movl $0x1e4, %edx            # imm = 0x1E4
callq 0x31c0
leaq 0x1137d(%rip), %rdi     # 0x2d583
leaq 0x11115(%rip), %rsi     # 0x2d322
leaq 0x11305(%rip), %rcx     # 0x2d519
movl $0x1ec, %edx            # imm = 0x1EC
callq 0x31c0
leaq 0xefbd(%rip), %rdi      # 0x2b1e2
leaq 0x110f6(%rip), %rsi     # 0x2d322
leaq 0x112e6(%rip), %rcx     # 0x2d519
movl $0x1d3, %edx            # imm = 0x1D3
callq 0x31c0
jmp 0x1c23f
movq %rax, %rbx
jmp 0x1c255
jmp 0x1c248
jmp 0x1c248
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3400
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1c271
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3310
movq %rbx, %rdi
callq 0x3500
nop