public void writeData(byte[] data, int stride) throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); DeflaterOutputStream zip = new DeflaterOutputStream(stream); int k; for (k = 0; k < data.length - stride; k += stride) { zip.write(0); zip.write(data, k, stride); } int remaining = data.length - k; if (remaining > 0) { zip.write(0); zip.write(data, k, remaining); } zip.close(); writeChunk(IDAT, stream.toByteArray()); }
@Override public void close() throws IOException { finish(); super.close(); }
fout = def = new DeflaterOutputStream(fout, pdfStream.getCompressionLevel(), 0x8000); def.finish(); updateCompressionFilter(pdfStream); byteArrayStream = new ByteArrayOutputStream(); DeflaterOutputStream zip = new DeflaterOutputStream(byteArrayStream, pdfStream.getCompressionLevel()); if (pdfStream instanceof PdfObjectStream) { PdfObjectStream objectStream = (PdfObjectStream) pdfStream; ((ByteArrayOutputStream) pdfStream.getOutputStream().getOutputStream()).writeTo(zip); zip.finish(); } else { if (pdfStream instanceof PdfObjectStream) {
private static void processExtraSamples(DeflaterOutputStream zip, DeflaterOutputStream mzip, byte[] outBuf, int samplePerPixel, int bitsPerSample, int width, int height) throws java.io.IOException { if (bitsPerSample == 8) { byte[] mask = new byte[width * height]; int mptr = 0; int optr = 0; int total = width * height * samplePerPixel; for (int k = 0; k < total; k += samplePerPixel) { for (int s = 0; s < samplePerPixel - 1; ++s) { outBuf[optr++] = outBuf[k + s]; } mask[mptr++] = outBuf[k + samplePerPixel - 1]; } zip.write(outBuf, 0, optr); mzip.write(mask, 0, mptr); } else throw new IOException(IOException.ExtraSamplesAreNotSupported); }
private static void processExtraSamples(DeflaterOutputStream zip, DeflaterOutputStream mzip, byte[] outBuf, int samplePerPixel, int bitsPerSample, int width, int height) throws java.io.IOException { if (bitsPerSample == 8) { byte[] mask = new byte[width * height]; int mptr = 0; int optr = 0; int total = width * height * samplePerPixel; for (int k = 0; k < total; k += samplePerPixel) { for (int s = 0; s < samplePerPixel - 1; ++s) { outBuf[optr++] = outBuf[k + s]; } mask[mptr++] = outBuf[k + samplePerPixel - 1]; } zip.write(outBuf, 0, optr); mzip.write(mask, 0, mptr); } else throw new IOException(IOException.ExtraSamplesAreNotSupported); }
public void writeData(byte[] data, int stride) throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); DeflaterOutputStream zip = new DeflaterOutputStream(stream); int k; for (k = 0; k < data.length - stride; k += stride) { zip.write(0); zip.write(data, k, stride); } int remaining = data.length - k; if (remaining > 0) { zip.write(0); zip.write(data, k, remaining); } zip.close(); writeChunk(IDAT, stream.toByteArray()); }
@Override public void close() throws IOException { finish(); super.close(); }
public void writeIccProfile(byte[] data) throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); stream.write((byte) 'I'); stream.write((byte) 'C'); stream.write((byte) 'C'); stream.write(0); stream.write(0); DeflaterOutputStream zip = new DeflaterOutputStream(stream); zip.write(data); zip.close(); writeChunk(iCCP, stream.toByteArray()); }
public void writeIccProfile(byte[] data) throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); stream.write((byte) 'I'); stream.write((byte) 'C'); stream.write((byte) 'C'); stream.write(0); stream.write(0); DeflaterOutputStream zip = new DeflaterOutputStream(stream); zip.write(data); zip.close(); writeChunk(iCCP, stream.toByteArray()); }
if (extraSamples > 0) { mstream = new ByteArrayOutputStream(); mzip = new DeflaterOutputStream(mstream); stream = new ByteArrayOutputStream(); if (compression != TIFFConstants.COMPRESSION_OJPEG && compression != TIFFConstants.COMPRESSION_JPEG) zip = new DeflaterOutputStream(stream); processExtraSamples(zip, mzip, outBuf, samplePerPixel, bitsPerSample, w, height); else zip.write(outBuf); photometric == TIFFConstants.PHOTOMETRIC_MINISBLACK ? RawImageData.CCITT_BLACKIS1 : 0, g4.close(), null); } else { zip.close(); RawImageHelper.updateRawImageParameters(tiff.image, w, h, samplePerPixel - extraSamples, bitsPerSample, stream.toByteArray()); tiff.image.setDeflated(true); tiff.image.setRotation(rotation); if (extraSamples > 0) { mzip.close(); RawImageData mimg = (RawImageData) ImageDataFactory.createRawImage(null); RawImageHelper.updateRawImageParameters(mimg, w, h, 1, bitsPerSample, mstream.toByteArray());
if (extraSamples > 0) { mstream = new ByteArrayOutputStream(); mzip = new DeflaterOutputStream(mstream); stream = new ByteArrayOutputStream(); if (compression != TIFFConstants.COMPRESSION_OJPEG && compression != TIFFConstants.COMPRESSION_JPEG) zip = new DeflaterOutputStream(stream); processExtraSamples(zip, mzip, outBuf, samplePerPixel, bitsPerSample, w, height); else zip.write(outBuf); photometric == TIFFConstants.PHOTOMETRIC_MINISBLACK ? RawImageData.CCITT_BLACKIS1 : 0, g4.close(), null); } else { zip.close(); RawImageHelper.updateRawImageParameters(tiff.image, w, h, samplePerPixel - extraSamples, bitsPerSample, stream.toByteArray()); tiff.image.setDeflated(true); tiff.image.setRotation(rotation); if (extraSamples > 0) { mzip.close(); RawImageData mimg = (RawImageData) ImageDataFactory.createRawImage(null); RawImageHelper.updateRawImageParameters(mimg, w, h, 1, bitsPerSample, mstream.toByteArray());