// Assumption: alGamesInfo is set to a valid object and noOfGames = alGamesInfo.size().
  public void setSelectedGameIndex(int newGameIndex) {
    if ((newGameIndex < 1) || (newGameIndex > noOfGames - 2))
      // => Invalid game index passed.
      selGameIndex = 1; // reset
    else selGameIndex = newGameIndex;

    // FIXME: Handle case when alGamesInfo.get(%index%).getLogo() = null (when %id%.png is absent)
    // Create top blurred image.
    BufferedImage biTemp = alGamesInfo.get(selGameIndex - 1).getLogo();
    biTopBlurred =
        UIHelpers.EmptyCompatibleImage(
            biTemp.getWidth(), biTemp.getHeight(), biTemp.getColorModel().getTransparency());
    blurOp.filter(biTemp, biTopBlurred);
    biTopBlurred = blurOp.filter(biTopBlurred, null);
    biTopBlurred = blurOp.filter(biTopBlurred, null);

    // Create bottom blurred image.
    // TODO: NULL pointer exception occurs here is there are no
    // logo and screenshot images available for a game
    biTemp = alGamesInfo.get(selGameIndex + 1).getLogo();
    biBottomBlurred =
        UIHelpers.EmptyCompatibleImage(
            biTemp.getWidth(), biTemp.getHeight(), biTemp.getColorModel().getTransparency());
    blurOp.filter(biTemp, biBottomBlurred);
    biBottomBlurred = blurOp.filter(biBottomBlurred, null);
    biBottomBlurred = blurOp.filter(biBottomBlurred, null);
  }
示例#2
0
 /** @see Graphics2D#drawImage(BufferedImage, BufferedImageOp, int, int) */
 public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
   BufferedImage result = img;
   if (op != null) {
     result = op.createCompatibleDestImage(img, img.getColorModel());
     result = op.filter(img, result);
   }
   drawImage(result, x, y, null);
 }
示例#3
0
文件: Filter.java 项目: Tug/robotarm
 /**
  * Transformation d'une BufferedImage en utilisant la classe ConvolveOp On applique a l'image une
  * matrice de convolution Flou, contrast, netteté, detection de contour, binarisation, posteriser
  * Ces fonctions ne sont plus utilisés durant le traitement
  */
 public static BufferedImage blur(BufferedImage bi, int n) {
   int n2 = n * n;
   float coef = 1.0f / n2;
   float[] kernel = new float[n2];
   for (int i = 0; i < n2; i++) kernel[i] = coef;
   BufferedImageOp blurOp = new ConvolveOp(new Kernel(n, n, kernel));
   return blurOp.filter(bi, null);
 }
 protected static BufferedImage rotateImage(BufferedImage original, float degrees) {
   if (degrees == 0.0f) {
     return original;
   } else {
     AffineTransform at = new AffineTransform();
     at.rotate(Math.toRadians(degrees), original.getWidth() / 2.0f, original.getHeight() / 2.0f);
     BufferedImageOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
     return op.filter(original, null);
   }
 }
示例#5
0
文件: IconIO.java 项目: munix/jdget
  /**
   * @param image
   * @return
   */
  public static BufferedImage blur(final BufferedImage image) {
    final float[] matrix = new float[400];
    for (int i = 0; i < 400; i++) {
      matrix[i] = 1.0f / 400.0f;
    }

    final BufferedImageOp op =
        new ConvolveOp(new Kernel(20, 20, matrix), ConvolveOp.EDGE_NO_OP, null);
    return op.filter(image, null);
  }
示例#6
0
文件: Filter.java 项目: Tug/robotarm
 // valeur possible pour threshold = [0, 255] exemple : 64, 128,192
 public static BufferedImage threshold(BufferedImage bi, int threshold) {
   int minimum = 0;
   int maximum = 255;
   short[] thresholdArray = new short[256];
   for (int i = 0; i < 256; i++) {
     if (i < threshold) thresholdArray[i] = (short) minimum;
     else thresholdArray[i] = (short) maximum;
   }
   BufferedImageOp thresholdOp = new LookupOp(new ShortLookupTable(0, thresholdArray), null);
   return thresholdOp.filter(bi, null);
 }
