// File: kylegranger[P]ImageScaling/linear16.cpp
// Function: CLinear16::WriteSimpleScanline(color_t*, unsigned short*, ESimpleFormat)
void CLinear16::WriteSimpleScanline(color_t *src, uint16_t *dst, 
	ESimpleFormat format)
{

	switch (format)
	{
	case ESimpleFormatRgba:
		for (int i = 0; i < mWidth; i++)
		{
			*dst++ = src->r;
			*dst++ = src->g;
			*dst++ = src->b;
			*dst++ = src->a;
			src++;
		}
		break;
	case ESimpleFormatBgra:
		for (int i = 0; i < mWidth; i++)
		{
			*dst++ = src->b;
			*dst++ = src->g;
			*dst++ = src->r;
			*dst++ = src->a;
			src++;
		}
		break;
	case ESimpleFormatRgb:
		for (int i = 0; i < mWidth; i++)
		{
			*dst++ = src->r;
			*dst++ = src->g;
			*dst++ = src->b;
			src++;
		}
		break;
	case ESimpleFormatBgr:
		for (int i = 0; i < mWidth; i++)
		{
			*dst++ = src->b;
			*dst++ = src->g;
			*dst++ = src->r;
			src++;
		}
		break;
	case ESimpleFormatL:
		for (int i = 0; i < mWidth; i++)
		{
			*dst++ = (src->r * 299 + src->g * 587 + src->b * 114) / 1000;
			src++;
		}
		break;
	case ESimpleFormatLa:
		for (int i = 0; i < mWidth; i++)
		{
			*dst++ = (src->r * 299 + src->g * 587 + src->b * 114) / 1000;
			*dst++ = src->a;
			src++;
		}
		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 0xa5a8
movq -0x40(%rbp), %rax
leaq 0x16f37(%rip), %rcx     # 0x211a4
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 0xa30d
movq -0x10(%rbp), %rax
movw 0x4(%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw 0x2(%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw (%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw 0x6(%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xa27d
jmp 0xa5a8
movl $0x0, -0x24(%rbp)
movq -0x48(%rbp), %rcx
movl -0x24(%rbp), %eax
cmpl (%rcx), %eax
jge 0xa3a9
movq -0x10(%rbp), %rax
movw (%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw 0x2(%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw 0x4(%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw 0x6(%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xa319
jmp 0xa5a8
movl $0x0, -0x28(%rbp)
movq -0x48(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl (%rcx), %eax
jge 0xa424
movq -0x10(%rbp), %rax
movw 0x4(%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw 0x2(%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw (%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xa3b5
jmp 0xa5a8
movl $0x0, -0x2c(%rbp)
movq -0x48(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl (%rcx), %eax
jge 0xa49f
movq -0x10(%rbp), %rax
movw (%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw 0x2(%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw 0x4(%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xa430
jmp 0xa5a8
movl $0x0, -0x30(%rbp)
movq -0x48(%rbp), %rcx
movl -0x30(%rbp), %eax
cmpl (%rcx), %eax
jge 0xa514
movq -0x10(%rbp), %rax
movzwl 0x4(%rax), %eax
imull $0x12b, %eax, %eax      # imm = 0x12B
movq -0x10(%rbp), %rcx
movzwl 0x2(%rcx), %ecx
imull $0x24b, %ecx, %ecx      # imm = 0x24B
addl %ecx, %eax
movq -0x10(%rbp), %rcx
movzwl (%rcx), %ecx
imull $0x72, %ecx, %ecx
addl %ecx, %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
movw %ax, %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xa4ab
jmp 0xa5a8
movl $0x0, -0x34(%rbp)
movq -0x48(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl (%rcx), %eax
jge 0xa5a6
movq -0x10(%rbp), %rax
movzwl 0x4(%rax), %eax
imull $0x12b, %eax, %eax      # imm = 0x12B
movq -0x10(%rbp), %rcx
movzwl 0x2(%rcx), %ecx
imull $0x24b, %ecx, %ecx      # imm = 0x24B
addl %ecx, %eax
movq -0x10(%rbp), %rcx
movzwl (%rcx), %ecx
imull $0x72, %ecx, %ecx
addl %ecx, %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
movw %ax, %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movw 0x6(%rax), %cx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x18(%rbp)
movw %cx, (%rax)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xa520
jmp 0xa5a8
popq %rbp
retq
nopw (%rax,%rax)