From 82ff5808945b6641a0d8e6dd73c7c2fa7727832f Mon Sep 17 00:00:00 2001 From: sam Date: Tue, 4 Jan 2005 02:59:22 +0000 Subject: [PATCH] * print colour count in debug messages git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/pwntcha/trunk@402 92316355-f0b4-4df1-b90c-862c8a59935f --- src/common.h | 1 + src/filters.c | 22 ++++++++++++++++++++++ src/main.c | 8 ++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) 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);