use of com.tom_roush.pdfbox.filter.Filter in project PdfBox-Android by TomRoush.
the class JPEGFactory method prepareImageXObject.
/**
* Create a PDImageXObject while making a decision whether not to
* compress, use Flate filter only, or Flate and LZW filters.
*
* @param document The document.
* @param byteArray array with data.
* @param width the image width
* @param height the image height
* @param bitsPerComponent the bits per component
* @param initColorSpace the color space
* @return the newly created PDImageXObject with the data compressed.
* @throws IOException
*/
private static PDImageXObject prepareImageXObject(PDDocument document, byte[] byteArray, int width, int height, int bitsPerComponent, PDColorSpace initColorSpace) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Filter filter = FilterFactory.INSTANCE.getFilter(COSName.FLATE_DECODE);
filter.encode(new ByteArrayInputStream(byteArray), baos, new COSDictionary(), 0);
ByteArrayInputStream encodedByteStream = new ByteArrayInputStream(baos.toByteArray());
return new // TODO: PdfBox-Android should be DCT
PDImageXObject(// TODO: PdfBox-Android should be DCT
document, // TODO: PdfBox-Android should be DCT
encodedByteStream, // TODO: PdfBox-Android should be DCT
COSName.FLATE_DECODE, width, height, bitsPerComponent, initColorSpace);
}
use of com.tom_roush.pdfbox.filter.Filter in project PdfBox-Android by TomRoush.
the class COSInputStream method create.
static COSInputStream create(List<Filter> filters, COSDictionary parameters, InputStream in, ScratchFile scratchFile, DecodeOptions options) throws IOException {
List<DecodeResult> results = new ArrayList<DecodeResult>();
InputStream input = in;
if (filters.isEmpty()) {
input = in;
} else {
Set<Filter> filterSet = new HashSet<Filter>(filters);
if (filterSet.size() != filters.size()) {
throw new IOException("Duplicate");
}
// apply filters
for (int i = 0; i < filters.size(); i++) {
if (scratchFile != null) {
// scratch file
final RandomAccess buffer = scratchFile.createBuffer();
DecodeResult result = filters.get(i).decode(input, new RandomAccessOutputStream(buffer), parameters, i, options);
results.add(result);
input = new RandomAccessInputStream(buffer) {
@Override
public void close() throws IOException {
buffer.close();
}
};
} else {
// in-memory
ByteArrayOutputStream output = new ByteArrayOutputStream();
DecodeResult result = filters.get(i).decode(input, output, parameters, i, options);
results.add(result);
input = new ByteArrayInputStream(output.toByteArray());
}
}
}
return new COSInputStream(input, results);
}
Aggregations