# Fix incorrect ANSI color contrast adjustment on some background colors \(\#38155\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/5b1c87b6a6006b69779f8ea048d0f691bc19e085)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 5b1c87b6a6006b69779f8ea048d0f691bc19e085

Requested commit: 5b1c87b6a6006b69779f8ea048d0f691bc19e085

Commit: 5b1c87b6a6006b69779f8ea048d0f691bc19e085

Tree: c5eacc2b2709c1dcd80511bd634eda362d8a0061

Author: Tim Vermeulen

Committer: GitHub

## Message

```
Fix incorrect ANSI color contrast adjustment on some background colors (#38155)

The `Hsla` -> `Rgba` conversion sometimes results in negative (but very
close to 0) color components due to floating point imprecision, causing
the `.powf(constants.main_trc)` computations in the `srgb_to_y` function
to evaluate to `NaN`. This propagates to `apca_contrast` which then
makes `ensure_minimum_contrast` unconditionally return `black` for
certain background colors. This PR addresses this by clamping the rgba
components in `impl From<Hsla> for Rgba` to 0-1.

Before/after:
<img width="1044" height="48" alt="before"
src="https://github.com/user-attachments/assets/771f809f-3959-43e9-8ed0-152ff284cef8"
/>
<img width="1044" height="49" alt="after"
src="https://github.com/user-attachments/assets/5fd6ae25-1ef0-4334-90d1-7fc5acf48958"
/>

Release Notes:

- Fixed an issue where ANSI colors were incorrectly adjusted to improve
contrast on some background colors
```

## Parents

- [0fef17baa23130557813bd688ab0d3064bf4681e](https://git.cafe/gitcafe/zed/commit/0fef17baa23130557813bd688ab0d3064bf4681e?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/5b1c87b6a6006b69779f8ea048d0f691bc19e085?format=markdown)
