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 CHANGED
@@ -2,20 +2,19 @@ export type BlurMode = 'gaussian' | 'fast';
2
2
  export interface BlurOptions {
3
3
  /** 模糊半径,越大越糊。0 = 不模糊。 */
4
4
  radius: number;
5
- /** 兼容旧字段;photon 实现里 'gaussian' 会多过一次 box_blur。 */
5
+ /** 兼容旧字段;当前实现都按 gaussian 处理。 */
6
6
  mode?: BlurMode;
7
7
  }
8
8
  /**
9
- * 模糊算法(photon WASM 实现):
9
+ * 真高斯模糊(photon WASM 实现)。
10
10
  *
11
- * 把图缩到 1/N 尺寸(N 由 radius 决定),不做 upsample 直接编 JPEG。
12
- * 缩小本身就是强力模糊(细节都被平均掉了),同时 JPEG 编码体积小、耗时短,
13
- * 整体在 100ms 量级完成。聊天客户端展示时会自动放大,看起来就是糊图。
11
+ * 流程:
12
+ * 1. 把图缩到一半尺寸,减少模糊本身的计算量
13
+ * 2. 对缩小图做 gaussian_blur(半径按 radius 派生)
14
+ * 3. 放大回原尺寸(Triangle 让放大过程平滑,模糊就不会因放大变锯齿)
15
+ * 4. 编码 JPEG q=80
14
16
  *
15
- * - radius 0 直接编 JPEG(不模糊)
16
- * - radius 1..50 → factor = round(radius / 4) + 2 ≈ 2-15 倍下采样
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 sw = Math.max(2, Math.round(w / factor));
319
- const sh = Math.max(2, Math.round(h2 / factor));
320
- const small = (0, import_node.resize)(img, sw, sh, import_node.SamplingFilter.Triangle);
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
- if (options.mode === "gaussian") (0, import_node.box_blur)(small);
323
- return Buffer.from(small.get_bytes_jpeg(85));
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
- small.free();
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
- box_blur,
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 sw = Math.max(2, Math.round(w / factor));
301
- const sh = Math.max(2, Math.round(h2 / factor));
302
- const small = resize(img, sw, sh, SamplingFilter.Triangle);
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
- if (options.mode === "gaussian") box_blur(small);
305
- return Buffer.from(small.get_bytes_jpeg(85));
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
- small.free();
312
+ half.free();
308
313
  }
309
314
  } finally {
310
315
  img.free();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-argus",
3
3
  "description": "百眼巨人 Argus:让群友通过 /peek 命令偷窥你电脑屏幕的 Koishi 插件。",
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",