Search in sources :

Example 26 with ParameterBlockJAI

use of javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.

the class JP2KKakaduWriteTest method write.

private static synchronized void write(String file, RenderedImage bi, boolean codeStreamOnly, double quality, boolean useJAI, JP2KKakaduImageWriteParam addParam) throws IOException {
    writeOperations++;
    file += "_Q" + quality + (codeStreamOnly ? ".j2c" : ".jp2");
    final ImageOutputStream outputStream = ImageIO.createImageOutputStream(new File(file));
    JP2KKakaduImageWriteParam param = new JP2KKakaduImageWriteParam();
    param.setQuality(quality);
    param.setWriteCodeStreamOnly(codeStreamOnly);
    if (addParam != null) {
        param.setSourceRegion(addParam.getSourceRegion());
        param.setSourceSubsampling(addParam.getSourceXSubsampling(), addParam.getSourceYSubsampling(), addParam.getSubsamplingXOffset(), addParam.getSubsamplingYOffset());
        param.setCLevels(addParam.getCLevels());
        param.setQualityLayers(addParam.getQualityLayers());
    }
    if (!useJAI) {
        final ImageWriter writer = new JP2KKakaduImageWriterSpi().createWriterInstance();
        // final ImageWriter writer = new
        // J2KImageWriterSpi().createWriterInstance();
        writer.setOutput(outputStream);
        // J2KImageWriteParam ioparam = (J2KImageWriteParam)
        // writer.getDefaultWriteParam();
        // ioparam.setWriteCodeStreamOnly(true);
        // ioparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        // ioparam.setCompressionType("JPEG2000");
        // ioparam.setCompressionQuality((float)quality);
        // ioparam.setEncodingRate((quality)*24);
        // writer.write(null, new IIOImage(bi, null, null), ioparam);
        writer.write(null, new IIOImage(bi, null, null), param);
        writer.dispose();
    } else {
        final ParameterBlockJAI pbjImageWrite = new ParameterBlockJAI("ImageWrite");
        final ImageWriter writer = new JP2KKakaduImageWriterSpi().createWriterInstance();
        pbjImageWrite.setParameter("writer", writer);
        pbjImageWrite.setParameter("output", outputStream);
        pbjImageWrite.setParameter("writeParam", param);
        pbjImageWrite.addSource(bi);
        RenderedOp image = JAI.create("ImageWrite", pbjImageWrite);
    }
}
Also used : RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageWriter(javax.imageio.ImageWriter) File(java.io.File) ImageOutputStream(javax.imageio.stream.ImageOutputStream) FileImageOutputStream(javax.imageio.stream.FileImageOutputStream) IIOImage(javax.imageio.IIOImage)

Example 27 with ParameterBlockJAI

use of javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.

the class JP2KKakaduWriteTest method testKakaduWriter.

public void testKakaduWriter() throws KduException, FileNotFoundException, IOException {
    if (!isKakaduAvailable) {
        LOGGER.warning("Kakadu libs not found: test are skipped ");
        return;
    }
    for (String fileName : files) {
        // final String filePath = inputFileName + fileName;
        // final File file = new File(filePath);
        final File file = TestData.file(this, fileName);
        final String filePath = file.getAbsolutePath();
        if (!file.exists()) {
            LOGGER.warning("Unable to find the file " + filePath + // + "\n Be sure you have properly specified the \"data.path\" property linking to the location where test data is available."
            "\n This test will be skipped");
            continue;
        } else {
            final String suffix = fileName.substring(0, fileName.length() - 4);
            LinkedList<TestConfiguration> configs = new LinkedList<TestConfiguration>();
            configs.add(new TestConfiguration(outputFileName + "_" + suffix, true, lossLessQuality, false, null));
            configs.add(new TestConfiguration(outputFileName + "_" + suffix, false, lossLessQuality, false, null));
            configs.add(new TestConfiguration(outputFileName + "_" + suffix, true, lossyQuality, false, null));
            configs.add(new TestConfiguration(outputFileName + "_" + suffix, false, lossyQuality, false, null));
            configs.add(new TestConfiguration(outputFileName + "_JAI_" + suffix, true, lossLessQuality, true, null));
            configs.add(new TestConfiguration(outputFileName + "_JAI_" + suffix, false, lossLessQuality, true, null));
            // configs.add(new TestConfiguration(
            // outputFileName + "_JAI_" + suffix, true, lossyQuality,
            // true, null));
            // configs.add(new TestConfiguration(
            // outputFileName + "_JAI_" + suffix, false, lossyQuality,
            // true, null));
            JP2KKakaduImageWriteParam param = new JP2KKakaduImageWriteParam();
            final int levels = 2;
            param.setCLevels(levels);
            configs.add(new TestConfiguration(outputFileName + "_" + levels + "levels_" + suffix, true, lossLessQuality, false, param));
            configs.add(new TestConfiguration(outputFileName + "_" + levels + "levels_" + suffix, false, lossLessQuality, false, param));
            configs.add(new TestConfiguration(outputFileName + "_" + levels + "levels_" + suffix, true, lossyQuality, false, param));
            configs.add(new TestConfiguration(outputFileName + "_" + levels + "levels_" + suffix, false, lossyQuality, false, param));
            for (TestConfiguration config : configs) {
                final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
                ImageReader reader = ImageIO.getImageReaders(ImageIO.createImageInputStream(file)).next();
                pbjImageRead.setParameter("reader", reader);
                pbjImageRead.setParameter("Input", file);
                RenderedOp image = JAI.create("ImageRead", pbjImageRead);
                write(config.outputFileName, image, config.writeCodeStreamOnly, config.quality, config.useJAI, config.param);
            }
        }
    }
}
Also used : RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) ImageReader(javax.imageio.ImageReader) File(java.io.File) LinkedList(java.util.LinkedList)

