Skip to content

Conversation

@expenses
Copy link
Contributor

@expenses expenses commented Oct 22, 2025

Currently, our Color type is quantized to 8 bits for no good reason. I thought I'd change it to use floating point values between 0.0 and 1.0,as well as introduce explicitly quantized color types (one encoded using the sRGB transfer function and another quantized linearly). This will require a lot of code changes elsewhere and will probably not get merged any time soon.

Edit: I've changed this to just include the first Color changes

@ogoffart
Copy link
Member

I know this is a DRAFT, but be careful not to change the public API.

@expenses
Copy link
Contributor Author

I know this is a DRAFT, but be careful not to change the public API.

Fair enough, I'll restore the old structs/functions and mark them as deprecated.

@expenses expenses force-pushed the sane-color-handling branch from ca01bc5 to e442f12 Compare November 10, 2025 15:41
@expenses expenses changed the title DRAFT: Make internal::core::graphics::color types more sensible Change color type to use f32 values internally Nov 10, 2025
@expenses
Copy link
Contributor Author

Okay, I've decided to approach this slightly differently. I've changed the color type to use f32 values internally which makes some things a lot more sensible, without doing any changes elsewhere.

@expenses expenses marked this pull request as ready for review November 10, 2025 15:44
@tronical
Copy link
Member

I think that's a very good direction. I think on desktop and MPU this makes sense. But we may need to retain the u8/u8/u8 code path for MCUs, as some don't have an FPU (we emulate) and because it increase the size of the color type by a factor of four. I'm sure that we can find a compromise / solution there.

Tangential: In the spirit of the unstable-XX features and the color crate being under the linebender org, we could also offer conversions from its color types (with the caveats of loss that come with it).

@expenses
Copy link
Contributor Author

I think that's a very good direction. I think on desktop and MPU this makes sense. But we may need to retain the u8/u8/u8 code path for MCUs, as some don't have an FPU (we emulate) and because it increase the size of the color type by a factor of four. I'm sure that we can find a compromise / solution there.

What's the best way to determine if int values should be used? cfg(slint_int_coord) maybe?

@tronical
Copy link
Member

That's a good question. Perhaps the libm feature? Quoting from the docs:

libm — This feature enables floating point arithmetic emulation using the libm crate. Use this
in MCU environments where the processor does not support floating point arithmetic.

(we could rename it if necessary)

Let's see what Olivier says.

@expenses expenses force-pushed the sane-color-handling branch from 280e8dd to 23673c4 Compare November 11, 2025 08:49
@expenses
Copy link
Contributor Author

20251111_12h09m32s_grim something seems to be going wrong with the C bindgen

// therefore it is ok to reinterpret_cast
("MenuEntryModel".into(), "std::shared_ptr<slint::Model<MenuEntry>>".into()),
("Coord".into(), "float".into()),
("Channel".into(), "uint8_t".into()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, otherwise it tries to use an undefined Channel type

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I guess the differences in rendering come from changing the mix/transparentize functions now operating always on f32?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

@expenses expenses merged commit e7ec065 into slint-ui:master Nov 12, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants