// File: /workspace/github_cpp_makefile_star2_O1/ticky[P]ps2iconsys/gbLib/src/gbImageLoader_TGA.cpp
// Function: GhulbusUtil::gbImageType_TGA_T::ReadFile(std::basic_ifstream<char, std::char_traits<char>>&, int*, int*, int*, unsigned char**, unsigned int**)
void gbImageType_TGA_T::ReadFile(std::ifstream& file, int* width, int* height, int* bpp, 
			                       unsigned char** pp_data, unsigned int** pp_palette)
	{
		TGAHEADER header;
		file.seekg(m_file_offset, ::std::ios::beg);
		file.read( reinterpret_cast<char*>(&header), sizeof(TGAHEADER));
		unsigned char* data = new unsigned char[header.Width*header.Height*header.ImagePixelSize];

		switch(header.ImageTypeCode) {
			case 2:	//Unmapped RBG
				ReadUnmappedRBG(file, header, data, m_file_offset);
				if((header.ImageDescByte & 0x20) == 0) {		//Truvision?
					FlipImageVertical(header, data);
				}
				break;
			case 1:	case 3:	case 9:	case 10: case 11: case 32: case 33:
			default:
				delete[] data;
				throw( Ghulbus::gbException( Ghulbus::gbException::GB_NOTIMPLEMENTED ) );
		}

		if(file.fail()) {
			delete[] data;
			throw( Ghulbus::gbException( Ghulbus::gbException::GB_FAILED,
			                             "Error while reading TGA image file" ) );
		}
				
		*width      = header.Width;
		*height     = header.Height;
		*bpp        = header.ImagePixelSize;
		*pp_data    = data;
		*pp_palette = NULL;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
movl 0x8(%rdi), %esi
movq %r13, %rdi
xorl %edx, %edx
callq 0x2270
leaq 0xe(%rsp), %r14
movl $0x12, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x2240
movzwl 0xc(%r14), %eax
movzwl 0xe(%r14), %ecx
imull %eax, %ecx
movzbl 0x10(%r14), %edi
imull %ecx, %edi
callq 0x2030
movq %rax, %r15
cmpb $0x2, 0x2(%r14)
jne 0x7f0b
movl 0x8(%rbx), %eax
movzbl 0xe(%rsp), %ecx
leaq (%rax,%rcx), %rsi
addq $0x12, %rsi
movq %r13, %rdi
xorl %edx, %edx
callq 0x2270
movzwl 0x1a(%rsp), %eax
movzwl 0x1c(%rsp), %ecx
imull %eax, %ecx
movzbl 0x1e(%rsp), %edx
imull %ecx, %edx
shrl $0x3, %edx
movq %r13, %rdi
movq %r15, 0x20(%rsp)
movq %r15, %rsi
callq 0x2240
testb $0x20, 0x1f(%rsp)
jne 0x7eac
movzwl 0x1c(%rsp), %r9d
cmpq $0x2, %r9
jb 0x7eac
movzbl 0x1e(%rsp), %eax
movl %eax, %ecx
shrl $0x3, %ecx
movzwl 0x1a(%rsp), %edx
movl %r9d, %esi
shrl %esi
movq %rcx, %rdi
imulq %rdx, %rdi
decq %r9
imulq %rdi, %r9
movq 0x20(%rsp), %r11
movq %r11, %r8
addq %r9, %r8
movq %rdi, %r9
negq %r9
xorl %r10d, %r10d
testq %rdx, %rdx
je 0x7e9e
movq %r8, %rbx
movq %r11, %r14
xorl %r15d, %r15d
cmpb $0x8, %al
jb 0x7e90
xorl %r12d, %r12d
movb (%r14,%r12), %bpl
xorb (%rbx,%r12), %bpl
movb %bpl, (%r14,%r12)
xorb (%rbx,%r12), %bpl
movb %bpl, (%rbx,%r12)
xorb %bpl, (%r14,%r12)
incq %r12
cmpq %r12, %rcx
jne 0x7e70
incq %r15
addq %rcx, %r14
addq %rcx, %rbx
cmpq %rdx, %r15
jne 0x7e69
incq %r10
addq %rdi, %r11
addq %r9, %r8
cmpq %rsi, %r10
jne 0x7e5b
movq (%r13), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x20(%r13,%rax)
jne 0x7f2f
movq 0x80(%rsp), %rax
movzwl 0x1a(%rsp), %ecx
movq 0x28(%rsp), %rdx
movl %ecx, (%rdx)
movzwl 0x1c(%rsp), %ecx
movq 0x30(%rsp), %rdx
movl %ecx, (%rdx)
movzbl 0x1e(%rsp), %ecx
movq 0x38(%rsp), %rdx
movl %ecx, (%rdx)
movq 0x40(%rsp), %rcx
movq 0x20(%rsp), %rdx
movq %rdx, (%rcx)
movq $0x0, (%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x2250
movl $0x18, %edi
callq 0x20e0
movq %rax, %rbx
movq %rax, %rdi
movl $0x5, %esi
callq 0x85e2
jmp 0x7f5a
movq 0x20(%rsp), %rdi
callq 0x2250
movl $0x18, %edi
callq 0x20e0
movq %rax, %rbx
leaq 0x2531(%rip), %rdx      # 0xa47e
movq %rax, %rdi
movl $0x1, %esi
callq 0x85f8
leaq 0x6e2f(%rip), %rsi      # 0xed90
leaq 0x6bc(%rip), %rdx       # 0x8624
movq %rbx, %rdi
callq 0x2320