if(!JAIHelper.isJAIused())
message="JPeg 2000 Images and JAI not setup.\nYou need both JAI and imageio.jar on classpath, " +
"and the VM parameter -Dorg.jpedal.jai=true switch turned on";
throw new PdfException(message);
}
if(iir==null)
return null;
try{
// ImageIO.setUseCache(false);
ImageInputStream iin = ImageIO.createImageInputStream(in);
try{
iir.setInput(iin, true); //new MemoryCacheImageInputStream(in));
image = iir.read(0);
//does not work correctly if indexed so we manipulate the data
//if you need to alter check the images on page 42, 53, 71, 80, 89, 98, 107 and 114 are displayed in black
//infinite/Plumbing_Fixtures_2_V1_replaced.pdf
byte[] index = getIndexedMap();
if(index!=null && value==ColorSpaces.DeviceRGB){
data = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
image=ColorSpaceConvertor.convertIndexedToFlat(8,w, h, data, index,false,false);
}
}catch(Exception e){
if(LogWriter.isOutput())
LogWriter.writeLog("Problem reading JPEG 2000: " + e);
e.printStackTrace();
image=null;
}finally {
iir.dispose();
iin.close();
in.close();
}
if(image!=null){
image=cleanupImage(image,pX,pY,value);
//ensure white background
if(image.getType()== BufferedImage.TYPE_BYTE_INDEXED){
BufferedImage oldImage=image;
int newW=image.getWidth();
int newH=image.getHeight();
image=new BufferedImage(newW, newH, BufferedImage.TYPE_INT_RGB);
Graphics2D g2= (Graphics2D) image.getGraphics();
g2.setPaint(Color.WHITE);
g2.fillRect(0,0,newW,newH);
g2.drawImage(oldImage,0,0,null);
}
image=ColorSpaceConvertor.convertToRGB(image);
}
} catch (Exception ee) {
image = null;
if(LogWriter.isOutput())
LogWriter.writeLog("Problem reading JPEG 2000: " + ee);
String message="Exception "+ee+" with JPeg 2000 Image";
if(!JAIHelper.isJAIused())
message="JPeg 2000 Images and JAI not setup.\nYou need both JAI and imageio.jar on classpath, " +
"and the VM parameter -Dorg.jpedal.jai=true switch turned on";
throw new PdfException(message);
//ee.printStackTrace();
} catch (Error ee2) {
image = null;
ee2.printStackTrace();
if(LogWriter.isOutput())
LogWriter.writeLog("Problem reading JPEG 2000: " + ee2);
throw new PdfException("JPeg 2000 Images need both JAI (imageio.jar) on classpath, " +
"and the VM parameter -Dorg.jpedal.jai=true switch turned on");
//ee.printStackTrace();
}
return image;