xmlgraphics-batik-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 48407] OutOfMemoryError, when zooming in svg document
Date Tue, 22 Jun 2010 11:36:57 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=48407

--- Comment #4 from Christoph Bimminger <christoph.bimminger@systema.info> 2010-06-22
07:36:51 EDT ---
The bug also occurs with up-to-date nightly build batik-src-10-05-21.

I analyzed the bug, and tried to fix it with a local hack. In
org.apache.batik.ext.awt.image.renderable.ClipRable8Bit an alpha mask is
created, where the BufferedImage is used for. If I see right, the Alpha Mask -
which supports BYTE_GRAY, only contains 100% white area in the shape region. 

For my purpose, I removed the BufferedImage completely. The "hacked"
createRendering method looks like posted below (see lines commented-out). I
assume that there might occur rendering bugs when image shapes are not
rectangular? But better such a rendering bug than the OutOfMemoryError.

A task would, in my humble opinion, be to eliminate the BufferedImage here and
use kind of "ShapeImage" that delegates to the shape for the alpha mask. The
shape can be used to determine the alpha value of each pixel when multiplying
the image with the alpha mask, without needing a large BufferedImage. But it
will be tricky to find a structure to multiply image value and alpha intensity,
on something different to a BufferedImage. Can a BufferedImage in original
image dimension be used, and be scaled "on the fly" when rendering, without
requireing large memory for a scaled BufferedImage?

public RenderedImage createRendering(RenderContext rc) {

        AffineTransform usr2dev = rc.getTransform();

        // Just copy over the rendering hints.
        RenderingHints rh = rc.getRenderingHints();
        if (rh == null)  rh = new RenderingHints(null);

        Shape aoi = rc.getAreaOfInterest();
        if (aoi == null) aoi = getBounds2D();

        Rectangle2D rect     = getBounds2D();
        Rectangle2D clipRect = clipPath.getBounds2D();
        Rectangle2D aoiRect  = aoi.getBounds2D();

        if ( ! rect.intersects(clipRect) )
            return null;
        Rectangle2D.intersect(rect, clipRect, rect);


        if ( ! rect.intersects(aoiRect) )
            return null;
        Rectangle2D.intersect(rect, aoi.getBounds2D(), rect);

        Rectangle devR = usr2dev.createTransformedShape(rect).getBounds();

        if ((devR.width == 0) || (devR.height == 0) || false)
            return null;

//        BufferedImage bi = new BufferedImage(devR.width, devR.height,
//                                             BufferedImage.TYPE_BYTE_GRAY);

        Shape devShape = usr2dev.createTransformedShape(getClipPath());
        Rectangle devAOIR;
        devAOIR = usr2dev.createTransformedShape(aoi).getBounds();

//        Graphics2D g2d = GraphicsUtil.createGraphics(bi, rh);

        if (false) {
            java.util.Set s = rh.keySet();
            java.util.Iterator i = s.iterator();
            while (i.hasNext()) {
                Object o = i.next();
                System.out.println("XXX: " + o + " -> " + rh.get(o));
            }
        }
//        g2d.translate(-devR.x, -devR.y);
//        g2d.setPaint(Color.white);
//        g2d.fill(devShape);
//        g2d.dispose();

        RenderedImage ri;
        ri = getSource().createRendering(new RenderContext(usr2dev, rect, rh));

        CachableRed cr, clipCr;
        cr = RenderedImageCachableRed.wrap(ri);
//        clipCr = new BufferedImageCachableRed(bi, devR.x, devR.y);
        CachableRed ret = cr;
//        CachableRed ret = new MultiplyAlphaRed(cr, clipCr);

          // Pad back out to the proper size...
        ret = new PadRed(ret, devAOIR, PadMode.ZERO_PAD, rh);

        return ret;
    }

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org


Mime
View raw message