Example 28 with ParameterBlockJAI

use of javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.

the class AsciiGridTest method testReadGrassGZ.

/**
 * Read a GRASS, compressed (GZ) file
 */
public void testReadGrassGZ() throws FileNotFoundException, IOException {
    // be run only when extensive tests are requested.
    if (TestData.isExtensiveTest()) {
        String title = new String("JAI ImageRead on a GRASS GZipped file ");
        LOGGER.info("\n\n " + title + " \n");
        File inputFile = TestData.file(this, "spearfish.asc.gz");
        final GZIPInputStream stream = new GZIPInputStream(new FileInputStream(inputFile));
        ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageRead");
        pbjImageRead.setParameter("Input", stream);
        RenderedOp image = JAI.create("ImageRead", pbjImageRead);
        if (TestData.isInteractiveTest())
            ImageIOUtilities.visualize(image, title, true);
        else {
            assertNotNull(image.getTiles());
            image.dispose();
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 29 with ParameterBlockJAI

use of javax.media.jai.ParameterBlockJAI in project imageio-ext by geosolutions-it.

the class ArcGridReadTest method readJAI.

/**
 * Simple test read through JAI - ImageIO
 *
 * @throws FileNotFoundException
 * @throws IOException
 */
@org.junit.Test
public void readJAI() throws FileNotFoundException, IOException {
    if (!isGDALAvailable) {
        return;
    }
    final ParameterBlockJAI pbjImageRead;
    final String fileName = "095b_dem_90m.asc";
    TestData.unzipFile(this, "arcgrid.zip");
    final File file = TestData.file(this, fileName);
    pbjImageRead = new ParameterBlockJAI("ImageRead");
    pbjImageRead.setParameter("Input", file);
    RenderedOp image = JAI.create("ImageRead", pbjImageRead);
    if (TestData.isInteractiveTest())
        Viewer.visualizeAllInformation(image, fileName);
    else
        image.getTiles();
    Assert.assertEquals(351, image.getWidth());
    Assert.assertEquals(350, image.getHeight());
    ImageIOUtilities.disposeImage(image);
}
Also used : RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) File(java.io.File) Test(org.junit.Test)

Example 30 with ParameterBlockJAI

use of javax.media.jai.ParameterBlockJAI in project digilib by robcast.

the class JAIDocuImage method loadSubimage.

/* Load an image file into the Object. */
public void loadSubimage(ImageInput ii, Rectangle region, int subsample) throws FileOpException {
    logger.debug("loadSubimage");
    this.input = ii;
    if (ii.hasFile()) {
        img = JAI.create("fileload", ii.getFile().getAbsolutePath());
    } else if (ii.hasInputStream()) {
        img = JAI.create("stream", ii.getInputStream());
    } else {
        throw new FileOpException("unable to get data for image!");
    }
    if ((region.width < img.getWidth()) || (region.height < img.getHeight())) {
        // setup Crop
        ParameterBlock cp = new ParameterBlock();
        cp.addSource(img);
        cp.add((float) region.x);
        cp.add((float) region.y);
        cp.add((float) region.width);
        cp.add((float) region.height);
        logger.debug("loadSubimage: crop");
        img = JAI.create("crop", cp);
    }
    if (subsample > 1) {
        float sc = 1f / subsample;
        ParameterBlockJAI sp = new ParameterBlockJAI("scale");
        sp.addSource(img);
        sp.setParameter("xScale", sc);
        sp.setParameter("yScale", sc);
        sp.setParameter("interpolation", Interpolation.getInstance(Interpolation.INTERP_NEAREST));
        // scale
        logger.debug("loadSubimage: scale");
        img = JAI.create("scale", sp);
    }
}
Also used : ParameterBlock(java.awt.image.renderable.ParameterBlock) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) FileOpException(digilib.io.FileOpException)

Aggregations

ParameterBlockJAI (javax.media.jai.ParameterBlockJAI)76 File (java.io.File)71 RenderedOp (javax.media.jai.RenderedOp)71 Test (org.junit.Test)57 ImageReadParam (javax.imageio.ImageReadParam)48 AbstractGDALTest (it.geosolutions.imageio.gdalframework.AbstractGDALTest)32 ImageWriter (javax.imageio.ImageWriter)28 ImageLayout (javax.media.jai.ImageLayout)26 ImageWriteParam (javax.imageio.ImageWriteParam)23 RenderingHints (java.awt.RenderingHints)22 FileImageOutputStreamExtImpl (it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl)20 FileNotFoundException (java.io.FileNotFoundException)13 ImageReader (javax.imageio.ImageReader)13 Rectangle (java.awt.Rectangle)9 IIOMetadata (javax.imageio.metadata.IIOMetadata)5 FileImageInputStreamExtImpl (it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl)3 ColorSpace (java.awt.color.ColorSpace)3 ColorModel (java.awt.image.ColorModel)3 RenderedImage (java.awt.image.RenderedImage)3 SampleModel (java.awt.image.SampleModel)3