forked from torch/image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppm.c
58 lines (45 loc) · 1.23 KB
/
ppm.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <TH.h>
#include <luaT.h>
#define torch_(NAME) TH_CONCAT_3(torch_, Real, NAME)
#define torch_Tensor TH_CONCAT_STRING_3(torch., Real, Tensor)
#define libppm_(NAME) TH_CONCAT_3(libppm_, Real, NAME)
/* Get the next character in the file, skipping over comments, which
* start with a # and continue to the end of the line.
*/
static char ppm_getc(FILE *fp)
{
char ch;
ch = (char)getc(fp);
if (ch == '#') {
do {
ch = (char)getc(fp);
} while (ch != '\n' && ch != '\r');
}
return ch;
}
/* Get the next integer, skipping whitespace and comments. */
static long ppm_get_long(FILE *fp)
{
char ch;
long i = 0;
do {
ch = ppm_getc(fp);
} while (ch == ' ' || ch == ',' || ch == '\t' || ch == '\n' || ch == '\r');
do {
i = i * 10 + ch - '0';
ch = ppm_getc(fp);
} while (ch >= '0' && ch <= '9');
return i;
}
#include "generic/ppm.c"
#include "THGenerateAllTypes.h"
DLL_EXPORT int luaopen_libppm(lua_State *L)
{
libppm_FloatMain_init(L);
libppm_DoubleMain_init(L);
libppm_ByteMain_init(L);
luaL_register(L, "libppm.double", libppm_DoubleMain__);
luaL_register(L, "libppm.float", libppm_FloatMain__);
luaL_register(L, "libppm.byte", libppm_ByteMain__);
return 1;
}