1 31 32 package org.opencms.setup.comptest; 33 34 import com.alkacon.simapi.RenderSettings; 35 import com.alkacon.simapi.Simapi; 36 import com.alkacon.simapi.filter.ImageMath; 37 import com.alkacon.simapi.filter.RotateFilter; 38 39 import org.opencms.setup.CmsSetupBean; 40 41 import java.awt.image.BufferedImage ; 42 import java.io.File ; 43 import java.util.Arrays ; 44 import java.util.Iterator ; 45 46 import javax.imageio.ImageIO ; 47 48 49 58 public class CmsSetupTestSimapi implements I_CmsSetupTest { 59 60 61 public static final String TEST_NAME = "Image Processing"; 62 63 66 public String getName() { 67 68 return TEST_NAME; 69 } 70 71 74 public CmsSetupTestResult execute(CmsSetupBean setupBean) { 75 76 CmsSetupTestResult testResult = new CmsSetupTestResult(this); 77 boolean ok = true; 78 Throwable ex = null; 79 try { 80 RenderSettings settings = new RenderSettings(Simapi.RENDER_QUALITY); 81 settings.setCompressionQuality(0.85f); 82 Simapi simapi = new Simapi(settings); 83 84 ImageIO.scanForPlugins(); 85 Iterator pngReaders = ImageIO.getImageReadersByFormatName(Simapi.TYPE_PNG); 86 if (!pngReaders.hasNext()) { 87 throw (new Exception ("No Java ImageIO readers for the PNG format are available.")); 88 } 89 Iterator pngWriters = ImageIO.getImageWritersByFormatName(Simapi.TYPE_PNG); 90 if (!pngWriters.hasNext()) { 91 throw (new Exception ("No Java ImageIO writers for the PNG format are available.")); 92 } 93 94 String basePath = setupBean.getWebAppRfsPath(); 95 if (!basePath.endsWith(File.separator)) { 96 basePath += File.separator; 97 } 98 basePath += "setup" + File.separator + "resources" + File.separator; 99 100 BufferedImage img1 = Simapi.read(basePath + "test1.png"); 101 BufferedImage img3 = simapi.applyFilter(img1, new RotateFilter(ImageMath.PI)); 102 simapi.write(img3, basePath + "test3.png", Simapi.TYPE_PNG); 103 BufferedImage img2 = Simapi.read(basePath + "test2.png"); 104 105 ok = Arrays.equals(simapi.getBytes(img2, Simapi.TYPE_PNG), simapi.getBytes(img3, Simapi.TYPE_PNG)); 106 } catch (Throwable e) { 107 ok = false; 108 ex = e; 109 } 110 111 if (ok) { 112 testResult.setResult(RESULT_PASSED); 113 testResult.setGreen(); 114 } else { 115 testResult.setYellow(); 116 if (ex != null) { 117 testResult.setResult(RESULT_FAILED); 118 testResult.setHelp(ex.toString()); 119 testResult.setInfo("<p><code>-Djava.awt.headless=true</code> JVM parameter or X-Server may be missing.<br>" 120 + "<b>You can continue the setup, but image processing will be disabled.</b></p>"); 121 } else { 122 testResult.setResult(RESULT_WARNING); 123 testResult.setHelp("Image processing works but result does not exactly match."); 124 StringBuffer info = new StringBuffer (); 125 info.append("<p>Please check the following images for visible differences:</p>"); 126 info.append("<table width='100%'>"); 127 info.append("<tr><th>Expected</th><th>Result</th></tr>"); 128 info.append("<tr><td align='center' width='50%'><img SRC='resources/test2.png'></td>"); 129 info.append("<td align='center' width='50%'><img SRC='resources/test3.png'></td></table>"); 130 info.append("<p><b>You can continue the setup, but image processing may not always work as expected.</b></p>"); 131 testResult.setInfo(info.toString()); 132 } 133 } 134 return testResult; 135 } 136 } 137 | Popular Tags |