public Image getScreenshot() {
   BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
   Graphics g = image.getGraphics();
   paint(g);
   g.dispose();
   return image;
 }
Example #2
0
  /** paint the canvas into a image file of given width and height */
  public void writeToImage(String s, int w, int h) {
    String ext;
    File f;
    try {
      ext = s.substring(s.lastIndexOf(".") + 1);
      f = new File(s);
    } catch (Exception e) {
      System.out.println(e);
      return;
    }
    if (!ext.equals("jpg") && !ext.equals("png")) {
      System.out.println("Cannot write to file: Illegal extension " + ext);
      return;
    }
    boolean opq = true;
    if (theOpaque != null) opq = theOpaque;

    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    g2.setBackground(Color.white);
    g2.setPaint(Color.black);
    g2.setStroke(new BasicStroke(1));
    g2.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    doBuffer(g2, true, new Rectangle(0, 0, w, h));
    try {
      ImageIO.write(image, ext, f);
    } catch (Exception e) {
      System.out.println(e);
    }
  }
 public static BufferedImage copyImage(BufferedImage source) {
   BufferedImage b =
       new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
   Graphics g = b.getGraphics();
   g.drawImage(source, 0, 0, null);
   g.dispose();
   return b;
 }
Example #4
0
 public void drawScaledImage(BufferedImage im, int x, int y, int w, int h) {
   float scaleX = w * 1.0f / im.getWidth();
   float scaleY = h * 1.0f / im.getHeight();
   AffineTransform tx = new AffineTransform();
   tx.scale(scaleX, scaleY);
   BufferedImageOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
   drawImage(im, op, x, y);
 }
Example #5
0
 public void paint(Graphics g) {
   synchronized (this) {
     Graphics2D g2d = (Graphics2D) g;
     if (img != null) {
       int imgw = img.getWidth();
       int imgh = img.getHeight();
       g2d.setComposite(AlphaComposite.Src);
       g2d.drawImage(img, null, 0, 0);
     }
   }
 }
Example #6
0
 public static BufferedImage cropImage(BufferedImage bi, int x, int y, int w, int h) {
   BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white);
   g2.fillRect(0, 0, w, h);
   g2.drawImage(bi, -x, -y, null); // this);
   g2.dispose();
   return image;
 }
Example #7
0
 private static ImageIcon makeRolloverIcon(ImageIcon srcIcon) {
   RescaleOp op =
       new RescaleOp(new float[] {1.2f, 1.2f, 1.2f, 1f}, new float[] {0f, 0f, 0f, 0f}, null);
   BufferedImage img =
       new BufferedImage(
           srcIcon.getIconWidth(), srcIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
   Graphics g = img.getGraphics();
   // g.drawImage(srcIcon.getImage(), 0, 0, null);
   srcIcon.paintIcon(null, g, 0, 0);
   g.dispose();
   return new ImageIcon(op.filter(img, null));
 }
Example #8
0
 public static BufferedImage tileImage(BufferedImage im, int width, int height) {
   GraphicsConfiguration gc =
       GraphicsEnvironment.getLocalGraphicsEnvironment()
           .getDefaultScreenDevice()
           .getDefaultConfiguration();
   int transparency = Transparency.OPAQUE; // Transparency.BITMASK;
   BufferedImage compatible = gc.createCompatibleImage(width, height, transparency);
   Graphics2D g = (Graphics2D) compatible.getGraphics();
   g.setPaint(new TexturePaint(im, new Rectangle(0, 0, im.getWidth(), im.getHeight())));
   g.fillRect(0, 0, width, height);
   return compatible;
 }
Example #9
0
 public static BufferedImage scaleImage(BufferedImage bi, double scale) {
   int w1 = (int) (Math.round(scale * bi.getWidth()));
   int h1 = (int) (Math.round(scale * bi.getHeight()));
   BufferedImage image = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white);
   g2.fillRect(0, 0, w1, h1);
   g2.drawImage(bi, 0, 0, w1, h1, null); // this);
   g2.dispose();
   return image;
 }
