Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass an Iterator as source (for BGR->RGB for example) #26

Open
Zerowalker opened this issue Jan 11, 2023 · 1 comment
Open

Pass an Iterator as source (for BGR->RGB for example) #26

Zerowalker opened this issue Jan 11, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@Zerowalker
Copy link

Is it possible to add the ability to pass an iterator into the encoder (without having an effect on performance)?
I tried looking through the code but it was a bit too complex for me.

Why I ask is that in case you have BGR data, you currently have to convert it beforehand.
Which means going through everything just to convert it,
it's very fast though, but I would imagine it being faster if it could be done when the data is actually being encoded.

Here's an example of BGR to RGB:

pub fn bgr_to_rgb(b: &mut [u8]) {
    // swap R<->B to convert BGR->RGB
    b.chunks_exact_mut(3).for_each(|l| l.swap(0, 2));
}

Now if we could pass an iterator the swap could be done on-the-fly which might be more cache friendly as well.

Thoughts on this?

@bvibber
Copy link
Owner

bvibber commented Jan 11, 2023

Hmmm, seems plausible in principle! Doing the swizzle while data's hot is good for cache, and should be vectorization-friendly.

Main holdup off the top of my head -- we need random access to run filters in parallel, so the API needs to provide for creating a separate iterator for each chunk.

@bvibber bvibber added the enhancement New feature or request label Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants