Commit graph

57 commits

Author SHA1 Message Date
Pekka Paalanen
6db55fe7e4 color: export weston_CIExy_to_XYZ()
This will be needed by color-lcms.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-12-02 11:46:44 +02:00
Pekka Paalanen
f69bb08738 color-lcms: constify build_3d_lut()
These arrays are read-only here.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-10-21 14:23:37 +03:00
Pekka Paalanen
33ee2c9fb4 color: make 3x1d.fill_in populate a vec3 array
This removes the API impedance mismatch between
weston_color_curve_sample() and weston_color_curve_to_3x1D_LUT() that
was temporarily introduced in the previous commit. That mismatch is now
limited to gl_color_curve_lut_3x1d().

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-10-21 14:23:37 +03:00
Derek Foreman
2c7fd792b5 frontend: Add support for forcing a color format
Allow dictating which color format we'd like to use. This introduces the
front-end side and the core parts, leaving the EDID parsing and DRM
connector property for later patches.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
2025-10-18 14:02:16 +01:00
Pekka Paalanen
6ec30279f7 color: weston_color_profile_params_to_str() const
As it should have been. Found, when I temporarily needed to print
'static const struct weston_color_profile_params'.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-10-07 17:23:35 +03:00
Pekka Paalanen
d7030571c5 frontend,color: print details of the set color profile
It is nice to see the numbers of a parametric color profile when created
from CTA or EDID or just to cross-check with weston.ini.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-09-25 18:03:31 +03:00
Pekka Paalanen
f3badf2c2d color: introduce struct weston_color_tf
At first I wanted to wrap

	float tf_params[MAX_PARAMS_TF]

into a struct, so that it would become type-safe to pass into functions,
and it could be copied with a simple assignment. Then I noticed that for
tf_params to be operable, it must always be accompanied by struct
weston_color_tf_info. Hence, struct weston_color_tf was born.

The need for #define MAX_PARAMS_TF got eliminated.

Because struct weston_color_tf is a member of struct
weston_color_profile_params, now both need to not contain implicit
padding.

This patch makes the internal enumerated TF structures follow the
current protocol requests: all color channels use the same curve.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-09-25 18:03:31 +03:00
Pekka Paalanen
7b5053f7fa color: drop weston_color_curve_from_tf_info()
This was never used, and I happened to write a slightly different
version of it in color-lcms.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-09-25 18:03:31 +03:00
Leandro Ribeiro
6fe0cfc2b8 color: introduce output color effects
Output color effects are applied to the whole output scenegraph. It
depends on color-management being disabled, as the color effects are
applied in sRGB content.

For now we added only a few accessibility options: color inversion,
deuteranopia, protanopia and tritanopia CVD correction.

Note that surfaces presented on outputs that contains a color effect
can't be used for direct scanout (i.e. bypass composition and offloading
to KMS overlay planes). The color effect is applied in our GL-renderer.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-09-18 12:32:13 -03:00
Leandro Ribeiro
fceb4151a3 color: allow creating LUT from curve even when bad precision may occur
At this point, the DRM/KMS API supports offloading post-blend color
xform only through LUT's. This is not ideal, and an API to improve that
should be proposed in the future.

But we still want to experiment with offloading pre-blend (not post)
color transformation through the colorop API, which is close to being
accepted upstream. But this requires us to offload post-blend as well.

weston_color_curve_to_3x1D_LUT() currently fails if we detect that
crafting a LUT from the color curve may result in bad precision.
Instead, let's add a boolean param to control if we forbid or not bad
precision. This should allow us to offload post-blend xform through
LUT's.

This also improves the error messages in this function.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-09-02 13:34:00 +00:00
Pekka Paalanen
6b051ce76b color: print details of the color pipeline
Give a little more insight to the values in a pipeline.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-06-17 10:40:03 +03:00
Leandro Ribeiro
8ef3423bf7 color: remove unused WESTON_COLOR_MAPPING_TYPE_3D_LUT
Since "color: do not use color steps for non-optimized pipelines",
WESTON_COLOR_MAPPING_TYPE_3D_LUT became unused. So drop it from our
code.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-05-13 17:36:52 +03:00
Leandro Ribeiro
df07af056d color: do not use color steps for non-optimized pipelines
For non-optimized pipelines, stop using the color steps (pre curve,
color mapping and post curve). Instead, make use of the
xform->to_shaper_plus_3dlut() vfunc.

