-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
118 lines (93 loc) · 2.5 KB
/
main.c
File metadata and controls
118 lines (93 loc) · 2.5 KB
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
#include "stdlib.h"
#include "math.h"
#define LOGENABLE
#include "log.h"
#include "glgrid.h"
#include "gldebug.h"
void dummy_transform(Grid_t* grid)
{
// Rotation center
float x0 = grid->rect.width/2;
float y0 = grid->rect.height/2;
float minX = 0;
float maxX = 0;
float minY = 0;
float maxY = 0;
int i;
for (i = 0; i < grid->count; i++)
{
float * pX = &grid->vertices[3 * i + 0];
float * pY = &grid->vertices[3 * i + 1];
float x = *pX;
float y = *pY;
float r = (float)sqrt((x - x0)*(x - x0) + (y - y0)*(y - y0));
float a = (float)atan2((x - x0),(y - y0));
r = r * 0.07f;
r = r * r;
a += 0.2f;
if (r>800) r = 800;
*pX = x0 + r*(float)sin(a);
*pY = y0 + r*(float)cos(a);
if (i == 0) {
minX = *pX;
maxX = *pX;
minY = *pY;
maxY = *pY;
} else {
if (minX>*pX) minX = *pX;
if (maxX<*pX) maxX = *pX;
if (minY>*pY) minY = *pY;
if (maxY<*pY) maxY = *pY;
}
}
grid->rect.x = minX;
grid->rect.y = minY;
grid->rect.width = maxX - minX;
grid->rect.height = maxY - minY;
IFRectFloat2Int(&grid->rect);
}
int main(int argc, char** argv)
{
int errorcode = 0;
Buffer_t* in = NULL;
Grid_t grid = {0};
Buffer_t* out = NULL;
LOG_SET(LOG_MAXLVL);
for (;;) {
// 1- read an image
in = LoadBMPToXBUFF("image.bmp");
if (NULL==in) {
STDERR("Invalid input Image\n");
errorcode = 1;
break;
}
// 2- create a grid geometry (20x20)
grid = CreateGLGrid(in, 20);
if (0==grid.count) {
STDERR("Invalid Grid\n");
errorcode = 2;
break;
}
// 3- deform grid
dummy_transform(&grid);
// 4- generate new buffer
out = RenderGLGrid(&grid, RGB_TEXTURE_MODE);
if (NULL==in) {
STDERR("No output\n");
errorcode = 3;
break;
}
// 5- save output
if (SaveBMPFromXBUFF("result.bmp", out)) {
STDERR("Invalid output Image\n");
errorcode = 1;
break;
}
STDOUT("result.bmp generated !\n");
break;
}
FreeGLGrid(&grid);
if (NULL!=in) FreeBuffer(in);
if (NULL!=out) FreeBuffer(out);
return errorcode;
}