diff --git a/pom.xml b/pom.xml index 91f360a..79fbcc9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ icu.namophice ink-photo-album - 1.1-SNAPSHOT + 1.0 17 diff --git a/src/main/java/icu/namophice/inkphotoalbum/business/MasterService.java b/src/main/java/icu/namophice/inkphotoalbum/business/MasterService.java index f07c287..667caf5 100644 --- a/src/main/java/icu/namophice/inkphotoalbum/business/MasterService.java +++ b/src/main/java/icu/namophice/inkphotoalbum/business/MasterService.java @@ -5,14 +5,8 @@ import icu.namophice.inkphotoalbum.driver.EPaper; import icu.namophice.inkphotoalbum.utils.CommonUtil; import icu.namophice.inkphotoalbum.utils.ImageUtil; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; import java.awt.image.BufferedImage; import java.io.File; -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.security.cert.X509Certificate; import java.util.Arrays; import java.util.Random; @@ -84,56 +78,14 @@ public class MasterService { DefaultConfig.imageIndex = 0; } - final StringBuilder imageUrlStr = new StringBuilder(); - try { - final URL url = new URL(DefaultConfig.imageUrlArr[new Random().nextInt(DefaultConfig.imageUrlArr.length)]); + BufferedImage targetImage = ImageUtil.getImageToScreen( + DefaultConfig.imageUrlArr[new Random().nextInt(DefaultConfig.imageUrlArr.length)], + true + ); - trustAllHttpsCertificates(); - HostnameVerifier hv = (urlHostName, session) -> { - System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost()); - return true; - }; - HttpsURLConnection.setDefaultHostnameVerifier(hv); - - final HttpURLConnection conn = (HttpURLConnection) (url.openConnection()); - final URL imageUrl = conn.getURL(); - imageUrlStr.append(imageUrl.getProtocol()).append("://").append(imageUrl.getHost()).append(imageUrl.getPath()); - } catch (IOException e) { - DefaultConfig.imageIndex = 0; - throw e; - } - - if (imageUrlStr.length() > 0) { - BufferedImage targetImage = ImageUtil.getImageToScreen(imageUrlStr.toString(), true); - - CommonUtil.printLogToConsole("Print images to screen ..."); - ePaper.drawImage(targetImage); - DefaultConfig.imageIndex++; - } - } - } - - /** - * 跳过SSL证书验证 - * @throws Exception - */ - private static void trustAllHttpsCertificates() throws Exception { - javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1]; - javax.net.ssl.TrustManager tm = new miTM(); - trustAllCerts[0] = tm; - javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL"); - sc.init(null, trustAllCerts, null); - javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - } - - private static class miTM implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager { - @Override - public void checkClientTrusted(X509Certificate[] chain, String authType) {} - @Override - public void checkServerTrusted(X509Certificate[] chain, String authType) {} - @Override - public X509Certificate[] getAcceptedIssuers() { - return null; + CommonUtil.printLogToConsole("Print images to screen ..."); + ePaper.drawImage(targetImage); + DefaultConfig.imageIndex++; } } diff --git a/src/main/java/icu/namophice/inkphotoalbum/config/DefaultConfig.java b/src/main/java/icu/namophice/inkphotoalbum/config/DefaultConfig.java index 242d008..dec5416 100644 --- a/src/main/java/icu/namophice/inkphotoalbum/config/DefaultConfig.java +++ b/src/main/java/icu/namophice/inkphotoalbum/config/DefaultConfig.java @@ -14,12 +14,10 @@ import java.io.FileReader; public class DefaultConfig { public static final String[] imageUrlArr = { - "https://api.ixiaowai.cn/api/api.php", - "https://api.ixiaowai.cn/api/api2.php", - "https://api.ixiaowai.cn/mcapi/mcapi.php", - "https://api.ixiaowai.cn/mcapi/mcapi2.php", - "https://api.ixiaowai.cn/gqapi/gqapi.php", - "https://api.ixiaowai.cn/gqapi/gqapi2.php" + "https://www.dmoe.cc/random.php", + "https://cdn.seovx.com/d/?mom=302", + "https://api.paugram.com/wallpaper/", + "https://api.yimian.xyz/img" }; public static final String configFileName = "conf.json"; diff --git a/src/main/java/icu/namophice/inkphotoalbum/utils/ImageUtil.java b/src/main/java/icu/namophice/inkphotoalbum/utils/ImageUtil.java index 0eda984..9b8cdfc 100644 --- a/src/main/java/icu/namophice/inkphotoalbum/utils/ImageUtil.java +++ b/src/main/java/icu/namophice/inkphotoalbum/utils/ImageUtil.java @@ -317,6 +317,7 @@ public class ImageUtil { final int height = originImage.getHeight(); BufferedImage targetImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); + final int maxValue = 0xf73140, minValue = 0x83fd10; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { int rgb = originImage.getRGB(i, j); @@ -325,14 +326,18 @@ public class ImageUtil { int binValue; // 0是黑 1是白 ,或者说数值小就靠近黑色,数值大就靠近白色 - if(oneGate > 0xec82e0) { // 大于一定数值,直接用白点 + if (oneGate > maxValue) { // 大于一定数值,直接用白点 binValue = 0xffffff; - } else if(oneGate < 0x6ea050) { // 小于一定数值直接用黑点 + } else if (oneGate < minValue) { // 小于一定数值直接用黑点 binValue = 0; - } else if(oneGate > randomNum) { // 模拟灰阶使用随机数画白点 - binValue = 0xffffff; } else { - binValue = 0; + // 模拟灰阶使用随机数画白点 + final int random = new Random().nextInt(100); + if (oneGate > ((maxValue - minValue) / 2) + minValue) { + binValue = random < 60 ? 0xffffff : 0; + } else { + binValue = random < 80 ? 0 : 0xffffff; + } } targetImage.setRGB(i, j, binValue); } diff --git a/src/main/resources/images/default.bmp b/src/main/resources/images/default.bmp index 25ce18f..07c4f9a 100644 Binary files a/src/main/resources/images/default.bmp and b/src/main/resources/images/default.bmp differ diff --git a/start.sh b/start.sh index 1506e9e..8ce5783 100644 --- a/start.sh +++ b/start.sh @@ -5,6 +5,6 @@ while true do cd /opt/software/ink-photo-album - /usr/bin/sudo /usr/bin/java -jar /opt/software/ink-photo-album/ink-photo-album-1.0-SNAPSHOT-all.jar + /usr/bin/sudo /usr/bin/java -jar /opt/software/ink-photo-album/ink-photo-album-1.0.jar sleep 5m done