コード例 #1
0
ファイル: DebugGraphics.java プロジェクト: GregBowyer/Hotspot
  /** Overrides <code>Graphics.drawImage</code>. */
  public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info.log(toShortString() + " Drawing image: " + img + " at: " + new Point(x, y));
    }

    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawImage(img, x, y, observer);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      int i, count = (info.flashCount * 2) - 1;
      ImageProducer oldProducer = img.getSource();
      ImageProducer newProducer =
          new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor));
      Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer);
      DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();

      Image imageToDraw;
      for (i = 0; i < count; i++) {
        imageToDraw = (i % 2) == 0 ? newImage : img;
        loadImage(imageToDraw);
        graphics.drawImage(imageToDraw, x, y, imageObserver);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
    }
    return graphics.drawImage(img, x, y, observer);
  }
コード例 #2
0
  /**
   * Uses a ImageFilter to return a cropped version of the image. Hopefully useful when handling
   * tilesets.
   */
  public static Image getTile(Image tileset, int x1, int x2, int y1, int y2, int scale) {
    JPanel producer = new JPanel();
    // Crop tileset to grab tile
    ImageFilter cropper = new CropImageFilter(x1, y1, x2 - x1, y2 - y1);
    Image cropped = producer.createImage(new FilteredImageSource(tileset.getSource(), cropper));

    return scaleImage(cropped, scale);
  }
コード例 #3
0
ファイル: DebugGraphics.java プロジェクト: GregBowyer/Hotspot
  /** Overrides <code>Graphics.drawImage</code>. */
  public boolean drawImage(
      Image img,
      int dx1,
      int dy1,
      int dx2,
      int dy2,
      int sx1,
      int sy1,
      int sx2,
      int sy2,
      Color bgcolor,
      ImageObserver observer) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info.log(
          toShortString()
              + " Drawing image: "
              + img
              + " destination: "
              + new Rectangle(dx1, dy1, dx2, dy2)
              + " source: "
              + new Rectangle(sx1, sy1, sx2, sy2)
              + ", bgcolor: "
              + bgcolor);
    }

    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      int i, count = (info.flashCount * 2) - 1;
      ImageProducer oldProducer = img.getSource();
      ImageProducer newProducer =
          new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor));
      Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer);
      DebugGraphicsObserver imageObserver = new DebugGraphicsObserver();

      Image imageToDraw;
      for (i = 0; i < count; i++) {
        imageToDraw = (i % 2) == 0 ? newImage : img;
        loadImage(imageToDraw);
        graphics.drawImage(
            imageToDraw, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, imageObserver);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
    }
    return graphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
  }
コード例 #4
0
 static Icon getOceanDisabledButtonIcon(Image image) {
   Object[] range = (Object[]) UIManager.get("Button.disabledGrayRange");
   int min = 180;
   int max = 215;
   if (range != null) {
     min = ((Integer) range[0]).intValue();
     max = ((Integer) range[1]).intValue();
   }
   ImageProducer prod =
       new FilteredImageSource(image.getSource(), new OceanDisabledButtonImageFilter(min, max));
   return new ImageIconUIResource(Toolkit.getDefaultToolkit().createImage(prod));
 }
コード例 #5
0
ファイル: AquaUtils.java プロジェクト: susotajuraj/jdk8u-jdk
 static Image generateDisabledImage(final Image image) {
   final ImageProducer prod =
       new FilteredImageSource(
           image.getSource(),
           new IconImageFilter() {
             @Override
             int getGreyFor(final int gray) {
               return 255 - ((255 - gray) * 65 / 100);
             }
           });
   return Toolkit.getDefaultToolkit().createImage(prod);
 }
コード例 #6
0
ファイル: AquaUtils.java プロジェクト: susotajuraj/jdk8u-jdk
 static Image generateSelectedDarkImage(final Image image) {
   final ImageProducer prod =
       new FilteredImageSource(
           image.getSource(),
           new IconImageFilter() {
             @Override
             int getGreyFor(final int gray) {
               return gray * 75 / 100;
             }
           });
   return Toolkit.getDefaultToolkit().createImage(prod);
 }
