# How to determine the subjective brightness of my screen?

## Recommended Posts

I like playing video games, and I like having the lights down low. My favourite game however, has pretty drastic brightness changes, and I can't cope with a bright screen in a dim room. Here is an example:

1 - Exploring a dark dungeon

2 - The interface is always very bright

3 - Regular gameplay is mostly like this

My intension is to control the lights in my room, especially around my desk, according to the subjective perceived brightness on screen.

I can properly grab screen RGB values from my games, and I can control my lamps. Both of that was rather easy.

I am struggling with finding the right approach how to map the screen buffer RGB values to the brightness I should set my lamps to.

My personal perception is that the images above are

1. dark (but not very dark)
2. very bright
3. medium to bright

There are formulas (like this one) that calculate the perceived reception of a single pixel but I don't think the "average perceived brightness" of the screen is going to help me much here. My feeling is that the bigger an adjacent, bright area is on screen, the brighter it seems to my eyes.

To make it even more challenging, I cannot make use of overly performance-hungry solutions like converting every RGB value into the HSL space. However, I think that analyzing every 10th pixel is still reasonable.

Any kind of idea is welcome.

Thank you for reading.

##### Link to post

What does this have to do with Delphi?

##### Link to post
1 hour ago, Anders Melander said:

What does this have to do with Delphi?

From what I perceive in the above report, he wants to do a "remote control" for the monitor and control the brightness of the lamp next to his computer, or even, control the screen brightness of MSWindows via his software, working in the background ... um spy for good in the darkness of your room! a RTX/DLSS homeless!

And, the chosen language was ... guess if you can!

Perhaps, in "C" I could give more performance in this task, or not !!!

NOTE: most likely, he should make use of the MSWindows API functions, directly or indirectly, to adjust the "GAMMA" efect!

NOTE2: maybe this help in this road...

hug

Edited by Guest

##### Link to post
6 hours ago, Anders Melander said:

What does this have to do with Delphi?

The category is "Algorithms, Data Structures and Class Design"

##### Link to post
52 minutes ago, Der schöne Günther said:

The category is "Algorithms, Data Structures and Class Design"

That doesn't answer the question. The overall category is "Delphi" and the Q doesn't have anything to do with Delphi.

You have a better chance of getting a usable answer to stuff like this on stackoverflow.

##### Link to post
2 hours ago, Anders Melander said:

That doesn't answer the question. The overall category is "Delphi" and the Q doesn't have anything to do with Delphi.

You have a better chance of getting a usable answer to stuff like this on stackoverflow.

Question as asked like here would not pass on Stack Overflow.

• 1

##### Link to post
Just now, Dalija Prasnikar said:

Question as asked like here would not pass on Stack Overflow.

And there's a lesson in that.

##### Link to post

Thanks for your concern, but if questions here on Delphi-Praxis are only allowed if they include at least one StringList and a DBGrid, I'd rather hear that from a moderator.

• 1

##### Link to post
2 hours ago, Anders Melander said:

And there's a lesson in that.

Yes, there is, but Delphi Praxis allows much broader questions than Stack Overflow.

So, while debugging questions here and there require same amount of information, algorithms generally don't fall into same category.

I don't think that asking for some pointers and ideas is somehow not welcome here. How does it relate with Delphi... well, obviously implementation would be in Delphi.

• 1

##### Link to post
15 hours ago, Der schöne Günther said:

Any kind of idea is welcome.

I did something not so similar but as an idea i think it might work for you nicely.

One client asked on behave of a client of his to add functionality to sort huge amount of small images (like icons and avatars) by colors similarity and closeness.

So i thought and thought and came by this idea to compress them all into very small images then after that analyze the colors and their corners.

For you it might work as i think you already have access to these big full screen frames, so try to capture one per second then compress/reencode it into small images like 64x64 or even 32x32 (16x16..10x10.. try to find what does work for you ) using PNG (jpeg might work but it is very lossy) PNG might be better option, use Windows WIC as it is fast, after that you need to get one number from these fewer pixels, so Light intensity (mentioned above) or image brightness or... any other formula will do, as it does reflect the brightness in all, only keep in mind the cofactors mentioned in SO might need to adjust for your use,

