Script
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.InvalidPropertiesFormatException;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFactoryConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
public static class Keys
{
public final static String ISVALID = "isValid";
public final static String ORDER = "order";
public final static String PRECINCTS = "precincts";
public final static String SOP = "sop"; //start of packet marker
public final static String EPH = "eph"; //end of packet header(?)
public final static String LAYERS = "layers";
public final static String LEVELS = "levels";
public final static String CODEBLOCKWIDTH = "codeBlockWidth";
public final static String CODEBLOCKHEIGHT = "codeBlockHeight";
public final static String CODEBLOCKSIZE = "codeBlockSize";
public final static String CODINGBYPASS = "codingBypass";
public final static String TRANSFORMATION = "transformation";
public final static String PRECINCTSIZE = "precinctSize";
public final static String NUMBEROFTILES = "numberOfTiles";
public final static String COMPRESSIONRATES = "compressionRates";
}
//these are the BL jpeg2000 settings loaded as defaults
//irreversible
private static boolean irreversible = true;
//progression order
private static String progressionOrder = "RPCL";
//components?
//tile size (-1 for none)
//private static int tileSize = -1;
private static int numTiles = 1;
//number of levels
private static int levels = 7;
//codestream markers (FIXME check this is all we need for packet length markers)
private static boolean SOP = true;
private static boolean EPH = true;
//precincts
//NOTE: we rely on these being in descending order
//FIXME: openjpeg needs the extra 128 values?
private static int[] precincts = { 256, 256, 128, 128, 128, 128, 128 };
//code block size
private static int codeblockSize = 64;
//coder bypass
private static boolean coderBypass = true; //NOTE: when enabled causes artefacts with openjpeg
//compression rates
//NOTE: these should be in ascending ratio of compression i.e. 1:1 -> 320:1
//also, layers = compressionRates.size
//FIXME: should 1 be 2.16??
private static double[] compressionRates = { 1, 2.4, 2.75, 3.4, 4.6, 7, 11.25, 20, 40, 80, 160, 320 };
DocumentBuilder docB = null;
Document doc = null;
boolean jpylyzerMatch = false;
boolean ssimMatch = false;
boolean profileMatch = true; //assume true unless set to false
String key = "";
String path = "";
String pathCCB = "";
String result = "";
try {
docB = DocumentBuilderFactory.newInstance ().newDocumentBuilder ();
} catch (ParserConfigurationException pce) {}
try {
doc = docB.parse (new ByteArrayInputStream(jpylyzer.getBytes()));
} catch (IOException ioe) {
ioe.printStackTrace ();
}
catch (SAXException se) {
se.printStackTrace ();
}
Node root = doc.getFirstChild ();
XPath xpath = XPathFactory.newInstance ().newXPath ();
key = "";
pathCCB = "/jpylyzer/properties/contiguousCodestreamBox/";
path = pathCCB + "cod/";
try
{
key = Keys.ISVALID;
result = xpath.evaluate ("/jpylyzer/isValidJP2", root);
jpylyzerMatch = new Boolean(result);
key = Keys.ORDER;
result = xpath.evaluate(path + key, root);
if (!result.toLowerCase().equals(progressionOrder.toLowerCase())) {
profileMatch = false;
}
key = Keys.PRECINCTS;
result = xpath.evaluate(path + key, root);
if (!(result.toLowerCase().equals("yes") == (precincts.length > 0))) {
profileMatch = false;
}
key = Keys.SOP; //start of packet marker
result = xpath.evaluate(path + key, root);
if (!(SOP == result.toLowerCase().equals("yes"))) {
profileMatch = false;
}
key = Keys.EPH; //end of packet header(?)
result = xpath.evaluate(path + key, root);
if (!(EPH == result.toLowerCase().equals("yes"))) {
profileMatch = false;
}
key = Keys.LAYERS;
result = xpath.evaluate(path + key, root);
if (!new Integer(result).equals(compressionRates.length)) {
profileMatch = false;
}
key = Keys.LEVELS;
result = xpath.evaluate(path + key, root);
if (!new Integer(result).equals(levels - 1)) {
profileMatch = false;
}
key = Keys.CODEBLOCKWIDTH;
result = xpath.evaluate(path + key, root);
if (!new Integer(result).equals(codeblockSize)) {
profileMatch = false;
}
key = Keys.CODEBLOCKHEIGHT;
result = xpath.evaluate(path + key, root);
if (!new Integer(result).equals(codeblockSize)) {
profileMatch = false;
}
key = Keys.CODINGBYPASS;
result = xpath.evaluate(path + key, root);
if (!(result.toLowerCase().equals("yes") == coderBypass)) {
profileMatch = false;
}
key = Keys.TRANSFORMATION;
result = xpath.evaluate(path + key, root);
if (!(result.toLowerCase().equals("9-7 irreversible") == irreversible)) {
profileMatch = false;
}
int x = 0;
int y = 0;
key = Keys.PRECINCTSIZE;
int count = new Integer(xpath.evaluate("count(" + path + key + "X)", root));
List precs = new LinkedList();
//load the precincts in to an array list
for (int i = 0; i < count; i++) {
//note xpath array references are 1-based, not 0-based
x = new Integer(xpath.evaluate(path + key + "X[" + (i + 1) + "]", root));
y = new Integer(xpath.evaluate(path + key + "Y[" + (i + 1) + "]", root));
//assume x==y
if(x!=y) profileMatch = false;
precs.add(x);
}
//for each precinct in the jpylyzer output...
for(int i=0;i0) profileMatch = false;
path = pathCCB + "siz/";
key = Keys.NUMBEROFTILES;
result = xpath.evaluate(path + key, root);
if (!new Integer(result).equals(numTiles)) {
profileMatch = false;
}
} catch (XPathExpressionException xpee) {
profileMatch = false;
jpylyzerMatch = false;
xpee.printStackTrace ();
}
try {
docB = DocumentBuilderFactory.newInstance ().newDocumentBuilder ();
} catch (ParserConfigurationException pce) { }
try {
doc = docB.parse (new ByteArrayInputStream(siftcomp.getBytes()));
} catch (IOException ioe) {
ioe.printStackTrace ();
} catch (SAXException se) {
se.printStackTrace ();
}
Node root = doc.getFirstChild ();
XPath xpath = XPathFactory.newInstance ().newXPath ();
key = "";
path = "/comparison/task/ssim";
try {
String result = xpath.evaluate (path, root);
ssimMatch = (new Double(result))>0.9;
} catch (XPathExpressionException xpee) {
xpee.printStackTrace ();
}
//compare with input profile
String rep = "\n\n";
rep = rep + "";
rep = rep + jpylyzerMatch;
rep = rep + "\n";
rep = rep + "";
rep = rep + profileMatch;
rep = rep + "\n";
rep = rep + "";
rep = rep + ssimMatch;
rep = rep + "\n";
rep = rep + "\n";
report = rep;
String suc = "FAILURE";
//Beanshell can't do &
if(jpylyzerMatch)
if(profileMatch)
if(ssimMatch) suc = "SUCCESS";
success = suc;
Comments (0)
No comments yet
Log in to make a comment