final PDColorSpace colorSpace = pdImage.getColorSpace(); final int numComponents = colorSpace.getNumberOfComponents(); final int bitsPerComponent = pdImage.getBitsPerComponent(); final float[] decode = getDecodeArray(pdImage); options.setSourceRegion(clipped); try (ImageInputStream iis = new MemoryCacheImageInputStream(pdImage.createInputStream(options))) inputWidth = pdImage.getWidth(); startx = clipped.x; starty = clipped.y;
AffineTransform at = ctm.createAffineTransform(); if (!pdImage.getInterpolate()) boolean isScaledUp = pdImage.getWidth() < Math.round(at.getScaleX()) || pdImage.getHeight() < Math.round(at.getScaleY()); if (isScaledUp || pdImage.isStencil()) if (pdImage.isStencil()) BufferedImage mask = pdImage.getImage(); BufferedImage renderedMask = new BufferedImage((int) Math.ceil(bounds.getWidth()), (int) Math.ceil(bounds.getHeight()), BufferedImage image = pdImage.getStencilImage(getNonStrokingPaint()); drawBufferedImage(pdImage.getImage(null, subsampling), at); drawBufferedImage(pdImage.getImage(), at); if (!pdImage.getInterpolate())
private static float[] getDecodeArray(PDImage pdImage) throws IOException final COSArray cosDecode = pdImage.getDecode(); float[] decode = null; int numberOfComponents = pdImage.getColorSpace().getNumberOfComponents(); if (cosDecode.size() != numberOfComponents * 2) if (pdImage.isStencil() && cosDecode.size() >= 2 && cosDecode.get(0) instanceof COSNumber && cosDecode.get(1) instanceof COSNumber) return pdImage.getColorSpace().getDefaultDecode(pdImage.getBitsPerComponent());
private static Rectangle clipRegion(PDImage pdImage, Rectangle region) { if (region == null) { return new Rectangle(0, 0, pdImage.getWidth(), pdImage.getHeight()); } else { int x = Math.max(0, region.x); int y = Math.max(0, region.y); int width = Math.min(region.width, pdImage.getWidth() - x); int height = Math.min(region.height, pdImage.getHeight() - y); return new Rectangle(x, y, width, height); } }
int width = pdImage.getWidth(); int height = pdImage.getHeight(); try (InputStream iis = pdImage.createInputStream())
COSArray colorKey) throws IOException if (pdImage.isEmpty()) final PDColorSpace colorSpace = pdImage.getColorSpace(); final int numComponents = colorSpace.getNumberOfComponents(); final int width = (int) Math.ceil(clipped.getWidth() / subsampling); final int height = (int) Math.ceil(clipped.getHeight() / subsampling); final int bitsPerComponent = pdImage.getBitsPerComponent(); final float[] decode = getDecodeArray(pdImage); if (width <= 0 || height <= 0 || pdImage.getWidth() <= 0 || pdImage.getHeight() <= 0) final float[] defaultDecode = pdImage.getColorSpace().getDefaultDecode(8); if (bitsPerComponent == 8 && Arrays.equals(decode, defaultDecode) && colorKey == null)
DecodeOptions options = new DecodeOptions(currentSubsampling); options.setSourceRegion(clipped); try (InputStream input = pdImage.createInputStream(options)) inputWidth = pdImage.getWidth(); startx = clipped.x; starty = clipped.y; scanHeight = clipped.height; final int numComponents = pdImage.getColorSpace().getNumberOfComponents(); return pdImage.getColorSpace().toRGBImage(raster); return pdImage.getColorSpace().toRGBImage(raster);
String suffix = pdImage.getSuffix(); if (suffix == null || "jb2".equals(suffix)) BufferedImage image = pdImage.getImage(); if (image != null) String colorSpaceName = pdImage.getColorSpace().getName(); if (directJPEG || !hasMasks(pdImage) && InputStream data = pdImage.createInputStream(JPEG); IOUtils.copy(data, out); IOUtils.closeQuietly(data); String colorSpaceName = pdImage.getColorSpace().getName(); if (directJPEG || !hasMasks(pdImage) && InputStream data = pdImage.createInputStream( Arrays.asList(COSName.JPX_DECODE.getName())); IOUtils.copy(data, out);
private List<PDColorSpace> getImageCS() { try { PDColorSpace buffer = ColorSpaceFactory .getColorSpace(((PDImage) this.simplePDObject) .getColorSpace(), this.document, this.flavour); if (buffer != null) { List<PDColorSpace> colorSpaces = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); colorSpaces.add(buffer); return Collections.unmodifiableList(colorSpaces); } } catch (IOException e) { LOGGER.debug( "Problems with color space obtaining from InlineImage XObject. " + e.getMessage(), e); } return Collections.emptyList(); }
@Override public void drawImage(PDImage pdImage) throws IOException { if (pdImage instanceof PDImageXObject) { if (pdImage.isStencil()) { processColor(getGraphicsState().getNonStrokingColor()); } PDImageXObject xobject = (PDImageXObject)pdImage; if (seen.contains(xobject.getCOSObject())) { // skip duplicate image return; } seen.add(xobject.getCOSObject()); } // save image String name = prefix + "-" + imageCounter; imageCounter++; System.out.println("Writing image: " + name); write2file(pdImage, name, directJPEG); }
@Override public Boolean getInterpolate() { return Boolean.valueOf(((PDImage) this.simplePDObject) .getInterpolate()); }
if (pdImage.isEmpty()) final PDColorSpace colorSpace = pdImage.getColorSpace(); final int numComponents = colorSpace.getNumberOfComponents(); final int width = pdImage.getWidth(); final int height = pdImage.getHeight(); final int bitsPerComponent = pdImage.getBitsPerComponent(); final float[] decode = getDecodeArray(pdImage); final float[] defaultDecode = pdImage.getColorSpace().getDefaultDecode(8); if (bitsPerComponent == 8 && Arrays.equals(decode, defaultDecode) && colorKey == null)
final PDColorSpace colorSpace = pdImage.getColorSpace(); final float[] decode = getDecodeArray(pdImage); BufferedImage bim = null; options.setSourceRegion(clipped); try (InputStream iis = pdImage.createInputStream(options)) inputWidth = pdImage.getWidth(); startx = clipped.x; starty = clipped.y;
String suffix = pdImage.getSuffix(); if (suffix == null || "jb2".equals(suffix)) BufferedImage image = pdImage.getImage(); if (image != null) String colorSpaceName = pdImage.getColorSpace().getName(); if (directJPEG || !hasMasks(pdImage) && InputStream data = pdImage.createInputStream(JPEG); IOUtils.copy(data, out); IOUtils.closeQuietly(data); String colorSpaceName = pdImage.getColorSpace().getName(); if (directJPEG || !hasMasks(pdImage) && InputStream data = pdImage.createInputStream( Arrays.asList(COSName.JPX_DECODE.getName())); IOUtils.copy(data, out);
int width = pdImage.getWidth(); int height = pdImage.getHeight(); try (InputStream iis = pdImage.createInputStream())
/** * Calculated the subsampling frequency for a given PDImage based on the current transformation * and its calculated transform * * @param pdImage PDImage to be drawn * @param at Transform that will be applied to the image when drawing * @return The rounded-down ratio of image pixels to drawn pixels. Returned value will always be * >=1. */ private int getSubsampling(PDImage pdImage, AffineTransform at) { // calculate subsampling according to the resulting image size double scale = Math.abs(at.getDeterminant() * xform.getDeterminant()); int subsampling = (int) Math.floor(Math.sqrt(pdImage.getWidth() * pdImage.getHeight() / scale)); if (subsampling > 8) { subsampling = 8; } if (subsampling < 1) { subsampling = 1; } if (subsampling > pdImage.getWidth() || subsampling > pdImage.getHeight()) { // For very small images it is possible that the subsampling would imply 0 size. // To avoid problems, the subsampling is set to no less than the smallest dimension. subsampling = Math.min(pdImage.getWidth(), pdImage.getHeight()); } return subsampling; }
@Override public void drawImage(PDImage pdImage) throws IOException { if (pdImage instanceof PDImageXObject) { if (pdImage.isStencil()) { processColor(getGraphicsState().getNonStrokingColor()); } PDImageXObject xobject = (PDImageXObject)pdImage; if (seen.contains(xobject.getCOSObject())) { // skip duplicate image return; } seen.add(xobject.getCOSObject()); } // save image String name = prefix + "-" + imageCounter; imageCounter++; System.out.println("Writing image: " + name); write2file(pdImage, name, directJPEG); }
private static BufferedImage from8bit(PDImage pdImage, WritableRaster raster) throws IOException try (InputStream input = pdImage.createInputStream()) final int width = pdImage.getWidth(); final int height = pdImage.getHeight(); final int numComponents = pdImage.getColorSpace().getNumberOfComponents(); byte[] tempBytes = new byte[numComponents * width]; return pdImage.getColorSpace().toRGBImage(raster);
AffineTransform at = ctm.createAffineTransform(); if (!pdImage.getInterpolate()) boolean isScaledUp = pdImage.getWidth() < Math.round(at.getScaleX()) || pdImage.getHeight() < Math.round(at.getScaleY()); if (isScaledUp || pdImage.isStencil()) if (pdImage.isStencil()) BufferedImage mask = pdImage.getImage(); BufferedImage renderedMask = new BufferedImage((int) Math.ceil(bounds.getWidth()), (int) Math.ceil(bounds.getHeight()), BufferedImage image = pdImage.getStencilImage(getNonStrokingPaint()); drawBufferedImage(pdImage.getImage(null, subsampling), at); drawBufferedImage(pdImage.getImage(), at); if (!pdImage.getInterpolate())
COSArray colorKey) throws IOException if (pdImage.isEmpty()) final PDColorSpace colorSpace = pdImage.getColorSpace(); final int numComponents = colorSpace.getNumberOfComponents(); final int width = (int) Math.ceil(clipped.getWidth() / subsampling); final int height = (int) Math.ceil(clipped.getHeight() / subsampling); final int bitsPerComponent = pdImage.getBitsPerComponent(); final float[] decode = getDecodeArray(pdImage); if (width <= 0 || height <= 0 || pdImage.getWidth() <= 0 || pdImage.getHeight() <= 0) final float[] defaultDecode = pdImage.getColorSpace().getDefaultDecode(8); if (bitsPerComponent == 8 && Arrays.equals(decode, defaultDecode) && colorKey == null)