]> git.imager.perl.org - imager.git/blob - CountColor/CountColor.xs
t1 no longer needs a type check
[imager.git] / CountColor / CountColor.xs
1 #define PERL_NO_GET_CONTEXT
2 #ifdef __cplusplus
3 extern "C" {
4 #endif
5 #include "EXTERN.h"
6 #include "perl.h"
7 #include "XSUB.h"
8 #include "ppport.h"
9 #ifdef __cplusplus
10 }
11 #endif
12
13 #include "imext.h"
14 #include "imperl.h"
15
16 DEFINE_IMAGER_CALLBACKS;
17
18 int
19 count_color(i_img *im, i_color *color) {
20   int x, y, chan;
21   i_color c;
22   int count = 0;
23
24   for (x = 0; x < im->xsize; ++x) {
25     for (y = 0; y < im->ysize; ++y) {
26       int match = 1;
27       i_gpix(im, x, y, &c);
28       for (chan = 0; chan < im->channels; ++chan) {
29         if (c.channel[chan] != color->channel[chan]) {
30           match = 0;
31           break;
32         }
33       }
34       if (match) ++count;
35     }
36   }
37
38   return count;
39 }
40
41 MODULE = Imager::CountColor   PACKAGE = Imager::CountColor
42
43 PROTOTYPES: ENABLE
44
45 int
46 count_color(im, color)
47         Imager::ImgRaw im
48         Imager::Color color
49
50 BOOT:
51         PERL_INITIALIZE_IMAGER_CALLBACKS;
52