Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function HighContrastText(ABackground: TColor): TColor;
- var
- R, G, B, Luminance: Single;
- begin
- // Convert system color to RGB if needed
- ABackground := ColorToRGB(ABackground);
- // Calculate relative luminance using standard coefficients
- // Using ITU-R BT.709 coefficients
- R := (ABackground and $FF) / 255;
- G := ((ABackground shr 8) and $FF) / 255;
- B := ((ABackground shr 16) and $FF) / 255;
- Luminance := 0.2126 * R + 0.7152 * G + 0.0722 * B;
- // If background is dark, return white; if light, return black
- if Luminance < 0.5 then
- Result := clWhite
- else
- Result := clBlack;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement