{
// wrap and rethrow any exceptions
throw new IOException("Could not read JPEG 2000 (JPX) image", e);
}
COSDictionary parameters = result.getParameters();
// "If the image stream uses the JPXDecode filter, this entry is optional
// and shall be ignored if present"
parameters.setInt(COSName.BITS_PER_COMPONENT, image.getColorModel().getComponentSize(0));
// "Decode shall be ignored, except in the case where the image is treated as a mask"
if (!parameters.getBoolean(COSName.IMAGE_MASK, false))
{
parameters.setItem(COSName.DECODE, null);
}
// override dimensions, see PDFBOX-1735
parameters.setInt(COSName.WIDTH, image.getWidth());
parameters.setInt(COSName.HEIGHT, image.getHeight());
// extract embedded color space
if (!parameters.containsKey(COSName.COLORSPACE))
{
result.setColorSpace(new PDJPXColorSpace(image.getColorModel().getColorSpace()));
}
return image;