Now you have one number out of the screen frame lets call it B, and because how lighting and illuminating works the lighting, the following formula might be sufficient

T = E*(B^2)+L*B+C

E,L,C >=0

you need to find these cofactors manually to fit your need, as it is impossible to imagine what could work for you and your hardware, also they might be unneeded if your lighting will use thresholds like three steps but you will need them in case of linear change if you lighting can/must be controlled in range.

Hope that helps.

##### Link to post
3 hours ago, Dalija Prasnikar said:

Question as asked like here would not pass on Stack Overflow.

But we are not StackOverlfow. Thank god.

I''ve got some code for calculating brightness, but this is for converting color bitmaps to grayscale. I'm not sure whether this fits your purpose because perceived brightness of a screen might be different of the brightness of a picture.

```type
TRgbBrightnessChannelEnum = (rcbAverage, rcbFastLuminance, rcbRed, rcbGreen, rcbBlue, rcbLuminance);

function GetFastLuminance(_Red, _Green, _Blue: Byte): Byte;
begin
Result := Round(0.299 * _Red + 0.587 * _Green + 0.114 * _Blue);
end;

function GetRgbLuminance(_Red, _Green, _Blue: Byte): Byte;
var
Hls: THlsRec;
begin
GetRgbHls(_Red, _Green, _Blue, Hls);
{\$IFDEF dzUseGraphics32}
Result := Round(Hls.Luminance * HLSMAX);
{\$ELSE}
Result := Hls.Luminance;
{\$ENDIF}
end;

function GetRgbBrightness(_Red, _Green, _Blue: Byte; _Channel: TRgbBrightnessChannelEnum): Byte;
begin
case _Channel of
rcbAverage: Result := Round((_Red + _Green + _Blue) / 3);
rcbFastLuminance: Result := GetFastLuminance(_Red, _Green, _Blue);
rcbRed: Result := _Red;
rcbGreen: Result := _Green;
rcbBlue: Result := _Blue;
else //  rcbLuminance: ;
{\$IFDEF dzUseGraphics32}
Result := Round(GetRgbLuminance(_Red, _Green, _Blue) * HLSMAX);
{\$ELSE}
Result := GetRgbLuminance(_Red, _Green, _Blue);
{\$ENDIF}
end;
end;```

This is from the unit u_dzGraphicsUtils from my dzlib.

• 1

##### Link to post

It seems that, after a certain level of knowledge and life experience, and some practice, many people still do not understand that there are other people who need an answer, however obvious they are, however stupid they are, however insignificant that they are, etc.

Who asks, has doubt!

Whoever answers does not need to question (also) whether the question is insignificant, stupid, obvious, or any other reason!

If you have time available in your lifetime, in this life plan, simply answer!

Otherwise, ignore it! Go do something more important in your life!

that said,

hug to everyone! (even to hypocrites and geniuses cloistered in their holy ignorance of social life)

##### Link to post

In photo editors you usually have a histogram function which gives a distribution of the brightnes levels as a curve.

With that you could find out whether more of the image is dark or bright. Most such photo editors can calculate this really quicky.

So histogram might be a keyword to look for.

• 1

##### Link to post
On 2/6/2021 at 11:53 AM, Der schöne Günther said:

My intension is to control the lights in my room, especially around my desk, according to the subjective perceived brightness on screen.

(**bolding in the quote is mine -- John)

The term "reference" comes to mind.  You want to compare brightness level of the screen - as you see it - to the overall brightness level of the room.  You then want to adjust screen brightness to a value that suits your personal comfort level.  Essentially, *you* (your internal values) are the reference for this comparison.

*You* are the perceiver of the room and screen brightness levels.  So, these values are external to the computer.  As noted above, you also provide the reference value for comparison.  Meaning the reference value is also external to the computer.  Somehow, you have to get these 3 values into the computer (your software) in order for it to make appropriate screen adjustments.

