koishi-plugin-argus 0.4.0 → 0.4.1
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/blur.d.ts +9 -10
- package/lib/index.cjs +12 -7
- package/lib/index.mjs +13 -8
- package/package.json +1 -1
package/lib/blur.d.ts
CHANGED
|
@@ -2,20 +2,19 @@ export type BlurMode = 'gaussian' | 'fast';
|
|
|
2
2
|
export interface BlurOptions {
|
|
3
3
|
/** 模糊半径,越大越糊。0 = 不模糊。 */
|
|
4
4
|
radius: number;
|
|
5
|
-
/**
|
|
5
|
+
/** 兼容旧字段;当前实现都按 gaussian 处理。 */
|
|
6
6
|
mode?: BlurMode;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* 真高斯模糊(photon WASM 实现)。
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* 流程:
|
|
12
|
+
* 1. 把图缩到一半尺寸,减少模糊本身的计算量
|
|
13
|
+
* 2. 对缩小图做 gaussian_blur(半径按 radius 派生)
|
|
14
|
+
* 3. 放大回原尺寸(Triangle 让放大过程平滑,模糊就不会因放大变锯齿)
|
|
15
|
+
* 4. 编码 JPEG q=80
|
|
14
16
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* - radius 51..200 → factor = round(radius / 6) + 4 ≈ 12-37 倍下采样
|
|
18
|
-
*
|
|
19
|
-
* `mode='gaussian'` 时多过一次 box_blur 让边缘柔和。
|
|
17
|
+
* 这种"先缩半 → 真高斯 → 拉回"的方式能在 ~500ms 内做出真正高斯模糊,
|
|
18
|
+
* 而不是简单的马赛克 / 像素化。
|
|
20
19
|
*/
|
|
21
20
|
export declare function blurImage(input: Buffer, options: BlurOptions): Buffer;
|
package/lib/index.cjs
CHANGED
|
@@ -312,17 +312,22 @@ function blurImage(input, options) {
|
|
|
312
312
|
if (radius === 0) {
|
|
313
313
|
return Buffer.from(img.get_bytes_jpeg(85));
|
|
314
314
|
}
|
|
315
|
-
const factor = radius <= 50 ? Math.round(radius / 4) + 2 : Math.round(radius / 6) + 4;
|
|
316
315
|
const w = img.get_width();
|
|
317
316
|
const h2 = img.get_height();
|
|
318
|
-
const
|
|
319
|
-
const
|
|
320
|
-
const
|
|
317
|
+
const halfW = Math.max(2, Math.round(w / 2));
|
|
318
|
+
const halfH = Math.max(2, Math.round(h2 / 2));
|
|
319
|
+
const halfRadius = Math.max(1, Math.round(radius / 2));
|
|
320
|
+
const half = (0, import_node.resize)(img, halfW, halfH, import_node.SamplingFilter.Triangle);
|
|
321
321
|
try {
|
|
322
|
-
|
|
323
|
-
|
|
322
|
+
(0, import_node.gaussian_blur)(half, halfRadius);
|
|
323
|
+
const back = (0, import_node.resize)(half, w, h2, import_node.SamplingFilter.Triangle);
|
|
324
|
+
try {
|
|
325
|
+
return Buffer.from(back.get_bytes_jpeg(80));
|
|
326
|
+
} finally {
|
|
327
|
+
back.free();
|
|
328
|
+
}
|
|
324
329
|
} finally {
|
|
325
|
-
|
|
330
|
+
half.free();
|
|
326
331
|
}
|
|
327
332
|
} finally {
|
|
328
333
|
img.free();
|
package/lib/index.mjs
CHANGED
|
@@ -283,7 +283,7 @@ import { h } from "koishi";
|
|
|
283
283
|
// src/blur.ts
|
|
284
284
|
import {
|
|
285
285
|
PhotonImage,
|
|
286
|
-
|
|
286
|
+
gaussian_blur,
|
|
287
287
|
resize,
|
|
288
288
|
SamplingFilter
|
|
289
289
|
} from "@cf-wasm/photon/node";
|
|
@@ -294,17 +294,22 @@ function blurImage(input, options) {
|
|
|
294
294
|
if (radius === 0) {
|
|
295
295
|
return Buffer.from(img.get_bytes_jpeg(85));
|
|
296
296
|
}
|
|
297
|
-
const factor = radius <= 50 ? Math.round(radius / 4) + 2 : Math.round(radius / 6) + 4;
|
|
298
297
|
const w = img.get_width();
|
|
299
298
|
const h2 = img.get_height();
|
|
300
|
-
const
|
|
301
|
-
const
|
|
302
|
-
const
|
|
299
|
+
const halfW = Math.max(2, Math.round(w / 2));
|
|
300
|
+
const halfH = Math.max(2, Math.round(h2 / 2));
|
|
301
|
+
const halfRadius = Math.max(1, Math.round(radius / 2));
|
|
302
|
+
const half = resize(img, halfW, halfH, SamplingFilter.Triangle);
|
|
303
303
|
try {
|
|
304
|
-
|
|
305
|
-
|
|
304
|
+
gaussian_blur(half, halfRadius);
|
|
305
|
+
const back = resize(half, w, h2, SamplingFilter.Triangle);
|
|
306
|
+
try {
|
|
307
|
+
return Buffer.from(back.get_bytes_jpeg(80));
|
|
308
|
+
} finally {
|
|
309
|
+
back.free();
|
|
310
|
+
}
|
|
306
311
|
} finally {
|
|
307
|
-
|
|
312
|
+
half.free();
|
|
308
313
|
}
|
|
309
314
|
} finally {
|
|
310
315
|
img.free();
|