Get Dynamic Range Color from HDR content

I have a app that extend the brightness of XDR display. In other words the default 100% brightness is not 1600nits brightness. To make it possible we need extend it max value.
This script is not about that but I was intresting to know more about HDR.

To test this AppleScript you need to have a display with HDR support.
The content could be any video of YouTube with HDR support.

If the content is playing it return Dynamic Range Color value

If the return of maximumPotentialExtendedDynamicRangeColorComponentValue is 1.0
it could mean 2 things. You display screen do not support HDR or the content is not HDR.

use framework "Foundation"
use scripting additions

set theScreen to current application's NSScreen's mainScreen()
-- Check if we are in EDR mode (extended dynamic range)
set displayMode to theScreen's maximumPotentialExtendedDynamicRangeColorComponentValue()

if (displayMode is 16.0) then
	if theScreen's maximumExtendedDynamicRangeColorComponentValue() is not 1.0 then
		set theResult to theScreen's maximumExtendedDynamicRangeColorComponentValue()
	else
		set theResult to "The content is not HDR or the screen do not support HDR"
	end if
end if

set theResult to "Dynamic Range Color: " & theResult
return theResult

Maybe I have done something wrong but this code do something very strange.

If the target value is 1.0

If the range value is 1.1 - 16.0 it will return true, but 1.5 - 16.0 return false
Its looks like a value between 1.0-1.499999 is same as 1.0
Maybe Objective-C bridge convert the real to integer and back to real and that why.

use framework "Foundation"
use scripting additions

set theScreen to current application's NSScreen's mainScreen()
set displayMode to theScreen's maximumPotentialExtendedDynamicRangeColorComponentValue()

set dynamicRangeColorValue to theScreen's maximumExtendedDynamicRangeColorComponentValue()
set theRange to current application's NSMakeRange(1.49, 16.0)
if current application's NSLocationInRange(dynamicRangeColorValue, theRange) then
	return dynamicRangeColorValue
else
	return "The content is not HDR or the screen do not support HDR"
end if

I feel stupid I should have checked the method of NSMakeRange. it use NSInteger

:wink:

Its most likely that maximumExtendedDynamicRangeColorComponentValue would be more 2 if the content video is HDR. So we could use {2,16}. So if the content is not HDR or the screen do not support HDR we will get a value of 1.0

use framework "Foundation"
use scripting additions

set theScreen to current application's NSScreen's mainScreen()
set displayMode to theScreen's maximumPotentialExtendedDynamicRangeColorComponentValue()
log displayMode
if displayMode is 16.0 then
	set dynamicRangeColorValue to theScreen's maximumExtendedDynamicRangeColorComponentValue()
	log dynamicRangeColorValue() as real
	set theRange to {2, 16}
	if current application's NSLocationInRange(dynamicRangeColorValue, theRange) then
		return dynamicRangeColorValue
	else
		return "The content is not HDR or the Screen do not support HDR"
	end if
end if