Recent

Author Topic: GtoH  (Read 1554 times)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
GtoH
« on: January 23, 2023, 10:47:30 pm »
I am trying to find additional information on the "GtoH" function discussed here

https://wiki.lazarus.freepascal.org/BGRABitmap_tutorial_4

Can anyone point me to some references?

Cheers

EDIT: Sorry, I meant this for BGRABitmap. I can't seem to delete it and repost. Can the mod move it?
« Last Edit: January 23, 2023, 11:00:21 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: GtoH
« Reply #1 on: January 24, 2023, 12:01:02 am »
basiccolorspace.inc:
Code: Pascal  [Select][+][-]
  1.   {** Converts a G hue (GSBA) to a H hue (HSLA) }
  2.   function GtoH(ghue: word): word;


VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: GtoH
« Reply #2 on: January 24, 2023, 12:19:08 am »
Yes, that is the function, but what is GSAB?

That is my question.

“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: GtoH
« Reply #3 on: January 24, 2023, 12:26:50 am »
@VTwin
perhaps this can help ? https://wiki.freepascal.org/BGRABitmap_Pixel_types

Quote
TGSBAPixel = THSLAPixel;

Pixel color defined in corrected HSL colorspace. G stands for corrected hue and B stands for actual brightness. Values range from 0 to 65535

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: GtoH
« Reply #4 on: January 24, 2023, 12:40:17 am »
Thanks TRon. I am familiar with that page. It does not give information on the model though. I am looking for external information on the transformation.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: GtoH
« Reply #5 on: January 24, 2023, 12:49:37 am »
I do not believe you are able to find anything external as afaik it is an internal used format to correct a pixel in the HSL colorspace.

Any details should then come from the author. Do note afaik.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: GtoH
« Reply #6 on: January 24, 2023, 02:28:24 pm »
I meant "GSB". Gamma corrected hue, Saturation, Brightness, I guess.

https://wiki.freepascal.org/LazPaint_LZP_Format

Quote
"HSL is the standard HSL colorspace, without gamma correction
GSB is the corrected HSL colorspace of LazPaint. It is computed with gamma correction and the B (brightness) component correspond to the perceived lightness"

https://wiki.lazarus.freepascal.org/BGRABitmap_tutorial_4#Using_HSLA_colorspace

Quote
"HSLA colors have gamma correction, but..."

Maybe it is specific to LazPaint, but I was hoping to find another reference. The statements sound contradictory, but I likely misunderstand.  Perhaps circular could clarify?

(BTW, thanks for moving this thread theo)
« Last Edit: January 24, 2023, 02:30:49 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: GtoH
« Reply #7 on: January 24, 2023, 02:42:46 pm »
Hi!

GSBA is only for internal use.

GSBA  is used as HSLA with gamma correction in opposite to HSLA which owns no gamma correction.

That's the whole secret.

Winni

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: GtoH
« Reply #8 on: January 25, 2023, 08:58:23 pm »
Here I am.  :)

H stands for hue where the 6 primary colors red/yellow/green/cyan/blue/violet are stretched equally. The value goes from red = 0 to red = 65536. So each of the 6 segments are of size 65536/6 = 10922.6

Note that here the primary colors are the ones of sRGB colorspace.

G is corrected in the sense that each segment does not have the same size. The exact size of the segments is described in HtoG function:
Code: Pascal  [Select][+][-]
  1. function HtoG(hue: word): word;
  2. const
  3.   segmentDest: array[0..5] of UInt32or64 =
  4.      (13653, 10923, 8192, 13653, 10923, 8192);
  5.   segmentSrc: array[0..5] of UInt32or64 =
  6.      (10923, 10922, 10923, 10923, 10922, 10923);

The segments are:
  • Red to Yellow: H in 0..10923 (size 10923), G in 0..13653 (size 13653)
  • Yellow to Green: H in 10923..21845 (size 10922), G in 13653..24576 (size 10923)
  • Green to Cyan: H in 21845..32768 (size 10923), G in 24576..32768 (size 8192)
  • Cyan to Blue: H in 32768..43691 (size 10923), G in 32768..46421 (size 13653)
  • Blue to Violet: H in 43691..54613 (size 10922), G in 46421..57344 (size 10923)
  • Violet to Red: H in 54613..65536 (size 10923), G in 57344..65536 (size 8192)

Red has the same value 0 both as H and G. Cyan has same value 32768 both as H and G. Intermediate colors do not have the same value due to the stretching.

The gradient from Red to Yellow and Cyan to Blue are stretched in G because it is easier to see intermediate colors in this segment. Also there is a need for symmetry so that the opposite color is always obtained by adding 32768.

The gradient from Green to Cyan is shrunk in G because it is less easy to differentiate the shades. Symmetry also is applied here so gradient from Violet to Red is also shrunk.

The amount to which the segments are stretched was done by me in a rather experimental way. Though you can see that it kind of match the U'V'W' diagram of the sRGB colorspace:
https://commons.wikimedia.org/wiki/File:CIE_U%27V%27W%27_Diagramme_de_chromaticit%C3%A9_001.png

The smallest segment is between yellow and green and the widest is between Red to Yellow and Cyan to blue. Arguably though the segment from Violet to Red not so small, it is shrunk in the G scale for symmetry.

As a final note, this correction of the hue scale is not quite the same as the gamma correction, which is already taken into account in the THSLAPixel colorspace. This gamma correction is rather about the intermediate colors between the primary colors, where the dark colors are overrepresented without gamma correction because 128, the middle value is in fact darker than the middle lightness. So you will not get the same RGB values using THSLAPixel instead of the standard HSL colorspace that does not have gamma correction (TStdHSLA).

So when computing a color with GSBA colorspace, first the hue is stretched to reflect the fact that some gradients of colors are easier to perceive. Then the saturated color is interpolated using gamma correction (as with THSLAPixel). Finally and this is quite important, the B value is really the perceived brightness, taking into account that each channel RGB does not have the same luminosity. It is different from HSL colorspace where the luminosity is rather a mix of the saturated color with black (luminosity below 32768) or white (luminosity over 32768).
« Last Edit: January 25, 2023, 09:01:06 pm by circular »
Conscience is the debugger of the mind

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: GtoH
« Reply #9 on: January 26, 2023, 05:45:14 pm »
Wow, that is great. Thanks so much for the detailed answer circular.

The linked diagram is helpful in understanding the rationale. Very cool!

I have played with them a bit trying to get a feel for the differences. Attached are two Mandlebrot images, one using the HSL hue, and one using the GSB hue.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: GtoH
« Reply #10 on: January 26, 2023, 05:47:11 pm »
HSL
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: GtoH
« Reply #11 on: January 26, 2023, 08:08:50 pm »
Interesting. What I notice I that the red-yellow is more represented with the G hue. And with the H hue, there is a green area that does not seem to have a gradient.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018