1 17 18 19 20 package org.apache.fop.image; 21 22 import java.io.IOException ; 23 24 import org.apache.xmlgraphics.image.codec.png.PNGRed; 25 import org.apache.xmlgraphics.image.codec.png.PNGDecodeParam; 26 import org.apache.xmlgraphics.image.codec.util.SeekableStream; 27 import org.apache.xmlgraphics.image.rendered.CachableRed; 28 import org.apache.commons.io.IOUtils; 29 30 36 public class PNGImage extends XmlGraphicsCommonsImage { 37 38 42 public PNGImage(FopImage.ImageInfo imgReader) { 43 super(imgReader); 44 this.loaded = 0; } 46 47 51 protected CachableRed decodeImage(SeekableStream stream) throws IOException { 52 PNGDecodeParam param = new PNGDecodeParam(); 53 param.setPerformGammaCorrection(true); 54 param.setDisplayExponent(2.2f); PNGRed red = new PNGRed(stream, param); 56 String unit = (String )red.getProperty("pixel_units"); 57 if ("Meters".equals(unit)) { 58 this.dpiHorizontal = ((Integer )red.getProperty("x_pixels_per_unit")).intValue() 59 * 25.4f / 1000f; 60 this.dpiVertical = ((Integer )red.getProperty("y_pixels_per_unit")).intValue() 61 * 25.4f / 1000f; 62 } 63 return red; 64 } 65 66 72 protected boolean loadOriginalData() { 73 try { 74 seekableInput.seek(0); 75 this.raw = IOUtils.toByteArray(seekableInput); 76 77 } catch (java.io.IOException ex) { 78 log.error("Error while loading raw image: " + ex.getMessage(), ex); 79 return false; 80 } finally { 81 IOUtils.closeQuietly(inputStream); 82 inputStream = null; 83 } 84 85 return true; 86 } 87 88 } 89 | Popular Tags |