Exemplo n.º 1
0
 private void captureScreen(IScreen scr) {
   ScreenImage simg = scr.capture();
   scr_img = simg.getImage();
   darker_factor = 0.6f;
   RescaleOp op = new RescaleOp(darker_factor, 0, null);
   scr_img_darker = op.filter(scr_img, null);
 }
Exemplo n.º 2
0
  public static BufferedImage doContrast(BufferedImage img, float f) {
    float brightenFactor = 1 + f;

    RescaleOp op = new RescaleOp(brightenFactor, 0, null);
    img = op.filter(img, img);

    return img;
  }
Exemplo n.º 3
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));
 }
Exemplo n.º 4
0
 private BufferedImage windowWithRasterOp(
     BufferedImage srcImg, float windowLocation, float windowWidth) {
   // final int windowedImageBandValuesCount = 256;  // for BufferedImage.TYPE_INT_RGB
   // final float windowedImageBandValuesCount = 1.0F;
   // final float windowedImageBandValuesCount = 65535F;
   // final float windowedImageBandValuesCount = 4095F;
   final float windowedImageBandValuesCount =
       (1 << srcImg.getColorModel().getComponentSize(0)) - 1;
   float scale = windowedImageBandValuesCount / windowWidth;
   float offset = (windowWidth / 2 - windowLocation) * scale;
   RescaleOp rescaleOp = new RescaleOp(scale, offset, null);
   return rescaleOp.filter(srcImg, null);
 }
Exemplo n.º 5
0
 /** Takes a snapshot of the screen, fades it, and sets it as the background. */
 public static void snapshot() {
   Dimension dim = getInstance().component.getPreferredSize();
   java.awt.Rectangle rect = new java.awt.Rectangle(0, 0, dim.width, dim.height);
   BufferedImage image = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_RGB);
   Graphics g = image.getGraphics();
   g.setColor(java.awt.Color.WHITE);
   g.fillRect(0, 0, rect.width, rect.height);
   g.setColor(java.awt.Color.BLACK);
   getInstance().component.paintComponent(g);
   float factor = 0.8f;
   float base = 255f * (1f - factor);
   RescaleOp op = new RescaleOp(factor, base, null);
   BufferedImage filteredImage =
       new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
   op.filter(image, filteredImage);
   getInstance().background = filteredImage;
   getInstance().component.repaint();
 }
  /**
   * Creates BufferedImage for hwComponentType at path of size. If marked, the result image is
   * brighter by 50%.
   *
   * @param hwComponentType
   * @param path
   * @param width
   * @param marked
   * @return
   */
  protected BufferedImage createImage(
      HwTypeEnum hwComponentType, String path, Integer width, boolean marked) {

    BufferedImage bi = null;

    Image tmp = null;

    try {
      // loads image from path and scales it to desired size
      tmp = getScaledImage(path, width);
    } catch (IOException ex) {
      try {
        // load default image
        tmp = getScaledImage(getImagePath(hwComponentType), width);
      } catch (IOException ex1) {
        // should never happen, all hwComponentType default icons are in .jar as a resource
      }
    }

    // create new buffered image to paint on
    bi = new BufferedImage(tmp.getWidth(null), tmp.getHeight(null), BufferedImage.TYPE_INT_ARGB);

    // create graphics and set hints
    Graphics2D graphics2D = bi.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics2D.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

    // draw image
    graphics2D.drawImage(tmp, 0, 0, null);

    // if marked, draw transparent white rectangle over
    if (marked) {
      rescaleOp.filter(bi, bi);
    }

    graphics2D.dispose();

    return bi;
  }
Exemplo n.º 7
0
 public BufferedImage getBrighten() {
   RescaleOp rop = new RescaleOp(1.0F, 0.0F, null);
   return this.image = rop.filter(this.image, null);
 }
Exemplo n.º 8
0
 /**
  * @time : 11:08:58 AM Sep 10, 2015 @Description : For static snapshot, we are used to put a dark
  *     image as back image. So the original image should be darken.
  */
 public void darkScreenImage() {
   RescaleOp ro = new RescaleOp(0.9f, 0, null);
   whiteImage = ro.filter(screenImage, null);
 }
