-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfunctions.cpp
executable file
·89 lines (75 loc) · 1.68 KB
/
functions.cpp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
void output(int level, const char* fmt, ...) {
va_list args;
if (level<=g_verbosity) {
va_start(args,fmt);
vprintf(fmt,args);
va_end(args);
}
}
#ifdef WIN32
class my_timer {
public:
void set() {
QueryPerformanceCounter(&t1);
}
double read() {
QueryPerformanceCounter(&t2);
return (double)(t2.QuadPart-t1.QuadPart)/frequency.QuadPart;
}
my_timer() {
QueryPerformanceFrequency(&frequency);
}
void report(const char* name) {
if (g_timing) output(0,"%s: %.3fs\n",name,this->read());
}
private:
LARGE_INTEGER t1;
LARGE_INTEGER t2;
LARGE_INTEGER frequency;
};
#else
class my_timer {
public:
void set() { }
double read() { return 0; }
void report(const char* name) { if (g_timing) printf("Timing not available\n"); }
};
#endif
void report_time(const char* name, double time) {
if (g_timing) output(0,"%s: %.3fs\n",name,time);
}
#ifndef WIN32
#define SNPRINTF snprintf
int _stricmp(const char* a, const char* b) { return strcasecmp(a,b); }
void* _aligned_malloc(size_t size, int boundary) { return memalign(boundary,size); }
void _aligned_free(void* a) { free(a); }
void fopen_s(FILE** f,const char* filename, const char* mode) { *f=fopen(filename,mode); }
#else
#define SNPRINTF _snprintf_s
#endif
void clear_temp() {
int i,c;
for (i=0; i<g_numimages; i++) {
for (c=0; c<g_numchannels; c++) {
if (g_images[i].channels[c].f) {
fclose(g_images[i].channels[c].f);
#ifdef WIN32
DeleteFile(g_images[i].channels[c].filename);
#endif
}
}
}
}
void die(const char* error, ...) {
va_list args;
va_start(args,error);
vprintf(error,args);
va_end(args);
printf("\n");
clear_temp();
if (g_debug) {
printf("\nPress Enter to end\n");
getchar();
}
exit(1);
}