Exemplo n.º 1
0
 public float interpolate(float xpos, float ypos, float[][] f, boolean periodic) {
   Interpolation.setSpace(ssx, ssy);
   // Normal Interpolation
   if (!periodic) {
     if (interpolationMethod == 0) return Interpolation.biLin(xpos, ypos, f);
     else return Interpolation.biCubic(xpos, ypos, f);
   }
   // Periodic Interpolation
   else {
     if (interpolationMethod == 0) return Interpolation.per_BiLin(xpos, ypos, f);
     else return Interpolation.per_BiCub(xpos, ypos, f);
   }
 }
Exemplo n.º 2
0
 private RenderedOp createScaledImage(
     RenderedImage sourceImage, S2Resolution resolution, int level) {
   int sourceWidth = sourceImage.getWidth();
   int sourceHeight = sourceImage.getHeight();
   int targetWidth = imageLayouts[0].width >> level;
   int targetHeight = imageLayouts[0].height >> level;
   float scaleX = (float) targetWidth / (float) sourceWidth;
   float scaleY = (float) targetHeight / (float) sourceHeight;
   float corrFactorX = resolution == S2Resolution.R20M ? R20M_X_FACTOR : R60M_X_FACTOR;
   float corrFactorY = resolution == S2Resolution.R20M ? R20M_Y_FACTOR : R60M_Y_FACTOR;
   final Dimension tileDim = getTileDim(targetWidth, targetHeight);
   ImageLayout imageLayout = new ImageLayout();
   imageLayout.setTileWidth(tileDim.width);
   imageLayout.setTileHeight(tileDim.height);
   RenderingHints renderingHints =
       new RenderingHints(
           JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_ZERO));
   renderingHints.put(JAI.KEY_IMAGE_LAYOUT, imageLayout);
   RenderedOp scaledImage =
       ScaleDescriptor.create(
           sourceImage,
           scaleX * corrFactorX,
           scaleY * corrFactorY,
           0F,
           0F,
           Interpolation.getInstance(Interpolation.INTERP_NEAREST),
           renderingHints);
   if (scaledImage.getWidth() != targetWidth || scaledImage.getHeight() != targetHeight) {
     return CropDescriptor.create(
         scaledImage, 0.0F, 0.0F, (float) targetWidth, (float) targetHeight, null);
   } else {
     return scaledImage;
   }
 }
Exemplo n.º 3
0
 private int calcHashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((interpolation == null) ? 0 : interpolation.hashCode());
   result = prime * result + Arrays.hashCode(x);
   result = prime * result + Arrays.hashCode(y);
   return result;
 }
Exemplo n.º 4
0
 @Override
 public Vector3 interpolate(Vector3 target, float alpha, Interpolation interpolator) {
   return lerp(target, interpolator.apply(0f, 1f, alpha));
 }
Exemplo n.º 5
0
  /**
   * Taken from http://today.java.net/pub/a/today/2007/04/03/perils-of-image- getscaledinstance.html
   * License: unknown Convenience method that returns a scaled instance of the provided {@code
   * BufferedImage}.
   *
   * @param img the original image to be scaled
   * @param targetWidth the desired width of the scaled instance, in pixels
   * @param targetHeight the desired height of the scaled instance, in pixels
   * @param hint
   * @param higherQuality if true, this method will use a multi-step scaling technique that provides
   *     higher quality than the usual one-step technique (only useful in downscaling cases, where
   *     {@code targetWidth} or {@code targetHeight} is smaller than the original dimensions, and
   *     generally only when the {@code BILINEAR} hint is specified)
   * @return a scaled version of the original {@code BufferedImage}
   */
  public static BufferedImage getScaledInstance(
      final Image img,
      int width,
      int height,
      final Interpolation interpolation,
      final boolean higherQuality) {
    final double faktor =
        Math.max((double) img.getWidth(null) / width, (double) img.getHeight(null) / height);
    width = Math.max((int) (img.getWidth(null) / faktor), 1);
    height = Math.max((int) (img.getHeight(null) / faktor), 1);
    if (faktor == 1.0 && img instanceof BufferedImage) {
      return (BufferedImage) img;
    }

    Image ret = img;
    int w, h;
    if (higherQuality) {
      // Use multi-step technique: start with original size, then
      // scale down in multiple passes with drawImage()
      // until the target size is reached
      w = Math.max(width, img.getWidth(null));
      h = Math.max(height, img.getHeight(null));
    } else {
      // Use one-step technique: scale directly from original
      // size to target size with a single drawImage() call
      w = width;
      h = height;
    }

    do {
      if (higherQuality && w > width) {
        w /= 2;
        if (w < width) {
          w = width;
        }
      }

      if (higherQuality && h > height) {
        h /= 2;
        if (h < height) {
          h = height;
        }
      }
      // use 6 as default image type. java versions <16 u17 return type 0
      // for loaded pngs
      int type = 6;
      if (ret instanceof BufferedImage) {
        type = ((BufferedImage) ret).getType();
        if (type == 0) {
          type = 6;
        }
      }
      if (w == 0) {
        final int o = 2;
      }
      final BufferedImage tmp = new BufferedImage(w, h, type);
      final Graphics2D g2 = tmp.createGraphics();
      g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, interpolation.getHint());
      g2.drawImage(ret, 0, 0, w, h, null);
      g2.dispose();

      ret = tmp;
    } while (w != width || h != height);

    return (BufferedImage) ret;
  }