Changeset 423 for pwntcha


Ignore:
Timestamp:
Jan 5, 2005, 6:02:53 PM (18 years ago)
Author:
Sam Hocevar
Message:
  • fixed a bug in scode.c that was missing bottom lines
  • work with colour images
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pwntcha/trunk/src/scode.c

    r409 r423  
    2323{
    2424    char *result;
    25     int stats[256];
     25    int stats[3 * 256];
    2626    int x, y, i, incell = 0, cur = 0, xmin = 0;
    2727    int r, g, b;
     
    3030    /* allocate enough place */
    3131    result = malloc(1024 * sizeof(char));
     32
     33    tmp1 = filter_dup(img);
     34
     35    /* Remove border */
     36    getpixel(img, 1, 1, &r, &g, &b);
     37    for(y = 0; y < img->height; y++)
     38    {
     39        setpixel(tmp1, 0, y, r, g, b);
     40        setpixel(tmp1, img->width - 1, y, r, g, b);
     41    }
     42
     43    for(x = 0; x < img->width; x++)
     44    {
     45        setpixel(tmp1, x, 0, r, g, b);
     46        setpixel(tmp1, x, img->height - 1, r, g, b);
     47    }
    3248
    3349    /* Detect background: first and last 3 lines */
     
    3854        for(x = 0; x < img->width; x++)
    3955        {
    40             getpixel(img, x, y, &r, &g, &b);
    41             stats[r]++;
    42             getpixel(img, x, img->width - 1 - y, &r, &g, &b);
    43             stats[r]++;
     56            getpixel(tmp1, x, y, &r, &g, &b);
     57            stats[r + g + b]++;
     58            getpixel(tmp1, x, img->height - 1 - y, &r, &g, &b);
     59            stats[r + g + b]++;
    4460        }
    4561
    4662    /* Set non-background colours to 0 */
    47     tmp1 = image_new(img->width, img->height);
    48 
    4963    for(y = 0; y < img->height; y++)
    5064        for(x = 0; x < img->width; x++)
    5165        {
    52             getpixel(img, x, y, &r, &g, &b);
    53             if(stats[r])
     66            getpixel(tmp1, x, y, &r, &g, &b);
     67            if(stats[r + g + b])
    5468                setpixel(tmp1, x, y, 255, 255, 255);
    5569            else
Note: See TracChangeset for help on using the changeset viewer.