コード例 #7
0
  // ///////////////////////////////////////////////////////////////
  // 双线性内插值算法
  // 参数:img:要缩放的Image对象
  // dstW:目标图像宽
  // dstH:目标图像高
  // comp:组件参数,比如Applet
  //
  // 公式:f(i+u,j+v) = (1-u)(1-v)f(i,j) + (1-u)vf(i,j+1) + u(1-v)f(i+1,j) +
  // uvf(i+1,j+1)
  //
  // ///////////////////////////////////////////////////////////////
  public static Image doubleLinearScale(Image img, int dstW, int dstH) {
    OperateImage OI = new OperateImage();
    Image imgTemp;
    int[] scaled, src;
    int srcW, srcH;
    int R, G, B;
    double widthFactor, heightFactor, tempX, tempY;
    // double srcX_float = 0.0, srcY_float = 0.0;// 坐标的小数部分
    // int srcX_int = 0, srcY_int = 0;// 坐标的整数部分
    src = OI.takeImg(img, img.getWidth(null), img.getHeight(null));
    ColorModel cm = ColorModel.getRGBdefault();
    for (int j = 0; j < src.length; j++) {
      R = cm.getRed(src[j]);
      G = cm.getGreen(src[j]);
      B = cm.getBlue(src[j]);
      if (R >= 200 && G >= 200 && B >= 200) src[j] = 0xffffffff;
      else src[j] = 0xff000000;
    }
    scaled = new int[dstW * dstH]; // 存放缩放后的图片
    srcW = img.getWidth(null);
    srcH = img.getHeight(null);

    widthFactor = srcW / (dstW + 0.0);
    // System.out.println("widthFactor:"+widthFactor);
    heightFactor = srcH / (dstH + 0.0);
    // System.out.println("heightFactor:"+heightFactor);
    for (int a = 0; a < dstH; a++)
      for (int b = 0; b < dstW; b++) {
        tempX = b * widthFactor;
        tempY = a * heightFactor;
        scaled[a * dstW + b] = getDestPixle(src, srcW, srcH, tempX, tempY);
      }
    // System.out.println("双线性内插值算法完成!");
    imgTemp = OI.madeImg(scaled, dstW, dstH);
    ImageFilter filter = new BWFilter();
    return Toolkit.getDefaultToolkit()
        .createImage(new FilteredImageSource(imgTemp.getSource(), filter));
    // return imgTemp;
  }
コード例 #8
0
ファイル: CropTest3.java プロジェクト: 735254599/coloringPad
  public void init() {
    MediaTracker mt = new MediaTracker(this); // 建立一个媒体跟踪器对象

    try {
      url = new URL("file:c:/1.jpg");
    } catch (MalformedURLException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } //

    // 实现完全加载图像
    try {
      im = createImage((ImageProducer) url.getContent()); //
      mt.addImage(im, 0);
      mt.waitForID(0);
    } catch (Exception e) {
      e.printStackTrace();
    }
    // ----------------------
    ImageFilter filter = new CropImageFilter(110, 5, 100, 100); // 获取图片指定位置和大小

    FilteredImageSource fis = new FilteredImageSource(im.getSource(), filter);
    cropped = createImage(fis);
  }
コード例 #9
0
 public Image getImageFromIconSheet(int x, int y) {
   return createImage(
       new FilteredImageSource(
           iconSheet.getSource(), new CropImageFilter(x * 16, y * 16, 16, 16)));
 }
コード例 #10
0
 private static ImageIcon makeGrayImageIcon5(Image img) {
   // RGBImageFilter
   ImageProducer ip = new FilteredImageSource(img.getSource(), new GrayImageFilter());
   return new ImageIcon(Toolkit.getDefaultToolkit().createImage(ip));
 }
コード例 #11
0
 private static ImageIcon makeGrayImageIcon4(Image img) {
   // GrayFilter2
   ImageProducer ip = new FilteredImageSource(img.getSource(), new GrayFilter(true, 50));
   return new ImageIcon(Toolkit.getDefaultToolkit().createImage(ip));
 }
