| 1 |
|
| #include "imager.h" |
| 2 |
|
| #include "regmach.h" |
| 3 |
|
| |
| 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 |
|
| */ |
| 31 |
|
| |
| 32 |
28 |
| i_img* i_transform2(i_img_dim width, i_img_dim height, int channels, |
| 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; |
| 39 |
|
| i_img_dim x, y; |
| 40 |
|
| i_color val; |
| 41 |
|
| int i; |
| 42 |
|
| int need_images; |
| 43 |
|
| |
| 44 |
28 |
| i_clear_error(); |
| 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 */ |
| 49 |
28 |
| need_images = 0; |
| 50 |
207 |
▶ | for (i = 0; i < ops_count; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < ops_count; ++i) { |
179 |
28 |
207 |
|
| 51 |
179 |
▶ | switch (ops[i].code) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch (ops[i].code) { |
19 |
160 |
179 |
|
| 52 |
19 |
| case rbc_getp1: |
| 53 |
|
| case rbc_getp2: |
| 54 |
|
| case rbc_getp3: |
| 55 |
19 |
▶ | if (ops[i].code - rbc_getp1 + 1 > need_images) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ops[i].code - rbc_getp1 + 1 > need_images) { |
18 |
1 |
19 |
|
| 56 |
18 |
| need_images = ops[i].code - rbc_getp1 + 1; |
| 57 |
|
| } |
| 58 |
|
| } |
| 59 |
|
| } |
| 60 |
|
| |
| 61 |
28 |
▶ | if (need_images > in_imgs_count) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (need_images > in_imgs_count) { |
1 |
27 |
28 |
|
| 62 |
1 |
| i_push_errorf(0, "not enough images, code requires %d, %d supplied", |
| 63 |
|
| need_images, in_imgs_count); |
| 64 |
1 |
| return NULL; |
| 65 |
|
| } |
| 66 |
|
| |
| 67 |
|
| /* FIXME: add a validation check for the supplied ops vs |
| 68 |
|
| the supplied registers and a return op |
| 69 |
|
| */ |
| 70 |
|
| |
| 71 |
27 |
| new_img = i_img_8_new(width, height, channels); |
| 72 |
891 |
▶ | for (x = 0; x < width; ++x) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (x = 0; x < width; ++x) { |
864 |
27 |
891 |
|
| 73 |
181946 |
▶ | for (y = 0; y < height; ++y) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (y = 0; y < height; ++y) { |
181082 |
864 |
181946 |
|
| 74 |
181082 |
| n_regs[0] = x; |
| 75 |
181082 |
| n_regs[1] = y; |
| 76 |
181082 |
| val = i_rm_run(ops, ops_count, n_regs, n_regs_count, c_regs, c_regs_count, |
| 77 |
|
| in_imgs, in_imgs_count); |
| 78 |
181082 |
| i_ppix(new_img, x, y, &val); |
| 79 |
|
| } |
| 80 |
|
| } |
| 81 |
|
| |
| 82 |
27 |
| return new_img; |
| 83 |
|
| } |
| 84 |
|
| |
| 85 |
|
| /* |
| 86 |
|
| =head1 AUTHOR |
| 87 |
|
| |
| 88 |
|
| Tony Cook <tony@develop-help.com> |
| 89 |
|
| |
| 90 |
|
| =head1 SEE ALSO |
| 91 |
|
| |
| 92 |
|
| Imager(3), regmach.c |
| 93 |
|
| |
| 94 |
|
| =cut |
| 95 |
|
| */ |