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
10cdf0e10cSrcweir  *
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 package graphical;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import helper.OSHelper;
26cdf0e10cSrcweir import helper.ProcessHandler;
27cdf0e10cSrcweir import java.io.File;
28cdf0e10cSrcweir import java.io.IOException;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir /**
31cdf0e10cSrcweir  * Helper class to interpret a jpg filename
32cdf0e10cSrcweir  */
33cdf0e10cSrcweir class NameDPIPage
34cdf0e10cSrcweir {
35cdf0e10cSrcweir 
36cdf0e10cSrcweir     String Name;
37cdf0e10cSrcweir     int DPI;
38cdf0e10cSrcweir     int Page;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir     private NameDPIPage(String _sName, int _nDPI, int _nPage)
41cdf0e10cSrcweir     {
42cdf0e10cSrcweir         Name = _sName;
43cdf0e10cSrcweir         DPI = _nDPI;
44cdf0e10cSrcweir         Page = _nPage;
45cdf0e10cSrcweir     }
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     public static NameDPIPage interpret(String _sFilename)
48cdf0e10cSrcweir     {
49cdf0e10cSrcweir         String sBasename = FileHelper.getBasename(_sFilename);         // if exist a path, remove it
50cdf0e10cSrcweir         String sNameNoSuffix = FileHelper.getNameNoSuffix(sBasename);  // remove extension (.jpg)
51cdf0e10cSrcweir 
52cdf0e10cSrcweir         // check if there exist a 'DPI_' at specific position
53cdf0e10cSrcweir         String sDPICheck = sNameNoSuffix.substring(sNameNoSuffix.length() - 8, sNameNoSuffix.length() - 4);
54cdf0e10cSrcweir         String sName;
55cdf0e10cSrcweir         int nDPI = -1;
56cdf0e10cSrcweir         int nPage = -1;
57cdf0e10cSrcweir         if (sDPICheck.equals("DPI_"))
58cdf0e10cSrcweir         {
59cdf0e10cSrcweir             // seems to be a generated filename by us.
60cdf0e10cSrcweir             int nDPIStart = sNameNoSuffix.lastIndexOf("_", sNameNoSuffix.length() - 8);
61cdf0e10cSrcweir             sName = sNameNoSuffix.substring(0, nDPIStart);
62cdf0e10cSrcweir             if (nDPIStart > 0)
63cdf0e10cSrcweir             {
64cdf0e10cSrcweir                 String sDPI = sNameNoSuffix.substring(nDPIStart + 1, sNameNoSuffix.length() - 8);
65cdf0e10cSrcweir                 try
66cdf0e10cSrcweir                 {
67cdf0e10cSrcweir                     nDPI = Integer.valueOf(sDPI).intValue();
68cdf0e10cSrcweir                 }
69cdf0e10cSrcweir                 catch (java.lang.NumberFormatException e)
70cdf0e10cSrcweir                 {
71cdf0e10cSrcweir                     GlobalLogWriter.println("DPI: Number format exception");
72cdf0e10cSrcweir                 }
73cdf0e10cSrcweir                 String sPage = sNameNoSuffix.substring(sNameNoSuffix.length() - 4);
74cdf0e10cSrcweir                 try
75cdf0e10cSrcweir                 {
76cdf0e10cSrcweir                     nPage = Integer.valueOf(sPage).intValue();
77cdf0e10cSrcweir                 }
78cdf0e10cSrcweir                 catch (java.lang.NumberFormatException e)
79cdf0e10cSrcweir                 {
80cdf0e10cSrcweir                     GlobalLogWriter.println("Page: Number format exception");
81cdf0e10cSrcweir                 }
82cdf0e10cSrcweir             }
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir         else
85cdf0e10cSrcweir         {
86cdf0e10cSrcweir             sName = sNameNoSuffix;
87cdf0e10cSrcweir         }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         return new NameDPIPage(sName, nDPI, nPage);
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir class CountNotXXXPixelsFromImage extends Thread
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     private String m_sFilename;
97cdf0e10cSrcweir     protected int m_nValue;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     CountNotXXXPixelsFromImage(String _sFilename)
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         m_sFilename = _sFilename;
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     public int getValue()
105cdf0e10cSrcweir     {
106cdf0e10cSrcweir         return m_nValue;
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     protected void setValue(int _nValue)
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir         m_nValue = _nValue;
112cdf0e10cSrcweir     }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     protected String getFilename()
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir         return m_sFilename;
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir class CountNotWhitePixelsFromImage extends CountNotXXXPixelsFromImage
121cdf0e10cSrcweir {
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     CountNotWhitePixelsFromImage(String _sFilename)
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir         super(_sFilename);
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     public void run()
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         try
131cdf0e10cSrcweir         {
132cdf0e10cSrcweir             final int nNotWhiteCount = PixelCounter.countNotWhitePixelsFromImage(getFilename());
133cdf0e10cSrcweir             setValue(nNotWhiteCount);
134cdf0e10cSrcweir         }
135cdf0e10cSrcweir         catch (java.io.IOException e)
136cdf0e10cSrcweir         {
137cdf0e10cSrcweir             m_nValue = -1;
138cdf0e10cSrcweir         }
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir class CountNotBlackPixelsFromImage extends CountNotXXXPixelsFromImage
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     CountNotBlackPixelsFromImage(String _sFilename)
146cdf0e10cSrcweir     {
147cdf0e10cSrcweir         super(_sFilename);
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     public void run()
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         try
153cdf0e10cSrcweir         {
154cdf0e10cSrcweir             final int nNotBlackCount = PixelCounter.countNotBlackPixelsFromImage(getFilename());
155cdf0e10cSrcweir             setValue(nNotBlackCount);
156cdf0e10cSrcweir         }
157cdf0e10cSrcweir         catch (java.io.IOException e)
158cdf0e10cSrcweir         {
159cdf0e10cSrcweir             m_nValue = -1;
160cdf0e10cSrcweir         }
161cdf0e10cSrcweir     }
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir /**
165cdf0e10cSrcweir  *
166cdf0e10cSrcweir  * @author ll93751
167cdf0e10cSrcweir  */
168cdf0e10cSrcweir public class JPEGComparator extends EnhancedComplexTestCase
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     // @Override
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     public String[] getTestMethodNames()
173cdf0e10cSrcweir     {
174cdf0e10cSrcweir         return new String[]{"CompareJPEGvsJPEG"};
175cdf0e10cSrcweir     }
176cdf0e10cSrcweir     private Tolerance m_aTolerance;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     /**
179cdf0e10cSrcweir      * test function.
180cdf0e10cSrcweir      */
181cdf0e10cSrcweir     public void CompareJPEGvsJPEG()
182cdf0e10cSrcweir     {
183cdf0e10cSrcweir         GlobalLogWriter.set(log);
184cdf0e10cSrcweir         ParameterHelper aParam = new ParameterHelper(param);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         // run through all documents found in Inputpath
187cdf0e10cSrcweir         foreachJPEGcompareWithJPEG(aParam);
188cdf0e10cSrcweir     }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     public void checkOneFile(String _sDocumentName, String _sResult, ParameterHelper _aParams) throws OfficeException
191cdf0e10cSrcweir     {
192cdf0e10cSrcweir         // private void callEveryPictureInIniFile(IniFile _aIniFile, String _sSectionName, ParameterHelper _aParam)
193cdf0e10cSrcweir         // {
194cdf0e10cSrcweir         String sPath = FileHelper.getPath(_sDocumentName);
195cdf0e10cSrcweir         String sSectionName = FileHelper.getBasename(_sDocumentName);
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         // take the build id out of the ini file in the reference file and put it into the current parameter helper
198cdf0e10cSrcweir         String sIniFileForRefBuildID = FileHelper.appendPath(sPath, sSectionName + ".ini");
199cdf0e10cSrcweir         IniFile aIniFileForRefBuildID = new IniFile(sIniFileForRefBuildID);
200cdf0e10cSrcweir         String sRefBuildID = aIniFileForRefBuildID.getValue("global", "buildid");
201cdf0e10cSrcweir         aIniFileForRefBuildID.close();
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         _aParams.getTestParameters().put("RefBuildId", sRefBuildID);
204cdf0e10cSrcweir 
205cdf0e10cSrcweir         String sIniFile = FileHelper.appendPath(sPath, "index.ini");
206cdf0e10cSrcweir         IniFile aIniFile = new IniFile(sIniFile);
207cdf0e10cSrcweir         if (aIniFile.hasValue(sSectionName, "pages"))
208cdf0e10cSrcweir         {
209cdf0e10cSrcweir             // only which has 'pages' has also pictures
210cdf0e10cSrcweir             int nPages = aIniFile.getIntValue(sSectionName, "pages", 0);
211cdf0e10cSrcweir             String sJPEGSchema = aIniFile.getValue(sSectionName, "jpegschema");
212cdf0e10cSrcweir             int nTolerance = aIniFile.getIntValue(sSectionName, "tolerance", 0);
213cdf0e10cSrcweir             m_aTolerance = new Tolerance(nTolerance);
214cdf0e10cSrcweir             for (int i = 1; i <= nPages; i++)
215cdf0e10cSrcweir             {
216cdf0e10cSrcweir                 String sJPEGFilename = JPEGCreator.getFilenameForJPEGSchema(sJPEGSchema, i);
217cdf0e10cSrcweir                 // String sPath = FileHelper.getPath(_aParam.getInputPath());
218cdf0e10cSrcweir                 String sJPEGPath = FileHelper.getPath(sJPEGFilename);
219cdf0e10cSrcweir                 if (!sPath.equals(sJPEGPath))
220cdf0e10cSrcweir                 {
221cdf0e10cSrcweir                     GlobalLogWriter.println("Path where to find the index and where to file the JPEG pictures are not the same.");
222cdf0e10cSrcweir 
223cdf0e10cSrcweir                 }
224cdf0e10cSrcweir                 // String sEntry = FileHelper.appendPath(sPath, sSection);
225cdf0e10cSrcweir                 File aFile = new File(sJPEGFilename);
226cdf0e10cSrcweir                 assure("File '" + sJPEGFilename + "' doesn't exists.", aFile.exists(), true);
227cdf0e10cSrcweir                 if (aFile.exists())
228cdf0e10cSrcweir                 {
229cdf0e10cSrcweir                     GlobalLogWriter.println("Page: " + i);
230cdf0e10cSrcweir                     checkOnePicture(sJPEGFilename, _sResult, _aParams);
231cdf0e10cSrcweir                 }
232cdf0e10cSrcweir             }
233cdf0e10cSrcweir         }
234cdf0e10cSrcweir         else
235cdf0e10cSrcweir         {
236cdf0e10cSrcweir             GlobalLogWriter.println("The document '" + sSectionName + "' seems to have no picture representation.");
237cdf0e10cSrcweir         }
238cdf0e10cSrcweir 
239cdf0e10cSrcweir         String sResultIniFile = FileHelper.appendPath(_sResult, sSectionName);
240cdf0e10cSrcweir         evaluateResult(sResultIniFile, _aParams);
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     private void evaluateResult(String _sDocument, ParameterHelper _aParams)
244cdf0e10cSrcweir     {
245cdf0e10cSrcweir         String sResultIniFile = _sDocument + ".ini";
246cdf0e10cSrcweir         File aFile = new File(sResultIniFile);
247cdf0e10cSrcweir         assure("Result file doesn't exists " + sResultIniFile, aFile.exists());
248cdf0e10cSrcweir 
249cdf0e10cSrcweir         int good = 0;
250cdf0e10cSrcweir         int bad = 0;
251cdf0e10cSrcweir         int ugly = 0;
252cdf0e10cSrcweir         int ok_status = 1; // 1=ok 2=bad 3=ugly
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         IniFile aResultIniFile = new IniFile(sResultIniFile);
255cdf0e10cSrcweir         int nPages = aResultIniFile.getIntValue("global", "pages", 0);
256cdf0e10cSrcweir         for (int i = 0; i < nPages; i++)
257cdf0e10cSrcweir         {
258cdf0e10cSrcweir             String sCurrentPage = "page" + String.valueOf(i + 1);
259cdf0e10cSrcweir             int nPercent = aResultIniFile.getIntValue(sCurrentPage, "percent", -1);
260cdf0e10cSrcweir             if (nPercent == 0)
261cdf0e10cSrcweir             {
262cdf0e10cSrcweir                 good++;
263cdf0e10cSrcweir             }
264cdf0e10cSrcweir             else if (nPercent <= 5)
265cdf0e10cSrcweir             {
266cdf0e10cSrcweir                 bad++;
267cdf0e10cSrcweir                 ok_status = 2;
268cdf0e10cSrcweir             }
269cdf0e10cSrcweir             else
270cdf0e10cSrcweir             {
271cdf0e10cSrcweir                 ugly++;
272cdf0e10cSrcweir                 ok_status = 3;
273cdf0e10cSrcweir             }
274cdf0e10cSrcweir         }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir         assure("Error: document doesn't contains pages", nPages > 0);
277cdf0e10cSrcweir 
278cdf0e10cSrcweir // TODO: this information has to come out of the ini files
279cdf0e10cSrcweir         String sStatusRunThrough = "PASSED, ";
280cdf0e10cSrcweir         String sPassed = "OK";
281cdf0e10cSrcweir 
282cdf0e10cSrcweir         String sStatusMessage = "From " + nPages + " page(s) are: ";
283cdf0e10cSrcweir         String sGood = "";
284cdf0e10cSrcweir         String sBad = "";
285cdf0e10cSrcweir         String sUgly = "";
286cdf0e10cSrcweir 
287cdf0e10cSrcweir         if (good > 0)
288cdf0e10cSrcweir         {
289cdf0e10cSrcweir             sGood = " good:=" + good;
290cdf0e10cSrcweir             sStatusMessage += sGood;
291cdf0e10cSrcweir         }
292cdf0e10cSrcweir         if (bad > 0)
293cdf0e10cSrcweir         {
294cdf0e10cSrcweir             sBad = " bad:=" + bad;
295cdf0e10cSrcweir             sStatusMessage += sBad;
296cdf0e10cSrcweir         }
297cdf0e10cSrcweir         if (ugly > 0)
298cdf0e10cSrcweir         {
299cdf0e10cSrcweir             sUgly = " ugly:=" + ugly;
300cdf0e10cSrcweir             sStatusMessage += sUgly;
301cdf0e10cSrcweir         }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir         // Failure matrix
304cdf0e10cSrcweir         //         0     1
305cdf0e10cSrcweir         // ugly    OK    FAILED
306cdf0e10cSrcweir         // bad     OK
307cdf0e10cSrcweir         // good    OK
308cdf0e10cSrcweir 
309cdf0e10cSrcweir         if (ugly > 0)
310cdf0e10cSrcweir         {
311cdf0e10cSrcweir             sPassed = "FAILED";
312cdf0e10cSrcweir         }
313cdf0e10cSrcweir         else
314cdf0e10cSrcweir         {
315cdf0e10cSrcweir             if (bad > 0)
316cdf0e10cSrcweir             {
317cdf0e10cSrcweir                 sPassed = "NEED A LOOK";
318cdf0e10cSrcweir             }
319cdf0e10cSrcweir             else
320cdf0e10cSrcweir             {
321cdf0e10cSrcweir                 sPassed = "OK";
322cdf0e10cSrcweir             }
323cdf0e10cSrcweir         }
324cdf0e10cSrcweir         sStatusRunThrough += sPassed;
325cdf0e10cSrcweir         aResultIniFile.insertValue("global", "state", sStatusRunThrough);
326cdf0e10cSrcweir         aResultIniFile.insertValue("global", "info", sStatusMessage);
327cdf0e10cSrcweir         aResultIniFile.close();
328cdf0e10cSrcweir 
329cdf0e10cSrcweir         _aParams.getTestParameters().put("current_state", sStatusRunThrough);
330cdf0e10cSrcweir         _aParams.getTestParameters().put("current_info", sStatusMessage);
331cdf0e10cSrcweir         _aParams.getTestParameters().put("current_ok_status", ok_status);
332cdf0e10cSrcweir 
333cdf0e10cSrcweir         // if we have a ugly page, we must return this as a FAILED STATUS in Log file!
334cdf0e10cSrcweir         assure("There exist pages marked as ugly.", ugly == 0);
335cdf0e10cSrcweir     }
336cdf0e10cSrcweir 
337cdf0e10cSrcweir     private void checkOnePicture(String _sDocumentName, String _sResult, ParameterHelper _aParams)
338cdf0e10cSrcweir     {
339cdf0e10cSrcweir         GlobalLogWriter.println("JPEG: Compare difference between '" + _sDocumentName + "'  and '" + _sResult + "'");
340cdf0e10cSrcweir         File aResultFile = new File(_sResult);
341cdf0e10cSrcweir         if (aResultFile.isDirectory())
342cdf0e10cSrcweir         {
343cdf0e10cSrcweir             // result is just a directory, so we search for the basename of the source and take this.
344cdf0e10cSrcweir             String sBasename = FileHelper.getBasename(_sDocumentName);
345cdf0e10cSrcweir             String sResultFilename = FileHelper.appendPath(_sResult, sBasename);
346cdf0e10cSrcweir             aResultFile = new File(sResultFilename);
347cdf0e10cSrcweir             if (aResultFile.exists())
348cdf0e10cSrcweir             {
349cdf0e10cSrcweir                 // Original and Result exists
350cdf0e10cSrcweir                 String sInputPath = _aParams.getInputPath();
351cdf0e10cSrcweir                 if (sInputPath.toLowerCase().endsWith("index.ini"))
352cdf0e10cSrcweir                 {
353cdf0e10cSrcweir                     // special case
354cdf0e10cSrcweir                     // we want to get the buildid from the info file.
355cdf0e10cSrcweir                 }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir                 compareJPEG(_sDocumentName, sResultFilename, _aParams);
358cdf0e10cSrcweir 
359cdf0e10cSrcweir             }
360cdf0e10cSrcweir             else
361cdf0e10cSrcweir             {
362cdf0e10cSrcweir                 String sResultFilenamePDF = util.utils.replaceAll13(sResultFilename, ".ps_", ".pdf_");
363cdf0e10cSrcweir                 File aResultPDFFile = new File(sResultFilenamePDF);
364cdf0e10cSrcweir                 if (aResultPDFFile.exists())
365cdf0e10cSrcweir                 {
366cdf0e10cSrcweir                     // Original and Result exists
367cdf0e10cSrcweir                     String sInputPath = _aParams.getInputPath();
368cdf0e10cSrcweir                     if (sInputPath.toLowerCase().endsWith("index.ini"))
369cdf0e10cSrcweir                     {
370cdf0e10cSrcweir                         // special case
371cdf0e10cSrcweir                         // we want to get the buildid from the info file.
372cdf0e10cSrcweir                     }
373cdf0e10cSrcweir 
374cdf0e10cSrcweir                     compareJPEG(_sDocumentName, sResultFilenamePDF, _aParams);
375cdf0e10cSrcweir                 }
376cdf0e10cSrcweir                 else
377cdf0e10cSrcweir                 {
378cdf0e10cSrcweir                     GlobalLogWriter.println("Warning: Result JPEG doesn't exists '" + sResultFilename + "'");
379cdf0e10cSrcweir                 }
380cdf0e10cSrcweir             }
381cdf0e10cSrcweir         }
382cdf0e10cSrcweir         else
383cdf0e10cSrcweir         {
384cdf0e10cSrcweir             // result is also a file
385cdf0e10cSrcweir             if (aResultFile.exists())
386cdf0e10cSrcweir             {
387cdf0e10cSrcweir                 compareJPEG(_sDocumentName, _sResult, _aParams);
388cdf0e10cSrcweir             }
389cdf0e10cSrcweir             else
390cdf0e10cSrcweir             {
391cdf0e10cSrcweir                 GlobalLogWriter.println("Warning: Result JPEG doesn't exists '" + _sResult + "'");
392cdf0e10cSrcweir             }
393cdf0e10cSrcweir         }
394cdf0e10cSrcweir     }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir     /**
397cdf0e10cSrcweir      * compare 2 JPEGs, it is a need, that both _sDocumentName and _sResultFilename exist.
398cdf0e10cSrcweir      * @param _sDocumentName
399cdf0e10cSrcweir      * @param _sResult
400cdf0e10cSrcweir      * @param _aParams
401cdf0e10cSrcweir      * @return 0=no difference !=0 both files differ
402cdf0e10cSrcweir      */
403cdf0e10cSrcweir     private void compareJPEG(String _sDocumentName, String _sResult, ParameterHelper _aParams)
404cdf0e10cSrcweir     {
405cdf0e10cSrcweir         NameDPIPage aNameDPIPage = NameDPIPage.interpret(_sDocumentName);
406cdf0e10cSrcweir 
407cdf0e10cSrcweir         String sSourceBasename = FileHelper.getBasename(_sDocumentName);
408cdf0e10cSrcweir         String sSourcePath = FileHelper.getPath(_sDocumentName);
409cdf0e10cSrcweir         String sDestinationBasename = FileHelper.getBasename(_sResult);
410cdf0e10cSrcweir         String sDestinationPath = FileHelper.getPath(_sResult);
411cdf0e10cSrcweir 
412cdf0e10cSrcweir         if (!sSourcePath.equals(sDestinationPath))
413cdf0e10cSrcweir         {
414cdf0e10cSrcweir             // we want to have all in one Directory, Original, Reference and the Difference result.
415cdf0e10cSrcweir             // copy the original file to the reference path
416cdf0e10cSrcweir             String sNewSourceBasename = "Original_" + sSourceBasename;
417cdf0e10cSrcweir             // String sSource = FileHelper.appendPath(sSourcePath, sSourceBasename);
418cdf0e10cSrcweir             String sSource = _sDocumentName;
419cdf0e10cSrcweir             String sDestination = FileHelper.appendPath(sDestinationPath, sNewSourceBasename);
420cdf0e10cSrcweir             FileHelper.copy(sSource, sDestination);
421cdf0e10cSrcweir             sSourceBasename = sNewSourceBasename;
422cdf0e10cSrcweir             //
423cdf0e10cSrcweir             JPEGCreator.convertToNearSameFileWithWidth340(sDestination);
424cdf0e10cSrcweir         }
425cdf0e10cSrcweir         String sDifferenceBasename = "Difference_between_" + FileHelper.getNameNoSuffix(sSourceBasename) + "_and_" + FileHelper.getNameNoSuffix(sDestinationBasename) + ".jpg";
426cdf0e10cSrcweir         // String sDifferencePath = sDestinationPath;
427cdf0e10cSrcweir 
428cdf0e10cSrcweir         String sSource = FileHelper.appendPath(sDestinationPath, sSourceBasename);
429cdf0e10cSrcweir         String sDestination = FileHelper.appendPath(sDestinationPath, sDestinationBasename);
430cdf0e10cSrcweir         String sDifference = FileHelper.appendPath(sDestinationPath, sDifferenceBasename);
431cdf0e10cSrcweir         int nErr = compareJPEG(sSource, sDestination, sDifference);
432cdf0e10cSrcweir         if (nErr == 0 && FileHelper.exists(sDifference))
433cdf0e10cSrcweir         {
434cdf0e10cSrcweir             // check the difference, returns the count of different colors
435cdf0e10cSrcweir             // this means, 1=only one color, no differences found.
436cdf0e10cSrcweir             int nResult = identify(sDifference);
437cdf0e10cSrcweir             int nPercentColorDiffer = 0;
438cdf0e10cSrcweir 
439cdf0e10cSrcweir             String sResult = "YES";
440cdf0e10cSrcweir 
441cdf0e10cSrcweir             if (m_aTolerance != null)
442cdf0e10cSrcweir             {
443cdf0e10cSrcweir                 final int nAcceptedTolerance = m_aTolerance.getAccept();
444cdf0e10cSrcweir                 if (nResult <= nAcceptedTolerance)
445cdf0e10cSrcweir                 {
446cdf0e10cSrcweir                     nResult = 1;
447cdf0e10cSrcweir                     sResult = "IN TOLERANCE";
448cdf0e10cSrcweir                     GlobalLogWriter.println("The differences are in tolerance.");
449cdf0e10cSrcweir 
450cdf0e10cSrcweir                 }
451cdf0e10cSrcweir             }
452cdf0e10cSrcweir             if (nResult != 1)
453cdf0e10cSrcweir             {
454cdf0e10cSrcweir                 sResult = "NO";
455cdf0e10cSrcweir                 try
456cdf0e10cSrcweir                 {
457cdf0e10cSrcweir                     nPercentColorDiffer = estimateGfx(sSource, sDestination, sDifference);
458cdf0e10cSrcweir                 }
459cdf0e10cSrcweir                 catch (java.io.IOException e)
460cdf0e10cSrcweir                 {
461cdf0e10cSrcweir                     GlobalLogWriter.println("Can't estimate the different colors. " + e.getMessage());
462cdf0e10cSrcweir                 }
463cdf0e10cSrcweir             }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir             // store the result in a result.ini file
466cdf0e10cSrcweir             String sResultFile = FileHelper.appendPath(sDestinationPath, aNameDPIPage.Name + ".ini");
467cdf0e10cSrcweir             int nPage = aNameDPIPage.Page;
468cdf0e10cSrcweir             if (nPage < 0)
469cdf0e10cSrcweir             {
470cdf0e10cSrcweir                 nPage = 0;
471cdf0e10cSrcweir             }
472cdf0e10cSrcweir             IniFile aResultIni = new IniFile(sResultFile);
473cdf0e10cSrcweir 
474cdf0e10cSrcweir             String[] aComment =
475cdf0e10cSrcweir             {
476cdf0e10cSrcweir                 "; This file is automatically created by a graphical.JPEGComparator run",
477cdf0e10cSrcweir                 "; ",
478cdf0e10cSrcweir                 "; If you see this file in a browser you may have forgotten to set the follows in the property file",
479cdf0e10cSrcweir                 "; " + PropertyName.DOC_COMPARATOR_HTML_OUTPUT_PREFIX + "=http://<computer>/gfxcmp_ui/cw.php?inifile=",
480cdf0e10cSrcweir                 "; Please check the documentation if you got confused.",
481cdf0e10cSrcweir                 "; ",
482cdf0e10cSrcweir                 "; "
483cdf0e10cSrcweir             };
484cdf0e10cSrcweir             aResultIni.insertFirstComment(aComment);
485cdf0e10cSrcweir 
486cdf0e10cSrcweir             // write down the global flags
487cdf0e10cSrcweir             int nMaxPage = Math.max(nPage, aResultIni.getIntValue("global", "pages", 0));
488cdf0e10cSrcweir             aResultIni.insertValue("global", "pages", nMaxPage);
489cdf0e10cSrcweir 
490cdf0e10cSrcweir             // INIoutput.writeValue("buildid", _sBuildID);
491cdf0e10cSrcweir             // INIoutput.writeValue("refbuildid", _sRefBuildID);
492cdf0e10cSrcweir             String sRefBuildId = (String) _aParams.getTestParameters().get("RefBuildId");
493cdf0e10cSrcweir             if (sRefBuildId == null)
494cdf0e10cSrcweir             {
495cdf0e10cSrcweir                 sRefBuildId = "";
496cdf0e10cSrcweir             }
497cdf0e10cSrcweir             aResultIni.insertValue("global", "refbuildid", sRefBuildId);
498cdf0e10cSrcweir 
499cdf0e10cSrcweir             aResultIni.insertValue("global", "diffdiff", "no");
500cdf0e10cSrcweir             aResultIni.insertValue("global", "basename", aNameDPIPage.Name);
501cdf0e10cSrcweir             aResultIni.insertValue("global", "dpi", aNameDPIPage.DPI);
502cdf0e10cSrcweir 
503cdf0e10cSrcweir             // write down flags for each page
504cdf0e10cSrcweir             String sSection = "page" + String.valueOf(nPage);
505cdf0e10cSrcweir 
506cdf0e10cSrcweir             aResultIni.insertValue(sSection, "oldgfx", sSource);
507cdf0e10cSrcweir             aResultIni.insertValue(sSection, "newgfx", sDestination);
508cdf0e10cSrcweir             aResultIni.insertValue(sSection, "diffgfx", sDifference);
509cdf0e10cSrcweir             aResultIni.insertValue(sSection, "percent", nPercentColorDiffer);
510cdf0e10cSrcweir             aResultIni.insertValue(sSection, "BM", "false");
511cdf0e10cSrcweir             aResultIni.insertValue(sSection, "result", sResult);
512cdf0e10cSrcweir 
513cdf0e10cSrcweir             aResultIni.close();
514cdf0e10cSrcweir         }
515cdf0e10cSrcweir     }
516cdf0e10cSrcweir 
517cdf0e10cSrcweir //    // This creates a status for exact on document
518cdf0e10cSrcweir //    static boolean createINIStatus(StatusHelper[] aList, String _sFilenamePrefix, String _sOutputPath, String _sAbsoluteInputFile, String _sBuildID, String _sRefBuildID)
519cdf0e10cSrcweir //        {
520cdf0e10cSrcweir //            // Status
521cdf0e10cSrcweir //            String fs = System.getProperty("file.separator");
522cdf0e10cSrcweir //            String sBasename = FileHelper.getBasename(_sAbsoluteInputFile);
523cdf0e10cSrcweir //            String sNameNoSuffix = FileHelper.getNameNoSuffix(sBasename);
524cdf0e10cSrcweir ////            String sHTMLFile = _sFilenamePrefix + sNameNoSuffix + ".html";
525cdf0e10cSrcweir ////            HTMLOutputter HTMLoutput = HTMLOutputter.create(_sOutputPath, sHTMLFile, "", "");
526cdf0e10cSrcweir ////            HTMLoutput.header(sNameNoSuffix);
527cdf0e10cSrcweir ////  TODO: version info was fine
528cdf0e10cSrcweir ////            HTMLoutput.checkSection(sBasename);
529cdf0e10cSrcweir //            // Status end
530cdf0e10cSrcweir //
531cdf0e10cSrcweir //            String sINIFile = _sFilenamePrefix + sNameNoSuffix + ".ini";
532cdf0e10cSrcweir //            INIOutputter INIoutput = INIOutputter.create(_sOutputPath, sINIFile, "", "");
533cdf0e10cSrcweir //            INIoutput.createHeader();
534cdf0e10cSrcweir ////  TODO: version info was fine
535cdf0e10cSrcweir //
536cdf0e10cSrcweir //            INIoutput.writeSection("global");
537cdf0e10cSrcweir //            INIoutput.writeValue("pages", String.valueOf(aList.length));
538cdf0e10cSrcweir //            INIoutput.writeValue("buildid", _sBuildID);
539cdf0e10cSrcweir //            INIoutput.writeValue("refbuildid", _sRefBuildID);
540cdf0e10cSrcweir //            INIoutput.writeValue("diffdiff", "no");
541cdf0e10cSrcweir //            INIoutput.writeValue("basename", sBasename);
542cdf0e10cSrcweir //
543cdf0e10cSrcweir //            boolean bResultIsOk = true;          // result over all pages
544cdf0e10cSrcweir //            for (int i=0;i<aList.length; i++)
545cdf0e10cSrcweir //            {
546cdf0e10cSrcweir //                INIoutput.writeSection("page" + String.valueOf(i + 1));   // list start at point 0, but this is page 1 and so on... current_page = (i + 1)
547cdf0e10cSrcweir //                aList[i].printStatus();
548cdf0e10cSrcweir //
549cdf0e10cSrcweir //                boolean bCurrentResult = true;   // result over exact one page
550cdf0e10cSrcweir //
551cdf0e10cSrcweir //                int nCurrentDiffStatus = aList[i].nDiffStatus;
552cdf0e10cSrcweir //
553cdf0e10cSrcweir //                // check if the status is in a defined range
554cdf0e10cSrcweir //                if (nCurrentDiffStatus == StatusHelper.DIFF_NO_DIFFERENCES)
555cdf0e10cSrcweir //                {
556cdf0e10cSrcweir //                    // ok.
557cdf0e10cSrcweir //                }
558cdf0e10cSrcweir //                else if (nCurrentDiffStatus == StatusHelper.DIFF_DIFFERENCES_FOUND && aList[i].nPercent < 5)
559cdf0e10cSrcweir //                {
560cdf0e10cSrcweir //                    // ok.
561cdf0e10cSrcweir //                }
562cdf0e10cSrcweir //                else if (nCurrentDiffStatus == StatusHelper.DIFF_AFTER_MOVE_DONE_NO_PROBLEMS)
563cdf0e10cSrcweir //                {
564cdf0e10cSrcweir //                    // ok.
565cdf0e10cSrcweir //                }
566cdf0e10cSrcweir //                else if (nCurrentDiffStatus == StatusHelper.DIFF_AFTER_MOVE_DONE_DIFFERENCES_FOUND && aList[i].nPercent2 < 5)
567cdf0e10cSrcweir //                {
568cdf0e10cSrcweir //                    // ok.
569cdf0e10cSrcweir //                }
570cdf0e10cSrcweir //                else
571cdf0e10cSrcweir //                {
572cdf0e10cSrcweir //                    // failed.
573cdf0e10cSrcweir //                    bCurrentResult = false; // logic: nDiff==0 = true if there is no difference
574cdf0e10cSrcweir //                }
575cdf0e10cSrcweir //
576cdf0e10cSrcweir //                // Status
577cdf0e10cSrcweir ////                HTMLoutput.checkLine(aList[i], bCurrentResult);
578cdf0e10cSrcweir //                INIoutput.checkLine(aList[i], bCurrentResult);
579cdf0e10cSrcweir //                bResultIsOk &= bCurrentResult;
580cdf0e10cSrcweir //            }
581cdf0e10cSrcweir //            // Status
582cdf0e10cSrcweir ////            HTMLoutput.close();
583cdf0e10cSrcweir //            INIoutput.close();
584cdf0e10cSrcweir //            return bResultIsOk;
585cdf0e10cSrcweir //        }
586cdf0e10cSrcweir     /**
587cdf0e10cSrcweir      * count how much pixel differ and between Old or New and the Difference graphics
588cdf0e10cSrcweir      *
589cdf0e10cSrcweir      * First, count the old graphics, then the new graphics due to the fact both should be equal
590cdf0e10cSrcweir      * it should be legal to take result from old or new. We take the graphics with less values.
591cdf0e10cSrcweir      *
592cdf0e10cSrcweir      * Second, count the difference graphics, now take the percent algorithm and
593cdf0e10cSrcweir      * build a percent value, which contain the number of different pixels as a percent value
594cdf0e10cSrcweir      *
595cdf0e10cSrcweir      * Interpretation:
596cdf0e10cSrcweir      * 0%    there is no difference
597cdf0e10cSrcweir      *
598cdf0e10cSrcweir      * &lt;100% Take a look into the difference graphics, maybe the difference graphics shows
599cdf0e10cSrcweir      *       text like outlined or the text is little bit move left, right up or down.
600cdf0e10cSrcweir      *
601cdf0e10cSrcweir      * &gt;>100% Yes it's possible that there is a difference more then 100%, maybe a font problem
602cdf0e10cSrcweir      *       between old and new graphics. The font of the new graphics is little bit bigger,
603cdf0e10cSrcweir      *       so the pixel count between old graphics and new graphics is twice the more.
604cdf0e10cSrcweir      *
605cdf0e10cSrcweir      * @param _sOldGfx path & name to the jpeg file (1)
606cdf0e10cSrcweir      * @param _sNewGfx path & name to the other jpeg file (2)
607cdf0e10cSrcweir      * @param _sDiffGfx path & name to the new difference file which shows the difference between (1) and (2)
608cdf0e10cSrcweir      * @return the count of different pixels
609cdf0e10cSrcweir      * @throws java.io.IOException if file access is not possible
610cdf0e10cSrcweir      */
611cdf0e10cSrcweir     public static int estimateGfx(String _sOldGfx, String _sNewGfx, String _sDiffGfx)
612cdf0e10cSrcweir             throws java.io.IOException
613cdf0e10cSrcweir     {
614cdf0e10cSrcweir         TimeHelper a = new TimeHelper();
615cdf0e10cSrcweir         a.start();
616cdf0e10cSrcweir         // Count Pixels
617cdf0e10cSrcweir         final int nNotWhiteCount_OldGraphic = PixelCounter.countNotWhitePixelsFromImage(_sOldGfx);
618cdf0e10cSrcweir         final int nNotWhiteCount_NewGraphic = PixelCounter.countNotWhitePixelsFromImage(_sNewGfx);
619cdf0e10cSrcweir         final int nNotBlackCount_DiffGraphic = PixelCounter.countNotBlackPixelsFromImage(_sDiffGfx);
620cdf0e10cSrcweir 
621cdf0e10cSrcweir         // Count Pixels in different threads
622cdf0e10cSrcweir //        CountNotWhitePixelsFromImage t1 = new CountNotWhitePixelsFromImage(_sOldGfx);
623cdf0e10cSrcweir //        CountNotWhitePixelsFromImage t2 = new CountNotWhitePixelsFromImage(_sNewGfx);
624cdf0e10cSrcweir //        CountNotBlackPixelsFromImage t3 = new CountNotBlackPixelsFromImage(_sDiffGfx);
625cdf0e10cSrcweir //        t1.start();
626cdf0e10cSrcweir //        t2.start();
627cdf0e10cSrcweir //        t3.start();
628cdf0e10cSrcweir //        try
629cdf0e10cSrcweir //        {
630cdf0e10cSrcweir //            t1.join();
631cdf0e10cSrcweir //        }
632cdf0e10cSrcweir //        catch (InterruptedException ex)
633cdf0e10cSrcweir //        {
634cdf0e10cSrcweir //            GlobalLogWriter.get().println("Thread 1 failed: " + ex.getMessage());
635cdf0e10cSrcweir //        }
636cdf0e10cSrcweir //        try
637cdf0e10cSrcweir //        {
638cdf0e10cSrcweir //            t2.join();
639cdf0e10cSrcweir //        }
640cdf0e10cSrcweir //        catch (InterruptedException ex)
641cdf0e10cSrcweir //        {
642cdf0e10cSrcweir //            GlobalLogWriter.get().println("Thread 2 failed: " + ex.getMessage());
643cdf0e10cSrcweir //        }
644cdf0e10cSrcweir //        try
645cdf0e10cSrcweir //        {
646cdf0e10cSrcweir //            t3.join();
647cdf0e10cSrcweir //        }
648cdf0e10cSrcweir //        catch (InterruptedException ex)
649cdf0e10cSrcweir //        {
650cdf0e10cSrcweir //            GlobalLogWriter.get().println("Thread 3 failed: " + ex.getMessage());
651cdf0e10cSrcweir //        }
652cdf0e10cSrcweir //        final int nNotWhiteCount_OldGraphic = t1.getValue();
653cdf0e10cSrcweir //        final int nNotWhiteCount_NewGraphic = t2.getValue();
654cdf0e10cSrcweir //        final int nNotBlackCount_DiffGraphic = t3.getValue();
655cdf0e10cSrcweir 
656cdf0e10cSrcweir         a.stop();
657cdf0e10cSrcweir         GlobalLogWriter.println("Thread Time is: " + a.getTime());
658cdf0e10cSrcweir 
659cdf0e10cSrcweir         int nMinNotWhiteCount = Math.min(nNotWhiteCount_NewGraphic, nNotWhiteCount_OldGraphic);
660cdf0e10cSrcweir 
661cdf0e10cSrcweir         // check if not zero
662cdf0e10cSrcweir         if (nMinNotWhiteCount == 0)
663cdf0e10cSrcweir         {
664cdf0e10cSrcweir             nMinNotWhiteCount = Math.max(nNotWhiteCount_NewGraphic, nNotWhiteCount_OldGraphic);
665cdf0e10cSrcweir             if (nMinNotWhiteCount == 0)
666cdf0e10cSrcweir             {
667cdf0e10cSrcweir                 nMinNotWhiteCount = 1;
668cdf0e10cSrcweir             }
669cdf0e10cSrcweir         }
670cdf0e10cSrcweir 
671cdf0e10cSrcweir         int nPercent = Math.abs(nNotBlackCount_DiffGraphic * 100 / nMinNotWhiteCount);
672cdf0e10cSrcweir         GlobalLogWriter.println("Graphics check, pixel based:" + String.valueOf(nPercent) + "% pixel differ ");
673cdf0e10cSrcweir         return nPercent;
674cdf0e10cSrcweir     }
675cdf0e10cSrcweir 
676cdf0e10cSrcweir     private static int compareJPEG(String _sOldGfx, String _sNewGfx, String _sDiffGfx)
677cdf0e10cSrcweir     {
678cdf0e10cSrcweir         String sComposite = "composite";
679cdf0e10cSrcweir         if (OSHelper.isWindows())
680cdf0e10cSrcweir         {
681cdf0e10cSrcweir             sComposite = "composite.exe";
682cdf0e10cSrcweir             String sIMPath = (String) param.get("imagemagick.path");
683cdf0e10cSrcweir             if (sIMPath != null)
684cdf0e10cSrcweir             {
685cdf0e10cSrcweir                 sComposite = FileHelper.appendPath(sIMPath, sComposite);
686cdf0e10cSrcweir             }
687cdf0e10cSrcweir         }
688cdf0e10cSrcweir 
689cdf0e10cSrcweir         // String sCommand = sComposite + " -compose difference " +
690cdf0e10cSrcweir         //     StringHelper.doubleQuoteIfNeed(_sOldGfx) + " " +
691cdf0e10cSrcweir         //     StringHelper.doubleQuoteIfNeed(_sNewGfx) + " " +
692cdf0e10cSrcweir         //     StringHelper.doubleQuoteIfNeed(_sDiffGfx);
693cdf0e10cSrcweir 
694cdf0e10cSrcweir         String[] sCommandArray =
695cdf0e10cSrcweir         {
696cdf0e10cSrcweir             sComposite,
697cdf0e10cSrcweir             "-compose",
698cdf0e10cSrcweir             "difference",
699cdf0e10cSrcweir             _sOldGfx,
700cdf0e10cSrcweir             _sNewGfx,
701cdf0e10cSrcweir             _sDiffGfx
702cdf0e10cSrcweir         };
703cdf0e10cSrcweir 
704cdf0e10cSrcweir         ProcessHandler aHandler = new ProcessHandler(sCommandArray);
705cdf0e10cSrcweir         boolean bBackValue = aHandler.executeSynchronously();
706cdf0e10cSrcweir         int nExitCode = aHandler.getExitCode();
707cdf0e10cSrcweir         if (nExitCode != 0)
708cdf0e10cSrcweir         {
709cdf0e10cSrcweir             GlobalLogWriter.println("'" + sComposite + "' return with ");
710cdf0e10cSrcweir             String sBack = aHandler.getOutputText();
711cdf0e10cSrcweir             GlobalLogWriter.println("'" + sBack + "'");
712cdf0e10cSrcweir         }
713cdf0e10cSrcweir         else
714cdf0e10cSrcweir         {
715cdf0e10cSrcweir             // creates an extra smaller difference picture
716cdf0e10cSrcweir             File aDiffFile = new File(_sDiffGfx);
717cdf0e10cSrcweir             if (aDiffFile.exists())
718cdf0e10cSrcweir             {
719cdf0e10cSrcweir                 JPEGCreator.convertToNearSameFileWithWidth340(_sDiffGfx);
720cdf0e10cSrcweir             }
721cdf0e10cSrcweir         }
722cdf0e10cSrcweir         return nExitCode;
723cdf0e10cSrcweir     }
724cdf0e10cSrcweir 
725cdf0e10cSrcweir     /**
726cdf0e10cSrcweir      * wrapper for ImageMagick identify,
727cdf0e10cSrcweir      * function checks how many different colors a picture contains.
728cdf0e10cSrcweir      * if it's only one color (nResult==1), like background color, there is no difference.
729cdf0e10cSrcweir      */
730cdf0e10cSrcweir     int identify(String _sDiffGfx)
731cdf0e10cSrcweir     {
732cdf0e10cSrcweir         int nResult = 0;
733cdf0e10cSrcweir         // would like to know what the meaning of %k is for ImageMagick's 'identify'
734cdf0e10cSrcweir         String sIM_Format = "%k";
735cdf0e10cSrcweir         // if (OSHelper.isWindows())
736cdf0e10cSrcweir         // {
737cdf0e10cSrcweir         //     sIM_Format = "%%k";
738cdf0e10cSrcweir         // }
739cdf0e10cSrcweir 
740cdf0e10cSrcweir         String sIdentify = "identify";
741cdf0e10cSrcweir         if (OSHelper.isWindows())
742cdf0e10cSrcweir         {
743cdf0e10cSrcweir             sIdentify = "identify.exe";
744cdf0e10cSrcweir             String sIMPath = (String) param.get("imagemagick.path");
745cdf0e10cSrcweir             if (sIMPath != null)
746cdf0e10cSrcweir             {
747cdf0e10cSrcweir                 sIdentify = FileHelper.appendPath(sIMPath, sIdentify);
748cdf0e10cSrcweir             }
749cdf0e10cSrcweir         }
750cdf0e10cSrcweir 
751cdf0e10cSrcweir         // String sCommand = sIdentify + " " + sIM_Format + " " + StringHelper.doubleQuoteIfNeed(_sDiffGfx);
752cdf0e10cSrcweir 
753cdf0e10cSrcweir         String[] sCommandArray =
754cdf0e10cSrcweir         {
755cdf0e10cSrcweir             sIdentify,
756cdf0e10cSrcweir             "-format",
757cdf0e10cSrcweir             sIM_Format,
758cdf0e10cSrcweir             _sDiffGfx
759cdf0e10cSrcweir         };
760cdf0e10cSrcweir         ProcessHandler aHandler = new ProcessHandler(sCommandArray);
761cdf0e10cSrcweir         boolean bBackValue = aHandler.executeSynchronously();
762cdf0e10cSrcweir         int nExitCode = aHandler.getExitCode();
763cdf0e10cSrcweir 
764cdf0e10cSrcweir         String sBack = aHandler.getOutputText();
765cdf0e10cSrcweir         GlobalLogWriter.println("'" + sBack + "'");
766cdf0e10cSrcweir 
767cdf0e10cSrcweir         // try to interpret the result, which we get as a String
768cdf0e10cSrcweir         try
769cdf0e10cSrcweir         {
770cdf0e10cSrcweir             int nIdx = sBack.indexOf("\n");
771cdf0e10cSrcweir             if (nIdx > 0)
772cdf0e10cSrcweir             {
773cdf0e10cSrcweir                 sBack = sBack.substring(0, nIdx);
774cdf0e10cSrcweir             }
775cdf0e10cSrcweir 
776cdf0e10cSrcweir             nResult = Integer.valueOf(sBack).intValue();
777cdf0e10cSrcweir         }
778cdf0e10cSrcweir         catch (java.lang.NumberFormatException e)
779cdf0e10cSrcweir         {
780cdf0e10cSrcweir             GlobalLogWriter.println("identify(): Number format exception");
781cdf0e10cSrcweir             nResult = 0;
782cdf0e10cSrcweir         }
783cdf0e10cSrcweir         return nResult;
784cdf0e10cSrcweir     }
785cdf0e10cSrcweir //    public static void main(String [] _args)
786cdf0e10cSrcweir //    {
787cdf0e10cSrcweir //// give an index.ini file, ok
788cdf0e10cSrcweir //// give a directory, where exist jpeg files ok
789cdf0e10cSrcweir //// inputpath (given file) doesn't exists
790cdf0e10cSrcweir //// give a jpeg file.
791cdf0e10cSrcweir //
792cdf0e10cSrcweir //        String args[] = {
793cdf0e10cSrcweir //            "-TimeOut", "3600000",
794cdf0e10cSrcweir //            "-tb", "java_complex",
795cdf0e10cSrcweir //            "-o", "graphical.JPEGComparator",
796cdf0e10cSrcweir //            "-DOC_COMPARATOR_INPUT_PATH", "C:\\CWS\\temp\\output\\index.ini",
797cdf0e10cSrcweir //            "-DOC_COMPARATOR_OUTPUT_PATH", "C:\\CWS\\temp\\output2",
798cdf0e10cSrcweir ////            "-DOC_COMPARATOR_INPUT_PATH", "C:\\CWS\\temp\\output\\GroupReport.odt.pdf_180DPI_0001.jpg",
799cdf0e10cSrcweir ////            "-DOC_COMPARATOR_OUTPUT_PATH", "C:\\CWS\\temp\\output2\\Report1.odt.pdf_180DPI_0001.jpg",
800cdf0e10cSrcweir //            "-DOC_COMPARATOR_HTML_OUTPUT_PREFIX", "http://so-gfxcmp-lin.germany.sun.com/gfxcmp_ui/cw.php?inifile=",
801cdf0e10cSrcweir ////            "-DOC_COMPARATOR_REFERENCE_CREATOR_TYPE", "PDF",      /* default: "OOo" */
802cdf0e10cSrcweir ////            "-DOC_COMPARATOR_REFERENCE_CREATOR_TYPE", "msoffice", /* default: "OOo" */
803cdf0e10cSrcweir ////            "-OFFICE_VIEWABLE", "false",
804cdf0e10cSrcweir ////            "-AppExecutionCommand", "\"C:/Programme/sun/staroffice 9/program/soffice.exe\"  -norestore -nocrashreport -accept=pipe,name=ll93751;urp;",
805cdf0e10cSrcweir //            "-NoOffice"
806cdf0e10cSrcweir //        };
807cdf0e10cSrcweir //
808cdf0e10cSrcweir //        org.openoffice.Runner.main(args);
809cdf0e10cSrcweir //    }
810cdf0e10cSrcweir }
811