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;
}
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!");
}
}
Aggregations