test we don't use vars and that we have use 5.006.
[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
35db02fc 19#define i_img_has_alpha(im) (i_img_alpha_channel((im), NULL))
bea65b1f 20
836d9f54
TC
21/*
22=item i_psamp(im, left, right, y, samples, channels, channel_count)
23=category Drawing
24
25Writes sample values from C<samples> to C<im> for the horizontal line
26(left, y) to (right-1, y) inclusive for the channels specified by
27C<channels>, an array of C<int> with C<channel_count> elements.
28
29If C<channels> is C<NULL> then the first C<channels_count> channels
30are written to for each pixel.
31
32Returns the number of samples written, which should be (right - left)
33* channel_count. If a channel not in the image is in channels, left
34is negative, left is outside the image or y is outside the image,
35returns -1 and pushes an error.
36
37=cut
38*/
39
40#define i_psamp(im, l, r, y, samps, chans, count) \
41 (((im)->i_f_psamp)((im), (l), (r), (y), (samps), (chans), (count)))
42
43/*
44=item i_psampf(im, left, right, y, samples, channels, channel_count)
45=category Drawing
46
47Writes floating point sample values from C<samples> to C<im> for the
48horizontal line (left, y) to (right-1, y) inclusive for the channels
49specified by C<channels>, an array of C<int> with C<channel_count>
50elements.
51
52If C<channels> is C<NULL> then the first C<channels_count> channels
53are written to for each pixel.
54
55Returns the number of samples written, which should be (right - left)
56* channel_count. If a channel not in the image is in channels, left
57is negative, left is outside the image or y is outside the image,
58returns -1 and pushes an error.
59
60=cut
61*/
62
63#define i_psampf(im, l, r, y, samps, chans, count) \
64 (((im)->i_f_psampf)((im), (l), (r), (y), (samps), (chans), (count)))
65
cf8c77ae
TC
66#ifndef IMAGER_DIRECT_IMAGE_CALLS
67#define IMAGER_DIRECT_IMAGE_CALLS 1
68#endif
69
70#if IMAGER_DIRECT_IMAGE_CALLS
71
72#define i_ppix(im, x, y, val) (((im)->i_f_ppix)((im), (x), (y), (val)))
73#define i_gpix(im, x, y, val) (((im)->i_f_gpix)((im), (x), (y), (val)))
74#define i_ppixf(im, x, y, val) (((im)->i_f_ppixf)((im), (x), (y), (val)))
75#define i_gpixf(im, x, y, val) (((im)->i_f_gpixf)((im), (x), (y), (val)))
76#define i_plin(im, l, r, y, val) (((im)->i_f_plin)(im, l, r, y, val))
77#define i_glin(im, l, r, y, val) (((im)->i_f_glin)(im, l, r, y, val))
78#define i_plinf(im, l, r, y, val) (((im)->i_f_plinf)(im, l, r, y, val))
79#define i_glinf(im, l, r, y, val) (((im)->i_f_glinf)(im, l, r, y, val))
80
81#define i_gsamp(im, l, r, y, samps, chans, count) \
82 (((im)->i_f_gsamp)((im), (l), (r), (y), (samps), (chans), (count)))
83#define i_gsampf(im, l, r, y, samps, chans, count) \
84 (((im)->i_f_gsampf)((im), (l), (r), (y), (samps), (chans), (count)))
85
86#endif
87
88#define i_gsamp_bits(im, l, r, y, samps, chans, count, bits) \
89 (((im)->i_f_gsamp_bits) ? ((im)->i_f_gsamp_bits)((im), (l), (r), (y), (samps), (chans), (count), (bits)) : -1)
90#define i_psamp_bits(im, l, r, y, samps, chans, count, bits) \
91 (((im)->i_f_psamp_bits) ? ((im)->i_f_psamp_bits)((im), (l), (r), (y), (samps), (chans), (count), (bits)) : -1)
92
93#define i_findcolor(im, color, entry) \
94 (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0)
95
96#define i_gpal(im, l, r, y, vals) \
97 (((im)->i_f_gpal) ? ((im)->i_f_gpal)((im), (l), (r), (y), (vals)) : 0)
98#define i_ppal(im, l, r, y, vals) \
99 (((im)->i_f_ppal) ? ((im)->i_f_ppal)((im), (l), (r), (y), (vals)) : 0)
100#define i_addcolors(im, colors, count) \
101 (((im)->i_f_addcolors) ? ((im)->i_f_addcolors)((im), (colors), (count)) : -1)
102#define i_getcolors(im, index, color, count) \
103 (((im)->i_f_getcolors) ? \
104 ((im)->i_f_getcolors)((im), (index), (color), (count)) : 0)
105#define i_setcolors(im, index, color, count) \
106 (((im)->i_f_setcolors) ? \
107 ((im)->i_f_setcolors)((im), (index), (color), (count)) : 0)
108#define i_colorcount(im) \
109 (((im)->i_f_colorcount) ? ((im)->i_f_colorcount)(im) : -1)
110#define i_maxcolors(im) \
111 (((im)->i_f_maxcolors) ? ((im)->i_f_maxcolors)(im) : -1)
112#define i_findcolor(im, color, entry) \
113 (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0)
114
115#define i_img_virtual(im) ((im)->virtual)
116#define i_img_type(im) ((im)->type)
117#define i_img_bits(im) ((im)->bits)
118
768dd2c8
TC
119#define pIMCTX im_context_t my_im_ctx
120
74315ca9 121#ifdef IMAGER_NO_CONTEXT
768dd2c8
TC
122#define dIMCTXctx(ctx) pIMCTX = (ctx)
123#define dIMCTX dIMCTXctx(im_get_context())
124#define dIMCTXim(im) dIMCTXctx((im)->context)
a38f29c7 125#define dIMCTXio(io) dIMCTXctx((io)->context)
74315ca9
TC
126#define aIMCTX my_im_ctx
127#else
128#define aIMCTX im_get_context()
129#endif
130
44d86483
TC
131#define i_img_8_new(xsize, ysize, channels) im_img_8_new(aIMCTX, (xsize), (ysize), (channels))
132#define i_img_16_new(xsize, ysize, channels) im_img_16_new(aIMCTX, (xsize), (ysize), (channels))
133#define i_img_double_new(xsize, ysize, channels) im_img_double_new(aIMCTX, (xsize), (ysize), (channels))
134#define i_img_pal_new(xsize, ysize, channels, maxpal) im_img_pal_new(aIMCTX, (xsize), (ysize), (channels), (maxpal))
135
136#define i_img_alloc() im_img_alloc(aIMCTX)
137#define i_img_init(im) im_img_init(aIMCTX, im)
138
139#define i_set_image_file_limits(width, height, bytes) im_set_image_file_limits(aIMCTX, width, height, bytes)
140#define i_get_image_file_limits(width, height, bytes) im_get_image_file_limits(aIMCTX, width, height, bytes)
141#define i_int_check_image_file_limits(width, height, channels, sample_size) im_int_check_image_file_limits(aIMCTX, width, height, channels, sample_size)
142
143#define i_clear_error() im_clear_error(aIMCTX)
144#define i_push_errorvf(code, fmt, args) im_push_errorvf(aIMCTX, code, fmt, args)
145#define i_push_error(code, msg) im_push_error(aIMCTX, code, msg)
8b30e240 146#define i_errors() im_errors(aIMCTX)
44d86483 147
ed60e785
TC
148#define io_new_fd(fd) im_io_new_fd(aIMCTX, (fd))
149#define io_new_bufchain() im_io_new_bufchain(aIMCTX)
150#define io_new_buffer(data, len, closecb, closectx) im_io_new_buffer(aIMCTX, (data), (len), (closecb), (closectx))
151#define io_new_cb(p, readcb, writecb, seekcb, closecb, destroycb) \
152 im_io_new_cb(aIMCTX, (p), (readcb), (writecb), (seekcb), (closecb), (destroycb))
153
bea65b1f 154#endif