You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by mihir <mi...@yahoo.com> on 2013/03/07 17:06:50 UTC

OutofMemory while reading JPEG file Using Apache Batik

Hello All

this is my first post to this forum. i have generated svg file, using
following code,


public class TestSVGGen {

	static BufferedImage img;

	public void paint(SVGGraphics2D g2d) {
		g2d.setPaint(Color.red);
		g2d.fill(new Rectangle(10, 10, 100, 100));
		g2d.drawImage(img, 0, 0, img.getWidth() ,img.getHeight(), null);
		g2d.setSVGCanvasSize(new Dimension(img.getWidth(), img.getHeight()));
	}

	public static void main(String[] args) throws IOException {
		
		img =
ImageIO.read(TestSVGGen.class.getClassLoader().getResourceAsStream("images/test_offscreen.jpg"));
		
		// Get a DOMImplementation.
		DOMImplementation domImpl = GenericDOMImplementation
				.getDOMImplementation();

		// Create an instance of org.w3c.dom.Document.
		String svgNS = "http://www.w3.org/2000/svg";
		Document document = domImpl.createDocument(svgNS, "svg", null);

		// Create an instance of the SVG Generator.
		SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
		

		// Ask the test to render into the SVG Graphics2D implementation.
		TestSVGGen test = new TestSVGGen();
		test.paint(svgGenerator);

		// Finally, stream out SVG to the standard output using
		// UTF-8 encoding.
		boolean useCSS = true; // we want to use CSS style attributes
		File file = new File("image.svg");
		FileOutputStream fos = new FileOutputStream(file);
		Writer out = new OutputStreamWriter(fos, "UTF-8");
		svgGenerator.stream(out, useCSS);
		
		
	}

now , i want to re size this image canvas to 18,000 * 18000 in dimensions
because i want to re size included image to this size , but whenever i try
the following code (only portion of the code)

svgCanvas.setSize(new Dimension(18000, 18000));

the program throws out of memory exception,

what should i do to re size to specified large size , is there any work
around like tiling or segmentation of image .

i am very new to batik so please help me






--
View this message in context: http://batik.2283329.n4.nabble.com/OutofMemory-while-reading-JPEG-file-Using-Apache-Batik-tp4655495.html
Sent from the Batik - Users mailing list archive at Nabble.com.

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


RE: OutofMemory while reading JPEG file Using Apache Batik

Posted by mihir <mi...@yahoo.com>.
Hello Martin 

thank you for your attempt for me.

i want to create JPEG/ PNG file not tiff file without out of memory error.
I used TiledImageTranscoder but it creates TIFF file which i don't want.

can you explain me more where can i use above code ??

do i need to overwrite PngWriter's writeImage method.

Thank You
Mihir Parekh



--
View this message in context: http://batik.2283329.n4.nabble.com/OutofMemory-while-reading-JPEG-file-Using-Apache-Batik-tp4655495p4655518.html
Sent from the Batik - Users mailing list archive at Nabble.com.

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


RE: OutofMemory while reading JPEG file Using Apache Batik

Posted by Martin Gainty <mg...@hotmail.com>.
My attempt was for you to  1)begoff the BufferedImage empty createCompatibleWritableRaster method and2)implement createCompatibleWritableRaster(int width,int height) from another source

(such as java.aw.image.Raster seen here)
    public WritableRaster createCompatibleWritableRaster(int w, int h) {        if (w <= 0 || h <=0) {            throw new RasterFormatException("negative " +                                          ((w <= 0) ? "width" : "height"));        }        SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);        return new SunWritableRaster(sm, new Point(0,0));    }    
but if you want to render a TIFFImage I suppose that will work just as well

Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.

 > Date: Sat, 16 Mar 2013 21:23:37 -0700
> From: mihir_amreli@yahoo.com
> To: batik-users@xmlgraphics.apache.org
> Subject: RE: OutofMemory while reading JPEG file Using Apache Batik
> 
> Hello Martin,
> 
> please look at
> http://painterly.costar.sfu.ca/browser/trunk/libs/jiu/net/sourceforge/jiu/codecs/tiff/TIFFDecoder.java?rev=372
> 
> Thank You
> Mihir Parekh
> 
> 
> 
> --
> View this message in context: http://batik.2283329.n4.nabble.com/OutofMemory-while-reading-JPEG-file-Using-Apache-Batik-tp4655495p4655515.html
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
 		 	   		  

RE: OutofMemory while reading JPEG file Using Apache Batik

Posted by mihir <mi...@yahoo.com>.
Hello Martin,

please look at
http://painterly.costar.sfu.ca/browser/trunk/libs/jiu/net/sourceforge/jiu/codecs/tiff/TIFFDecoder.java?rev=372

Thank You
Mihir Parekh



--
View this message in context: http://batik.2283329.n4.nabble.com/OutofMemory-while-reading-JPEG-file-Using-Apache-Batik-tp4655495p4655515.html
Sent from the Batik - Users mailing list archive at Nabble.com.

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