In this patch we add a bool to signalize that the steps are valid (for
optimized pipelines) or not. If not (non-optimized ones), the vfunc must
be used.

This brings flexibility for the renderer/backend implementing the xform.
For now we only implement xform's in the GL-renderer, and this has no
behavior changes. It should be relevant when we implement the xform in
our DRM-backend, see commit "color: add to_shaper_plus_3dlut() vfunc to
struct weston_color_transform".

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-05-13 17:36:52 +03:00
Leandro Ribeiro
0945ac3fa8 color: add to_shaper_plus_3dlut() vfunc to struct weston_color_transform
This function allow us to get a shaper (3x1D LUT) + 3D LUT that is
equivalent to a certain xform.

With that, we allow backend/renderer that are not capable of handling
the color steps of the xform to fallback to something else.

E.g. when we introduce the code to offload color xform to KMS using the
DRM-backend, we'll depend on the driver/hardware implementing the color
steps. With this patch, DRM-backend should be able to fallback to a
shaper (3x1D LUT) + 3DLUT, color operations that should be commonly
supported by drivers/hardwares.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-05-13 17:36:52 +03:00
Pekka Paalanen
b15dcfe790 gl-renderer: add offset to the color mapping matrix
The offset will be useful for black point handling.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-05-05 11:26:24 +03:00
Pekka Paalanen
70b5ec5bfe color: use weston_mat3f for mapping step
Replace a plain array with a type-safe documented structure.
This will get more wide use later.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-14 17:11:43 +03:00
Pekka Paalanen
98ec0d9b6c color: structurize parametric curve data
Rather than using a two-dimensional array, provide names to the fields.
The fields are primarily used by their names, but we also need the data
as a flat array of floats, so use unions to achieve that: two different
views into the same data.

This makes the code more self-explanatory. In color-operations.c it
removes a handful of temporaries. Comparison in color-properties.c is
simplified. ARRAY_COPY() turns into an assignment.

MAX_PARAMS_PARAM_CURVE is eliminated. Instead of having to maintain a
copy in fragment.glsl, the definition there is automated.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-14 11:00:21 +00:00
Leandro Ribeiro
0af48f0415 color: add function to create 3x1D LUT from color curve
Some external API's (e.g. DRM/KMS) are not capable of dealing with
enumerated color curves. In such cases, we may need to create LUT's that
correspond to such curves and give them to such API's

So add function weston_color_curve_to_3x1D_LUT() to craft 3x1D LUT from
a color curve.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Leandro Ribeiro
2ac863397c color: add function to create color curve from tf
When we create a parametric color profile (we still do not fully
support, but plan to), a struct weston_color_tf_info is created.

So add a new function weston_color_curve_from_tf_info() to create a
color curve given a transfer function.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Leandro Ribeiro
209882c7d4 color: add curve type enumerated
Not all color curves comes from parameters. For instance, with the
CM&HDR protocol users can set color curves from tf_info.

So let's add a new curve type to accommodate that.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Leandro Ribeiro
0fe575b4a9 color: move LINPOW/POWLIN to new enum weston_color_curve_parametric_type
This just makes the code more readable and should help us to avoid
mistakes in the future. No behavior changes.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Leandro Ribeiro
037f2dbff1 color: define max number of params for parametric curves and tf's
Up to now we were using 10 as the max number of params for color curves
and transfer functions. But this came from LittleCMS, whose parametric
curves may contain up to 10 params.

But out color curves and tf's are not tied to LittleCMS, so let's define
constants to help avoid confusion.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-04-10 12:43:00 +00:00
Pekka Paalanen
98becedfcd libweston: publish eotf and colorimetry mode to string
Frontend wants to print these sometimes.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2025-04-03 17:49:20 +03:00
Robert Mader
9124a98aec color: update color-management protocol to wp-v1
For a list of changes that got squashed into this commit see
https://gitlab.freedesktop.org/rmader/weston/-/commits/color-management-protocol-wp-v1-bkp

