feat: add JPEG damage filter to fx #56

Merged
Passthem merged 1 commits from pi-agent/konabot:feat/fx-jpeg-damage into master 2026-03-14 01:01:39 +08:00
Contributor

PR Type

Enhancement, Tests, Documentation


Description

  • 新增 JPEG 损坏滤镜

  • 注册滤镜到管理器

  • 添加单元测试验证

  • 更新用户文档说明


Diagram Walkthrough

flowchart LR
  User["用户"] -- "请求" --> Manager["滤镜管理器"]
  Manager -- "调用" --> Impl["滤镜实现"]
  Impl -- "处理" --> Image["图像数据"]
  Image -- "返回" --> Result["损坏效果"]

File Walkthrough

Relevant files
Enhancement
fx_handle.py
新增 JPEG 损坏滤镜方法                                                                                     

konabot/plugins/fx_process/fx_handle.py

  • 新增 apply_jpeg_damage 静态方法
  • 实现 Alpha 通道保留逻辑
  • 限制质量参数范围 1 至 95
+24/-0   
fx_manager.py
注册 JPEG 损坏滤镜配置                                                                                     

konabot/plugins/fx_process/fx_manager.py

  • 新增 "JPEG 损坏" 映射配置
  • 关联至 apply_jpeg_damage 方法
+1/-0     
Tests
test_fx_process.py
新增滤镜功能单元测试文件                                                                                         

tests/test_fx_process.py

  • 创建 test_fx_process.py 文件
  • 验证图像尺寸和模式保持
  • 测试质量参数范围限制
+37/-0   
Documentation
fx.txt
更新用户文档滤镜使用说明                                                                                         

konabot/docs/user/fx.txt

  • 添加 fx JPEG 损坏 用法
  • 说明质量参数建议范围
+2/-0     

### **PR Type** Enhancement, Tests, Documentation ___ ### **Description** - 新增 JPEG 损坏滤镜 - 注册滤镜到管理器 - 添加单元测试验证 - 更新用户文档说明 ___ ### Diagram Walkthrough ```mermaid flowchart LR User["用户"] -- "请求" --> Manager["滤镜管理器"] Manager -- "调用" --> Impl["滤镜实现"] Impl -- "处理" --> Image["图像数据"] Image -- "返回" --> Result["损坏效果"] ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table> <tr> <td> <details> <summary><strong>fx_handle.py</strong><dd><code>新增 JPEG 损坏滤镜方法</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> konabot/plugins/fx_process/fx_handle.py - 新增 `apply_jpeg_damage` 静态方法 - 实现 Alpha 通道保留逻辑 - 限制质量参数范围 1 至 95 </details> </td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/fx-jpeg-damage/konabot/plugins/fx_process/fx_handle.py">+24/-0</a>&nbsp; &nbsp; </td> </tr> <tr> <td> <details> <summary><strong>fx_manager.py</strong><dd><code>注册 JPEG 损坏滤镜配置</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> konabot/plugins/fx_process/fx_manager.py - 新增 "JPEG 损坏" 映射配置 - 关联至 `apply_jpeg_damage` 方法 </details> </td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/fx-jpeg-damage/konabot/plugins/fx_process/fx_manager.py">+1/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>test_fx_process.py</strong><dd><code>新增滤镜功能单元测试文件</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> tests/test_fx_process.py - 创建 `test_fx_process.py` 文件 - 验证图像尺寸和模式保持 - 测试质量参数范围限制 </details> </td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/fx-jpeg-damage/tests/test_fx_process.py">+37/-0</a>&nbsp; &nbsp; </td> </tr> </table></td></tr><tr><td><strong>Documentation</strong></td><td><table> <tr> <td> <details> <summary><strong>fx.txt</strong><dd><code>更新用户文档滤镜使用说明</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> konabot/docs/user/fx.txt - 添加 `fx JPEG 损坏` 用法 - 说明质量参数建议范围 </details> </td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/fx-jpeg-damage/konabot/docs/user/fx.txt">+2/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></td></tr></tr></tbody></table> </details> ___
pi-agent added 1 commit 2026-03-14 00:52:57 +08:00
Collaborator

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵
🧪 PR contains tests
🔒 No security concerns identified
 Recommended focus areas for review

测试导入稳定性

测试文件使用 importlib 动态加载被测模块。如果被测模块 fx_handle.py 内部包含相对导入或依赖特定的包上下文,这种加载方式可能会导致测试失败。建议确认该导入方式在项目中的通用性或改为标准导入。

MODULE_PATH = Path(__file__).resolve().parents[1] / "konabot/plugins/fx_process/fx_handle.py"
SPEC = spec_from_file_location("test_fx_handle_module", MODULE_PATH)
assert SPEC is not None and SPEC.loader is not None
fx_handle = module_from_spec(SPEC)
SPEC.loader.exec_module(fx_handle)
资源管理

BytesIO 对象 output 在使用后未显式关闭。虽然它是内存对象,但建议在使用完毕后调用 output.close() 或使用 with 语句,以遵循资源管理的最佳实践。

output = BytesIO()
rgb_image.save(output, format='JPEG', quality=quality, optimize=False)
output.seek(0)
damaged = Image.open(output).convert('RGB')
## PR Reviewer Guide 🔍 Here are some key observations to aid the review process: <table> <tr><td>⏱️&nbsp;<strong>Estimated effort to review</strong>: 2 🔵🔵⚪⚪⚪</td></tr> <tr><td>🧪&nbsp;<strong>PR contains tests</strong></td></tr> <tr><td>🔒&nbsp;<strong>No security concerns identified</strong></td></tr> <tr><td>⚡&nbsp;<strong>Recommended focus areas for review</strong><br><br> <details><summary><a href='https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/fx-jpeg-damage/tests/test_fx_process.py#L10-L14'><strong>测试导入稳定性</strong></a> 测试文件使用 `importlib` 动态加载被测模块。如果被测模块 `fx_handle.py` 内部包含相对导入或依赖特定的包上下文,这种加载方式可能会导致测试失败。建议确认该导入方式在项目中的通用性或改为标准导入。 </summary> ```python MODULE_PATH = Path(__file__).resolve().parents[1] / "konabot/plugins/fx_process/fx_handle.py" SPEC = spec_from_file_location("test_fx_handle_module", MODULE_PATH) assert SPEC is not None and SPEC.loader is not None fx_handle = module_from_spec(SPEC) SPEC.loader.exec_module(fx_handle) ``` </details> <details><summary><a href='https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/feat/fx-jpeg-damage/konabot/plugins/fx_process/fx_handle.py#L185-L188'><strong>资源管理</strong></a> `BytesIO` 对象 `output` 在使用后未显式关闭。虽然它是内存对象,但建议在使用完毕后调用 `output.close()` 或使用 `with` 语句,以遵循资源管理的最佳实践。 </summary> ```python output = BytesIO() rgb_image.save(output, format='JPEG', quality=quality, optimize=False) output.seek(0) damaged = Image.open(output).convert('RGB') ``` </details> </td></tr> </table>
Passthem merged commit f9a312b80a into master 2026-03-14 01:01:39 +08:00
Passthem reviewed 2026-03-14 01:02:17 +08:00
Passthem left a comment
Owner

我同意

我同意
Passthem requested review from Passthem 2026-03-14 01:02:25 +08:00
Passthem refused to review 2026-03-14 01:02:47 +08:00
Collaborator

Failed to generate code suggestions for PR

Failed to generate code suggestions for PR
Sign in to join this conversation.
No description provided.