- Timestamp:
- Jan 3, 2005, 4:29:46 PM (18 years ago)
- Location:
- pwntcha/trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
pwntcha/trunk/src/common.h
r385 r387 19 19 20 20 /* available CAPTCHA decoders */ 21 char * slashdot_decode(char *image);21 char * decode_slashdot(struct image *img); 22 22 23 23 /* image operations */ 24 struct image * load_image(char *name);25 struct image * new_image(int width, int height);24 struct image * image_load(char *name); 25 struct image * image_new(int width, int height); 26 26 int getgray(struct image *img, int x, int y, int *g); 27 27 int getpixel(struct image *img, int x, int y, int *r, int *g, int *b); … … 29 29 30 30 /* image filters */ 31 void f lood_fill(struct image *img, int x, int y, int r, int g, int b);32 struct image *fil l_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);31 void filter_flood_fill(struct image *img, int x, int y, int r, int g, int b); 32 struct image *filter_fill_holes(struct image *img); 33 struct image *filter_detect_lines(struct image *img); 34 struct image *filter_equalize(struct image *img); 35 struct image *filter_trick(struct image *img); 36 struct image *filter_smooth(struct image *img); 37 struct image *filter_median(struct image *img); 38 38 -
pwntcha/trunk/src/filters.c
r385 r387 25 25 26 26 /* Functions */ 27 void f lood_fill(struct image *img, int x, int y, int r, int g, int b)27 void filter_flood_fill(struct image *img, int x, int y, int r, int g, int b) 28 28 { 29 29 int oldr, oldg, oldb; … … 38 38 getpixel(img, x + 1, y, &nextr, &nextg, &nextb); 39 39 if(nextr == oldr && nextg == oldg && nextb == oldb) 40 f lood_fill(img, x + 1, y, r, g, b);40 filter_flood_fill(img, x + 1, y, r, g, b); 41 41 42 42 getpixel(img, x - 1, y, &nextr, &nextg, &nextb); 43 43 if(nextr == oldr && nextg == oldg && nextb == oldb) 44 f lood_fill(img, x - 1, y, r, g, b);44 filter_flood_fill(img, x - 1, y, r, g, b); 45 45 46 46 getpixel(img, x, y + 1, &nextr, &nextg, &nextb); 47 47 if(nextr == oldr && nextg == oldg && nextb == oldb) 48 f lood_fill(img, x, y + 1, r, g, b);48 filter_flood_fill(img, x, y + 1, r, g, b); 49 49 50 50 getpixel(img, x, y - 1, &nextr, &nextg, &nextb); 51 51 if(nextr == oldr && nextg == oldg && nextb == oldb) 52 f lood_fill(img, x, y - 1, r, g, b);53 } 54 55 struct image *fil l_holes(struct image *img)52 filter_flood_fill(img, x, y - 1, r, g, b); 53 } 54 55 struct image *filter_fill_holes(struct image *img) 56 56 { 57 57 struct image *dst; … … 59 59 int r, g, b; 60 60 61 dst = new_image(img->width, img->height);61 dst = image_new(img->width, img->height); 62 62 63 63 for(y = 0; y < img->height; y++) … … 103 103 } 104 104 105 struct image * detect_lines(struct image *img)105 struct image *filter_detect_lines(struct image *img) 106 106 { 107 107 struct image *dst; … … 109 109 int r, ra, rb, g, b; 110 110 111 dst = new_image(img->width, img->height);111 dst = image_new(img->width, img->height); 112 112 113 113 /* Remove white lines */ … … 143 143 } 144 144 145 struct image * equalize(struct image *img)145 struct image *filter_equalize(struct image *img) 146 146 { 147 147 struct image *dst; … … 149 149 int r, g, b; 150 150 151 dst = new_image(img->width, img->height);151 dst = image_new(img->width, img->height); 152 152 153 153 for(y = 0; y < img->height; y++) … … 162 162 } 163 163 164 struct image * trick(struct image *img)164 struct image *filter_trick(struct image *img) 165 165 { 166 166 #define TSIZE 3 … … 169 169 int r, g, b; 170 170 171 dst = new_image(img->width, img->height);171 dst = image_new(img->width, img->height); 172 172 173 173 for(y = 0; y < img->height; y++) … … 208 208 } 209 209 210 struct image * smooth(struct image *img)210 struct image *filter_smooth(struct image *img) 211 211 { 212 212 #define SSIZE 3 … … 215 215 int r, g, b; 216 216 217 dst = new_image(img->width, img->height);217 dst = image_new(img->width, img->height); 218 218 219 219 for(y = 0; y < img->height; y++) … … 239 239 } 240 240 241 struct image * median(struct image *img)241 struct image *filter_median(struct image *img) 242 242 { 243 243 #define MSIZE 4 … … 246 246 int r, g, b; 247 247 248 dst = new_image(img->width, img->height);248 dst = image_new(img->width, img->height); 249 249 250 250 for(y = 0; y < img->height; y++) -
pwntcha/trunk/src/image.c
r383 r387 25 25 #endif 26 26 27 struct image * load_image(char *name)27 struct image * image_load(char *name) 28 28 { 29 29 struct image * img; … … 57 57 } 58 58 59 struct image * new_image(int width, int height)59 struct image * image_new(int width, int height) 60 60 { 61 61 struct image * img; … … 131 131 } 132 132 133 void display_image(struct image *img)133 void image_display(struct image *img) 134 134 { 135 135 #if defined(HAVE_IMLIB2_H) -
pwntcha/trunk/src/main.c
r383 r387 18 18 int main(int argc, char *argv[]) 19 19 { 20 struct image *img; 20 21 char *result; 21 22 … … 26 27 } 27 28 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); 29 37 if(!result) 38 { 39 fprintf(stderr, "sorry, decoding failed\n"); 30 40 return -1; 41 } 31 42 32 43 printf("%s\n", result); -
pwntcha/trunk/src/slashdot.c
r386 r387 35 35 36 36 /* 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; 37 char * decode_slashdot(struct image *img) 38 { 39 struct image *tmp, *tmp2; 44 40 45 41 /* Slashdot captchas have 7 characters */ … … 47 43 48 44 /* Clean image a bit */ 49 tmp = detect_lines(img);50 tmp = fil l_holes(tmp);45 tmp = filter_detect_lines(img); 46 tmp = filter_fill_holes(tmp); 51 47 52 48 /* 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); 55 51 count_objects(tmp2); 56 52 57 53 /* Invert rotation and find glyphs */ 58 54 tmp = rotate(tmp); 59 tmp = median(tmp);55 tmp = filter_median(tmp); 60 56 tmp = find_glyphs(tmp); 61 57 … … 72 68 int r, g, b; 73 69 74 dst = new_image(img->width, img->height);70 dst = image_new(img->width, img->height); 75 71 76 72 for(y = 0; y < img->height; y++) … … 91 87 { 92 88 gotblack = 1; 93 f lood_fill(dst, x, y, 255 - objects, 0, 0);89 filter_flood_fill(dst, x, y, 255 - objects, 0, 0); 94 90 objects++; 95 91 } … … 120 116 first = i; 121 117 last = i; 122 f lood_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); 123 119 } 124 120 } … … 154 150 } 155 151 156 dst = new_image(img->width * FACTOR, img->height * FACTOR);152 dst = image_new(img->width * FACTOR, img->height * FACTOR); 157 153 158 154 for(y = 0; y < img->height * FACTOR; y++) … … 187 183 int r, g, b; 188 184 189 dst = new_image(img->width, img->height);185 dst = image_new(img->width, img->height); 190 186 191 187 for(y = 0; y < img->height; y++) … … 222 218 glyphs[22]; 223 219 struct image *dst; 224 struct image *font = load_image(FONTNAME);220 struct image *font = image_load(FONTNAME); 225 221 int x, y, i = 0; 226 222 int r, g, b; … … 234 230 } 235 231 236 dst = new_image(img->width, img->height);232 dst = image_new(img->width, img->height); 237 233 238 234 for(y = 0; y < img->height; y++)
Note: See TracChangeset
for help on using the changeset viewer.