Co-authored-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
Signed-off-by: Robert Mader <robert.mader@collabora.com>
Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-02-26 10:09:43 -03:00
Leandro Ribeiro
70ad4cd901 color-lcms: print params from parametric color profiles
Start to print the parameters from struct cmlcms_color_profile::params
in cmlcms_color_profile_print(). This will be useful for the next
commit, in which we add tests that craft parametric color profiles.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-01-20 09:30:46 +00:00
Leandro Ribeiro
5d7e2710a2 color: cosmetic changes to the CM&HDR protocol implementation
No behavior changes. Adjust a few comments, error messages, variable
names, etc.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-01-20 09:30:46 +00:00
Leandro Ribeiro
0ed8294881 color: add weston_color_profile_param_builder_set_primary_luminance()
This follows a recent change in the CM&HDR protocol (more specifically,
v4 of the experimental version). Now users of the API can set luminance
parameters for the primary color volume.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-01-20 09:30:46 +00:00
Leandro Ribeiro
9ae0a7ec05 color: accept max_fall and max_cll even for tf different from PQ
The CM&HDR protocol extension spec relaxed the requirements for the
max_fall and max_cll setters. Now we accept such values even when the
transfer function is not PQ.

This also fixes an issue in which we'd not accept target_luminance
for transfer function different from PQ, which was not on the spec.

INCONSISTENT_SET is not being used in any other errors, so remove that
from enum weston_color_profile_param_builder_error.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-01-20 09:30:46 +00:00
Leandro Ribeiro
1082ef328a color: rename luminance to target luminance
In the experimental color-management protocol v3
(xx-color-management-v3), we had only the luminance parameters that were
defining the luminance range targeted by the image description. But in
v4 a way to specify luminance parameters for the primary color volume
has been added.

In order to avoid confusion, rename existent luminance variables to
target luminance.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2025-01-20 09:30:46 +00:00
Leandro Ribeiro
93d086f068 color: add get_color_profile_from_params() to color managers
Add function to color managers to create color profiles from parameters.
This will be used by the parametric color profile builder that we'll add
in the next commit.

WARNING: we still do not fully support creating color profiles from
parameters. This just creates a boilerplate color profile that we're
planning to extend later.

Co-authored-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2024-06-17 11:50:40 -03:00
Leandro Ribeiro
89a57c7b10 color: keep track of supported primaries and transfer functions
In the next commits we'll start support clients that want to create
image descriptions through params using the CM&HDR protocol extension.

In order to do that, we'll have to expose the primaries and transfer
functions that the color manager supports. So keep track of that.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2024-06-17 11:50:40 -03:00
Pekka Paalanen
45ae99aff7 backend-drm: get KMS colorimetry modes
Based on KMS "Colorspace" connector property, populate the mask of
supported colorimetry modes on a head.

EDID should be checked too, but it is currently ignored.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2024-05-06 10:39:42 +00:00
Pekka Paalanen
53493aaddc libweston: add colorimetry_mode API
This API is mostly for use by the DRM-backend. Colorimetry mode is is
the KMS connector property "Colorspace" which defines the video signal
encoding colorimetry. A video sink indicates the supported modes in EDID
or DisplayID.

This patch adds the libweston API that allows backends to indicate the
supported modes for the frontends, and frontends to set the mode to be
used by backends. Colorimetry mode does not directly affect color
management inside Weston, it is only metadata for the video sink. It is
the frontend's responsibility to set up an output color profile that
agrees with the colorimetry mode. (That API has not been implemented
yet.) eotf_mode will be the same.

There is only one reason to make this a libweston core API instead of
a backend-drm API: when wayland-backend gains color-management protocol
support, meaning it can forward WCG and HDR content correctly to a
host compositor, the supported colorimetry modes can be determined from
the host compositor's supported color-management features, allowing the
guest Weston to pick some other output image description than the host
compositor's preferred image description. This likely allows only a few
other choices from standard colorspaces, so it's possible this isn't
sufficient for that use case.

