Java Code Examples for java.awt.image.WritableRenderedImage

The following are top voted examples for showing how to use java.awt.image.WritableRenderedImage. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: rastertheque   File: SnapshotImage.java   View source code 6 votes vote down vote up
/**
 * Constructs a <code>SnapshotImage</code> from a <code>PlanarImage</code>
 * source.
 *
 * @param source a <code>PlanarImage</code> source.
 * @throws IllegalArgumentException if source is null.
 */
public SnapshotImage(PlanarImage source) {
    super(new ImageLayout(source), null, null);

    // Record the source image
    this.source = source;
    //  Set image parameters to match the source

    //  Determine which tiles of the source image are writable
    if (source instanceof WritableRenderedImage) {
        WritableRenderedImage wri = (WritableRenderedImage)source;
        wri.addTileObserver(this);

        Point[] pts = wri.getWritableTileIndices();
        if (pts != null) {
            int num = pts.length;
            for (int i = 0; i < num; i++) {
                //  Add these tiles to the active list
                Point p = pts[i];
                activeTiles.add(new Point(p.x, p.y));
           }
        }
    }
}
 
Example 2
Project: rastertheque   File: SnapshotImage.java   View source code 6 votes vote down vote up
/**
 * Receives the information that a tile is either about to become
 * writable, or is about to become no longer writable.
 *
 * @param source the <code>WritableRenderedImage</code> for which we
 *               are an observer.
 * @param tileX the X index of the tile.
 * @param tileY the Y index of the tile.
 * @param willBeWritable true if the tile is becoming writable.
 */
public void tileUpdate(WritableRenderedImage source,
                       int tileX, int tileY,
                       boolean willBeWritable) {
    if (willBeWritable) {
        // If the last Snapshot doesn't have the tile, copy it
        if ((tail != null) && (!tail.hasTile(tileX, tileY))) {
            tail.addTile(createTileCopy(tileX, tileY), tileX, tileY);
        }
        // Add the tile to the active list
        activeTiles.add(new Point(tileX, tileY));
    } else {
        // Remove the tile from the active list
        activeTiles.remove(new Point(tileX, tileY));
    }
}
 
Example 3
Project: soil_sealing   File: JiffleScriptListProcess.java   View source code 6 votes vote down vote up
/**
 * Private method used for executing the script operation on an input image with the selected GridGeometry2D.
 * 
 * @param input RenderedImage to process
 * @param jb jiffleBuilder object with the script to execute
 * @param destGridGeometry GridGeometry object associated to the output image
 * @return img output image generated from the script
 * @throws JiffleException
 */
private RenderedImage jiffleProcessExecution(RenderedImage input, JiffleBuilder jb,
        GridGeometry2D destGridGeometry) throws JiffleException {

    // Setting of the source
    jb.source("image", input, null, false);

    // Now we specify the tile dimensions of the final image
    int tileWidth = input.getTileWidth();
    int tileHeight = input.getTileHeight();
    // Creation of a SampleModel associated with the final image
    SampleModel sm = RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_DOUBLE,
            tileWidth, tileHeight, 1);
    // Selection of the GridEnvelope associated to the input coverage
    final GridEnvelope2D gr2d = destGridGeometry.getGridRange2D();
    // Final image creation
    final WritableRenderedImage img = new TiledImage(gr2d.x, gr2d.y, gr2d.width, gr2d.height,
            0, 0, sm, PlanarImage.createColorModel(sm));
    // Setting of the final image
    jb.dest("dest", img);

    // Finally we run the script and retrieve the resulting image.
    jb.run();

    return img;
}
 
Example 4
Project: rastertheque   File: SnapshotImage.java   View source code 5 votes vote down vote up
/**
 * Creates a snapshot of this image.  This snapshot may be used
 * indefinitely, and will always appear to have the pixel data that
 * this image has currently.  The snapshot is semantically a copy
 * of this image but may be implemented in a more efficient manner.
 * Multiple snapshots taken at different times may share tiles that
 * have not changed, and tiles that are currently static in this
 * image's source do not need to be copied at all.
 *
 * @return a <code>PlanarImage</code> snapshot.
 */
