pointer to a description of how unsharp mask works
[imager.git] / iolayer.h
CommitLineData
02d1d628
AMH
1#ifndef _IOLAYER_H_
2#define _IOLAYER_H_
3
4
5/* How the IO layer works:
6 *
7 * Start by getting an io_glue object. Then define its
8 * datasource via io_obj_setp_buffer or io_obj_setp_cb. Before
9 * using the io_glue object be sure to call io_glue_commit_types().
10 * After that data can be read via the io_glue->readcb() method.
11 *
12 */
13
14
15#include <stdio.h>
16#ifndef _MSC_VER
17#include <unistd.h>
18#endif
19#include <sys/types.h>
20
21/* #define BBSIZ 1096 */
22#define BBSIZ 1096
23#define IO_FAKE_SEEK 1<<0L
24#define IO_TEMP_SEEK 1<<1L
25
26
27typedef union { int i; void *p; } iorp;
28
29typedef enum { FDSEEK, FDNOSEEK, BUFFER, CBSEEK, CBNOSEEK, BUFCHAIN } io_type;
30
31#ifdef _MSC_VER
32typedef int ssize_t;
33#endif
34
35struct _io_glue;
36
37/* Callbacks we give out */
38
39typedef ssize_t(*readp) (struct _io_glue *ig, void *buf, size_t count);
40typedef ssize_t(*writep)(struct _io_glue *ig, const void *buf, size_t count);
41typedef off_t (*seekp) (struct _io_glue *ig, off_t offset, int whence);
42typedef void (*closep)(struct _io_glue *ig);
43typedef ssize_t(*sizep) (struct _io_glue *ig);
44
45
46
47/* Callbacks we get */
48
49typedef ssize_t(*readl) (int fd, void *buf, size_t count);
50typedef ssize_t(*writel)(int fd, const void *buf, size_t count);
51typedef off_t (*seekl) (int fd, off_t offset, int whence);
52typedef ssize_t(*sizel) (int fd);
53
54extern char *io_type_names[];
55
56
57typedef struct _io_blink {
58 char buf[BBSIZ];
59 /* size_t cnt; */
60 size_t len; /* How large is this buffer = BBZIS for now */
61 struct _io_blink *next;
62 struct _io_blink *prev;
63} io_blink;
64
65
66/* Structures that describe callback interfaces */
67
68typedef struct {
69 off_t offset;
70 off_t cpos;
71} io_ex_rseek;
72
73
74typedef struct {
75 off_t offset;
76 off_t cpos;
77 io_blink *head;
78 io_blink *tail;
79 io_blink *cp;
80} io_ex_fseek;
81
82
83typedef struct {
84 off_t offset; /* Offset of the source - not used */
85 off_t length; /* Total length of chain in bytes */
86 io_blink *head; /* Start of chain */
87 io_blink *tail; /* End of chain */
88 off_t tfill; /* End of stream in last link */
89 io_blink *cp; /* Current element of list */
90 off_t cpos; /* Offset within the current */
91 off_t gpos; /* Global position in stream */
92} io_ex_bchain;
93
94
95/* Structures to describe data sources */
96
97typedef struct {
98 io_type type;
99 int fd;
100} io_fdseek;
101
102typedef struct {
103 io_type type; /* Must be first parameter */
104 char *name; /* Data source name */
105 char *c;
106 size_t len;
107} io_buffer;
108
109typedef struct {
110 io_type type; /* Must be first parameter */
111 char *name; /* Data source name */
112 void *p; /* Callback data */
113 readl readcb;
114 writel writecb;
115 seekl seekcb;
116} io_cb;
117
118typedef union {
119 io_type type;
120 io_fdseek fdseek;
121 io_buffer buffer;
122 io_cb cb;
123} io_obj;
124
125typedef struct _io_glue {
126 io_obj source;
127 int flags; /* Flags */
128 void *exdata; /* Pair specific data */
129 readp readcb;
130 writep writecb;
131 seekp seekcb;
132 closep closecb;
133 sizep sizecb;
134} io_glue;
135
136void io_obj_setp_buffer (io_obj *io, void *p, size_t len);
137void io_obj_setp_cb (io_obj *io, void *p, readl readcb, writel writecb, seekl seekcb);
138void io_glue_commit_types(io_glue *ig);
139void io_glue_gettypes (io_glue *ig, int reqmeth);
140
141
142/* XS functions */
143io_glue *io_new_fd(int fd);
144io_glue *io_new_bufchain();
145size_t io_slurp(io_glue *ig, unsigned char **c);
146void io_glue_DESTROY(io_glue *ig);
147
148#endif /* _IOLAYER_H_ */