-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopacity.c
More file actions
38 lines (28 loc) · 793 Bytes
/
opacity.c
File metadata and controls
38 lines (28 loc) · 793 Bytes
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
#include <stdlib.h>
#include "farbfeld.h"
int main(int argc, char** argv)
{
uint32_t width, height;
uint16_t opacity;
pixel_t rgba;
if (argc != 2) {
fprintf(stderr, "usage: %s OPACITY_PCT\n", argv[0]);
return 1;
}
long opacity_pct = strtol(argv[1], NULL, 10);
if (opacity_pct > 100 || opacity_pct < 0) {
fprintf(stderr, "opacity out of range: %ld%%\n", opacity_pct);
return 1;
}
opacity = (uint16_t)(65535 * (opacity_pct / 100.0));
read_header(&width, &height);
write_header(width, height);
for (uint32_t i = 0; i < height; i++) {
for (uint32_t j = 0; j < width; j++) {
read_pixel(&rgba);
rgba.a = opacity;
write_pixel(&rgba);
}
}
return 0;
}