# Rotating a buffer with ippiRotate_

## Rotating a buffer with ippiRotate_

I want to flip the following buffer upside down. See example source and destination.

source (src):

01 02 03
04 05 06
07 08 09

destination (dst - correct):

07 08 09
04 05 06
01 02 03

The following sample does not rotate the buffer correctly. What am I doing wrong?

unsigned char src [9] = {1,2,3,4,5,6,7,8,9};
IppiSize size = {3,3};
IppiRect roi = {0,0,3,3};
unsigned char dst [9];
int step = 3;

IppStatus status = ippiRotate_8u_C1R(src, size, step, roi, dst, step, roi, 90, 0, 0, IPPI_INTER_LINEAR);

destination (dst - wrong):

01 04 07
00 00 00
00 58 C3

4 posts / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.

Hi,

What you want to do is not a rotation. As you said, it's a flip. For this, use the ippiMirror function.

Best Regards,
Matthieu

Quoting - matthieu.darbois
Hi,

What you want to do is not a rotation. As you said, it's a flip. For this, use the ippiMirror function.

Best Regards,

Matthieu,
For this partically case ( angle == 90) - yes, the Mirror function is the best choise,
but for arbitrary cases - first of all call ippiAddRotateShift(,,,,,) for computing shift values of an images... .
The function helps compute shift values xShift, yShift that should be passed to ippiRotate function for the rotation around (xCenter, yCenter) to take place.
For your cases, it seems to me that shiftY == 2 ...

Instead of flipping your buffer, you should just process it backwards (in-place) for better performance.

Suppose you have 500x400 with step/pitch of 512, you should call IPP functions with the following :

pSrc = pBuffer + (height - 1) * step = pBuffer + 399 * 512;
srcRoi = { 500, 400 };
srcStep = -step = -512;

IPP will view the last row as the first, and jump by -512 pixels after every row.