diff --git a/src/scode.c b/src/scode.c index c1506b7..b2f459a 100644 --- a/src/scode.c +++ b/src/scode.c @@ -24,7 +24,7 @@ char *decode_scode(struct image *img) char *result; int stats[3 * 256]; int x, y, i, incell = 0, cur = 0, xmin = 0; - int r, g, b; + int r, g, b, r2, g2, b2; struct image *tmp1; /* allocate enough place */ @@ -33,23 +33,31 @@ char *decode_scode(struct image *img) tmp1 = image_dup(img); /* Remove border */ + getpixel(img, 0, 0, &r2, &g2, &b2); 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++) + if(r != r2 || g != g2 || b != b2) { - setpixel(tmp1, x, 0, r, g, b); - setpixel(tmp1, x, img->height - 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 < 3 * 256; i++) stats[i] = 0; + /* Set (0, 0) colour to background */ + stats[r2 + g2 + b2] = 1; + for(y = 0; y < 6; y++) { int y2 = (y & 1) ? img->width - 1 - y / 2 : y / 2;