Skip to content

HexColor: how the convesion works? what's the maths behind? #1497

Answered by dlemstra
Gounlaf asked this question in Help
Discussion options

You must be logged in to vote

I used the same method as the one that was being used in ImageMagick. I don't know the logic behind this so that is why I asked GitHub copilot for an answer:

How would you scale a 16 bit short to an 8 bit char?

To scale a 16-bit short to an 8-bit char, you can perform a right shift operation by 8 bits. This operation effectively divides the 16-bit value by 256 (2^8), which scales it down to an 8-bit range. Please note that this operation may lose some data because it discards the least significant 8 bits. If you want to preserve more information, you might want to use a different scaling method, such as rounding to the nearest equivalent 8-bit value.

The operation that it suggested was

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@dlemstra
Comment options

Answer selected by Gounlaf
@Gounlaf
Comment options

Gounlaf Dec 26, 2023
Author Sponsor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants