diff --git a/src/common.h b/src/common.h index 5c8e0d1..2544be5 100644 --- a/src/common.h +++ b/src/common.h @@ -45,4 +45,5 @@ struct image *filter_trick(struct image *img); struct image *filter_smooth(struct image *img); struct image *filter_median(struct image *img); struct image *filter_contrast(struct image *img); +int filter_count(struct image *img); diff --git a/src/filters.c b/src/filters.c index 126ad05..4cf1cd8 100644 --- a/src/filters.c +++ b/src/filters.c @@ -329,3 +329,25 @@ struct image *filter_contrast(struct image *img) return dst; } +int filter_count(struct image *img) +{ + int histo[256]; + int x, y, i, count = 0; + int r, g, b; + + for(i = 0; i < 256; i++) + histo[i] = 0; + + for(y = 0; y < img->height; y++) + for(x = 0; x < img->width; x++) + { + getgray(img, x, y, &r); + histo[r] = 1; + } + + for(i = 0; i < 256; i++) + count += histo[i]; + + return count; +} + diff --git a/src/main.c b/src/main.c index 46f9129..beebc0c 100644 --- a/src/main.c +++ b/src/main.c @@ -108,6 +108,7 @@ int main(int argc, char *argv[]) { char *input = argv[optind], *result; struct image *img; + int count; img = image_load(argv[optind]); if(!img) @@ -117,7 +118,9 @@ int main(int argc, char *argv[]) continue; } - dprintf("image size %ix%i\n", img->width, img->height); + count = filter_count(img); + dprintf("image size %ix%i, %i colours\n", + img->width, img->height, count); if(!strcmp(mode, "test")) result = decode_test(img); @@ -134,7 +137,8 @@ int main(int argc, char *argv[]) dprintf("autodetecting phpBB captcha\n"); result = decode_phpbb(img); } - else if(img->height == 25 || img->height == 30) + else if((img->height == 25 || img->height == 30) + && count < 10) { dprintf("autodetecting scode captcha\n"); result = decode_scode(img);