If you want this to be an automated process, then ideally you will need to have room and screen brightness sensors sending data to the computer (your software).  You will also need to quantify the reference value (remove it from the subjective) for comparing room and screen brightness.

In the not-so-ideal world, maybe you can fudge a number for room brightness and do an internal calculation of screen brightness.  Perhaps a reference value could be arrived at by trial-and-error.  All this would remove the need for external hardware.

Make sense...?
John

Edited by jonnyg
• 1

##### Link to post
9 hours ago, jonnyg said:

You then want to adjust screen brightness

Actually he wants to adjust the room lighting:

9 hours ago, jonnyg said:

My﻿﻿ intension is to control the﻿ lights in ﻿my ﻿room﻿﻿

##### Link to post

You're right (about room lighting).  My bad.

##### Link to post

Thank you very much for the replies.

14 hours ago, TurboMagic said:

So histogram might be a keyword to look for.

Exactly, that looks promising. I will dig into that 👍

##### Link to post

@Der schöne Günther I.e. the overall luminosity of the image?

Unsure if there needs to be something additional in the equation as mathematical and perceived luminosity might not be the same?

##### Link to post
26 minutes ago, Lars Fosdal said:

Unsure if there needs to be something additional in the equation as mathematical and perceived luminosity might not be the same?

Since in the end, you cannot do anything about the monitor characteristics, or the adjustments applied by the user, I think that concern is probably below the noise level.

##### Link to post

In my experience, lower the display's contrast and brightness and set the gamma correction higher in the game.

Constantly changing lighting conditions can't be the answer for anything because it's just exhausting for the pupil.

That's why I have to turn off instantly in modern displays and w10 the automatic brightness correction.

On the other way, if you like it anyway, there are tons of DIY Ambilight kits on Ali*.

Edited by Attila Kovacs

##### Link to post
7 minutes ago, Bill Meyer said:

Since in the end, you cannot do anything about the monitor characteristics, or the adjustments applied by the user, I think that concern is probably below the noise level.

True, although he may need to take into the consideration whether the monitor and game is using HDR or not?

##### Link to post
1 hour ago, Attila Kovacs said:

there are tons of DIY Ambilight kits on Ali*.

Now where's the fun in that?

My desk lamp (pictures here) also has integration with something called "Razer Chroma", but I didn't really like it and decided to roll my own.

The regular room lamps are Philips Hue, but this desk lamp has extremely low latency and therefore is an excellent choice for coupling to the screen. The regular lamps have a noticeable delay.

1 hour ago, Lars Fosdal said:

need to take into the consideration whether the monitor and game is using HDR or not

Good point. The monitor does not support HDR. That would make it very challenging.

##### Link to post

Yes, it probably would (except for my desk lamp, which is not a Hue lamp).

But as I said, this is just a free time project for personal leisure. And the Hue Sync box probably has other limitations, which I will run into later. I'd like to have full flexibility here. I have no deadline. This is just for fun.

Edited by Der schöne Günther
• 1

##### Link to post
On 2/6/2021 at 11:53 AM, Der schöne Günther said:

My intension is to control the lights in my room, especially around my desk, according to the subjective perceived brightness on screen.

I can properly grab screen RGB values from my games, and I can control my lamps. Both of that was rather easy.

I couldn't see a way to edit/delete my earlier post where I misread what was being controlled.   😞  Anyway...

A bit off topic, but related:
How are you detecting the brightness of your lamps?  You must have some kind of photocell, or...?

If you had manual control of your lamps, you could make a visual brightness comparison, and adjust the lamps accordingly.  Presumably you want to automate this process (in software), in which case, how are you going to do that?  If you compare lamp brightness to screen brightness, how are you going to decide what's an appropriate match in software (this refers back to the "subjective" aspect)?

Someone else suggested that going this route (of frequent adjustment) might be visually disruptive.  I'm inclined to agree. But it's still an intriguing project.

John

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account