// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/libsquish/rangefit.cpp
// Function: squish::RangeFit::RangeFit(squish::ColourSet const*, int, float*)
RangeFit::RangeFit( ColourSet const* colours, int flags, float* metric )
  : ColourFit( colours, flags )
{
    // initialise the metric (old perceptual = 0.2126f, 0.7152f, 0.0722f)
    if( metric )
        m_metric = Vec3( metric[0], metric[1], metric[2] );
    else
        m_metric = Vec3( 1.0f );

    // initialise the best error
    m_besterror = FLT_MAX;

    // cache some values
    int const count = m_colours->GetCount();
    Vec3 const* values = m_colours->GetPoints();
    float const* weights = m_colours->GetWeights();

    // get the covariance matrix
    Sym3x3 covariance = ComputeWeightedCovariance( count, values, weights );

    // compute the principle component
    Vec3 principle = ComputePrincipleComponent( covariance );

    // get the min and max range as the codebook endpoints
    Vec3 start( 0.0f );
    Vec3 end( 0.0f );
    if( count > 0 )
    {
        float min, max;

        // compute the range
        start = end = values[0];
        min = max = Dot( values[0], principle );
        for( int i = 1; i < count; ++i )
        {
            float val = Dot( values[i], principle );
            if( val < min )
            {
                start = values[i];
                min = val;
            }
            else if( val > max )
            {
                end = values[i];
                max = val;
            }
        }
    }

    // clamp the output to [0, 1]
    Vec3 const one( 1.0f );
    Vec3 const zero( 0.0f );
    start = Min( one, Max( zero, start ) );
    end = Min( one, Max( zero, end ) );

    // clamp to the grid and save
    Vec3 const grid( 31.0f, 63.0f, 31.0f );
    Vec3 const gridrcp( 1.0f/31.0f, 1.0f/63.0f, 1.0f/31.0f );
    Vec3 const half( 0.5f );
    m_start = Truncate( grid*start + half )*gridrcp;
    m_end = Truncate( grid*end + half )*gridrcp;
}

