Search in sources :

Example 31 with ParameterBlockJAI

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

the class JAIDocuImage method blur.

public void blur(int radius) throws ImageOpException {
    RenderedImage blurredImg;
    int klen = Math.max(radius, 2);
    logger.debug("blur: " + klen);
    int ksize = klen * klen;
    float f = 1f / ksize;
    float[] kern = new float[ksize];
    for (int i = 0; i < ksize; i++) {
        kern[i] = f;
    }
    KernelJAI blur = new KernelJAI(klen, klen, kern);
    ParameterBlockJAI param = new ParameterBlockJAI("Convolve");
    param.addSource(img);
    param.setParameter("kernel", blur);
    // hint with border extender
    RenderingHints hint = new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_COPY));
    blurredImg = JAI.create("Convolve", param, hint);
    if (blurredImg == null) {
        throw new ImageOpException("Unable to scale");
    }
    img = blurredImg;
}
Also used : ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) KernelJAI(javax.media.jai.KernelJAI) RenderedImage(java.awt.image.RenderedImage) RenderingHints(java.awt.RenderingHints)

Example 32 with ParameterBlockJAI

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

the class JAIDocuImage method scaleAll.

public void scaleAll(float scale) throws ImageOpException {
    RenderedImage scaledImg;
    // DEBUG
    logger.debug("scaleAll: " + scale);
    ParameterBlockJAI param = new ParameterBlockJAI("Scale");
    param.addSource(img);
    param.setParameter("xScale", scale);
    param.setParameter("yScale", scale);
    param.setParameter("interpolation", interpol);
    // hint with border extender
    RenderingHints hint = new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_COPY));
    // scale
    scaledImg = JAI.create("Scale", param, hint);
    if (scaledImg == null) {
        throw new ImageOpException("Unable to scale");
    }
    img = scaledImg;
}
Also used : ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) RenderedImage(java.awt.image.RenderedImage) RenderingHints(java.awt.RenderingHints)

Example 33 with ParameterBlockJAI

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

the class JAIDocuImage method scaleBinary.

public void scaleBinary(float scale) throws ImageOpException {
    RenderedImage scaledImg;
    // DEBUG
    logger.debug("scaleBinary: " + scale);
    ParameterBlockJAI param = new ParameterBlockJAI("SubsampleBinaryToGray");
    param.addSource(img);
    param.setParameter("xScale", scale);
    param.setParameter("yScale", scale);
    // hint with border extender
    RenderingHints hint = new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_COPY));
    // scale
    scaledImg = JAI.create("SubsampleBinaryToGray", param, hint);
    if (scaledImg == null) {
        throw new ImageOpException("Unable to scale");
    }
    img = scaledImg;
}
Also used : ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) RenderedImage(java.awt.image.RenderedImage) RenderingHints(java.awt.RenderingHints)

Example 34 with ParameterBlockJAI

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

the class JP2KKakaduWriteTest method testKakaduWriterParam.

public void testKakaduWriterParam() throws KduException, FileNotFoundException, IOException {
    if (!isKakaduAvailable) {
        LOGGER.warning("Kakadu libs not found: test are skipped ");
        return;
    }
    if (files.length == 0) {
        LOGGER.warning("No files have been specified. This test will be skipped");
        return;
    }
    final String fileName = files[0];
    // 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");
        return;
    }
    final String suffix = fileName.substring(0, fileName.length() - 4);
    LinkedList<TestConfiguration> configs = new LinkedList<TestConfiguration>();
    JP2KKakaduImageWriteParam param = new JP2KKakaduImageWriteParam();
    param.setSourceRegion(new Rectangle(100, 0, 450, 800));
    param.setSourceSubsampling(2, 3, 0, 0);
    configs.add(new TestConfiguration(outputFileName + "_pp_" + suffix, true, lossLessQuality, false, param));
    configs.add(new TestConfiguration(outputFileName + "_pp_" + suffix, false, lossLessQuality, false, param));
    configs.add(new TestConfiguration(outputFileName + "_pp_" + suffix, true, lossyQuality, false, param));
    configs.add(new TestConfiguration(outputFileName + "_pp_" + suffix, false, lossyQuality, false, param));
    configs.add(new TestConfiguration(outputFileName + "_pp_JAI_" + suffix, true, lossLessQuality, true, param));
    configs.add(new TestConfiguration(outputFileName + "_pp_JAI_" + suffix, false, lossLessQuality, true, 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) Rectangle(java.awt.Rectangle) ImageReader(javax.imageio.ImageReader) File(java.io.File) LinkedList(java.util.LinkedList)

Example 35 with ParameterBlockJAI

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

the class JP2KakaduReadTest method jaiReadFromFile.

@org.junit.Test
public void jaiReadFromFile() throws IOException {
    if (!runTests)
        return;
    final File file = TestData.file(this, "CB_TM432.jp2");
    ImageReadDescriptorMT.register(JAI.getDefaultInstance());
    final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI("ImageReadMT");
    ImageLayout l = new ImageLayout();
    l.setTileHeight(256);
    l.setTileWidth(256);
    JP2KKakaduImageReadParam rp = new JP2KKakaduImageReadParam();
    rp.setSourceSubsampling(1, 1, 0, 0);
    rp.setSourceRegion(new Rectangle(10, 10, 200, 200));
    rp.setInterpolationType(JP2KKakaduImageReadParam.INTERPOLATION_BILINEAR);
    rp.setQualityLayers(2);
    pbjImageRead.setParameter("ReadParam", rp);
    pbjImageRead.setParameter("Input", file);
    pbjImageRead.setParameter("imageChoice", 0);
    RenderedOp image = JAI.create("ImageReadMT", pbjImageRead, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, l));
    if (TestData.isInteractiveTest())
        ImageIOUtilities.visualize(image);
    else
        Assert.assertNotNull(image.getTiles());
}
Also used : RenderedOp(javax.media.jai.RenderedOp) ParameterBlockJAI(javax.media.jai.ParameterBlockJAI) Rectangle(java.awt.Rectangle) File(java.io.File) ImageLayout(javax.media.jai.ImageLayout) RenderingHints(java.awt.RenderingHints)

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