// SPDX-License-Identifier: MIT
// Copyright (c) 2026 Incoprea
// Compare two display colors for contrast
// Not compiled or tested in-world
// Setup: Use a spare owned prim. Set FOREGROUND and BACKGROUND components0..1. Touch for owner-only numeric output.
// Stop / restore: Remove/disable; no colors or materials are applied.
// Notes: This is a numeric design aid; actual text readability also depends on size, weight, viewer rendering and lighting.
// License: see LICENSE in this distribution.
// Original Incoprea. MIT. Color calculation only.
vector FOREGROUND=<0.9,1.0,0.92>;
vector BACKGROUND=<0.05,0.12,0.08>;
float dec(float v)
{
    if(v<=0.04045)return v/12.92;
    return llPow((v+0.055)/1.055,2.4);
}
float lum(vector c)
{
    return 0.2126*dec(c.x)+0.7152*dec(c.y)+0.0722*dec(c.z);
}
default
{
    touch_start(integer detectedCount)
    {
        if(llDetectedKey(0)!=llGetOwner())return;
        float a=lum(FOREGROUND);
        float b=lum(BACKGROUND);
        if(a<b)
        {
            float temp=a;
            a=b;
            b=temp;
        }
        llOwnerSay("Contrast ratio="+(string)((a+0.05)/(b+0.05))+":1");
    }
}
