1
2 /*
3 * Copyright (C) 2015-2018 Alibaba Group Holding Limited
4 */
5
6 #include <stdio.h>
7 #include "to_rgb565.h"
8 #include <stdbool.h>
9
10 // 顺时针90度
rotate_right90(unsigned char * src,int srcW,int srcH,int channel)11 int rotate_right90(unsigned char *src, int srcW, int srcH, int channel)
12 {
13 unsigned char *tempSrc = NULL;
14 int mSize = srcW * srcH * sizeof(char) * channel;
15 int i = 0;
16 int j = 0;
17 int k = 0;
18 int desW = 0;
19 int desH = 0;
20
21 desW = srcH;
22 desH = srcW;
23
24 tempSrc = (unsigned char *)malloc(sizeof(char) * srcW * srcH * channel);
25 memcpy(tempSrc, src, mSize);
26
27 for (i = 0; i < desH; i++) {
28 for (j = 0; j < desW; j++) {
29 for (k = 0; k < channel; k++)
30 src[(i * desW + j) * channel + k] =
31 tempSrc[((srcH - 1 - j) * srcW + i) * channel + k];
32
33 }
34 }
35
36 free(tempSrc);
37 return 0;
38 }
39
40 // 逆时针90度
rotate_left90(unsigned char * src,int srcW,int srcH,int channel)41 int rotate_left90(unsigned char *src, int srcW, int srcH, int channel)
42 {
43 unsigned char *tempSrc = NULL;
44 int mSize = srcW * srcH * sizeof(char) * channel;
45 int i = 0;
46 int j = 0;
47 int k = 0;
48 int desW = 0;
49 int desH = 0;
50
51 desW = srcH;
52 desH = srcW;
53
54 tempSrc = (unsigned char *)malloc(sizeof(char) * srcW * srcH * channel);
55 memcpy(tempSrc, src, mSize);
56
57 for (i = 0; i < desH; i++) {
58 for (j = 0; j < desW; j++) {
59 for (k = 0; k < channel; k++)
60 src[(i * desW + j) * channel + k] =
61 tempSrc[(j * srcW + i) * channel + k];
62
63 }
64 }
65
66 free(tempSrc);
67 return 0;
68 }
69
70 // 旋转180度
rotate_down(unsigned char * src,int srcW,int srcH,int channel)71 int rotate_down(unsigned char *src, int srcW, int srcH, int channel)
72 {
73 unsigned char *tempSrc = NULL;
74 int mSize = srcW * srcH * sizeof(char) * channel;
75 int i = 0;
76 int j = 0;
77 int k = 0;
78 int desW = 0;
79 int desH = 0;
80
81 desW = srcW;
82 desH = srcH;
83
84 tempSrc = (unsigned char *)malloc(sizeof(char) * srcW * srcH * channel);
85 memcpy(tempSrc, src, mSize);
86
87 for (i = 0; i < desH; i++) {
88 for (j = 0; j < desW; j++) {
89 for (k = 0; k < channel; k++)
90 src[(i * desW + j) * channel + k] =
91 tempSrc[((srcH - 1 - i) * srcW +
92 srcW - 1 - j) * channel + k];
93
94 }
95 }
96
97 free(tempSrc);
98 return 0;
99 }
100
101