add i_errors()/im_errors() to the API
[imager.git] / immacros.h
CommitLineData
bea65b1f
TC
1/*
2 Imager "functions" implemented as macros
3
4 I suppose these could go in imdatatypes, but they aren't types.
5*/
6#ifndef IMAGER_IMMACROS_H_
7#define IMAGER_IMMACROS_H_
8
9/*
5715f7c3 10=item i_img_has_alpha(C<im>)
bea65b1f
TC
11
12=category Image Information
13
14Return true if the image has an alpha channel.
15
16=cut
17*/
18
19#define i_img_has_alpha(im) ((im)->channels == 2 || (im)->channels == 4)
20
21/*
5715f7c3 22=item i_img_color_channels(C<im>)
bea65b1f
TC
23
24=category Image Information
25
26The number of channels holding color information.
27
28=cut
29*/
30
31#define i_img_color_channels(im) (i_img_has_alpha(im) ? (im)->channels - 1 : (im)->channels)
32
836d9f54
TC
33/*
34=item i_psamp(im, left, right, y, samples, channels, channel_count)
35=category Drawing
36
37Writes sample values from C<samples> to C<im> for the horizontal line
38(left, y) to (right-1, y) inclusive for the channels specified by
39C<channels>, an array of C<int> with C<channel_count> elements.
40
41If C<channels> is C<NULL> then the first C<channels_count> channels
42are written to for each pixel.
43
44Returns the number of samples written, which should be (right - left)
45* channel_count. If a channel not in the image is in channels, left
46is negative, left is outside the image or y is outside the image,
47returns -1 and pushes an error.
48
49=cut
50*/
51
52#define i_psamp(im, l, r, y, samps, chans, count) \
53 (((im)->i_f_psamp)((im), (l), (r), (y), (samps), (chans), (count)))
54
55/*
56=item i_psampf(im, left, right, y, samples, channels, channel_count)
57=category Drawing
58
59Writes floating point sample values from C<samples> to C<im> for the
60horizontal line (left, y) to (right-1, y) inclusive for the channels
61specified by C<channels>, an array of C<int> with C<channel_count>
62elements.
63
64If C<channels> is C<NULL> then the first C<channels_count> channels
65are written to for each pixel.
66
67Returns the number of samples written, which should be (right - left)
68* channel_count. If a channel not in the image is in channels, left
69is negative, left is outside the image or y is outside the image,
70returns -1 and pushes an error.
71
72=cut
73*/
74
75#define i_psampf(im, l, r, y, samps, chans, count) \
76 (((im)->i_f_psampf)((im), (l), (r), (y), (samps), (chans), (count)))
77
0e2999c7
TC
78#ifndef IMAGER_DIRECT_IMAGE_CALLS
79#define IMAGER_DIRECT_IMAGE_CALLS 1
80#endif
81
82#if IMAGER_DIRECT_IMAGE_CALLS
83
84#define i_ppix(im, x, y, val) (((im)->i_f_ppix)((im), (x), (y), (val)))
85#define i_gpix(im, x, y, val) (((im)->i_f_gpix)((im), (x), (y), (val)))
86#define i_ppixf(im, x, y, val) (((im)->i_f_ppixf)((im), (x), (y), (val)))
87#define i_gpixf(im, x, y, val) (((im)->i_f_gpixf)((im), (x), (y), (val)))
88#define i_plin(im, l, r, y, val) (((im)->i_f_plin)(im, l, r, y, val))
89#define i_glin(im, l, r, y, val) (((im)->i_f_glin)(im, l, r, y, val))
90#define i_plinf(im, l, r, y, val) (((im)->i_f_plinf)(im, l, r, y, val))
91#define i_glinf(im, l, r, y, val) (((im)->i_f_glinf)(im, l, r, y, val))
92
93#define i_gsamp(im, l, r, y, samps, chans, count) \
94 (((im)->i_f_gsamp)((im), (l), (r), (y), (samps), (chans), (count)))
95#define i_gsampf(im, l, r, y, samps, chans, count) \
96 (((im)->i_f_gsampf)((im), (l), (r), (y), (samps), (chans), (count)))
97
98#endif
99
100#define i_gsamp_bits(im, l, r, y, samps, chans, count, bits) \
101 (((im)->i_f_gsamp_bits) ? ((im)->i_f_gsamp_bits)((im), (l), (r), (y), (samps), (chans), (count), (bits)) : -1)
102#define i_psamp_bits(im, l, r, y, samps, chans, count, bits) \
103 (((im)->i_f_psamp_bits) ? ((im)->i_f_psamp_bits)((im), (l), (r), (y), (samps), (chans), (count), (bits)) : -1)
104
105#define i_findcolor(im, color, entry) \
106 (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0)
107
108#define i_gpal(im, l, r, y, vals) \
109 (((im)->i_f_gpal) ? ((im)->i_f_gpal)((im), (l), (r), (y), (vals)) : 0)
110#define i_ppal(im, l, r, y, vals) \
111 (((im)->i_f_ppal) ? ((im)->i_f_ppal)((im), (l), (r), (y), (vals)) : 0)
112#define i_addcolors(im, colors, count) \
113 (((im)->i_f_addcolors) ? ((im)->i_f_addcolors)((im), (colors), (count)) : -1)
114#define i_getcolors(im, index, color, count) \
115 (((im)->i_f_getcolors) ? \
116 ((im)->i_f_getcolors)((im), (index), (color), (count)) : 0)
117#define i_setcolors(im, index, color, count) \
118 (((im)->i_f_setcolors) ? \
119 ((im)->i_f_setcolors)((im), (index), (color), (count)) : 0)
120#define i_colorcount(im) \
121 (((im)->i_f_colorcount) ? ((im)->i_f_colorcount)(im) : -1)
122#define i_maxcolors(im) \
123 (((im)->i_f_maxcolors) ? ((im)->i_f_maxcolors)(im) : -1)
124#define i_findcolor(im, color, entry) \
125 (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0)
126
127#define i_img_virtual(im) ((im)->virtual)
128#define i_img_type(im) ((im)->type)
129#define i_img_bits(im) ((im)->bits)
130
bd251423
TC
131#define pIMCTX im_context_t my_im_ctx
132
9c852bc4 133#ifdef IMAGER_NO_CONTEXT
bd251423
TC
134#define dIMCTXctx(ctx) pIMCTX = (ctx)
135#define dIMCTX dIMCTXctx(im_get_context())
136#define dIMCTXim(im) dIMCTXctx((im)->context)
4989825c 137#define dIMCTXio(io) dIMCTXctx((io)->context)
9c852bc4
TC
138#define aIMCTX my_im_ctx
139#else
140#define aIMCTX im_get_context()
141#endif
142
a482206e
TC
143#define i_img_8_new(xsize, ysize, channels) im_img_8_new(aIMCTX, (xsize), (ysize), (channels))
144#define i_img_16_new(xsize, ysize, channels) im_img_16_new(aIMCTX, (xsize), (ysize), (channels))
145#define i_img_double_new(xsize, ysize, channels) im_img_double_new(aIMCTX, (xsize), (ysize), (channels))
146#define i_img_pal_new(xsize, ysize, channels, maxpal) im_img_pal_new(aIMCTX, (xsize), (ysize), (channels), (maxpal))
147
148#define i_img_alloc() im_img_alloc(aIMCTX)
149#define i_img_init(im) im_img_init(aIMCTX, im)
150
151#define i_set_image_file_limits(width, height, bytes) im_set_image_file_limits(aIMCTX, width, height, bytes)
152#define i_get_image_file_limits(width, height, bytes) im_get_image_file_limits(aIMCTX, width, height, bytes)
153#define i_int_check_image_file_limits(width, height, channels, sample_size) im_int_check_image_file_limits(aIMCTX, width, height, channels, sample_size)
154
155#define i_clear_error() im_clear_error(aIMCTX)
156#define i_push_errorvf(code, fmt, args) im_push_errorvf(aIMCTX, code, fmt, args)
157#define i_push_error(code, msg) im_push_error(aIMCTX, code, msg)
fa56d5a9 158#define i_errors() im_errors(aIMCTX)
a482206e 159
f6703858
TC
160#define io_new_fd(fd) im_io_new_fd(aIMCTX, (fd))
161#define io_new_bufchain() im_io_new_bufchain(aIMCTX)
162#define io_new_buffer(data, len, closecb, closectx) im_io_new_buffer(aIMCTX, (data), (len), (closecb), (closectx))
163#define io_new_cb(p, readcb, writecb, seekcb, closecb, destroycb) \
164 im_io_new_cb(aIMCTX, (p), (readcb), (writecb), (seekcb), (closecb), (destroycb))
165
bea65b1f 166#endif