2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 import helper
.ProcessHandler
;
24 import convwatch
.PixelCounter
;
25 import convwatch
.StatusHelper
;
26 import helper
.OSHelper
;
27 import helper
.StringHelper
;
28 import java
.util
.ArrayList
;
31 // -----------------------------------------------------------------------------
32 // --------------------------------- PRNCompare ---------------------------------
34 // class DifferenceType
36 // final static int NO_DIFFERENCE = 1;
37 // final static int DIFFERENCE = 2;
39 // public int nValue = NO_DIFFERENCE;
40 // public boolean equals(int _n)
42 // if ( _n == nValue ) return true;
47 // -----------------------------------------------------------------------------
48 public class PRNCompare
50 // OSHelper m_aHelper;
55 // m_aHelper = new OSHelper();
56 fs
= System
.getProperty("file.separator");
59 String
executeSynchronously(String _sCommand
)
61 // System.out.println(_sCommand);
63 ProcessHandler aHandler
= new ProcessHandler(_sCommand
);
64 aHandler
.executeSynchronously();
66 String sText
= aHandler
.getOutputText();
68 GlobalLogWriter
.get().println("Exitcode: " + String
.valueOf(aHandler
.getExitCode()));
73 int getMaxNumOfFileEntry(String _sDirectory
, String _sBasename
)
75 // TODO: check if directory exist should be done earlier
76 File aDirectory
= new File(_sDirectory
);
77 File
[] aDirList
= aDirectory
.listFiles(
80 boolean accept(File filename)
82 if (filename.getName().endsWith("jpg"))
90 for(int n
= 0; n
<aDirList
.length
; n
++)
92 String sDirEntry
= aDirList
[n
].getName();
93 if (sDirEntry
.endsWith(".jpg"))
95 int nNum
= nMaxNumber
;
97 if (sDirEntry
.startsWith(_sBasename
))
99 // System.out.println(sDirEntry);
100 int nJpgIdx
= sDirEntry
.lastIndexOf(".jpg");
101 String sValue
= sDirEntry
.substring(_sBasename
.length(), nJpgIdx
);
105 nValue
= Integer
.valueOf(sValue
).intValue();
107 catch(java
.lang
.NumberFormatException e
)
111 // System.out.println(nValue);
115 if (nNum
> nMaxNumber
)
125 String m_sReferencePath
;
126 String m_sOutputPath
;
128 String m_sReferenceFile
;
129 String m_sPostScriptFile
;
130 // String m_sOldDiff;
132 int m_nResolutionInDPI
= 0;
133 TriState m_tUseBorderMove
;
134 String m_sDocumentType
;
136 public void setInputPath(String _sInputPath
) { m_sInputPath
= _sInputPath
; }
138 public void setReferencePath(String _sReferencePath
) { m_sReferencePath
= _sReferencePath
; }
140 public void setOutputPath(String _sOutPath
) { m_sOutputPath
= _sOutPath
; }
142 public void setDocFile(String _sDocFile
) { m_sDocFile
= _sDocFile
;}
144 public void setReferenceFile(String _sPRNFile
){ m_sReferenceFile
= _sPRNFile
;}
146 public void setPostScriptFile(String _sPSFile
){ m_sPostScriptFile
= _sPSFile
;}
148 public void setBorderMove(TriState _b
) {m_tUseBorderMove
= _b
;}
149 public TriState
getBorderMove() {return m_tUseBorderMove
;}
150 // public void setOldDiffPath(String _sOldDiff)
152 // m_sOldDiff = _sOldDiff;
154 public void setMaxPages(int _n
) {m_nMaxPages
= _n
;}
155 int getMaxPages() {return m_nMaxPages
;}
157 public void setResolutionInDPI(int _n
) {m_nResolutionInDPI
= _n
;}
158 int getResolutionInDPI() {return m_nResolutionInDPI
;}
160 public void setDocumentType(String _sTypeName
)
162 m_sDocumentType
= _sTypeName
;
165 // -----------------------------------------------------------------------------
167 public StatusHelper
[] compare()
169 createJPEGFromPostscript(m_sOutputPath
, m_sReferencePath
, m_sReferenceFile
, getResolutionInDPI());
170 // TODO: Assume, that Postscript is already in the OutputPath, this may change.
171 createJPEGFromPostscript(m_sOutputPath
, m_sOutputPath
, m_sPostScriptFile
, getResolutionInDPI());
172 StatusHelper
[] aList
= createDiffs(m_sOutputPath
,
173 m_sOutputPath
, m_sReferenceFile
,
174 m_sOutputPath
, m_sPostScriptFile
,
175 getMaxPages(), m_tUseBorderMove
);
182 public StatusHelper
[] compare_new()
184 String
[] aRefList
= createJPEGFromPostscript(m_sOutputPath
, m_sReferencePath
, m_sReferenceFile
, getResolutionInDPI());
185 // TODO: Assume, that Postscript is already in the OutputPath, this may change.
186 String
[] aPSList
= createJPEGFromPostscript(m_sOutputPath
, m_sOutputPath
, m_sPostScriptFile
, getResolutionInDPI());
187 StatusHelper
[] aList
= createDiffs(m_sOutputPath
,
190 getMaxPages(), m_tUseBorderMove
);
195 static String
getJPEGName(String _sOutputPath
, String _sBasename
, String _sGS_PageOutput
)
197 String fs
= System
.getProperty("file.separator");
199 String sJPEGName
= _sOutputPath
+ fs
+ _sBasename
+ _sGS_PageOutput
+ ".jpg";
204 * Create via ghostscript (gs) from the reference file for every page a JPEG file
207 * m_sOutputPath, m_sReferenceFile, m_sReferencePath
209 * return exit code from gs command
211 public static String
[] createJPEGFromPostscript(String _sOutputPath
, String _sSourcePath
, String _sSourceFile
, int _nResolutionInDPI
)
213 String sGS_PageOutput
= "%04d";
214 // if ( OSHelper.isWindows() )
216 // sGS_PageOutput = "%%d";
219 FileHelper
.makeDirectories("", _sOutputPath
);
221 // create a jpeg from original prn
222 String fs
= System
.getProperty("file.separator");
224 String sJPGFilename
= getJPEGName(_sOutputPath
, _sSourceFile
, sGS_PageOutput
);
225 String sOriginalFile
= _sSourcePath
+ fs
+ _sSourceFile
;
227 if (OSHelper
.isWindows())
229 sGS
= "gswin32c.exe";
232 String
[] sCommandArray
=
238 "-r" + String
.valueOf(_nResolutionInDPI
),
240 "-sOutputFile=" + sJPGFilename
,
243 // System.out.println("Start Command array");
246 // Runtime.getRuntime().exec(sCommandArray);
247 // } catch (Exception e) {
248 // System.out.println("FAILED");
250 // System.out.println("done");
252 ProcessHandler aHandler
= new ProcessHandler(sCommandArray
);
253 aHandler
.executeSynchronously();
255 // TODO: return a real filename, due to the fact we don't know how much files are created, maybe better to return a list
257 ArrayList
<String
> m_aFileList
= new ArrayList
<String
>();
258 for (int i
=1;i
<9999;i
++)
260 String sNewJPEGFilename
= utils
.replaceAll13(sJPGFilename
, sGS_PageOutput
, StringHelper
.createValueString(i
, 4));
261 if (FileHelper
.exists(sNewJPEGFilename
))
263 m_aFileList
.add(sNewJPEGFilename
); // as long as the files exist, fill the array
267 break; // stop file check
270 String
[] aList
= new String
[m_aFileList
.size()];
271 aList
= m_aFileList
.toArray(aList
);
272 return aList
; // sNewJPEGFilename;
276 * Create Difference Files from the JPEGs
277 * parameter, how much difference files should create
283 public StatusHelper
[] createDiffs(String _sOutputPath
, String _sSourcePath1
, String _sSourceFile1
, String _sSourcePath2
, String _sSourceFile2
, int _nMaxDiffs
, TriState _tUseBorderMove
)
290 String sS1Basename
= FileHelper
.getBasename(_sSourceFile1
);
291 String sS2Basename
= FileHelper
.getBasename(_sSourceFile2
);
293 // count, from which file (jpegs) exist more, take the less one
294 // more are not compareable
295 int nS1_Files
= getMaxNumOfFileEntry(_sSourcePath1
, sS1Basename
);
296 int nS2_Files
= getMaxNumOfFileEntry(_sSourcePath2
, sS2Basename
);
298 // System.out.println("count of s1 files " + String.valueOf(nS1_Files));
299 // System.out.println("count of s2 files " + String.valueOf(nS2_Files));
301 // take the min of both
302 int nMin
= Math
.min(nS1_Files
, nS2_Files
);
303 nMin
= Math
.min(nMin
, _nMaxDiffs
);
305 StatusHelper
[] aList
= new StatusHelper
[nMin
];
307 // TODO: if both document do not have same page count, produce an error
308 // System.out.println("min of both: " + String.valueOf(nMin));
310 int nStatusIndex
= 0;
311 for (int i
=1;i
<=nMin
;i
++)
313 String sOldGfx
= getJPEGName(_sSourcePath1
, sS1Basename
, StringHelper
.createValueString(i
, 4));
314 String sNewGfx
= getJPEGName(_sSourcePath2
, sS2Basename
, StringHelper
.createValueString(i
, 4));
315 String sDiffGfx_
= getJPEGName(_sOutputPath
, sS1Basename
+ ".diff", StringHelper
.createValueString(i
, 4));
318 String sDiffGfx
= compareJPEGs(sOldGfx
, sNewGfx
, sDiffGfx_
);
319 StatusHelper aStatus
= new StatusHelper(sOldGfx
, sNewGfx
, sDiffGfx
);
321 // if (FileHelper.exists(sDiffGfx))
322 if (sDiffGfx
.length() > 0)
324 int nResult
= identify(sDiffGfx
);
327 aStatus
.nDiffStatus
= StatusHelper
.DIFF_NO_DIFFERENCES
;
333 int nPercent
= estimateGfx(sOldGfx
, sNewGfx
, sDiffGfx
);
334 aStatus
.nDiffStatus
= StatusHelper
.DIFF_DIFFERENCES_FOUND
;
335 aStatus
.nPercent
= nPercent
;
337 // GlobalLogWriter.get().println("Hello World: Percent:= " + nPercent);
338 // GlobalLogWriter.get().println("Hello World: TriState:= " + _tUseBorderMove.intValue());
339 // GlobalLogWriter.get().println("Hello World: DocType:= " + m_sDocumentType);
341 // TODO: insert here the new BorderRemover if the percentage value is creater than 75%
343 ((_tUseBorderMove
== TriState
.TRUE
) ||
344 ((_tUseBorderMove
== TriState
.UNSET
) &&
345 m_sDocumentType
.indexOf("MS PowerPoint") > 0)))
347 setBorderMove(TriState
.TRUE
);
349 String sOld_BM_Gfx
= getJPEGName(_sSourcePath1
, sS1Basename
+ ".BM", StringHelper
.createValueString(i
, 4));
350 String sNew_BM_Gfx
= getJPEGName(_sSourcePath2
, sS2Basename
+ ".BM", StringHelper
.createValueString(i
, 4));
351 String sDiff_BM_Gfx_
= getJPEGName(_sOutputPath
, sS1Basename
+ ".diff.BM", StringHelper
.createValueString(i
, 4));
352 aStatus
.setFilesForBorderMove(sOld_BM_Gfx
, sNew_BM_Gfx
, sDiff_BM_Gfx_
);
355 BorderRemover a
= new BorderRemover();
356 a
.createNewImageWithoutBorder(sOldGfx
, sOld_BM_Gfx
);
357 a
.createNewImageWithoutBorder(sNewGfx
, sNew_BM_Gfx
);
359 String sDiff_BM_Gfx
= compareJPEGs( sOld_BM_Gfx
, sNew_BM_Gfx
, sDiff_BM_Gfx_
);
361 // if (FileHelper.exists(sDiff_BM_Gfx))
362 if (sDiff_BM_Gfx
.length() > 0)
364 nResult
= identify(sDiff_BM_Gfx
);
367 aStatus
.nDiffStatus
= StatusHelper
.DIFF_AFTER_MOVE_DONE_NO_PROBLEMS
;
368 aStatus
.nPercent2
= 0;
372 nPercent
= estimateGfx(sOld_BM_Gfx
, sNew_BM_Gfx
, sDiff_BM_Gfx
);
373 aStatus
.nDiffStatus
= StatusHelper
.DIFF_AFTER_MOVE_DONE_DIFFERENCES_FOUND
;
374 aStatus
.nPercent2
= nPercent
;
381 catch(java
.io
.IOException e
)
383 GlobalLogWriter
.get().println("Exception caught. At border remove: " + e
.getMessage());
389 catch (java
.io
.IOException e
)
391 GlobalLogWriter
.get().println(e
.getMessage());
395 // checkDiff(sOldGfx, sNewGfx, sDiffGfx);
396 // if (i >= _nMaxDiffs)
401 aList
[nStatusIndex
++] = aStatus
;
407 public StatusHelper
[] createDiffs(String _sOutputPath
, String
[] _aRefList
, String
[] _aPSList
, int _nMaxDiffs
, TriState _tUseBorderMove
)
414 // count, from which file (jpegs) exist more, take the less one
415 // more are not compareable
417 // take the min of both
418 int nMin
= Math
.min(_aRefList
.length
, _aPSList
.length
);
419 nMin
= Math
.min(nMin
, _nMaxDiffs
);
421 StatusHelper
[] aList
= new StatusHelper
[nMin
];
423 // TODO: if both document do not have same page count, produce an error
424 // System.out.println("min of both: " + String.valueOf(nMin));
426 int nStatusIndex
= 0;
427 for (int i
=1;i
<=nMin
;i
++)
429 String sOldGfx
= _aRefList
[i
];
430 String sNewGfx
= _aPSList
[i
];
431 // String sDiffGfx_ = getJPEGName(_sOutputPath, sS1Basename + ".diff", StringHelper.createValueString(i, 4));
434 String sDiffGfx
= compareJPEGs(sOldGfx
, sNewGfx
);
435 StatusHelper aStatus
= new StatusHelper(sOldGfx
, sNewGfx
, sDiffGfx
);
437 // if (FileHelper.exists(sDiffGfx))
438 if (sDiffGfx
.length() > 0)
440 int nResult
= identify(sDiffGfx
);
443 aStatus
.nDiffStatus
= StatusHelper
.DIFF_NO_DIFFERENCES
;
449 int nPercent
= estimateGfx(sOldGfx
, sNewGfx
, sDiffGfx
);
450 // GlobalLogWriter.get().println("Hello World: Percent:= " + nPercent);
451 // GlobalLogWriter.get().println("Hello World: TriState:= " + _tUseBorderMove.intValue());
452 // GlobalLogWriter.get().println("Hello World: DocType:= " + m_sDocumentType);
454 aStatus
.nDiffStatus
= StatusHelper
.DIFF_DIFFERENCES_FOUND
;
455 aStatus
.nPercent
= nPercent
;
458 ((_tUseBorderMove
== TriState
.TRUE
) ||
459 ((_tUseBorderMove
== TriState
.UNSET
) &&
460 m_sDocumentType
.indexOf("MS PowerPoint") > 0)))
462 _tUseBorderMove
= TriState
.TRUE
;
463 // TODO: problem is here, that we have to create some new names.
465 String sBasename1
= FileHelper
.getBasename(sOldGfx
);
466 String sNameNoSuffix1
= FileHelper
.getNameNoSuffix(sBasename1
);
467 String sBasename2
= FileHelper
.getBasename(sNewGfx
);
468 String sNameNoSuffix2
= FileHelper
.getNameNoSuffix(sBasename2
);
470 String sTmpDir
= util
.utils
.getUsersTempDir();
471 String fs
= System
.getProperty("file.separator");
473 String sOld_BM_Gfx
= sTmpDir
+ fs
+ sNameNoSuffix1
+ "-BM-" + StringHelper
.createValueString(i
, 4) + ".jpg";
474 String sNew_BM_Gfx
= sTmpDir
+ fs
+ sNameNoSuffix2
+ "-BM-" + StringHelper
.createValueString(i
, 4) + ".jpg";
477 BorderRemover a
= new BorderRemover();
478 a
.createNewImageWithoutBorder(sOldGfx
, sOld_BM_Gfx
);
479 a
.createNewImageWithoutBorder(sNewGfx
, sNew_BM_Gfx
);
481 String sDiff_BM_Gfx
= compareJPEGs( sOld_BM_Gfx
, sNew_BM_Gfx
);
483 aStatus
.setFilesForBorderMove(sOld_BM_Gfx
, sNew_BM_Gfx
, sDiff_BM_Gfx
);
485 // if (FileHelper.exists(sDiff_BM_Gfx))
486 if (sDiff_BM_Gfx
.length() > 0)
488 nResult
= identify(sDiff_BM_Gfx
);
491 aStatus
.nDiffStatus
= StatusHelper
.DIFF_AFTER_MOVE_DONE_NO_PROBLEMS
;
492 aStatus
.nPercent2
= 0;
496 nPercent
= estimateGfx(sOld_BM_Gfx
, sNew_BM_Gfx
, sDiff_BM_Gfx
);
497 aStatus
.nDiffStatus
= StatusHelper
.DIFF_AFTER_MOVE_DONE_DIFFERENCES_FOUND
;
498 aStatus
.nPercent2
= nPercent
;
505 catch(java
.io
.IOException e
)
507 GlobalLogWriter
.get().println("Exception caught. At border remove: " + e
.getMessage());
511 catch (java
.io
.IOException e
)
513 GlobalLogWriter
.get().println(e
.getMessage());
517 // checkDiff(sOldGfx, sNewGfx, sDiffGfx);
518 // if (i >= _nMaxDiffs)
523 aList
[nStatusIndex
++] = aStatus
;
528 public static String
compareJPEGs(String _sOldGfx
, String _sNewGfx
)
530 String sBasename1
= FileHelper
.getBasename(_sOldGfx
);
531 String sNameNoSuffix1
= FileHelper
.getNameNoSuffix(sBasename1
);
532 String sBasename2
= FileHelper
.getBasename(_sNewGfx
);
533 String sNameNoSuffix2
= FileHelper
.getNameNoSuffix(sBasename2
);
535 String sTmpDir
= util
.utils
.getUsersTempDir();
536 String fs
= System
.getProperty("file.separator");
538 String sDiffName
= sTmpDir
+ fs
+ sNameNoSuffix1
+ "-" + sNameNoSuffix2
+ "-diff.jpg";
540 return compareJPEGs(_sOldGfx
, _sNewGfx
, sDiffName
);
543 public static String
compareJPEGs(String _sOldGfx
, String _sNewGfx
, String _sDiffGfx
)
545 String sComposite
= "composite";
546 if (OSHelper
.isWindows())
548 sComposite
= "composite.exe";
551 // String sCommand = sComposite + " -compose difference " +
552 // StringHelper.doubleQuoteIfNeed(_sOldGfx) + " " +
553 // StringHelper.doubleQuoteIfNeed(_sNewGfx) + " " +
554 // StringHelper.doubleQuoteIfNeed(_sDiffGfx);
556 String
[] sCommandArray
=
566 ProcessHandler aHandler
= new ProcessHandler(sCommandArray
);
567 aHandler
.executeSynchronously();
569 String sBack
= aHandler
.getOutputText();
570 GlobalLogWriter
.get().println("'" + sBack
+ "'");
572 // return aHandler.getExitCode();
573 if (FileHelper
.exists(_sDiffGfx
))
581 * wrapper for ImageMagick identify,
582 * function checks how many different colors a picture contains.
583 * if it's only one color (nResult==1), like background color, there is no difference.
585 int identify(String _sDiffGfx
)
588 // would like to know what the meaning of %k is for ImageMagick's 'identify'
589 String sIM_Format
= "%k";
590 // if (OSHelper.isWindows())
592 // sIM_Format = "%%k";
595 String sIdentify
= "identify";
596 if (OSHelper
.isWindows())
598 sIdentify
= "identify.exe";
601 // String sCommand = sIdentify + " " + sIM_Format + " " + StringHelper.doubleQuoteIfNeed(_sDiffGfx);
603 String
[] sCommandArray
=
610 ProcessHandler aHandler
= new ProcessHandler(sCommandArray
);
611 aHandler
.executeSynchronously();
612 String sBack
= aHandler
.getOutputText();
613 GlobalLogWriter
.get().println("'" + sBack
+ "'");
615 // try to interpret the result, which we get as a String
618 int nIdx
= sBack
.indexOf("\n");
621 sBack
= sBack
.substring(0, nIdx
);
624 nResult
= Integer
.valueOf(sBack
).intValue();
626 catch(java
.lang
.NumberFormatException e
)
628 GlobalLogWriter
.get().println("Number format exception");
635 * Check 2 different differ files
636 * return 1 if there is no difference between both diff files.
639 // TODO: Maybe a StatusHelper is a better return value
640 public StatusHelper
checkDiffDiff(String _sOutputPath
, String _sSourcePath1
, String _sSourceFile1
, String _sSourcePath2
, String _sSourceFile2
)
642 String sNewGfx
= _sSourcePath1
+ fs
+ _sSourceFile1
;
643 String sOldGfx
= _sSourcePath2
+ fs
+ _sSourceFile2
;
647 sDiffGfx
= getJPEGName(_sOutputPath
, _sSourceFile1
+ ".diff", StringHelper
.createValueString(nNumber
, 4));
649 StatusHelper aCurrentStatus
= new StatusHelper(sOldGfx
, sNewGfx
, sDiffGfx
);
651 // String sComposite = "composite";
652 // if (OSHelper.isWindows())
654 // sComposite = "composite.exe";
657 // String sCommand = sComposite +" -compose difference " +
658 // StringHelper.doubleQuoteIfNeed(sOldGfx) + " " +
659 // StringHelper.doubleQuoteIfNeed(sNewGfx) + " " +
660 // StringHelper.doubleQuoteIfNeed(sDiffGfx);
663 // // System.out.println(sCommand);
664 // // executeSynchronously(sCommand);
665 // ProcessHandler aHandler = new ProcessHandler(sCommand);
666 // boolean bBackValue = aHandler.executeSynchronously();
668 compareJPEGs(sOldGfx
, sNewGfx
, sDiffGfx
);
670 if (FileHelper
.exists(sDiffGfx
))
672 int nResult
= identify(sDiffGfx
);
675 aCurrentStatus
.nDiffStatus
= StatusHelper
.DIFF_NO_DIFFERENCES
;
679 aCurrentStatus
.nDiffStatus
= StatusHelper
.DIFF_DIFFERENCES_FOUND
;
682 aCurrentStatus
.nPercent
= estimateGfx(sOldGfx
, sNewGfx
, sDiffGfx
);
684 catch (java
.io
.IOException e
)
686 GlobalLogWriter
.get().println(e
.getMessage());
687 aCurrentStatus
.nPercent
= -1;
690 // LLA: should diffdiff file delete?
691 // File aFile = new File(sDiffGfx);
696 GlobalLogWriter
.get().println("composite can't create the diffdiff file.");
699 return aCurrentStatus
;
702 // -----------------------------------------------------------------------------
704 * count how much pixel differ and between Old or New and the Difference graphics
706 * First, count the old graphics, then the new graphics due to the fact both should be equal
707 * it should be legal to take result from old or new. We take the graphics with less values.
709 * Second, count the difference graphics, now take the percent algorithm and
710 * build a percent value, which contain the number of different pixels as a percent value
713 * 0% there is no difference
715 * <100% Take a look into the difference graphics, maybe the difference graphics shows
716 * text like outlined or the text is little bit move left, right up or down.
718 * >100% Yes it's possible that there is a difference more then 100%, maybe a font problem
719 * between old and new graphics. The font of the new graphics is little bit bigger,
720 * so the pixel count between old graphics and new graphics is twice the more.
723 public int estimateGfx(String _sOldGfx
, String _sNewGfx
, String _sDiffGfx
)
724 throws java
.io
.IOException
727 int nNotWhiteCount_OldGraphic
= PixelCounter
.countNotWhitePixelsFromImage(_sOldGfx
);
728 int nNotWhiteCount_NewGraphic
= PixelCounter
.countNotWhitePixelsFromImage(_sNewGfx
);
729 int nNotBlackCount_DiffGraphic
= PixelCounter
.countNotBlackPixelsFromImage(_sDiffGfx
);
731 int nMinNotWhiteCount
= Math
.min(nNotWhiteCount_NewGraphic
, nNotWhiteCount_OldGraphic
);
734 if (nMinNotWhiteCount
== 0)
736 nMinNotWhiteCount
= Math
.max(nNotWhiteCount_NewGraphic
, nNotWhiteCount_OldGraphic
);
737 if (nMinNotWhiteCount
== 0)
739 nMinNotWhiteCount
= 1;
743 int nPercent
= Math
.abs(nNotBlackCount_DiffGraphic
* 100 / nMinNotWhiteCount
);
744 GlobalLogWriter
.get().println( "Graphics check, pixel based:" + String
.valueOf(nPercent
) + "% pixel differ ");
751 * Some selftest functionallity
753 // public static void main(String[] args)
755 // System.out.println(FileHelper.getNameNoSuffix("doc.sxw"));
756 // System.out.println(FileHelper.getSuffix("doc.sxw"));
757 // System.out.println(FileHelper.getBasename("doc.sxw"));
758 // System.out.println(FileHelper.getBasename("/tmp/doc.sxw"));
760 // PRNCompare a = new PRNCompare();
761 // a.setInputPath( "/cws/so-cwsserv06/qadev18/SRC680/src.m47/convwatch.keep/input/msoffice/xp/PowerPoint");
762 // a.setReferencePath( "/cws/so-cwsserv06/qadev18/SRC680/src.m47/convwatch.keep/input/msoffice/xp/PowerPoint");
763 // a.setOutputPath( "/tmp/convwatch_java");
764 // a.setDocFile( "1_Gov.ppt");
765 // a.setReferenceFile( "1_Gov.prn" );
766 // a.setPostScriptFile("1_Gov.ps" );
770 // LLA: 20040804 sample how to build jpegs from reference files
771 // a.createJPEGFromPostscript("/tmp/convwatch_java",
772 // "/home/apitest/WorkFromHome/20040804/reference", "worddoc.prn" );
774 // a.createJPEGFromPostscript("/tmp/convwatch_java",
775 // "/home/apitest/WorkFromHome/20040804/reference", "worddoc.ps" );
777 // Status[] aList = a.createDiffs("/tmp/convwatch_java",
778 // "/tmp/convwatch_java", "worddoc.prn",
779 // "/tmp/convwatch_java", "worddoc.ps",
782 // LLA: 20040805 sample how to check 2 gfx files
783 // this function return DifferenceType.NO_DIFFERENCE if the pictures contain no graphically difference
784 // DifferenceType aReturnValue = a.checkDiffDiff("/tmp/convwatch_java",
785 // "/tmp/convwatch_java", "worddoc.prn.diff1.jpg",
786 // "/tmp/convwatch_java/old", "worddoc.prn.diff1.jpg");
787 // if (aReturnValue.equals( DifferenceType.NO_DIFFERENCE ))
789 // System.out.println("There is no difference between both diff files.");
792 // a.setOldDiff( "/olddiffs");