WIP, it compiles
[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
74315ca9
TC
78#ifdef IMAGER_NO_CONTEXT
79#define dIMCTX im_context_t my_im_ctx = im_get_context()
80#define dIMCTXa(a) im_context_t my_im_ctx = im_get_context()
696cb85d 81#define dIMCTXim(im) im_context_t my_im_ctx = (im)->context
74315ca9
TC
82#define aIMCTX my_im_ctx
83#else
84#define aIMCTX im_get_context()
85#endif
86
696cb85d
TC
87#define pIMCTX im_context_t my_im_ctx
88
44d86483
TC
89#define i_img_8_new(xsize, ysize, channels) im_img_8_new(aIMCTX, (xsize), (ysize), (channels))
90#define i_img_16_new(xsize, ysize, channels) im_img_16_new(aIMCTX, (xsize), (ysize), (channels))
91#define i_img_double_new(xsize, ysize, channels) im_img_double_new(aIMCTX, (xsize), (ysize), (channels))
92#define i_img_pal_new(xsize, ysize, channels, maxpal) im_img_pal_new(aIMCTX, (xsize), (ysize), (channels), (maxpal))
93
94#define i_img_alloc() im_img_alloc(aIMCTX)
95#define i_img_init(im) im_img_init(aIMCTX, im)
96
97#define i_set_image_file_limits(width, height, bytes) im_set_image_file_limits(aIMCTX, width, height, bytes)
98#define i_get_image_file_limits(width, height, bytes) im_get_image_file_limits(aIMCTX, width, height, bytes)
99#define i_int_check_image_file_limits(width, height, channels, sample_size) im_int_check_image_file_limits(aIMCTX, width, height, channels, sample_size)
100
101#define i_clear_error() im_clear_error(aIMCTX)
102#define i_push_errorvf(code, fmt, args) im_push_errorvf(aIMCTX, code, fmt, args)
103#define i_push_error(code, msg) im_push_error(aIMCTX, code, msg)
104
bea65b1f 105#endif