From 21a6a717f494dc5dc265027740fd63c447da3b52 Mon Sep 17 00:00:00 2001 From: sam Date: Wed, 5 Jan 2005 17:02:53 +0000 Subject: [PATCH] * fixed a bug in scode.c that was missing bottom lines * work with colour images git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/pwntcha/trunk@423 92316355-f0b4-4df1-b90c-862c8a59935f --- src/scode.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/scode.c b/src/scode.c index 68e634b..afdd43b 100644 --- a/src/scode.c +++ b/src/scode.c @@ -22,7 +22,7 @@ static char find_glyph(struct image *img, int xmin, int xmax); char *decode_scode(struct image *img) { char *result; - int stats[256]; + int stats[3 * 256]; int x, y, i, incell = 0, cur = 0, xmin = 0; int r, g, b; struct image *tmp1; @@ -30,6 +30,22 @@ char *decode_scode(struct image *img) /* allocate enough place */ result = malloc(1024 * sizeof(char)); + tmp1 = filter_dup(img); + + /* Remove border */ + getpixel(img, 1, 1, &r, &g, &b); + for(y = 0; y < img->height; y++) + { + setpixel(tmp1, 0, y, r, g, b); + setpixel(tmp1, img->width - 1, y, r, g, b); + } + + for(x = 0; x < img->width; x++) + { + setpixel(tmp1, x, 0, r, g, b); + setpixel(tmp1, x, img->height - 1, r, g, b); + } + /* Detect background: first and last 3 lines */ for(i = 0; i < 256; i++) stats[i] = 0; @@ -37,20 +53,18 @@ char *decode_scode(struct image *img) for(y = 0; y < 3; y++) for(x = 0; x < img->width; x++) { - getpixel(img, x, y, &r, &g, &b); - stats[r]++; - getpixel(img, x, img->width - 1 - y, &r, &g, &b); - stats[r]++; + getpixel(tmp1, x, y, &r, &g, &b); + stats[r + g + b]++; + getpixel(tmp1, x, img->height - 1 - y, &r, &g, &b); + stats[r + g + b]++; } /* Set non-background colours to 0 */ - tmp1 = image_new(img->width, img->height); - for(y = 0; y < img->height; y++) for(x = 0; x < img->width; x++) { - getpixel(img, x, y, &r, &g, &b); - if(stats[r]) + getpixel(tmp1, x, y, &r, &g, &b); + if(stats[r + g + b]) setpixel(tmp1, x, y, 255, 255, 255); else setpixel(tmp1, x, y, 0, 0, 0);