views:

55

answers:

2

Hi Everyone,

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.

+1  A: 

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...

jdehaan
So, if w * h (assuming it's a multiple of 4) is the resolution of the image, I could treat first w*h elements of array as Y plane and the next w*h/2 as U and the rest as V? And to achieve 90 degrees rotation, I could just transpose these values separately? That would make the algorithm very simple indeed!
aniait
This is correct but with 4:2:0 subsampling U plane size is w*h/4 and not w*h/2. The links in the answer should provide you also more details if the format is not quite matching, there are so many from these YUV formats!
jdehaan
A: 

I think YUV420p is indeed planar.

Try and take a look at AviSynth's source code. The turn (rotate) functions are in turn.cpp and turnfunc.cpp

http://www.avisynth.org/

quantumSoup
Thanks, will try the same.
aniait