コード例 #1
0
ファイル: ScratchFilter.java プロジェクト: adelq/WebcamStudio
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) dst = createCompatibleDestImage(src, null);

    int width = src.getWidth();
    int height = src.getHeight();
    int numScratches = (int) (density * width * height / 100);
    ArrayList<Line2D> lines = new ArrayList<Line2D>();
    {
      float l = length * width;
      Random random = new Random(seed);
      Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(new Color(color));
      g.setStroke(new BasicStroke(this.width));
      for (int i = 0; i < numScratches; i++) {
        float x = width * random.nextFloat();
        float y = height * random.nextFloat();
        float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f));
        float s = (float) Math.sin(a) * l;
        float c = (float) Math.cos(a) * l;
        float x1 = x - c;
        float y1 = y - s;
        float x2 = x + c;
        float y2 = y + s;
        g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
        lines.add(new Line2D.Float(x1, y1, x2, y2));
      }
      g.dispose();
    }

    if (false) {
      //		int[] inPixels = getRGB( src, 0, 0, width, height, null );
      int[] inPixels = new int[width * height];
      int index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float sx = x, sy = y;
          for (int i = 0; i < numScratches; i++) {
            Line2D.Float l = (Line2D.Float) lines.get(i);
            float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1);
            if (dot > 0) inPixels[index] |= (1 << i);
          }
          index++;
        }
      }

      Colormap colormap = new LinearColormap();
      index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff;
          inPixels[index] = colormap.getColor(f);
          index++;
        }
      }
      setRGB(dst, 0, 0, width, height, inPixels);
    }
    return dst;
  }
コード例 #2
0
ファイル: img_jsp.java プロジェクト: qq494679975/house
 // 给定范围获得随机颜色
 Color getRandColor(int fc, int bc) {
   Random random = new Random();
   if (fc > 255) fc = 255;
   if (bc > 255) bc = 255;
   int r = fc + random.nextInt(bc - fc);
   int g = fc + random.nextInt(bc - fc);
   int b = fc + random.nextInt(bc - fc);
   return new Color(r, g, b);
 }
コード例 #3
0
ファイル: CA.java プロジェクト: jkwhite/nausicaa
 public static int randomColor(Random om) {
   return pack(
       om.nextInt(256),
       om.nextInt(256),
       om.nextInt(256),
       // 255);
       // 253 + Rand.om.nextInt(3));
       // 200 + Rand.om.nextInt(53));
       randAlpha(om));
 }
コード例 #4
0
ファイル: SparkleFilter.java プロジェクト: JoaPiep/VRL
 public void setDimensions(int width, int height) {
   this.width = width;
   this.height = height;
   centreX = width / 2;
   centreY = height / 2;
   super.setDimensions(width, height);
   randomNumbers.setSeed(seed);
   rayLengths = new float[rays];
   for (int i = 0; i < rays; i++)
     rayLengths[i] = radius + randomness / 100.0f * radius * (float) randomNumbers.nextGaussian();
 }
コード例 #5
0
ファイル: ScalarImage.java プロジェクト: JoeyPrink/TEALsim
 public void setRandom(Random random)
       /* Sets all the scalars in 'this' to random values uniformly distributed
        *   over (0.0, 1.0) using the pseudo-random generator 'random'. */
     {
   // setZero();
   for (int k = 0; k < size; ++k) f[k] = random.nextFloat();
 }
コード例 #6
0
ファイル: CA.java プロジェクト: jkwhite/nausicaa
 public static int randAlpha(Random om) {
   switch (om.nextInt(5)) {
     case 0:
       return 253;
     case 1:
       return 254;
     default:
       return 255;
   }
 }
コード例 #7
0
ファイル: TJUnitTest.java プロジェクト: sbesson/bioformats
  private static void bufSizeTest() throws Exception {
    int w, h, i, subsamp;
    byte[] srcBuf, jpegBuf;
    TJCompressor tjc = null;
    Random r = new Random();

    try {
      tjc = new TJCompressor();
      System.out.println("Buffer size regression test");
      for (subsamp = 0; subsamp < TJ.NUMSAMP; subsamp++) {
        for (w = 1; w < 48; w++) {
          int maxh = (w == 1) ? 2048 : 48;
          for (h = 1; h < maxh; h++) {
            if (h % 100 == 0) System.out.format("%04d x %04d\b\b\b\b\b\b\b\b\b\b\b", w, h);
            srcBuf = new byte[w * h * 4];
            jpegBuf = new byte[TJ.bufSize(w, h, subsamp)];
            for (i = 0; i < w * h * 4; i++) {
              srcBuf[i] = (byte) (r.nextInt(2) * 255);
            }
            tjc.setSourceImage(srcBuf, w, 0, h, TJ.PF_BGRX);
            tjc.setSubsamp(subsamp);
            tjc.setJPEGQuality(100);
            tjc.compress(jpegBuf, 0);

            srcBuf = new byte[h * w * 4];
            jpegBuf = new byte[TJ.bufSize(h, w, subsamp)];
            for (i = 0; i < h * w * 4; i++) {
              srcBuf[i] = (byte) (r.nextInt(2) * 255);
            }
            tjc.setSourceImage(srcBuf, h, 0, w, TJ.PF_BGRX);
            tjc.compress(jpegBuf, 0);
          }
        }
      }
      System.out.println("Done.      ");
    } catch (Exception e) {
      if (tjc != null) tjc.close();
      throw e;
    }
    if (tjc != null) tjc.close();
  }
