Пример #1
0
  /**
   * Copies data from this images tile grid into wr. wr may extend outside the bounds of this image
   * in which case the data in wr outside the bounds will not be touched.
   *
   * @param wr Raster to fill with image data.
   */
  public void copyToRaster(WritableRaster wr) {
    Rectangle wrR = wr.getBounds();

    int tx0 = getXTile(wrR.x);
    int ty0 = getYTile(wrR.y);
    int tx1 = getXTile(wrR.x + wrR.width - 1);
    int ty1 = getYTile(wrR.y + wrR.height - 1);

    if (tx0 < minTileX) tx0 = minTileX;
    if (ty0 < minTileY) ty0 = minTileY;

    if (tx1 >= minTileX + numXTiles) tx1 = minTileX + numXTiles - 1;
    if (ty1 >= minTileY + numYTiles) ty1 = minTileY + numYTiles - 1;

    final boolean is_INT_PACK = GraphicsUtil.is_INT_PACK_Data(getSampleModel(), false);

    int xtiles = (tx1 - tx0 + 1);
    boolean[] got = new boolean[xtiles * (ty1 - ty0 + 1)];

    // Run through and get the tiles that are just sitting in the
    // cache...
    for (int y = ty0; y <= ty1; y++)
      for (int x = tx0; x <= tx1; x++) {
        Raster r = tiles.getTileNoCompute(x, y);
        if (r == null) continue; // Not there.

        got[x - tx0 + (y - ty0) * xtiles] = true;

        if (is_INT_PACK) GraphicsUtil.copyData_INT_PACK(r, wr);
        else GraphicsUtil.copyData_FALLBACK(r, wr);
      }

    // Run through and pick up the ones we need to compute...
    for (int y = ty0; y <= ty1; y++)
      for (int x = tx0; x <= tx1; x++) {
        if (got[x - tx0 + (y - ty0) * xtiles]) continue; // already have.

        Raster r = getTile(x, y);
        if (is_INT_PACK) GraphicsUtil.copyData_INT_PACK(r, wr);
        else GraphicsUtil.copyData_FALLBACK(r, wr);
      }
  }
Пример #2
0
  public WritableRaster copyData(WritableRaster wr) {
    int tx0 = getXTile(wr.getMinX());
    int ty0 = getYTile(wr.getMinY());
    int tx1 = getXTile(wr.getMinX() + wr.getWidth() - 1);
    int ty1 = getYTile(wr.getMinY() + wr.getHeight() - 1);

    final boolean is_INT_PACK = GraphicsUtil.is_INT_PACK_Data(getSampleModel(), false);

    for (int y = ty0; y <= ty1; y++)
      for (int x = tx0; x <= tx1; x++) {
        Raster r = getTile(x, y);
        if (is_INT_PACK) GraphicsUtil.copyData_INT_PACK(r, wr);
        else GraphicsUtil.copyData_FALLBACK(r, wr);
      }

    return wr;
  }
Пример #3
0
  protected void drawBlockAndCopy(TileBlock[] blocks, WritableRaster wr) {
    if (blocks.length == 1) {
      TileBlock curr = blocks[0];
      int xloc = curr.getXLoc() * tileWidth + tileGridXOff;
      int yloc = curr.getYLoc() * tileHeight + tileGridYOff;
      if ((xloc == wr.getMinX()) && (yloc == wr.getMinY())) {
        // Safe to draw in place...
        drawBlockInPlace(blocks, wr);
        return;
      }
    }

    int maxSz = 0;
    for (int i = 0; i < blocks.length; i++) {
      int sz = ((blocks[i].getWidth() * tileWidth) * (blocks[i].getHeight() * tileHeight));
      if (sz > maxSz) maxSz = sz;
    }
    DataBufferInt dbi = new DataBufferInt(maxSz);
    int[] masks = {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000};
    boolean use_INT_PACK = GraphicsUtil.is_INT_PACK_Data(wr.getSampleModel(), false);

    for (int i = 0; i < blocks.length; i++) {
      TileBlock curr = blocks[i];
      int xloc = curr.getXLoc() * tileWidth + tileGridXOff;
      int yloc = curr.getYLoc() * tileHeight + tileGridYOff;
      Rectangle tb =
          new Rectangle(xloc, yloc, curr.getWidth() * tileWidth, curr.getHeight() * tileHeight);
      tb = tb.intersection(bounds);
      Point loc = new Point(tb.x, tb.y);
      WritableRaster child =
          Raster.createPackedRaster(dbi, tb.width, tb.height, tb.width, masks, loc);
      genRect(child);
      if (use_INT_PACK) GraphicsUtil.copyData_INT_PACK(child, wr);
      else GraphicsUtil.copyData_FALLBACK(child, wr);

      if (Thread.currentThread().isInterrupted()) return;
    }
  }
