xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Raja Nagendra Kumar <nagendra.r...@tejasoft.com>
Subject Optimum Memory (can compromise on speed) way to Transcode
Date Fri, 14 Aug 2015 07:40:43 GMT
Hi,

We have a huge svg of size

<svg width="3750" height="12245" xmlns="http://www.w3.org/2000/svg">

How to optimse the below code for  optimum memory.. say it should not 
take x times more memory than width etc.. i.e in case the api allows 
writing line by line of slice by slice converstion rather than entire 
width x height x y bytes metrics etc. This way, I hope memory 
requirements can be as low as possible through slice or line by line 
writing approach to give infinate size svg images conversion.

The code used is

TranscoderInput bInputSVG =newTranscoderInput(lInputReader);
TranscoderOutput  bOutputPNG =newTranscoderOutput(lOutputStream);
Transcoder bTranscoder = aTranscoderExt.getTranscoder();
bTranscoder.addTranscodingHint(ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER,newFloat(0.256));
bTranscoder.addTranscodingHint(ImageTranscoder.KEY_BACKGROUND_COLOR, Color.white);
bTranscoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,newFloat(1.0));
//bTranscoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, new Float(svgWidth));
bTranscoder.transcode(bInputSVG, bOutputPNG);


but we are getting out of memory error

java.lang.OutOfMemoryError: Java heap space
     at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75)
     at java.awt.image.Raster.createPackedRaster(Raster.java:467)
     at 
java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)
     at java.awt.image.BufferedImage.<init>(BufferedImage.java:340)
     at 
org.apache.batik.transcoder.image.PNGTranscoder.createImage(PNGTranscoder.java:59)
     at 
org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:116)
     at 
org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
     at 
org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
     at 
com.teja.svg.converter.java.utils.TranscodeUtils.doTranscode(TranscodeUtils.java:58)
     at 
com.teja.svg.converter.java.test.TestSVGPNGTranscoder.testTranscode(TestSVGPNGTranscoder.java:26)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at 
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
     at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
     at 
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
     at 
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
     at 
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)


Process finished with exit code -1

Any pointers to optimum api usage for least memory irrespective of svg 
image sizes would help a lot.

Regards
Nagendra
-- 

TejaSoft Innovations Pvt. Ltd. <http://www.tejasoft.com>

Raja Nagendra Kumar / Java Code Surgeon (Audit & Repair)
nagendra.raja@tejasoft.com <mailto:nagendra.raja@tejasoft.com>/ 
+91-9886723872

TejaSoft Innovations Pvt. Ltd.
+91-80-28436591
17c/17, Nandi Gardens, Sector-2, J.P Nagar 9th Phase, Avalahalli, 
Bangalore-560108, KA, IN
www.tejasoft.com <http://www.tejasoft.com>


Mime
View raw message