public PlanarImage createSnapshot() {
    if (source instanceof WritableRenderedImage) {
        // Create a new Snapshot
        Snapshot snap = new Snapshot(this);

        // For each active tile:
        Iterator iter = activeTiles.iterator();
        while (iter.hasNext()) {
            Point p = (Point)iter.next();

            // Make a copy and store it in the Snapshot
            Raster tile = createTileCopy(p.x, p.y);
            snap.addTile(tile, p.x, p.y);
        }

        // Add the new Snapshot to the list of snapshots
        if (tail == null) {
            tail = snap;
        } else {
            tail.setNext(snap);
            snap.setPrev(tail);
            tail = snap;
        }

        // Create a proxy and return it
        return new SnapshotProxy(snap);
    } else {
        return source;
    }
}
 
Example 5
Project: rastertheque   File: PlanarImage.java   View source code 5 votes vote down vote up
/**
    * Creates a snapshot, that is, a virtual copy of the image's
    * current contents.  If the image is not a
    * <code>WritableRenderedImage</code>, it is returned unchanged.
    * Otherwise, a <code>SnapshotImage</code> is created and the
    * result of calling its <code>createSnapshot()</code> is
    * returned.
    *
    * @return A <code>PlanarImage</code> with immutable contents.
    */
   public PlanarImage createSnapshot() {
if (this instanceof WritableRenderedImage) {
           if (snapshot == null) {
               synchronized (this) {
                   snapshot = new SnapshotImage(this);
               }
           }
           return snapshot.createSnapshot();

} else {
           return this;
       }
   }
 
Example 6
Project: rastertheque   File: RookIterFactory.java   View source code 5 votes vote down vote up
/**
 * Constructs and returns an instance of WritableRookIter suitable for
 * iterating over the given bounding rectangle within the given
 * WritableRenderedImage source.  If the bounds parameter is null,
 * the entire image will be used.
 *
 * @param im a WritableRenderedImage source.
 * @param bounds the bounding Rectangle for the iterator, or null.
 * @return a WritableRookIter allowing read/write access to the source.
 */
public static WritableRookIter createWritable(WritableRenderedImage im,
                                              Rectangle bounds) {
    if (bounds == null) {
        bounds = new Rectangle(im.getMinX(), im.getMinY(),
                               im.getWidth(), im.getHeight());
    }

    SampleModel sm = im.getSampleModel();
    if (sm instanceof ComponentSampleModel) {
        switch (sm.getDataType()) {
        case DataBuffer.TYPE_BYTE:
            // return new WritableRookIterCSMByte(im, bounds);
        case DataBuffer.TYPE_SHORT:
            // return new WritableRookIterCSMShort(im, bounds);
        case DataBuffer.TYPE_USHORT:
            // return new WritableRookIterCSMUShort(im, bounds);
        case DataBuffer.TYPE_INT:
            // return new WritableRookIterCSMInt(im, bounds);
        case DataBuffer.TYPE_FLOAT:
            // return new WritableRookIterCSMFloat(im, bounds);
        case DataBuffer.TYPE_DOUBLE:
            // return new WritableRookIterCSMDouble(im, bounds);
        }
    }

    return new WritableRookIterFallback(im, bounds);
}
 
