Commit | Line | Data |
---|---|---|
92bda632 | 1 | #include "imager.h" |
02d1d628 AMH |
2 | #include "regmach.h" |
3 | ||
bf94b653 TC |
4 | /* |
5 | =head1 NAME | |
6 | ||
7 | trans2.c - entry point for the general transformation engine | |
8 | ||
9 | =head1 SYNOPSIS | |
10 | ||
11 | int width, height, channels; | |
12 | struct rm_ops *ops; | |
13 | int op_count; | |
14 | double *n_regs; | |
15 | int n_regs_count; | |
16 | i_color *c_regs; | |
17 | int c_regs_count; | |
18 | i_img **in_imgs; | |
19 | int in_imgs_count; | |
20 | i_img *result = transform2(width, height, channels, ops, ops_count, | |
21 | n_regs, n_regs_count, c_regs, c_regs_count, | |
22 | in_imgs, in_imgs_count); | |
23 | ||
24 | =head1 DESCRIPTION | |
25 | ||
26 | This (short) file implements the transform2() function, just iterating | |
27 | over the image - most of the work is done in L<regmach.c> | |
28 | ||
29 | =cut | |
30 | */ | |
3bb1c1f3 | 31 | |
8d14daab | 32 | i_img* i_transform2(i_img_dim width, i_img_dim height, int channels, |
02d1d628 AMH |
33 | struct rm_op *ops, int ops_count, |
34 | double *n_regs, int n_regs_count, | |
35 | i_color *c_regs, int c_regs_count, | |
36 | i_img **in_imgs, int in_imgs_count) | |
37 | { | |
38 | i_img *new_img; | |
8d14daab | 39 | i_img_dim x, y; |
02d1d628 AMH |
40 | i_color val; |
41 | int i; | |
bf94b653 TC |
42 | int need_images; |
43 | ||
44 | i_clear_error(); | |
02d1d628 AMH |
45 | |
46 | /* since the number of images is variable and the image numbers | |
47 | for getp? are fixed, we can check them here instead of in the | |
48 | register machine - this will help performance */ | |
bf94b653 | 49 | need_images = 0; |
02d1d628 AMH |
50 | for (i = 0; i < ops_count; ++i) { |
51 | switch (ops[i].code) { | |
52 | case rbc_getp1: | |
53 | case rbc_getp2: | |
54 | case rbc_getp3: | |
bf94b653 TC |
55 | if (ops[i].code - rbc_getp1 + 1 > need_images) { |
56 | need_images = ops[i].code - rbc_getp1 + 1; | |
02d1d628 AMH |
57 | } |
58 | } | |
59 | } | |
bf94b653 TC |
60 | |
61 | if (need_images > in_imgs_count) { | |
62 | i_push_errorf(0, "not enough images, code requires %d, %d supplied", | |
63 | need_images, in_imgs_count); | |
64 | return NULL; | |
65 | } | |
02d1d628 AMH |
66 | |
67 | new_img = i_img_empty_ch(NULL, width, height, channels); | |
68 | for (x = 0; x < width; ++x) { | |
69 | for (y = 0; y < height; ++y) { | |
70 | n_regs[0] = x; | |
71 | n_regs[1] = y; | |
b33c08f8 | 72 | val = i_rm_run(ops, ops_count, n_regs, n_regs_count, c_regs, c_regs_count, |
02d1d628 AMH |
73 | in_imgs, in_imgs_count); |
74 | i_ppix(new_img, x, y, &val); | |
75 | } | |
76 | } | |
77 | ||
78 | return new_img; | |
79 | } | |
bf94b653 TC |
80 | |
81 | /* | |
82 | =head1 AUTHOR | |
83 | ||
84 | Tony Cook <tony@develop-help.com> | |
85 | ||
86 | =head1 SEE ALSO | |
87 | ||
88 | Imager(3), regmach.c | |
89 | ||
90 | =cut | |
91 | */ |