RE: OutofMemory while reading JPEG file Using Apache Batik

Posted by Martin Gainty <mg...@hotmail.com>.
Mihir

I cant find TiffDecoder.java on the Simon Fraser site..is there another location we can pull from (preferably svn
but git will do)

Thanks,Martin ______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.

 > Date: Sat, 16 Mar 2013 09:50:38 -0700
> From: mihir_amreli@yahoo.com
> To: batik-users@xmlgraphics.apache.org
> Subject: Re: OutofMemory while reading JPEG file Using Apache Batik
> 
> Hello 
> 
> DeWeese Thomas  
> 
> i solved the issue using following great lib
> 
> Tiff Decider
> <http://painterly.costar.sfu.ca/browser/trunk/libs/jiu/net/sourceforge/jiu/codecs/tiff/TIFFDecoder.java?rev=372http://>  
> 
> and 
> 
> PNGJ <http://code.google.com/p/pngj/>   progressive image writer 
> 
> with only 25 MB of memory at a time.
> 
> Thank You
> Mihir Parekh
> 
> 
> 
> --
> View this message in context: http://batik.2283329.n4.nabble.com/OutofMemory-while-reading-JPEG-file-Using-Apache-Batik-tp4655495p4655511.html
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
 		 	   		  

Re: OutofMemory while reading JPEG file Using Apache Batik

Posted by mihir <mi...@yahoo.com>.
Hello 

DeWeese Thomas  

i solved the issue using following great lib

Tiff Decider
<http://painterly.costar.sfu.ca/browser/trunk/libs/jiu/net/sourceforge/jiu/codecs/tiff/TIFFDecoder.java?rev=372http://>  

and 

PNGJ <http://code.google.com/p/pngj/>   progressive image writer 

with only 25 MB of memory at a time.

Thank You
Mihir Parekh



--
View this message in context: http://batik.2283329.n4.nabble.com/OutofMemory-while-reading-JPEG-file-Using-Apache-Batik-tp4655495p4655511.html
Sent from the Batik - Users mailing list archive at Nabble.com.

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


Re: OutofMemory while reading JPEG file Using Apache Batik

Posted by DeWeese Thomas <th...@gmail.com>.
Sorry I'm not familiar enough with the current set of tools to tell you what might process the image progressively (rather than trying to load the whole thing into memory).

On Mar 14, 2013, at 12:49 PM, mihir <mi...@yahoo.com> wrote:

> Hello  DeWeese Thomas 
> 
> i solved the issue and now i have successfully created tiff file 18000 *
> 18000 in dimensions, but it is in tiff format and the size is 35.8 mb . how
> can i convert this tiff to jpeg or png ? if i am use JAVA Advanced Imaging
> API , it throws the same out of memory error. please help me to achieve my
> goal.
> 
> Thanks
> 
> 
> 
> --
> View this message in context: http://batik.2283329.n4.nabble.com/OutofMemory-while-reading-JPEG-file-Using-Apache-Batik-tp4655495p4655505.html
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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


Re: OutofMemory while reading JPEG file Using Apache Batik

Posted by mihir <mi...@yahoo.com>.
Hello  DeWeese Thomas 

i solved the issue and now i have successfully created tiff file 18000 *
18000 in dimensions, but it is in tiff format and the size is 35.8 mb . how
can i convert this tiff to jpeg or png ? if i am use JAVA Advanced Imaging
API , it throws the same out of memory error. please help me to achieve my
goal.

Thanks



--
View this message in context: http://batik.2283329.n4.nabble.com/OutofMemory-while-reading-JPEG-file-Using-Apache-Batik-tp4655495p4655505.html
Sent from the Batik - Users mailing list archive at Nabble.com.

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


Re: OutofMemory while reading JPEG file Using Apache Batik

Posted by mihir <mi...@yahoo.com>.
Hello  DeWeese Thomas

thank you for your prompt reply . i tried your solution and it throws a
following exception

***** CSSEngine: exception property.syntax.error:org.w3c.dom.DOMException:
The "o" identifier is not a valid value for the "shape-rendering" property. 

AttrValue:auto

***** CSSEngine: exception property.syntax.error:org.w3c.dom.DOMException:
The "" identifier is not a valid value for the "shape-rendering" property. 

AttrValue:auto

Exception:org.w3c.dom.DOMException
org.w3c.dom.DOMException: The "" identifier is not a valid value for the
"shape-rendering" property. 
	at
org.apache.batik.css.engine.value.AbstractValueFactory.createInvalidIdentifierDOMException(AbstractValueFactory.java:50)
	at
org.apache.batik.css.engine.value.IdentifierManager.createValue(IdentifierManager.java:48)
	at org.apache.batik.css.engine.CSSEngine$1.property(CSSEngine.java:744)
	at
org.apache.batik.css.engine.CSSEngine.getCascadedStyleMap(CSSEngine.java:768)
	at
