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