示例#7
0
 public BufferedImage sharpenImage(BufferedImage img) {
   if (sharpenLevel <= 0) return img;
   int width = img.getWidth(null);
   int height = img.getHeight(null);
   BufferedImage tmp = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
   tmp.getGraphics().drawImage(img, 0, 0, null);
   Kernel kernel;
   if (sharpenLevel == 1) {
     kernel =
         new Kernel(
             3, 3, new float[] {-0.25f, -0.5f, -0.25f, -0.5f, 4, -0.5f, -0.25f, -0.5f, -0.25f});
   } else {
     kernel = new Kernel(3, 3, new float[] {-0.5f, -1, -0.5f, -1, 7, -1, -0.5f, -1, -0.5f});
   }
   BufferedImageOp op = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
   return op.filter(tmp, null);
 }
  /**
   * Blurs the image.
   *
   * @param bi The BufferedImage on which the blur effect is done.
   * @return BufferedImage The manipuated image
   */
  public static BufferedImage blur(BufferedImage bi) {
    int xSize = bi.getWidth();
    int ySize = bi.getHeight();

    BufferedImage newBi = new BufferedImage(xSize, ySize, 3);

    float[] matrix = {
      0.111f, 0.111f, 0.111f,
      0.111f, 0.111f, 0.111f,
      0.111f, 0.111f, 0.111f,
    };

    BufferedImageOp op = new ConvolveOp(new Kernel(3, 3, matrix));
    bi = op.filter(bi, newBi);

    addImage(bi);
    return newBi;
  }
示例#9
0
  public static BufferedImage blurImage(BufferedImage image) {
    float ninth = 1.0f / 9.0f;
    float[] blurKernel = {
      ninth, ninth, ninth,
      ninth, ninth, ninth,
      ninth, ninth, ninth
    };

    HashMap<Key, Object> map = new HashMap<Key, Object>();

    map.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

    map.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    map.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    RenderingHints hints = new RenderingHints(map);
    BufferedImageOp op = new ConvolveOp(new Kernel(3, 3, blurKernel), ConvolveOp.EDGE_NO_OP, hints);
    return op.filter(image, null);
  }
示例#10
0
 public void transformImage(
     SunGraphics2D sg, BufferedImage img, BufferedImageOp op, int x, int y) {
   if (op != null) {
     if (op instanceof AffineTransformOp) {
       AffineTransformOp atop = (AffineTransformOp) op;
       transformImage(sg, img, x, y, atop.getTransform(), atop.getInterpolationType());
       return;
     } else {
       img = op.filter(img, null);
     }
   }
   copyImage(sg, img, x, y, null);
 }
示例#11
0
 /**
  * Draws the image resulting from applying the {@code BufferedImageOp} to the specified image at
  * the location {@code (x, y)}.
  *
  * @param img the image.
  * @param op the operation.
  * @param x the x-coordinate.
  * @param y the y-coordinate.
  */
 @Override
 public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
   BufferedImage imageToDraw = op.filter(img, null);
   drawImage(imageToDraw, new AffineTransform(1f, 0f, 0f, 1f, x, y), null);
 }
 public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
   drawImage(op.filter(img, null), x, y, null);
 }
 /**
  * Apply a filter and repaint.
  *
  * @param op the image operation to apply
  */
 private void filter(BufferedImageOp op) {
   if (image == null) return;
   image = op.filter(image, null);
   repaint();
 }
示例#14
0
 /**
  * Converts a {@link BufferedImage} object into a gray scale image using the available filters in
  * Java.
  *
  * @param src The {@link BufferedImage} to be converted.
  * @return a {@link BufferedImage} which is converted in gray scale.
  */
 private static BufferedImage convertToGrayscale(BufferedImage src) {
   ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
   BufferedImageOp op = new ColorConvertOp(cs, null);
   BufferedImage grayImg = op.filter(src, null);
   return grayImg;
 }
示例#15
0
文件: Filter.java 项目: Tug/robotarm
 public static BufferedImage posterize(BufferedImage bi) {
   short[] post = new short[256];
   for (int i = 0; i < 256; i++) post[i] = (short) (i - (i % 32));
   BufferedImageOp posterizeOp = new LookupOp(new ShortLookupTable(0, post), null);
   return posterizeOp.filter(bi, null);
 }
示例#16
0
文件: Filter.java 项目: Tug/robotarm
 public static BufferedImage contrast(BufferedImage bi) {
   float coef = 0.165f;
   float[] kernel = {coef, coef, coef, coef, coef, coef, coef, coef, coef};
   BufferedImageOp blurOp = new ConvolveOp(new Kernel(3, 3, kernel));
   return blurOp.filter(bi, null);
 }