diff options
Diffstat (limited to 'apps/plugins/imageviewer/jpegp/FILEGETC.c')
-rw-r--r-- | apps/plugins/imageviewer/jpegp/FILEGETC.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/apps/plugins/imageviewer/jpegp/FILEGETC.c b/apps/plugins/imageviewer/jpegp/FILEGETC.c new file mode 100644 index 0000000000..bb7f0c485f --- /dev/null +++ b/apps/plugins/imageviewer/jpegp/FILEGETC.c | |||
@@ -0,0 +1,71 @@ | |||
1 | #include "rb_glue.h" | ||
2 | |||
3 | static int fd; | ||
4 | |||
5 | extern int GETC(void) | ||
6 | { | ||
7 | unsigned char x; | ||
8 | rb->read(fd, &x, 1); | ||
9 | return x; | ||
10 | } | ||
11 | |||
12 | // multibyte readers: host-endian independent - if evaluated in right order (ie. don't optimize) | ||
13 | |||
14 | extern int GETWbi(void) // 16-bit big-endian | ||
15 | { | ||
16 | return ( GETC()<<8 ) | GETC(); | ||
17 | } | ||
18 | |||
19 | extern int GETDbi(void) // 32-bit big-endian | ||
20 | { | ||
21 | return ( GETC()<<24 ) | ( GETC()<<16 ) | ( GETC()<<8 ) | GETC(); | ||
22 | } | ||
23 | |||
24 | extern int GETWli(void) // 16-bit little-endian | ||
25 | { | ||
26 | return GETC() | ( GETC()<<8 ); | ||
27 | } | ||
28 | |||
29 | extern int GETDli(void) // 32-bit little-endian | ||
30 | { | ||
31 | return GETC() | ( GETC()<<8 ) | ( GETC()<<16 ) | ( GETC()<<24 ); | ||
32 | } | ||
33 | |||
34 | // seek | ||
35 | |||
36 | extern void SEEK(int d) | ||
37 | { | ||
38 | rb->lseek(fd, d, SEEK_CUR); | ||
39 | } | ||
40 | |||
41 | extern void POS(int d) | ||
42 | { | ||
43 | rb->lseek(fd, d, SEEK_SET); | ||
44 | } | ||
45 | |||
46 | extern int TELL(void) | ||
47 | { | ||
48 | return rb->lseek(fd, 0, SEEK_CUR); | ||
49 | } | ||
50 | |||
51 | // OPEN/CLOSE file | ||
52 | |||
53 | extern void *OPEN(char *f) | ||
54 | { | ||
55 | printf("Opening %s\n", f); | ||
56 | |||
57 | fd = rb->open(f,O_RDONLY); | ||
58 | |||
59 | if ( fd < 0 ) | ||
60 | { | ||
61 | printf("Error opening %s\n", f); | ||
62 | return NULL; | ||
63 | } | ||
64 | |||
65 | return &fd; | ||
66 | } | ||
67 | |||
68 | extern int CLOSE(void) | ||
69 | { | ||
70 | return rb->close(fd); | ||
71 | } | ||