version 0.3.18
[fms.git] / src / freenet / captcha / alternatecaptcha2.cpp
index 08cbdd6..f63d525 100644 (file)
@@ -5,6 +5,7 @@
 \r
 #include <cmath>\r
 #include <vector>\r
+#include <cstdlib>\r
 \r
 #ifdef ALTERNATE_CAPTCHA\r
 \r
@@ -16,6 +17,11 @@ AlternateCaptcha2::AlternateCaptcha2()
 \r
 void AlternateCaptcha2::Generate()\r
 {\r
+       if(m_fonts.size()==0)\r
+       {\r
+               return;\r
+       }\r
+\r
        std::string puzzlestring=GenerateRandomString(6);\r
        std::vector<int> fontnums(puzzlestring.size(),0);\r
        \r
@@ -42,9 +48,9 @@ void AlternateCaptcha2::Generate()
        for(int i=0; i<numlines; i++)\r
        {\r
                int x1=rand()%150;\r
-               int y1=(rand()%100)+100;\r
+               int y1=(rand()%80)+110;\r
                int x2=(rand()%150)+150;\r
-               int y2=(rand()%100)+100;\r
+               int y2=(rand()%80)+110;\r
                bigbmp.Line(x1,y1,x2,y2,white);\r
                bigbmp.Line(x1+1,y1,x2+1,y2,white);\r
        }\r
@@ -61,14 +67,14 @@ void AlternateCaptcha2::Generate()
        // rotate and skew the big bitmap a few times\r
        int lastrot=0;\r
        int thisrot=0;\r
-       int numrots=(rand()%4)+4;\r
+       int numrots=(rand()%3)+4;\r
        for(int i=0; i<numrots; i++)\r
        {\r
                thisrot=((rand()%180)-90);\r
                bigbmp.Rotate(-lastrot+thisrot,0,0,150,150);\r
                int offset=rand()%10000;\r
-               float freq=3.0+(float(rand()%7000)/1000.0);\r
-               float amp=1.0+(float(rand()%1000)/500.0);\r
+               float freq=5.0+(float(rand()%7000)/1000.0);\r
+               float amp=1.0+(float(rand()%500)/500.0);\r
                for(int y=0; y<bigbmp.Height(); y++)\r
                {\r
                        double shift=sin((double)(y+offset)/freq)*amp;\r
@@ -78,7 +84,7 @@ void AlternateCaptcha2::Generate()
        }\r
 \r
        // rotate the big bitmap back to (almost) horizontal\r
-       bigbmp.Rotate(-lastrot+((rand()%10)-5),0,0,150,150);\r
+       bigbmp.Rotate(-lastrot+((rand()%20)-10),0,0,150,150);\r
 \r
        // grab the center of the big bitmap as the final bitmap\r
        FreeImage::Bitmap bmp(110,50,32);\r