]> git.sesse.net Git - nageru/blob - util.cpp
Add some utility functions for working with .flo files.
[nageru] / util.cpp
1 #include <assert.h>
2 #include <stdio.h>
3
4 #include <memory>
5
6 #include "util.h"
7
8 using namespace std;
9
10 Flow read_flow(const char *filename)
11 {
12         FILE *flowfp = fopen(filename, "rb");
13         uint32_t hdr, width, height;
14         fread(&hdr, sizeof(hdr), 1, flowfp);
15         fread(&width, sizeof(width), 1, flowfp);
16         fread(&height, sizeof(height), 1, flowfp);
17
18         unique_ptr<Vec2[]> flow(new Vec2[width * height]);
19         fread(flow.get(), width * height * sizeof(Vec2), 1, flowfp);
20
21         Flow ret;
22         ret.width = width;
23         ret.height = height;
24         ret.flow = move(flow);
25         return ret;
26 }