Package java.awt.image

Examples of java.awt.image.WritableRaster


final class ConstantOpImage extends PatternOpImage {

    /** Creates a Raster defining tile (0, 0) of the master pattern. */
    private static Raster makePattern(SampleModel sampleModel,
                                      Number[] bandValues) {
        WritableRaster pattern = RasterFactory.createWritableRaster(
                                 sampleModel, new Point(0, 0));

        int width = sampleModel.getWidth();
        int height = sampleModel.getHeight();
        int dataType = sampleModel.getTransferType();
        int numBands = sampleModel.getNumBands();
 
        switch (dataType) {
        case DataBuffer.TYPE_BYTE:
            int[] bvalues = new int[numBands];
            for (int i = 0; i < numBands; i++) {
                bvalues[i] = bandValues[i].intValue() & ImageUtil.BYTE_MASK;
            }

            /* Put the first scanline in with setPixels. */
            for (int x = 0; x < width; x++) {
                pattern.setPixel(x, 0, bvalues);
            }
            break;

        case DataBuffer.TYPE_USHORT:  // USHORT is less than 127
        case DataBuffer.TYPE_SHORT:
        case DataBuffer.TYPE_INT:
            int[] ivalues = new int[numBands];
            for (int i = 0; i < numBands; i++) {
                ivalues[i] = bandValues[i].intValue();
            }

            /* Put the first scanline in with setPixels. */
            for (int x = 0; x < width; x++) {
                pattern.setPixel(x, 0, ivalues);
            }
            break;

        case DataBuffer.TYPE_FLOAT:
            float[] fvalues = new float[numBands];
            for (int i = 0; i < numBands; i++) {
                fvalues[i] = bandValues[i].floatValue();
            }

            /* Put the first scanline in with setPixels. */
            for (int x = 0; x < width; x++) {
                pattern.setPixel(x, 0, fvalues);
            }
            break;

        case DataBuffer.TYPE_DOUBLE:
            double[] dvalues = new double[numBands];
            for (int i = 0; i < numBands; i++) {
                dvalues[i] = bandValues[i].doubleValue();
            }

            /* Put the first scanline in with setPixels. */
            for (int x = 0; x < width; x++) {
                pattern.setPixel(x, 0, dvalues);
            }
            break;
        }

        /* Copy the first line out. */
        Object odata = pattern.getDataElements(0, 0, width, 1, null);

        /* Use the first line to copy other rows. */
        for (int y = 1; y < height; y++) {
            pattern.setDataElements(0, y, width, 1, odata);
        }

        return pattern;
    }
View Full Code Here