Example #10
0
 public static BufferedImage rotateImage(BufferedImage bi) {
   int w = bi.getWidth();
   int h = bi.getHeight();
   BufferedImage image = new BufferedImage(h, w, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = image.createGraphics();
   g2.setRenderingHint(
       RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   g2.setPaint(Color.white); // getBackground());
   g2.fillRect(0, 0, h, w);
   g2.rotate(90 * Math.PI / 180);
   g2.drawImage(bi, 0, -h, w, h, null); // this);
   g2.dispose();
   return image;
 }
  public void generarFondo(Component componente) {
    Rectangle areaDibujo = this.getBounds();
    BufferedImage tmp;
    GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration();

    tmp = gc.createCompatibleImage(areaDibujo.width, areaDibujo.height, BufferedImage.TRANSLUCENT);
    Graphics2D g2d = (Graphics2D) tmp.getGraphics();
    g2d.setColor(new Color(55, 55, 255, 165));
    g2d.fillRect(0, 0, areaDibujo.width, areaDibujo.height);
    fondo = tmp;
  }
 public void overlay() {
   for (int y = 0; y < height; ++y) {
     for (int x = 0; x < width; ++x) {
       // System.out.println(nonMax.getRGB(x,y));
       if (nonMax.getRGB(x, y) != -1) {
         int rgb = img.getRGB(x, y);
         Color color = new Color(rgb);
         Color res = new Color(255, color.getGreen(), color.getBlue());
         img.setRGB(x, y, res.getRGB());
       }
     }
   }
   ImageIcon icon1 = new ImageIcon(img);
   lbl1.setIcon(icon1);
 }
 private void writeEdges(int pixels[]) {
   // NOTE: There is currently no mechanism for obtaining the edge data
   // in any other format other than an INT_ARGB type BufferedImage.
   // This may be easily remedied by providing alternative accessors.
   nonMax = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
   nonMax.getWritableTile(0, 0).setDataElements(0, 0, width, height, pixels);
 }
  private void buildAccumulator(int r) {
    accImage = new BufferedImage(width, height, greyScale.getType());
    Graphics2D g = accImage.createGraphics();
    g.setColor(new Color(0, 0, 0, 0));
    g.fillRect(0, 0, width, height);
    g.dispose();
    int max = 0;

    double[] a = new double[1];
    for (int y = 0; y < height; ++y)
      for (int x = 0; x < width; ++x) {
        a[0] = acc[y * width + x][r - rmin] & 0xFF;
        accImage.getRaster().setPixel(x, y, a);
      }
    ImageIcon icon2 = new ImageIcon(accImage);
    lbl2.setIcon(icon2);
  }
 public void loadImage() throws IOException {
   nonMax = ImageIO.read(new File(path));
   width = nonMax.getWidth();
   height = nonMax.getHeight();
   rmax = width > height ? height / 2 : width / 2;
   accRMax = (rmax + offset - 1) / offset;
   whichRadius.setMaximum(accRMax);
   img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
   Graphics g = img.getGraphics();
   g.drawImage(nonMax, 0, 0, null);
   g.dispose();
   res = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
   g = res.getGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
   greyScale = copyImage(nonMax);
   ImageIcon icon = new ImageIcon(img);
   ImageIcon icon2 = new ImageIcon(greyScale);
   lbl1.setIcon(icon);
   lbl2.setIcon(icon2);
 }
  public void sobel() {
    sobel = new BufferedImage(width, height, filtered.getType());
    Graphics2D g = sobel.createGraphics();
    g.setColor(new Color(0, 0, 0, 0));
    g.fillRect(0, 0, width, height);
    g.dispose();

    int[] tmp = new int[1];
    sX = new double[height][width];
    sY = new double[height][width];
    double maxX = 0;
    double maxY = 0;
    for (int y = 1; y < height - 1; ++y)
      for (int x = 1; x < width - 1; ++x) {
        double Xvalue = 0;
        double Yvalue = 0;
        for (int j = -1; j <= 1; ++j)
          for (int i = -1; i <= 1; ++i) {

            Xvalue += GX[1 + j][1 + i] * filtered.getRaster().getPixel(x + i, y + j, tmp)[0];
            Yvalue += GY[1 + j][1 + i] * filtered.getRaster().getPixel(x + i, y + j, tmp)[0];
          }
        if (Xvalue > maxX) maxX = Xvalue;
        if (Yvalue > maxY) maxY = Yvalue;
        sX[y][x] = Xvalue;
        sY[y][x] = Yvalue;
      }

    for (int y = 1; y < height - 1; ++y)
      for (int x = 1; x < width - 1; ++x) {
        double[] a = {(Math.abs((sX[y][x] / maxX * 255)) + Math.abs((sY[y][x] / maxY) * 255))};
        // if (a[0] > 0) binary[y][x] = 1;
        // if (a[0] <= 0) binary[y][x] = 0;

        sobel.getRaster().setPixel(x, y, a);
      }
    ImageIcon icon2 = new ImageIcon(sobel);
    lbl2.setIcon(icon2);
  }
Example #17
0
  public synchronized void paint(Graphics gin) {
    Graphics2D g = (Graphics2D) gin;

    if (im == null) return;

    int height = getHeight();
    int width = getWidth();

    if (fit) {
      t = new AffineTransform();
      double scale = Math.min(((double) width) / im.getWidth(), ((double) height) / im.getHeight());
      // we'll re-center the transform in a moment.
      t.scale(scale, scale);
    }

    // if the image (in either X or Y) is smaller than the view port, then center
    // the image with respect to that axis.
    double mwidth = im.getWidth() * t.getScaleX();
    double mheight = im.getHeight() * t.getScaleY();
    if (mwidth < width)
      t.preConcatenate(
          AffineTransform.getTranslateInstance((width - mwidth) / 2.0 - t.getTranslateX(), 0));
    if (mheight < height)
      t.preConcatenate(
          AffineTransform.getTranslateInstance(0, (height - mheight) / 2.0 - t.getTranslateY()));

    // if we're allowing panning (because only a portion of the image is visible),
    // don't allow translations that show less information that is possible.
    Point2D topleft = t.transform(new Point2D.Double(0, 0), null);
    Point2D bottomright = t.transform(new Point2D.Double(im.getWidth(), im.getHeight()), null);

    if (mwidth > width) {
      if (topleft.getX() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(-topleft.getX(), 0));
      if (bottomright.getX() < width)
        t.preConcatenate(AffineTransform.getTranslateInstance(width - bottomright.getX(), 0));
      //		    t.translate(width-bottomright.getX(), 0);
    }
    if (mheight > height) {
      if (topleft.getY() > 0)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, -topleft.getY()));
      if (bottomright.getY() < height)
        t.preConcatenate(AffineTransform.getTranslateInstance(0, height - bottomright.getY()));
    }

    g.drawImage(im, t, null);
  }
