1*cdf0e10cSrcweir /* 2*cdf0e10cSrcweir * ************************************************************************ 3*cdf0e10cSrcweir * 4*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 7*cdf0e10cSrcweir * 8*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 9*cdf0e10cSrcweir * 10*cdf0e10cSrcweir * This file is part of OpenOffice.org. 11*cdf0e10cSrcweir * 12*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 13*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 14*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 15*cdf0e10cSrcweir * 16*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 17*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 18*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 20*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 21*cdf0e10cSrcweir * 22*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 23*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 24*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 25*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 26*cdf0e10cSrcweir * 27*cdf0e10cSrcweir * *********************************************************************** 28*cdf0e10cSrcweir */ 29*cdf0e10cSrcweir package graphical; 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir import helper.OSHelper; 32*cdf0e10cSrcweir import helper.ProcessHandler; 33*cdf0e10cSrcweir import java.io.File; 34*cdf0e10cSrcweir import java.io.IOException; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir /** 37*cdf0e10cSrcweir * Helper class to interpret a jpg filename 38*cdf0e10cSrcweir */ 39*cdf0e10cSrcweir class NameDPIPage 40*cdf0e10cSrcweir { 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir String Name; 43*cdf0e10cSrcweir int DPI; 44*cdf0e10cSrcweir int Page; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir private NameDPIPage(String _sName, int _nDPI, int _nPage) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir Name = _sName; 49*cdf0e10cSrcweir DPI = _nDPI; 50*cdf0e10cSrcweir Page = _nPage; 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir public static NameDPIPage interpret(String _sFilename) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir String sBasename = FileHelper.getBasename(_sFilename); // if exist a path, remove it 56*cdf0e10cSrcweir String sNameNoSuffix = FileHelper.getNameNoSuffix(sBasename); // remove extension (.jpg) 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir // check if there exist a 'DPI_' at specific position 59*cdf0e10cSrcweir String sDPICheck = sNameNoSuffix.substring(sNameNoSuffix.length() - 8, sNameNoSuffix.length() - 4); 60*cdf0e10cSrcweir String sName; 61*cdf0e10cSrcweir int nDPI = -1; 62*cdf0e10cSrcweir int nPage = -1; 63*cdf0e10cSrcweir if (sDPICheck.equals("DPI_")) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir // seems to be a generated filename by us. 66*cdf0e10cSrcweir int nDPIStart = sNameNoSuffix.lastIndexOf("_", sNameNoSuffix.length() - 8); 67*cdf0e10cSrcweir sName = sNameNoSuffix.substring(0, nDPIStart); 68*cdf0e10cSrcweir if (nDPIStart > 0) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir String sDPI = sNameNoSuffix.substring(nDPIStart + 1, sNameNoSuffix.length() - 8); 71*cdf0e10cSrcweir try 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir nDPI = Integer.valueOf(sDPI).intValue(); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir catch (java.lang.NumberFormatException e) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir GlobalLogWriter.println("DPI: Number format exception"); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir String sPage = sNameNoSuffix.substring(sNameNoSuffix.length() - 4); 80*cdf0e10cSrcweir try 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir nPage = Integer.valueOf(sPage).intValue(); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir catch (java.lang.NumberFormatException e) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir GlobalLogWriter.println("Page: Number format exception"); 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir else 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir sName = sNameNoSuffix; 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir return new NameDPIPage(sName, nDPI, nPage); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir class CountNotXXXPixelsFromImage extends Thread 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir private String m_sFilename; 103*cdf0e10cSrcweir protected int m_nValue; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir CountNotXXXPixelsFromImage(String _sFilename) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir m_sFilename = _sFilename; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir public int getValue() 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir return m_nValue; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir protected void setValue(int _nValue) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir m_nValue = _nValue; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir protected String getFilename() 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir return m_sFilename; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir class CountNotWhitePixelsFromImage extends CountNotXXXPixelsFromImage 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir CountNotWhitePixelsFromImage(String _sFilename) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir super(_sFilename); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir public void run() 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir try 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir final int nNotWhiteCount = PixelCounter.countNotWhitePixelsFromImage(getFilename()); 139*cdf0e10cSrcweir setValue(nNotWhiteCount); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir catch (java.io.IOException e) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir m_nValue = -1; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir class CountNotBlackPixelsFromImage extends CountNotXXXPixelsFromImage 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir CountNotBlackPixelsFromImage(String _sFilename) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir super(_sFilename); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir public void run() 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir try 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir final int nNotBlackCount = PixelCounter.countNotBlackPixelsFromImage(getFilename()); 161*cdf0e10cSrcweir setValue(nNotBlackCount); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir catch (java.io.IOException e) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir m_nValue = -1; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir /** 171*cdf0e10cSrcweir * 172*cdf0e10cSrcweir * @author ll93751 173*cdf0e10cSrcweir */ 174*cdf0e10cSrcweir public class JPEGComparator extends EnhancedComplexTestCase 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir // @Override 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir public String[] getTestMethodNames() 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir return new String[]{"CompareJPEGvsJPEG"}; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir private Tolerance m_aTolerance; 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir /** 185*cdf0e10cSrcweir * test function. 186*cdf0e10cSrcweir */ 187*cdf0e10cSrcweir public void CompareJPEGvsJPEG() 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir GlobalLogWriter.set(log); 190*cdf0e10cSrcweir ParameterHelper aParam = new ParameterHelper(param); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir // run through all documents found in Inputpath 193*cdf0e10cSrcweir foreachJPEGcompareWithJPEG(aParam); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir public void checkOneFile(String _sDocumentName, String _sResult, ParameterHelper _aParams) throws OfficeException 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir // private void callEveryPictureInIniFile(IniFile _aIniFile, String _sSectionName, ParameterHelper _aParam) 199*cdf0e10cSrcweir // { 200*cdf0e10cSrcweir String sPath = FileHelper.getPath(_sDocumentName); 201*cdf0e10cSrcweir String sSectionName = FileHelper.getBasename(_sDocumentName); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir // take the build id out of the ini file in the reference file and put it into the current parameter helper 204*cdf0e10cSrcweir String sIniFileForRefBuildID = FileHelper.appendPath(sPath, sSectionName + ".ini"); 205*cdf0e10cSrcweir IniFile aIniFileForRefBuildID = new IniFile(sIniFileForRefBuildID); 206*cdf0e10cSrcweir String sRefBuildID = aIniFileForRefBuildID.getValue("global", "buildid"); 207*cdf0e10cSrcweir aIniFileForRefBuildID.close(); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir _aParams.getTestParameters().put("RefBuildId", sRefBuildID); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir String sIniFile = FileHelper.appendPath(sPath, "index.ini"); 212*cdf0e10cSrcweir IniFile aIniFile = new IniFile(sIniFile); 213*cdf0e10cSrcweir if (aIniFile.hasValue(sSectionName, "pages")) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir // only which has 'pages' has also pictures 216*cdf0e10cSrcweir int nPages = aIniFile.getIntValue(sSectionName, "pages", 0); 217*cdf0e10cSrcweir String sJPEGSchema = aIniFile.getValue(sSectionName, "jpegschema"); 218*cdf0e10cSrcweir int nTolerance = aIniFile.getIntValue(sSectionName, "tolerance", 0); 219*cdf0e10cSrcweir m_aTolerance = new Tolerance(nTolerance); 220*cdf0e10cSrcweir for (int i = 1; i <= nPages; i++) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir String sJPEGFilename = JPEGCreator.getFilenameForJPEGSchema(sJPEGSchema, i); 223*cdf0e10cSrcweir // String sPath = FileHelper.getPath(_aParam.getInputPath()); 224*cdf0e10cSrcweir String sJPEGPath = FileHelper.getPath(sJPEGFilename); 225*cdf0e10cSrcweir if (!sPath.equals(sJPEGPath)) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir GlobalLogWriter.println("Path where to find the index and where to file the JPEG pictures are not the same."); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir // String sEntry = FileHelper.appendPath(sPath, sSection); 231*cdf0e10cSrcweir File aFile = new File(sJPEGFilename); 232*cdf0e10cSrcweir assure("File '" + sJPEGFilename + "' doesn't exists.", aFile.exists(), true); 233*cdf0e10cSrcweir if (aFile.exists()) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir GlobalLogWriter.println("Page: " + i); 236*cdf0e10cSrcweir checkOnePicture(sJPEGFilename, _sResult, _aParams); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir else 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir GlobalLogWriter.println("The document '" + sSectionName + "' seems to have no picture representation."); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir String sResultIniFile = FileHelper.appendPath(_sResult, sSectionName); 246*cdf0e10cSrcweir evaluateResult(sResultIniFile, _aParams); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir private void evaluateResult(String _sDocument, ParameterHelper _aParams) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir String sResultIniFile = _sDocument + ".ini"; 252*cdf0e10cSrcweir File aFile = new File(sResultIniFile); 253*cdf0e10cSrcweir assure("Result file doesn't exists " + sResultIniFile, aFile.exists()); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir int good = 0; 256*cdf0e10cSrcweir int bad = 0; 257*cdf0e10cSrcweir int ugly = 0; 258*cdf0e10cSrcweir int ok_status = 1; // 1=ok 2=bad 3=ugly 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir IniFile aResultIniFile = new IniFile(sResultIniFile); 261*cdf0e10cSrcweir int nPages = aResultIniFile.getIntValue("global", "pages", 0); 262*cdf0e10cSrcweir for (int i = 0; i < nPages; i++) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir String sCurrentPage = "page" + String.valueOf(i + 1); 265*cdf0e10cSrcweir int nPercent = aResultIniFile.getIntValue(sCurrentPage, "percent", -1); 266*cdf0e10cSrcweir if (nPercent == 0) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir good++; 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir else if (nPercent <= 5) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir bad++; 273*cdf0e10cSrcweir ok_status = 2; 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir else 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir ugly++; 278*cdf0e10cSrcweir ok_status = 3; 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir assure("Error: document doesn't contains pages", nPages > 0); 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir // TODO: this information has to come out of the ini files 285*cdf0e10cSrcweir String sStatusRunThrough = "PASSED, "; 286*cdf0e10cSrcweir String sPassed = "OK"; 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir String sStatusMessage = "From " + nPages + " page(s) are: "; 289*cdf0e10cSrcweir String sGood = ""; 290*cdf0e10cSrcweir String sBad = ""; 291*cdf0e10cSrcweir String sUgly = ""; 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir if (good > 0) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir sGood = " good:=" + good; 296*cdf0e10cSrcweir sStatusMessage += sGood; 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir if (bad > 0) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir sBad = " bad:=" + bad; 301*cdf0e10cSrcweir sStatusMessage += sBad; 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir if (ugly > 0) 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir sUgly = " ugly:=" + ugly; 306*cdf0e10cSrcweir sStatusMessage += sUgly; 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir // Failure matrix 310*cdf0e10cSrcweir // 0 1 311*cdf0e10cSrcweir // ugly OK FAILED 312*cdf0e10cSrcweir // bad OK 313*cdf0e10cSrcweir // good OK 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir if (ugly > 0) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir sPassed = "FAILED"; 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir else 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir if (bad > 0) 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir sPassed = "NEED A LOOK"; 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir else 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir sPassed = "OK"; 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir sStatusRunThrough += sPassed; 331*cdf0e10cSrcweir aResultIniFile.insertValue("global", "state", sStatusRunThrough); 332*cdf0e10cSrcweir aResultIniFile.insertValue("global", "info", sStatusMessage); 333*cdf0e10cSrcweir aResultIniFile.close(); 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir _aParams.getTestParameters().put("current_state", sStatusRunThrough); 336*cdf0e10cSrcweir _aParams.getTestParameters().put("current_info", sStatusMessage); 337*cdf0e10cSrcweir _aParams.getTestParameters().put("current_ok_status", ok_status); 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir // if we have a ugly page, we must return this as a FAILED STATUS in Log file! 340*cdf0e10cSrcweir assure("There exist pages marked as ugly.", ugly == 0); 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir private void checkOnePicture(String _sDocumentName, String _sResult, ParameterHelper _aParams) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir GlobalLogWriter.println("JPEG: Compare difference between '" + _sDocumentName + "' and '" + _sResult + "'"); 346*cdf0e10cSrcweir File aResultFile = new File(_sResult); 347*cdf0e10cSrcweir if (aResultFile.isDirectory()) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir // result is just a directory, so we search for the basename of the source and take this. 350*cdf0e10cSrcweir String sBasename = FileHelper.getBasename(_sDocumentName); 351*cdf0e10cSrcweir String sResultFilename = FileHelper.appendPath(_sResult, sBasename); 352*cdf0e10cSrcweir aResultFile = new File(sResultFilename); 353*cdf0e10cSrcweir if (aResultFile.exists()) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir // Original and Result exists 356*cdf0e10cSrcweir String sInputPath = _aParams.getInputPath(); 357*cdf0e10cSrcweir if (sInputPath.toLowerCase().endsWith("index.ini")) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir // special case 360*cdf0e10cSrcweir // we want to get the buildid from the info file. 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir compareJPEG(_sDocumentName, sResultFilename, _aParams); 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir else 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir String sResultFilenamePDF = util.utils.replaceAll13(sResultFilename, ".ps_", ".pdf_"); 369*cdf0e10cSrcweir File aResultPDFFile = new File(sResultFilenamePDF); 370*cdf0e10cSrcweir if (aResultPDFFile.exists()) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir // Original and Result exists 373*cdf0e10cSrcweir String sInputPath = _aParams.getInputPath(); 374*cdf0e10cSrcweir if (sInputPath.toLowerCase().endsWith("index.ini")) 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir // special case 377*cdf0e10cSrcweir // we want to get the buildid from the info file. 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir compareJPEG(_sDocumentName, sResultFilenamePDF, _aParams); 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir else 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir GlobalLogWriter.println("Warning: Result JPEG doesn't exists '" + sResultFilename + "'"); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir else 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir // result is also a file 391*cdf0e10cSrcweir if (aResultFile.exists()) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir compareJPEG(_sDocumentName, _sResult, _aParams); 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir else 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir GlobalLogWriter.println("Warning: Result JPEG doesn't exists '" + _sResult + "'"); 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir /** 403*cdf0e10cSrcweir * compare 2 JPEGs, it is a need, that both _sDocumentName and _sResultFilename exist. 404*cdf0e10cSrcweir * @param _sDocumentName 405*cdf0e10cSrcweir * @param _sResult 406*cdf0e10cSrcweir * @param _aParams 407*cdf0e10cSrcweir * @return 0=no difference !=0 both files differ 408*cdf0e10cSrcweir */ 409*cdf0e10cSrcweir private void compareJPEG(String _sDocumentName, String _sResult, ParameterHelper _aParams) 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir NameDPIPage aNameDPIPage = NameDPIPage.interpret(_sDocumentName); 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir String sSourceBasename = FileHelper.getBasename(_sDocumentName); 414*cdf0e10cSrcweir String sSourcePath = FileHelper.getPath(_sDocumentName); 415*cdf0e10cSrcweir String sDestinationBasename = FileHelper.getBasename(_sResult); 416*cdf0e10cSrcweir String sDestinationPath = FileHelper.getPath(_sResult); 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir if (!sSourcePath.equals(sDestinationPath)) 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir // we want to have all in one Directory, Original, Reference and the Difference result. 421*cdf0e10cSrcweir // copy the original file to the reference path 422*cdf0e10cSrcweir String sNewSourceBasename = "Original_" + sSourceBasename; 423*cdf0e10cSrcweir // String sSource = FileHelper.appendPath(sSourcePath, sSourceBasename); 424*cdf0e10cSrcweir String sSource = _sDocumentName; 425*cdf0e10cSrcweir String sDestination = FileHelper.appendPath(sDestinationPath, sNewSourceBasename); 426*cdf0e10cSrcweir FileHelper.copy(sSource, sDestination); 427*cdf0e10cSrcweir sSourceBasename = sNewSourceBasename; 428*cdf0e10cSrcweir // 429*cdf0e10cSrcweir JPEGCreator.convertToNearSameFileWithWidth340(sDestination); 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir String sDifferenceBasename = "Difference_between_" + FileHelper.getNameNoSuffix(sSourceBasename) + "_and_" + FileHelper.getNameNoSuffix(sDestinationBasename) + ".jpg"; 432*cdf0e10cSrcweir // String sDifferencePath = sDestinationPath; 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir String sSource = FileHelper.appendPath(sDestinationPath, sSourceBasename); 435*cdf0e10cSrcweir String sDestination = FileHelper.appendPath(sDestinationPath, sDestinationBasename); 436*cdf0e10cSrcweir String sDifference = FileHelper.appendPath(sDestinationPath, sDifferenceBasename); 437*cdf0e10cSrcweir int nErr = compareJPEG(sSource, sDestination, sDifference); 438*cdf0e10cSrcweir if (nErr == 0 && FileHelper.exists(sDifference)) 439*cdf0e10cSrcweir { 440*cdf0e10cSrcweir // check the difference, returns the count of different colors 441*cdf0e10cSrcweir // this means, 1=only one color, no differences found. 442*cdf0e10cSrcweir int nResult = identify(sDifference); 443*cdf0e10cSrcweir int nPercentColorDiffer = 0; 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir String sResult = "YES"; 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir if (m_aTolerance != null) 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir final int nAcceptedTolerance = m_aTolerance.getAccept(); 450*cdf0e10cSrcweir if (nResult <= nAcceptedTolerance) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir nResult = 1; 453*cdf0e10cSrcweir sResult = "IN TOLERANCE"; 454*cdf0e10cSrcweir GlobalLogWriter.println("The differences are in tolerance."); 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir if (nResult != 1) 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir sResult = "NO"; 461*cdf0e10cSrcweir try 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir nPercentColorDiffer = estimateGfx(sSource, sDestination, sDifference); 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir catch (java.io.IOException e) 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir GlobalLogWriter.println("Can't estimate the different colors. " + e.getMessage()); 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir // store the result in a result.ini file 472*cdf0e10cSrcweir String sResultFile = FileHelper.appendPath(sDestinationPath, aNameDPIPage.Name + ".ini"); 473*cdf0e10cSrcweir int nPage = aNameDPIPage.Page; 474*cdf0e10cSrcweir if (nPage < 0) 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir nPage = 0; 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir IniFile aResultIni = new IniFile(sResultFile); 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir String[] aComment = 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir "; This file is automatically created by a graphical.JPEGComparator run", 483*cdf0e10cSrcweir "; ", 484*cdf0e10cSrcweir "; If you see this file in a browser you may have forgotten to set the follows in the property file", 485*cdf0e10cSrcweir "; " + PropertyName.DOC_COMPARATOR_HTML_OUTPUT_PREFIX + "=http://<computer>/gfxcmp_ui/cw.php?inifile=", 486*cdf0e10cSrcweir "; Please check the documentation if you got confused.", 487*cdf0e10cSrcweir "; ", 488*cdf0e10cSrcweir "; " 489*cdf0e10cSrcweir }; 490*cdf0e10cSrcweir aResultIni.insertFirstComment(aComment); 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir // write down the global flags 493*cdf0e10cSrcweir int nMaxPage = Math.max(nPage, aResultIni.getIntValue("global", "pages", 0)); 494*cdf0e10cSrcweir aResultIni.insertValue("global", "pages", nMaxPage); 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir // INIoutput.writeValue("buildid", _sBuildID); 497*cdf0e10cSrcweir // INIoutput.writeValue("refbuildid", _sRefBuildID); 498*cdf0e10cSrcweir String sRefBuildId = (String) _aParams.getTestParameters().get("RefBuildId"); 499*cdf0e10cSrcweir if (sRefBuildId == null) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir sRefBuildId = ""; 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir aResultIni.insertValue("global", "refbuildid", sRefBuildId); 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir aResultIni.insertValue("global", "diffdiff", "no"); 506*cdf0e10cSrcweir aResultIni.insertValue("global", "basename", aNameDPIPage.Name); 507*cdf0e10cSrcweir aResultIni.insertValue("global", "dpi", aNameDPIPage.DPI); 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir // write down flags for each page 510*cdf0e10cSrcweir String sSection = "page" + String.valueOf(nPage); 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir aResultIni.insertValue(sSection, "oldgfx", sSource); 513*cdf0e10cSrcweir aResultIni.insertValue(sSection, "newgfx", sDestination); 514*cdf0e10cSrcweir aResultIni.insertValue(sSection, "diffgfx", sDifference); 515*cdf0e10cSrcweir aResultIni.insertValue(sSection, "percent", nPercentColorDiffer); 516*cdf0e10cSrcweir aResultIni.insertValue(sSection, "BM", "false"); 517*cdf0e10cSrcweir aResultIni.insertValue(sSection, "result", sResult); 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir aResultIni.close(); 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir } 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir // // This creates a status for exact on document 524*cdf0e10cSrcweir // static boolean createINIStatus(StatusHelper[] aList, String _sFilenamePrefix, String _sOutputPath, String _sAbsoluteInputFile, String _sBuildID, String _sRefBuildID) 525*cdf0e10cSrcweir // { 526*cdf0e10cSrcweir // // Status 527*cdf0e10cSrcweir // String fs = System.getProperty("file.separator"); 528*cdf0e10cSrcweir // String sBasename = FileHelper.getBasename(_sAbsoluteInputFile); 529*cdf0e10cSrcweir // String sNameNoSuffix = FileHelper.getNameNoSuffix(sBasename); 530*cdf0e10cSrcweir //// String sHTMLFile = _sFilenamePrefix + sNameNoSuffix + ".html"; 531*cdf0e10cSrcweir //// HTMLOutputter HTMLoutput = HTMLOutputter.create(_sOutputPath, sHTMLFile, "", ""); 532*cdf0e10cSrcweir //// HTMLoutput.header(sNameNoSuffix); 533*cdf0e10cSrcweir //// TODO: version info was fine 534*cdf0e10cSrcweir //// HTMLoutput.checkSection(sBasename); 535*cdf0e10cSrcweir // // Status end 536*cdf0e10cSrcweir // 537*cdf0e10cSrcweir // String sINIFile = _sFilenamePrefix + sNameNoSuffix + ".ini"; 538*cdf0e10cSrcweir // INIOutputter INIoutput = INIOutputter.create(_sOutputPath, sINIFile, "", ""); 539*cdf0e10cSrcweir // INIoutput.createHeader(); 540*cdf0e10cSrcweir //// TODO: version info was fine 541*cdf0e10cSrcweir // 542*cdf0e10cSrcweir // INIoutput.writeSection("global"); 543*cdf0e10cSrcweir // INIoutput.writeValue("pages", String.valueOf(aList.length)); 544*cdf0e10cSrcweir // INIoutput.writeValue("buildid", _sBuildID); 545*cdf0e10cSrcweir // INIoutput.writeValue("refbuildid", _sRefBuildID); 546*cdf0e10cSrcweir // INIoutput.writeValue("diffdiff", "no"); 547*cdf0e10cSrcweir // INIoutput.writeValue("basename", sBasename); 548*cdf0e10cSrcweir // 549*cdf0e10cSrcweir // boolean bResultIsOk = true; // result over all pages 550*cdf0e10cSrcweir // for (int i=0;i<aList.length; i++) 551*cdf0e10cSrcweir // { 552*cdf0e10cSrcweir // INIoutput.writeSection("page" + String.valueOf(i + 1)); // list start at point 0, but this is page 1 and so on... current_page = (i + 1) 553*cdf0e10cSrcweir // aList[i].printStatus(); 554*cdf0e10cSrcweir // 555*cdf0e10cSrcweir // boolean bCurrentResult = true; // result over exact one page 556*cdf0e10cSrcweir // 557*cdf0e10cSrcweir // int nCurrentDiffStatus = aList[i].nDiffStatus; 558*cdf0e10cSrcweir // 559*cdf0e10cSrcweir // // check if the status is in a defined range 560*cdf0e10cSrcweir // if (nCurrentDiffStatus == StatusHelper.DIFF_NO_DIFFERENCES) 561*cdf0e10cSrcweir // { 562*cdf0e10cSrcweir // // ok. 563*cdf0e10cSrcweir // } 564*cdf0e10cSrcweir // else if (nCurrentDiffStatus == StatusHelper.DIFF_DIFFERENCES_FOUND && aList[i].nPercent < 5) 565*cdf0e10cSrcweir // { 566*cdf0e10cSrcweir // // ok. 567*cdf0e10cSrcweir // } 568*cdf0e10cSrcweir // else if (nCurrentDiffStatus == StatusHelper.DIFF_AFTER_MOVE_DONE_NO_PROBLEMS) 569*cdf0e10cSrcweir // { 570*cdf0e10cSrcweir // // ok. 571*cdf0e10cSrcweir // } 572*cdf0e10cSrcweir // else if (nCurrentDiffStatus == StatusHelper.DIFF_AFTER_MOVE_DONE_DIFFERENCES_FOUND && aList[i].nPercent2 < 5) 573*cdf0e10cSrcweir // { 574*cdf0e10cSrcweir // // ok. 575*cdf0e10cSrcweir // } 576*cdf0e10cSrcweir // else 577*cdf0e10cSrcweir // { 578*cdf0e10cSrcweir // // failed. 579*cdf0e10cSrcweir // bCurrentResult = false; // logic: nDiff==0 = true if there is no difference 580*cdf0e10cSrcweir // } 581*cdf0e10cSrcweir // 582*cdf0e10cSrcweir // // Status 583*cdf0e10cSrcweir //// HTMLoutput.checkLine(aList[i], bCurrentResult); 584*cdf0e10cSrcweir // INIoutput.checkLine(aList[i], bCurrentResult); 585*cdf0e10cSrcweir // bResultIsOk &= bCurrentResult; 586*cdf0e10cSrcweir // } 587*cdf0e10cSrcweir // // Status 588*cdf0e10cSrcweir //// HTMLoutput.close(); 589*cdf0e10cSrcweir // INIoutput.close(); 590*cdf0e10cSrcweir // return bResultIsOk; 591*cdf0e10cSrcweir // } 592*cdf0e10cSrcweir /** 593*cdf0e10cSrcweir * count how much pixel differ and between Old or New and the Difference graphics 594*cdf0e10cSrcweir * 595*cdf0e10cSrcweir * First, count the old graphics, then the new graphics due to the fact both should be equal 596*cdf0e10cSrcweir * it should be legal to take result from old or new. We take the graphics with less values. 597*cdf0e10cSrcweir * 598*cdf0e10cSrcweir * Second, count the difference graphics, now take the percent algorithm and 599*cdf0e10cSrcweir * build a percent value, which contain the number of different pixels as a percent value 600*cdf0e10cSrcweir * 601*cdf0e10cSrcweir * Interpretation: 602*cdf0e10cSrcweir * 0% there is no difference 603*cdf0e10cSrcweir * 604*cdf0e10cSrcweir * <100% Take a look into the difference graphics, maybe the difference graphics shows 605*cdf0e10cSrcweir * text like outlined or the text is little bit move left, right up or down. 606*cdf0e10cSrcweir * 607*cdf0e10cSrcweir * >>100% Yes it's possible that there is a difference more then 100%, maybe a font problem 608*cdf0e10cSrcweir * between old and new graphics. The font of the new graphics is little bit bigger, 609*cdf0e10cSrcweir * so the pixel count between old graphics and new graphics is twice the more. 610*cdf0e10cSrcweir * 611*cdf0e10cSrcweir * @param _sOldGfx path & name to the jpeg file (1) 612*cdf0e10cSrcweir * @param _sNewGfx path & name to the other jpeg file (2) 613*cdf0e10cSrcweir * @param _sDiffGfx path & name to the new difference file which shows the difference between (1) and (2) 614*cdf0e10cSrcweir * @return the count of different pixels 615*cdf0e10cSrcweir * @throws java.io.IOException if file access is not possible 616*cdf0e10cSrcweir */ 617*cdf0e10cSrcweir public static int estimateGfx(String _sOldGfx, String _sNewGfx, String _sDiffGfx) 618*cdf0e10cSrcweir throws java.io.IOException 619*cdf0e10cSrcweir { 620*cdf0e10cSrcweir TimeHelper a = new TimeHelper(); 621*cdf0e10cSrcweir a.start(); 622*cdf0e10cSrcweir // Count Pixels 623*cdf0e10cSrcweir final int nNotWhiteCount_OldGraphic = PixelCounter.countNotWhitePixelsFromImage(_sOldGfx); 624*cdf0e10cSrcweir final int nNotWhiteCount_NewGraphic = PixelCounter.countNotWhitePixelsFromImage(_sNewGfx); 625*cdf0e10cSrcweir final int nNotBlackCount_DiffGraphic = PixelCounter.countNotBlackPixelsFromImage(_sDiffGfx); 626*cdf0e10cSrcweir 627*cdf0e10cSrcweir // Count Pixels in different threads 628*cdf0e10cSrcweir // CountNotWhitePixelsFromImage t1 = new CountNotWhitePixelsFromImage(_sOldGfx); 629*cdf0e10cSrcweir // CountNotWhitePixelsFromImage t2 = new CountNotWhitePixelsFromImage(_sNewGfx); 630*cdf0e10cSrcweir // CountNotBlackPixelsFromImage t3 = new CountNotBlackPixelsFromImage(_sDiffGfx); 631*cdf0e10cSrcweir // t1.start(); 632*cdf0e10cSrcweir // t2.start(); 633*cdf0e10cSrcweir // t3.start(); 634*cdf0e10cSrcweir // try 635*cdf0e10cSrcweir // { 636*cdf0e10cSrcweir // t1.join(); 637*cdf0e10cSrcweir // } 638*cdf0e10cSrcweir // catch (InterruptedException ex) 639*cdf0e10cSrcweir // { 640*cdf0e10cSrcweir // GlobalLogWriter.get().println("Thread 1 failed: " + ex.getMessage()); 641*cdf0e10cSrcweir // } 642*cdf0e10cSrcweir // try 643*cdf0e10cSrcweir // { 644*cdf0e10cSrcweir // t2.join(); 645*cdf0e10cSrcweir // } 646*cdf0e10cSrcweir // catch (InterruptedException ex) 647*cdf0e10cSrcweir // { 648*cdf0e10cSrcweir // GlobalLogWriter.get().println("Thread 2 failed: " + ex.getMessage()); 649*cdf0e10cSrcweir // } 650*cdf0e10cSrcweir // try 651*cdf0e10cSrcweir // { 652*cdf0e10cSrcweir // t3.join(); 653*cdf0e10cSrcweir // } 654*cdf0e10cSrcweir // catch (InterruptedException ex) 655*cdf0e10cSrcweir // { 656*cdf0e10cSrcweir // GlobalLogWriter.get().println("Thread 3 failed: " + ex.getMessage()); 657*cdf0e10cSrcweir // } 658*cdf0e10cSrcweir // final int nNotWhiteCount_OldGraphic = t1.getValue(); 659*cdf0e10cSrcweir // final int nNotWhiteCount_NewGraphic = t2.getValue(); 660*cdf0e10cSrcweir // final int nNotBlackCount_DiffGraphic = t3.getValue(); 661*cdf0e10cSrcweir 662*cdf0e10cSrcweir a.stop(); 663*cdf0e10cSrcweir GlobalLogWriter.println("Thread Time is: " + a.getTime()); 664*cdf0e10cSrcweir 665*cdf0e10cSrcweir int nMinNotWhiteCount = Math.min(nNotWhiteCount_NewGraphic, nNotWhiteCount_OldGraphic); 666*cdf0e10cSrcweir 667*cdf0e10cSrcweir // check if not zero 668*cdf0e10cSrcweir if (nMinNotWhiteCount == 0) 669*cdf0e10cSrcweir { 670*cdf0e10cSrcweir nMinNotWhiteCount = Math.max(nNotWhiteCount_NewGraphic, nNotWhiteCount_OldGraphic); 671*cdf0e10cSrcweir if (nMinNotWhiteCount == 0) 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir nMinNotWhiteCount = 1; 674*cdf0e10cSrcweir } 675*cdf0e10cSrcweir } 676*cdf0e10cSrcweir 677*cdf0e10cSrcweir int nPercent = Math.abs(nNotBlackCount_DiffGraphic * 100 / nMinNotWhiteCount); 678*cdf0e10cSrcweir GlobalLogWriter.println("Graphics check, pixel based:" + String.valueOf(nPercent) + "% pixel differ "); 679*cdf0e10cSrcweir return nPercent; 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir private static int compareJPEG(String _sOldGfx, String _sNewGfx, String _sDiffGfx) 683*cdf0e10cSrcweir { 684*cdf0e10cSrcweir String sComposite = "composite"; 685*cdf0e10cSrcweir if (OSHelper.isWindows()) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir sComposite = "composite.exe"; 688*cdf0e10cSrcweir String sIMPath = (String) param.get("imagemagick.path"); 689*cdf0e10cSrcweir if (sIMPath != null) 690*cdf0e10cSrcweir { 691*cdf0e10cSrcweir sComposite = FileHelper.appendPath(sIMPath, sComposite); 692*cdf0e10cSrcweir } 693*cdf0e10cSrcweir } 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir // String sCommand = sComposite + " -compose difference " + 696*cdf0e10cSrcweir // StringHelper.doubleQuoteIfNeed(_sOldGfx) + " " + 697*cdf0e10cSrcweir // StringHelper.doubleQuoteIfNeed(_sNewGfx) + " " + 698*cdf0e10cSrcweir // StringHelper.doubleQuoteIfNeed(_sDiffGfx); 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir String[] sCommandArray = 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir sComposite, 703*cdf0e10cSrcweir "-compose", 704*cdf0e10cSrcweir "difference", 705*cdf0e10cSrcweir _sOldGfx, 706*cdf0e10cSrcweir _sNewGfx, 707*cdf0e10cSrcweir _sDiffGfx 708*cdf0e10cSrcweir }; 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir ProcessHandler aHandler = new ProcessHandler(sCommandArray); 711*cdf0e10cSrcweir boolean bBackValue = aHandler.executeSynchronously(); 712*cdf0e10cSrcweir int nExitCode = aHandler.getExitCode(); 713*cdf0e10cSrcweir if (nExitCode != 0) 714*cdf0e10cSrcweir { 715*cdf0e10cSrcweir GlobalLogWriter.println("'" + sComposite + "' return with "); 716*cdf0e10cSrcweir String sBack = aHandler.getOutputText(); 717*cdf0e10cSrcweir GlobalLogWriter.println("'" + sBack + "'"); 718*cdf0e10cSrcweir } 719*cdf0e10cSrcweir else 720*cdf0e10cSrcweir { 721*cdf0e10cSrcweir // creates an extra smaller difference picture 722*cdf0e10cSrcweir File aDiffFile = new File(_sDiffGfx); 723*cdf0e10cSrcweir if (aDiffFile.exists()) 724*cdf0e10cSrcweir { 725*cdf0e10cSrcweir JPEGCreator.convertToNearSameFileWithWidth340(_sDiffGfx); 726*cdf0e10cSrcweir } 727*cdf0e10cSrcweir } 728*cdf0e10cSrcweir return nExitCode; 729*cdf0e10cSrcweir } 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir /** 732*cdf0e10cSrcweir * wrapper for ImageMagick identify, 733*cdf0e10cSrcweir * function checks how many different colors a picture contains. 734*cdf0e10cSrcweir * if it's only one color (nResult==1), like background color, there is no difference. 735*cdf0e10cSrcweir */ 736*cdf0e10cSrcweir int identify(String _sDiffGfx) 737*cdf0e10cSrcweir { 738*cdf0e10cSrcweir int nResult = 0; 739*cdf0e10cSrcweir // would like to know what the meaning of %k is for ImageMagick's 'identify' 740*cdf0e10cSrcweir String sIM_Format = "%k"; 741*cdf0e10cSrcweir // if (OSHelper.isWindows()) 742*cdf0e10cSrcweir // { 743*cdf0e10cSrcweir // sIM_Format = "%%k"; 744*cdf0e10cSrcweir // } 745*cdf0e10cSrcweir 746*cdf0e10cSrcweir String sIdentify = "identify"; 747*cdf0e10cSrcweir if (OSHelper.isWindows()) 748*cdf0e10cSrcweir { 749*cdf0e10cSrcweir sIdentify = "identify.exe"; 750*cdf0e10cSrcweir String sIMPath = (String) param.get("imagemagick.path"); 751*cdf0e10cSrcweir if (sIMPath != null) 752*cdf0e10cSrcweir { 753*cdf0e10cSrcweir sIdentify = FileHelper.appendPath(sIMPath, sIdentify); 754*cdf0e10cSrcweir } 755*cdf0e10cSrcweir } 756*cdf0e10cSrcweir 757*cdf0e10cSrcweir // String sCommand = sIdentify + " " + sIM_Format + " " + StringHelper.doubleQuoteIfNeed(_sDiffGfx); 758*cdf0e10cSrcweir 759*cdf0e10cSrcweir String[] sCommandArray = 760*cdf0e10cSrcweir { 761*cdf0e10cSrcweir sIdentify, 762*cdf0e10cSrcweir "-format", 763*cdf0e10cSrcweir sIM_Format, 764*cdf0e10cSrcweir _sDiffGfx 765*cdf0e10cSrcweir }; 766*cdf0e10cSrcweir ProcessHandler aHandler = new ProcessHandler(sCommandArray); 767*cdf0e10cSrcweir boolean bBackValue = aHandler.executeSynchronously(); 768*cdf0e10cSrcweir int nExitCode = aHandler.getExitCode(); 769*cdf0e10cSrcweir 770*cdf0e10cSrcweir String sBack = aHandler.getOutputText(); 771*cdf0e10cSrcweir GlobalLogWriter.println("'" + sBack + "'"); 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir // try to interpret the result, which we get as a String 774*cdf0e10cSrcweir try 775*cdf0e10cSrcweir { 776*cdf0e10cSrcweir int nIdx = sBack.indexOf("\n"); 777*cdf0e10cSrcweir if (nIdx > 0) 778*cdf0e10cSrcweir { 779*cdf0e10cSrcweir sBack = sBack.substring(0, nIdx); 780*cdf0e10cSrcweir } 781*cdf0e10cSrcweir 782*cdf0e10cSrcweir nResult = Integer.valueOf(sBack).intValue(); 783*cdf0e10cSrcweir } 784*cdf0e10cSrcweir catch (java.lang.NumberFormatException e) 785*cdf0e10cSrcweir { 786*cdf0e10cSrcweir GlobalLogWriter.println("identify(): Number format exception"); 787*cdf0e10cSrcweir nResult = 0; 788*cdf0e10cSrcweir } 789*cdf0e10cSrcweir return nResult; 790*cdf0e10cSrcweir } 791*cdf0e10cSrcweir // public static void main(String [] _args) 792*cdf0e10cSrcweir // { 793*cdf0e10cSrcweir //// give an index.ini file, ok 794*cdf0e10cSrcweir //// give a directory, where exist jpeg files ok 795*cdf0e10cSrcweir //// inputpath (given file) doesn't exists 796*cdf0e10cSrcweir //// give a jpeg file. 797*cdf0e10cSrcweir // 798*cdf0e10cSrcweir // String args[] = { 799*cdf0e10cSrcweir // "-TimeOut", "3600000", 800*cdf0e10cSrcweir // "-tb", "java_complex", 801*cdf0e10cSrcweir // "-o", "graphical.JPEGComparator", 802*cdf0e10cSrcweir // "-DOC_COMPARATOR_INPUT_PATH", "C:\\CWS\\temp\\output\\index.ini", 803*cdf0e10cSrcweir // "-DOC_COMPARATOR_OUTPUT_PATH", "C:\\CWS\\temp\\output2", 804*cdf0e10cSrcweir //// "-DOC_COMPARATOR_INPUT_PATH", "C:\\CWS\\temp\\output\\GroupReport.odt.pdf_180DPI_0001.jpg", 805*cdf0e10cSrcweir //// "-DOC_COMPARATOR_OUTPUT_PATH", "C:\\CWS\\temp\\output2\\Report1.odt.pdf_180DPI_0001.jpg", 806*cdf0e10cSrcweir // "-DOC_COMPARATOR_HTML_OUTPUT_PREFIX", "http://so-gfxcmp-lin.germany.sun.com/gfxcmp_ui/cw.php?inifile=", 807*cdf0e10cSrcweir //// "-DOC_COMPARATOR_REFERENCE_CREATOR_TYPE", "PDF", /* default: "OOo" */ 808*cdf0e10cSrcweir //// "-DOC_COMPARATOR_REFERENCE_CREATOR_TYPE", "msoffice", /* default: "OOo" */ 809*cdf0e10cSrcweir //// "-OFFICE_VIEWABLE", "false", 810*cdf0e10cSrcweir //// "-AppExecutionCommand", "\"C:/Programme/sun/staroffice 9/program/soffice.exe\" -norestore -nocrashreport -accept=pipe,name=ll93751;urp;", 811*cdf0e10cSrcweir // "-NoOffice" 812*cdf0e10cSrcweir // }; 813*cdf0e10cSrcweir // 814*cdf0e10cSrcweir // org.openoffice.Runner.main(args); 815*cdf0e10cSrcweir // } 816*cdf0e10cSrcweir } 817