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 
NameDPIPage(String _sName, int _nDPI, int _nPage)40cdf0e10cSrcweir     private NameDPIPage(String _sName, int _nDPI, int _nPage)
41cdf0e10cSrcweir     {
42cdf0e10cSrcweir         Name = _sName;
43cdf0e10cSrcweir         DPI = _nDPI;
44cdf0e10cSrcweir         Page = _nPage;
45cdf0e10cSrcweir     }
46cdf0e10cSrcweir 
interpret(String _sFilename)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 
CountNotXXXPixelsFromImage(String _sFilename)99cdf0e10cSrcweir     CountNotXXXPixelsFromImage(String _sFilename)
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         m_sFilename = _sFilename;
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir 
getValue()104cdf0e10cSrcweir     public int getValue()
105cdf0e10cSrcweir     {
106cdf0e10cSrcweir         return m_nValue;
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir 
setValue(int _nValue)109cdf0e10cSrcweir     protected void setValue(int _nValue)
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir         m_nValue = _nValue;
112cdf0e10cSrcweir     }
113cdf0e10cSrcweir 
getFilename()114cdf0e10cSrcweir     protected String getFilename()
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir         return m_sFilename;
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir class CountNotWhitePixelsFromImage extends CountNotXXXPixelsFromImage
121cdf0e10cSrcweir {
122cdf0e10cSrcweir 
CountNotWhitePixelsFromImage(String _sFilename)123cdf0e10cSrcweir     CountNotWhitePixelsFromImage(String _sFilename)
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir         super(_sFilename);
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
run()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 
CountNotBlackPixelsFromImage(String _sFilename)145cdf0e10cSrcweir     CountNotBlackPixelsFromImage(String _sFilename)
146cdf0e10cSrcweir     {
147cdf0e10cSrcweir         super(_sFilename);
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir 
run()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 
getTestMethodNames()172cdf0e10cSrcweir     public String[] getTestMethodNames()
173cdf0e10cSrcweir     {
174cdf0e10cSrcweir         return new String[]{"CompareJPEGvsJPEG"};
175cdf0e10cSrcweir     }
176cdf0e10cSrcweir     private Tolerance m_aTolerance;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     /**
179cdf0e10cSrcweir      * test function.
180cdf0e10cSrcweir      */
CompareJPEGvsJPEG()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 
checkOneFile(String _sDocumentName, String _sResult, ParameterHelper _aParams)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 
evaluateResult(String _sDocument, ParameterHelper _aParams)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 
checkOnePicture(String _sDocumentName, String _sResult, ParameterHelper _aParams)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      */
compareJPEG(String _sDocumentName, String _sResult, ParameterHelper _aParams)402cdf0e10cSrcweir     private void compareJPEG(String _sDocumentName, String _sResult, ParameterHelper _aParams)
403cdf0e10cSrcweir     {
404cdf0e10cSrcweir         NameDPIPage aNameDPIPage = NameDPIPage.interpret(_sDocumentName);
405cdf0e10cSrcweir 
406cdf0e10cSrcweir         String sSourceBasename = FileHelper.getBasename(_sDocumentName);
407cdf0e10cSrcweir         String sSourcePath = FileHelper.getPath(_sDocumentName);
408cdf0e10cSrcweir         String sDestinationBasename = FileHelper.getBasename(_sResult);
409cdf0e10cSrcweir         String sDestinationPath = FileHelper.getPath(_sResult);
410cdf0e10cSrcweir 
411cdf0e10cSrcweir         if (!sSourcePath.equals(sDestinationPath))
412cdf0e10cSrcweir         {
413cdf0e10cSrcweir             // we want to have all in one Directory, Original, Reference and the Difference result.
414cdf0e10cSrcweir             // copy the original file to the reference path
415cdf0e10cSrcweir             String sNewSourceBasename = "Original_" + sSourceBasename;
416cdf0e10cSrcweir             // String sSource = FileHelper.appendPath(sSourcePath, sSourceBasename);
417cdf0e10cSrcweir             String sSource = _sDocumentName;
418cdf0e10cSrcweir             String sDestination = FileHelper.appendPath(sDestinationPath, sNewSourceBasename);
419cdf0e10cSrcweir             FileHelper.copy(sSource, sDestination);
420cdf0e10cSrcweir             sSourceBasename = sNewSourceBasename;
421cdf0e10cSrcweir             //
422cdf0e10cSrcweir             JPEGCreator.convertToNearSameFileWithWidth340(sDestination);
423cdf0e10cSrcweir         }
424cdf0e10cSrcweir         String sDifferenceBasename = "Difference_between_" + FileHelper.getNameNoSuffix(sSourceBasename) + "_and_" + FileHelper.getNameNoSuffix(sDestinationBasename) + ".jpg";
425cdf0e10cSrcweir         // String sDifferencePath = sDestinationPath;
426cdf0e10cSrcweir 
427cdf0e10cSrcweir         String sSource = FileHelper.appendPath(sDestinationPath, sSourceBasename);
428cdf0e10cSrcweir         String sDestination = FileHelper.appendPath(sDestinationPath, sDestinationBasename);
429cdf0e10cSrcweir         String sDifference = FileHelper.appendPath(sDestinationPath, sDifferenceBasename);
430cdf0e10cSrcweir         int nErr = compareJPEG(sSource, sDestination, sDifference);
431cdf0e10cSrcweir         if (nErr == 0 && FileHelper.exists(sDifference))
432cdf0e10cSrcweir         {
433cdf0e10cSrcweir             // check the difference, returns the count of different colors
434cdf0e10cSrcweir             // this means, 1=only one color, no differences found.
435cdf0e10cSrcweir             int nResult = identify(sDifference);
436cdf0e10cSrcweir             int nPercentColorDiffer = 0;
437cdf0e10cSrcweir 
438cdf0e10cSrcweir             String sResult = "YES";
439cdf0e10cSrcweir 
440cdf0e10cSrcweir             if (m_aTolerance != null)
441cdf0e10cSrcweir             {
442cdf0e10cSrcweir                 final int nAcceptedTolerance = m_aTolerance.getAccept();
443cdf0e10cSrcweir                 if (nResult <= nAcceptedTolerance)
444cdf0e10cSrcweir                 {
445cdf0e10cSrcweir                     nResult = 1;
446cdf0e10cSrcweir                     sResult = "IN TOLERANCE";
447cdf0e10cSrcweir                     GlobalLogWriter.println("The differences are in tolerance.");
448cdf0e10cSrcweir 
449cdf0e10cSrcweir                 }
450cdf0e10cSrcweir             }
451cdf0e10cSrcweir             if (nResult != 1)
452cdf0e10cSrcweir             {
453cdf0e10cSrcweir                 sResult = "NO";
454cdf0e10cSrcweir                 try
455cdf0e10cSrcweir                 {
456cdf0e10cSrcweir                     nPercentColorDiffer = estimateGfx(sSource, sDestination, sDifference);
457cdf0e10cSrcweir                 }
458cdf0e10cSrcweir                 catch (java.io.IOException e)
459cdf0e10cSrcweir                 {
460cdf0e10cSrcweir                     GlobalLogWriter.println("Can't estimate the different colors. " + e.getMessage());
461cdf0e10cSrcweir                 }
462cdf0e10cSrcweir             }
463cdf0e10cSrcweir 
464cdf0e10cSrcweir             // store the result in a result.ini file
465cdf0e10cSrcweir             String sResultFile = FileHelper.appendPath(sDestinationPath, aNameDPIPage.Name + ".ini");
466cdf0e10cSrcweir             int nPage = aNameDPIPage.Page;
467cdf0e10cSrcweir             if (nPage < 0)
468cdf0e10cSrcweir             {
469cdf0e10cSrcweir                 nPage = 0;
470cdf0e10cSrcweir             }
471cdf0e10cSrcweir             IniFile aResultIni = new IniFile(sResultFile);
472cdf0e10cSrcweir 
473cdf0e10cSrcweir             String[] aComment =
474cdf0e10cSrcweir             {
475cdf0e10cSrcweir                 "; This file is automatically created by a graphical.JPEGComparator run",
476cdf0e10cSrcweir                 "; ",
477cdf0e10cSrcweir                 "; If you see this file in a browser you may have forgotten to set the follows in the property file",
478cdf0e10cSrcweir                 "; " + PropertyName.DOC_COMPARATOR_HTML_OUTPUT_PREFIX + "=http://<computer>/gfxcmp_ui/cw.php?inifile=",
479cdf0e10cSrcweir                 "; Please check the documentation if you got confused.",
480cdf0e10cSrcweir                 "; ",
481cdf0e10cSrcweir                 "; "
482cdf0e10cSrcweir             };
483cdf0e10cSrcweir             aResultIni.insertFirstComment(aComment);
484cdf0e10cSrcweir 
485cdf0e10cSrcweir             // write down the global flags
486cdf0e10cSrcweir             int nMaxPage = Math.max(nPage, aResultIni.getIntValue("global", "pages", 0));
487cdf0e10cSrcweir             aResultIni.insertValue("global", "pages", nMaxPage);
488cdf0e10cSrcweir 
489cdf0e10cSrcweir             // INIoutput.writeValue("buildid", _sBuildID);
490cdf0e10cSrcweir             // INIoutput.writeValue("refbuildid", _sRefBuildID);
491cdf0e10cSrcweir             String sRefBuildId = (String) _aParams.getTestParameters().get("RefBuildId");
492cdf0e10cSrcweir             if (sRefBuildId == null)
493cdf0e10cSrcweir             {
494cdf0e10cSrcweir                 sRefBuildId = "";
495cdf0e10cSrcweir             }
496cdf0e10cSrcweir             aResultIni.insertValue("global", "refbuildid", sRefBuildId);
497cdf0e10cSrcweir 
498cdf0e10cSrcweir             aResultIni.insertValue("global", "diffdiff", "no");
499cdf0e10cSrcweir             aResultIni.insertValue("global", "basename", aNameDPIPage.Name);
500cdf0e10cSrcweir             aResultIni.insertValue("global", "dpi", aNameDPIPage.DPI);
501cdf0e10cSrcweir 
502cdf0e10cSrcweir             // write down flags for each page
503cdf0e10cSrcweir             String sSection = "page" + String.valueOf(nPage);
504cdf0e10cSrcweir 
505cdf0e10cSrcweir             aResultIni.insertValue(sSection, "oldgfx", sSource);
506cdf0e10cSrcweir             aResultIni.insertValue(sSection, "newgfx", sDestination);
507cdf0e10cSrcweir             aResultIni.insertValue(sSection, "diffgfx", sDifference);
508cdf0e10cSrcweir             aResultIni.insertValue(sSection, "percent", nPercentColorDiffer);
509cdf0e10cSrcweir             aResultIni.insertValue(sSection, "BM", "false");
510cdf0e10cSrcweir             aResultIni.insertValue(sSection, "result", sResult);
511cdf0e10cSrcweir 
512cdf0e10cSrcweir             aResultIni.close();
513cdf0e10cSrcweir         }
514cdf0e10cSrcweir     }
515cdf0e10cSrcweir 
516cdf0e10cSrcweir //    // This creates a status for exact on document
517cdf0e10cSrcweir //    static boolean createINIStatus(StatusHelper[] aList, String _sFilenamePrefix, String _sOutputPath, String _sAbsoluteInputFile, String _sBuildID, String _sRefBuildID)
518cdf0e10cSrcweir //        {
519cdf0e10cSrcweir //            // Status
520cdf0e10cSrcweir //            String fs = System.getProperty("file.separator");
521cdf0e10cSrcweir //            String sBasename = FileHelper.getBasename(_sAbsoluteInputFile);
522cdf0e10cSrcweir //            String sNameNoSuffix = FileHelper.getNameNoSuffix(sBasename);
523cdf0e10cSrcweir ////            String sHTMLFile = _sFilenamePrefix + sNameNoSuffix + ".html";
524cdf0e10cSrcweir ////            HTMLOutputter HTMLoutput = HTMLOutputter.create(_sOutputPath, sHTMLFile, "", "");
525cdf0e10cSrcweir ////            HTMLoutput.header(sNameNoSuffix);
526cdf0e10cSrcweir ////  TODO: version info was fine
527cdf0e10cSrcweir ////            HTMLoutput.checkSection(sBasename);
528cdf0e10cSrcweir //            // Status end
529cdf0e10cSrcweir //
530cdf0e10cSrcweir //            String sINIFile = _sFilenamePrefix + sNameNoSuffix + ".ini";
531cdf0e10cSrcweir //            INIOutputter INIoutput = INIOutputter.create(_sOutputPath, sINIFile, "", "");
532cdf0e10cSrcweir //            INIoutput.createHeader();
533cdf0e10cSrcweir ////  TODO: version info was fine
534cdf0e10cSrcweir //
535cdf0e10cSrcweir //            INIoutput.writeSection("global");
536cdf0e10cSrcweir //            INIoutput.writeValue("pages", String.valueOf(aList.length));
537cdf0e10cSrcweir //            INIoutput.writeValue("buildid", _sBuildID);
538cdf0e10cSrcweir //            INIoutput.writeValue("refbuildid", _sRefBuildID);
539cdf0e10cSrcweir //            INIoutput.writeValue("diffdiff", "no");
540cdf0e10cSrcweir //            INIoutput.writeValue("basename", sBasename);
541cdf0e10cSrcweir //
542cdf0e10cSrcweir //            boolean bResultIsOk = true;          // result over all pages
543cdf0e10cSrcweir //            for (int i=0;i<aList.length; i++)
544cdf0e10cSrcweir //            {
545cdf0e10cSrcweir //                INIoutput.writeSection("page" + String.valueOf(i + 1));   // list start at point 0, but this is page 1 and so on... current_page = (i + 1)
546cdf0e10cSrcweir //                aList[i].printStatus();
547cdf0e10cSrcweir //
548cdf0e10cSrcweir //                boolean bCurrentResult = true;   // result over exact one page
549cdf0e10cSrcweir //
550cdf0e10cSrcweir //                int nCurrentDiffStatus = aList[i].nDiffStatus;
551cdf0e10cSrcweir //
552cdf0e10cSrcweir //                // check if the status is in a defined range
553cdf0e10cSrcweir //                if (nCurrentDiffStatus == StatusHelper.DIFF_NO_DIFFERENCES)
554cdf0e10cSrcweir //                {
555cdf0e10cSrcweir //                    // ok.
556cdf0e10cSrcweir //                }
557cdf0e10cSrcweir //                else if (nCurrentDiffStatus == StatusHelper.DIFF_DIFFERENCES_FOUND && aList[i].nPercent < 5)
558cdf0e10cSrcweir //                {
559cdf0e10cSrcweir //                    // ok.
560cdf0e10cSrcweir //                }
561cdf0e10cSrcweir //                else if (nCurrentDiffStatus == StatusHelper.DIFF_AFTER_MOVE_DONE_NO_PROBLEMS)
562cdf0e10cSrcweir //                {
563cdf0e10cSrcweir //                    // ok.
564cdf0e10cSrcweir //                }
565cdf0e10cSrcweir //                else if (nCurrentDiffStatus == StatusHelper.DIFF_AFTER_MOVE_DONE_DIFFERENCES_FOUND && aList[i].nPercent2 < 5)
566cdf0e10cSrcweir //                {
567cdf0e10cSrcweir //                    // ok.
568cdf0e10cSrcweir //                }
569cdf0e10cSrcweir //                else
570cdf0e10cSrcweir //                {
571cdf0e10cSrcweir //                    // failed.
572cdf0e10cSrcweir //                    bCurrentResult = false; // logic: nDiff==0 = true if there is no difference
573cdf0e10cSrcweir //                }
574cdf0e10cSrcweir //
575cdf0e10cSrcweir //                // Status
576cdf0e10cSrcweir ////                HTMLoutput.checkLine(aList[i], bCurrentResult);
577cdf0e10cSrcweir //                INIoutput.checkLine(aList[i], bCurrentResult);
578cdf0e10cSrcweir //                bResultIsOk &= bCurrentResult;
579cdf0e10cSrcweir //            }
580cdf0e10cSrcweir //            // Status
581cdf0e10cSrcweir ////            HTMLoutput.close();
582cdf0e10cSrcweir //            INIoutput.close();
583cdf0e10cSrcweir //            return bResultIsOk;
584cdf0e10cSrcweir //        }
585cdf0e10cSrcweir     /**
586cdf0e10cSrcweir      * count how much pixel differ and between Old or New and the Difference graphics
587cdf0e10cSrcweir      *
588cdf0e10cSrcweir      * First, count the old graphics, then the new graphics due to the fact both should be equal
589cdf0e10cSrcweir      * it should be legal to take result from old or new. We take the graphics with less values.
590cdf0e10cSrcweir      *
591cdf0e10cSrcweir      * Second, count the difference graphics, now take the percent algorithm and
592cdf0e10cSrcweir      * build a percent value, which contain the number of different pixels as a percent value
593cdf0e10cSrcweir      *
594cdf0e10cSrcweir      * Interpretation:
595cdf0e10cSrcweir      * 0%    there is no difference
596cdf0e10cSrcweir      *
597cdf0e10cSrcweir      * &lt;100% Take a look into the difference graphics, maybe the difference graphics shows
598cdf0e10cSrcweir      *       text like outlined or the text is little bit move left, right up or down.
599cdf0e10cSrcweir      *
600cdf0e10cSrcweir      * &gt;>100% Yes it's possible that there is a difference more then 100%, maybe a font problem
601cdf0e10cSrcweir      *       between old and new graphics. The font of the new graphics is little bit bigger,
602cdf0e10cSrcweir      *       so the pixel count between old graphics and new graphics is twice the more.
603cdf0e10cSrcweir      *
604cdf0e10cSrcweir      * @param _sOldGfx path & name to the jpeg file (1)
605cdf0e10cSrcweir      * @param _sNewGfx path & name to the other jpeg file (2)
606cdf0e10cSrcweir      * @param _sDiffGfx path & name to the new difference file which shows the difference between (1) and (2)
607cdf0e10cSrcweir      * @return the count of different pixels
608cdf0e10cSrcweir      * @throws java.io.IOException if file access is not possible
609cdf0e10cSrcweir      */
estimateGfx(String _sOldGfx, String _sNewGfx, String _sDiffGfx)610cdf0e10cSrcweir     public static int estimateGfx(String _sOldGfx, String _sNewGfx, String _sDiffGfx)
611cdf0e10cSrcweir             throws java.io.IOException
612cdf0e10cSrcweir     {
613cdf0e10cSrcweir         TimeHelper a = new TimeHelper();
614cdf0e10cSrcweir         a.start();
615cdf0e10cSrcweir         // Count Pixels
616cdf0e10cSrcweir         final int nNotWhiteCount_OldGraphic = PixelCounter.countNotWhitePixelsFromImage(_sOldGfx);
617cdf0e10cSrcweir         final int nNotWhiteCount_NewGraphic = PixelCounter.countNotWhitePixelsFromImage(_sNewGfx);
618cdf0e10cSrcweir         final int nNotBlackCount_DiffGraphic = PixelCounter.countNotBlackPixelsFromImage(_sDiffGfx);
619cdf0e10cSrcweir 
620cdf0e10cSrcweir         // Count Pixels in different threads
621cdf0e10cSrcweir //        CountNotWhitePixelsFromImage t1 = new CountNotWhitePixelsFromImage(_sOldGfx);
622cdf0e10cSrcweir //        CountNotWhitePixelsFromImage t2 = new CountNotWhitePixelsFromImage(_sNewGfx);
623cdf0e10cSrcweir //        CountNotBlackPixelsFromImage t3 = new CountNotBlackPixelsFromImage(_sDiffGfx);
624cdf0e10cSrcweir //        t1.start();
625cdf0e10cSrcweir //        t2.start();
626cdf0e10cSrcweir //        t3.start();
627cdf0e10cSrcweir //        try
628cdf0e10cSrcweir //        {
629cdf0e10cSrcweir //            t1.join();
630cdf0e10cSrcweir //        }
631cdf0e10cSrcweir //        catch (InterruptedException ex)
632cdf0e10cSrcweir //        {
633cdf0e10cSrcweir //            GlobalLogWriter.get().println("Thread 1 failed: " + ex.getMessage());
634cdf0e10cSrcweir //        }
635cdf0e10cSrcweir //        try
636cdf0e10cSrcweir //        {
637cdf0e10cSrcweir //            t2.join();
638cdf0e10cSrcweir //        }
639cdf0e10cSrcweir //        catch (InterruptedException ex)
640cdf0e10cSrcweir //        {
641cdf0e10cSrcweir //            GlobalLogWriter.get().println("Thread 2 failed: " + ex.getMessage());
642cdf0e10cSrcweir //        }
643cdf0e10cSrcweir //        try
644cdf0e10cSrcweir //        {
645cdf0e10cSrcweir //            t3.join();
646cdf0e10cSrcweir //        }
647cdf0e10cSrcweir //        catch (InterruptedException ex)
648cdf0e10cSrcweir //        {
649cdf0e10cSrcweir //            GlobalLogWriter.get().println("Thread 3 failed: " + ex.getMessage());
650cdf0e10cSrcweir //        }
651cdf0e10cSrcweir //        final int nNotWhiteCount_OldGraphic = t1.getValue();
652cdf0e10cSrcweir //        final int nNotWhiteCount_NewGraphic = t2.getValue();
653cdf0e10cSrcweir //        final int nNotBlackCount_DiffGraphic = t3.getValue();
654cdf0e10cSrcweir 
655cdf0e10cSrcweir         a.stop();
656cdf0e10cSrcweir         GlobalLogWriter.println("Thread Time is: " + a.getTime());
657cdf0e10cSrcweir 
658cdf0e10cSrcweir         int nMinNotWhiteCount = Math.min(nNotWhiteCount_NewGraphic, nNotWhiteCount_OldGraphic);
659cdf0e10cSrcweir 
660cdf0e10cSrcweir         // check if not zero
661cdf0e10cSrcweir         if (nMinNotWhiteCount == 0)
662cdf0e10cSrcweir         {
663cdf0e10cSrcweir             nMinNotWhiteCount = Math.max(nNotWhiteCount_NewGraphic, nNotWhiteCount_OldGraphic);
664cdf0e10cSrcweir             if (nMinNotWhiteCount == 0)
665cdf0e10cSrcweir             {
666cdf0e10cSrcweir                 nMinNotWhiteCount = 1;
667cdf0e10cSrcweir             }
668cdf0e10cSrcweir         }
669cdf0e10cSrcweir 
670cdf0e10cSrcweir         int nPercent = Math.abs(nNotBlackCount_DiffGraphic * 100 / nMinNotWhiteCount);
671cdf0e10cSrcweir         GlobalLogWriter.println("Graphics check, pixel based:" + String.valueOf(nPercent) + "% pixel differ ");
672cdf0e10cSrcweir         return nPercent;
673cdf0e10cSrcweir     }
674cdf0e10cSrcweir 
compareJPEG(String _sOldGfx, String _sNewGfx, String _sDiffGfx)675cdf0e10cSrcweir     private static int compareJPEG(String _sOldGfx, String _sNewGfx, String _sDiffGfx)
676cdf0e10cSrcweir     {
677cdf0e10cSrcweir         String sComposite = "composite";
678cdf0e10cSrcweir         if (OSHelper.isWindows())
679cdf0e10cSrcweir         {
680cdf0e10cSrcweir             sComposite = "composite.exe";
681cdf0e10cSrcweir             String sIMPath = (String) param.get("imagemagick.path");
682cdf0e10cSrcweir             if (sIMPath != null)
683cdf0e10cSrcweir             {
684cdf0e10cSrcweir                 sComposite = FileHelper.appendPath(sIMPath, sComposite);
685cdf0e10cSrcweir             }
686cdf0e10cSrcweir         }
687cdf0e10cSrcweir 
688cdf0e10cSrcweir         // String sCommand = sComposite + " -compose difference " +
689cdf0e10cSrcweir         //     StringHelper.doubleQuoteIfNeed(_sOldGfx) + " " +
690cdf0e10cSrcweir         //     StringHelper.doubleQuoteIfNeed(_sNewGfx) + " " +
691cdf0e10cSrcweir         //     StringHelper.doubleQuoteIfNeed(_sDiffGfx);
692cdf0e10cSrcweir 
693cdf0e10cSrcweir         String[] sCommandArray =
694cdf0e10cSrcweir         {
695cdf0e10cSrcweir             sComposite,
696cdf0e10cSrcweir             "-compose",
697cdf0e10cSrcweir             "difference",
698cdf0e10cSrcweir             _sOldGfx,
699cdf0e10cSrcweir             _sNewGfx,
700cdf0e10cSrcweir             _sDiffGfx
701cdf0e10cSrcweir         };
702cdf0e10cSrcweir 
703cdf0e10cSrcweir         ProcessHandler aHandler = new ProcessHandler(sCommandArray);
704cdf0e10cSrcweir         boolean bBackValue = aHandler.executeSynchronously();
705cdf0e10cSrcweir         int nExitCode = aHandler.getExitCode();
706cdf0e10cSrcweir         if (nExitCode != 0)
707cdf0e10cSrcweir         {
708cdf0e10cSrcweir             GlobalLogWriter.println("'" + sComposite + "' return with ");
709cdf0e10cSrcweir             String sBack = aHandler.getOutputText();
710cdf0e10cSrcweir             GlobalLogWriter.println("'" + sBack + "'");
711cdf0e10cSrcweir         }
712cdf0e10cSrcweir         else
713cdf0e10cSrcweir         {
714cdf0e10cSrcweir             // creates an extra smaller difference picture
715cdf0e10cSrcweir             File aDiffFile = new File(_sDiffGfx);
716cdf0e10cSrcweir             if (aDiffFile.exists())
717cdf0e10cSrcweir             {
718cdf0e10cSrcweir                 JPEGCreator.convertToNearSameFileWithWidth340(_sDiffGfx);
719cdf0e10cSrcweir             }
720cdf0e10cSrcweir         }
721cdf0e10cSrcweir         return nExitCode;
722cdf0e10cSrcweir     }
723cdf0e10cSrcweir 
724cdf0e10cSrcweir     /**
725cdf0e10cSrcweir      * wrapper for ImageMagick identify,
726cdf0e10cSrcweir      * function checks how many different colors a picture contains.
727cdf0e10cSrcweir      * if it's only one color (nResult==1), like background color, there is no difference.
728cdf0e10cSrcweir      */
identify(String _sDiffGfx)729cdf0e10cSrcweir     int identify(String _sDiffGfx)
730cdf0e10cSrcweir     {
731cdf0e10cSrcweir         int nResult = 0;
732cdf0e10cSrcweir         // would like to know what the meaning of %k is for ImageMagick's 'identify'
733cdf0e10cSrcweir         String sIM_Format = "%k";
734cdf0e10cSrcweir         // if (OSHelper.isWindows())
735cdf0e10cSrcweir         // {
736cdf0e10cSrcweir         //     sIM_Format = "%%k";
737cdf0e10cSrcweir         // }
738cdf0e10cSrcweir 
739cdf0e10cSrcweir         String sIdentify = "identify";
740cdf0e10cSrcweir         if (OSHelper.isWindows())
741cdf0e10cSrcweir         {
742cdf0e10cSrcweir             sIdentify = "identify.exe";
743cdf0e10cSrcweir             String sIMPath = (String) param.get("imagemagick.path");
744cdf0e10cSrcweir             if (sIMPath != null)
745cdf0e10cSrcweir             {
746cdf0e10cSrcweir                 sIdentify = FileHelper.appendPath(sIMPath, sIdentify);
747cdf0e10cSrcweir             }
748cdf0e10cSrcweir         }
749cdf0e10cSrcweir 
750cdf0e10cSrcweir         // String sCommand = sIdentify + " " + sIM_Format + " " + StringHelper.doubleQuoteIfNeed(_sDiffGfx);
751cdf0e10cSrcweir 
752cdf0e10cSrcweir         String[] sCommandArray =
753cdf0e10cSrcweir         {
754cdf0e10cSrcweir             sIdentify,
755cdf0e10cSrcweir             "-format",
756cdf0e10cSrcweir             sIM_Format,
757cdf0e10cSrcweir             _sDiffGfx
758cdf0e10cSrcweir         };
759cdf0e10cSrcweir         ProcessHandler aHandler = new ProcessHandler(sCommandArray);
760cdf0e10cSrcweir         boolean bBackValue = aHandler.executeSynchronously();
761cdf0e10cSrcweir         int nExitCode = aHandler.getExitCode();
762cdf0e10cSrcweir 
763cdf0e10cSrcweir         String sBack = aHandler.getOutputText();
764cdf0e10cSrcweir         GlobalLogWriter.println("'" + sBack + "'");
765cdf0e10cSrcweir 
766cdf0e10cSrcweir         // try to interpret the result, which we get as a String
767cdf0e10cSrcweir         try
768cdf0e10cSrcweir         {
769cdf0e10cSrcweir             int nIdx = sBack.indexOf("\n");
770cdf0e10cSrcweir             if (nIdx > 0)
771cdf0e10cSrcweir             {
772cdf0e10cSrcweir                 sBack = sBack.substring(0, nIdx);
773cdf0e10cSrcweir             }
774cdf0e10cSrcweir 
775cdf0e10cSrcweir             nResult = Integer.valueOf(sBack).intValue();
776cdf0e10cSrcweir         }
777cdf0e10cSrcweir         catch (java.lang.NumberFormatException e)
778cdf0e10cSrcweir         {
779cdf0e10cSrcweir             GlobalLogWriter.println("identify(): Number format exception");
780cdf0e10cSrcweir             nResult = 0;
781cdf0e10cSrcweir         }
782cdf0e10cSrcweir         return nResult;
783cdf0e10cSrcweir     }
784cdf0e10cSrcweir //    public static void main(String [] _args)
785cdf0e10cSrcweir //    {
786cdf0e10cSrcweir //// give an index.ini file, ok
787cdf0e10cSrcweir //// give a directory, where exist jpeg files ok
788cdf0e10cSrcweir //// inputpath (given file) doesn't exists
789cdf0e10cSrcweir //// give a jpeg file.
790cdf0e10cSrcweir //
791cdf0e10cSrcweir //        String args[] = {
792cdf0e10cSrcweir //            "-TimeOut", "3600000",
793cdf0e10cSrcweir //            "-tb", "java_complex",
794cdf0e10cSrcweir //            "-o", "graphical.JPEGComparator",
795cdf0e10cSrcweir //            "-DOC_COMPARATOR_INPUT_PATH", "C:\\CWS\\temp\\output\\index.ini",
796cdf0e10cSrcweir //            "-DOC_COMPARATOR_OUTPUT_PATH", "C:\\CWS\\temp\\output2",
797cdf0e10cSrcweir ////            "-DOC_COMPARATOR_INPUT_PATH", "C:\\CWS\\temp\\output\\GroupReport.odt.pdf_180DPI_0001.jpg",
798cdf0e10cSrcweir ////            "-DOC_COMPARATOR_OUTPUT_PATH", "C:\\CWS\\temp\\output2\\Report1.odt.pdf_180DPI_0001.jpg",
799cdf0e10cSrcweir //            "-DOC_COMPARATOR_HTML_OUTPUT_PREFIX", "http://so-gfxcmp-lin.germany.sun.com/gfxcmp_ui/cw.php?inifile=",
800cdf0e10cSrcweir ////            "-DOC_COMPARATOR_REFERENCE_CREATOR_TYPE", "PDF",      /* default: "OOo" */
801cdf0e10cSrcweir ////            "-DOC_COMPARATOR_REFERENCE_CREATOR_TYPE", "msoffice", /* default: "OOo" */
802cdf0e10cSrcweir ////            "-OFFICE_VIEWABLE", "false",
803cdf0e10cSrcweir ////            "-AppExecutionCommand", "\"C:/Programme/sun/staroffice 9/program/soffice.exe\"  -norestore -nocrashreport -accept=pipe,name=ll93751;urp;",
804cdf0e10cSrcweir //            "-NoOffice"
805cdf0e10cSrcweir //        };
806cdf0e10cSrcweir //
807cdf0e10cSrcweir //        org.openoffice.Runner.main(args);
808cdf0e10cSrcweir //    }
809cdf0e10cSrcweir }
810