Search in sources :

Example 81 with RenderedOp

use of javax.media.jai.RenderedOp in project lotro-tools by dmorcellet.

the class ComparePngFiles method comparePNGFiles.

public static boolean comparePNGFiles(File file1, File file2) {
    RenderedOp image1 = ImageTools.readImage(file1);
    int h1 = image1.getHeight();
    int w1 = image1.getWidth();
    RenderedOp image2 = ImageTools.readImage(file2);
    int h2 = image2.getHeight();
    int w2 = image2.getWidth();
    if ((h1 == h2) && (w1 == w2)) {
        int nbDiffs = 0;
        // int nbPixels=h1*w1;
        boolean same = true;
        Raster r1 = image1.getData();
        int nbBands1 = r1.getNumBands();
        Raster r2 = image2.getData();
        int nbBands2 = r2.getNumBands();
        double[] buffer1 = null;
        double[] buffer2 = null;
        for (int i = 0; i < h1; i++) {
            buffer1 = r1.getPixels(0, i, w1, 1, buffer1);
            buffer2 = r2.getPixels(0, i, w1, 1, buffer2);
            for (int j = 0; j < w1; j++) {
                if (!compareSample(j, buffer1, buffer2, nbBands1, nbBands2)) {
                    nbDiffs++;
                    if (nbDiffs > MAX_DIFFS)
                        same = false;
                }
            }
        /*
        int length1=buffer1.length;
        int length2=buffer2.length;
        if (length1==length2)
        {
          for(int j=0;j<length1;j++)
          {
            if (buffer1[j]!=buffer2[j])
            {
              nbDiffs++;
              same=false;
            }
          }
        }
        else
        {
          System.out.println("Bad length!");
          same=false;
        }
        */
        }
        // System.out.println(nbDiffs+ " / "+nbPixels);
        return same;
    }
    System.out.println("Size differ: h1=" + h1 + ", h2=" + h2 + ", w1=" + w1 + ",w2=" + w2);
    return false;
}
Also used : RenderedOp(javax.media.jai.RenderedOp) Raster(java.awt.image.Raster)

Example 82 with RenderedOp

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

the class JAIDocuImage method identify.

/* Check image size and type and store in ImageFile f */
public ImageInput identify(ImageInput input) throws IOException {
    this.input = input;
    // try parent method first
    ImageInput imf = super.identify(input);
    if (imf != null) {
        return imf;
    }
    /*
		 * try JAI
		 */
    logger.debug("identifying (JAI) " + input);
    try {
        RenderedOp img = null;
        if (input.hasFile()) {
            String t = FileOps.mimeForFile(input.getFile());
            input.setMimetype(t);
            img = JAI.create("fileload", input.getFile().getAbsolutePath());
        } else if (input.hasInputStream()) {
            img = JAI.create("stream", input.getInputStream());
        // FIXME: where do we get the mimetype?
        } else {
            throw new FileOpException("unable to get data for image!");
        }
        ImageSize d = new ImageSize(img.getWidth(), img.getHeight());
        input.setSize(d);
        logger.debug("image size: " + d);
        return input;
    } catch (Exception e) {
        throw new FileOpException("ERROR: unable to identify image!");
    }
}
Also used : RenderedOp(javax.media.jai.RenderedOp) ImageInput(digilib.io.ImageInput) ImageSize(digilib.util.ImageSize) FileOpException(digilib.io.FileOpException) IOException(java.io.IOException) FileOpException(digilib.io.FileOpException)

Aggregations

RenderedOp (javax.media.jai.RenderedOp)82 File (java.io.File)72 ParameterBlockJAI (javax.media.jai.ParameterBlockJAI)71 Test (org.junit.Test)61 ImageReadParam (javax.imageio.ImageReadParam)48 AbstractGDALTest (it.geosolutions.imageio.gdalframework.AbstractGDALTest)32 ImageWriter (javax.imageio.ImageWriter)28 ImageLayout (javax.media.jai.ImageLayout)28 ImageWriteParam (javax.imageio.ImageWriteParam)23 RenderingHints (java.awt.RenderingHints)21 FileImageOutputStreamExtImpl (it.geosolutions.imageio.stream.output.FileImageOutputStreamExtImpl)20 ImageReader (javax.imageio.ImageReader)14 FileNotFoundException (java.io.FileNotFoundException)13 Rectangle (java.awt.Rectangle)9 IIOMetadata (javax.imageio.metadata.IIOMetadata)5 IOException (java.io.IOException)4 ImageInputStream (javax.imageio.stream.ImageInputStream)4 FileImageInputStreamExtImpl (it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl)3 ColorSpace (java.awt.color.ColorSpace)3 ColorModel (java.awt.image.ColorModel)3