You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

93 line
2.3 KiB

  1. /*
  2. * java.c: decode java captchas I forgot about
  3. * $Id$
  4. *
  5. * Copyright: (c) 2005 Sam Hocevar <sam@zoy.org>
  6. * This program is free software. It comes without any warranty, to
  7. * the extent permitted by applicable law. You can redistribute it
  8. * and/or modify it under the terms of the Do What The Fuck You Want
  9. * To Public License, Version 2, as published by Sam Hocevar. See
  10. * http://sam.zoy.org/wtfpl/COPYING for more details.
  11. */
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <limits.h>
  16. #include "config.h"
  17. #include "common.h"
  18. /* Main function */
  19. char *decode_java(struct image *img)
  20. {
  21. struct image *tmp;
  22. int x, y, dx, dy, best = 0, bestx, besty;
  23. int r, g, b, r2, g2, b2, r3, g3, b3, r4, g4, b4, i, j, c;
  24. tmp = image_dup(img);
  25. filter_threshold(tmp, 245);
  26. for(dy = 0; dy < 20; dy++)
  27. {
  28. if(dy > -5 && dy < 5)
  29. continue;
  30. for(dx = -20; dx < 20; dx++)
  31. {
  32. int good = 0;
  33. if(dx > -5 && dx < 5)
  34. continue;
  35. for(y = 0; y < tmp->height - dy; y++)
  36. {
  37. for(x = 0; x < tmp->width; x++)
  38. {
  39. getpixel(tmp, x, y, &r, &g, &b);
  40. getpixel(tmp, x + dx, y + dy, &r2, &g2, &b2);
  41. if(r && r2)
  42. good++;
  43. }
  44. }
  45. if(good > best)
  46. {
  47. best = good;
  48. bestx = dx;
  49. besty = dy;
  50. }
  51. }
  52. }
  53. for(y = 0; y < tmp->height - besty; y++)
  54. {
  55. for(x = 0; x < tmp->width; x++)
  56. {
  57. getpixel(tmp, x, y, &r, &g, &b);
  58. getpixel(tmp, x + bestx, y + besty, &r2, &g2, &b2);
  59. getpixel(tmp, x - bestx, y - besty, &r3, &g3, &b3);
  60. getpixel(tmp, x + 2 * bestx, y + 2 * besty, &r4, &g4, &b4);
  61. if(r && r2)
  62. {
  63. if(r3 && r4)
  64. setpixel(img, x, y, 0, 127, 0);
  65. else
  66. setpixel(img, x, y, 0, 255, 255);
  67. }
  68. else if(r)
  69. setpixel(img, x, y, 0, 0, 127);
  70. else
  71. setpixel(img, x, y, 0, 0, 0);
  72. }
  73. }
  74. image_save(img, "test.bmp");
  75. image_free(tmp);
  76. return NULL;
  77. }