#include "../../../include/freenet/captcha/easybmp/EasyBMP_Font.h"\r
#include "../../../include/freenet/captcha/easybmp/EasyBMP_Geometry.h"\r
\r
+#include <cstdlib>\r
+\r
#ifdef XMEM\r
#include <xmem.h>\r
#endif\r
void SimpleCaptcha::Generate()\r
{\r
BMP bmp;\r
- int bmpwidth=100;\r
+ int bmpwidth=110;\r
int bmpheight=50;\r
+ RGBApixel lettercols[5];\r
std::string puzzlestring;\r
std::string tempfilename=GenerateRandomString(10);\r
tempfilename+=".bmp";\r
bmp.SetSize(bmpwidth,bmpheight);\r
\r
// first draw some random lines around the bitmap\r
- int numlines=(rand()%20)+10;\r
+ int numlines=(rand()%10)+10;\r
for(int i=0; i<numlines; i++)\r
{\r
RGBApixel pixel;\r
DrawAALine(bmp,x1,y1,x2,y2,pixel);\r
}\r
\r
- // print puzzle onto bitmap\r
+ // draw some random arcs\r
+ int numarcs=(rand()%10)+10;\r
+ for(int i=0; i<numarcs; i++)\r
+ {\r
+ RGBApixel pixel;\r
+ int x1=rand()%bmpwidth;\r
+ int y1=rand()%bmpwidth;\r
+ int radius=rand()%(bmpheight/2);\r
+ double startangle=(double)(rand()%360)*(3.14159/180);\r
+ double endangle=(double)(rand()%360)*(3.14159/180);\r
+ pixel.Red=100+(rand()%150);\r
+ pixel.Green=100+(rand()%150);\r
+ pixel.Blue=100+(rand()%150);\r
+ DrawArc(bmp,x1,y1,radius,startangle,endangle,pixel);\r
+ }\r
+\r
for(int i=0; i<5; i++)\r
{\r
// keep the colors dark\r
+ lettercols[i].Red=(rand()%150);\r
+ lettercols[i].Green=(rand()%150);\r
+ lettercols[i].Blue=(rand()%150);\r
+ // draw a line with the letter color\r
+ DrawAALine(bmp,rand()%bmpwidth,rand()%bmpheight,rand()%bmpwidth,rand()%bmpheight,lettercols[i]);\r
+ }\r
+\r
+ // print puzzle onto bitmap\r
+ for(int i=0; i<5; i++)\r
+ {\r
+ PrintLetter(bmp,puzzlestring[i],5+(i*20)+(rand()%11)-5,10+(rand()%10),20,lettercols[i]);\r
+ }\r
+\r
+ /* TOO dificult to solve with this\r
+ // skew image left/right\r
+ double skew=0;\r
+ for(int yy=0; yy<bmpheight; yy++)\r
+ {\r
RGBApixel pixel;\r
- pixel.Red=(rand()%200);\r
- pixel.Green=(rand()%200);\r
- pixel.Blue=(rand()%200);\r
- PrintLetter(bmp,puzzlestring[i],5+(i*20),10+(rand()%10),20,pixel);\r
+ skew=skew+(double)((rand()%11)-5)/20.0;\r
+ int xx;\r
+ for(xx=0; xx<skew; xx++)\r
+ {\r
+ pixel.Red=255;\r
+ pixel.Green=255;\r
+ pixel.Blue=255;\r
+ bmp.SetPixel(xx,yy,pixel);\r
+ }\r
+ if(skew<0)\r
+ {\r
+ for(xx=0; xx<bmpwidth+skew; xx++)\r
+ {\r
+ pixel=bmp.GetPixel(xx-skew,yy);\r
+ bmp.SetPixel(xx,yy,pixel);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ for(xx=bmpwidth-1; xx>skew; xx--)\r
+ {\r
+ pixel=bmp.GetPixel(xx-skew,yy);\r
+ bmp.SetPixel(xx,yy,pixel);\r
+ }\r
+ }\r
+ for(xx=bmpwidth+skew; xx<bmpwidth; xx++)\r
+ {\r
+ pixel.Red=255;\r
+ pixel.Green=255;\r
+ pixel.Blue=255;\r
+ bmp.SetPixel(xx,yy,pixel);\r
+ }\r
+ }\r
+ */\r
+\r
+ // generate noise for each pixel\r
+ for(int yy=0; yy<bmpheight; yy++)\r
+ {\r
+ for(int xx=0; xx<bmpwidth; xx++)\r
+ {\r
+ RGBApixel pixel=bmp.GetPixel(xx,yy);\r
+ int tempred=pixel.Red+(rand()%21)-10;\r
+ int tempgreen=pixel.Green+(rand()%21)-10;\r
+ int tempblue=pixel.Blue+(rand()%21)-10;\r
+\r
+ tempred < 0 ? tempred=0 : false;\r
+ tempred > 255 ? tempred=255 : false;\r
+ tempgreen < 0 ? tempgreen=0 : false;\r
+ tempgreen > 255 ? tempgreen=255 : false;\r
+ tempblue < 0 ? tempblue=0 : false;\r
+ tempblue > 255 ? tempblue=255 : false;\r
+\r
+ pixel.Red=tempred;\r
+ pixel.Green=tempgreen;\r
+ pixel.Blue=tempblue;\r
+\r
+ bmp.SetPixel(xx,yy,pixel);\r
+ }\r
}\r
\r
bmp.WriteToFile(tempfilename.c_str());\r
\r
const std::string SimpleCaptcha::GenerateRandomString(const int len)\r
{\r
- static std::string chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";\r
+ // no l,1 O,0 because they look too much alike\r
+ static std::string chars="abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789";\r
std::string temp="";\r
for(int i=0; i<len; i++)\r
{\r
fread(&m_puzzle[0],1,filelen,infile);\r
fclose(infile);\r
}\r
-}
\ No newline at end of file
+}\r