/** * {@inheritDoc} * The returned images are cached via a SoftReference. */ @Override public BufferedImage getImage() throws IOException { return getImage(null, 1); }
private static byte pngFilterUp(int x, int b) { // Same as pngFilterSub, just called with the prior row return pngFilterSub(x, b); }
@Override public BufferedImage getImage() throws IOException { return SampledImageReader.getRGBImage(this, null); }
public XObjImageValidator(PreflightContext context, PDImageXObject xobj) { super(context, xobj.getCOSObject()); this.xImage = xobj; }
@Override public InputStream createInputStream() throws IOException { return getStream().createInputStream(); }
private boolean hasMasks(PDImage pdImage) throws IOException { if (pdImage instanceof PDImageXObject) { PDImageXObject ximg = (PDImageXObject) pdImage; return ximg.getMask() != null || ximg.getSoftMask() != null; } return false; }
@Override public BufferedImage getStencilImage(Paint paint) throws IOException { if (!isStencil()) { throw new IllegalStateException("Image is not a stencil"); } return SampledImageReader.getStencilImage(this, paint); }
/** * {@inheritDoc} * The returned images are not cached. */ @Override public BufferedImage getStencilImage(Paint paint) throws IOException { if (!isStencil()) { throw new IllegalStateException("Image is not a stencil"); } return SampledImageReader.getStencilImage(this, paint); }
/** * Creates a thumbnail Image XObject from the given COSBase and name. * @param cosStream the COS stream * @return an XObject * @throws IOException if there is an error creating the XObject. */ public static PDImageXObject createThumbnail(COSStream cosStream) throws IOException { // thumbnails are special, any non-null subtype is treated as being "Image" PDStream pdStream = new PDStream(cosStream); return new PDImageXObject(pdStream, null); }
/** * Creates a new JPEG PDImageXObject from a BufferedImage. * <p> * Do not read a JPEG image from a stream/file and call this method; you'll get more speed and * quality by calling {@link #createFromStream(org.apache.pdfbox.pdmodel.PDDocument, * java.io.InputStream) createFromStream()} instead. * * @param document the document where the image will be created * @param image the BufferedImage to embed * @return a new Image XObject * @throws IOException if the JPEG data cannot be written */ public static PDImageXObject createFromImage(PDDocument document, BufferedImage image) throws IOException { return createFromImage(document, image, 0.75f); }
@Override public int getBitsPerComponent() { if (isStencil()) { return 1; } else { return parameters.getInt(COSName.BPC, COSName.BITS_PER_COMPONENT, -1); } }
@Override public InputStream createInputStream(DecodeOptions options) throws IOException { // Decode options are irrelevant for inline image, as the data is always buffered. return createInputStream(); }
/** * Sets the metadata associated with this XObject, or null if there is none. * @param meta the metadata associated with this object */ public void setMetadata(PDMetadata meta) { getCOSObject().setItem(COSName.METADATA, meta); }
@Override public InputStream createInputStream(DecodeOptions options) throws IOException { return getStream().createInputStream(options); }
/** * Returns an RGB buffered image containing the opaque image stream without any masks applied. * If this Image XObject is a mask then the buffered image will contain the raw mask. * @return the image without any masks applied * @throws IOException if the image cannot be read */ public BufferedImage getOpaqueImage() throws IOException { return SampledImageReader.getRGBImage(this, null); }
/** * Sets the key of this XObject in the structural parent tree. * @param key the new key for this XObject */ public void setStructParent(int key) { getCOSObject().setInt(COSName.STRUCT_PARENT, key); }
@Override public InputStream createInputStream(List<String> stopFilters) throws IOException { return getStream().createInputStream(stopFilters); }
@Override public BufferedImage getImage(Rectangle region, int subsampling) throws IOException { return SampledImageReader.getRGBImage(this, region, subsampling, null); }
@Override public COSArray getDecode() { COSBase decode = getCOSObject().getDictionaryObject(COSName.DECODE); if (decode instanceof COSArray) { return (COSArray) decode; } return null; }
/** * Returns the content of the given image as an AWT buffered image with an RGB color space. * If a color key mask is provided then an ARGB image is returned instead. * This method never returns null. * @param pdImage the image to read * @param colorKey an optional color key mask * @return content of this image as an RGB buffered image * @throws IOException if the image cannot be read */ public static BufferedImage getRGBImage(PDImage pdImage, COSArray colorKey) throws IOException { return getRGBImage(pdImage, null, 1, colorKey); }