Changeset 387 for pwntcha


Ignore:
Timestamp:
Jan 3, 2005, 4:29:46 PM (16 years ago)
Author:
Sam Hocevar
Message:
  • renamed a few functions
Location:
pwntcha/trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • pwntcha/trunk/src/common.h

    r385 r387  
    1919
    2020/* available CAPTCHA decoders */
    21 char * slashdot_decode(char *image);
     21char * decode_slashdot(struct image *img);
    2222
    2323/* image operations */
    24 struct image * load_image(char *name);
    25 struct image * new_image(int width, int height);
     24struct image * image_load(char *name);
     25struct image * image_new(int width, int height);
    2626int getgray(struct image *img, int x, int y, int *g);
    2727int getpixel(struct image *img, int x, int y, int *r, int *g, int *b);
     
    2929
    3030/* image filters */
    31 void flood_fill(struct image *img, int x, int y, int r, int g, int b);
    32 struct image *fill_holes(struct image *img);
    33 struct image *detect_lines(struct image *img);
    34 struct image *equalize(struct image *img);
    35 struct image *trick(struct image *img);
    36 struct image *smooth(struct image *img);
    37 struct image *median(struct image *img);
     31void filter_flood_fill(struct image *img, int x, int y, int r, int g, int b);
     32struct image *filter_fill_holes(struct image *img);
     33struct image *filter_detect_lines(struct image *img);
     34struct image *filter_equalize(struct image *img);
     35struct image *filter_trick(struct image *img);
     36struct image *filter_smooth(struct image *img);
     37struct image *filter_median(struct image *img);
    3838
  • pwntcha/trunk/src/filters.c

    r385 r387  
    2525
    2626/* Functions */
    27 void flood_fill(struct image *img, int x, int y, int r, int g, int b)
     27void filter_flood_fill(struct image *img, int x, int y, int r, int g, int b)
    2828{
    2929    int oldr, oldg, oldb;
     
    3838    getpixel(img, x + 1, y, &nextr, &nextg, &nextb);
    3939    if(nextr == oldr && nextg == oldg && nextb == oldb)
    40         flood_fill(img, x + 1, y, r, g, b);
     40        filter_flood_fill(img, x + 1, y, r, g, b);
    4141
    4242    getpixel(img, x - 1, y, &nextr, &nextg, &nextb);
    4343    if(nextr == oldr && nextg == oldg && nextb == oldb)
    44         flood_fill(img, x - 1, y, r, g, b);
     44        filter_flood_fill(img, x - 1, y, r, g, b);
    4545
    4646    getpixel(img, x, y + 1, &nextr, &nextg, &nextb);
    4747    if(nextr == oldr && nextg == oldg && nextb == oldb)
    48         flood_fill(img, x, y + 1, r, g, b);
     48        filter_flood_fill(img, x, y + 1, r, g, b);
    4949
    5050    getpixel(img, x, y - 1, &nextr, &nextg, &nextb);
    5151    if(nextr == oldr && nextg == oldg && nextb == oldb)
    52         flood_fill(img, x, y - 1, r, g, b);
    53 }
    54 
    55 struct image *fill_holes(struct image *img)
     52        filter_flood_fill(img, x, y - 1, r, g, b);
     53}
     54
     55struct image *filter_fill_holes(struct image *img)
    5656{
    5757    struct image *dst;
     
    5959    int r, g, b;
    6060
    61     dst = new_image(img->width, img->height);
     61    dst = image_new(img->width, img->height);
    6262
    6363    for(y = 0; y < img->height; y++)
     
    103103}
    104104
    105 struct image *detect_lines(struct image *img)
     105struct image *filter_detect_lines(struct image *img)
    106106{
    107107    struct image *dst;
     
    109109    int r, ra, rb, g, b;
    110110
    111     dst = new_image(img->width, img->height);
     111    dst = image_new(img->width, img->height);
    112112
    113113    /* Remove white lines */
     
    143143}
    144144
    145 struct image *equalize(struct image *img)
     145struct image *filter_equalize(struct image *img)
    146146{
    147147    struct image *dst;
     
    149149    int r, g, b;
    150150
    151     dst = new_image(img->width, img->height);
     151    dst = image_new(img->width, img->height);
    152152
    153153    for(y = 0; y < img->height; y++)
     
    162162}
    163163
    164 struct image *trick(struct image *img)
     164struct image *filter_trick(struct image *img)
    165165{
    166166#define TSIZE 3
     
    169169    int r, g, b;
    170170
    171     dst = new_image(img->width, img->height);
     171    dst = image_new(img->width, img->height);
    172172
    173173    for(y = 0; y < img->height; y++)
     
    208208}
    209209
    210 struct image *smooth(struct image *img)
     210struct image *filter_smooth(struct image *img)
    211211{
    212212#define SSIZE 3
     
    215215    int r, g, b;
    216216
    217     dst = new_image(img->width, img->height);
     217    dst = image_new(img->width, img->height);
    218218
    219219    for(y = 0; y < img->height; y++)
     
    239239}
    240240
    241 struct image *median(struct image *img)
     241struct image *filter_median(struct image *img)
    242242{
    243243#define MSIZE 4
     
    246246    int r, g, b;
    247247
    248     dst = new_image(img->width, img->height);
     248    dst = image_new(img->width, img->height);
    249249
    250250    for(y = 0; y < img->height; y++)
  • pwntcha/trunk/src/image.c

    r383 r387  
    2525#endif
    2626
    27 struct image * load_image(char *name)
     27struct image * image_load(char *name)
    2828{
    2929    struct image * img;
     
    5757}
    5858
    59 struct image * new_image(int width, int height)
     59struct image * image_new(int width, int height)
    6060{
    6161    struct image * img;
     
    131131}
    132132
    133 void display_image(struct image *img)
     133void image_display(struct image *img)
    134134{
    135135#if defined(HAVE_IMLIB2_H)
  • pwntcha/trunk/src/main.c

    r383 r387  
    1818int main(int argc, char *argv[])
    1919{
     20    struct image *img;
    2021    char *result;
    2122
     
    2627    }
    2728
    28     result = slashdot_decode(argv[1]);
     29    img = image_load(argv[1]);
     30    if(!img)
     31    {
     32        fprintf(stderr, "cannot load %s\n", argv[1]);
     33        return -1;
     34    }
     35
     36    result = decode_slashdot(img);
    2937    if(!result)
     38    {
     39        fprintf(stderr, "sorry, decoding failed\n");
    3040        return -1;
     41    }
    3142
    3243    printf("%s\n", result);
  • pwntcha/trunk/src/slashdot.c

    r386 r387  
    3535
    3636/* Main function */
    37 char * slashdot_decode(char *image)
    38 {
    39     struct image *img, *tmp, *tmp2;
    40 
    41     img = load_image(image);
    42     if(img == NULL)
    43         return NULL;
     37char * decode_slashdot(struct image *img)
     38{
     39    struct image *tmp, *tmp2;
    4440
    4541    /* Slashdot captchas have 7 characters */
     
    4743
    4844    /* Clean image a bit */
    49     tmp = detect_lines(img);
    50     tmp = fill_holes(tmp);
     45    tmp = filter_detect_lines(img);
     46    tmp = filter_fill_holes(tmp);
    5147
    5248    /* Detect small objects to guess image orientation */
    53     tmp2 = median(tmp);
    54     tmp2 = equalize(tmp2);
     49    tmp2 = filter_median(tmp);
     50    tmp2 = filter_equalize(tmp2);
    5551    count_objects(tmp2);
    5652
    5753    /* Invert rotation and find glyphs */
    5854    tmp = rotate(tmp);
    59     tmp = median(tmp);
     55    tmp = filter_median(tmp);
    6056    tmp = find_glyphs(tmp);
    6157
     
    7268    int r, g, b;
    7369
    74     dst = new_image(img->width, img->height);
     70    dst = image_new(img->width, img->height);
    7571
    7672    for(y = 0; y < img->height; y++)
     
    9187                {
    9288                    gotblack = 1;
    93                     flood_fill(dst, x, y, 255 - objects, 0, 0);
     89                    filter_flood_fill(dst, x, y, 255 - objects, 0, 0);
    9490                    objects++;
    9591                }
     
    120116                first = i;
    121117            last = i;
    122             flood_fill(dst, objlist[i].xmin, objlist[i].ymin, 0, 0, 255);
     118            filter_flood_fill(dst, objlist[i].xmin, objlist[i].ymin, 0, 0, 255);
    123119        }
    124120    }
     
    154150    }
    155151
    156     dst = new_image(img->width * FACTOR, img->height * FACTOR);
     152    dst = image_new(img->width * FACTOR, img->height * FACTOR);
    157153
    158154    for(y = 0; y < img->height * FACTOR; y++)
     
    187183    int r, g, b;
    188184
    189     dst = new_image(img->width, img->height);
     185    dst = image_new(img->width, img->height);
    190186
    191187    for(y = 0; y < img->height; y++)
     
    222218    glyphs[22];
    223219    struct image *dst;
    224     struct image *font = load_image(FONTNAME);
     220    struct image *font = image_load(FONTNAME);
    225221    int x, y, i = 0;
    226222    int r, g, b;
     
    234230    }
    235231
    236     dst = new_image(img->width, img->height);
     232    dst = image_new(img->width, img->height);
    237233
    238234    for(y = 0; y < img->height; y++)
Note: See TracChangeset for help on using the changeset viewer.