Search code examples
c++algorithmimage-processingyuv

How to rotate yuv420 data?


I need to know how to rotate an image, which is in yuv420p format by 90 degrees. The option of converting this to rgb, rotating and again reconverting to yuv is not feasible. Even an algorithm would help.

Regards, Anirudh.


Solution

  • I suppose it is not planar YUV, if it is it already it's quite easy (skip first and last steps). You meant to have YUV 4:2:0 planar, but then I do not understand why you have difficulties.

    1. convert it to a planar first: allocate space for planes and put bytes at right places according to the packed YUV format you have.
    2. rotate the Y, U, V planes separately. The "color" (U, V) information for each block then shall be kept the same.
    3. recombine the planes to reobtain the right packed YUV you had at the beginning

    This always works fine if your image dimensions are multiple of 4. If not, then take care...