// File: /workspace/github_cpp_makefile_star2_O3/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:
addl $0xfffff3c5, %ecx       # imm = 0xFFFFF3C5
cmpl $0x5, %ecx
ja 0x7ad5
leaq 0x1690c(%rip), %rax     # 0x1e260
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl (%rdi), %eax
testl %eax, %eax
jle 0x7ad5
xorl %ecx, %ecx
movzwl 0x4(%rsi,%rcx,8), %edi
movw %di, (%rdx,%rcx,8)
movzwl 0x2(%rsi,%rcx,8), %edi
movw %di, 0x2(%rdx,%rcx,8)
movzwl (%rsi,%rcx,8), %edi
movw %di, 0x4(%rdx,%rcx,8)
movzwl 0x6(%rsi,%rcx,8), %edi
movw %di, 0x6(%rdx,%rcx,8)
incq %rcx
cmpl %ecx, %eax
jne 0x7969
jmp 0x7ad5
movl (%rdi), %eax
testl %eax, %eax
jle 0x7ad5
xorl %ecx, %ecx
movzwl 0x4(%rsi,%rcx,8), %edi
imull $0x12b, %edi, %edi      # imm = 0x12B
movzwl 0x2(%rsi,%rcx,8), %r8d
imull $0x24b, %r8d, %r8d      # imm = 0x24B
addl %edi, %r8d
movzwl (%rsi,%rcx,8), %edi
imull $0x72, %edi, %edi
addl %r8d, %edi
imulq $0x10624dd3, %rdi, %rdi # imm = 0x10624DD3
shrq $0x26, %rdi
movw %di, (%rdx,%rcx,2)
incq %rcx
cmpl %ecx, %eax
jne 0x79a7
jmp 0x7ad5
movl (%rdi), %eax
testl %eax, %eax
jle 0x7ad5
xorl %ecx, %ecx
movzwl 0x4(%rsi,%rcx,8), %edi
movw %di, (%rdx)
movzwl 0x2(%rsi,%rcx,8), %edi
movw %di, 0x2(%rdx)
movzwl (%rsi,%rcx,8), %edi
movw %di, 0x4(%rdx)
incq %rcx
addq $0x6, %rdx
cmpl %ecx, %eax
jne 0x79f3
jmp 0x7ad5
movl (%rdi), %eax
testl %eax, %eax
jle 0x7ad5
xorl %ecx, %ecx
movzwl (%rsi,%rcx,8), %edi
movw %di, (%rdx)
movzwl 0x2(%rsi,%rcx,8), %edi
movw %di, 0x2(%rdx)
movzwl 0x4(%rsi,%rcx,8), %edi
movw %di, 0x4(%rdx)
incq %rcx
addq $0x6, %rdx
cmpl %ecx, %eax
jne 0x7a28
jmp 0x7ad5
movl (%rdi), %eax
testl %eax, %eax
jle 0x7ad5
xorl %ecx, %ecx
movzwl (%rsi,%rcx,8), %edi
movw %di, (%rdx,%rcx,8)
movzwl 0x2(%rsi,%rcx,8), %edi
movw %di, 0x2(%rdx,%rcx,8)
movzwl 0x4(%rsi,%rcx,8), %edi
movw %di, 0x4(%rdx,%rcx,8)
movzwl 0x6(%rsi,%rcx,8), %edi
movw %di, 0x6(%rdx,%rcx,8)
incq %rcx
cmpl %ecx, %eax
jne 0x7a59
jmp 0x7ad5
movl (%rdi), %eax
testl %eax, %eax
jle 0x7ad5
xorl %ecx, %ecx
movzwl 0x4(%rsi,%rcx,8), %edi
imull $0x12b, %edi, %edi      # imm = 0x12B
movzwl 0x2(%rsi,%rcx,8), %r8d
imull $0x24b, %r8d, %r8d      # imm = 0x24B
addl %edi, %r8d
movzwl (%rsi,%rcx,8), %edi
imull $0x72, %edi, %edi
addl %r8d, %edi
imulq $0x10624dd3, %rdi, %rdi # imm = 0x10624DD3
shrq $0x26, %rdi
movw %di, (%rdx,%rcx,4)
movzwl 0x6(%rsi,%rcx,8), %edi
movw %di, 0x2(%rdx,%rcx,4)
incq %rcx
cmpl %ecx, %eax
jne 0x7a90
retq