Color functions. Only 8bit RGB supported?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
GothicIII
Posts: 20
Joined: 17 May 2022, 04:16

Color functions. Only 8bit RGB supported?

Post by GothicIII » 17 May 2022, 04:45

Hello ahk community,

my goal is to simply read RGB values from a pixel to compare them against other values.
While the 8bit colorpalette is working fine (0x00BBGGRR) I have difficulties to realize this with 10/12bit depth content.
Many areas are returning 0xFFFFFF as color which translates to white while the real displayed color is different.

=> If I turn off HDR while inside the application the picture becomes too bright which marks many areas as white
(as expected due to the lost color information which confirms that only 8bit RGB is supported from PixelGetColor()).

I understand that the builtin-Function PixelGetColor() only outputs 8bit-RGB values, so nothing to do here.

Another approach I tried was using builtin windows function with dllcall.
Using user32.dll and gdi32.dll functions I thought I should somehow retrieve the correct results:

Code: Select all

;Create device handle
dc:=DllCall("user32\GetDC", "int", 0)
;Retrieve Pixel from x and y coordinates
pixel:=dllcall("gdi32\GetPixel", "int", dc, "int", x, "int", y, "int")
But the pixel-value is the same as the result of PixelGetColor(). Digging deeper the GetPixel-Function returns a COLORREF value. And this value is also only 8bit-RGB.

There are some more advanced complex functions like BitBlt() but currently I don't know if it is worth the time to figure it out how it works since
it requires a bit copy operation to another handle and I don't want go down that rabbit hole where I need to write like 5 functions just to retrieve a color from a pixel.

Are there any simple ways to retrieve 10bit colors?

Greetings

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: Color functions. Only 8bit RGB supported?

Post by boiler » 17 May 2022, 07:01

The premise and the terminology used in your question are wrong. You are implying that AHK is not representing the full color pallet that Windows is using to display colors. 0xFFFFFF is not an 8-bit color pallet. Each component (red, green, and blue) is made up of one byte, which is 8 bits each (ranging from 0 to 255 or 0x00 to 0xFF in value). It is a total of 3 bytes for RGB and 4 bytes when you include the alpha channel which produces over 16 million colors compared to the 1 byte of an 8-bit pallet that can produce only 256 different colors. An 8-bit pallet can only devote 2 or 3 bits to each RGB component.

There are no more bits to be added beyond what AHK uses to represent colors that are otherwise used by Windows. So now that you know that PixelGetColor() is indeed retrieving the “true color” values, you should be checking how you are locating the pixels making the comparisons in your script. The issue is not due to a limitation in AHK’s treatment of colors. If it is returning white when you think it should be different, the issue is probably that you are not using the correct coordinates and/or coordinate reference (see CoordMode).

Another issue could be the particular window from which you are trying to retrieve the colors. Test it on a simple MS Paint or similar window that you know isn’t being rendered in some sort of hardware accelerated mode first.

GothicIII
Posts: 20
Joined: 17 May 2022, 04:16

Re: Color functions. Only 8bit RGB supported?

Post by GothicIII » 17 May 2022, 07:47

Thanks for correcting me.

My code works when I try to get the pixel color out of a dx12 application when rendered in SDR (8bit depth for each color channel). Since the pixels I check are not transparent, the alpha channel can be ignored.
The problem comes up when I switch to HDR (deep color) mode. My understanding is that each color channel (RGB) is expanded to 10bits. That means each color channel has the range from 0x000 to 0x3FF (0xFFF with 12bit depth).
So I thought that 10bit RGB-data should be longer.

It is not a problem with coordmode since the same code is working in SDR. e.g. the original color 0x99CC33 appears in HDR as 0xFFFF2D and 0xD3BC8E, 0x3B4255 both appear as 0xFFFFFF.
If I disable HDR (Win+Alt+B) inside the application the color palette is not reloaded but just converted back to 8bits for each color channel. And those pixels I check are indeed white.

That's why I assumed that PixelGetColor does not work with a wider color gamut.

I am no expert in that topic. Maybe I need to retrieve the color in another format?
If I check my display settings the color output is set to YCbCr444 (chroma subsampling) with 10bit color depth if HDR is on. HDR set to off, the color output falls back to regular RGB.

Am I completly wrong in that regard?

EDIT: If I take a screenshot inside the HDR application and paste it in paint, the same effect happens. Meaning the relevant sections are all bright white.
Last edited by GothicIII on 17 May 2022, 11:07, edited 1 time in total.

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: Color functions. Only 8bit RGB supported?

Post by boiler » 17 May 2022, 08:46

OK, well it does look like you really do mean a deeper color mode than the 8-bits per channel. I am not going to be able to help you there, but thanks for clarifying.

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Color functions. Only 8bit RGB supported?

Post by iseahound » 18 May 2022, 11:17

GothicIII wrote:
17 May 2022, 04:45
Many areas are returning 0xFFFFFF as color which translates to white while the real displayed color is different.
Really? Give one of these apps a shot:

viewtopic.php?t=66463

and include a screenshot if possible

iPhilip
Posts: 801
Joined: 02 Oct 2013, 12:21

Re: Color functions. Only 8bit RGB supported?

Post by iPhilip » 18 May 2022, 18:39

@GothicIII, As you already observed from your tests, the PixelGetColor and the underlying GetPixel fuctions return a COLORREF value which is, by definition, an 8bit-RGB value (0x00BBGGRR). When using high dynamic range displays (HDR) you must rely on a different set of rendering APIs. See Using DirectX with high dynamic range Displays and Advanced Color for more information.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

GothicIII
Posts: 20
Joined: 17 May 2022, 04:16

Re: Color functions. Only 8bit RGB supported?

Post by GothicIII » 20 May 2022, 04:10

@iPhilip
Yeah thanks for confirming the problem.

Seems I am the 1st one digging into it. I thought HDR is not that niche on PC. What a bummer.

I scrolled over some of the documentation you linked and also followed the further links but currently I don't see any easy solution here especially not for AHK.
Having two ideas:
-(fast) accessing the frame buffer directly to get the pixel information (don't know if directx allows this. I know on unix it is possible). But this is beyond my capabilities.
-(slow) Write a capture method and store a format which is compatible with wide color gammut and interpret the captured data to get the pixel information.

I could do the 2nd method but this will go deep down to my personal queue from my todo-list...

iPhilip
Posts: 801
Joined: 02 Oct 2013, 12:21

Re: Color functions. Only 8bit RGB supported?

Post by iPhilip » 20 May 2022, 10:45

GothicIII wrote:
20 May 2022, 04:10
I could do the 2nd method but this will go deep down to my personal queue from my todo-list...
I hear you. Same here.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

Post Reply

Return to “Ask for Help (v2)”