// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movl 0x8(%rax), %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2290
movq -0x10(%rbp), %rdi
leaq -0x42(%rbp), %rsi
movl $0x12, %edx
callq 0x2260
movzwl -0x36(%rbp), %eax
movzwl -0x34(%rbp), %ecx
imull %ecx, %eax
movzbl -0x32(%rbp), %ecx
imull %ecx, %eax
movslq %eax, %rdi
callq 0x2040
movq %rax, -0x50(%rbp)
movzbl -0x40(%rbp), %eax
movl %eax, -0x54(%rbp)
subl $0x1, %eax
je 0xdfde
jmp 0xdf7d
movl -0x54(%rbp), %eax
subl $0x2, %eax
je 0xdfab
jmp 0xdf87
movl -0x54(%rbp), %eax
subl $0x3, %eax
je 0xdfde
jmp 0xdf91
movl -0x54(%rbp), %eax
addl $-0x9, %eax
subl $0x3, %eax
jb 0xdfde
jmp 0xdf9e
movl -0x54(%rbp), %eax
addl $-0x20, %eax
subl $0x2, %eax
jb 0xdfde
jmp 0xdfe0
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rdx
movl 0x8(%rax), %ecx
leaq -0x42(%rbp), %rsi
callq 0xe0d0
movzbl -0x31(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0xdfdc
movq -0x50(%rbp), %rsi
leaq -0x42(%rbp), %rdi
callq 0xe150
jmp 0xe029
jmp 0xdfe0
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0xdff7
movq -0x68(%rbp), %rdi
callq 0x2270
movl $0x18, %edi
callq 0x20f0
movq %rax, %rdi
movq %rdi, -0x70(%rbp)
movl $0x5, %esi
callq 0xf060
movq -0x70(%rbp), %rdi
leaq 0x9d73(%rip), %rsi      # 0x17d90
leaq 0x112c(%rip), %rdx      # 0xf150
callq 0x2340
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
addq -0x18(%rax), %rdi
callq 0x2030
testb $0x1, %al
jne 0xe03f
jmp 0xe08f
movq -0x50(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, %rax
je 0xe056
movq -0x78(%rbp), %rdi
callq 0x2270
movl $0x18, %edi
callq 0x20f0
movq %rax, %rdi
movq %rdi, -0x80(%rbp)
movl $0x1, %esi
leaq 0x33ee(%rip), %rdx      # 0x11461
callq 0xf0b0
movq -0x80(%rbp), %rdi
leaq 0x9d0d(%rip), %rsi      # 0x17d90
leaq 0x10c6(%rip), %rdx      # 0xf150
callq 0x2340
movzwl -0x36(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movzwl -0x34(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movzbl -0x32(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq 0x10(%rbp), %rax
movq $0x0, (%rax)
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)