#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
typedef unsigned char u8;
typedef unsigned short u16;
#define ROW 4
#define COL 3
u16 data[ROW][COL] = {
1,2,3,
4,5,6,
7,8,9,
10,11,12
};
void rotate_180_degree(u16 weight,u16 height,u16 *pframe_buffer)
{
u16 temp;
u16 i,j;
u16 times = height/2;
u16 *pfront;
u16 *back;
for(i=0;i<times;i++)
{
pfront = pframe_buffer+i*weight;
back = pframe_buffer + (height-1-i)*weight;
for(j=0;j<weight;j++)
{
temp = pfront[j];
pfront[j] = back[weight-1-j];
back[weight-1-j] = temp;
}
}
if(height&0x0001)
{
pfront = pframe_buffer+times*weight;
for(j=0;j<weight/2;j++)
{
temp = pfront[j];
pfront[j] = pfront[weight-1-j];
pfront[weight-1-j] = temp;
}
}
}
void printf_data()
{
u16 i,j;
for(i=0;i<ROW;i++)
{
for(j=0;j<COL;j++)
{
printf("%02d ",data[i][j]);
}
printf("\n");
}
}
int main(int argc, char *argv[]) {
printf_data();
rotate_180_degree(COL,ROW,&data[0][0]);
printf("\n\n");
printf_data();
return 0;
}