Ogeon

joined 1 year ago
[โ€“] Ogeon@programming.dev 1 points 3 months ago

Right, there may be too many unknowns involved. ๐Ÿค”

[โ€“] Ogeon@programming.dev 18 points 3 months ago (4 children)

Option<T> has a From<T> implementation that lets you write Option::from($file_path).map(|path| path.to_string()) to accept both cases in the same expression.

https://doc.rust-lang.org/std/option/enum.Option.html#impl-From%3CT%3E-for-Option%3CT%3E

[โ€“] Ogeon@programming.dev 1 points 4 months ago* (last edited 4 months ago)

The rabbit hole goes deep if you really feel like going spelunking. A basic understanding of RGB, HSV and HSL takes you very far and lets you do a lot of things already. It's good enough as long as it looks good, after all. ๐Ÿ™‚

You really don't need to read all of it to get started!

[โ€“] Ogeon@programming.dev 2 points 4 months ago (2 children)

This depends a bit on what you are looking for. The library documentation is supposed to guide you to a practical starting point, but it's still quite light on the theoretical parts. I haven't really collected any specific beginner material, so this may still be a bit technical. There's a ton of info about the basics, with varying levels of detail.

Assuming you are starting from almost nothing, I would recommend getting familiar with what RGB is and how its components relate. This is the format most images are encoded in and most devices and software use. The Wikipedia page is quite thorough, so no need to read all of it: https://en.wikipedia.org/wiki/RGB_color_model

Next, it's good to know there are other models. HSV and HSL tend to be used in color pickers (a bit more intuitive than RGB), so you have probably interacted with them at some point. Again, the Wikipedia page may be a good source: https://en.wikipedia.org/wiki/HSL_and_HSV

That's often good enough for producing colors and reading or writing images. If you want to go more into editing, it's good to know that you will need to massage the values you get from the images. They usually don't represent the actual light intensities, so they have to be made linear. Palette offers functions for it and represents it in the type system. This video is a slightly simplified explanation of the problem (when it mentions the square root, it's an approximation): https://youtu.be/LKnqECcg6Gw

At some point, you will realize that neither linear nor non-linear RGB is the universal answer to good looking colors. They are used in different situations. There is another category of color models/spaces that are called "perceptually uniform", meaning that they try to simulate or predict how we actually experience the colors and relate it to the numbers in the computer. This page shows the problem and introduces one of those models: https://bottosson.github.io/posts/colorwrong

I can probably provide more sources if you have any specific things you want to read about, but this is a start.

 

The maintainer here! Feel free to ask questions. I know especially CAM16 can feel a bit abstract if you aren't in the loop, but I will try to answer what I can. I have tried my best to explain the concepts in the docs, but it can always be better.

[โ€“] Ogeon@programming.dev 16 points 5 months ago

A "mantra" more programmers should have is to fix the cause of the issue, and not just the symptoms. You have to understand what the problem is to be able to fix it.

[โ€“] Ogeon@programming.dev 9 points 6 months ago (1 children)

Simple features are often complex to make, and complex features are often way too simple to make.

 

Just to reiterate what the linked blog post mentions; this isn't a bug with Iced, specifically, but seemed to have been brought into light by having Iced 0.12.0 among the dependencies. Many variants of this bug has been reported to the Rust compiler repository and some seem to be fixed by the next trait resolver.

[โ€“] Ogeon@programming.dev 1 points 7 months ago

That's nice to hear! And the Ok* color spaces are indeed quite neat

[โ€“] Ogeon@programming.dev 6 points 7 months ago (1 children)

ICC profiles are definitely part of the field, but that's sort of a topic of its own. At least in terms of scope. The color space rabbit hole is so deep that I never got as far as including them. There are other crates that go into those parts and it should be easy to bridge between them and Palette.

I would say Palette is more for the "business logic" of working with colors, so converting, manipulating and analyzing. The difference from ICC profiles when converting with Palette is that you need to know more about the source and destination color spaces during compile time. ICC profiles use more runtime information.

Palette could be used for applications like image manipulation programs, 3D rendering, generative art, UI color theme generation, computer vision, and a lot more. A lot of people also use it for smaller tasks like converting HSL input to RGB output or making gradients.

 

Hey, folks! Here's another update for Palette, the color crate I'm maintaining. Feel free to let me know if you have any questions or feedback! I will do my best to answer.

[โ€“] Ogeon@programming.dev 46 points 10 months ago (1 children)

It's useful for keeping track of your mental gymnastics.

[โ€“] Ogeon@programming.dev 2 points 11 months ago* (last edited 11 months ago) (1 children)

It may be possible to use the Any trait to "launder" the value by first casting it to &amp;Any and then downcasting it to the generic type.

let any_value = match tmp_value {
    serde_json::Value::Number(x) => x as &amp;Any,
    // ...
};

let maybe_value = any_value.downcast_ref::&lt; T >();

I haven't tested it, so I may have missed something.

Edit: to be clear, this will not actually let you return multiple types, but let the caller decide which type to expect. I assumed this was your goal.

[โ€“] Ogeon@programming.dev 11 points 1 year ago* (last edited 1 year ago)

I'm of course only one single anecdotal sample, but the release cadence has probably been the least of my problems. My experience is that it's fine to not update for quite some time. I have a crate with 1.60 (released about one and a half years ago) as MSRV, which means I run unit tests with that version, as well as stable, beta and nightly. The only pressure to upgrade is that some dependencies are starting to move on. Not that the newer compilers reject my code, not even anything deprecated.

Also, small, frequent releases usually takes away a lot of the drama around upgrading, in my experience. Not the opposite. A handful of changes are easier to deal with than a whole boatload. Both for the one releasing and for the users.

 

I suppose I should start posting updates here too. ๐Ÿ˜

view more: next โ€บ