Package java.awt.image

Examples of java.awt.image.Raster


        rgb.getHeight(),
        BufferedImage.TYPE_INT_RGB);
    DataBufferInt dbi = new DataBufferInt(
        rgb.getData(),
        rgb.getHeight() * rgb.getWidth());
    Raster r = Raster.createRaster(
        im.getSampleModel(),
        dbi,
        null);
    im.setData(r);
    return im;
View Full Code Here


     * @param rect the region to extract from image.
     */

    protected void getTilePixels(Rectangle rect) {
        // Grab the pixels
        Raster src = image.getData(rect);
        int col = (int) rect.getX();
        int row = (int) rect.getY();
        int rows = (int) rect.getHeight();
        int cols = (int) rect.getWidth();
        src.getPixels(col, row, cols, rows, _pixels);
    }
View Full Code Here

      Integer key = new Integer( parallelPos );
      Object o =  childRasterCache.get( key );
      if ( o !=null ) return (Raster) o;
      else {
        Raster r;
        if ( info.isVertical ) r = raster.createChild( 0, parallelPos, this.perpendicularLength, info.parallelLength-parallelPos, 0, 0, null );
        else r = raster.createChild( parallelPos, 0, info.parallelLength-parallelPos, this.perpendicularLength, 0, 0, null );
        childRasterCache.put( key, r );
                                //System.out.println( "Storing child raster in cache. Position: " + Integer.toString(parallelPos) );
        return r;
View Full Code Here

     * {@inheritDoc}
     */
    public final Raster getRaster(int x, int y, int w, int h) {         
        // If working raster is big enough, reuse it. Otherwise,
        // build a large enough new one.
        Raster raster = saved;
        if (raster == null ||
            raster.getWidth() < w || raster.getHeight() < h)
        {
            raster = getCachedRaster(model, w, h);
            saved = raster;
        }

        // Access raster internal int array. Because we use a DirectColorModel,
        // we know the DataBuffer is of type DataBufferInt and the SampleModel
        // is SinglePixelPackedSampleModel.
        // Adjust for initial offset in DataBuffer and also for the scanline
        // stride.
        DataBufferInt rasterDB = (DataBufferInt)raster.getDataBuffer();
        int[] pixels = rasterDB.getBankData()[0];
        int off = rasterDB.getOffset();
        int scanlineStride = ((SinglePixelPackedSampleModel)
                              raster.getSampleModel()).getScanlineStride();
        int adjust = scanlineStride - w;
       
        fillRaster(pixels, off, adjust, x, y, w, h); // delegate to subclass
       
        return raster;
View Full Code Here

    private static synchronized Raster getCachedRaster(ColorModel cm,
                                                       int w, int h)
    {
        if (cm == cachedModel) {
            if (cached != null) {
                Raster ras = (Raster) cached.get();
                if (ras != null &&
                    ras.getWidth() >= w &&
                    ras.getHeight() >= h)
                {
                    cached = null;
                    return ras;
                }
            }
View Full Code Here

     */
    private static synchronized void putCachedRaster(ColorModel cm,
                                                     Raster ras)
    {
        if (cached != null) {
            Raster cras = (Raster) cached.get();
            if (cras != null) {
                int cw = cras.getWidth();
                int ch = cras.getHeight();
                int iw = ras.getWidth();
                int ih = ras.getHeight();
                if (cw >= iw && ch >= ih) {
                    return;
                }
View Full Code Here

                    final BufferedImage i = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
                    try {
                        i.createGraphics().drawImage(scaled, 0, 0, width, height, null);
                        image = i;
                        // check outcome
                        final Raster raster = i.getData();
                        int[] pixel = new int[3];
                        pixel = raster.getPixel(0, 0, pixel);
                        if (pixel[0] != 0 || pixel[1] != 0 || pixel[2] != 0) image = i;
                    } catch (final Exception e) {
                        //java.lang.ClassCastException: [I cannot be cast to [B
                    }
View Full Code Here

public Raster getData(Rectangle bounds) {
     int startX = XToTileX(bounds.x);
     int startY = YToTileY(bounds.y);
     int endX = XToTileX(bounds.x + bounds.width - 1);
     int endY = YToTileY(bounds.y + bounds.height - 1);
     Raster tile;

     if ((startX == endX) && (startY == endY)) {
         tile = getTile(startX, startY);
         return tile.createChild(bounds.x, bounds.y,
                                 bounds.width, bounds.height,
                                 bounds.x, bounds.y, null);
     } else {
         // Create a WritableRaster of the desired size
         SampleModel sm =
             sampleModel.createCompatibleSampleModel(bounds.width,
                                                    bounds.height);

         // Translate it
         WritableRaster dest =
             Raster.createWritableRaster(sm, bounds.getLocation());

         for (int j = startY; j <= endY; j++) {
             for (int i = startX; i <= endX; i++) {
                 tile = getTile(i, j);
                 Rectangle intersectRect =
                     bounds.intersection(tile.getBounds());
                 Raster liveRaster = tile.createChild(intersectRect.x,
                                                      intersectRect.y,
                                                      intersectRect.width,
                                                      intersectRect.height,
                                                      intersectRect.x,
                                                      intersectRect.y,
View Full Code Here

  * @return a reference to the supplied WritableRaster, or to a
  *         new WritableRaster if the supplied one was null.
  */
public WritableRaster copyData(WritableRaster dest) {
     Rectangle bounds;
     Raster tile;
                
     if (dest == null) {
         bounds = getBounds();
         Point p = new Point(minX, minY);
         /* A SampleModel to hold the entire image. */
         SampleModel sm = sampleModel.createCompatibleSampleModel(
                                      width, height);
         dest = Raster.createWritableRaster(sm, p);
     } else {
         bounds = dest.getBounds();
     }
    
     int startX = XToTileX(bounds.x);
     int startY = YToTileY(bounds.y);
     int endX = XToTileX(bounds.x + bounds.width - 1);
     int endY = YToTileY(bounds.y + bounds.height - 1);
        
     for (int j = startY; j <= endY; j++) {
         for (int i = startX; i <= endX; i++) {
             tile = getTile(i, j);
             Rectangle intersectRect =
                 bounds.intersection(tile.getBounds());
             Raster liveRaster = tile.createChild(intersectRect.x,
                                                  intersectRect.y,
                                                  intersectRect.width,
                                                  intersectRect.height,
                                                  intersectRect.x,
                                                  intersectRect.y,
View Full Code Here

        public void copyTo(BufferedImage image, double gamma, Rectangle roi) {
            boolean flip = origin() == IPL_ORIGIN_BL; // need to add support for ROI..

            ByteBuffer in  = getByteBuffer(roi == null ? 0 : roi.y*widthStep() + roi.x*nChannels());
            SampleModel sm = image.getSampleModel();
            Raster r       = image.getRaster();
            DataBuffer out = r.getDataBuffer();
            int x = -r.getSampleModelTranslateX();
            int y = -r.getSampleModelTranslateY();
            int step = sm.getWidth()*sm.getNumBands();
            int channels = sm.getNumBands();
            if (sm instanceof ComponentSampleModel) {
                step = ((ComponentSampleModel)sm).getScanlineStride();
                channels = ((ComponentSampleModel)sm).getPixelStride();
View Full Code Here

TOP

Related Classes of java.awt.image.Raster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.