Ivan Stimac
Ivan Stimac

Reputation: 59

translating pixel unpacking to halide algorithm

I have a buffer filled with pixel data in pattern UY1VY2... and I want to unpack that to another buffer in pattern Y1UVY2UV... So basically if I had a vector of that data I want following operation

for(x=0; x<sizeof(in_buffer); x+=4)
    out_buffer.push_back(in_buffer[x+1]+ in_buffer[x+0] + in_buffer [x+2: x+4]) ---> [Y1,U,V,Y2,U,V]

Can this kind of operation be implemented with halide? Thanks!

Upvotes: 0

Views: 125

Answers (1)

Alex Reinking
Alex Reinking

Reputation: 20016

Sure, something like this ought to work:

out_buffer(c, x) = in_buffer(mux(c, {1, 0, c}), x);

Then in the schedule, you'd use set_bounds and unroll to make sure the c loop didn't actually have to check the value of c. See this tutorial for more details: https://halide-lang.org/tutorials/tutorial_lesson_16_rgb_generate.html

Upvotes: 2

Related Questions