1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package convwatch;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir 
27cdf0e10cSrcweir import helper.ProcessHandler;
28cdf0e10cSrcweir import java.io.File;
29cdf0e10cSrcweir import convwatch.PixelCounter;
30cdf0e10cSrcweir import convwatch.StatusHelper;
31cdf0e10cSrcweir import helper.OSHelper;
32cdf0e10cSrcweir import helper.StringHelper;
33cdf0e10cSrcweir import java.util.ArrayList;
34cdf0e10cSrcweir import util.utils;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // -----------------------------------------------------------------------------
37cdf0e10cSrcweir // --------------------------------- PRNCompare ---------------------------------
38cdf0e10cSrcweir 
39cdf0e10cSrcweir // class DifferenceType
40cdf0e10cSrcweir // {
41cdf0e10cSrcweir //     final static int NO_DIFFERENCE = 1;
42cdf0e10cSrcweir //     final static int DIFFERENCE = 2;
43cdf0e10cSrcweir //
44cdf0e10cSrcweir //     public int nValue = NO_DIFFERENCE;
45cdf0e10cSrcweir //     public boolean equals(int _n)
46cdf0e10cSrcweir //         {
47cdf0e10cSrcweir //             if ( _n == nValue ) return true;
48cdf0e10cSrcweir //             return false;
49cdf0e10cSrcweir //         }
50cdf0e10cSrcweir // }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir // -----------------------------------------------------------------------------
53cdf0e10cSrcweir public class PRNCompare
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     // OSHelper m_aHelper;
56cdf0e10cSrcweir     String fs;
57cdf0e10cSrcweir 
PRNCompare()58cdf0e10cSrcweir     public PRNCompare()
59cdf0e10cSrcweir         {
60cdf0e10cSrcweir             // m_aHelper = new OSHelper();
61cdf0e10cSrcweir             fs = System.getProperty("file.separator");
62cdf0e10cSrcweir         }
63cdf0e10cSrcweir 
executeSynchronously(String _sCommand)64cdf0e10cSrcweir     String executeSynchronously(String _sCommand)
65cdf0e10cSrcweir         {
66cdf0e10cSrcweir             // System.out.println(_sCommand);
67cdf0e10cSrcweir 
68cdf0e10cSrcweir             ProcessHandler aHandler = new ProcessHandler(_sCommand);
69cdf0e10cSrcweir             boolean bBackValue = aHandler.executeSynchronously();
70cdf0e10cSrcweir 
71cdf0e10cSrcweir             String sText = aHandler.getOutputText();
72cdf0e10cSrcweir 
73cdf0e10cSrcweir             GlobalLogWriter.get().println("Exitcode: " + String.valueOf(aHandler.getExitCode()));
74cdf0e10cSrcweir             return sText;
75cdf0e10cSrcweir         }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 
getMaxNumOfFileEntry(String _sDirectory, String _sBasename)78cdf0e10cSrcweir     int getMaxNumOfFileEntry(String _sDirectory, String _sBasename)
79cdf0e10cSrcweir         {
80cdf0e10cSrcweir //  TODO: check if directory exist should be done earlier
81cdf0e10cSrcweir             File aDirectory = new File(_sDirectory);
82cdf0e10cSrcweir             File[] aDirList = aDirectory.listFiles(
83cdf0e10cSrcweir                 /*
84cdf0e10cSrcweir                   new FileFilter() {
85cdf0e10cSrcweir                   boolean accept(File filename)
86cdf0e10cSrcweir                   {
87cdf0e10cSrcweir                   if (filename.getName().endsWith("jpg"))
88cdf0e10cSrcweir                   return true;
89cdf0e10cSrcweir                   return false;
90cdf0e10cSrcweir                   }
91cdf0e10cSrcweir                   } */
92cdf0e10cSrcweir                 );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir             int nMaxNumber = 0;
95cdf0e10cSrcweir             for(int n = 0; n<aDirList.length ; n++)
96cdf0e10cSrcweir             {
97cdf0e10cSrcweir                 String sDirEntry = aDirList[n].getName();
98cdf0e10cSrcweir                 if (sDirEntry.endsWith(".jpg"))
99cdf0e10cSrcweir                 {
100cdf0e10cSrcweir                     int nNum = nMaxNumber;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir                     if (sDirEntry.startsWith(_sBasename))
103cdf0e10cSrcweir                     {
104cdf0e10cSrcweir                         // System.out.println(sDirEntry);
105cdf0e10cSrcweir                         int nJpgIdx = sDirEntry.lastIndexOf(".jpg");
106cdf0e10cSrcweir                         String sValue = sDirEntry.substring(_sBasename.length(), nJpgIdx);
107cdf0e10cSrcweir                         int nValue = 0;
108cdf0e10cSrcweir                         try
109cdf0e10cSrcweir                         {
110cdf0e10cSrcweir                             nValue = Integer.valueOf(sValue).intValue();
111cdf0e10cSrcweir                         }
112cdf0e10cSrcweir                         catch(java.lang.NumberFormatException e)
113cdf0e10cSrcweir                         {
114cdf0e10cSrcweir                         }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir                         // System.out.println(nValue);
117cdf0e10cSrcweir                         nNum = nValue;
118cdf0e10cSrcweir                     }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir                     if (nNum > nMaxNumber)
121cdf0e10cSrcweir                     {
122cdf0e10cSrcweir                         nMaxNumber = nNum;
123cdf0e10cSrcweir                     }
124cdf0e10cSrcweir                 }
125cdf0e10cSrcweir             }
126cdf0e10cSrcweir             return nMaxNumber;
127cdf0e10cSrcweir         }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     String m_sInputPath;
130cdf0e10cSrcweir     String m_sReferencePath;
131cdf0e10cSrcweir     String m_sOutputPath;
132cdf0e10cSrcweir     String m_sDocFile;
133cdf0e10cSrcweir     String m_sReferenceFile;
134cdf0e10cSrcweir     String m_sPostScriptFile;
135cdf0e10cSrcweir     // String m_sOldDiff;
136cdf0e10cSrcweir     int m_nMaxPages = 0;
137cdf0e10cSrcweir     int m_nResolutionInDPI = 0;
138cdf0e10cSrcweir     TriState m_tUseBorderMove;
139cdf0e10cSrcweir     String m_sDocumentType;
140cdf0e10cSrcweir 
setInputPath(String _sInputPath)141cdf0e10cSrcweir     public void setInputPath(String _sInputPath) { m_sInputPath = _sInputPath; }
142cdf0e10cSrcweir 
setReferencePath(String _sReferencePath)143cdf0e10cSrcweir     public void setReferencePath(String _sReferencePath) { m_sReferencePath = _sReferencePath; }
144cdf0e10cSrcweir 
setOutputPath(String _sOutPath)145cdf0e10cSrcweir     public void setOutputPath(String _sOutPath) { m_sOutputPath = _sOutPath; }
146cdf0e10cSrcweir 
setDocFile(String _sDocFile)147cdf0e10cSrcweir     public void setDocFile(String _sDocFile) { m_sDocFile = _sDocFile;}
148cdf0e10cSrcweir 
setReferenceFile(String _sPRNFile)149cdf0e10cSrcweir     public void setReferenceFile(String _sPRNFile){ m_sReferenceFile = _sPRNFile;}
150cdf0e10cSrcweir 
setPostScriptFile(String _sPSFile)151cdf0e10cSrcweir     public void setPostScriptFile(String _sPSFile){ m_sPostScriptFile = _sPSFile;}
152cdf0e10cSrcweir 
setBorderMove(TriState _b)153cdf0e10cSrcweir     public void setBorderMove(TriState _b) {m_tUseBorderMove = _b;}
getBorderMove()154cdf0e10cSrcweir     public TriState getBorderMove() {return m_tUseBorderMove;}
155cdf0e10cSrcweir     // public void setOldDiffPath(String _sOldDiff)
156cdf0e10cSrcweir     //     {
157cdf0e10cSrcweir     //         m_sOldDiff = _sOldDiff;
158cdf0e10cSrcweir     //     }
setMaxPages(int _n)159cdf0e10cSrcweir     public void setMaxPages(int _n) {m_nMaxPages = _n;}
getMaxPages()160cdf0e10cSrcweir     int getMaxPages() {return m_nMaxPages;}
161cdf0e10cSrcweir 
setResolutionInDPI(int _n)162cdf0e10cSrcweir     public void setResolutionInDPI(int _n) {m_nResolutionInDPI = _n;}
getResolutionInDPI()163cdf0e10cSrcweir     int getResolutionInDPI() {return m_nResolutionInDPI;}
164cdf0e10cSrcweir 
setDocumentType(String _sTypeName)165cdf0e10cSrcweir     public void setDocumentType(String _sTypeName)
166cdf0e10cSrcweir         {
167cdf0e10cSrcweir             m_sDocumentType = _sTypeName;
168cdf0e10cSrcweir         }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     // -----------------------------------------------------------------------------
171cdf0e10cSrcweir 
compare()172cdf0e10cSrcweir     public StatusHelper[] compare()
173cdf0e10cSrcweir         {
174cdf0e10cSrcweir             createJPEGFromPostscript(m_sOutputPath, m_sReferencePath, m_sReferenceFile, getResolutionInDPI());
175cdf0e10cSrcweir //  TODO: Assume, that Postscript is already in the OutputPath, this may change.
176cdf0e10cSrcweir             createJPEGFromPostscript(m_sOutputPath, m_sOutputPath, m_sPostScriptFile, getResolutionInDPI());
177cdf0e10cSrcweir             StatusHelper[] aList = createDiffs(m_sOutputPath,
178cdf0e10cSrcweir                                                m_sOutputPath, m_sReferenceFile,
179cdf0e10cSrcweir                                                m_sOutputPath, m_sPostScriptFile,
180cdf0e10cSrcweir                                                getMaxPages(), m_tUseBorderMove);
181cdf0e10cSrcweir 
182cdf0e10cSrcweir //  TODO: Rename?
183cdf0e10cSrcweir 
184cdf0e10cSrcweir             return aList;
185cdf0e10cSrcweir         }
186cdf0e10cSrcweir 
compare_new()187cdf0e10cSrcweir     public StatusHelper[] compare_new()
188cdf0e10cSrcweir         {
189cdf0e10cSrcweir             String[] aRefList = createJPEGFromPostscript(m_sOutputPath, m_sReferencePath, m_sReferenceFile, getResolutionInDPI());
190cdf0e10cSrcweir //  TODO: Assume, that Postscript is already in the OutputPath, this may change.
191cdf0e10cSrcweir             String[] aPSList = createJPEGFromPostscript(m_sOutputPath, m_sOutputPath, m_sPostScriptFile, getResolutionInDPI());
192cdf0e10cSrcweir             StatusHelper[] aList = createDiffs(m_sOutputPath,
193cdf0e10cSrcweir                                                aRefList,
194cdf0e10cSrcweir                                                aPSList,
195cdf0e10cSrcweir                                                getMaxPages(), m_tUseBorderMove);
196cdf0e10cSrcweir 
197cdf0e10cSrcweir             return aList;
198cdf0e10cSrcweir         }
199cdf0e10cSrcweir 
getJPEGName(String _sOutputPath, String _sBasename, String _sGS_PageOutput)200cdf0e10cSrcweir     static String getJPEGName(String _sOutputPath, String _sBasename, String _sGS_PageOutput)
201cdf0e10cSrcweir         {
202cdf0e10cSrcweir             String fs = System.getProperty("file.separator");
203cdf0e10cSrcweir 
204cdf0e10cSrcweir             String sJPEGName = _sOutputPath + fs + _sBasename + _sGS_PageOutput + ".jpg";
205cdf0e10cSrcweir             return sJPEGName;
206cdf0e10cSrcweir         }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     /**
209cdf0e10cSrcweir      * Create via ghostscript (gs) from the reference file for every page a JPEG file
210cdf0e10cSrcweir      *
211cdf0e10cSrcweir      * MUST set:
212cdf0e10cSrcweir      * m_sOutputPath, m_sReferenceFile, m_sReferencePath
213cdf0e10cSrcweir      *
214cdf0e10cSrcweir      * return exit code from gs command
215cdf0e10cSrcweir      */
createJPEGFromPostscript(String _sOutputPath, String _sSourcePath, String _sSourceFile, int _nResolutionInDPI)216cdf0e10cSrcweir     public static String[] createJPEGFromPostscript(String _sOutputPath, String _sSourcePath, String _sSourceFile, int _nResolutionInDPI)
217cdf0e10cSrcweir         {
218cdf0e10cSrcweir             String sGS_PageOutput = "%04d";
219cdf0e10cSrcweir             // if ( OSHelper.isWindows() )
220cdf0e10cSrcweir             // {
221cdf0e10cSrcweir             //     sGS_PageOutput = "%%d";
222cdf0e10cSrcweir             // }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir             FileHelper.makeDirectories("", _sOutputPath);
225cdf0e10cSrcweir 
226cdf0e10cSrcweir             // create a jpeg from original prn
227cdf0e10cSrcweir             String fs = System.getProperty("file.separator");
228cdf0e10cSrcweir 
229cdf0e10cSrcweir             String sJPGFilename = getJPEGName(_sOutputPath, _sSourceFile, sGS_PageOutput);
230cdf0e10cSrcweir             String sOriginalFile = _sSourcePath + fs + _sSourceFile;
231cdf0e10cSrcweir             String sCommand;
232cdf0e10cSrcweir             String sGS = "gs";
233cdf0e10cSrcweir             if (OSHelper.isWindows())
234cdf0e10cSrcweir             {
235cdf0e10cSrcweir                 sGS = "gswin32c.exe";
236cdf0e10cSrcweir             }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir             sCommand = sGS + " -dNOPROMPT -dBATCH -sDEVICE=jpeg -r" + String.valueOf(_nResolutionInDPI) + " -dNOPAUSE -sOutputFile=" + StringHelper.doubleQuoteIfNeed(sJPGFilename) + " " + StringHelper.doubleQuoteIfNeed(sOriginalFile);
239cdf0e10cSrcweir             String[] sCommandArray =
240cdf0e10cSrcweir                 {
241cdf0e10cSrcweir                     sGS,
242cdf0e10cSrcweir                     "-dNOPROMPT",
243cdf0e10cSrcweir                     "-dBATCH",
244cdf0e10cSrcweir                     "-sDEVICE=jpeg",
245cdf0e10cSrcweir                     "-r" + String.valueOf(_nResolutionInDPI),
246cdf0e10cSrcweir                     "-dNOPAUSE",
247cdf0e10cSrcweir                     "-sOutputFile=" + sJPGFilename,
248cdf0e10cSrcweir                     sOriginalFile
249cdf0e10cSrcweir                 };
250cdf0e10cSrcweir             // System.out.println("Start Command array");
251cdf0e10cSrcweir             // try
252cdf0e10cSrcweir             // {
253cdf0e10cSrcweir             //     Runtime.getRuntime().exec(sCommandArray);
254cdf0e10cSrcweir             // } catch (Exception e) {
255cdf0e10cSrcweir             //     System.out.println("FAILED");
256cdf0e10cSrcweir             // }
257cdf0e10cSrcweir             // System.out.println("done");
258cdf0e10cSrcweir 
259cdf0e10cSrcweir             ProcessHandler aHandler = new ProcessHandler(sCommandArray);
260cdf0e10cSrcweir             boolean bBackValue = aHandler.executeSynchronously();
261cdf0e10cSrcweir 
262cdf0e10cSrcweir             // TODO: return a real filename, due to the fact we don't know how much files are created, maybe better to return a list
263cdf0e10cSrcweir 
264cdf0e10cSrcweir             ArrayList m_aFileList = new ArrayList();
265cdf0e10cSrcweir             for (int i=1;i<9999;i++)
266cdf0e10cSrcweir             {
267cdf0e10cSrcweir                 String sNewJPEGFilename = utils.replaceAll13(sJPGFilename, sGS_PageOutput, StringHelper.createValueString(i, 4));
268cdf0e10cSrcweir                 if (FileHelper.exists(sNewJPEGFilename))
269cdf0e10cSrcweir                 {
270cdf0e10cSrcweir                     m_aFileList.add(sNewJPEGFilename); // as long as the files exist, fill the array
271cdf0e10cSrcweir                 }
272cdf0e10cSrcweir                 else
273cdf0e10cSrcweir                 {
274cdf0e10cSrcweir                     break;                             // stop file check
275cdf0e10cSrcweir                 }
276cdf0e10cSrcweir             }
277cdf0e10cSrcweir             String[] aList = new String[m_aFileList.size()];
278cdf0e10cSrcweir             aList = (String[])m_aFileList.toArray(aList);
279cdf0e10cSrcweir             return aList; // sNewJPEGFilename;
280cdf0e10cSrcweir         }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     /**
283cdf0e10cSrcweir      * Create Difference Files from the JPEGs
284cdf0e10cSrcweir      * parameter, how much difference files should create
285cdf0e10cSrcweir      *
286cdf0e10cSrcweir      * m_sPostScriptFile
287cdf0e10cSrcweir      * m_sReferenceFile
288cdf0e10cSrcweir      * m_sOutputPath
289cdf0e10cSrcweir      */
createDiffs(String _sOutputPath, String _sSourcePath1, String _sSourceFile1, String _sSourcePath2, String _sSourceFile2, int _nMaxDiffs, TriState _tUseBorderMove)290cdf0e10cSrcweir     public StatusHelper[] createDiffs(String _sOutputPath, String _sSourcePath1, String _sSourceFile1, String _sSourcePath2, String _sSourceFile2, int _nMaxDiffs, TriState _tUseBorderMove)
291cdf0e10cSrcweir         {
292cdf0e10cSrcweir             if (_nMaxDiffs < 1)
293cdf0e10cSrcweir             {
294cdf0e10cSrcweir                 _nMaxDiffs = 1;
295cdf0e10cSrcweir             }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir             String sS1Basename = FileHelper.getBasename(_sSourceFile1);
298cdf0e10cSrcweir             String sS2Basename = FileHelper.getBasename(_sSourceFile2);
299cdf0e10cSrcweir 
300cdf0e10cSrcweir             // count, from which file (jpegs) exist more, take the less one
301cdf0e10cSrcweir             // more are not compareable
302cdf0e10cSrcweir             int nS1_Files = getMaxNumOfFileEntry(_sSourcePath1, sS1Basename);
303cdf0e10cSrcweir             int nS2_Files = getMaxNumOfFileEntry(_sSourcePath2, sS2Basename);
304cdf0e10cSrcweir 
305cdf0e10cSrcweir             // System.out.println("count of s1 files " + String.valueOf(nS1_Files));
306cdf0e10cSrcweir             // System.out.println("count of s2 files " + String.valueOf(nS2_Files));
307cdf0e10cSrcweir 
308cdf0e10cSrcweir             // take the min of both
309cdf0e10cSrcweir             int nMin = Math.min(nS1_Files, nS2_Files);
310cdf0e10cSrcweir             nMin = Math.min(nMin, _nMaxDiffs);
311cdf0e10cSrcweir 
312cdf0e10cSrcweir             StatusHelper[] aList = new StatusHelper[nMin];
313cdf0e10cSrcweir 
314cdf0e10cSrcweir //  TODO: if both document do not have same page count, produce an error
315cdf0e10cSrcweir             // System.out.println("min of both: " + String.valueOf(nMin));
316cdf0e10cSrcweir 
317cdf0e10cSrcweir             int nStatusIndex = 0;
318cdf0e10cSrcweir             for (int i=1;i<=nMin;i++)
319cdf0e10cSrcweir             {
320cdf0e10cSrcweir                 String sOldGfx =  getJPEGName(_sSourcePath1, sS1Basename, StringHelper.createValueString(i, 4));
321cdf0e10cSrcweir                 String sNewGfx =  getJPEGName(_sSourcePath2, sS2Basename, StringHelper.createValueString(i, 4));
322cdf0e10cSrcweir                 String sDiffGfx_ = getJPEGName(_sOutputPath, sS1Basename + ".diff", StringHelper.createValueString(i, 4));
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 
325cdf0e10cSrcweir                 String sDiffGfx = compareJPEGs(sOldGfx, sNewGfx, sDiffGfx_);
326cdf0e10cSrcweir                 StatusHelper aStatus = new StatusHelper(sOldGfx, sNewGfx, sDiffGfx);
327cdf0e10cSrcweir 
328cdf0e10cSrcweir                 // if (FileHelper.exists(sDiffGfx))
329cdf0e10cSrcweir                 if (sDiffGfx.length() > 0)
330cdf0e10cSrcweir                 {
331cdf0e10cSrcweir                     int nResult = identify(sDiffGfx);
332cdf0e10cSrcweir                     if (nResult == 1)
333cdf0e10cSrcweir                     {
334cdf0e10cSrcweir                         aStatus.nDiffStatus = StatusHelper.DIFF_NO_DIFFERENCES;
335cdf0e10cSrcweir                     }
336cdf0e10cSrcweir                     else
337cdf0e10cSrcweir                     {
338cdf0e10cSrcweir                         try
339cdf0e10cSrcweir                         {
340cdf0e10cSrcweir                             int nPercent = estimateGfx(sOldGfx, sNewGfx, sDiffGfx);
341cdf0e10cSrcweir                             aStatus.nDiffStatus = StatusHelper.DIFF_DIFFERENCES_FOUND;
342cdf0e10cSrcweir                             aStatus.nPercent = nPercent;
343cdf0e10cSrcweir 
344cdf0e10cSrcweir                             // GlobalLogWriter.get().println("Hello World:  Percent:= " + nPercent);
345cdf0e10cSrcweir                             // GlobalLogWriter.get().println("Hello World: TriState:= " + _tUseBorderMove.intValue());
346cdf0e10cSrcweir                             // GlobalLogWriter.get().println("Hello World:  DocType:= " + m_sDocumentType);
347cdf0e10cSrcweir 
348cdf0e10cSrcweir // TODO: insert here the new BorderRemover if the percentage value is creater than 75%
349cdf0e10cSrcweir                             if (nPercent > 75 &&
350cdf0e10cSrcweir                                 ((_tUseBorderMove == TriState.TRUE ) ||
351cdf0e10cSrcweir                                  ((_tUseBorderMove == TriState.UNSET) &&
352cdf0e10cSrcweir                                   m_sDocumentType.indexOf("MS PowerPoint") > 0)))
353cdf0e10cSrcweir                             {
354cdf0e10cSrcweir                                 setBorderMove(TriState.TRUE);
355cdf0e10cSrcweir 
356cdf0e10cSrcweir                                 String sOld_BM_Gfx =  getJPEGName(_sSourcePath1, sS1Basename + ".BM", StringHelper.createValueString(i, 4));
357cdf0e10cSrcweir                                 String sNew_BM_Gfx =  getJPEGName(_sSourcePath2, sS2Basename + ".BM", StringHelper.createValueString(i, 4));
358cdf0e10cSrcweir                                 String sDiff_BM_Gfx_ = getJPEGName(_sOutputPath, sS1Basename + ".diff.BM", StringHelper.createValueString(i, 4));
359cdf0e10cSrcweir                                 aStatus.setFilesForBorderMove(sOld_BM_Gfx, sNew_BM_Gfx, sDiff_BM_Gfx_);
360cdf0e10cSrcweir                                 try
361cdf0e10cSrcweir                                 {
362cdf0e10cSrcweir                                     BorderRemover a = new BorderRemover();
363cdf0e10cSrcweir                                     a.createNewImageWithoutBorder(sOldGfx, sOld_BM_Gfx);
364cdf0e10cSrcweir                                     a.createNewImageWithoutBorder(sNewGfx, sNew_BM_Gfx);
365cdf0e10cSrcweir 
366cdf0e10cSrcweir                                     String sDiff_BM_Gfx = compareJPEGs( sOld_BM_Gfx, sNew_BM_Gfx, sDiff_BM_Gfx_);
367cdf0e10cSrcweir 
368cdf0e10cSrcweir                                     // if (FileHelper.exists(sDiff_BM_Gfx))
369cdf0e10cSrcweir                                     if (sDiff_BM_Gfx.length() > 0)
370cdf0e10cSrcweir                                     {
371cdf0e10cSrcweir                                         nResult = identify(sDiff_BM_Gfx);
372cdf0e10cSrcweir                                         if (nResult == 1)
373cdf0e10cSrcweir                                         {
374cdf0e10cSrcweir                                             aStatus.nDiffStatus = StatusHelper.DIFF_AFTER_MOVE_DONE_NO_PROBLEMS;
375cdf0e10cSrcweir                                             aStatus.nPercent2 = 0;
376cdf0e10cSrcweir                                         }
377cdf0e10cSrcweir                                         else
378cdf0e10cSrcweir                                         {
379cdf0e10cSrcweir                                             nPercent = estimateGfx(sOld_BM_Gfx, sNew_BM_Gfx, sDiff_BM_Gfx);
380cdf0e10cSrcweir                                             aStatus.nDiffStatus = StatusHelper.DIFF_AFTER_MOVE_DONE_DIFFERENCES_FOUND;
381cdf0e10cSrcweir                                             aStatus.nPercent2 = nPercent;
382cdf0e10cSrcweir                                         }
383cdf0e10cSrcweir                                     }
384cdf0e10cSrcweir                                     else
385cdf0e10cSrcweir                                     {
386cdf0e10cSrcweir                                     }
387cdf0e10cSrcweir                                 }
388cdf0e10cSrcweir                                 catch(java.io.IOException e)
389cdf0e10cSrcweir                                 {
390cdf0e10cSrcweir                                     GlobalLogWriter.get().println("Exception caught. At border remove: " + e.getMessage());
391cdf0e10cSrcweir                                 }
392cdf0e10cSrcweir                             }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 
395cdf0e10cSrcweir                         }
396cdf0e10cSrcweir                         catch (java.io.IOException e)
397cdf0e10cSrcweir                         {
398cdf0e10cSrcweir                             GlobalLogWriter.get().println(e.getMessage());
399cdf0e10cSrcweir                         }
400cdf0e10cSrcweir                     }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir                     // checkDiff(sOldGfx, sNewGfx, sDiffGfx);
403cdf0e10cSrcweir                     // if (i >= _nMaxDiffs)
404cdf0e10cSrcweir                     // {
405cdf0e10cSrcweir                     //     break;
406cdf0e10cSrcweir                     // }
407cdf0e10cSrcweir                 }
408cdf0e10cSrcweir                 aList[nStatusIndex ++] = aStatus;
409cdf0e10cSrcweir             }
410cdf0e10cSrcweir             return aList;
411cdf0e10cSrcweir         }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir 
createDiffs(String _sOutputPath, String[] _aRefList, String[] _aPSList, int _nMaxDiffs, TriState _tUseBorderMove)414cdf0e10cSrcweir     public StatusHelper[] createDiffs(String _sOutputPath, String[] _aRefList, String[] _aPSList, int _nMaxDiffs, TriState _tUseBorderMove)
415cdf0e10cSrcweir         {
416cdf0e10cSrcweir             if (_nMaxDiffs < 1)
417cdf0e10cSrcweir             {
418cdf0e10cSrcweir                 _nMaxDiffs = 1;
419cdf0e10cSrcweir             }
420cdf0e10cSrcweir 
421cdf0e10cSrcweir             // count, from which file (jpegs) exist more, take the less one
422cdf0e10cSrcweir             // more are not compareable
423cdf0e10cSrcweir 
424cdf0e10cSrcweir             // take the min of both
425cdf0e10cSrcweir             int nMin = Math.min(_aRefList.length, _aPSList.length);
426cdf0e10cSrcweir             nMin = Math.min(nMin, _nMaxDiffs);
427cdf0e10cSrcweir 
428cdf0e10cSrcweir             StatusHelper[] aList = new StatusHelper[nMin];
429cdf0e10cSrcweir 
430cdf0e10cSrcweir //  TODO: if both document do not have same page count, produce an error
431cdf0e10cSrcweir             // System.out.println("min of both: " + String.valueOf(nMin));
432cdf0e10cSrcweir 
433cdf0e10cSrcweir             int nStatusIndex = 0;
434cdf0e10cSrcweir             for (int i=1;i<=nMin;i++)
435cdf0e10cSrcweir             {
436cdf0e10cSrcweir                 String sOldGfx =  _aRefList[i];
437cdf0e10cSrcweir                 String sNewGfx =  _aPSList[i];
438cdf0e10cSrcweir                 // String sDiffGfx_ = getJPEGName(_sOutputPath, sS1Basename + ".diff", StringHelper.createValueString(i, 4));
439cdf0e10cSrcweir 
440cdf0e10cSrcweir 
441cdf0e10cSrcweir                 String sDiffGfx = compareJPEGs(sOldGfx, sNewGfx );
442cdf0e10cSrcweir                 StatusHelper aStatus = new StatusHelper(sOldGfx, sNewGfx, sDiffGfx);
443cdf0e10cSrcweir 
444cdf0e10cSrcweir                 // if (FileHelper.exists(sDiffGfx))
445cdf0e10cSrcweir                 if (sDiffGfx.length() > 0)
446cdf0e10cSrcweir                 {
447cdf0e10cSrcweir                     int nResult = identify(sDiffGfx);
448cdf0e10cSrcweir                     if (nResult == 1)
449cdf0e10cSrcweir                     {
450cdf0e10cSrcweir                         aStatus.nDiffStatus = StatusHelper.DIFF_NO_DIFFERENCES;
451cdf0e10cSrcweir                     }
452cdf0e10cSrcweir                     else
453cdf0e10cSrcweir                     {
454cdf0e10cSrcweir                         try
455cdf0e10cSrcweir                         {
456cdf0e10cSrcweir                             int nPercent = estimateGfx(sOldGfx, sNewGfx, sDiffGfx);
457cdf0e10cSrcweir                             // GlobalLogWriter.get().println("Hello World:  Percent:= " + nPercent);
458cdf0e10cSrcweir                             // GlobalLogWriter.get().println("Hello World: TriState:= " + _tUseBorderMove.intValue());
459cdf0e10cSrcweir                             // GlobalLogWriter.get().println("Hello World:  DocType:= " + m_sDocumentType);
460cdf0e10cSrcweir 
461cdf0e10cSrcweir                             aStatus.nDiffStatus = StatusHelper.DIFF_DIFFERENCES_FOUND;
462cdf0e10cSrcweir                             aStatus.nPercent = nPercent;
463cdf0e10cSrcweir 
464cdf0e10cSrcweir                             if (nPercent > 75 &&
465cdf0e10cSrcweir                                 ((_tUseBorderMove == TriState.TRUE ) ||
466cdf0e10cSrcweir                                  ((_tUseBorderMove == TriState.UNSET) &&
467cdf0e10cSrcweir                                   m_sDocumentType.indexOf("MS PowerPoint") > 0)))
468cdf0e10cSrcweir                             {
469cdf0e10cSrcweir                                 _tUseBorderMove = TriState.TRUE;
470cdf0e10cSrcweir //  TODO: problem is here, that we have to create some new names.
471cdf0e10cSrcweir 
472cdf0e10cSrcweir                                 String sBasename1 = FileHelper.getBasename(sOldGfx);
473cdf0e10cSrcweir                                 String sNameNoSuffix1 = FileHelper.getNameNoSuffix(sBasename1);
474cdf0e10cSrcweir                                 String sBasename2 = FileHelper.getBasename(sNewGfx);
475cdf0e10cSrcweir                                 String sNameNoSuffix2 = FileHelper.getNameNoSuffix(sBasename2);
476cdf0e10cSrcweir 
477cdf0e10cSrcweir                                 String sTmpDir = util.utils.getUsersTempDir();
478cdf0e10cSrcweir                                 String fs = System.getProperty("file.separator");
479cdf0e10cSrcweir 
480cdf0e10cSrcweir                                 String sOld_BM_Gfx =  sTmpDir + fs + sNameNoSuffix1 + "-BM-" + StringHelper.createValueString(i, 4) + ".jpg";
481cdf0e10cSrcweir                                 String sNew_BM_Gfx =  sTmpDir + fs + sNameNoSuffix2 + "-BM-" + StringHelper.createValueString(i, 4) + ".jpg";
482cdf0e10cSrcweir                                 try
483cdf0e10cSrcweir                                 {
484cdf0e10cSrcweir                                     BorderRemover a = new BorderRemover();
485cdf0e10cSrcweir                                     a.createNewImageWithoutBorder(sOldGfx, sOld_BM_Gfx);
486cdf0e10cSrcweir                                     a.createNewImageWithoutBorder(sNewGfx, sNew_BM_Gfx);
487cdf0e10cSrcweir 
488cdf0e10cSrcweir                                     String sDiff_BM_Gfx = compareJPEGs( sOld_BM_Gfx, sNew_BM_Gfx );
489cdf0e10cSrcweir 
490cdf0e10cSrcweir                                     aStatus.setFilesForBorderMove(sOld_BM_Gfx, sNew_BM_Gfx, sDiff_BM_Gfx);
491cdf0e10cSrcweir 
492cdf0e10cSrcweir                                     // if (FileHelper.exists(sDiff_BM_Gfx))
493cdf0e10cSrcweir                                     if (sDiff_BM_Gfx.length() > 0)
494cdf0e10cSrcweir                                     {
495cdf0e10cSrcweir                                         nResult = identify(sDiff_BM_Gfx);
496cdf0e10cSrcweir                                         if (nResult == 1)
497cdf0e10cSrcweir                                         {
498cdf0e10cSrcweir                                             aStatus.nDiffStatus = StatusHelper.DIFF_AFTER_MOVE_DONE_NO_PROBLEMS;
499cdf0e10cSrcweir                                             aStatus.nPercent2 = 0;
500cdf0e10cSrcweir                                         }
501cdf0e10cSrcweir                                         else
502cdf0e10cSrcweir                                         {
503cdf0e10cSrcweir                                             nPercent = estimateGfx(sOld_BM_Gfx, sNew_BM_Gfx, sDiff_BM_Gfx);
504cdf0e10cSrcweir                                             aStatus.nDiffStatus = StatusHelper.DIFF_AFTER_MOVE_DONE_DIFFERENCES_FOUND;
505cdf0e10cSrcweir                                             aStatus.nPercent2 = nPercent;
506cdf0e10cSrcweir                                         }
507cdf0e10cSrcweir                                     }
508cdf0e10cSrcweir                                     else
509cdf0e10cSrcweir                                     {
510cdf0e10cSrcweir                                     }
511cdf0e10cSrcweir                                 }
512cdf0e10cSrcweir                                 catch(java.io.IOException e)
513cdf0e10cSrcweir                                 {
514cdf0e10cSrcweir                                     GlobalLogWriter.get().println("Exception caught. At border remove: " + e.getMessage());
515cdf0e10cSrcweir                                 }
516cdf0e10cSrcweir                             }
517cdf0e10cSrcweir                         }
518cdf0e10cSrcweir                         catch (java.io.IOException e)
519cdf0e10cSrcweir                         {
520cdf0e10cSrcweir                             GlobalLogWriter.get().println(e.getMessage());
521cdf0e10cSrcweir                         }
522cdf0e10cSrcweir                     }
523cdf0e10cSrcweir 
524cdf0e10cSrcweir                     // checkDiff(sOldGfx, sNewGfx, sDiffGfx);
525cdf0e10cSrcweir                     // if (i >= _nMaxDiffs)
526cdf0e10cSrcweir                     // {
527cdf0e10cSrcweir                     //     break;
528cdf0e10cSrcweir                     // }
529cdf0e10cSrcweir                 }
530cdf0e10cSrcweir                 aList[nStatusIndex ++] = aStatus;
531cdf0e10cSrcweir             }
532cdf0e10cSrcweir             return aList;
533cdf0e10cSrcweir         }
534cdf0e10cSrcweir 
compareJPEGs(String _sOldGfx, String _sNewGfx)535cdf0e10cSrcweir     public static String compareJPEGs(String _sOldGfx, String _sNewGfx)
536cdf0e10cSrcweir         {
537cdf0e10cSrcweir             String sBasename1 = FileHelper.getBasename(_sOldGfx);
538cdf0e10cSrcweir             String sNameNoSuffix1 = FileHelper.getNameNoSuffix(sBasename1);
539cdf0e10cSrcweir             String sBasename2 = FileHelper.getBasename(_sNewGfx);
540cdf0e10cSrcweir             String sNameNoSuffix2 = FileHelper.getNameNoSuffix(sBasename2);
541cdf0e10cSrcweir 
542cdf0e10cSrcweir             String sTmpDir = util.utils.getUsersTempDir();
543cdf0e10cSrcweir             String fs = System.getProperty("file.separator");
544cdf0e10cSrcweir 
545cdf0e10cSrcweir             String sDiffName = sTmpDir + fs + sNameNoSuffix1 + "-" + sNameNoSuffix2 + "-diff.jpg";
546cdf0e10cSrcweir 
547cdf0e10cSrcweir             return compareJPEGs(_sOldGfx, _sNewGfx, sDiffName);
548cdf0e10cSrcweir         }
549cdf0e10cSrcweir 
compareJPEGs(String _sOldGfx, String _sNewGfx, String _sDiffGfx)550cdf0e10cSrcweir     public static String compareJPEGs(String _sOldGfx, String _sNewGfx, String _sDiffGfx)
551cdf0e10cSrcweir         {
552cdf0e10cSrcweir             String sComposite = "composite";
553cdf0e10cSrcweir             if (OSHelper.isWindows())
554cdf0e10cSrcweir             {
555cdf0e10cSrcweir                 sComposite = "composite.exe";
556cdf0e10cSrcweir             }
557cdf0e10cSrcweir 
558cdf0e10cSrcweir             // String sCommand = sComposite + " -compose difference " +
559cdf0e10cSrcweir             //     StringHelper.doubleQuoteIfNeed(_sOldGfx) + " " +
560cdf0e10cSrcweir             //     StringHelper.doubleQuoteIfNeed(_sNewGfx) + " " +
561cdf0e10cSrcweir             //     StringHelper.doubleQuoteIfNeed(_sDiffGfx);
562cdf0e10cSrcweir 
563cdf0e10cSrcweir             String[] sCommandArray =
564cdf0e10cSrcweir                 {
565cdf0e10cSrcweir                     sComposite,
566cdf0e10cSrcweir                     "-compose",
567cdf0e10cSrcweir                     "difference",
568cdf0e10cSrcweir                     _sOldGfx,
569cdf0e10cSrcweir                     _sNewGfx,
570cdf0e10cSrcweir                     _sDiffGfx
571cdf0e10cSrcweir                 };
572cdf0e10cSrcweir 
573cdf0e10cSrcweir             ProcessHandler aHandler = new ProcessHandler(sCommandArray);
574cdf0e10cSrcweir             boolean bBackValue = aHandler.executeSynchronously();
575cdf0e10cSrcweir 
576cdf0e10cSrcweir             String sBack = aHandler.getOutputText();
577cdf0e10cSrcweir             GlobalLogWriter.get().println("'" + sBack + "'");
578cdf0e10cSrcweir 
579cdf0e10cSrcweir             // return aHandler.getExitCode();
580cdf0e10cSrcweir             if (FileHelper.exists(_sDiffGfx))
581cdf0e10cSrcweir             {
582cdf0e10cSrcweir                 return _sDiffGfx;
583cdf0e10cSrcweir             }
584cdf0e10cSrcweir             return "";
585cdf0e10cSrcweir         }
586cdf0e10cSrcweir 
587cdf0e10cSrcweir     /**
588cdf0e10cSrcweir      * wrapper for ImageMagick identify,
589cdf0e10cSrcweir      * function checks how many different colors a picture contains.
590cdf0e10cSrcweir      * if it's only one color (nResult==1), like background color, there is no difference.
591cdf0e10cSrcweir      */
identify(String _sDiffGfx)592cdf0e10cSrcweir     int identify(String _sDiffGfx)
593cdf0e10cSrcweir         {
594cdf0e10cSrcweir             int nResult = 0;
595cdf0e10cSrcweir             // would like to know what the meaning of %k is for ImageMagick's 'identify'
596cdf0e10cSrcweir             String sIM_Format = "%k";
597cdf0e10cSrcweir             // if (OSHelper.isWindows())
598cdf0e10cSrcweir             // {
599cdf0e10cSrcweir             //     sIM_Format = "%%k";
600cdf0e10cSrcweir             // }
601cdf0e10cSrcweir 
602cdf0e10cSrcweir             String sIdentify = "identify";
603cdf0e10cSrcweir             if (OSHelper.isWindows())
604cdf0e10cSrcweir             {
605cdf0e10cSrcweir                 sIdentify = "identify.exe";
606cdf0e10cSrcweir             }
607cdf0e10cSrcweir 
608cdf0e10cSrcweir             // String sCommand = sIdentify + " " + sIM_Format + " " + StringHelper.doubleQuoteIfNeed(_sDiffGfx);
609cdf0e10cSrcweir 
610cdf0e10cSrcweir             String[] sCommandArray =
611cdf0e10cSrcweir                 {
612cdf0e10cSrcweir                     sIdentify,
613cdf0e10cSrcweir                     "-format",
614cdf0e10cSrcweir                     sIM_Format,
615cdf0e10cSrcweir                     _sDiffGfx
616cdf0e10cSrcweir                 };
617cdf0e10cSrcweir             ProcessHandler aHandler = new ProcessHandler(sCommandArray);
618cdf0e10cSrcweir             boolean bBackValue = aHandler.executeSynchronously();
619cdf0e10cSrcweir             String sBack = aHandler.getOutputText();
620cdf0e10cSrcweir             GlobalLogWriter.get().println("'" + sBack + "'");
621cdf0e10cSrcweir 
622cdf0e10cSrcweir             // try to interpret the result, which we get as a String
623cdf0e10cSrcweir             try
624cdf0e10cSrcweir             {
625cdf0e10cSrcweir                 int nIdx = sBack.indexOf("\n");
626cdf0e10cSrcweir                 if (nIdx > 0)
627cdf0e10cSrcweir                 {
628cdf0e10cSrcweir                     sBack = sBack.substring(0, nIdx);
629cdf0e10cSrcweir                 }
630cdf0e10cSrcweir 
631cdf0e10cSrcweir                 nResult = Integer.valueOf(sBack).intValue();
632cdf0e10cSrcweir             }
633cdf0e10cSrcweir             catch(java.lang.NumberFormatException e)
634cdf0e10cSrcweir             {
635cdf0e10cSrcweir                 GlobalLogWriter.get().println("Number format exception");
636cdf0e10cSrcweir                 nResult = 0;
637cdf0e10cSrcweir             }
638cdf0e10cSrcweir             return nResult;
639cdf0e10cSrcweir         }
640cdf0e10cSrcweir 
641cdf0e10cSrcweir     /*
642cdf0e10cSrcweir      * Check 2 different differ files
643cdf0e10cSrcweir      * return 1 if there is no difference between both diff files.
644cdf0e10cSrcweir      */
645cdf0e10cSrcweir 
646cdf0e10cSrcweir //  TODO: Maybe a StatusHelper is a better return value
checkDiffDiff(String _sOutputPath, String _sSourcePath1, String _sSourceFile1, String _sSourcePath2, String _sSourceFile2)647cdf0e10cSrcweir     public StatusHelper checkDiffDiff(String _sOutputPath, String _sSourcePath1, String _sSourceFile1, String _sSourcePath2, String _sSourceFile2)
648cdf0e10cSrcweir         {
649cdf0e10cSrcweir             String sNewGfx =  _sSourcePath1 + fs + _sSourceFile1;
650cdf0e10cSrcweir             String sOldGfx =  _sSourcePath2 + fs + _sSourceFile2;
651cdf0e10cSrcweir 
652cdf0e10cSrcweir             int nNumber = 1;
653cdf0e10cSrcweir             String sDiffGfx;
654cdf0e10cSrcweir             sDiffGfx = getJPEGName(_sOutputPath, _sSourceFile1 + ".diff", StringHelper.createValueString(nNumber, 4));
655cdf0e10cSrcweir 
656cdf0e10cSrcweir             StatusHelper aCurrentStatus = new StatusHelper(sOldGfx, sNewGfx, sDiffGfx);
657cdf0e10cSrcweir 
658cdf0e10cSrcweir             // String sComposite = "composite";
659cdf0e10cSrcweir             // if (OSHelper.isWindows())
660cdf0e10cSrcweir             // {
661cdf0e10cSrcweir             //     sComposite = "composite.exe";
662cdf0e10cSrcweir             // }
663cdf0e10cSrcweir             //
664cdf0e10cSrcweir             // String sCommand = sComposite  +" -compose difference " +
665cdf0e10cSrcweir             //     StringHelper.doubleQuoteIfNeed(sOldGfx) + " " +
666cdf0e10cSrcweir             //     StringHelper.doubleQuoteIfNeed(sNewGfx) + " " +
667cdf0e10cSrcweir             //     StringHelper.doubleQuoteIfNeed(sDiffGfx);
668cdf0e10cSrcweir             //
669cdf0e10cSrcweir             //
670cdf0e10cSrcweir             // // System.out.println(sCommand);
671cdf0e10cSrcweir             // // executeSynchronously(sCommand);
672cdf0e10cSrcweir             // ProcessHandler aHandler = new ProcessHandler(sCommand);
673cdf0e10cSrcweir             // boolean bBackValue = aHandler.executeSynchronously();
674cdf0e10cSrcweir 
675cdf0e10cSrcweir             compareJPEGs(sOldGfx, sNewGfx, sDiffGfx);
676cdf0e10cSrcweir 
677cdf0e10cSrcweir             if (FileHelper.exists(sDiffGfx))
678cdf0e10cSrcweir             {
679cdf0e10cSrcweir                 int nResult = identify(sDiffGfx);
680cdf0e10cSrcweir                 if (nResult == 1)
681cdf0e10cSrcweir                 {
682cdf0e10cSrcweir                     aCurrentStatus.nDiffStatus = StatusHelper.DIFF_NO_DIFFERENCES;
683cdf0e10cSrcweir                 }
684cdf0e10cSrcweir                 else
685cdf0e10cSrcweir                 {
686cdf0e10cSrcweir                     aCurrentStatus.nDiffStatus = StatusHelper.DIFF_DIFFERENCES_FOUND;
687cdf0e10cSrcweir                     try
688cdf0e10cSrcweir                     {
689cdf0e10cSrcweir                         aCurrentStatus.nPercent = estimateGfx(sOldGfx, sNewGfx, sDiffGfx);
690cdf0e10cSrcweir                     }
691cdf0e10cSrcweir                     catch (java.io.IOException e)
692cdf0e10cSrcweir                     {
693cdf0e10cSrcweir                         GlobalLogWriter.get().println(e.getMessage());
694cdf0e10cSrcweir                         aCurrentStatus.nPercent = -1;
695cdf0e10cSrcweir                     }
696cdf0e10cSrcweir                 }
697cdf0e10cSrcweir                 // LLA: should diffdiff file delete?
698cdf0e10cSrcweir                 // File aFile = new File(sDiffGfx);
699cdf0e10cSrcweir                 // aFile.delete();
700cdf0e10cSrcweir             }
701cdf0e10cSrcweir             else
702cdf0e10cSrcweir             {
703cdf0e10cSrcweir                 GlobalLogWriter.get().println("composite can't create the diffdiff file.");
704cdf0e10cSrcweir             }
705cdf0e10cSrcweir 
706cdf0e10cSrcweir             return aCurrentStatus;
707cdf0e10cSrcweir         }
708cdf0e10cSrcweir 
709cdf0e10cSrcweir     // -----------------------------------------------------------------------------
710cdf0e10cSrcweir     /**
711cdf0e10cSrcweir      * count how much pixel differ and between Old or New and the Difference graphics
712cdf0e10cSrcweir      *
713cdf0e10cSrcweir      * First, count the old graphics, then the new graphics due to the fact both should be equal
714cdf0e10cSrcweir      * it should be legal to take result from old or new. We take the graphics with less values.
715cdf0e10cSrcweir      *
716cdf0e10cSrcweir      * Second, count the difference graphics, now take the percent algorithm and
717cdf0e10cSrcweir      * build a percent value, which contain the number of different pixels as a percent value
718cdf0e10cSrcweir      *
719cdf0e10cSrcweir      * Interpretation:
720cdf0e10cSrcweir      * 0%    there is no difference
721cdf0e10cSrcweir      *
722cdf0e10cSrcweir      * <100% Take a look into the difference graphics, maybe the difference graphics shows
723cdf0e10cSrcweir      *       text like outlined or the text is little bit move left, right up or down.
724cdf0e10cSrcweir      *
725cdf0e10cSrcweir      * >100% Yes it's possible that there is a difference more then 100%, maybe a font problem
726cdf0e10cSrcweir      *       between old and new graphics. The font of the new graphics is little bit bigger,
727cdf0e10cSrcweir      *       so the pixel count between old graphics and new graphics is twice the more.
728cdf0e10cSrcweir      *
729cdf0e10cSrcweir      */
estimateGfx(String _sOldGfx, String _sNewGfx, String _sDiffGfx)730cdf0e10cSrcweir     public int estimateGfx(String _sOldGfx, String _sNewGfx, String _sDiffGfx)
731cdf0e10cSrcweir         throws java.io.IOException
732cdf0e10cSrcweir         {
733cdf0e10cSrcweir             // new count pixels
734cdf0e10cSrcweir             int nNotWhiteCount_OldGraphic = PixelCounter.countNotWhitePixelsFromImage(_sOldGfx);
735cdf0e10cSrcweir             int nNotWhiteCount_NewGraphic = PixelCounter.countNotWhitePixelsFromImage(_sNewGfx);
736cdf0e10cSrcweir             int nNotBlackCount_DiffGraphic = PixelCounter.countNotBlackPixelsFromImage(_sDiffGfx);
737cdf0e10cSrcweir 
738cdf0e10cSrcweir             int nMinNotWhiteCount = Math.min(nNotWhiteCount_NewGraphic, nNotWhiteCount_OldGraphic);
739cdf0e10cSrcweir 
740cdf0e10cSrcweir             // check if not zero
741cdf0e10cSrcweir             if (nMinNotWhiteCount == 0)
742cdf0e10cSrcweir             {
743cdf0e10cSrcweir                 nMinNotWhiteCount = Math.max(nNotWhiteCount_NewGraphic, nNotWhiteCount_OldGraphic);
744cdf0e10cSrcweir                 if (nMinNotWhiteCount == 0)
745cdf0e10cSrcweir                 {
746cdf0e10cSrcweir                     nMinNotWhiteCount = 1;
747cdf0e10cSrcweir                 }
748cdf0e10cSrcweir             }
749cdf0e10cSrcweir 
750cdf0e10cSrcweir             int nPercent = Math.abs(nNotBlackCount_DiffGraphic * 100 / nMinNotWhiteCount);
751cdf0e10cSrcweir             GlobalLogWriter.get().println( "Graphics check, pixel based:" + String.valueOf(nPercent) + "% pixel differ ");
752cdf0e10cSrcweir             return nPercent;
753cdf0e10cSrcweir         }
754cdf0e10cSrcweir 
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 
757cdf0e10cSrcweir /*
758cdf0e10cSrcweir  * Some selftest functionallity
759cdf0e10cSrcweir  */
760cdf0e10cSrcweir //    public static void main(String[] args)
761cdf0e10cSrcweir //        {
762cdf0e10cSrcweir             // System.out.println(FileHelper.getNameNoSuffix("doc.sxw"));
763cdf0e10cSrcweir             // System.out.println(FileHelper.getSuffix("doc.sxw"));
764cdf0e10cSrcweir             // System.out.println(FileHelper.getBasename("doc.sxw"));
765cdf0e10cSrcweir             // System.out.println(FileHelper.getBasename("/tmp/doc.sxw"));
766cdf0e10cSrcweir 
767cdf0e10cSrcweir //            PRNCompare a = new PRNCompare();
768cdf0e10cSrcweir //             a.setInputPath(     "/cws/so-cwsserv06/qadev18/SRC680/src.m47/convwatch.keep/input/msoffice/xp/PowerPoint");
769cdf0e10cSrcweir //             a.setReferencePath( "/cws/so-cwsserv06/qadev18/SRC680/src.m47/convwatch.keep/input/msoffice/xp/PowerPoint");
770cdf0e10cSrcweir //             a.setOutputPath(    "/tmp/convwatch_java");
771cdf0e10cSrcweir //             a.setDocFile(       "1_Gov.ppt");
772cdf0e10cSrcweir //             a.setReferenceFile( "1_Gov.prn" );
773cdf0e10cSrcweir //             a.setPostScriptFile("1_Gov.ps" );
774cdf0e10cSrcweir             // a.compare();
775cdf0e10cSrcweir 
776cdf0e10cSrcweir 
777cdf0e10cSrcweir // LLA: 20040804 sample how to build jpegs from reference files
778cdf0e10cSrcweir //             a.createJPEGFromPostscript("/tmp/convwatch_java",
779cdf0e10cSrcweir //                                        "/home/apitest/WorkFromHome/20040804/reference", "worddoc.prn" );
780cdf0e10cSrcweir //
781cdf0e10cSrcweir //             a.createJPEGFromPostscript("/tmp/convwatch_java",
782cdf0e10cSrcweir //                                        "/home/apitest/WorkFromHome/20040804/reference", "worddoc.ps" );
783cdf0e10cSrcweir 
784cdf0e10cSrcweir //             Status[] aList = a.createDiffs("/tmp/convwatch_java",
785cdf0e10cSrcweir //                                            "/tmp/convwatch_java", "worddoc.prn",
786cdf0e10cSrcweir //                                            "/tmp/convwatch_java", "worddoc.ps",
787cdf0e10cSrcweir //                                            2);
788cdf0e10cSrcweir 
789cdf0e10cSrcweir // LLA: 20040805 sample how to check 2 gfx files
790cdf0e10cSrcweir // this function return DifferenceType.NO_DIFFERENCE if the pictures contain no graphically difference
791cdf0e10cSrcweir //             DifferenceType aReturnValue = a.checkDiffDiff("/tmp/convwatch_java",
792cdf0e10cSrcweir //                                                           "/tmp/convwatch_java", "worddoc.prn.diff1.jpg",
793cdf0e10cSrcweir //                                                           "/tmp/convwatch_java/old", "worddoc.prn.diff1.jpg");
794cdf0e10cSrcweir //             if (aReturnValue.equals( DifferenceType.NO_DIFFERENCE ))
795cdf0e10cSrcweir //             {
796cdf0e10cSrcweir //                 System.out.println("There is no difference between both diff files.");
797cdf0e10cSrcweir //             }
798cdf0e10cSrcweir 
799cdf0e10cSrcweir             // a.setOldDiff(       "/olddiffs");
800cdf0e10cSrcweir //        }
801cdf0e10cSrcweir }
802