View Javadoc

1   /*
2    * JCaptcha, the open source java framework for captcha definition and integration
3    * Copyright (c)  2007 jcaptcha.net. All Rights Reserved.
4    * See the LICENSE.txt file distributed with this package.
5    */
6   
7   /*
8    * jcaptcha, the open source java framework for captcha definition and integration
9    * copyright (c)  2007 jcaptcha.net. All Rights Reserved.
10   * See the LICENSE.txt file distributed with this package.
11   */
12  
13  /*
14   * jcaptcha, the open source java framework for captcha definition and integration
15   * copyright (c)  2007 jcaptcha.net. All Rights Reserved.
16   * See the LICENSE.txt file distributed with this package.
17   */
18  
19  package com.octo.captcha.engine.image.fisheye;
20  
21  import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
22  import com.octo.captcha.component.image.backgroundgenerator.FileReaderRandomBackgroundGenerator;
23  import com.octo.captcha.component.image.deformation.ImageDeformation;
24  import com.octo.captcha.component.image.deformation.ImageDeformationByFilters;
25  import com.octo.captcha.engine.image.ListImageCaptchaEngine;
26  import com.octo.captcha.image.fisheye.FishEyeFactory;
27  
28  import java.awt.image.ImageFilter;
29  
30  /***
31   * Produce fishEye from files. FishEye are done from sphere
32   *
33   * @author <a href="mailto:mag@jcaptcha.net">Marc-Antoine Garrigue</a>
34   * @version 1.0
35   */
36  public class SimpleFishEyeEngine extends ListImageCaptchaEngine {
37  
38      /***
39       * this method should be implemented as folow : <ul> <li>First construct all the factories you want to initialize
40       * the gimpy with</li> <li>then call the this.addFactoriy method for each factory</li> </ul>
41       */
42      protected void buildInitialFactories() {
43          //build filters
44          com.jhlabs.image.SphereFilter sphere = new com.jhlabs.image.SphereFilter();
45          com.jhlabs.image.RippleFilter ripple = new com.jhlabs.image.RippleFilter();
46          com.jhlabs.image.TwirlFilter twirl = new com.jhlabs.image.TwirlFilter();
47          com.jhlabs.image.WaterFilter water = new com.jhlabs.image.WaterFilter();
48  
49          ripple.setWaveType(com.jhlabs.image.RippleFilter.NOISE);
50          ripple.setXAmplitude(10);
51          ripple.setYAmplitude(10);
52          ripple.setXWavelength(10);
53          ripple.setYWavelength(10);
54          ripple.setEdgeAction(com.jhlabs.image.TransformFilter.CLAMP);
55  
56          water.setAmplitude(10);
57   //       water.setAntialias(true);
58          water.setWavelength(20);
59  
60          twirl.setAngle(4);
61  
62          sphere.setRefractionIndex(2);
63  
64          ImageDeformation rippleDef = new ImageDeformationByFilters(
65                  new ImageFilter[]{});
66          ImageDeformation sphereDef = new ImageDeformationByFilters(
67                  new ImageFilter[]{});
68          ImageDeformation waterDef = new ImageDeformationByFilters(
69                  new ImageFilter[]{});
70          ImageDeformation twirlDef = new ImageDeformationByFilters(
71                  new ImageFilter[]{});
72  
73          //add background from files
74          BackgroundGenerator generator = new FileReaderRandomBackgroundGenerator(
75                  new Integer(250), new Integer(250),
76                  "./fisheyebackgrounds");
77          addFactory(
78                  new FishEyeFactory(generator, sphereDef, new Integer(10),
79                          new Integer(5)));
80          addFactory(
81                  new FishEyeFactory(generator, rippleDef, new Integer(10),
82                          new Integer(5)));
83          addFactory(
84                  new FishEyeFactory(generator, waterDef, new Integer(10),
85                          new Integer(5)));
86          addFactory(
87                  new FishEyeFactory(generator, twirlDef, new Integer(10),
88                          new Integer(5)));
89  
90      }
91  }