コード例 #12
0
ファイル: JpegEncoder.java プロジェクト: BobSimons/erddap
  /*
   * This method creates and fills three arrays, Y, Cb, and Cr using the
   * input image.
   */
  private void getYCCArray() {
    int[] values = new int[imageWidth * imageHeight];
    int r;
    int g;
    int b;
    int y;
    int x;

    // In order to minimize the chance that grabPixels will throw an exception
    // it may be necessary to grab some pixels every few scanlines and process
    // those before going for more.  The time expense may be prohibitive.
    // However, for a situation where memory overhead is a concern, this may be
    // the only choice.
    PixelGrabber grabber =
        new PixelGrabber(
            imageobj.getSource(), 0, 0, imageWidth, imageHeight, values, 0, imageWidth);
    MaxHsampFactor = 1;
    MaxVsampFactor = 1;

    for (y = 0; y < NumberOfComponents; y++) {
      MaxHsampFactor = Math.max(MaxHsampFactor, HsampFactor[y]);
      MaxVsampFactor = Math.max(MaxVsampFactor, VsampFactor[y]);
    }

    for (y = 0; y < NumberOfComponents; y++) {
      compWidth[y] =
          ((((imageWidth % 8) != 0)
                      ? (((int) Math.ceil((double) imageWidth / 8.0)) * 8)
                      : imageWidth)
                  / MaxHsampFactor)
              * HsampFactor[y];

      if (compWidth[y] != ((imageWidth / MaxHsampFactor) * HsampFactor[y])) {
        lastColumnIsDummy[y] = true;
      }

      // results in a multiple of 8 for compWidth
      // this will make the rest of the program fail for the unlikely
      // event that someone tries to compress an 16 x 16 pixel image
      // which would of course be worse than pointless
      BlockWidth[y] = (int) Math.ceil((double) compWidth[y] / 8.0);
      compHeight[y] =
          ((((imageHeight % 8) != 0)
                      ? (((int) Math.ceil((double) imageHeight / 8.0)) * 8)
                      : imageHeight)
                  / MaxVsampFactor)
              * VsampFactor[y];

      if (compHeight[y] != ((imageHeight / MaxVsampFactor) * VsampFactor[y])) {
        lastRowIsDummy[y] = true;
      }

      BlockHeight[y] = (int) Math.ceil((double) compHeight[y] / 8.0);
    }

    try {
      if (grabber.grabPixels() != true) {
        try {
          throw new AWTException("Grabber returned false: " + grabber.status());
        } catch (Exception e) {
          String2.log(MustBe.throwableToString(e));
        }
      }
    } catch (InterruptedException e) {
    }

    ;
    float[][] Y = new float[compHeight[0]][compWidth[0]];
    float[][] Cr1 = new float[compHeight[0]][compWidth[0]];
    float[][] Cb1 = new float[compHeight[0]][compWidth[0]];
    float[][] Cb2 = new float[compHeight[1]][compWidth[1]];
    float[][] Cr2 = new float[compHeight[2]][compWidth[2]];
    int index = 0;

    for (y = 0; y < imageHeight; ++y) {
      for (x = 0; x < imageWidth; ++x) {
        r = ((values[index] >> 16) & 0xff);
        g = ((values[index] >> 8) & 0xff);
        b = (values[index] & 0xff);

        // The following three lines are a more correct color conversion but
        // the current conversion technique is sufficient and results in a higher
        // compression rate.
        //                Y[y][x] = 16 + (float)(0.8588*(0.299 * (float)r + 0.587 * (float)g + 0.114
        // * (float)b ));
        //                Cb1[y][x] = 128 + (float)(0.8784*(-0.16874 * (float)r - 0.33126 * (float)g
        // + 0.5 * (float)b));
        //                Cr1[y][x] = 128 + (float)(0.8784*(0.5 * (float)r - 0.41869 * (float)g -
        // 0.08131 * (float)b));
        Y[y][x] = (float) (((0.299 * (float) r) + (0.587 * (float) g) + (0.114 * (float) b)));
        Cb1[y][x] =
            128 + (float) (((-0.16874 * (float) r) - (0.33126 * (float) g) + (0.5 * (float) b)));
        Cr1[y][x] =
            128 + (float) (((0.5 * (float) r) - (0.41869 * (float) g) - (0.08131 * (float) b)));
        index++;
      }
    }

    // Need a way to set the H and V sample factors before allowing downsampling.
    // For now (04/04/98) downsampling must be hard coded.
    // Until a better downsampler is implemented, this will not be done.
    // Downsampling is currently supported.  The downsampling method here
    // is a simple box filter.
    Components[0] = Y;

    //        Cb2 = DownSample(Cb1, 1);
    Components[1] = Cb1;

    //        Cr2 = DownSample(Cr1, 2);
    Components[2] = Cr1;
  }
コード例 #13
0
 static Icon getOceanToolBarIcon(Image i) {
   ImageProducer prod = new FilteredImageSource(i.getSource(), new OceanToolBarImageFilter());
   return new ImageIconUIResource(Toolkit.getDefaultToolkit().createImage(prod));
 }
コード例 #14
0
ファイル: AquaUtils.java プロジェクト: susotajuraj/jdk8u-jdk
 static Image generateLightenedImage(Image image, ImageFilter filter) {
   final ImageProducer prod = new FilteredImageSource(image.getSource(), filter);
   return Toolkit.getDefaultToolkit().createImage(prod);
 }