porescene.color.conversion module

Color Space Conversion

Some functions to convert color tuples between following color spaces:

  • HEX

  • Standard RGB

  • Normalized standard RGB

  • Normalized linear RGB

porescene.color.conversion.hex2rgb(h)[source]

Convert HEX into sRGB.

Returns a three-element or four-element tuple depending on whether or not a alpha value is given.

Parameters:

h (str) –

The color value in HEX notation. The function supports following forms of HEX string always with and without a prefixed hash (#):

  • #RGB

  • #RGBA

  • #RRGGBB

  • #RRGGBBAA

Return type:

tuple[int, int, int] | tuple[int, int, int, float]

porescene.color.conversion.lnrgb2nrgb(r, g, b, a=None)[source]
Overloads:
  • r (float), g (float), b (float), a (None) → ColorTupleFloat3

  • r (float), g (float), b (float), a (float) → ColorTupleFloat4

Converts normalized linear RGB into sRGB in range [0, 1].

porescene.color.conversion.nrgb2lnrgb(r, g, b, a=None)[source]
Overloads:
  • r (float), g (float), b (float), a (None) → ColorTupleFloat3

  • r (float), g (float), b (float), a (float) → ColorTupleFloat4

Converts normalized sRGB into normalized linear RGB.

porescene.color.conversion.nrgb2rgb(r, g, b, a=None)[source]
Overloads:
  • r (float), g (float), b (float), a (None) → ColorTupleInt3

  • r (float), g (float), b (float), a (float) → ColorTupleInt3Float1

Converts sRGB from range [0, 1] into range [0, 255].

porescene.color.conversion.rgb2hex(r, g, b, a=None)[source]

Convert sRGB channels into a hex color string.

Returns a #RRGGBB string, or #RRGGBBAA when a [0-1] is given.

Parameters:
  • r (int) – Red color channel [0 - 255]

  • g (int) – Green color channel [0 - 255]

  • b (int) – Blue color channel [0 - 255]

  • a (float | None) – Alpha color channel [0 - 1], by default None

Returns:

Hex color string

Return type:

str

porescene.color.conversion.rgb2nrgb(r, g, b, a=None)[source]
Overloads:
  • r (int), g (int), b (int), a (None) → ColorTupleFloat3

  • r (int), g (int), b (int), a (float) → ColorTupleFloat4

Converts sRGB from range [0, 255] into range [0, 1].