org.apache.batik.css.engine.CSSEngine.getComputedStyle(CSSEngine.java:876)
	at
org.apache.batik.bridge.CSSUtilities.getComputedStyle(CSSUtilities.java:82)
	at
org.apache.batik.bridge.CSSUtilities.convertVisibility(CSSUtilities.java:579)
	at
org.apache.batik.bridge.SVGSVGElementBridge.createGraphicsNode(SVGSVGElementBridge.java:142)
	at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:76)
	at
org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:208)
	at
com.mmg.app.svg.TiledImageTranscoder.transcode(TiledImageTranscoder.java:61)
	at
org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
	at
org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
	at
com.mmg.app.svg.ShoeComponentPNGCreator.savePngImage(ShoeComponentPNGCreator.java:601)
	at
com.mmg.app.svg.ShoeComponentPNGCreator.create72DPIOriginalImage(ShoeComponentPNGCreator.java:305)
	at
com.mmg.app.svg.ShoeComponentPNGCreator.processStyleImaging(ShoeComponentPNGCreator.java:226)
	at
com.mmg.app.svg.ShoeComponentPNGCreator.traverseFolder(ShoeComponentPNGCreator.java:186)
	at
com.mmg.app.svg.ShoeComponentPNGCreator.main(ShoeComponentPNGCreator.java:662)






--
View this message in context: http://batik.2283329.n4.nabble.com/OutofMemory-while-reading-JPEG-file-Using-Apache-Batik-tp4655495p4655503.html
Sent from the Batik - Users mailing list archive at Nabble.com.

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


Re: OutofMemory while reading JPEG file Using Apache Batik

Posted by Thomas DeWeese <th...@gmail.com>.
Your title seems to mismatch your description (such as it is).  If you are
trying to read a JPEG so large that it won't fit in memory I think you are
out of luck with Batik.
However if the problem is that you are trying to write a JPEG too large for
memory (which seems to match you saying svgCanvas.setSize(...) you might
try using the TiledImageTranscoderfrom the contrib directory which will
write a Tiled Tiff file rendering strips of the image rather than the
entire image at once.  I've used it in the past to print very large images
from Batik.

BTW have you adjusted the default Java memory partition (-Xmx)?  That might
help you although 18K x 18K is more than 1GB of memory so you would likely
need a 64bit version of Java so you can allocate more than 2GB of memory
and performance is likely to suffer.

-Thomas



On Thu, Mar 7, 2013 at 11:06 AM, mihir <mi...@yahoo.com> wrote:

> Hello All
>
> this is my first post to this forum. i have generated svg file, using
> following code,
>
>
> public class TestSVGGen {
>
>         static BufferedImage img;
>
>         public void paint(SVGGraphics2D g2d) {
>                 g2d.setPaint(Color.red);
>                 g2d.fill(new Rectangle(10, 10, 100, 100));
>                 g2d.drawImage(img, 0, 0, img.getWidth() ,img.getHeight(),
> null);
>                 g2d.setSVGCanvasSize(new Dimension(img.getWidth(),
> img.getHeight()));
>         }
>
>         public static void main(String[] args) throws IOException {
>
>                 img =
>
> ImageIO.read(TestSVGGen.class.getClassLoader().getResourceAsStream("images/test_offscreen.jpg"));
>
>                 // Get a DOMImplementation.
>                 DOMImplementation domImpl = GenericDOMImplementation
>                                 .getDOMImplementation();
>
>                 // Create an instance of org.w3c.dom.Document.
>                 String svgNS = "http://www.w3.org/2000/svg";
>                 Document document = domImpl.createDocument(svgNS, "svg",
> null);
>
>                 // Create an instance of the SVG Generator.
>                 SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
>
>
>                 // Ask the test to render into the SVG Graphics2D
> implementation.
>                 TestSVGGen test = new TestSVGGen();
>                 test.paint(svgGenerator);
>
>                 // Finally, stream out SVG to the standard output using
>                 // UTF-8 encoding.
>                 boolean useCSS = true; // we want to use CSS style
> attributes
>                 File file = new File("image.svg");
>                 FileOutputStream fos = new FileOutputStream(file);
>                 Writer out = new OutputStreamWriter(fos, "UTF-8");
>                 svgGenerator.stream(out, useCSS);
>
>
>         }
>
> now , i want to re size this image canvas to 18,000 * 18000 in dimensions
> because i want to re size included image to this size , but whenever i try
> the following code (only portion of the code)
>
> svgCanvas.setSize(new Dimension(18000, 18000));
>
> the program throws out of memory exception,
>
> what should i do to re size to specified large size , is there any work
> around like tiling or segmentation of image .
>
> i am very new to batik so please help me
>
>
>
>
>
>
> --
> View this message in context:
> http://batik.2283329.n4.nabble.com/OutofMemory-while-reading-JPEG-file-Using-Apache-Batik-tp4655495.html
> Sent from the Batik - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>