-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
42 lines (39 loc) · 860 Bytes
/
main.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
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <soundpipe.h>
struct Spa
{
char magic;
char nchan;
uint16_t sr;
uint32_t len;
};
int main()
{
int i, j;
uint8_t hdr[strlen("farbfeld") + 2 * sizeof(uint32_t)];
uint16_t h, w, rgba[4];
SPFLOAT *d;
fread(hdr, sizeof(hdr), 1, stdin);
w = ntohl(*((uint32_t *)(hdr + 8)));
h = ntohl(*((uint32_t *)(hdr + 12)));
d = calloc(w, sizeof(SPFLOAT));
if(!(h%2))
h--;
for(i = 0; i < h; i++) {
for(j = 0; j < w; j++) {
fread(rgba, sizeof(uint16_t), 4, stdin);
if(!rgba[0] & 0xff)
d[j] = ((SPFLOAT)(h-i)/(h-1.0) - 1) *2;
}
}
struct Spa spa = { 100, 1, 48000, w };
fwrite(&spa, sizeof(spa), 1, stdout);
for(i = 0; i < w; i++)
fwrite(d, sizeof(SPFLOAT), w, stdout);
free(d);
return 0;
}