pdfbox-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Rendering images from PDF files slower in OpenJDK
Date Wed, 03 Oct 2018 18:30:53 GMT
Am 03.10.2018 um 20:08 schrieb Tilman Hausherr:
>
> I could expand that one later so that it uses the raster of the actual 
> JPEG image from your PDF. 


Your JPEG file is here:

https://drive.google.com/file/d/1HvXMet6Wygzmko9ZmY9_zlvhv72v_QHf/view?usp=sharing

The modified code - please test on different openjdks. It took 137935 on 
oracle jdk8. (you may want to change the "50")



import java.awt.*;
import java.awt.color.*;
import java.awt.image.*;
import java.io.FileInputStream;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.MemoryCacheImageInputStream;

public class CConv
{

     static BufferedImage toRGBImageAWT(WritableRaster raster, 
ColorSpace colorSpace)
     {

         ColorModel colorModel = new ComponentColorModel(colorSpace,
                 false, false, Transparency.OPAQUE, 
raster.getDataBuffer().getDataType());

         BufferedImage src = new BufferedImage(colorModel, raster, 
false, null);
         BufferedImage dest = new BufferedImage(raster.getWidth(), 
raster.getHeight(),
                 BufferedImage.TYPE_INT_RGB);
         ColorConvertOp op = new ColorConvertOp(null);
         //System.out.println("src="+src);
         //System.out.println("dst="+dest);
         op.filter(src, dest);
         return dest;
     }

     public static void main(String args[]) throws Exception
     {
         ImageReader reader = 
ImageIO.getImageReadersByFormatName("JPEG").next();
         WritableRaster raster;
         FileInputStream fis = new FileInputStream("cmyk.jpg");
         try (ImageInputStream iis = new MemoryCacheImageInputStream(fis))
         {
             reader.setInput(iis);
             ImageReadParam irp = reader.getDefaultReadParam();
             raster = (WritableRaster) reader.readRaster(0, irp);
         }
         System.out.println("Raster: " + raster);

         ICC_Profile profile = 
ICC_Profile.getInstance("ISOcoated_v2_300_bas.icc");
         ICC_ColorSpace colorSpace = new ICC_ColorSpace(profile);
         long t0 = System.currentTimeMillis();
         for (int i = 0; i < 50; i++)
         {
             toRGBImageAWT(raster, colorSpace);
         }
         long t1 = System.currentTimeMillis();
         System.out.println((t1 - t0));
     }
}


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


Mime
View raw message