Example 7
Project: rastertheque   File: RectIterFactory.java   View source code 5 votes vote down vote up
/**
   * Constructs and returns an instance of WritableRectIter suitable for
   * iterating over the given bounding rectangle within the given
   * WritableRenderedImage source.  If the bounds parameter is null,
   * the entire image will be used.
   *
   * @param im a WritableRenderedImage source.
   * @param bounds the bounding Rectangle for the iterator, or null.
   * @return a WritableRectIter allowing read/write access to the source.
   */
  public static WritableRectIter createWritable(WritableRenderedImage im,
                                                Rectangle bounds) {
      if (bounds == null) {
          bounds = new Rectangle(im.getMinX(), im.getMinY(),
                                 im.getWidth(), im.getHeight());
      }

      SampleModel sm = im.getSampleModel();
      if (sm instanceof ComponentSampleModel) {
          switch (sm.getDataType()) {
          case DataBuffer.TYPE_BYTE:
              return new WritableRectIterCSMByte(im, bounds);
          case DataBuffer.TYPE_SHORT:
              // return new WritableRectIterCSMShort(im, bounds);
break;
          case DataBuffer.TYPE_USHORT:
              // return new WritableRectIterCSMUShort(im, bounds);
break;
          case DataBuffer.TYPE_INT:
              // return new WritableRectIterCSMInt(im, bounds);
break;
          case DataBuffer.TYPE_FLOAT:
              return new WritableRectIterCSMFloat(im, bounds);
          case DataBuffer.TYPE_DOUBLE:
              // return new WritableRectIterCSMDouble(im, bounds);
break;
          }
      }

      return new WritableRectIterFallback(im, bounds);
  }
 
Example 8
Project: rastertheque   File: RandomIterFactory.java   View source code 5 votes vote down vote up
/**
 * Constructs and returns an instance of WritableRandomIter
 * suitable for iterating over the given bounding rectangle within
 * the given WritableRenderedImage source.  If the bounds
 * parameter is null, the entire image will be used.
 *
 * @param im a WritableRenderedImage source.
 * @param bounds the bounding Rectangle for the iterator, or null.
 * @return a WritableRandomIter allowing read/write access to the source.
 */
public static WritableRandomIter createWritable(WritableRenderedImage im,
                                                Rectangle bounds) {
    if (bounds == null) {
        bounds = new Rectangle(im.getMinX(), im.getMinY(),
                               im.getWidth(), im.getHeight());
    }

    SampleModel sm = im.getSampleModel();
    if (sm instanceof ComponentSampleModel) {
        switch (sm.getDataType()) {
        case DataBuffer.TYPE_BYTE:
            // return new WritableRandomIterCSMByte(im, bounds);
        case DataBuffer.TYPE_SHORT:
            // return new WritableRandomIterCSMShort(im, bounds);
        case DataBuffer.TYPE_USHORT:
            // return new WritableRandomIterCSMUShort(im, bounds);
        case DataBuffer.TYPE_INT:
            // return new WritableRandomIterCSMInt(im, bounds);
        case DataBuffer.TYPE_FLOAT:
            // return new WritableRandomIterCSMFloat(im, bounds);
        case DataBuffer.TYPE_DOUBLE:
            // return new WritableRandomIterCSMDouble(im, bounds);
        }
    }

    return new WritableRandomIterFallback(im, bounds);
}
 
Example 9
Project: NK-VirtualGlobe   File: SAISFImage.java   View source code 5 votes vote down vote up
/**
 * Fetch the Java representation of the underlying image from these pixels.
 * This is the same copy that the browser uses to generate texture
 * information from.
 *
 * @return The image reference representing the current state
 */
public WritableRenderedImage getImage() {
	checkAccess(false);
		
	int width = getWidth( );
    int height = getHeight( );
    int components = getComponents( );
    int pixels[] = new int[width*height];
    getPixels( pixels );
		
    return( SFImageUtils.convertDataToRenderedImage( width, height, components, pixels ) );
}
 
Example 10
Project: NK-VirtualGlobe   File: SFImageWrapper.java   View source code 5 votes vote down vote up
/**
 * Fetch the Java representation of the underlying image from these pixels.
 * This is the same copy that the browser uses to generate texture
 * information from.
 *
 * @return The image reference representing the current state
 */
public WritableRenderedImage getImage() {
	checkReadAccess();
	
	int width = getWidth( );
	int height = getHeight( );
	int components = getComponents( );
	int pixels[] = new int[width*height];
	getPixels( pixels );
	
	return( SFImageUtils.convertDataToRenderedImage( width, height, components, pixels ) );
}
 
Example 11
Project: rastertheque   File: WritableRandomIterFallback.java   View source code 4 votes vote down vote up
public WritableRandomIterFallback(WritableRenderedImage im,
                                  Rectangle bounds) {
    super(im, bounds);
    this.wim = im;
}
 
