-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatrixTranspose_Test.c
123 lines (105 loc) · 2.59 KB
/
MatrixTranspose_Test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#define BUFF_SIZE (1024)
uint8_t SIDE_LEN = 0;
uint8_t DataList[BUFF_SIZE];
uint8_t TransList[BUFF_SIZE];
typedef struct
{
void (*BackWard);
void (*Foward);
void (*_180);
void (*xMirror);
void (*yMirror);
}Matrix_Method_t;
//----------------------------------------------------------------------------//
//逆时针
void MatrixTranspose_BackWard(uint8_t *src, uint8_t *dst)
{
uint8_t row,column;
for(row = 0; row < SIDE_LEN; row ++)
for(column = 0; column < SIDE_LEN; column ++){
*(dst+column+row*SIDE_LEN) = *(src+(SIDE_LEN-row-1)+SIDE_LEN*column);
}
}
//顺时针
void MatrixTranspose_Foward(uint8_t *src, uint8_t *dst)
{
uint8_t row,column;
for(row = 0; row < SIDE_LEN; row ++)
for(column = 0; column < SIDE_LEN; column ++){
*(dst+column+row*SIDE_LEN) = *(src+row+(SIDE_LEN-column-1)*SIDE_LEN);
}
}
//180度
void MatrixTranspose_180(uint8_t *src, uint8_t *dst)
{
uint8_t row,column;
for(row = 0; row < SIDE_LEN; row ++)
for(column = 0; column < SIDE_LEN; column ++){
*(dst+column+row*SIDE_LEN) = *(src+SIDE_LEN*SIDE_LEN-1-(column+row*SIDE_LEN));
}
}
//X轴镜像
void MatrixTranspose_xMirror(uint8_t *src, uint8_t *dst)
{
uint8_t row,column;
for(row = 0; row < SIDE_LEN; row ++)
for(column = 0; column < SIDE_LEN; column ++){
*(dst+column+row*SIDE_LEN) = *(src+(SIDE_LEN-row-1)*SIDE_LEN+column);
}
}
//y轴镜像
void MatrixTranspose_yMirror(uint8_t *src, uint8_t *dst)
{
uint8_t row,column;
for(row = 0; row < SIDE_LEN; row ++)
for(column = 0; column < SIDE_LEN; column ++){
*(dst+column+row*SIDE_LEN) = *(src+(SIDE_LEN-column-1)+SIDE_LEN*row);
}
}
//----------------------------------------------------------------------------//
void Dis_Matrix(uint8_t *src)
{
uint8_t i, num = 0;
for( i = 0; i < SIDE_LEN*SIDE_LEN; i ++)
{
printf("%4d ", *(src+i));
num ++;
if( (num%SIDE_LEN) == 0)
printf("\r\n");
}
}
//Init data list
void Create_DataList(void)
{
uint8_t i;
for( i = 0; i < SIDE_LEN*SIDE_LEN; i ++)
{
DataList[i] = i;
}
}
void Transpose_Test(void)
{
Create_DataList();//Init data list
printf("------------------Before----------------\r\n");
Dis_Matrix(DataList);
printf("------------------After-----------------\r\n");
//MatrixTranspose_BackWard(DataList, TransList);
//MatrixTranspose_Foward(DataList, TransList);
MatrixTranspose_180(DataList, TransList);
//MatrixTranspose_xMirror(DataList, TransList);
//MatrixTranspose_yMirror(DataList, TransList);
Dis_Matrix(TransList);
}
int main(void)
{
while(1)
{
scanf("%d",&SIDE_LEN);
system("cls");
Transpose_Test();
}
return 0;
}