File: util.cpp

package info (click to toggle)
nageru 2.3.2-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 3,120 kB
  • sloc: cpp: 39,131; perl: 94; sh: 18; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 556 bytes parent folder | download | duplicates (5)
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
#include "util.h"

#include <assert.h>
#include <memory>
#include <stdio.h>

using namespace std;

Flow read_flow(const char *filename)
{
	FILE *flowfp = fopen(filename, "rb");
	uint32_t hdr, width, height;
	fread(&hdr, sizeof(hdr), 1, flowfp);
	fread(&width, sizeof(width), 1, flowfp);
	fread(&height, sizeof(height), 1, flowfp);

	unique_ptr<Vec2[]> flow(new Vec2[width * height]);
	fread(flow.get(), width * height * sizeof(Vec2), 1, flowfp);
	fclose(flowfp);

	Flow ret;
	ret.width = width;
	ret.height = height;
	ret.flow = move(flow);
	return ret;
}