Skip to content

Efficient pixel conversions #6737

Answered by abadams
dCubelic asked this question in Q&A
Discussion options

You must be logged in to vote

I think you want something like this (this is for RGB to BGR, but the approach generalizes to other conversions):


    swapped(x, y, c) = mux(c, {input(x, y, 2), input(x, y, 1), input(x, y, 0)});

    swapped.vectorize(x, 16, TailStrategy::GuardWithIf)
        .reorder(c, x, y)
        .unroll(c)
        .parallel(y, 16, TailStrategy::GuardWithIf);

    input.dim(0).set_stride(3);
    input.dim(2).set_bounds(0, 3).set_stride(1);
    swapped.output_buffer().dim(0).set_stride(3);
    swapped.output_buffer().dim(2).set_bounds(0, 3).set_stride(1);

Notes:

  • Each f(...) = ... implies a separate loop nest, with a separate schedule. You've only provided a schedule for the first loop nest, so for …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by dCubelic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants