// File: ticky[P]ps2iconsys/gbLib/src/gbImageLoader_BMP.cpp
// Function: GhulbusUtil::ReadData1Bit(std::basic_ifstream<char, std::char_traits<char>>&, GhulbusUtil::BITMAPINFOHEADER const&, GhulbusUtil::BITMAPFILEHEADER const&, unsigned char*, unsigned int**, unsigned int)
static void ReadData1Bit(std::ifstream& file, BITMAPINFOHEADER const& iheader, BITMAPFILEHEADER const& fheader, 
		                     unsigned char* data, unsigned int** palette, unsigned int file_offset)
	{
		switch(iheader.biCompression)
			{
			case 0:					//uncompressed rgb (1 bit, palettized)
				(*palette) = new unsigned int[2];
				file.read( reinterpret_cast<char*>(*palette), 8 );
				file.seekg( file_offset+fheader.bfOffBits, ::std::ios::beg );
				file.read( reinterpret_cast<char*>(data), (iheader.biWidth*iheader.biHeight)>>3 );
				//unpack data (currently each byte describes eight consecutive pixels):
				for(int i=(iheader.biWidth*iheader.biHeight)-1; i>=7; i-=8) {
					data[i]   = (data[(i>>3)] & 0x1);
					data[i-1] = (data[(i>>3)] & 0x2)  >> 1;
					data[i-2] = (data[(i>>3)] & 0x4)  >> 2;
					data[i-3] = (data[(i>>3)] & 0x8)  >> 3;
					data[i-4] = (data[(i>>3)] & 0x10) >> 4;
					data[i-5] = (data[(i>>3)] & 0x20) >> 5;
					data[i-6] = (data[(i>>3)] & 0x40) >> 6;
					data[i-7] = (data[(i>>3)] & 0x80) >> 7;
				}
				break;
			default:
				throw( Ghulbus::gbException( Ghulbus::gbException::GB_NOTIMPLEMENTED ) );
			}
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
testl %eax, %eax
jne 0xe9c5
jmp 0xe7f1
movl $0x8, %edi
callq 0x2040
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
movl $0x8, %edx
callq 0x2260
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %eax
movq -0x18(%rbp), %rcx
addl 0xa(%rcx), %eax
movl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2290
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
imull 0x8(%rcx), %eax
sarl $0x3, %eax
movslq %eax, %rdx
callq 0x2260
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
imull 0x8(%rcx), %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
cmpl $0x7, -0x30(%rbp)
jl 0xe9c3
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
andl $0x1, %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movslq -0x30(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
andl $0x2, %eax
sarl %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
andl $0x4, %eax
sarl $0x2, %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
andl $0x8, %eax
sarl $0x3, %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
andl $0x10, %eax
sarl $0x4, %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x4, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
andl $0x20, %eax
sarl $0x5, %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x5, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
andl $0x40, %eax
sarl $0x6, %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x6, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
andl $0x80, %eax
sarl $0x7, %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x7, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x30(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x30(%rbp)
jmp 0xe86a
jmp 0xe9f7
movl $0x18, %edi
callq 0x20f0
movq %rax, %rdi
movq %rdi, -0x38(%rbp)
movl $0x5, %esi
callq 0xf060
movq -0x38(%rbp), %rdi
leaq 0x93a5(%rip), %rsi      # 0x17d90
leaq 0x75e(%rip), %rdx       # 0xf150
callq 0x2340
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)