Example #18
0
  public void run() {
    Thread me = Thread.currentThread();
    while (getSize().width <= 0) {
      try {
        anim.sleep(500);
      } catch (InterruptedException e) {
        return;
      }
    }

    Graphics2D g2d = null;
    Graphics2D BufferG2D = null;
    Graphics2D ScreenG2D = null;
    BasicStroke solid = new BasicStroke(9.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 9.0f);
    GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    int rule = AlphaComposite.SRC_OVER;
    AlphaComposite opaque = AlphaComposite.SrcOver;
    AlphaComposite blend = AlphaComposite.getInstance(rule, 0.9f);
    AlphaComposite set = AlphaComposite.Src;
    int frame = 0;
    int frametmp = 0;
    Dimension oldSize = getSize();
    Shape clippath = null;
    while (anim == me) {
      Dimension size = getSize();
      if (size.width != oldSize.width || size.height != oldSize.height) {
        img = null;
        clippath = null;
        if (BufferG2D != null) {
          BufferG2D.dispose();
          BufferG2D = null;
        }
        if (ScreenG2D != null) {
          ScreenG2D.dispose();
          ScreenG2D = null;
        }
      }
      oldSize = size;

      if (img == null) {
        img = (BufferedImage) createImage(size.width, size.height);
      }

      if (BufferG2D == null) {
        BufferG2D = img.createGraphics();
        BufferG2D.setRenderingHint(
            RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT);
        BufferG2D.setClip(clippath);
      }
      g2d = BufferG2D;

      float[] ctrlpts;
      for (int i = 0; i < animpts.length; i += 2) {
        animate(animpts, deltas, i + 0, size.width);
        animate(animpts, deltas, i + 1, size.height);
      }
      ctrlpts = animpts;
      int len = ctrlpts.length;
      gp.reset();
      int dir = 0;
      float prevx = ctrlpts[len - 2];
      float prevy = ctrlpts[len - 1];
      float curx = ctrlpts[0];
      float cury = ctrlpts[1];
      float midx = (curx + prevx) / 2.0f;
      float midy = (cury + prevy) / 2.0f;
      gp.moveTo(midx, midy);
      for (int i = 2; i <= ctrlpts.length; i += 2) {
        float x1 = (midx + curx) / 2.0f;
        float y1 = (midy + cury) / 2.0f;
        prevx = curx;
        prevy = cury;
        if (i < ctrlpts.length) {
          curx = ctrlpts[i + 0];
          cury = ctrlpts[i + 1];
        } else {
          curx = ctrlpts[0];
          cury = ctrlpts[1];
        }
        midx = (curx + prevx) / 2.0f;
        midy = (cury + prevy) / 2.0f;
        float x2 = (prevx + midx) / 2.0f;
        float y2 = (prevy + midy) / 2.0f;
        gp.curveTo(x1, y1, x2, y2, midx, midy);
      }
      gp.closePath();

      g2d.setComposite(set);
      g2d.setBackground(backgroundColor);
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

      if (bgChanged || bounds == null) {
        bounds = new Rectangle(0, 0, getWidth(), getHeight());
        bgChanged = false;
      }
      // g2d.clearRect(bounds.x-5, bounds.y-5, bounds.x + bounds.width + 5, bounds.y + bounds.height
      // + 5);
      g2d.clearRect(0, 0, getWidth(), getHeight());

      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.setColor(outerColor);
      g2d.setComposite(opaque);
      g2d.setStroke(solid);
      g2d.draw(gp);
      g2d.setPaint(gradient);

      if (!bgChanged) {
        bounds = gp.getBounds();
      } else {
        bounds = new Rectangle(0, 0, getWidth(), getHeight());
        bgChanged = false;
      }
      gradient =
          new GradientPaint(
              bounds.x,
              bounds.y,
              gradientColorA,
              bounds.x + bounds.width,
              bounds.y + bounds.height,
              gradientColorB,
              true);
      g2d.setComposite(blend);
      g2d.fill(gp);

      if (g2d == BufferG2D) {
        repaint();
      }
      ++frame;
      Thread.yield();
    }
    if (g2d != null) {
      g2d.dispose();
    }
  }
  public NetworkMapPanel(Hacker hacker, MapPanel mapPanel) {

    Dimension mapsize = mapPanel.networkPanel.getSize();
    double h = mapsize.getHeight();
    System.out.println(h);
    float multi = 400;
    HashMap<String, NetworkButton> networks = new HashMap<String, NetworkButton>();
    networks.put(
        "UGOPNet",
        new NetworkButton(
            "UGOPNet",
            3.0f,
            2.25f,
            1.1f,
            new Color(0, 0, 204),
            "images/browserhome.png",
            hacker,
            multi));
    networks.put(
        "SubNet",
        new NetworkButton(
            "SubNet", 3.0f, 3.5f, 1, new Color(0, 0, 150), "images/down.png", hacker, multi));
    networks.put(
        "ProgNet",
        new NetworkButton(
            "ProgNet", 3.5f, 3.0f, 1, new Color(0, 0, 150), "images/script.png", hacker, multi));
    networks.put(
        "DarkNet",
        new NetworkButton(
            "DarkNet", 3.0f, 4.0f, 0.9f, new Color(50, 50, 50), "images/exit.png", hacker, multi));
    networks.put(
        "LunarMicrosystems",
        new NetworkButton(
            "LunarMicrosystems",
            2,
            4.5f,
            1,
            new Color(0, 153, 255),
            "images/cpu.png",
            hacker,
            multi));
    networks.put(
        "DoSC",
        new NetworkButton(
            "DoSC", 2.25f, 3.25f, 1, new Color(0, 0, 204), "images/firewall.png", hacker, multi));
    networks.put(
        "DTNet",
        new NetworkButton(
            "DTNet",
            2.0f,
            2.0f,
            1,
            new Color(100, 100, 100),
            "images/ducttape.png",
            hacker,
            multi));
    networks.put(
        "GeNet",
        new NetworkButton(
            "GeNet",
            1.0f,
            2.0f,
            1,
            new Color(100, 100, 100),
            "images/germanium.png",
            hacker,
            multi));
    networks.put(
        "SiNet",
        new NetworkButton(
            "SiNet", 1.0f, 3.0f, 1, new Color(100, 100, 100), "images/silicon.png", hacker, multi));
    networks.put(
        "YBCONet",
        new NetworkButton(
            "YBCONet", 0.5f, 2.5f, 1, new Color(100, 100, 100), "images/YBCO.png", hacker, multi));
    networks.put(
        "PuNet",
        new NetworkButton(
            "PuNet",
            0,
            2.0f,
            0.8f,
            new Color(100, 100, 100),
            "images/plutonium.png",
            hacker,
            multi));
    networks.put(
        "UND",
        new NetworkButton(
            "UND", 3.5f, 3.5f, 1, new Color(0, 0, 204), "images/firewall.png", hacker, multi));
    networks.put(
        "UniversityNet",
        new NetworkButton(
            "UniversityNet",
            4.5f,
            2.0f,
            1.0f,
            new Color(0, 0, 204),
            "images/browser.png",
            hacker,
            multi));
    networks.put(
        "DoSCDataBank",
        new NetworkButton(
            "DoSCDatabank",
            1.75f,
            2.5f,
            1.3f,
            new Color(0, 0, 204),
            "images/compile.png",
            hacker,
            multi));
    networks.put(
        "DoSCBank",
        new NetworkButton(
            "DoSCBank", 2.5f, 2.0f, 1, new Color(0, 0, 204), "images/bank.png", hacker, multi));
    networks.put(
        "ArenaNet",
        new NetworkButton(
            "ArenaNet", 4.5f, 3.0f, 1, new Color(204, 0, 0), "images/attack.png", hacker, multi));
    networks.put(
        "TheArena",
        new NetworkButton(
            "TheArena", 4.0f, 4.0f, 1, new Color(204, 0, 0), "images/attack.png", hacker, multi));
    networks.put(
        "LunarCreditUnion",
        new NetworkButton(
            "LunarCreditUnion",
            2.5f,
            4,
            1,
            new Color(0, 153, 255),
            "images/pettycash.png",
            hacker,
            multi));
    networks.put(
        "SpyNet",
        new NetworkButton(
            "SpyNet",
            3.0f,
            4.0f,
            1,
            new Color(200, 200, 200),
            "images/watchIcon.png",
            hacker,
            multi));
    networks.put(
        "LunarDatabank",
        new NetworkButton(
            "LunarDatabank",
            1.0f,
            4.5f,
            1.4f,
            new Color(0, 153, 255),
            "images/bank.png",
            hacker,
            multi));
    networks.put(
        "LunarCorporate",
        new NetworkButton(
            "LunarCorporate", 0, 6.0f, 1, new Color(0, 153, 255), "images/hd.png", hacker, multi));
    networks.put(
        "LunarLabs",
        new NetworkButton(
            "LunarLabs",
            2.5f,
            5.0f,
            1,
            new Color(0, 153, 255),
            "images/repair.png",
            hacker,
            multi));
    networks.put(
        "LunarSpecOps",
        new NetworkButton(
            "LunarSpecOps",
            1f,
            6.0f,
            1,
            new Color(0, 153, 255),
            "images/watchIcon.png",
            hacker,
            multi));
    networks.put(
        "LunarSat",
        new NetworkButton(
            "LunarSat", 0.25f, 5.0f, 1, new Color(0, 153, 255), "images/scan.png", hacker, multi));
    networks.put(
        "LunarColonies",
        new NetworkButton(
            "LunarColonies",
            1.0f,
            5.5f,
            1,
            new Color(0, 153, 255),
            "images/new.png",
            hacker,
            multi));
    networks.put(
        "UGoPIntranet",
        new NetworkButton(
            "UGoPIntranet", 2.5f, 1, 1, new Color(0, 0, 204), "images/http.png", hacker, multi));
    networks.put(
        "UGoPCorporate",
        new NetworkButton(
            "UGoPCorporate", 3.0f, 0, 1, new Color(0, 0, 204), "images/hd.png", hacker, multi));
    networks.put(
        "UGoPDatabank",
        new NetworkButton(
            "UGoPDatabank",
            2.75f,
            1.5f,
            1.2f,
            new Color(0, 0, 204),
            "images/compile.png",
            hacker,
            multi));
    networks.put(
        "UGoPVault",
        new NetworkButton(
            "UGoPVault", 3.0f, 1.0f, 1, new Color(0, 0, 204), "images/bank.png", hacker, multi));
    networks.put(
        "TerrorNet",
        new NetworkButton(
            "TerrorNet",
            5.5f,
            5.0f,
            0.9f,
            new Color(204, 0, 0),
            "images/refresh.png",
            hacker,
            multi));
    networks.put(
        "TerrorStash",
        new NetworkButton(
            "TerrorStash", 4.5f, 4.5f, 1, new Color(204, 0, 0), "images/bank.png", hacker, multi));
    networks.put(
        "TerrorWeaponsNet",
        new NetworkButton(
            "TerrorWeaponsNet",
            5.0f,
            4.0f,
            1,
            new Color(204, 0, 0),
            "images/attack.png",
            hacker,
            multi));
    networks.put(
        "TerrorLeaders",
        new NetworkButton(
            "TerrorLeaders",
            6,
            6.0f,
            0.75f,
            new Color(204, 0, 0),
            "images/firewall.png",
            hacker,
            multi));
    networks.put(
        "InnerCircle",
        new NetworkButton(
            "InnerCircle",
            6,
            0,
            0.5f,
            new Color(150, 0, 100),
            "images/decompile.png",
            hacker,
            multi));
    networks.put(
        "LawNet",
        new NetworkButton(
            "LawNet",
            4.0f,
            1.5f,
            0.75f,
            new Color(150, 0, 100),
            "images/redirect.png",
            hacker,
            multi));
    networks.put(
        "GroundZero",
        new NetworkButton(
            "GroundZero",
            3.0f,
            5.5f,
            1,
            new Color(200, 200, 200),
            "images/ports.png",
            hacker,
            multi));
    networks.put(
        "Wastelands",
        new NetworkButton(
            "Wastelands",
            3.5f,
            4.5f,
            1.2f,
            new Color(204, 0, 0),
            "images/attack.png",
            hacker,
            multi));
    networks.put(
        "JuniperPenetentiary",
        new NetworkButton(
            "JuniperPenetentiary",
            7,
            0,
            0.75f,
            new Color(150, 0, 100),
            "images/firewall.png",
            hacker,
            multi));

    this.nodeList = networks;
    this.hacker = hacker;
    this.mapPanel = mapPanel;
    try {
      back = ImageLoader.getImage("images/NetMapFull.png");
    } catch (Exception e) {
    }
    setLayout(null);
    setBackground(MapPanel.NETWORK_INFO_BACKGROUND);
    setPreferredSize(new Dimension(back.getWidth(), back.getHeight()));

    populate();
  }