Example 12
Project: rastertheque   File: WritableRandomIterCSMShort.java   View source code 4 votes vote down vote up
public WritableRandomIterCSMShort(WritableRenderedImage im,
                                  Rectangle bounds) {
    super(im, bounds);
}
 
Example 13
Project: rastertheque   File: WritableRandomIterCSMByte.java   View source code 4 votes vote down vote up
public WritableRandomIterCSMByte(WritableRenderedImage im,
                                 Rectangle bounds) {
    super(im, bounds);
}
 
Example 14
Project: rastertheque   File: WritableRandomIterCSMInt.java   View source code 4 votes vote down vote up
public WritableRandomIterCSMInt(WritableRenderedImage im,
                                Rectangle bounds) {
    super(im, bounds);
}
 
Example 15
Project: rastertheque   File: WritableRandomIterCSMDouble.java   View source code 4 votes vote down vote up
public WritableRandomIterCSMDouble(WritableRenderedImage im,
                                   Rectangle bounds) {
    super(im, bounds);
}
 
Example 16
Project: rastertheque   File: WritableRectIterFallback.java   View source code 4 votes vote down vote up
public WritableRectIterFallback(WritableRenderedImage im,
                                Rectangle bounds) {
    super(im, bounds);
    this.wim = im;
}
 
Example 17
Project: rastertheque   File: WritableRandomIterCSMUShort.java   View source code 4 votes vote down vote up
public WritableRandomIterCSMUShort(WritableRenderedImage im,
                                   Rectangle bounds) {
    super(im, bounds);
}
 
Example 18
Project: rastertheque   File: WritableRookIterFallback.java   View source code 4 votes vote down vote up
public WritableRookIterFallback(WritableRenderedImage im,
                                Rectangle bounds) {
    super(im, bounds);
}
 
Example 19
Project: rastertheque   File: WritableRandomIterCSMFloat.java   View source code 4 votes vote down vote up
public WritableRandomIterCSMFloat(WritableRenderedImage im,
                                  Rectangle bounds) {
    super(im, bounds);
}
 
Example 20
Project: rastertheque   File: PlanarImage.java   View source code 3 votes vote down vote up
/**
    * Wraps an arbitrary <code>RenderedImage</code> to produce a
    * <code>PlanarImage</code>.  <code>PlanarImage</code> adds
    * various properties to an image, such as source and sink vectors
    * and the ability to produce snapshots, that are necessary for
    * JAI.
    *
    * <p> If the image is already a <code>PlanarImage</code>, it is
    * simply returned unchanged.  Otherwise, the image is wrapped in
    * a <code>RenderedImageAdapter</code> or
    * <code>WritableRenderedImageAdapter</code> as appropriate.
    *
    * @param image  The <code>RenderedImage</code> to be converted into
    *        a <code>PlanarImage</code>.
    *
    * @return A <code>PlanarImage</code> containing <code>image</code>'s
    *         pixel data.
    *
    * @throws IllegalArgumentException  If <code>image</code> is
    *         <code>null</code>.
    */
   public static PlanarImage wrapRenderedImage(RenderedImage image) {
       if (image == null) {
           throw new IllegalArgumentException(JaiI18N.getString("Generic0"));
       }

if (image instanceof PlanarImage) {
    return (PlanarImage)image;
} else if (image instanceof WritableRenderedImage) {
    return new WritableRenderedImageAdapter(
                          (WritableRenderedImage)image);
} else {
    return new RenderedImageAdapter(image);
       }
   }
 
Example 21
Project: NK-VirtualGlobe   File: MFImageWrapper.java   View source code 3 votes vote down vote up
/**
 * Fetch the Java representation of the underlying image from these pixels.
 * This is the same copy that the browser uses to generate texture
 * information from.
 *
 * @param imgIndex The index of the image in the array
 * @return The image reference representing the current state
 */