Exemplo n.º 9
0
 @Override
 public void paint(Graphics g) {
   RescaleOp ro = new RescaleOp(0.8f, 0, null);
   tempImage = ro.filter(image, null);
   g.drawImage(tempImage, 0, 0, this);
 }
Exemplo n.º 10
0
  /**
   * {@collect.stats} Rescales the source BufferedImage. If the color model in the source image is
   * not the same as that in the destination image, the pixels will be converted in the destination.
   * If the destination image is null, a BufferedImage will be created with the source ColorModel.
   * An IllegalArgumentException may be thrown if the number of scaling factors/offsets in this
   * object does not meet the restrictions stated in the class comments above, or if the source
   * image has an IndexColorModel.
   *
   * @param src the <code>BufferedImage</code> to be filtered
   * @param dst the destination for the filtering operation or <code>null</code>
   * @return the filtered <code>BufferedImage</code>.
   * @throws IllegalArgumentException if the <code>ColorModel</code> of <code>src</code> is an
   *     <code>IndexColorModel</code>, or if the number of scaling factors and offsets in this
   *     <code>RescaleOp</code> do not meet the requirements stated in the class comments.
   */
  public final BufferedImage filter(BufferedImage src, BufferedImage dst) {
    ColorModel srcCM = src.getColorModel();
    ColorModel dstCM;
    int numBands = srcCM.getNumColorComponents();

    if (srcCM instanceof IndexColorModel) {
      throw new IllegalArgumentException("Rescaling cannot be " + "performed on an indexed image");
    }
    if (length != 1 && length != numBands && length != srcCM.getNumComponents()) {
      throw new IllegalArgumentException(
          "Number of scaling constants "
              + "does not equal the number of"
              + " of color or color/alpha "
              + " components");
    }

    boolean needToConvert = false;

    // Include alpha
    if (length > numBands && srcCM.hasAlpha()) {
      length = numBands + 1;
    }

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

    if (dst == null) {
      dst = createCompatibleDestImage(src, null);
      dstCM = srcCM;
    } else {
      if (width != dst.getWidth()) {
        throw new IllegalArgumentException(
            "Src width (" + width + ") not equal to dst width (" + dst.getWidth() + ")");
      }
      if (height != dst.getHeight()) {
        throw new IllegalArgumentException(
            "Src height (" + height + ") not equal to dst height (" + dst.getHeight() + ")");
      }

      dstCM = dst.getColorModel();
      if (srcCM.getColorSpace().getType() != dstCM.getColorSpace().getType()) {
        needToConvert = true;
        dst = createCompatibleDestImage(src, null);
      }
    }

    BufferedImage origDst = dst;

    //
    // Try to use a native BI rescale operation first
    //
    if (ImagingLib.filter(this, src, dst) == null) {
      //
      // Native BI rescale failed - convert to rasters
      //
      WritableRaster srcRaster = src.getRaster();
      WritableRaster dstRaster = dst.getRaster();

      if (srcCM.hasAlpha()) {
        if (numBands - 1 == length || length == 1) {
          int minx = srcRaster.getMinX();
          int miny = srcRaster.getMinY();
          int[] bands = new int[numBands - 1];
          for (int i = 0; i < numBands - 1; i++) {
            bands[i] = i;
          }
          srcRaster =
              srcRaster.createWritableChild(
                  minx, miny, srcRaster.getWidth(), srcRaster.getHeight(), minx, miny, bands);
        }
      }
      if (dstCM.hasAlpha()) {
        int dstNumBands = dstRaster.getNumBands();
        if (dstNumBands - 1 == length || length == 1) {
          int minx = dstRaster.getMinX();
          int miny = dstRaster.getMinY();
          int[] bands = new int[numBands - 1];
          for (int i = 0; i < numBands - 1; i++) {
            bands[i] = i;
          }
          dstRaster =
              dstRaster.createWritableChild(
                  minx, miny, dstRaster.getWidth(), dstRaster.getHeight(), minx, miny, bands);
        }
      }

      //
      // Call the raster filter method
      //
      filter(srcRaster, dstRaster);
    }

    if (needToConvert) {
      // ColorModels are not the same
      ColorConvertOp ccop = new ColorConvertOp(hints);
      ccop.filter(dst, origDst);
    }

    return origDst;
  }