implement a flood_fill that stops at a given color rather than filling
[imager.git] / iolayert.h
CommitLineData
0778adbf
TC
1#ifndef IMAGER_IOLAYERT_H
2#define IMAGER_IOLAYERT_H
3
4#ifndef _MSC_VER
5#include <unistd.h>
6#endif
7#include <sys/types.h>
8
9typedef enum { FDSEEK, FDNOSEEK, BUFFER, CBSEEK, CBNOSEEK, BUFCHAIN } io_type;
10
11#ifdef _MSC_VER
12typedef int ssize_t;
13#endif
14
15typedef struct i_io_glue_t i_io_glue_t;
16
17/* compatibility for now */
18typedef i_io_glue_t io_glue;
19
20/* Callbacks we give out */
21
22typedef ssize_t(*i_io_readp_t) (io_glue *ig, void *buf, size_t count);
23typedef ssize_t(*i_io_writep_t)(io_glue *ig, const void *buf, size_t count);
24typedef off_t (*i_io_seekp_t) (io_glue *ig, off_t offset, int whence);
2b405c9e 25typedef int (*i_io_closep_t)(io_glue *ig);
0778adbf
TC
26typedef ssize_t(*i_io_sizep_t) (io_glue *ig);
27
28typedef void (*i_io_closebufp_t)(void *p);
29typedef void (*i_io_destroyp_t)(i_io_glue_t *ig);
30
31
32/* Callbacks we get */
33
34typedef ssize_t(*i_io_readl_t) (void *p, void *buf, size_t count);
35typedef ssize_t(*i_io_writel_t)(void *p, const void *buf, size_t count);
36typedef off_t (*i_io_seekl_t) (void *p, off_t offset, int whence);
2b405c9e 37typedef int (*i_io_closel_t)(void *p);
0778adbf
TC
38typedef void (*i_io_destroyl_t)(void *p);
39typedef ssize_t(*i_io_sizel_t) (void *p);
40
41extern char *io_type_names[];
42
43
44
45/* Structures to describe data sources */
46
47typedef struct {
48 io_type type;
49 int fd;
50} io_fdseek;
51
52typedef struct {
53 io_type type; /* Must be first parameter */
54 char *name; /* Data source name */
55 char *data;
56 size_t len;
57 i_io_closebufp_t closecb; /* free memory mapped segment or decrement refcount */
58 void *closedata;
59} io_buffer;
60
61typedef struct {
62 io_type type; /* Must be first parameter */
63 char *name; /* Data source name */
64 void *p; /* Callback data */
65 i_io_readl_t readcb;
66 i_io_writel_t writecb;
67 i_io_seekl_t seekcb;
68 i_io_closel_t closecb;
69 i_io_destroyl_t destroycb;
70} io_cb;
71
72typedef union {
73 io_type type;
74 io_fdseek fdseek;
75 io_buffer buffer;
76 io_cb cb;
77} io_obj;
78
79struct i_io_glue_t {
80 io_obj source;
81 int flags; /* Flags */
82 void *exdata; /* Pair specific data */
83 i_io_readp_t readcb;
84 i_io_writep_t writecb;
85 i_io_seekp_t seekcb;
86 i_io_closep_t closecb;
87 i_io_sizep_t sizecb;
88 i_io_destroyp_t destroycb;
89};
90
91#define i_io_type(ig) ((ig)->source.ig_type)
92#define i_io_read(ig, buf, size) ((ig)->readcb((ig), (buf), (size)))
93#define i_io_write(ig, data, size) ((ig)->writecb((ig), (data), (size)))
94#define i_io_seek(ig, offset, whence) ((ig)->seekcb((ig), (offset), (whence)))
95#define i_io_close(ig) ((ig)->closecb(ig))
96
97
98#endif