Rename GP_Context -> GP_Pixmap
[gfxprim.git] / libs / filters / point_filter.t
blobfba04afe54b11c9dfcee4fa695d5937e365d26a4
1 @ def filter_point_ex(op_name, filter_op, fopts):
2 int GP_Filter{{ op_name }}Ex(const GP_Pixmap *const src,
3                              GP_Coord x_src, GP_Coord y_src,
4                              GP_Size w_src, GP_Size h_src,
5                              GP_Pixmap *dst,
6                              GP_Coord x_dst, GP_Coord y_dst,
7                              {{ maybe_opts_r(fopts) }}
8                              GP_ProgressCallback *callback)
10         const GP_PixelTypeDescription *desc;
11         GP_FilterTables tables;
12         unsigned int i;
13         GP_Pixel j;
14         int ret, err;
16         if (GP_FilterTablesInit(&tables, src))
17                 return 1;
19         desc = GP_PixelTypeDesc(src->pixel_type);
21         for (i = 0; i < desc->numchannels; i++) {
22                 GP_Pixel chan_max = (1 << desc->channels[i].size);
23                 GP_Pixel *table = tables.table[i];
25                 for (j = 0; j < chan_max; j++)
26                         table[j] = {@ filter_op('((signed)j)', '((signed)chan_max - 1)') @};
27         }
29         ret = GP_FilterTablesApply(src, x_src, y_src, w_src, h_src,
30                                    dst, x_dst, y_dst, &tables, callback);
32         err = errno;
33         GP_FilterTablesFree(&tables);
34         errno = err;
36         return ret;
39 @ def filter_point_ex_alloc(op_name, fopts, opts):
40 GP_Pixmap *GP_Filter{{ op_name }}ExAlloc(const GP_Pixmap *const src,
41                                           GP_Coord x_src, GP_Coord y_src,
42                                           GP_Size w_src, GP_Size h_src,
43                                           {{ maybe_opts_r(fopts) }}
44                                           GP_ProgressCallback *callback)
46         GP_Pixmap *new = GP_PixmapAlloc(w_src, h_src,
47                                           src->pixel_type);
49         if (GP_Filter{{ op_name }}Ex(src, x_src, y_src, w_src, h_src, new, 0, 0,
50                                      {{ maybe_opts_r(opts) }}callback)) {
51                 int err = errno;
52                 GP_PixmapFree(new);
53                 errno = err;
54                 return NULL;
55         }
57         return new;
60 @ def filter_point(op_name, filter_op, fopts="", opts=""):
61 #include <errno.h>
63 #include "core/GP_Debug.h"
65 #include "filters/GP_ApplyTables.h"
66 #include "filters/GP_Point.h"
68 {@ filter_point_ex(op_name, filter_op, fopts) @}
69 {@ filter_point_ex_alloc(op_name, fopts, opts) @}
70 @ end