Search in sources :

Example 1 with J2KImageWriteParam

use of com.github.jaiimageio.jpeg2000.J2KImageWriteParam in project alliance by codice.

the class Jpeg2000ServiceImpl method createJpeg.

@Override
public byte[] createJpeg(BufferedImage bufferedImage, int blockWidth, int blockHeight) throws IOException {
    J2KImageWriter writer = createWriter();
    J2KImageWriteParam writeParams = (J2KImageWriteParam) writer.getDefaultWriteParam();
    setCommonWriteParams(writeParams);
    writeParams.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
    writeParams.setTiling(blockWidth, blockHeight, 0, 0);
    writeParams.setSOP(true);
    return encodeToByteArray(bufferedImage, writer, writeParams);
}
Also used : J2KImageWriteParam(com.github.jaiimageio.jpeg2000.J2KImageWriteParam) J2KImageWriter(com.github.jaiimageio.jpeg2000.impl.J2KImageWriter)

Example 2 with J2KImageWriteParam

use of com.github.jaiimageio.jpeg2000.J2KImageWriteParam in project alliance by codice.

the class NitfPreStoragePlugin method renderToJpeg2k.

private byte[] renderToJpeg2k(final BufferedImage bufferedImage) throws IOException {
    BufferedImage imageToCompress = bufferedImage;
    if (bufferedImage.getColorModel().getNumComponents() == ARGB_COMPONENT_COUNT) {
        imageToCompress = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
        Graphics2D g = imageToCompress.createGraphics();
        g.drawImage(bufferedImage, 0, 0, null);
    }
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    J2KImageWriter writer = new J2KImageWriter(new J2KImageWriterSpi());
    J2KImageWriteParam writeParams = (J2KImageWriteParam) writer.getDefaultWriteParam();
    writeParams.setLossless(false);
    writeParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    writeParams.setCompressionType("JPEG2000");
    writeParams.setCompressionQuality(0.0f);
    ImageOutputStream ios = new MemoryCacheImageOutputStream(os);
    writer.setOutput(ios);
    writer.write(null, new IIOImage(imageToCompress, null, null), writeParams);
    writer.dispose();
    ios.close();
    return os.toByteArray();
}
Also used : J2KImageWriterSpi(com.github.jaiimageio.jpeg2000.impl.J2KImageWriterSpi) MemoryCacheImageOutputStream(javax.imageio.stream.MemoryCacheImageOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) J2KImageWriteParam(com.github.jaiimageio.jpeg2000.J2KImageWriteParam) BufferedImage(java.awt.image.BufferedImage) J2KImageWriter(com.github.jaiimageio.jpeg2000.impl.J2KImageWriter) ImageOutputStream(javax.imageio.stream.ImageOutputStream) MemoryCacheImageOutputStream(javax.imageio.stream.MemoryCacheImageOutputStream) Graphics2D(java.awt.Graphics2D) IIOImage(javax.imageio.IIOImage)

Example 3 with J2KImageWriteParam

use of com.github.jaiimageio.jpeg2000.J2KImageWriteParam in project bioformats by openmicroscopy.

the class JAIIIOServiceImpl method writeImage.

/* @see JAIIIOService#writeImage(OutputStream, BufferedImage, JPEG2000CodecOptions) */
@Override
public void writeImage(OutputStream out, BufferedImage img, JPEG2000CodecOptions options) throws IOException, ServiceException {
    ImageOutputStream ios = ImageIO.createImageOutputStream(out);
    IIORegistry registry = IIORegistry.getDefaultInstance();
    Iterator<J2KImageWriterSpi> iter = ServiceLoader.load(J2KImageWriterSpi.class).iterator();
    registry.registerServiceProviders(iter);
    J2KImageWriterSpi spi = registry.getServiceProviderByClass(J2KImageWriterSpi.class);
    J2KImageWriter writer = new J2KImageWriter(spi);
    writer.setOutput(ios);
    String filter = options.lossless ? J2KImageWriteParam.FILTER_53 : J2KImageWriteParam.FILTER_97;
    IIOImage iioImage = new IIOImage(img, null, null);
    J2KImageWriteParam param = (J2KImageWriteParam) writer.getDefaultWriteParam();
    param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    param.setCompressionType("JPEG2000");
    if (!options.lossless) {
        param.setEncodingRate(options.quality);
    }
    param.setLossless(options.lossless);
    param.setFilter(filter);
    param.setCodeBlockSize(options.codeBlockSize);
    param.setComponentTransformation(false);
    if (options.tileWidth > 0 && options.tileHeight > 0) {
        param.setTiling(options.tileWidth, options.tileHeight, options.tileGridXOffset, options.tileGridYOffset);
    }
    if (options.numDecompositionLevels != null) {
        param.setNumDecompositionLevels(options.numDecompositionLevels.intValue());
    }
    writer.write(null, iioImage, param);
    ios.close();
}
Also used : J2KImageWriterSpi(com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriterSpi) IIORegistry(javax.imageio.spi.IIORegistry) J2KImageWriteParam(com.sun.media.imageio.plugins.jpeg2000.J2KImageWriteParam) ImageOutputStream(javax.imageio.stream.ImageOutputStream) J2KImageWriter(com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriter) IIOImage(javax.imageio.IIOImage)

Example 4 with J2KImageWriteParam

use of com.github.jaiimageio.jpeg2000.J2KImageWriteParam in project alliance by codice.

the class Jpeg2000ServiceImpl method createJpeg.

@Override
public byte[] createJpeg(BufferedImage bufferedImage) throws IOException {
    J2KImageWriter writer = createWriter();
    J2KImageWriteParam writeParams = (J2KImageWriteParam) writer.getDefaultWriteParam();
    setCommonWriteParams(writeParams);
    return encodeToByteArray(bufferedImage, writer, writeParams);
}
Also used : J2KImageWriteParam(com.github.jaiimageio.jpeg2000.J2KImageWriteParam) J2KImageWriter(com.github.jaiimageio.jpeg2000.impl.J2KImageWriter)

Aggregations

J2KImageWriteParam (com.github.jaiimageio.jpeg2000.J2KImageWriteParam)3 J2KImageWriter (com.github.jaiimageio.jpeg2000.impl.J2KImageWriter)3 IIOImage (javax.imageio.IIOImage)2 ImageOutputStream (javax.imageio.stream.ImageOutputStream)2 J2KImageWriterSpi (com.github.jaiimageio.jpeg2000.impl.J2KImageWriterSpi)1 J2KImageWriteParam (com.sun.media.imageio.plugins.jpeg2000.J2KImageWriteParam)1 J2KImageWriter (com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriter)1 J2KImageWriterSpi (com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriterSpi)1 Graphics2D (java.awt.Graphics2D)1 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IIORegistry (javax.imageio.spi.IIORegistry)1 MemoryCacheImageOutputStream (javax.imageio.stream.MemoryCacheImageOutputStream)1