Example #20
0
  /** Regenerates the image. */
  private synchronized void regenerateImage() {
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));

    if (mode == ColorPicker.BRI || mode == ColorPicker.SAT) {
      float bri2 = this.bri;
      float sat2 = this.sat;
      float radius = ((float) size) / 2f;
      float hue2;
      float k = 1.2f; // the number of pixels to antialias
      for (int y = 0; y < size; y++) {
        float y2 = (y - size / 2f);
        for (int x = 0; x < size; x++) {
          float x2 = (x - size / 2f);
          double theta = Math.atan2(y2, x2) - 3 * Math.PI / 2.0;
          if (theta < 0) theta += 2 * Math.PI;

          double r = Math.sqrt(x2 * x2 + y2 * y2);
          if (r <= radius) {
            if (mode == ColorPicker.BRI) {
              hue2 = (float) (theta / (2 * Math.PI));
              sat2 = (float) (r / radius);
            } else { // SAT
              hue2 = (float) (theta / (2 * Math.PI));
              bri2 = (float) (r / radius);
            }
            row[x] = Color.HSBtoRGB(hue2, sat2, bri2);
            if (r > radius - k) {
              int alpha = (int) (255 - 255 * (r - radius + k) / k);
              if (alpha < 0) alpha = 0;
              if (alpha > 255) alpha = 255;
              row[x] = row[x] & 0xffffff + (alpha << 24);
            }
          } else {
            row[x] = 0x00000000;
          }
        }
        image.getRaster().setDataElements(0, y, size, 1, row);
      }
    } else if (mode == ColorPicker.HUE) {
      float hue2 = this.hue;
      for (int y = 0; y < size; y++) {
        float y2 = ((float) y) / ((float) size);
        for (int x = 0; x < size; x++) {
          float x2 = ((float) x) / ((float) size);
          row[x] = Color.HSBtoRGB(hue2, x2, y2);
        }
        image.getRaster().setDataElements(0, y, image.getWidth(), 1, row);
      }
    } else { // mode is RED, GREEN, or BLUE
      int red2 = red;
      int green2 = green;
      int blue2 = blue;
      for (int y = 0; y < size; y++) {
        float y2 = ((float) y) / ((float) size);
        for (int x = 0; x < size; x++) {
          float x2 = ((float) x) / ((float) size);
          if (mode == ColorPicker.RED) {
            green2 = (int) (x2 * 255 + .49);
            blue2 = (int) (y2 * 255 + .49);
          } else if (mode == ColorPicker.GREEN) {
            red2 = (int) (x2 * 255 + .49);
            blue2 = (int) (y2 * 255 + .49);
          } else {
            red2 = (int) (x2 * 255 + .49);
            green2 = (int) (y2 * 255 + .49);
          }
          row[x] = 0xFF000000 + (red2 << 16) + (green2 << 8) + blue2;
        }
        image.getRaster().setDataElements(0, y, size, 1, row);
      }
    }
    repaint();
  }
