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