Пример #4
0
  public void copyToRasterByBlocks(WritableRaster wr) {
    final boolean is_INT_PACK = GraphicsUtil.is_INT_PACK_Data(getSampleModel(), false);

    Rectangle bounds = getBounds();
    Rectangle wrR = wr.getBounds();

    int tx0 = getXTile(wrR.x);
    int ty0 = getYTile(wrR.y);
    int tx1 = getXTile(wrR.x + wrR.width - 1);
    int ty1 = getYTile(wrR.y + wrR.height - 1);

    if (tx0 < minTileX) tx0 = minTileX;
    if (ty0 < minTileY) ty0 = minTileY;

    if (tx1 >= minTileX + numXTiles) tx1 = minTileX + numXTiles - 1;
    if (ty1 >= minTileY + numYTiles) ty1 = minTileY + numYTiles - 1;

    if ((tx1 < tx0) || (ty1 < ty0)) return;

    // System.out.println("WR: " + wrR);
    // System.out.println("ME: " + bounds);

    int insideTx0 = tx0;
    int insideTx1 = tx1;

    int insideTy0 = ty0;
    int insideTy1 = ty1;

    // Now figure out what tiles lie completely inside wr...
    int tx, ty;
    tx = tx0 * tileWidth + tileGridXOff;
    if ((tx < wrR.x) && (bounds.x != wrR.x))
      // Partial tile off the left.
      insideTx0++;

    ty = ty0 * tileHeight + tileGridYOff;
    if ((ty < wrR.y) && (bounds.y != wrR.y))
      // Partial tile off the top.
      insideTy0++;

    tx = (tx1 + 1) * tileWidth + tileGridXOff - 1;
    if ((tx >= (wrR.x + wrR.width)) && ((bounds.x + bounds.width) != (wrR.x + wrR.width)))
      // Partial tile off right
      insideTx1--;

    ty = (ty1 + 1) * tileHeight + tileGridYOff - 1;
    if ((ty >= (wrR.y + wrR.height)) && ((bounds.y + bounds.height) != (wrR.y + wrR.height)))
      // Partial tile off bottom
      insideTy1--;

    int xtiles = insideTx1 - insideTx0 + 1;
    int ytiles = insideTy1 - insideTy0 + 1;
    boolean[] occupied = null;
    if ((xtiles > 0) && (ytiles > 0)) occupied = new boolean[xtiles * ytiles];

    boolean[] got = new boolean[2 * (tx1 - tx0 + 1) + 2 * (ty1 - ty0 + 1)];
    int idx = 0;
    int numFound = 0;
    // Collect all the tiles that we currently have in cache...
    for (int y = ty0; y <= ty1; y++) {
      for (int x = tx0; x <= tx1; x++) {
        Raster ras = tiles.getTileNoCompute(x, y);
        boolean found = (ras != null);
        if ((y >= insideTy0) && (y <= insideTy1) && (x >= insideTx0) && (x <= insideTx1))
          occupied[(x - insideTx0) + (y - insideTy0) * xtiles] = found;
        else got[idx++] = found;

        if (!found) continue;

        numFound++;

        if (is_INT_PACK) GraphicsUtil.copyData_INT_PACK(ras, wr);
        else GraphicsUtil.copyData_FALLBACK(ras, wr);
      }
    }

    // System.out.println("Found: " + numFound + " out of " +
    //                    ((tx1-tx0+1)*(ty1-ty0+1)));

    // Compute the stuff from the middle in the largest possible Chunks.
    if ((xtiles > 0) && (ytiles > 0)) {
      TileBlock block =
          new TileBlock(insideTx0, insideTy0, xtiles, ytiles, occupied, 0, 0, xtiles, ytiles);
      // System.out.println("Starting Splits");
      drawBlock(block, wr);
      // Exception e= new Exception("Foo");
      // e.printStackTrace();
    }

    idx = 0;
    // Fill in the ones that weren't in the cache.
    for (ty = ty0; ty <= ty1; ty++) {

      for (tx = tx0; tx <= tx1; tx++) {
        // At least touch the tile...
        Raster ras = tiles.getTileNoCompute(tx, ty);

        if ((ty >= insideTy0) && (ty <= insideTy1) && (tx >= insideTx0) && (tx <= insideTx1)) {

          if (ras != null) continue;

          // Fill the tile from wr (since wr is full now
          // at least in the middle).
          WritableRaster tile = makeTile(tx, ty);
          if (is_INT_PACK) GraphicsUtil.copyData_INT_PACK(wr, tile);
          else GraphicsUtil.copyData_FALLBACK(wr, tile);

          tiles.setTile(tx, ty, tile);
        } else {
          if (got[idx++]) continue;

          // System.out.println("Computing : " + x + "," + y);

          ras = getTile(tx, ty); // Compute the tile..
          if (Thread.currentThread().isInterrupted()) return;

          if (is_INT_PACK) GraphicsUtil.copyData_INT_PACK(ras, wr);
          else GraphicsUtil.copyData_FALLBACK(ras, wr);
        }
      }
    }

    // System.out.println("Ending Computation: " + this);
  }