fix an unsigned comparison when converting character code to a glyph index with a...
[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   i_img_dim x, y;
21   int chan;
22   i_color c;
23   int count = 0;
24
25   for (x = 0; x < im->xsize; ++x) {
26     for (y = 0; y < im->ysize; ++y) {
27       int match = 1;
28       i_gpix(im, x, y, &c);
29       for (chan = 0; chan < im->channels; ++chan) {
30         if (c.channel[chan] != color->channel[chan]) {
31           match = 0;
32           break;
33         }
34       }
35       if (match) ++count;
36     }
37   }
38
39   return count;
40 }
41
42 MODULE = Imager::CountColor   PACKAGE = Imager::CountColor
43
44 PROTOTYPES: ENABLE
45
46 int
47 count_color(im, color)
48         Imager::ImgRaw im
49         Imager::Color color
50
51 BOOT:
52         PERL_INITIALIZE_IMAGER_CALLBACKS;
53