// Assembly:
subq $0x2b8, %rsp            # imm = 0x2B8
movq %rdi, 0x2b0(%rsp)
movq %rsi, 0x2a8(%rsp)
movl %edx, 0x2a4(%rsp)
movq %rcx, 0x298(%rsp)
movq 0x2b0(%rsp), %rdi
movq %rdi, 0x48(%rsp)
movq 0x2a8(%rsp), %rsi
movl 0x2a4(%rsp), %edx
callq 0xac5b0
movq 0x48(%rsp), %rdi
leaq 0x2155d(%rip), %rax     # 0xcec30
addq $0x10, %rax
movq %rax, (%rdi)
addq $0x14, %rdi
callq 0xab3a0
movq 0x48(%rsp), %rdi
addq $0x20, %rdi
callq 0xab3a0
movq 0x48(%rsp), %rdi
addq $0x2c, %rdi
callq 0xab3a0
cmpq $0x0, 0x298(%rsp)
je 0xad75a
movq 0x298(%rsp), %rax
movss (%rax), %xmm0
movq 0x298(%rsp), %rax
movss 0x4(%rax), %xmm1
movq 0x298(%rsp), %rax
movss 0x8(%rax), %xmm2
leaq 0x28c(%rsp), %rdi
callq 0xabe10
movq 0x48(%rsp), %rax
movq 0x28c(%rsp), %rcx
movq %rcx, 0x14(%rax)
movl 0x294(%rsp), %ecx
movl %ecx, 0x1c(%rax)
jmp 0xad78a
leaq 0x280(%rsp), %rdi
movss 0x5696(%rip), %xmm0     # 0xb2e00
callq 0xad380
movq 0x48(%rsp), %rax
movq 0x280(%rsp), %rcx
movq %rcx, 0x14(%rax)
movl 0x288(%rsp), %ecx
movl %ecx, 0x1c(%rax)
movq 0x48(%rsp), %rax
movl $0x7f7fffff, 0x38(%rax) # imm = 0x7F7FFFFF
movq 0x8(%rax), %rdi
callq 0xa43d0
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x27c(%rsp)
movq 0x8(%rax), %rdi
callq 0xab450
movq %rax, %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x270(%rsp)
movq 0x8(%rax), %rdi
callq 0xab460
movq %rax, 0x268(%rsp)
movl 0x27c(%rsp), %esi
movq 0x270(%rsp), %rdx
movq 0x268(%rsp), %rcx
leaq 0x250(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0xacc00
movq 0x40(%rsp), %rdi
callq 0xacfc0
movss %xmm1, 0x238(%rsp)
movlpd %xmm0, 0x230(%rsp)
movq 0x230(%rsp), %rax
movq %rax, 0x244(%rsp)
movl 0x238(%rsp), %eax
movl %eax, 0x24c(%rsp)
leaq 0x220(%rsp), %rdi
xorps %xmm0, %xmm0
callq 0xad380
leaq 0x210(%rsp), %rdi
xorps %xmm0, %xmm0
callq 0xad380
cmpl $0x0, 0x27c(%rsp)
jle 0xad9da
movq 0x270(%rsp), %rax
movq (%rax), %rcx
movq %rcx, 0x210(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x218(%rsp)
movq 0x210(%rsp), %rax
movq %rax, 0x220(%rsp)
movl 0x218(%rsp), %eax
movl %eax, 0x228(%rsp)
movq 0x270(%rsp), %rdi
leaq 0x244(%rsp), %rsi
callq 0xab480
movss %xmm0, 0x208(%rsp)
movss %xmm0, 0x20c(%rsp)
movl $0x1, 0x204(%rsp)
movl 0x204(%rsp), %eax
cmpl 0x27c(%rsp), %eax
jge 0xad9d8
movq 0x270(%rsp), %rdi
movslq 0x204(%rsp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rdi
leaq 0x244(%rsp), %rsi
callq 0xab480
movss %xmm0, 0x200(%rsp)
movss 0x200(%rsp), %xmm1
movss 0x20c(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xad96d
movq 0x270(%rsp), %rax
movslq 0x204(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, 0x220(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x228(%rsp)
movss 0x200(%rsp), %xmm0
movss %xmm0, 0x20c(%rsp)
jmp 0xad9c0
movss 0x200(%rsp), %xmm0
ucomiss 0x208(%rsp), %xmm0
jbe 0xad9be
movq 0x270(%rsp), %rax
movslq 0x204(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, 0x210(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x218(%rsp)
movss 0x200(%rsp), %xmm0
movss %xmm0, 0x208(%rsp)
jmp 0xad9c0
jmp 0xad9c2
movl 0x204(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x204(%rsp)
jmp 0xad8d5
jmp 0xad9da
leaq 0x1f4(%rsp), %rdi
movq %rdi, 0x10(%rsp)
movss 0x5411(%rip), %xmm0     # 0xb2e00
callq 0xad380
leaq 0x1e8(%rsp), %rdi
movq %rdi, 0x8(%rsp)
xorps %xmm0, %xmm0
callq 0xad380
movq 0x8(%rsp), %rdi
leaq 0x220(%rsp), %rsi
movq %rsi, 0x18(%rsp)
callq 0xae760
movq 0x10(%rsp), %rdi
movss %xmm1, 0x1c0(%rsp)
movlpd %xmm0, 0x1b8(%rsp)
movl 0x1c0(%rsp), %eax
movl %eax, 0x1d0(%rsp)
movq 0x1b8(%rsp), %rax
movq %rax, 0x1c8(%rsp)
leaq 0x1c8(%rsp), %rsi
callq 0xae6c0
movq 0x8(%rsp), %rdi
movss %xmm1, 0x1b0(%rsp)
movlpd %xmm0, 0x1a8(%rsp)
movl 0x1b0(%rsp), %eax
movl %eax, 0x1e0(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x1d8(%rsp)
movl 0x1e0(%rsp), %eax
movl %eax, 0x228(%rsp)
movq 0x1d8(%rsp), %rax
movq %rax, 0x220(%rsp)
leaq 0x210(%rsp), %rsi
movq %rsi, 0x28(%rsp)
callq 0xae760
movq 0x10(%rsp), %rdi
movss %xmm1, 0x180(%rsp)
movlpd %xmm0, 0x178(%rsp)
movl 0x180(%rsp), %eax
movl %eax, 0x190(%rsp)
movq 0x178(%rsp), %rax
movq %rax, 0x188(%rsp)
leaq 0x188(%rsp), %rsi
callq 0xae6c0
movss %xmm1, 0x170(%rsp)
movlpd %xmm0, 0x168(%rsp)
movl 0x170(%rsp), %eax
movl %eax, 0x1a0(%rsp)
movq 0x168(%rsp), %rax
movq %rax, 0x198(%rsp)
movl 0x1a0(%rsp), %eax
movl %eax, 0x218(%rsp)
movq 0x198(%rsp), %rax
movq %rax, 0x210(%rsp)
leaq 0x15c(%rsp), %rdi
movq %rdi, 0x20(%rsp)
movss 0x8a74(%rip), %xmm1     # 0xb65e0
movss 0xcf0c(%rip), %xmm2     # 0xbaa80
movaps %xmm2, %xmm0
callq 0xabe10
leaq 0x150(%rsp), %rdi
movq %rdi, 0x38(%rsp)
movss 0xceeb(%rip), %xmm1     # 0xbaa7c
movss 0xcedf(%rip), %xmm2     # 0xbaa78
movaps %xmm2, %xmm0
callq 0xabe10
leaq 0x144(%rsp), %rdi
movq %rdi, 0x30(%rsp)
movss 0x8a12(%rip), %xmm0     # 0xb65c8
callq 0xad380
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0xae800
movq 0x30(%rsp), %rsi
movss %xmm1, 0x100(%rsp)
movlpd %xmm0, 0xf8(%rsp)
movl 0x100(%rsp), %eax
movl %eax, 0x110(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x108(%rsp)
leaq 0x108(%rsp), %rdi
callq 0xae990
movss %xmm1, 0xf0(%rsp)
movlpd %xmm0, 0xe8(%rsp)
movl 0xf0(%rsp), %eax
movl %eax, 0x120(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x118(%rsp)
leaq 0x118(%rsp), %rdi
callq 0xae870
movq 0x38(%rsp), %rsi
movss %xmm1, 0xe0(%rsp)
movlpd %xmm0, 0xd8(%rsp)
movl 0xe0(%rsp), %eax
movl %eax, 0x130(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x128(%rsp)
leaq 0x128(%rsp), %rdi
callq 0xae800
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x48(%rsp), %rax
movss %xmm1, 0xd0(%rsp)
movlpd %xmm0, 0xc8(%rsp)
movl 0xd0(%rsp), %ecx
movl %ecx, 0x140(%rsp)
movq 0xc8(%rsp), %rcx
movq %rcx, 0x138(%rsp)
movl 0x140(%rsp), %ecx
movl %ecx, 0x28(%rax)
movq 0x138(%rsp), %rcx
movq %rcx, 0x20(%rax)
callq 0xae800
movq 0x30(%rsp), %rsi
movss %xmm1, 0x88(%rsp)
movlpd %xmm0, 0x80(%rsp)
movl 0x88(%rsp), %eax
movl %eax, 0x98(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x90(%rsp), %rdi
callq 0xae990
movss %xmm1, 0x78(%rsp)
movlpd %xmm0, 0x70(%rsp)
movl 0x78(%rsp), %eax
movl %eax, 0xa8(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0xae870
movq 0x38(%rsp), %rsi
movss %xmm1, 0x68(%rsp)
movlpd %xmm0, 0x60(%rsp)
movl 0x68(%rsp), %eax
movl %eax, 0xb8(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0xb0(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0xae800
movq 0x48(%rsp), %rax
movss %xmm1, 0x58(%rsp)
movlpd %xmm0, 0x50(%rsp)
movq 0x50(%rsp), %rcx
movq %rcx, 0xbc(%rsp)
movl 0x58(%rsp), %ecx
movl %ecx, 0xc4(%rsp)
movq 0xbc(%rsp), %rcx
movq %rcx, 0x2c(%rax)
movl 0xc4(%rsp), %ecx
movl %ecx, 0x34(%rax)
addq $0x2b8, %rsp            # imm = 0x2B8
retq
nopw %cs:(%rax,%rax)