lcms2.convert

convert(data: Any, src: Any, dst: Any, *, out: ndarray | None = None, out_dtype: DTypeLike = None, **options: Any) → ndarray[source]

Convert colours from src to dst.

src and dst may be Profile objects, built-in profile names, paths, or colour space objects (anything with to_xyz/from_xyz working in XYZ D50, Y = 1). Mixed conversions go through XYZ D50. Transforms are cached (LRU) per profile pair and options.

Parameters:
  • data (array-like or str) – (..., channels) pixels, or CSS colours ("#ff8000", "rebeccapurple", "rgb(255 128 0)", or a list of them), which become sRGB floats in 0..1.

  • src (Profile, str, path or colour space) – Source and destination.

  • dst (Profile, str, path or colour space) – Source and destination.

  • out – See Transform.apply().

  • out_dtype – See Transform.apply().

  • **options – Transform keywords: intent, bpc, proof, gamut_check, optimize, precision, flags.

Returns:

numpy.ndarray – Between two profiles the dtype follows the input (see Transform.apply()); when a colour space object is involved the result is float64, since analytic spaces work in floats. Pass out_dtype to choose.

Examples

>>> import lcms2
>>> lcms2.convert([255, 255, 255], "sRGB", "Lab").round(2) + 0.0
array([100.,   0.,   0.])
>>> lcms2.convert([[1.0, 0.0, 0.0]], "sRGB", "Display P3").round(3)
array([[0.917, 0.2  , 0.139]])
>>> lcms2.convert("#ffffff", "sRGB", "Lab").round(2) + 0.0
array([100.,   0.,   0.])