// File: kylegranger[P]ImageScaling/linear16.cpp
// Function: CLinear16::ReadSimpleScanline(unsigned short*, color_t*, ESimpleFormat)
void CLinear16::ReadSimpleScanline(uint16_t *src, color_t *dst, 
	ESimpleFormat format)
{
	switch (format)
	{
	case ESimpleFormatRgba:
		for (int i = 0; i < mWidth; i++)
		{
			dst->r = *src++;
			dst->g = *src++;
			dst->b = *src++;
			dst->a = *src++;
			dst++;
		}
		break;
	case ESimpleFormatBgra:
		for (int i = 0; i < mWidth; i++)
		{
			dst->b = *src++;
			dst->g = *src++;
			dst->r = *src++;
			dst->a = *src++;
			dst++;
		}
		break;
	case ESimpleFormatRgb:
		for (int i = 0; i < mWidth; i++)
		{
			dst->r = *src++;
			dst->g = *src++;
			dst->b = *src++;
			dst->a = 0xffff;
			dst++;
		}
		break;
	case ESimpleFormatBgr:
		for (int i = 0; i < mWidth; i++)
		{
			dst->b = *src++;
			dst->g = *src++;
			dst->r = *src++;
			dst->a = 0xffff;
			dst++;
		}
		break;
	case ESimpleFormatL:
		for (int i = 0; i < mWidth; i++)
		{
			dst->b = *src;
			dst->g = *src;
			dst->r = *src++;
			dst->a = 0xffff;
			dst++;
		}
		break;
	case ESimpleFormatLa:
		for (int i = 0; i < mWidth; i++)
		{
			dst->b = *src;
			dst->g = *src;
			dst->r = *src++;
			dst->a = *src++;
			dst++;
		}
		break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x1c(%rbp), %eax
addl $0xfffff3c5, %eax       # imm = 0xFFFFF3C5
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x5, %eax
ja 0xa920
movq -0x40(%rbp), %rax
leaq 0x16bcf(%rip), %rcx     # 0x211bc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, -0x20(%rbp)
movq -0x48(%rbp), %rcx
movl -0x20(%rbp), %eax
cmpl (%rcx), %eax
jge 0xa68d
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x6(%rax)
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xa5fd
jmp 0xa920
movl $0x0, -0x24(%rbp)
movq -0x48(%rbp), %rcx
movl -0x24(%rbp), %eax
cmpl (%rcx), %eax
jge 0xa729
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x6(%rax)
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xa699
jmp 0xa920
movl $0x0, -0x28(%rbp)
movq -0x48(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl (%rcx), %eax
jge 0xa7ae
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movq -0x18(%rbp), %rax
movw $0xffff, 0x6(%rax)      # imm = 0xFFFF
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xa735
jmp 0xa920
movl $0x0, -0x2c(%rbp)
movq -0x48(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl (%rcx), %eax
jge 0xa833
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x18(%rbp), %rax
movw $0xffff, 0x6(%rax)      # imm = 0xFFFF
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xa7ba
jmp 0xa920
movl $0x0, -0x30(%rbp)
movq -0x48(%rbp), %rcx
movl -0x30(%rbp), %eax
cmpl (%rcx), %eax
jge 0xa8a2
movq -0x10(%rbp), %rax
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x18(%rbp), %rax
movw $0xffff, 0x6(%rax)      # imm = 0xFFFF
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xa83f
jmp 0xa920
movl $0x0, -0x34(%rbp)
movq -0x48(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl (%rcx), %eax
jge 0xa91e
movq -0x10(%rbp), %rax
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0x10(%rbp)
movw (%rax), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x6(%rax)
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xa8ab
jmp 0xa920
popq %rbp
retq
nopw %cs:(%rax,%rax)