Ogeon / palette

A Rust library for linear color calculations and conversion
Apache License 2.0
751 stars 60 forks source link

Pixel to Struct of Arrays (and back again!) #305

Closed Ogeon closed 1 year ago

Ogeon commented 1 year ago

Description

As discussed in https://github.com/Ogeon/palette/discussions/303, it would be useful to have an interface for converting an array/Vec of colors to and from Struct of Arrays format. The first step should be:

In addition to that, we may want to add chunks and windows iterators.

The reference components will likely be necessary, due to the split into separate arrays, unless there's a smarter solution. They don't have to enable much more than reading and writing, though. It's also what would make it hard to implement the Index and IndexMut traits, if possible at all.

Motivation

The discussions in https://github.com/Ogeon/palette/discussions/303 covers it pretty well. One of the main reasons for a built-in interface is that it gives a way to correctly preserve the color type information across conversions. It also lowers the bar for working with SoA data.

okaneco commented 1 year ago

Good summary :slightly_smiling_face:

Another feature that I think would be useful is some way to reuse the existing allocations. It might be an extend-like interface so that users could call clear on the existing data and re-initialize with an iterator.

Ogeon commented 1 year ago

Ah, yes, that should also be there! I'll edit the description to include them...