njsmith / colorspacious

A powerful, accurate, and easy-to-use Python library for doing colorspace conversions
MIT License
169 stars 16 forks source link

HDR10 support #30

Open Tronic opened 1 year ago

Tronic commented 1 year ago

Nowadays the most commonly needed conversion tends to be HDR, with all new displays doing that natively. The module is clearly designed for SDR, but would it be possible to implement a meaningful HDR conversion?

Note that HDR exists with linear brightness (float16 or float32) that can be expressed as linear RGB using the BT.2020 primaries, but on wire and on some surface pixmaps a 10-bit integer quantization (PQ curve) is used. Note that the range of values uses limited range 64-940 (inclusive from black to peak up to 10 000 nits). sRGB white point would typically be mapped around 200 nits but may be configurable (brightness setting, or simply multiply values in linear space). To add to that complication, both RGB (all components either float linear or PQ10) and YUV formats are available (YUV apparently have 8 bit U and V as usual but Y using that 10 bit PQ curve).

https://en.wikipedia.org/wiki/Rec._2100 - HDR10 standard, BT.2020 primaries https://en.wikipedia.org/wiki/Perceptual_quantizer - PQ transfer function

And if anyone wants to dive into the YUV conversion, this thread has proper (full range RGB to limited range YUV conversions in 8 bits, just need to change Y to use PQ apparently):

https://stackoverflow.com/questions/17892346/how-to-convert-rgb-yuv-rgb-both-ways