// File: /workspace/github_cpp_makefile_star2_O3/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, %r15
movq %rdi, %rbx
movl 0x8(%rdi), %esi
movq %r15, %rdi
xorl %edx, %edx
callq 0x2270
leaq 0x6(%rsp), %r14
movl $0x12, %edx
movq %r15, %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, %r12
cmpb $0x2, 0x2(%r14)
jne 0x7c1b
movl 0x8(%rbx), %eax
movzbl 0x6(%rsp), %ecx
leaq (%rax,%rcx), %rsi
addq $0x12, %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x2270
movzwl 0x12(%rsp), %eax
movzwl 0x14(%rsp), %ecx
imull %eax, %ecx
movzbl 0x16(%rsp), %edx
imull %ecx, %edx
shrl $0x3, %edx
movq %r15, 0x20(%rsp)
movq %r15, %rdi
movq %r12, 0x18(%rsp)
movq %r12, %rsi
callq 0x2240
testb $0x20, 0x17(%rsp)
jne 0x7bb9
movzwl 0x14(%rsp), %r10d
cmpq $0x2, %r10
jb 0x7bb9
movzbl 0x16(%rsp), %eax
movl %eax, %ecx
shrl $0x3, %ecx
movzwl 0x12(%rsp), %edx
movl %r10d, %esi
shrl %esi
cmpw $0x2, %dx
movl $0x1, %edi
cmovael %edx, %edi
movq %rdx, %r8
imulq %rcx, %r8
decq %r10
imulq %r8, %r10
movq 0x18(%rsp), %rbp
movq %rbp, %r9
addq %r10, %r9
movq %r8, %r10
negq %r10
xorl %r11d, %r11d
movl %edx, %ebx
testw %bx, %bx
je 0x7ba9
movq %r9, %r14
movq %rbp, %rbx
xorl %r12d, %r12d
cmpb $0x8, %al
jb 0x7b97
xorl %r15d, %r15d
movb (%rbx,%r15), %r13b
xorb (%r14,%r15), %r13b
movb %r13b, (%rbx,%r15)
xorb (%r14,%r15), %r13b
movb %r13b, (%r14,%r15)
xorb %r13b, (%rbx,%r15)
incq %r15
cmpq %r15, %rcx
jne 0x7b77
incq %r12
addq %rcx, %rbx
addq %rcx, %r14
cmpq %rdi, %r12
jne 0x7b70
movl %edx, %ebx
jmp 0x7bab
xorl %ebx, %ebx
incq %r11
addq %r8, %rbp
addq %r10, %r9
cmpq %rsi, %r11
jne 0x7b62
movq 0x20(%rsp), %rcx
movq (%rcx), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x20(%rcx,%rax)
jne 0x7c3f
movq 0x80(%rsp), %rax
movzwl 0x12(%rsp), %ecx
movq 0x28(%rsp), %rdx
movl %ecx, (%rdx)
movzwl 0x14(%rsp), %ecx
movq 0x30(%rsp), %rdx
movl %ecx, (%rdx)
movzbl 0x16(%rsp), %ecx
movq 0x38(%rsp), %rdx
movl %ecx, (%rdx)
movq 0x40(%rsp), %rcx
movq 0x18(%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 %r12, %rdi
callq 0x2250
movl $0x18, %edi
callq 0x20e0
movq %rax, %rbx
movq %rax, %rdi
movl $0x5, %esi
callq 0x831a
jmp 0x7c6a
movq 0x18(%rsp), %rdi
callq 0x2250
movl $0x18, %edi
callq 0x20e0
movq %rax, %rbx
leaq 0x2871(%rip), %rdx      # 0xa4ce
movq %rax, %rdi
movl $0x1, %esi
callq 0x8330
leaq 0x711f(%rip), %rsi      # 0xed90
leaq 0x6e4(%rip), %rdx       # 0x835c
movq %rbx, %rdi
callq 0x2320