filters/gp_filter_resize_alloc: Check w and h
[gfxprim.git] / libs / filters / GP_ApplyTables.gen.c.t
blob1e488b802f4395826b32b6cbbf9b1076ed3d5a34
1 @ include source.t
2 /*
3  * Generic Point filer
4  *
5  * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz>
6  */
8 #include <errno.h>
10 #include "core/GP_Pixmap.h"
11 #include "core/GP_GetPutPixel.h"
12 #include "core/GP_Debug.h"
14 #include "filters/GP_ApplyTables.h"
16 @ for pt in pixeltypes:
17 @     if not pt.is_unknown() and not pt.is_palette():
18 static int apply_tables_{{ pt.name }}(const gp_pixmap *const src,
19                                       gp_coord x_src, gp_coord y_src,
20                                       gp_size w_src, gp_size h_src,
21                                       gp_pixmap *dst,
22                                       gp_coord x_dst, gp_coord y_dst,
23                                       const gp_filter_tables *const tables,
24                                       gp_progress_cb *callback)
26         GP_DEBUG(1, "Point filter %ux%u", w_src, h_src);
28         unsigned int x, y;
30 @         for c in pt.chanslist:
31         gp_pixel {{ c.name }};
32 @         end
34         for (y = 0; y < h_src; y++) {
35                 for (x = 0; x < w_src; x++) {
36                         unsigned int src_x = x_src + x;
37                         unsigned int src_y = y_src + y;
38                         unsigned int dst_x = x_dst + x;
39                         unsigned int dst_y = y_dst + y;
41                         gp_pixel pix = gp_getpixel_raw_{{ pt.pixelsize.suffix }}(src, src_x, src_y);
43 @         for c in pt.chanslist:
44                         {{ c.name }} = GP_PIXEL_GET_{{ c[0] }}_{{ pt.name }}(pix);
45                         {{ c.name }} = tables->table[{{ c.idx }}][{{ c.name }}];
46 @         end
48                         pix = GP_PIXEL_CREATE_{{ pt.name }}({{ arr_to_params(pt.chan_names) }});
49                         gp_putpixel_raw_{{ pt.pixelsize.suffix }}(dst, dst_x, dst_y, pix);
50                 }
52                 if (gp_progress_cb_report(callback, y, h_src, w_src)) {
53                         errno = ECANCELED;
54                         return 1;
55                 }
56         }
58         gp_progress_cb_done(callback);
60         return 0;
63 @ end
65 int gp_filter_tables_apply(const gp_pixmap *const src,
66                            gp_coord x_src, gp_coord y_src,
67                            gp_size w_src, gp_size h_src,
68                            gp_pixmap *dst,
69                            gp_coord x_dst, gp_coord y_dst,
70                            const gp_filter_tables *const tables,
71                            gp_progress_cb *callback)
73         GP_ASSERT(src->pixel_type == dst->pixel_type);
74         //TODO: Assert size
76         switch (src->pixel_type) {
77 @ for pt in pixeltypes:
78 @     if not pt.is_unknown() and not pt.is_palette():
79         case GP_PIXEL_{{ pt.name }}:
80                 return apply_tables_{{ pt.name }}(src, x_src, y_src,
81                                                   w_src, h_src, dst,
82                                                   x_dst, y_dst,
83                                                   tables, callback);
84         break;
85 @ end
86         default:
87                 errno = EINVAL;
88                 return -1;
89         }