Example #21
0
  public Dimension getMaximumSize() {
    if (im == null) return new Dimension(2, 2);

    return new Dimension(im.getWidth(), im.getHeight());
  }
 private void drawCircle(int pix, int xCenter, int yCenter, int r) {
   Graphics2D g = res.createGraphics();
   g.setColor(Color.RED);
   g.drawOval(xCenter - r, yCenter - r, r * 2, r * 2);
   g.dispose();
 }
  public void nonMax() {
    nonMax = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
    Graphics2D g = nonMax.createGraphics();
    g.setColor(new Color(0, 0, 0, 0));
    g.fillRect(0, 0, width, height);
    g.dispose();

    magnitude = new int[height * width];
    for (int y = 1; y < height - 1; y++) {
      for (int x = 1; x < width - 1; x++) {

        double xGrad = sX[y][x];
        double yGrad = sY[y][x];
        double gradMag = Math.hypot(xGrad, yGrad);

        // perform non-maximal supression
        double nMag = Math.hypot(sX[y - 1][x], sY[y - 1][x]);
        double sMag = Math.hypot(sX[y + 1][x], sY[y + 1][x]);
        double wMag = Math.hypot(sX[y][x - 1], sY[y][x - 1]);
        double eMag = Math.hypot(sX[y][x + 1], sY[y][x + 1]);
        double neMag = Math.hypot(sX[y - 1][x + 1], sY[y - 1][x + 1]);
        double seMag = Math.hypot(sX[y + 1][x + 1], sY[y + 1][x + 1]);
        double swMag = Math.hypot(sX[y + 1][x - 1], sY[y + 1][x - 1]);
        double nwMag = Math.hypot(sX[y - 1][x - 1], sY[y - 1][x - 1]);
        double tmp;
        /*
         * An explanation of what's happening here, for those who want
         * to understand the source: This performs the "non-maximal
         * supression" phase of the Canny edge detection in which we
         * need to compare the gradient magnitude to that in the
         * direction of the gradient; only if the value is a local
         * maximum do we consider the point as an edge candidate.
         *
         * We need to break the comparison into a number of different
         * cases depending on the gradient direction so that the
         * appropriate values can be used. To avoid computing the
         * gradient direction, we use two simple comparisons: first we
         * check that the partial derivatives have the same sign (1)
         * and then we check which is larger (2). As a consequence, we
         * have reduced the problem to one of four identical cases that
         * each test the central gradient magnitude against the values at
         * two points with 'identical support'; what this means is that
         * the geometry required to accurately interpolate the magnitude
         * of gradient function at those points has an identical
         * geometry (upto right-angled-rotation/reflection).
         *
         * When comparing the central gradient to the two interpolated
         * values, we avoid performing any divisions by multiplying both
         * sides of each inequality by the greater of the two partial
         * derivatives. The common comparand is stored in a temporary
         * variable (3) and reused in the mirror case (4).
         *
         */
        if (xGrad * yGrad <= (float) 0 /*(1)*/
            ? Math.abs(xGrad) >= Math.abs(yGrad) /*(2)*/
                ? (tmp = Math.abs(xGrad * gradMag))
                        >= Math.abs(yGrad * neMag - (xGrad + yGrad) * eMag) /*(3)*/
                    && tmp > Math.abs(yGrad * swMag - (xGrad + yGrad) * wMag) /*(4)*/
                : (tmp = Math.abs(yGrad * gradMag))
                        >= Math.abs(xGrad * neMag - (yGrad + xGrad) * nMag) /*(3)*/
                    && tmp > Math.abs(xGrad * swMag - (yGrad + xGrad) * sMag) /*(4)*/
            : Math.abs(xGrad) >= Math.abs(yGrad) /*(2)*/
                ? (tmp = Math.abs(xGrad * gradMag))
                        >= Math.abs(yGrad * seMag + (xGrad - yGrad) * eMag) /*(3)*/
                    && tmp > Math.abs(yGrad * nwMag + (xGrad - yGrad) * wMag) /*(4)*/
                : (tmp = Math.abs(yGrad * gradMag))
                        >= Math.abs(xGrad * seMag + (yGrad - xGrad) * sMag) /*(3)*/
                    && tmp > Math.abs(xGrad * nwMag + (yGrad - xGrad) * nMag) /*(4)*/) {
          magnitude[y * width + x] =
              gradMag >= MAGNITUDE_LIMIT ? MAGNITUDE_MAX : (int) (MAGNITUDE_SCALE * gradMag);
          // NOTE: The orientation of the edge is not employed by this
          // implementation. It is a simple matter to compute it at
          // this point as: Math.atan2(yGrad, xGrad);
        } else {
          magnitude[y * width + x] = 0;
        }
      }
    }

    ImageIcon icon2 = new ImageIcon(nonMax);
    lbl2.setIcon(icon2);
  }
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == b) {
      JFrame frame2 = new JFrame();
      JFileChooser chooser = new JFileChooser(".");
      int option =
          chooser.showOpenDialog(
              frame2); // parentComponent must a component like JFrame, JDialog...
      if (option == JFileChooser.APPROVE_OPTION) {
        File selectedFile = chooser.getSelectedFile();
        path = selectedFile.getAbsolutePath();
      }
      try {
        loadImage();
      } catch (IOException ioe) {
        System.out.println(ioe.getMessage());
      }
    } else if (e.getSource() == c) {

      gaussianBlur();
      // filtered = grayscale.filter(filtered, null);
      sobel();
      // thinImage();
      nonMax();
      float lowThreshold = 2.5f;
      float highThreshold = 7.5f;
      int low = Math.round(lowThreshold * MAGNITUDE_SCALE);
      int high = Math.round(highThreshold * MAGNITUDE_SCALE);
      performHysteresis(low, high);
      thresholdEdges();
      writeEdges(data);
      Hough();
      ImageIcon icon1 = new ImageIcon(res);
      lbl1.setIcon(icon1);
      ImageIcon icon2 = new ImageIcon(filtered);
      lbl2.setIcon(icon2);
      filterBtn.setSelected(true);
    }
    if (e.getSource() == findCircles) {
      try {
        accSize = Integer.parseInt(inputCircles.getText());
        res = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = res.getGraphics();
        g.drawImage(img, 0, 0, null);
        g.dispose();
        findMaxima();
        ImageIcon icon1 = new ImageIcon(res);
        lbl1.setIcon(icon1);
      } catch (Exception err) {
        System.out.println("Not a valid integer");
      }
    } else if (e.getSource() == filterBtn) {
      ImageIcon icon2 = new ImageIcon(filtered);
      lbl2.setIcon(icon2);
    } else if (e.getSource() == sobelBtn) {
      ImageIcon icon2 = new ImageIcon(sobel);
      lbl2.setIcon(icon2);
    } else if (e.getSource() == nonMaxBtn) {
      ImageIcon icon2 = new ImageIcon(nonMax);
      lbl2.setIcon(icon2);
    } else if (e.getSource() == accumulator) {
      buildAccumulator(whichRadius.getValue());
    }
  }