merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / runner / convwatch / PRNCompare.java
blob59664ec70e9312dd5ba693d401aabde26fac0929
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PRNCompare.java,v $
10 * $Revision: 1.8.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package convwatch;
34 import helper.ProcessHandler;
35 import java.io.File;
36 import convwatch.PixelCounter;
37 import convwatch.StatusHelper;
38 import helper.OSHelper;
39 import helper.StringHelper;
40 import java.util.ArrayList;
41 import util.utils;
43 // -----------------------------------------------------------------------------
44 // --------------------------------- PRNCompare ---------------------------------
46 // class DifferenceType
47 // {
48 // final static int NO_DIFFERENCE = 1;
49 // final static int DIFFERENCE = 2;
50 //
51 // public int nValue = NO_DIFFERENCE;
52 // public boolean equals(int _n)
53 // {
54 // if ( _n == nValue ) return true;
55 // return false;
56 // }
57 // }
59 // -----------------------------------------------------------------------------
60 public class PRNCompare
62 // OSHelper m_aHelper;
63 String fs;
65 public PRNCompare()
67 // m_aHelper = new OSHelper();
68 fs = System.getProperty("file.separator");
71 String executeSynchronously(String _sCommand)
73 // System.out.println(_sCommand);
75 ProcessHandler aHandler = new ProcessHandler(_sCommand);
76 boolean bBackValue = aHandler.executeSynchronously();
78 String sText = aHandler.getOutputText();
80 GlobalLogWriter.get().println("Exitcode: " + String.valueOf(aHandler.getExitCode()));
81 return sText;
85 int getMaxNumOfFileEntry(String _sDirectory, String _sBasename)
87 // TODO: check if directory exist should be done earlier
88 File aDirectory = new File(_sDirectory);
89 File[] aDirList = aDirectory.listFiles(
91 new FileFilter() {
92 boolean accept(File filename)
94 if (filename.getName().endsWith("jpg"))
95 return true;
96 return false;
98 } */
101 int nMaxNumber = 0;
102 for(int n = 0; n<aDirList.length ; n++)
104 String sDirEntry = aDirList[n].getName();
105 if (sDirEntry.endsWith(".jpg"))
107 int nNum = nMaxNumber;
109 if (sDirEntry.startsWith(_sBasename))
111 // System.out.println(sDirEntry);
112 int nJpgIdx = sDirEntry.lastIndexOf(".jpg");
113 String sValue = sDirEntry.substring(_sBasename.length(), nJpgIdx);
114 int nValue = 0;
117 nValue = Integer.valueOf(sValue).intValue();
119 catch(java.lang.NumberFormatException e)
123 // System.out.println(nValue);
124 nNum = nValue;
127 if (nNum > nMaxNumber)
129 nMaxNumber = nNum;
133 return nMaxNumber;
136 String m_sInputPath;
137 String m_sReferencePath;
138 String m_sOutputPath;
139 String m_sDocFile;
140 String m_sReferenceFile;
141 String m_sPostScriptFile;
142 // String m_sOldDiff;
143 int m_nMaxPages = 0;
144 int m_nResolutionInDPI = 0;
145 TriState m_tUseBorderMove;
146 String m_sDocumentType;
148 public void setInputPath(String _sInputPath) { m_sInputPath = _sInputPath; }
150 public void setReferencePath(String _sReferencePath) { m_sReferencePath = _sReferencePath; }
152 public void setOutputPath(String _sOutPath) { m_sOutputPath = _sOutPath; }
154 public void setDocFile(String _sDocFile) { m_sDocFile = _sDocFile;}
156 public void setReferenceFile(String _sPRNFile){ m_sReferenceFile = _sPRNFile;}
158 public void setPostScriptFile(String _sPSFile){ m_sPostScriptFile = _sPSFile;}
160 public void setBorderMove(TriState _b) {m_tUseBorderMove = _b;}
161 public TriState getBorderMove() {return m_tUseBorderMove;}
162 // public void setOldDiffPath(String _sOldDiff)
163 // {
164 // m_sOldDiff = _sOldDiff;
165 // }
166 public void setMaxPages(int _n) {m_nMaxPages = _n;}
167 int getMaxPages() {return m_nMaxPages;}
169 public void setResolutionInDPI(int _n) {m_nResolutionInDPI = _n;}
170 int getResolutionInDPI() {return m_nResolutionInDPI;}
172 public void setDocumentType(String _sTypeName)
174 m_sDocumentType = _sTypeName;
177 // -----------------------------------------------------------------------------
179 public StatusHelper[] compare()
181 createJPEGFromPostscript(m_sOutputPath, m_sReferencePath, m_sReferenceFile, getResolutionInDPI());
182 // TODO: Assume, that Postscript is already in the OutputPath, this may change.
183 createJPEGFromPostscript(m_sOutputPath, m_sOutputPath, m_sPostScriptFile, getResolutionInDPI());
184 StatusHelper[] aList = createDiffs(m_sOutputPath,
185 m_sOutputPath, m_sReferenceFile,
186 m_sOutputPath, m_sPostScriptFile,
187 getMaxPages(), m_tUseBorderMove);
189 // TODO: Rename?
191 return aList;
194 public StatusHelper[] compare_new()
196 String[] aRefList = createJPEGFromPostscript(m_sOutputPath, m_sReferencePath, m_sReferenceFile, getResolutionInDPI());
197 // TODO: Assume, that Postscript is already in the OutputPath, this may change.
198 String[] aPSList = createJPEGFromPostscript(m_sOutputPath, m_sOutputPath, m_sPostScriptFile, getResolutionInDPI());
199 StatusHelper[] aList = createDiffs(m_sOutputPath,
200 aRefList,
201 aPSList,
202 getMaxPages(), m_tUseBorderMove);
204 return aList;
207 static String getJPEGName(String _sOutputPath, String _sBasename, String _sGS_PageOutput)
209 String fs = System.getProperty("file.separator");
211 String sJPEGName = _sOutputPath + fs + _sBasename + _sGS_PageOutput + ".jpg";
212 return sJPEGName;
216 * Create via ghostscript (gs) from the reference file for every page a JPEG file
218 * MUST set:
219 * m_sOutputPath, m_sReferenceFile, m_sReferencePath
221 * return exit code from gs command
223 public static String[] createJPEGFromPostscript(String _sOutputPath, String _sSourcePath, String _sSourceFile, int _nResolutionInDPI)
225 String sGS_PageOutput = "%04d";
226 // if ( OSHelper.isWindows() )
227 // {
228 // sGS_PageOutput = "%%d";
229 // }
231 FileHelper.makeDirectories("", _sOutputPath);
233 // create a jpeg from original prn
234 String fs = System.getProperty("file.separator");
236 String sJPGFilename = getJPEGName(_sOutputPath, _sSourceFile, sGS_PageOutput);
237 String sOriginalFile = _sSourcePath + fs + _sSourceFile;
238 String sCommand;
239 String sGS = "gs";
240 if (OSHelper.isWindows())
242 sGS = "gswin32c.exe";
245 sCommand = sGS + " -dNOPROMPT -dBATCH -sDEVICE=jpeg -r" + String.valueOf(_nResolutionInDPI) + " -dNOPAUSE -sOutputFile=" + StringHelper.doubleQuoteIfNeed(sJPGFilename) + " " + StringHelper.doubleQuoteIfNeed(sOriginalFile);
246 String[] sCommandArray =
248 sGS,
249 "-dNOPROMPT",
250 "-dBATCH",
251 "-sDEVICE=jpeg",
252 "-r" + String.valueOf(_nResolutionInDPI),
253 "-dNOPAUSE",
254 "-sOutputFile=" + sJPGFilename,
255 sOriginalFile
257 // System.out.println("Start Command array");
258 // try
259 // {
260 // Runtime.getRuntime().exec(sCommandArray);
261 // } catch (Exception e) {
262 // System.out.println("FAILED");
263 // }
264 // System.out.println("done");
266 ProcessHandler aHandler = new ProcessHandler(sCommandArray);
267 boolean bBackValue = aHandler.executeSynchronously();
269 // TODO: return a real filename, due to the fact we don't know how much files are created, maybe better to return a list
271 ArrayList m_aFileList = new ArrayList();
272 for (int i=1;i<9999;i++)
274 String sNewJPEGFilename = utils.replaceAll13(sJPGFilename, sGS_PageOutput, StringHelper.createValueString(i, 4));
275 if (FileHelper.exists(sNewJPEGFilename))
277 m_aFileList.add(sNewJPEGFilename); // as long as the files exist, fill the array
279 else
281 break; // stop file check
284 String[] aList = new String[m_aFileList.size()];
285 aList = (String[])m_aFileList.toArray(aList);
286 return aList; // sNewJPEGFilename;
290 * Create Difference Files from the JPEGs
291 * parameter, how much difference files should create
293 * m_sPostScriptFile
294 * m_sReferenceFile
295 * m_sOutputPath
297 public StatusHelper[] createDiffs(String _sOutputPath, String _sSourcePath1, String _sSourceFile1, String _sSourcePath2, String _sSourceFile2, int _nMaxDiffs, TriState _tUseBorderMove)
299 if (_nMaxDiffs < 1)
301 _nMaxDiffs = 1;
304 String sS1Basename = FileHelper.getBasename(_sSourceFile1);
305 String sS2Basename = FileHelper.getBasename(_sSourceFile2);
307 // count, from which file (jpegs) exist more, take the less one
308 // more are not compareable
309 int nS1_Files = getMaxNumOfFileEntry(_sSourcePath1, sS1Basename);
310 int nS2_Files = getMaxNumOfFileEntry(_sSourcePath2, sS2Basename);
312 // System.out.println("count of s1 files " + String.valueOf(nS1_Files));
313 // System.out.println("count of s2 files " + String.valueOf(nS2_Files));
315 // take the min of both
316 int nMin = Math.min(nS1_Files, nS2_Files);
317 nMin = Math.min(nMin, _nMaxDiffs);
319 StatusHelper[] aList = new StatusHelper[nMin];
321 // TODO: if both document do not have same page count, produce an error
322 // System.out.println("min of both: " + String.valueOf(nMin));
324 int nStatusIndex = 0;
325 for (int i=1;i<=nMin;i++)
327 String sOldGfx = getJPEGName(_sSourcePath1, sS1Basename, StringHelper.createValueString(i, 4));
328 String sNewGfx = getJPEGName(_sSourcePath2, sS2Basename, StringHelper.createValueString(i, 4));
329 String sDiffGfx_ = getJPEGName(_sOutputPath, sS1Basename + ".diff", StringHelper.createValueString(i, 4));
332 String sDiffGfx = compareJPEGs(sOldGfx, sNewGfx, sDiffGfx_);
333 StatusHelper aStatus = new StatusHelper(sOldGfx, sNewGfx, sDiffGfx);
335 // if (FileHelper.exists(sDiffGfx))
336 if (sDiffGfx.length() > 0)
338 int nResult = identify(sDiffGfx);
339 if (nResult == 1)
341 aStatus.nDiffStatus = StatusHelper.DIFF_NO_DIFFERENCES;
343 else
347 int nPercent = estimateGfx(sOldGfx, sNewGfx, sDiffGfx);
348 aStatus.nDiffStatus = StatusHelper.DIFF_DIFFERENCES_FOUND;
349 aStatus.nPercent = nPercent;
351 // GlobalLogWriter.get().println("Hello World: Percent:= " + nPercent);
352 // GlobalLogWriter.get().println("Hello World: TriState:= " + _tUseBorderMove.intValue());
353 // GlobalLogWriter.get().println("Hello World: DocType:= " + m_sDocumentType);
355 // TODO: insert here the new BorderRemover if the percentage value is creater than 75%
356 if (nPercent > 75 &&
357 ((_tUseBorderMove == TriState.TRUE ) ||
358 ((_tUseBorderMove == TriState.UNSET) &&
359 m_sDocumentType.indexOf("MS PowerPoint") > 0)))
361 setBorderMove(TriState.TRUE);
363 String sOld_BM_Gfx = getJPEGName(_sSourcePath1, sS1Basename + ".BM", StringHelper.createValueString(i, 4));
364 String sNew_BM_Gfx = getJPEGName(_sSourcePath2, sS2Basename + ".BM", StringHelper.createValueString(i, 4));
365 String sDiff_BM_Gfx_ = getJPEGName(_sOutputPath, sS1Basename + ".diff.BM", StringHelper.createValueString(i, 4));
366 aStatus.setFilesForBorderMove(sOld_BM_Gfx, sNew_BM_Gfx, sDiff_BM_Gfx_);
369 BorderRemover a = new BorderRemover();
370 a.createNewImageWithoutBorder(sOldGfx, sOld_BM_Gfx);
371 a.createNewImageWithoutBorder(sNewGfx, sNew_BM_Gfx);
373 String sDiff_BM_Gfx = compareJPEGs( sOld_BM_Gfx, sNew_BM_Gfx, sDiff_BM_Gfx_);
375 // if (FileHelper.exists(sDiff_BM_Gfx))
376 if (sDiff_BM_Gfx.length() > 0)
378 nResult = identify(sDiff_BM_Gfx);
379 if (nResult == 1)
381 aStatus.nDiffStatus = StatusHelper.DIFF_AFTER_MOVE_DONE_NO_PROBLEMS;
382 aStatus.nPercent2 = 0;
384 else
386 nPercent = estimateGfx(sOld_BM_Gfx, sNew_BM_Gfx, sDiff_BM_Gfx);
387 aStatus.nDiffStatus = StatusHelper.DIFF_AFTER_MOVE_DONE_DIFFERENCES_FOUND;
388 aStatus.nPercent2 = nPercent;
391 else
395 catch(java.io.IOException e)
397 GlobalLogWriter.get().println("Exception caught. At border remove: " + e.getMessage());
403 catch (java.io.IOException e)
405 GlobalLogWriter.get().println(e.getMessage());
409 // checkDiff(sOldGfx, sNewGfx, sDiffGfx);
410 // if (i >= _nMaxDiffs)
411 // {
412 // break;
413 // }
415 aList[nStatusIndex ++] = aStatus;
417 return aList;
421 public StatusHelper[] createDiffs(String _sOutputPath, String[] _aRefList, String[] _aPSList, int _nMaxDiffs, TriState _tUseBorderMove)
423 if (_nMaxDiffs < 1)
425 _nMaxDiffs = 1;
428 // count, from which file (jpegs) exist more, take the less one
429 // more are not compareable
431 // take the min of both
432 int nMin = Math.min(_aRefList.length, _aPSList.length);
433 nMin = Math.min(nMin, _nMaxDiffs);
435 StatusHelper[] aList = new StatusHelper[nMin];
437 // TODO: if both document do not have same page count, produce an error
438 // System.out.println("min of both: " + String.valueOf(nMin));
440 int nStatusIndex = 0;
441 for (int i=1;i<=nMin;i++)
443 String sOldGfx = _aRefList[i];
444 String sNewGfx = _aPSList[i];
445 // String sDiffGfx_ = getJPEGName(_sOutputPath, sS1Basename + ".diff", StringHelper.createValueString(i, 4));
448 String sDiffGfx = compareJPEGs(sOldGfx, sNewGfx );
449 StatusHelper aStatus = new StatusHelper(sOldGfx, sNewGfx, sDiffGfx);
451 // if (FileHelper.exists(sDiffGfx))
452 if (sDiffGfx.length() > 0)
454 int nResult = identify(sDiffGfx);
455 if (nResult == 1)
457 aStatus.nDiffStatus = StatusHelper.DIFF_NO_DIFFERENCES;
459 else
463 int nPercent = estimateGfx(sOldGfx, sNewGfx, sDiffGfx);
464 // GlobalLogWriter.get().println("Hello World: Percent:= " + nPercent);
465 // GlobalLogWriter.get().println("Hello World: TriState:= " + _tUseBorderMove.intValue());
466 // GlobalLogWriter.get().println("Hello World: DocType:= " + m_sDocumentType);
468 aStatus.nDiffStatus = StatusHelper.DIFF_DIFFERENCES_FOUND;
469 aStatus.nPercent = nPercent;
471 if (nPercent > 75 &&
472 ((_tUseBorderMove == TriState.TRUE ) ||
473 ((_tUseBorderMove == TriState.UNSET) &&
474 m_sDocumentType.indexOf("MS PowerPoint") > 0)))
476 _tUseBorderMove = TriState.TRUE;
477 // TODO: problem is here, that we have to create some new names.
479 String sBasename1 = FileHelper.getBasename(sOldGfx);
480 String sNameNoSuffix1 = FileHelper.getNameNoSuffix(sBasename1);
481 String sBasename2 = FileHelper.getBasename(sNewGfx);
482 String sNameNoSuffix2 = FileHelper.getNameNoSuffix(sBasename2);
484 String sTmpDir = util.utils.getUsersTempDir();
485 String fs = System.getProperty("file.separator");
487 String sOld_BM_Gfx = sTmpDir + fs + sNameNoSuffix1 + "-BM-" + StringHelper.createValueString(i, 4) + ".jpg";
488 String sNew_BM_Gfx = sTmpDir + fs + sNameNoSuffix2 + "-BM-" + StringHelper.createValueString(i, 4) + ".jpg";
491 BorderRemover a = new BorderRemover();
492 a.createNewImageWithoutBorder(sOldGfx, sOld_BM_Gfx);
493 a.createNewImageWithoutBorder(sNewGfx, sNew_BM_Gfx);
495 String sDiff_BM_Gfx = compareJPEGs( sOld_BM_Gfx, sNew_BM_Gfx );
497 aStatus.setFilesForBorderMove(sOld_BM_Gfx, sNew_BM_Gfx, sDiff_BM_Gfx);
499 // if (FileHelper.exists(sDiff_BM_Gfx))
500 if (sDiff_BM_Gfx.length() > 0)
502 nResult = identify(sDiff_BM_Gfx);
503 if (nResult == 1)
505 aStatus.nDiffStatus = StatusHelper.DIFF_AFTER_MOVE_DONE_NO_PROBLEMS;
506 aStatus.nPercent2 = 0;
508 else
510 nPercent = estimateGfx(sOld_BM_Gfx, sNew_BM_Gfx, sDiff_BM_Gfx);
511 aStatus.nDiffStatus = StatusHelper.DIFF_AFTER_MOVE_DONE_DIFFERENCES_FOUND;
512 aStatus.nPercent2 = nPercent;
515 else
519 catch(java.io.IOException e)
521 GlobalLogWriter.get().println("Exception caught. At border remove: " + e.getMessage());
525 catch (java.io.IOException e)
527 GlobalLogWriter.get().println(e.getMessage());
531 // checkDiff(sOldGfx, sNewGfx, sDiffGfx);
532 // if (i >= _nMaxDiffs)
533 // {
534 // break;
535 // }
537 aList[nStatusIndex ++] = aStatus;
539 return aList;
542 public static String compareJPEGs(String _sOldGfx, String _sNewGfx)
544 String sBasename1 = FileHelper.getBasename(_sOldGfx);
545 String sNameNoSuffix1 = FileHelper.getNameNoSuffix(sBasename1);
546 String sBasename2 = FileHelper.getBasename(_sNewGfx);
547 String sNameNoSuffix2 = FileHelper.getNameNoSuffix(sBasename2);
549 String sTmpDir = util.utils.getUsersTempDir();
550 String fs = System.getProperty("file.separator");
552 String sDiffName = sTmpDir + fs + sNameNoSuffix1 + "-" + sNameNoSuffix2 + "-diff.jpg";
554 return compareJPEGs(_sOldGfx, _sNewGfx, sDiffName);
557 public static String compareJPEGs(String _sOldGfx, String _sNewGfx, String _sDiffGfx)
559 String sComposite = "composite";
560 if (OSHelper.isWindows())
562 sComposite = "composite.exe";
565 // String sCommand = sComposite + " -compose difference " +
566 // StringHelper.doubleQuoteIfNeed(_sOldGfx) + " " +
567 // StringHelper.doubleQuoteIfNeed(_sNewGfx) + " " +
568 // StringHelper.doubleQuoteIfNeed(_sDiffGfx);
570 String[] sCommandArray =
572 sComposite,
573 "-compose",
574 "difference",
575 _sOldGfx,
576 _sNewGfx,
577 _sDiffGfx
580 ProcessHandler aHandler = new ProcessHandler(sCommandArray);
581 boolean bBackValue = aHandler.executeSynchronously();
583 String sBack = aHandler.getOutputText();
584 GlobalLogWriter.get().println("'" + sBack + "'");
586 // return aHandler.getExitCode();
587 if (FileHelper.exists(_sDiffGfx))
589 return _sDiffGfx;
591 return "";
595 * wrapper for ImageMagick identify,
596 * function checks how many different colors a picture contains.
597 * if it's only one color (nResult==1), like background color, there is no difference.
599 int identify(String _sDiffGfx)
601 int nResult = 0;
602 // would like to know what the meaning of %k is for ImageMagick's 'identify'
603 String sIM_Format = "%k";
604 // if (OSHelper.isWindows())
605 // {
606 // sIM_Format = "%%k";
607 // }
609 String sIdentify = "identify";
610 if (OSHelper.isWindows())
612 sIdentify = "identify.exe";
615 // String sCommand = sIdentify + " " + sIM_Format + " " + StringHelper.doubleQuoteIfNeed(_sDiffGfx);
617 String[] sCommandArray =
619 sIdentify,
620 "-format",
621 sIM_Format,
622 _sDiffGfx
624 ProcessHandler aHandler = new ProcessHandler(sCommandArray);
625 boolean bBackValue = aHandler.executeSynchronously();
626 String sBack = aHandler.getOutputText();
627 GlobalLogWriter.get().println("'" + sBack + "'");
629 // try to interpret the result, which we get as a String
632 int nIdx = sBack.indexOf("\n");
633 if (nIdx > 0)
635 sBack = sBack.substring(0, nIdx);
638 nResult = Integer.valueOf(sBack).intValue();
640 catch(java.lang.NumberFormatException e)
642 GlobalLogWriter.get().println("Number format exception");
643 nResult = 0;
645 return nResult;
649 * Check 2 different differ files
650 * return 1 if there is no difference between both diff files.
653 // TODO: Maybe a StatusHelper is a better return value
654 public StatusHelper checkDiffDiff(String _sOutputPath, String _sSourcePath1, String _sSourceFile1, String _sSourcePath2, String _sSourceFile2)
656 String sNewGfx = _sSourcePath1 + fs + _sSourceFile1;
657 String sOldGfx = _sSourcePath2 + fs + _sSourceFile2;
659 int nNumber = 1;
660 String sDiffGfx;
661 sDiffGfx = getJPEGName(_sOutputPath, _sSourceFile1 + ".diff", StringHelper.createValueString(nNumber, 4));
663 StatusHelper aCurrentStatus = new StatusHelper(sOldGfx, sNewGfx, sDiffGfx);
665 // String sComposite = "composite";
666 // if (OSHelper.isWindows())
667 // {
668 // sComposite = "composite.exe";
669 // }
671 // String sCommand = sComposite +" -compose difference " +
672 // StringHelper.doubleQuoteIfNeed(sOldGfx) + " " +
673 // StringHelper.doubleQuoteIfNeed(sNewGfx) + " " +
674 // StringHelper.doubleQuoteIfNeed(sDiffGfx);
677 // // System.out.println(sCommand);
678 // // executeSynchronously(sCommand);
679 // ProcessHandler aHandler = new ProcessHandler(sCommand);
680 // boolean bBackValue = aHandler.executeSynchronously();
682 compareJPEGs(sOldGfx, sNewGfx, sDiffGfx);
684 if (FileHelper.exists(sDiffGfx))
686 int nResult = identify(sDiffGfx);
687 if (nResult == 1)
689 aCurrentStatus.nDiffStatus = StatusHelper.DIFF_NO_DIFFERENCES;
691 else
693 aCurrentStatus.nDiffStatus = StatusHelper.DIFF_DIFFERENCES_FOUND;
696 aCurrentStatus.nPercent = estimateGfx(sOldGfx, sNewGfx, sDiffGfx);
698 catch (java.io.IOException e)
700 GlobalLogWriter.get().println(e.getMessage());
701 aCurrentStatus.nPercent = -1;
704 // LLA: should diffdiff file delete?
705 // File aFile = new File(sDiffGfx);
706 // aFile.delete();
708 else
710 GlobalLogWriter.get().println("composite can't create the diffdiff file.");
713 return aCurrentStatus;
716 // -----------------------------------------------------------------------------
718 * count how much pixel differ and between Old or New and the Difference graphics
720 * First, count the old graphics, then the new graphics due to the fact both should be equal
721 * it should be legal to take result from old or new. We take the graphics with less values.
723 * Second, count the difference graphics, now take the percent algorithm and
724 * build a percent value, which contain the number of different pixels as a percent value
726 * Interpretation:
727 * 0% there is no difference
729 * <100% Take a look into the difference graphics, maybe the difference graphics shows
730 * text like outlined or the text is little bit move left, right up or down.
732 * >100% Yes it's possible that there is a difference more then 100%, maybe a font problem
733 * between old and new graphics. The font of the new graphics is little bit bigger,
734 * so the pixel count between old graphics and new graphics is twice the more.
737 public int estimateGfx(String _sOldGfx, String _sNewGfx, String _sDiffGfx)
738 throws java.io.IOException
740 // new count pixels
741 int nNotWhiteCount_OldGraphic = PixelCounter.countNotWhitePixelsFromImage(_sOldGfx);
742 int nNotWhiteCount_NewGraphic = PixelCounter.countNotWhitePixelsFromImage(_sNewGfx);
743 int nNotBlackCount_DiffGraphic = PixelCounter.countNotBlackPixelsFromImage(_sDiffGfx);
745 int nMinNotWhiteCount = Math.min(nNotWhiteCount_NewGraphic, nNotWhiteCount_OldGraphic);
747 // check if not zero
748 if (nMinNotWhiteCount == 0)
750 nMinNotWhiteCount = Math.max(nNotWhiteCount_NewGraphic, nNotWhiteCount_OldGraphic);
751 if (nMinNotWhiteCount == 0)
753 nMinNotWhiteCount = 1;
757 int nPercent = Math.abs(nNotBlackCount_DiffGraphic * 100 / nMinNotWhiteCount);
758 GlobalLogWriter.get().println( "Graphics check, pixel based:" + String.valueOf(nPercent) + "% pixel differ ");
759 return nPercent;
765 * Some selftest functionallity
767 // public static void main(String[] args)
768 // {
769 // System.out.println(FileHelper.getNameNoSuffix("doc.sxw"));
770 // System.out.println(FileHelper.getSuffix("doc.sxw"));
771 // System.out.println(FileHelper.getBasename("doc.sxw"));
772 // System.out.println(FileHelper.getBasename("/tmp/doc.sxw"));
774 // PRNCompare a = new PRNCompare();
775 // a.setInputPath( "/cws/so-cwsserv06/qadev18/SRC680/src.m47/convwatch.keep/input/msoffice/xp/PowerPoint");
776 // a.setReferencePath( "/cws/so-cwsserv06/qadev18/SRC680/src.m47/convwatch.keep/input/msoffice/xp/PowerPoint");
777 // a.setOutputPath( "/tmp/convwatch_java");
778 // a.setDocFile( "1_Gov.ppt");
779 // a.setReferenceFile( "1_Gov.prn" );
780 // a.setPostScriptFile("1_Gov.ps" );
781 // a.compare();
784 // LLA: 20040804 sample how to build jpegs from reference files
785 // a.createJPEGFromPostscript("/tmp/convwatch_java",
786 // "/home/apitest/WorkFromHome/20040804/reference", "worddoc.prn" );
788 // a.createJPEGFromPostscript("/tmp/convwatch_java",
789 // "/home/apitest/WorkFromHome/20040804/reference", "worddoc.ps" );
791 // Status[] aList = a.createDiffs("/tmp/convwatch_java",
792 // "/tmp/convwatch_java", "worddoc.prn",
793 // "/tmp/convwatch_java", "worddoc.ps",
794 // 2);
796 // LLA: 20040805 sample how to check 2 gfx files
797 // this function return DifferenceType.NO_DIFFERENCE if the pictures contain no graphically difference
798 // DifferenceType aReturnValue = a.checkDiffDiff("/tmp/convwatch_java",
799 // "/tmp/convwatch_java", "worddoc.prn.diff1.jpg",
800 // "/tmp/convwatch_java/old", "worddoc.prn.diff1.jpg");
801 // if (aReturnValue.equals( DifferenceType.NO_DIFFERENCE ))
802 // {
803 // System.out.println("There is no difference between both diff files.");
804 // }
806 // a.setOldDiff( "/olddiffs");
807 // }