koishi-plugin-best-cave 2.2.4 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/HashManager.d.ts +7 -1
- package/lib/index.js +12 -9
- package/package.json +1 -1
package/lib/HashManager.d.ts
CHANGED
|
@@ -63,7 +63,13 @@ export declare class HashManager {
|
|
|
63
63
|
* @returns {Promise<string>} 一个包含操作结果的报告字符串。
|
|
64
64
|
*/
|
|
65
65
|
checkForSimilarCaves(): Promise<string>;
|
|
66
|
-
|
|
66
|
+
/**
|
|
67
|
+
* @description 从单通道原始像素数据计算pHash。
|
|
68
|
+
* @param channelData - 单通道的像素值数组。
|
|
69
|
+
* @param size - 图像的边长(例如16)。
|
|
70
|
+
* @returns {string} 该通道的二进制哈希字符串。
|
|
71
|
+
*/
|
|
72
|
+
private _calculateHashFromRawChannel;
|
|
67
73
|
/**
|
|
68
74
|
* @description 生成768位颜色感知哈希(Color pHash)。
|
|
69
75
|
* @param imageBuffer - 图片的 Buffer 数据。
|
package/lib/index.js
CHANGED
|
@@ -806,11 +806,16 @@ var HashManager = class {
|
|
|
806
806
|
if (subHashDuplicates.length > 0) report += "\n图片局部重复:\n" + [...new Set(subHashDuplicates)].join("\n");
|
|
807
807
|
return report.trim();
|
|
808
808
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
809
|
+
/**
|
|
810
|
+
* @description 从单通道原始像素数据计算pHash。
|
|
811
|
+
* @param channelData - 单通道的像素值数组。
|
|
812
|
+
* @param size - 图像的边长(例如16)。
|
|
813
|
+
* @returns {string} 该通道的二进制哈希字符串。
|
|
814
|
+
*/
|
|
815
|
+
_calculateHashFromRawChannel(channelData, size) {
|
|
816
|
+
const totalLuminance = channelData.reduce((acc, val) => acc + val, 0);
|
|
812
817
|
const avgLuminance = totalLuminance / (size * size);
|
|
813
|
-
return
|
|
818
|
+
return channelData.map((lum) => lum > avgLuminance ? "1" : "0").join("");
|
|
814
819
|
}
|
|
815
820
|
/**
|
|
816
821
|
* @description 生成768位颜色感知哈希(Color pHash)。
|
|
@@ -826,11 +831,9 @@ var HashManager = class {
|
|
|
826
831
|
g.push(data[i + 1]);
|
|
827
832
|
b.push(data[i + 2]);
|
|
828
833
|
}
|
|
829
|
-
const
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
this._generateSingleChannelPHash(Buffer.from(b), 16)
|
|
833
|
-
]);
|
|
834
|
+
const rHash = this._calculateHashFromRawChannel(r, 16);
|
|
835
|
+
const gHash = this._calculateHashFromRawChannel(g, 16);
|
|
836
|
+
const bHash = this._calculateHashFromRawChannel(b, 16);
|
|
834
837
|
const combinedHash = rHash + gHash + bHash;
|
|
835
838
|
let hex = "";
|
|
836
839
|
for (let i = 0; i < combinedHash.length; i += 4) {
|