예제 #1
0
  /* (non-Javadoc)
   * @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage, java.awt.image.BufferedImage)
   */
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (src == null) {
      throw new NullPointerException("src image is null");
    }
    if (src == dst) {
      throw new IllegalArgumentException("src image cannot be the " + "same as the dst image");
    }

    boolean needToConvert = false;
    ColorModel srcCM = src.getColorModel();
    ColorModel dstCM;
    BufferedImage origDst = dst;

    if (srcCM instanceof IndexColorModel) {
      IndexColorModel icm = (IndexColorModel) srcCM;
      src = icm.convertToIntDiscrete(src.getRaster(), false);
      srcCM = src.getColorModel();
    }
    if (dst == null) {
      dst = createCompatibleDestImage(src, null);
      dstCM = srcCM;
      origDst = dst;
    } else {
      dstCM = dst.getColorModel();
      if (srcCM.getColorSpace().getType() != dstCM.getColorSpace().getType()) {
        needToConvert = true;
        dst = createCompatibleDestImage(src, null);
        dstCM = dst.getColorModel();
      } else if (dstCM instanceof IndexColorModel) {
        dst = createCompatibleDestImage(src, null);
        dstCM = dst.getColorModel();
      }
    }

    java.awt.image.CropImageFilter cropfilter =
        new java.awt.image.CropImageFilter(region.x, region.y, region.width, region.height);
    Image returnImage =
        Toolkit.getDefaultToolkit()
            .createImage(new java.awt.image.FilteredImageSource(src.getSource(), cropfilter));
    dst = ImageConverter.convertImage(returnImage);
    origDst = dst;

    if (needToConvert) {
      ColorConvertOp ccop = new ColorConvertOp(hints);
      ccop.filter(dst, origDst);
    } else if (origDst != dst) {
      java.awt.Graphics2D g2 = origDst.createGraphics();
      try {
        g2.drawImage(dst, 0, 0, null);
      } finally {
        g2.dispose();
      }
    }

    return origDst;
  }
예제 #2
0
 public Coin(String filename, int width, int height) {
   dim = new Dim(width, height, 1000, 700);
   ImageIcon ii = new ImageIcon(filename);
   ImageTransparency it = new ImageTransparency();
   ImageConverter ic = new ImageConverter();
   BufferedImage bi = ic.imageToBufferedImage(ii.getImage());
   coinImage = it.makeColorTransparent(bi, Color.white);
   getNewCoordinates();
   isVisible = false;
   isDead = false;
   appearTimer = new Timer();
   disappearTimer = new Timer();
   appear = new Appear();
   disappear = new Disappear();
   appearTimer.schedule(appear, getRandomAppearTime());
   appearTimerRunning = true;
   disappearTimerRunning = false;
   timersPaused = false;
 }
예제 #3
0
 // Conversion Options
 void conversions() {
   double[] weights = ColorProcessor.getWeightingFactors();
   boolean weighted = !(weights[0] == 1d / 3d && weights[1] == 1d / 3d && weights[2] == 1d / 3d);
   // boolean weighted = !(Math.abs(weights[0]-1d/3d)<0.0001 && Math.abs(weights[1]-1d/3d)<0.0001
   // && Math.abs(weights[2]-1d/3d)<0.0001);
   GenericDialog gd = new GenericDialog("Conversion Options");
   gd.addCheckbox("Scale when converting", ImageConverter.getDoScaling());
   String prompt = "Weighted RGB conversions";
   if (weighted)
     prompt +=
         " (" + IJ.d2s(weights[0]) + "," + IJ.d2s(weights[1]) + "," + IJ.d2s(weights[2]) + ")";
   gd.addCheckbox(prompt, weighted);
   gd.showDialog();
   if (gd.wasCanceled()) return;
   ImageConverter.setDoScaling(gd.getNextBoolean());
   Prefs.weightedColor = gd.getNextBoolean();
   if (!Prefs.weightedColor) ColorProcessor.setWeightingFactors(1d / 3d, 1d / 3d, 1d / 3d);
   else if (Prefs.weightedColor && !weighted)
     ColorProcessor.setWeightingFactors(0.299, 0.587, 0.114);
   return;
 }
예제 #4
0
 public Image convert(Image image, ImageDesc desc) {
   for (ImageConverter f : this) {
     image = f.convert(image, desc);
   }
   return image;
 }