/
ff-singen.c
57 lines (45 loc) · 984 Bytes
/
ff-singen.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
#include "tools.h"
int steps;
Coords size;
uint16_t get_pixel_value(uint32_t x, uint32_t y);
int main(int argc, char **argv)
{
int ret;
setvbuf(stdout, 0x0, _IOFBF, BUFSIZ);
if(argc != 4) {
fprintf(stderr, "Usage: %s width height steps\n", argv[0]);
return USERERR;
}
sscanf(argv[1], "%"SCNu32, &size.x);
sscanf(argv[2], "%"SCNu32, &size.y);
steps = atoi(argv[3]);
if(size.x == 0 || size.y == 0) {
fprintf(stderr, "Error: width and height must be >0\n");
return USERERR;
}
if(steps < 1) {
fprintf(stderr, "Error: steps must be >0\n");
return USERERR;
}
ret = ff_print_header(size);
if (ret != 0) {
ff_err(ret);
return ret;
}
FOR_X_Y(size.x, size.y,
uint16_t value = get_pixel_value(x, y);
ret = ff_print_bw(&value);
if (ret != 0) {
ff_err(ret);
return ret;
}
)
fflush(stdout);
return 0;
}
uint16_t
get_pixel_value(uint32_t x, uint32_t y)
{
uint16_t value = (sin(x*M_PI/size.x*2*steps)/2.+0.5)*UINT16_MAX;
return value;
}