https://bugs.documentfoundation.org/show_bug.cgi?id=156182
--- Comment #4 from Heiko Tietze <heiko.tie...@documentfoundation.org> --- Created attachment 188297 --> https://bugs.documentfoundation.org/attachment.cgi?id=188297&action=edit Playground Here is a macro to play with the various approaches. Not only the calculation makes a difference but also the threshold. My personal favorite is the quick and dirty #5. We have two functions implemented, isDark() and isBright(), both taking the luminance into account with thresholds <=62 and >=245 resp. In between is neither dark nor bright and I cannot assess the implications (beside the positive effect on all the isDark() cases). Sub Main Doc = ThisComponent Sheets=Doc.Sheets Sheet=Sheets.getByName("sheet1") Dim aColor Dim aLum as Double Formula = 5 for i = 0 to 11 for j = 0 to 9 Cell=sheet.getcellByposition(i,j) aColor = Cell.CellBackColor Select Case Formula Case 0 REM current implementation in color.hxx aLum = (Red(aColor) * 76 + Green(aColor) * 151 + Blue(aColor) * 29) / 256 Threshold = 62 Case 1 REM Photometric/digital ITU BT.709: https://stackoverflow.com/questions/596216/formula-to-determine-perceived-brightness-of-rgb-color aLum = Red(aColor) * 0.2126 + Green(aColor) * 0.7152 + Blue(aColor) * 0.0722 Threshold = 150 Case 2 REM Digital ITU BT.601 aLum = Red(aColor) * 0.299 + Green(aColor) * 0.587 + Blue(aColor) * 0.114 Threshold = 150 Case 3 REM http://alienryderflex.com/hsp.html aLum = sqr( (Red(aColor)/255)^2 * 0.299 + (Green(aColor)/255)^2 * 0.587 + (Blue(aColor)/255)^2 * 0.114 ) Threshold = 0.6 Case 4 REM Andy's Down and Dirty Version; https://stackoverflow.com/questions/71410478/what-is-the-constant-k-in-calculating-the-luminance aLum = sqr( (Red(aColor)/255)^2.2 * 0.2126 + (Green(aColor)/255)^2.2 * 0.7152 + (Blue(aColor)/255)^2.2 * 0.0722 ) Threshold = 0.6 Case 5 REM https://www.w3.org/TR/AERT/#color-contrast aLum = (Red(aColor) * 299 + Green(aColor) * 587 + Blue(aColor) * 114) / 1000 Threshold = 150 end select if (aLum > Threshold) then Cell.CharColor = RGB(0,0,0) else Cell.CharColor = RGB(255,255,255) end if next j next i End Sub -- You are receiving this mail because: You are the assignee for the bug.