// File: /workspace/github_cpp_makefile_star2_O1/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 0x83af
leaq 0x16f76(%rip), %rax     # 0x1f1a4
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl (%rdi), %eax
testl %eax, %eax
jle 0x83af
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 0x8243
jmp 0x83af
movl (%rdi), %eax
testl %eax, %eax
jle 0x83af
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 0x8281
jmp 0x83af
movl (%rdi), %eax
testl %eax, %eax
jle 0x83af
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 0x82cd
jmp 0x83af
movl (%rdi), %eax
testl %eax, %eax
jle 0x83af
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 0x8302
jmp 0x83af
movl (%rdi), %eax
testl %eax, %eax
jle 0x83af
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 0x8333
jmp 0x83af
movl (%rdi), %eax
testl %eax, %eax
jle 0x83af
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 0x836a
retq