    public Raster computeTile(int tileX, int tileY) {
        /* The origin of the tile. */
        Point org = new Point(tileXToX(tileX), tileYToY(tileY));

        /* Create a new WritableRaster to represent this tile. */
        WritableRaster dest = createWritableRaster(sampleModel, org);

        /* Find the intersection between this tile and the writable bounds. */
        Rectangle rect0 = new Rectangle(org.x, org.y, tileWidth, tileHeight);
        Rectangle destRect = rect0.intersection(computableBounds);
        Rectangle destRect1 = rect0.intersection(getBounds());
View Full Code Here

            int tx = tile.getMinX();
            int ty = tile.getMinY();

            if ( tile != null ) {
                WritableRaster wr =
                    tile instanceof WritableRaster ?
                    ((WritableRaster)tile).createWritableTranslatedChild(0, 0) :
                    tile.createWritableRaster(sampleModel,
                                              tile.getDataBuffer(),
                                              new Point(0, 0));
View Full Code Here

    public Raster computeTile(int tileX, int tileY) {
        // The origin of the tile.
        Point org = new Point(tileXToX(tileX), tileYToY(tileY));

        // Create a new WritableRaster to represent this tile.
        WritableRaster dest = createWritableRaster(sampleModel, org);

        // Find the intersection between this tile and the bounds.
        Rectangle destRect =
            getTileRect(tileX, tileY).intersection(getBounds());
View Full Code Here

                    maxY = im.getMinY();
                }
            }

            // Create minimum Raster.
            WritableRaster wr =
                raster.createCompatibleWritableRaster(minX, minY,
                                                      maxX - minX,
                                                      maxY - minY);

            // Extend the data.
            extend(wr, im);

            // Create a child with same bounds as the target Raster.
            Raster child =
                wr.createChild(raster.getMinX(), raster.getMinY(),
                               raster.getWidth(), raster.getHeight(),
                               raster.getMinX(), raster.getMinY(), null);

            // Copy the data from the child.
            JDKWorkarounds.setRect(raster, child, 0, 0);
View Full Code Here

                    maxY = im.getMinY();
                }
            }

            // Create minimum Raster.
            WritableRaster wr =
                raster.createCompatibleWritableRaster(minX, minY,
                                                      maxX - minX,
                                                      maxY - minY);

            // Extend the data.
            extend(wr, im);

            // Create a child with same bounds as the target Raster.
            Raster child =
                wr.createChild(raster.getMinX(), raster.getMinY(),
                               raster.getWidth(), raster.getHeight(),
                               raster.getMinX(), raster.getMinY(), null);

            // Copy the data from the child.
            JDKWorkarounds.setRect(raster, child, 0, 0);

            return;
        }

        Rectangle rect = new Rectangle();
       
        // Notionally extend the source image by treating it as a single
        // tile of an infinite tiled image.  Adjacent tiles are reflections
        // of one another.

        // Compute the min and max X and Y tile indices of the area
        // intersected by the output raster.
        int minTileX = PlanarImage.XToTileX(minX, imMinX, imWidth);
        int maxTileX = PlanarImage.XToTileX(maxX - 1, imMinX, imWidth);
        int minTileY = PlanarImage.YToTileY(minY, imMinY, imHeight);
        int maxTileY = PlanarImage.YToTileY(maxY - 1, imMinY, imHeight);

        // Loop over the tiles
        for (int tileY = minTileY; tileY <= maxTileY; tileY++) {
            int ty = tileY*imHeight + imMinY;
            for (int tileX = minTileX; tileX <= maxTileX; tileX++) {
                int tx = tileX*imWidth + imMinX;

                // Don't touch the central "tile" (actual image)
                if (tileX == 0 && tileY == 0) {
                    continue;
                }

                boolean flipX = (Math.abs(tileX) % 2) == 1;
                boolean flipY = (Math.abs(tileY) % 2) == 1;

                // Clip the tile bounds against the bounds of the Raster.
                // Keep track of the (x, y) offset of the start of the tile.
                rect.x = tx;
                rect.y = ty;
                rect.width = imWidth;
                rect.height = imHeight;

                int xOffset = 0;
                if (rect.x < minX) {
                    xOffset = minX - rect.x;
                    rect.x = minX;
                    rect.width -= xOffset;
                }
                int yOffset = 0;
                if (rect.y < minY) {
                    yOffset = minY - rect.y;
                    rect.y = minY;
                    rect.height -= yOffset;
                }
                if (rect.x + rect.width > maxX) {
                    rect.width = maxX - rect.x;
                }
                if (rect.y + rect.height > maxY) {
                    rect.height = maxY - rect.y;
                }

                int imX;
                if (flipX) {
                    if (xOffset == 0) {
                        imX = imMinX + imWidth - rect.width;
                    } else {
                        imX = imMinX;
                    }
                } else {
                    imX = imMinX + xOffset;
                }

                int imY;
                if (flipY) {
                    if (yOffset == 0) {
                        imY = imMinY + imHeight - rect.height;
                    } else {
                        imY = imMinY;
                    }
                } else {
                    imY = imMinY + yOffset;
                }

                // Create a child raster with coordinates within the
                // actual image.
                WritableRaster child =
                    RasterFactory.createWritableChild(raster,
                                                      rect.x, rect.y,
                                                      rect.width,
                                                      rect.height,
                                                      imX, imY,
View Full Code Here

     * @param tileX  The X index of the tile.
     * @param tileY  The Y index of the tile.
     */
    public Raster computeTile(int tileX, int tileY) {
        /* Create a new WritableRaster to represent this tile. */
        WritableRaster dest = createTile(tileX, tileY);

        /* Clip the raster bound to image bounds. */
        Rectangle destRect = dest.getBounds().intersection(getBounds());

        PlanarImage srcUnder = getSource(0);
        PlanarImage srcOver = getSource(1);

        Rectangle srcUnderBounds = srcUnder.getBounds();
View Full Code Here

     */
    private void overlayPixels(WritableRaster tile,
                               RenderedImage im,
                               Rectangle rect) {
        // Create a child of tile occupying the intersection area
        WritableRaster child =
            tile.createWritableChild(rect.x, rect.y,
                                     rect.width, rect.height,
                                     rect.x, rect.y,
                                     bandList);

View Full Code Here

            rs.getAsRectangleList(bounds.x, bounds.y,
                                  bounds.width, bounds.height);
        int numRects = rectList.size();
        for(int i = 0; i < numRects; i++) {
            Rectangle rect = (Rectangle)rectList.get(i);
            WritableRaster child =
                tile.createWritableChild(rect.x, rect.y,
                                         rect.width, rect.height,
                                         rect.x, rect.y,
                                         bandList);
            im.copyData(child);
View Full Code Here

        int tyMax = YToTileY(imRect.y + imRect.height - 1);

        // Loop over all in-bound tiles, find ones that have been computed
        for (int j = tyMin; j <= tyMax; j++) {
            for (int i = txMin; i <= txMax; i++) {
                WritableRaster t;
                if ((t = tiles[i - minTileX][j - minTileY]) != null
                    && !isTileLocked(i, j)) {
                    Rectangle tileRect = getTileRect(i, j);
                    tileRect = tileRect.intersection(imRect);
                    if(!tileRect.isEmpty()) {
View Full Code Here

TOP

Related Classes of java.awt.image.WritableRaster

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.