public WritableRenderedImage getImage(int imgIndex) {
    // Formula:
    //   Copy all but the last line of getPixel
    //   Invoke the magic code to convert from SFImage to WritableRenderedImage
    throw new RuntimeException("Not yet implemented");
}
 
Example 22
Project: rastertheque   File: WritableRenderedImageAdapter.java   View source code 2 votes vote down vote up
/**
 * Constructs a <code>WritableRenderedImageAdapter</code>.
 *
 * @param im A <code>WritableRenderedImage</code> to be `wrapped'
 * as a <code>PlanarImage</code>.
 * @throws <code>IllegalArgumentException</code> if <code>im</code> is
 *         <code>null</code>.
 */
public WritableRenderedImageAdapter(WritableRenderedImage im) {
    super(im);
    theWritableImage = im;
}
 
Example 23
Project: rastertheque   File: RookIterFactory.java   View source code 2 votes vote down vote up
/**
 * Constructs and returns an instance of WritableRookIter suitable for
 * iterating over the given bounding rectangle within the given
 * WritableRaster source.  If the bounds parameter is null,
 * the entire Raster will be used.
 *
 * @param ras a WritableRaster source.
 * @param bounds the bounding Rectangle for the iterator, or null.
 * @return a WritableRookIter allowing read/write access to the source.
 */
public static WritableRookIter createWritable(WritableRaster ras,
                                              Rectangle bounds) {
    WritableRenderedImage im = new WrapperWRI(ras);
    return createWritable(im, bounds);
}
 
Example 24
Project: rastertheque   File: RectIterFactory.java   View source code 2 votes vote down vote up
/**
 * Constructs and returns an instance of WritableRectIter suitable for
 * iterating over the given bounding rectangle within the given
 * WritableRaster source.  If the bounds parameter is null,
 * the entire Raster will be used.
 *
 * @param ras a WritableRaster source.
 * @param bounds the bounding Rectangle for the iterator, or null.
 * @return a WritableRectIter allowing read/write access to the source.
 */
public static WritableRectIter createWritable(WritableRaster ras,
                                              Rectangle bounds) {
    WritableRenderedImage im = new WrapperWRI(ras);
    return createWritable(im, bounds);
}
 
Example 25
Project: rastertheque   File: RandomIterFactory.java   View source code 2 votes vote down vote up
/**
 * Constructs and returns an instance of WritableRandomIter
 * suitable for iterating over the given bounding rectangle within
 * the given WritableRaster source.  If the bounds parameter is
 * null, the entire Raster will be used.
 *
 * @param ras a WritableRaster source.
 * @param bounds the bounding Rectangle for the iterator, or null.
 * @return a WritableRandomIter allowing read/write access to the source.
 */
public static WritableRandomIter createWritable(WritableRaster ras,
                                                Rectangle bounds) {
    WritableRenderedImage im = new WrapperWRI(ras);
    return createWritable(im, bounds);
}
 
Example 26
Project: NK-VirtualGlobe   File: SFImage.java   View source code 2 votes vote down vote up
/**
 * Fetch the Java representation of the underlying image from these pixels.
 * This is the same copy that the browser uses to generate texture
 * information from.
 *
 * @return The image reference representing the current state
 */
public WritableRenderedImage getImage();
 
Example 27
Project: NK-VirtualGlobe   File: MFImage.java   View source code 2 votes vote down vote up
/**
 * Fetch the Java representation of the underlying image from these pixels.
 * This is the same copy that the browser uses to generate texture
 * information from.
 *
 * @param imgIndex The index of the image in the array
 * @return The image reference representing the current state
 */
public WritableRenderedImage getImage(int imgIndex);
 
Example 28
Project: NK-VirtualGlobe   File: SAIMFImage.java   View source code 2 votes vote down vote up
/**
 * Fetch the Java representation of the underlying image from these pixels.
 * This is the same copy that the browser uses to generate texture
 * information from.
 *
 * @param imgIndex The index of the image in the array
 * @return The image reference representing the current state
 */
public WritableRenderedImage getImage(int imgIndex) {
    checkAccess(false);

    return null;
}