コード例 #8
0
ファイル: ScalarImage.java プロジェクト: JoeyPrink/TEALsim
  public ScalarImage(int width, int height, Random random)
        /* Constructs a new ScalarImage = < width, height, zero-buffer > */
      {
    this.width = width;
    this.height = height;
    size = width * height;

    f = new float[size];
    offset = new int[height];
    for (int j = 0; j < height; ++j) offset[j] = width * j;

    for (int k = 0; k < size; ++k) f[k] = random.nextFloat();
  }
コード例 #9
0
ファイル: Frame.java プロジェクト: stuydw/final
  /*======== public void drawPolygons() ==========
  Inputs:  EdgeMatrix pm
           Color c
  Returns:

  Go through the point matrix as if it were a polygon matrix
  Call drawline in batches of 3s to create triangles.

  04/16/12 22:05:02
  jdyrlandweaver
  ====================*/
  public void drawPolygons(EdgeMatrix pm, Color c) {

    Random rndm = new Random();

    Color rndmColor;
    float r, g, b;

    if (pm.getLastCol() < 3) return;

    for (int i = 0; i < pm.getLastCol() - 2; i += 3) {

      if (pm.calculateDot(i) > 0) {

        r = rndm.nextFloat();
        g = rndm.nextFloat();
        b = rndm.nextFloat();

        rndmColor = new Color(r, g, b);

        scanLine(pm, i, rndmColor);
      }
    }
  }
コード例 #10
0
ファイル: CA.java プロジェクト: jkwhite/nausicaa
 public void initRandom(int[] values) {
   Random r = new Random();
   for (int i = 0; i < getWidth(); i++) {
     set(i, 0, values[r.nextInt(values.length)]);
   }
 }
コード例 #11
0
 public Pickup(int fW, int fH) {
   type = "heart";
   x = r.nextInt(fW - 40) + 40;
   y = r.nextInt(fH - 40) + 40;
   position = new Point2D.Double(x, y);
 } // end constructor
コード例 #12
0
ファイル: img_jsp.java プロジェクト: qq494679975/house
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      response.setContentType("image/jpeg");
      pageContext =
          _jspxFactory.getPageContext(
              this, request, response, "/myhtml/errorpage/erroe.jsp", true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      out.write('\r');
      out.write('\n');

      // 设置页面不缓存
      response.setHeader("Pragma", "No-cache");
      response.setHeader("Cache-Control", "no-cache");
      response.setDateHeader("Expires", 0);

      //   在内存中创建图象
      int width = 60, height = 20;
      BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

      //   获取图形上下文
      Graphics g = image.getGraphics();

      // 生成随机类
      Random random = new Random();

      //   设定背景色
      g.setColor(getRandColor(200, 250));
      g.fillRect(0, 0, width, height);

      // 设定字体
      g.setFont(new Font("Times   New   Roman", Font.PLAIN, 18));

      // 画边框
      // g.setColor(new   Color());
      // g.drawRect(0,0,width-1,height-1);

      //   随机产生155条干扰线,使图象中的认证码不易被其它程序探测到
      g.setColor(getRandColor(160, 200));
      for (int i = 0; i < 155; i++) {
        int x = random.nextInt(width);
        int y = random.nextInt(height);
        int xl = random.nextInt(12);
        int yl = random.nextInt(12);
        g.drawLine(x, y, x + xl, y + yl);
      }

      //   取随机产生的认证码(4位数字)
      String sRand = "";
      for (int i = 0; i < 4; i++) {
        String rand = String.valueOf(random.nextInt(10));
        sRand += rand;
        //   将认证码显示到图象中
        g.setColor(
            new Color(
                20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
        // 调用函数出来的颜色相同,可能是å›
        // ä¸ºç§å­å¤ªæŽ¥è¿‘,所以只能直接生成
        g.drawString(rand, 13 * i + 6, 16);
      }

      //   将认证码存入SESSION
      session.setAttribute("rand", sRand);

      //   图象生效
      g.dispose();

      //   输出图象到页面
      ImageIO.write(image, "JPEG", response.getOutputStream());
      out.clear();
      out = pageContext.pushBody();

    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try {
            out.clearBuffer();
          } catch (java.io.IOException e) {
          }
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else log(t.getMessage(), t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }