1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
31 import helper
.ProcessHandler
;
33 import convwatch
.PixelCounter
;
34 import convwatch
.StatusHelper
;
35 import helper
.OSHelper
;
36 import helper
.StringHelper
;
37 import java
.util
.ArrayList
;
40 // -----------------------------------------------------------------------------
41 // --------------------------------- PRNCompare ---------------------------------
43 // class DifferenceType
45 // final static int NO_DIFFERENCE = 1;
46 // final static int DIFFERENCE = 2;
48 // public int nValue = NO_DIFFERENCE;
49 // public boolean equals(int _n)
51 // if ( _n == nValue ) return true;
56 // -----------------------------------------------------------------------------
57 public class PRNCompare
59 // OSHelper m_aHelper;
64 // m_aHelper = new OSHelper();
65 fs
= System
.getProperty("file.separator");
68 String
executeSynchronously(String _sCommand
)
70 // System.out.println(_sCommand);
72 ProcessHandler aHandler
= new ProcessHandler(_sCommand
);
73 boolean bBackValue
= aHandler
.executeSynchronously();
75 String sText
= aHandler
.getOutputText();
77 GlobalLogWriter
.get().println("Exitcode: " + String
.valueOf(aHandler
.getExitCode()));
82 int getMaxNumOfFileEntry(String _sDirectory
, String _sBasename
)
84 // TODO: check if directory exist should be done earlier
85 File aDirectory
= new File(_sDirectory
);
86 File
[] aDirList
= aDirectory
.listFiles(
89 boolean accept(File filename)
91 if (filename.getName().endsWith("jpg"))
99 for(int n
= 0; n
<aDirList
.length
; n
++)
101 String sDirEntry
= aDirList
[n
].getName();
102 if (sDirEntry
.endsWith(".jpg"))
104 int nNum
= nMaxNumber
;
106 if (sDirEntry
.startsWith(_sBasename
))
108 // System.out.println(sDirEntry);
109 int nJpgIdx
= sDirEntry
.lastIndexOf(".jpg");
110 String sValue
= sDirEntry
.substring(_sBasename
.length(), nJpgIdx
);
114 nValue
= Integer
.valueOf(sValue
).intValue();
116 catch(java
.lang
.NumberFormatException e
)
120 // System.out.println(nValue);
124 if (nNum
> nMaxNumber
)
134 String m_sReferencePath
;
135 String m_sOutputPath
;
137 String m_sReferenceFile
;
138 String m_sPostScriptFile
;
139 // String m_sOldDiff;
141 int m_nResolutionInDPI
= 0;
142 TriState m_tUseBorderMove
;
143 String m_sDocumentType
;
145 public void setInputPath(String _sInputPath
) { m_sInputPath
= _sInputPath
; }
147 public void setReferencePath(String _sReferencePath
) { m_sReferencePath
= _sReferencePath
; }
149 public void setOutputPath(String _sOutPath
) { m_sOutputPath
= _sOutPath
; }
151 public void setDocFile(String _sDocFile
) { m_sDocFile
= _sDocFile
;}
153 public void setReferenceFile(String _sPRNFile
){ m_sReferenceFile
= _sPRNFile
;}
155 public void setPostScriptFile(String _sPSFile
){ m_sPostScriptFile
= _sPSFile
;}
157 public void setBorderMove(TriState _b
) {m_tUseBorderMove
= _b
;}
158 public TriState
getBorderMove() {return m_tUseBorderMove
;}
159 // public void setOldDiffPath(String _sOldDiff)
161 // m_sOldDiff = _sOldDiff;
163 public void setMaxPages(int _n
) {m_nMaxPages
= _n
;}
164 int getMaxPages() {return m_nMaxPages
;}
166 public void setResolutionInDPI(int _n
) {m_nResolutionInDPI
= _n
;}
167 int getResolutionInDPI() {return m_nResolutionInDPI
;}
169 public void setDocumentType(String _sTypeName
)
171 m_sDocumentType
= _sTypeName
;
174 // -----------------------------------------------------------------------------
176 public StatusHelper
[] compare()
178 createJPEGFromPostscript(m_sOutputPath
, m_sReferencePath
, m_sReferenceFile
, getResolutionInDPI());
179 // TODO: Assume, that Postscript is already in the OutputPath, this may change.
180 createJPEGFromPostscript(m_sOutputPath
, m_sOutputPath
, m_sPostScriptFile
, getResolutionInDPI());
181 StatusHelper
[] aList
= createDiffs(m_sOutputPath
,
182 m_sOutputPath
, m_sReferenceFile
,
183 m_sOutputPath
, m_sPostScriptFile
,
184 getMaxPages(), m_tUseBorderMove
);
191 public StatusHelper
[] compare_new()
193 String
[] aRefList
= createJPEGFromPostscript(m_sOutputPath
, m_sReferencePath
, m_sReferenceFile
, getResolutionInDPI());
194 // TODO: Assume, that Postscript is already in the OutputPath, this may change.
195 String
[] aPSList
= createJPEGFromPostscript(m_sOutputPath
, m_sOutputPath
, m_sPostScriptFile
, getResolutionInDPI());
196 StatusHelper
[] aList
= createDiffs(m_sOutputPath
,
199 getMaxPages(), m_tUseBorderMove
);
204 static String
getJPEGName(String _sOutputPath
, String _sBasename
, String _sGS_PageOutput
)
206 String fs
= System
.getProperty("file.separator");
208 String sJPEGName
= _sOutputPath
+ fs
+ _sBasename
+ _sGS_PageOutput
+ ".jpg";
213 * Create via ghostscript (gs) from the reference file for every page a JPEG file
216 * m_sOutputPath, m_sReferenceFile, m_sReferencePath
218 * return exit code from gs command
220 public static String
[] createJPEGFromPostscript(String _sOutputPath
, String _sSourcePath
, String _sSourceFile
, int _nResolutionInDPI
)
222 String sGS_PageOutput
= "%04d";
223 // if ( OSHelper.isWindows() )
225 // sGS_PageOutput = "%%d";
228 FileHelper
.makeDirectories("", _sOutputPath
);
230 // create a jpeg from original prn
231 String fs
= System
.getProperty("file.separator");
233 String sJPGFilename
= getJPEGName(_sOutputPath
, _sSourceFile
, sGS_PageOutput
);
234 String sOriginalFile
= _sSourcePath
+ fs
+ _sSourceFile
;
237 if (OSHelper
.isWindows())
239 sGS
= "gswin32c.exe";
242 sCommand
= sGS
+ " -dNOPROMPT -dBATCH -sDEVICE=jpeg -r" + String
.valueOf(_nResolutionInDPI
) + " -dNOPAUSE -sOutputFile=" + StringHelper
.doubleQuoteIfNeed(sJPGFilename
) + " " + StringHelper
.doubleQuoteIfNeed(sOriginalFile
);
243 String
[] sCommandArray
=
249 "-r" + String
.valueOf(_nResolutionInDPI
),
251 "-sOutputFile=" + sJPGFilename
,
254 // System.out.println("Start Command array");
257 // Runtime.getRuntime().exec(sCommandArray);
258 // } catch (Exception e) {
259 // System.out.println("FAILED");
261 // System.out.println("done");
263 ProcessHandler aHandler
= new ProcessHandler(sCommandArray
);
264 boolean bBackValue
= aHandler
.executeSynchronously();
266 // TODO: return a real filename, due to the fact we don't know how much files are created, maybe better to return a list
268 ArrayList m_aFileList
= new ArrayList();
269 for (int i
=1;i
<9999;i
++)
271 String sNewJPEGFilename
= utils
.replaceAll13(sJPGFilename
, sGS_PageOutput
, StringHelper
.createValueString(i
, 4));
272 if (FileHelper
.exists(sNewJPEGFilename
))
274 m_aFileList
.add(sNewJPEGFilename
); // as long as the files exist, fill the array
278 break; // stop file check
281 String
[] aList
= new String
[m_aFileList
.size()];
282 aList
= (String
[])m_aFileList
.toArray(aList
);
283 return aList
; // sNewJPEGFilename;
287 * Create Difference Files from the JPEGs
288 * parameter, how much difference files should create
294 public StatusHelper
[] createDiffs(String _sOutputPath
, String _sSourcePath1
, String _sSourceFile1
, String _sSourcePath2
, String _sSourceFile2
, int _nMaxDiffs
, TriState _tUseBorderMove
)
301 String sS1Basename
= FileHelper
.getBasename(_sSourceFile1
);
302 String sS2Basename
= FileHelper
.getBasename(_sSourceFile2
);
304 // count, from which file (jpegs) exist more, take the less one
305 // more are not compareable
306 int nS1_Files
= getMaxNumOfFileEntry(_sSourcePath1
, sS1Basename
);
307 int nS2_Files
= getMaxNumOfFileEntry(_sSourcePath2
, sS2Basename
);
309 // System.out.println("count of s1 files " + String.valueOf(nS1_Files));
310 // System.out.println("count of s2 files " + String.valueOf(nS2_Files));
312 // take the min of both
313 int nMin
= Math
.min(nS1_Files
, nS2_Files
);
314 nMin
= Math
.min(nMin
, _nMaxDiffs
);
316 StatusHelper
[] aList
= new StatusHelper
[nMin
];
318 // TODO: if both document do not have same page count, produce an error
319 // System.out.println("min of both: " + String.valueOf(nMin));
321 int nStatusIndex
= 0;
322 for (int i
=1;i
<=nMin
;i
++)
324 String sOldGfx
= getJPEGName(_sSourcePath1
, sS1Basename
, StringHelper
.createValueString(i
, 4));
325 String sNewGfx
= getJPEGName(_sSourcePath2
, sS2Basename
, StringHelper
.createValueString(i
, 4));
326 String sDiffGfx_
= getJPEGName(_sOutputPath
, sS1Basename
+ ".diff", StringHelper
.createValueString(i
, 4));
329 String sDiffGfx
= compareJPEGs(sOldGfx
, sNewGfx
, sDiffGfx_
);
330 StatusHelper aStatus
= new StatusHelper(sOldGfx
, sNewGfx
, sDiffGfx
);
332 // if (FileHelper.exists(sDiffGfx))
333 if (sDiffGfx
.length() > 0)
335 int nResult
= identify(sDiffGfx
);
338 aStatus
.nDiffStatus
= StatusHelper
.DIFF_NO_DIFFERENCES
;
344 int nPercent
= estimateGfx(sOldGfx
, sNewGfx
, sDiffGfx
);
345 aStatus
.nDiffStatus
= StatusHelper
.DIFF_DIFFERENCES_FOUND
;
346 aStatus
.nPercent
= nPercent
;
348 // GlobalLogWriter.get().println("Hello World: Percent:= " + nPercent);
349 // GlobalLogWriter.get().println("Hello World: TriState:= " + _tUseBorderMove.intValue());
350 // GlobalLogWriter.get().println("Hello World: DocType:= " + m_sDocumentType);
352 // TODO: insert here the new BorderRemover if the percentage value is creater than 75%
354 ((_tUseBorderMove
== TriState
.TRUE
) ||
355 ((_tUseBorderMove
== TriState
.UNSET
) &&
356 m_sDocumentType
.indexOf("MS PowerPoint") > 0)))
358 setBorderMove(TriState
.TRUE
);
360 String sOld_BM_Gfx
= getJPEGName(_sSourcePath1
, sS1Basename
+ ".BM", StringHelper
.createValueString(i
, 4));
361 String sNew_BM_Gfx
= getJPEGName(_sSourcePath2
, sS2Basename
+ ".BM", StringHelper
.createValueString(i
, 4));
362 String sDiff_BM_Gfx_
= getJPEGName(_sOutputPath
, sS1Basename
+ ".diff.BM", StringHelper
.createValueString(i
, 4));
363 aStatus
.setFilesForBorderMove(sOld_BM_Gfx
, sNew_BM_Gfx
, sDiff_BM_Gfx_
);
366 BorderRemover a
= new BorderRemover();
367 a
.createNewImageWithoutBorder(sOldGfx
, sOld_BM_Gfx
);
368 a
.createNewImageWithoutBorder(sNewGfx
, sNew_BM_Gfx
);
370 String sDiff_BM_Gfx
= compareJPEGs( sOld_BM_Gfx
, sNew_BM_Gfx
, sDiff_BM_Gfx_
);
372 // if (FileHelper.exists(sDiff_BM_Gfx))
373 if (sDiff_BM_Gfx
.length() > 0)
375 nResult
= identify(sDiff_BM_Gfx
);
378 aStatus
.nDiffStatus
= StatusHelper
.DIFF_AFTER_MOVE_DONE_NO_PROBLEMS
;
379 aStatus
.nPercent2
= 0;
383 nPercent
= estimateGfx(sOld_BM_Gfx
, sNew_BM_Gfx
, sDiff_BM_Gfx
);
384 aStatus
.nDiffStatus
= StatusHelper
.DIFF_AFTER_MOVE_DONE_DIFFERENCES_FOUND
;
385 aStatus
.nPercent2
= nPercent
;
392 catch(java
.io
.IOException e
)
394 GlobalLogWriter
.get().println("Exception caught. At border remove: " + e
.getMessage());
400 catch (java
.io
.IOException e
)
402 GlobalLogWriter
.get().println(e
.getMessage());
406 // checkDiff(sOldGfx, sNewGfx, sDiffGfx);
407 // if (i >= _nMaxDiffs)
412 aList
[nStatusIndex
++] = aStatus
;
418 public StatusHelper
[] createDiffs(String _sOutputPath
, String
[] _aRefList
, String
[] _aPSList
, int _nMaxDiffs
, TriState _tUseBorderMove
)
425 // count, from which file (jpegs) exist more, take the less one
426 // more are not compareable
428 // take the min of both
429 int nMin
= Math
.min(_aRefList
.length
, _aPSList
.length
);
430 nMin
= Math
.min(nMin
, _nMaxDiffs
);
432 StatusHelper
[] aList
= new StatusHelper
[nMin
];
434 // TODO: if both document do not have same page count, produce an error
435 // System.out.println("min of both: " + String.valueOf(nMin));
437 int nStatusIndex
= 0;
438 for (int i
=1;i
<=nMin
;i
++)
440 String sOldGfx
= _aRefList
[i
];
441 String sNewGfx
= _aPSList
[i
];
442 // String sDiffGfx_ = getJPEGName(_sOutputPath, sS1Basename + ".diff", StringHelper.createValueString(i, 4));
445 String sDiffGfx
= compareJPEGs(sOldGfx
, sNewGfx
);
446 StatusHelper aStatus
= new StatusHelper(sOldGfx
, sNewGfx
, sDiffGfx
);
448 // if (FileHelper.exists(sDiffGfx))
449 if (sDiffGfx
.length() > 0)
451 int nResult
= identify(sDiffGfx
);
454 aStatus
.nDiffStatus
= StatusHelper
.DIFF_NO_DIFFERENCES
;
460 int nPercent
= estimateGfx(sOldGfx
, sNewGfx
, sDiffGfx
);
461 // GlobalLogWriter.get().println("Hello World: Percent:= " + nPercent);
462 // GlobalLogWriter.get().println("Hello World: TriState:= " + _tUseBorderMove.intValue());
463 // GlobalLogWriter.get().println("Hello World: DocType:= " + m_sDocumentType);
465 aStatus
.nDiffStatus
= StatusHelper
.DIFF_DIFFERENCES_FOUND
;
466 aStatus
.nPercent
= nPercent
;
469 ((_tUseBorderMove
== TriState
.TRUE
) ||
470 ((_tUseBorderMove
== TriState
.UNSET
) &&
471 m_sDocumentType
.indexOf("MS PowerPoint") > 0)))
473 _tUseBorderMove
= TriState
.TRUE
;
474 // TODO: problem is here, that we have to create some new names.
476 String sBasename1
= FileHelper
.getBasename(sOldGfx
);
477 String sNameNoSuffix1
= FileHelper
.getNameNoSuffix(sBasename1
);
478 String sBasename2
= FileHelper
.getBasename(sNewGfx
);
479 String sNameNoSuffix2
= FileHelper
.getNameNoSuffix(sBasename2
);
481 String sTmpDir
= util
.utils
.getUsersTempDir();
482 String fs
= System
.getProperty("file.separator");
484 String sOld_BM_Gfx
= sTmpDir
+ fs
+ sNameNoSuffix1
+ "-BM-" + StringHelper
.createValueString(i
, 4) + ".jpg";
485 String sNew_BM_Gfx
= sTmpDir
+ fs
+ sNameNoSuffix2
+ "-BM-" + StringHelper
.createValueString(i
, 4) + ".jpg";
488 BorderRemover a
= new BorderRemover();
489 a
.createNewImageWithoutBorder(sOldGfx
, sOld_BM_Gfx
);
490 a
.createNewImageWithoutBorder(sNewGfx
, sNew_BM_Gfx
);
492 String sDiff_BM_Gfx
= compareJPEGs( sOld_BM_Gfx
, sNew_BM_Gfx
);
494 aStatus
.setFilesForBorderMove(sOld_BM_Gfx
, sNew_BM_Gfx
, sDiff_BM_Gfx
);
496 // if (FileHelper.exists(sDiff_BM_Gfx))
497 if (sDiff_BM_Gfx
.length() > 0)
499 nResult
= identify(sDiff_BM_Gfx
);
502 aStatus
.nDiffStatus
= StatusHelper
.DIFF_AFTER_MOVE_DONE_NO_PROBLEMS
;
503 aStatus
.nPercent2
= 0;
507 nPercent
= estimateGfx(sOld_BM_Gfx
, sNew_BM_Gfx
, sDiff_BM_Gfx
);
508 aStatus
.nDiffStatus
= StatusHelper
.DIFF_AFTER_MOVE_DONE_DIFFERENCES_FOUND
;
509 aStatus
.nPercent2
= nPercent
;
516 catch(java
.io
.IOException e
)
518 GlobalLogWriter
.get().println("Exception caught. At border remove: " + e
.getMessage());
522 catch (java
.io
.IOException e
)
524 GlobalLogWriter
.get().println(e
.getMessage());
528 // checkDiff(sOldGfx, sNewGfx, sDiffGfx);
529 // if (i >= _nMaxDiffs)
534 aList
[nStatusIndex
++] = aStatus
;
539 public static String
compareJPEGs(String _sOldGfx
, String _sNewGfx
)
541 String sBasename1
= FileHelper
.getBasename(_sOldGfx
);
542 String sNameNoSuffix1
= FileHelper
.getNameNoSuffix(sBasename1
);
543 String sBasename2
= FileHelper
.getBasename(_sNewGfx
);
544 String sNameNoSuffix2
= FileHelper
.getNameNoSuffix(sBasename2
);
546 String sTmpDir
= util
.utils
.getUsersTempDir();
547 String fs
= System
.getProperty("file.separator");
549 String sDiffName
= sTmpDir
+ fs
+ sNameNoSuffix1
+ "-" + sNameNoSuffix2
+ "-diff.jpg";
551 return compareJPEGs(_sOldGfx
, _sNewGfx
, sDiffName
);
554 public static String
compareJPEGs(String _sOldGfx
, String _sNewGfx
, String _sDiffGfx
)
556 String sComposite
= "composite";
557 if (OSHelper
.isWindows())
559 sComposite
= "composite.exe";
562 // String sCommand = sComposite + " -compose difference " +
563 // StringHelper.doubleQuoteIfNeed(_sOldGfx) + " " +
564 // StringHelper.doubleQuoteIfNeed(_sNewGfx) + " " +
565 // StringHelper.doubleQuoteIfNeed(_sDiffGfx);
567 String
[] sCommandArray
=
577 ProcessHandler aHandler
= new ProcessHandler(sCommandArray
);
578 boolean bBackValue
= aHandler
.executeSynchronously();
580 String sBack
= aHandler
.getOutputText();
581 GlobalLogWriter
.get().println("'" + sBack
+ "'");
583 // return aHandler.getExitCode();
584 if (FileHelper
.exists(_sDiffGfx
))
592 * wrapper for ImageMagick identify,
593 * function checks how many different colors a picture contains.
594 * if it's only one color (nResult==1), like background color, there is no difference.
596 int identify(String _sDiffGfx
)
599 // would like to know what the meaning of %k is for ImageMagick's 'identify'
600 String sIM_Format
= "%k";
601 // if (OSHelper.isWindows())
603 // sIM_Format = "%%k";
606 String sIdentify
= "identify";
607 if (OSHelper
.isWindows())
609 sIdentify
= "identify.exe";
612 // String sCommand = sIdentify + " " + sIM_Format + " " + StringHelper.doubleQuoteIfNeed(_sDiffGfx);
614 String
[] sCommandArray
=
621 ProcessHandler aHandler
= new ProcessHandler(sCommandArray
);
622 boolean bBackValue
= aHandler
.executeSynchronously();
623 String sBack
= aHandler
.getOutputText();
624 GlobalLogWriter
.get().println("'" + sBack
+ "'");
626 // try to interpret the result, which we get as a String
629 int nIdx
= sBack
.indexOf("\n");
632 sBack
= sBack
.substring(0, nIdx
);
635 nResult
= Integer
.valueOf(sBack
).intValue();
637 catch(java
.lang
.NumberFormatException e
)
639 GlobalLogWriter
.get().println("Number format exception");
646 * Check 2 different differ files
647 * return 1 if there is no difference between both diff files.
650 // TODO: Maybe a StatusHelper is a better return value
651 public StatusHelper
checkDiffDiff(String _sOutputPath
, String _sSourcePath1
, String _sSourceFile1
, String _sSourcePath2
, String _sSourceFile2
)
653 String sNewGfx
= _sSourcePath1
+ fs
+ _sSourceFile1
;
654 String sOldGfx
= _sSourcePath2
+ fs
+ _sSourceFile2
;
658 sDiffGfx
= getJPEGName(_sOutputPath
, _sSourceFile1
+ ".diff", StringHelper
.createValueString(nNumber
, 4));
660 StatusHelper aCurrentStatus
= new StatusHelper(sOldGfx
, sNewGfx
, sDiffGfx
);
662 // String sComposite = "composite";
663 // if (OSHelper.isWindows())
665 // sComposite = "composite.exe";
668 // String sCommand = sComposite +" -compose difference " +
669 // StringHelper.doubleQuoteIfNeed(sOldGfx) + " " +
670 // StringHelper.doubleQuoteIfNeed(sNewGfx) + " " +
671 // StringHelper.doubleQuoteIfNeed(sDiffGfx);
674 // // System.out.println(sCommand);
675 // // executeSynchronously(sCommand);
676 // ProcessHandler aHandler = new ProcessHandler(sCommand);
677 // boolean bBackValue = aHandler.executeSynchronously();
679 compareJPEGs(sOldGfx
, sNewGfx
, sDiffGfx
);
681 if (FileHelper
.exists(sDiffGfx
))
683 int nResult
= identify(sDiffGfx
);
686 aCurrentStatus
.nDiffStatus
= StatusHelper
.DIFF_NO_DIFFERENCES
;
690 aCurrentStatus
.nDiffStatus
= StatusHelper
.DIFF_DIFFERENCES_FOUND
;
693 aCurrentStatus
.nPercent
= estimateGfx(sOldGfx
, sNewGfx
, sDiffGfx
);
695 catch (java
.io
.IOException e
)
697 GlobalLogWriter
.get().println(e
.getMessage());
698 aCurrentStatus
.nPercent
= -1;
701 // LLA: should diffdiff file delete?
702 // File aFile = new File(sDiffGfx);
707 GlobalLogWriter
.get().println("composite can't create the diffdiff file.");
710 return aCurrentStatus
;
713 // -----------------------------------------------------------------------------
715 * count how much pixel differ and between Old or New and the Difference graphics
717 * First, count the old graphics, then the new graphics due to the fact both should be equal
718 * it should be legal to take result from old or new. We take the graphics with less values.
720 * Second, count the difference graphics, now take the percent algorithm and
721 * build a percent value, which contain the number of different pixels as a percent value
724 * 0% there is no difference
726 * <100% Take a look into the difference graphics, maybe the difference graphics shows
727 * text like outlined or the text is little bit move left, right up or down.
729 * >100% Yes it's possible that there is a difference more then 100%, maybe a font problem
730 * between old and new graphics. The font of the new graphics is little bit bigger,
731 * so the pixel count between old graphics and new graphics is twice the more.
734 public int estimateGfx(String _sOldGfx
, String _sNewGfx
, String _sDiffGfx
)
735 throws java
.io
.IOException
738 int nNotWhiteCount_OldGraphic
= PixelCounter
.countNotWhitePixelsFromImage(_sOldGfx
);
739 int nNotWhiteCount_NewGraphic
= PixelCounter
.countNotWhitePixelsFromImage(_sNewGfx
);
740 int nNotBlackCount_DiffGraphic
= PixelCounter
.countNotBlackPixelsFromImage(_sDiffGfx
);
742 int nMinNotWhiteCount
= Math
.min(nNotWhiteCount_NewGraphic
, nNotWhiteCount_OldGraphic
);
745 if (nMinNotWhiteCount
== 0)
747 nMinNotWhiteCount
= Math
.max(nNotWhiteCount_NewGraphic
, nNotWhiteCount_OldGraphic
);
748 if (nMinNotWhiteCount
== 0)
750 nMinNotWhiteCount
= 1;
754 int nPercent
= Math
.abs(nNotBlackCount_DiffGraphic
* 100 / nMinNotWhiteCount
);
755 GlobalLogWriter
.get().println( "Graphics check, pixel based:" + String
.valueOf(nPercent
) + "% pixel differ ");
762 * Some selftest functionallity
764 // public static void main(String[] args)
766 // System.out.println(FileHelper.getNameNoSuffix("doc.sxw"));
767 // System.out.println(FileHelper.getSuffix("doc.sxw"));
768 // System.out.println(FileHelper.getBasename("doc.sxw"));
769 // System.out.println(FileHelper.getBasename("/tmp/doc.sxw"));
771 // PRNCompare a = new PRNCompare();
772 // a.setInputPath( "/cws/so-cwsserv06/qadev18/SRC680/src.m47/convwatch.keep/input/msoffice/xp/PowerPoint");
773 // a.setReferencePath( "/cws/so-cwsserv06/qadev18/SRC680/src.m47/convwatch.keep/input/msoffice/xp/PowerPoint");
774 // a.setOutputPath( "/tmp/convwatch_java");
775 // a.setDocFile( "1_Gov.ppt");
776 // a.setReferenceFile( "1_Gov.prn" );
777 // a.setPostScriptFile("1_Gov.ps" );
781 // LLA: 20040804 sample how to build jpegs from reference files
782 // a.createJPEGFromPostscript("/tmp/convwatch_java",
783 // "/home/apitest/WorkFromHome/20040804/reference", "worddoc.prn" );
785 // a.createJPEGFromPostscript("/tmp/convwatch_java",
786 // "/home/apitest/WorkFromHome/20040804/reference", "worddoc.ps" );
788 // Status[] aList = a.createDiffs("/tmp/convwatch_java",
789 // "/tmp/convwatch_java", "worddoc.prn",
790 // "/tmp/convwatch_java", "worddoc.ps",
793 // LLA: 20040805 sample how to check 2 gfx files
794 // this function return DifferenceType.NO_DIFFERENCE if the pictures contain no graphically difference
795 // DifferenceType aReturnValue = a.checkDiffDiff("/tmp/convwatch_java",
796 // "/tmp/convwatch_java", "worddoc.prn.diff1.jpg",
797 // "/tmp/convwatch_java/old", "worddoc.prn.diff1.jpg");
798 // if (aReturnValue.equals( DifferenceType.NO_DIFFERENCE ))
800 // System.out.println("There is no difference between both diff files.");
803 // a.setOldDiff( "/olddiffs");