Either way, it is easy to just copy the eotf_mode API design, and since
colorimetry_mode and eotf_mode go together, let both have the same API
design. It is possible to convert this to backend-drm API later.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2024-05-06 10:39:42 +00:00
Pekka Paalanen
161cc8643c libweston: move weston_output_color_outcome to private
Turns out these structures do not need to be in the public header, so
move them into a private header.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2024-05-06 10:39:42 +00:00
Leandro Ribeiro
9002667aa0 color: add support to parametric curves in weston_color_curve
Until now, all the curves would be represented with 3x1D LUT's. Now we
support LINPOW and POWLIN curves (arbitrary names that we've picked).
We can use these curves to represent LittleCMS curves type 1, 4 and
their inverses -1, -4. The reason why we want that is because we gain
precision using the parametric curves (compared to the LUT's);

Surprisingly we had to increase the tolerance of the sRGB->adobeRGB MAT
test. Our analysis is that the inverse EOTF power-law curve with
exponent 1.0 / 2.2 amplifies errors more than the LUT, specially for
input (optical) values closer to zero.

That makes sense, because this curve is more sensible to input values
closer to zero (i.e. little input variation results in lots of output
variation). And this model makes sense, as humans are more capable of
perceiving changes of light intensity in the dark.

But the downside of all that is that for input values closer to zero, a
little bit of noise increases significantly the error.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2024-03-26 11:23:26 +00:00
Pekka Paalanen
aef9404b1d color: generate id for color transformations
Just like with color profiles, generate an ID for color transformations
as well. This is not needed by protocol or anything, it is just for
debugging purposes. A small ID is easier for humans than a long pointer
value.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2024-03-20 12:58:12 +00:00
Pekka Paalanen
d9a7b3795a libweston: move color-management protocol init call to core
This reverts commit 188a3ebd5e.

Call weston_compositor_enable_color_management_protocol() after
compositor->color_manager has been set, and so allows to check if the
color manager supports the features mandatory in protocol. The check is
added in the next patch.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2024-02-23 16:46:39 +02:00
Pekka Paalanen
4f796a52e1 color: rename get_stock_sRGB_color_profile to ref_stock_sRGB_color_profile
This makes it more explicit that this indeed is increasing the reference
count, rather than just returning a pointer.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2024-02-23 16:46:39 +02:00
Leandro Ribeiro
188a3ebd5e libweston: expose color management support
In this patch we enable the color-management protocol support, as long
as the color-manager plugin in use supports it.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2024-02-14 11:15:35 -03:00
Leandro Ribeiro
5706d7e5d2 color: add support to the color-management protocol
In this MR we add support to the majority of the interfaces from the
color-management protocol.

That means that we are able to advertise output's images descriptions to
clients, preferred surface images descriptions, and so on. We also
support clients that wants to create ICC-based images descriptions and
set such descriptions for surfaces.

We still don't support the interface to allow clients to create
image descriptions from parameters, but that should be addressed
in the near future.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2024-02-14 11:15:35 -03:00
Leandro Ribeiro
a84806a88e libweston: add unique id generator
This is preparation for the CM&HDR protocol implementation. It requires
us to give a unique id to each color-profile, so let's do that.

In this commit we introduce a generic id generator to libweston, and
its first user: the color-profile.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2024-02-13 14:08:38 -03:00
Leandro Ribeiro
977c41a65c color: add get_stock_sRGB_color_profile() to color manager
In the next commit we'll stop using NULL as the stock sRGB color
profile, so add a function to the color manager to allow libweston core
to have access to the stock sRGB profile.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2023-10-30 11:47:35 +00:00
Leandro Ribeiro
d827bdd5d4 color-lcms: add debug scope for color tranformations
It prints the existent color transformations for new subscribers. Also
prints any creation/destruction of color transformations.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
2023-04-12 10:03:32 +00:00
Vitaly Prosyak
cd888bde6f gl-renderer: add matrix
Add matrix in color.h
Matrix is used as an optimized method for
color mapping vs 3DLUT.
Nothing sets color mapping to matrix yet.

Signed-off-by: Vitaly Prosyak <vitaly.prosyak@amd.com>
2022-09-28 10:28:28 +00:00
Vitaly Prosyak
96f0fc3974 gl-renderer: add post-curve set to identity
Add post-curve support in color.h.
Pre-curve and post-curve describe color pipeline components
in a single GL shader invocation.The GL shader is supposed
to match struct weston_color_transform exactly.
We have the following color pipeline:
shader A -> blending -> shader B -> KMS. Both A and B shaders
using the same source file :fragment.glsl.
Each shader has pre and post curve.

The typical color pipeline with 3DLUT:
Shader A: pre-curve identity->3DLUT->blending->post-curve identity
Shader B: pre-curve->3DLUT identity->post-curve identity->KMS

The typical color pipeline with matrix (in next commits):
Shader A: pre-curve->matrix->blending->post-curve identity
Shader B: pre-curve->matrix identity->post-curve identity->KMS
The pre-curve plays role of EOTF (shader A) or INV_EOTF
(shader B) becouse we are stiching the shaders.

We assume that someone in the future may use both pre-curve
and post-curve, for example, when it is not possible to combine
these curves into 3DLUT and we will do mapping elements based on
their location in ICC profile.

Signed-off-by: Vitaly Prosyak <vitaly.prosyak@amd.com>
2022-09-28 10:28:28 +00:00
Pekka Paalanen
dfba19abde color: simplify color manager API with weston_output_color_outcome
I am going to need to add yet another output property to be set by a
color manager: HDR Static Metadata Type 1. With the old color manager
API design, I would have needed to add the fourth function pointer to be
called always in the same group as the previous three. This seemed more
convoluted than it needs to be.

Therefore collapse the three existing function pointers in the API into
just one that is resposible for setting up all three things.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-05-06 09:33:35 +00:00
Pekka Paalanen
6c0524fd80 libweston: add struct weston_output_color_outcome
This new struct collects all the things that a color manager needs to
set up when any colorimetry aspect of an output changes. The intention
is to make the color manager API less verbose.

In this first step, the new struct is added and replaces the fields in
weston_output.

The intention is for the following color manager API changes to
dynamically allocate this structure. Unfortunately, until that actually
happens, we need a temporary way to allocate it. That is
weston_output::colorout_, which will be removed in the next patch. This
keeps the patches more palatable for review at the cost of some
back-and-forth in code changes.

This is a pure refactoring, no functional changes.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-05-06 09:33:35 +00:00
Pekka Paalanen
1d17e4991f backend-drm: check for HDR_OUTPUT_METADATA
Check whether HDR_OUTPUT_METADATA property exists on a KMS connector. If
yes, pretend that EDID claims support for all EOTF modes and update the
head supported EOTFs mask accordingly. If not, then only SDR is
possible.

Parsing EDID to take monitor capabilities into account is left for
later.

HDR mode cannot be set without HDR_OUTPUT_METADATA.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-05-02 12:19:24 +00:00
Pekka Paalanen
5f9b68d68f libweston: introduce weston_eotf_mode
This is the switch to turn HDR mode on.

The values in the enumeration come straight from CTA-861-G standard.
Monitors advertise support for some of the HDR modes in their EDID, and
I am not aware of any other way to detect if a HDR mode actually works
or not. Different monitors may support different and multiple modes.
Different modes may look different. Therefore the high-level choice of
how to drive a HDR video sink is left for the Weston frontend to decide.

All the details like what HDR metadata to use are left for the color
manager.

This commit adds the libweston API for backends to advertise support and
for frontends to choose a mode. Backend and frontend implementations
follow in other commits.

The frontend API does not limit the EOTF mode to the supported ones to
allow experimentation and overriding EDID.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2022-05-02 12:19:24 +00:00
Vitaly Prosyak
2e2ad02d5c libweston: add definition of color mapping function
Introduce 3D LUT definition as part of Weston
color transform struct. A 3D LUT is a LUT containing
entries for each possible RGB triplets.
Co-authored-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Signed-off-by: Vitaly Prosyak <vitaly.prosyak@amd.com>
2022-02-09 20:42:50 -05:00