灰度转换逻辑优化

This commit is contained in:
2023-07-02 16:34:04 +08:00
parent ddaa7da8eb
commit fe113ca87d
3 changed files with 11 additions and 32 deletions

View File

@@ -7,7 +7,6 @@ import icu.namophice.inkphotoalbum.utils.ImageUtil;
import java.awt.image.BufferedImage;
import java.io.File;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Random;
@@ -90,28 +89,4 @@ public class MasterService {
}
}
/**
* 跳过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;
}
}
}

View File

@@ -17,8 +17,7 @@ public class DefaultConfig {
"https://www.dmoe.cc/random.php",
"https://cdn.seovx.com/d/?mom=302",
"https://api.paugram.com/wallpaper/",
"https://api.yimian.xyz/img",
"https://img.xjh.me/random_img.php"
"https://api.yimian.xyz/img"
};
public static final String configFileName = "conf.json";

View File

@@ -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);
}