Problem with AreaOpiMage

View: New views
2 Messages — Rating Filter:   Alert me  

Problem with AreaOpiMage

by Daniele Andreis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

I have a problem with an extension of AreaOpImage. I have written an Operation which extends AreaOpImage. I have tested it with an Image with 4 tiles. The operation load correctly the first tile source, the output WritableRaster, and the destRect Resctangle (of the computeRect method). But the second tiles have a very strange dimension (I have used 512x512 tiles, and the dimension of the raster loaded is 512x3 or 1x512), and the thirth doesn't work becouse the destRect, the Rectangle which is the output area, isn't compatible with the input and output Raster. I have tried to load into the memory each tiles, before to call the operation, in order to understand if the problem is in the input image. The program load the tiles without problems. The output file is written by a RectIter object, it's possible that the problem is to use this object as a ended node of the chain?

Does somebody have any idea?


Thanks and regards

--
Daniele Andreis

Re: Problem with AreaOpiMage

by Daniele Andreis :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

I have solve my problem with an extension of AreaOpImage. In this extension I have overridden the computeTile method. I have copied the computeTile of the super class but I have delete some rows of code. I copy the code below.

    public Raster computeTile( int tileX, int tileY ) {
        // return super.computeTile(tileX, tileY);
        if (!cobbleSources) {
            return super.computeTile(tileX, tileY);
        }

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

        /* Clip output rectangle to image bounds. */
        Rectangle rect = new Rectangle(org.x, org.y, sampleModel.getWidth(), sampleModel
                .getHeight());

        int d_x0 = getMinX() + leftPadding;
        int d_y0 = getMinY() + topPadding;

        int d_w = getWidth() - leftPadding - rightPadding;
        d_w = Math.max(d_w, 0);

        int d_h = getHeight() - topPadding - bottomPadding;
        d_h = Math.max(d_h, 0);

        Rectangle theDest = new Rectangle(d_x0, d_y0, d_w, d_h);
        Rectangle destRect = rect.intersection(theDest);
        if ((destRect.width <= 0) || (destRect.height <= 0)) {
            return dest;
        }

        /* account for padding in srcRectangle */
        PlanarImage s = getSource(0);
        // Fix 4639755: Area operations throw exception for
        // destination extending beyond source bounds
        // The default dest image area is the same as the source
        // image area. However, when an ImageLayout hint is set,
        // this might be not true. So the destRect should be the
        // intersection of the provided rectangle, the destination
        // bounds and the source bounds.
        destRect = destRect.intersection(s.getBounds());
        Rectangle srcRect = new Rectangle(destRect);
        srcRect.x -= getLeftPadding();
        srcRect.width += getLeftPadding() + getRightPadding();
        srcRect.y -= getTopPadding();
        srcRect.height += getTopPadding() + getBottomPadding();

        Raster[] sources = new Raster[1];

        // Fetch the padded src rectangle
        sources[0] = (extender != null) ? s.getExtendedData(srcRect, extender) : s.getData(srcRect);

        // Make a destRectangle
        computeRect(sources, dest, destRect);

        // Recycle the source tile
        if (s.overlapsMultipleTiles(srcRect)) {
            recycleTile(sources[0]);
        }
        currentTile++;
        return dest;

    }


I have deleted the code:

        /*
         * The tileWidth and tileHeight of the source image
         * may differ from this tileWidth and tileHeight.
         */
        IntegerSequence srcXSplits = new IntegerSequence();
        IntegerSequence srcYSplits = new IntegerSequence();

        // there is only one source for an AreaOpImage
        s.getSplits(srcXSplits, srcYSplits, srcRect);

        // Initialize new sequences of X splits.
        IntegerSequence xSplits =
            new IntegerSequence(destRect.x, destRect.x + destRect.width);

        xSplits.insert(destRect.x);
        xSplits.insert(destRect.x + destRect.width);
       
        srcXSplits.startEnumeration();
        while (srcXSplits.hasMoreElements()) {
            int xsplit = srcXSplits.nextElement();
            int lsplit = xsplit - getLeftPadding();
            int rsplit = xsplit + getRightPadding();
            xSplits.insert(lsplit);
            xSplits.insert(rsplit);
        }

        // Initialize new sequences of Y splits.
        IntegerSequence ySplits =
            new IntegerSequence(destRect.y, destRect.y + destRect.height);

        ySplits.insert(destRect.y);
        ySplits.insert(destRect.y + destRect.height);
       
        srcYSplits.startEnumeration();
        while (srcYSplits.hasMoreElements()) {
            int ysplit = srcYSplits.nextElement();
            int tsplit = ysplit - getBottomPadding();
            int bsplit = ysplit + getTopPadding();
            ySplits.insert(tsplit);
            ySplits.insert(bsplit);
        }

        /*
         * Divide destRect into sub rectangles based on the source splits,
         * and compute each sub rectangle separately.
         */
        int x1, x2, y1, y2;
        Raster[] sources = new Raster[1];

        ySplits.startEnumeration();
        for (y1 = ySplits.nextElement(); ySplits.hasMoreElements(); y1 = y2) {
            y2 = ySplits.nextElement();

            int h = y2 - y1;
            int py1 = y1 - getTopPadding();
            int py2 = y2 + getBottomPadding();
        int ph = py2 - py1;

            xSplits.startEnumeration();
            for (x1 = xSplits.nextElement();
                 xSplits.hasMoreElements();
                 x1 = x2) {
                x2 = xSplits.nextElement();

                int w = x2 - x1;
                int px1 = x1 - getLeftPadding();
                int px2 = x2 + getRightPadding();
                int pw = px2 - px1;


Someone can explain me if the super class AreaOpImage can work with tiling?

thanks and regards


--
Daniele Andreis