Exemplo n.º 1
0
  // 이미지 높이
  public int getImageHeight(String pathname) {
    int height = -1;

    File file = new File(pathname);
    if (!file.exists()) return height;

    ParameterBlock pb = new ParameterBlock();
    pb.add(pathname);
    RenderedOp rOp = JAI.create("fileload", pb);

    BufferedImage bi = rOp.getAsBufferedImage();

    height = bi.getHeight();

    return height;
  }
Exemplo n.º 2
0
  // 이미지 폭
  public int getImageWidth(String pathname) {
    int width = -1;

    File file = new File(pathname);
    if (!file.exists()) return width;

    ParameterBlock pb = new ParameterBlock();
    pb.add(pathname);
    RenderedOp rOp = JAI.create("fileload", pb);

    BufferedImage bi = rOp.getAsBufferedImage();

    width = bi.getWidth();

    return width;
  }
Exemplo n.º 3
0
  @Test
  public void test2BandsBug() {
    // build a transparent image
    BufferedImage image = new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY);
    RenderedOp img = BandMergeDescriptor.create(null, 0, false, null, image, image);

    image = img.getAsBufferedImage();

    // create a palette out of it
    RenderedImage indexed = quantize(image);
    assertTrue(indexed.getColorModel() instanceof IndexColorModel);
    IndexColorModel icm = (IndexColorModel) indexed.getColorModel();

    // png encoder go mad if they get a one element palette, we need at
    // least two
    assertEquals(2, icm.getMapSize());
  }
Exemplo n.º 4
0
  /**
   * Overrides to use the same method to slice the tiles than {@code MetatileMapOutputFormat} so the
   * GeoServer settings such as use native accel are leveraged in the same way when calling {@link
   * RenderedImageMapResponse#formatImageOutputStream},
   *
   * @see org.geowebcache.layer.MetaTile#createTile(int, int, int, int)
   */
  @Override
  public RenderedImage createTile(
      final int x, final int y, final int tileWidth, final int tileHeight) {
    // check image type
    final int type;
    if (metaTileImage instanceof PlanarImage) {
      type = 1;
    } else if (metaTileImage instanceof BufferedImage) {
      type = 2;
    } else {
      type = 0;
    }

    // now do the splitting
    RenderedImage tile;
    switch (type) {
      case 0:
        // do a crop, and then turn it into a buffered image so that we can release
        // the image chain
        RenderedOp cropped =
            GTCropDescriptor.create(
                metaTileImage,
                Float.valueOf(x),
                Float.valueOf(y),
                Float.valueOf(tileWidth),
                Float.valueOf(tileHeight),
                NO_CACHE);
        tile = cropped.getAsBufferedImage();
        disposeLater(cropped);
        break;
      case 1:
        final PlanarImage pImage = (PlanarImage) metaTileImage;
        final WritableRaster wTile =
            WritableRaster.createWritableRaster(
                pImage.getSampleModel().createCompatibleSampleModel(tileWidth, tileHeight),
                new Point(x, y));
        Rectangle sourceArea = new Rectangle(x, y, tileWidth, tileHeight);
        sourceArea = sourceArea.intersection(pImage.getBounds());

        // copying the data to ensure we don't have side effects when we clean the cache
        pImage.copyData(wTile);
        if (wTile.getMinX() != 0 || wTile.getMinY() != 0) {
          tile =
              new BufferedImage(
                  pImage.getColorModel(),
                  (WritableRaster) wTile.createTranslatedChild(0, 0),
                  pImage.getColorModel().isAlphaPremultiplied(),
                  null);
        } else {
          tile =
              new BufferedImage(
                  pImage.getColorModel(),
                  wTile,
                  pImage.getColorModel().isAlphaPremultiplied(),
                  null);
        }
        break;
      case 2:
        final BufferedImage image = (BufferedImage) metaTileImage;
        tile = image.getSubimage(x, y, tileWidth, tileHeight);
        break;
      default:
        throw new IllegalStateException(
            Errors.format(
                ErrorKeys.ILLEGAL_ARGUMENT_$2,
                "metaTile class",
                metaTileImage.getClass().toString()));
    }

    return tile;
  }
Exemplo n.º 5
0
 private static double getRenderTime(RenderedOp op) {
   long t0 = System.nanoTime();
   op.getAsBufferedImage();
   long t1 = System.nanoTime();
   return (t1 - t0) / (1000.0 * 1000.0);
 }