From b79d45cf3423799c8d9dae8627c4767acc5cff5b Mon Sep 17 00:00:00 2001 From: jeremygan2021 Date: Thu, 5 Mar 2026 21:27:12 +0800 Subject: [PATCH] t --- convert_img.py | 7 ++++++- websocket_server/convert_img.py | 5 ++++- websocket_server/server.py | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/convert_img.py b/convert_img.py index 37abba2..2f09b1f 100644 --- a/convert_img.py +++ b/convert_img.py @@ -3,7 +3,7 @@ from machine import UART from config import ttl_tx, ttl_rx from printer_driver import TsplPrinter -def print_bitmap(printer, data, width, height, x_offset=0, y_offset=0): +def print_bitmap(printer, data, width, height, x_offset=0, y_offset=0, invert=False): """ 发送位图数据到打印机 :param printer: TsplPrinter 对象 @@ -12,7 +12,12 @@ def print_bitmap(printer, data, width, height, x_offset=0, y_offset=0): :param height: 图像高度 (dots) :param x_offset: X轴偏移 :param y_offset: Y轴偏移 + :param invert: 是否反色打印 (默认False) """ + if invert: + # 反转每一个字节 + data = bytearray([~b & 0xFF for b in data]) + width_bytes = (width + 7) // 8 # TSPL BITMAP 指令 diff --git a/websocket_server/convert_img.py b/websocket_server/convert_img.py index 71c6694..b62f20c 100644 --- a/websocket_server/convert_img.py +++ b/websocket_server/convert_img.py @@ -59,7 +59,10 @@ def image_to_tspl_commands(image_path): # 白色像素(255) -> 不打印(0) should_print = False - if pixel == 0: # Black + # 修正: 用户反馈打印颜色相反 + # 原逻辑: pixel==0(黑) -> 1. 结果: 黑底白猫 (反色) + # 新逻辑: pixel!=0(白) -> 1. + if pixel != 0: should_print = True if should_print: diff --git a/websocket_server/server.py b/websocket_server/server.py index 4e26954..c274994 100644 --- a/websocket_server/server.py +++ b/websocket_server/server.py @@ -539,7 +539,8 @@ def optimize_prompt(asr_text, progress_callback=None): 4. 背景必须是纯白 (White background)。 5. 提示词内容请使用英文描述,因为绘图模型对英文理解更好,但在描述中强调 "black and white line art", "simple lines", "vector style"。 6. 尺寸比例遵循宽48mm:高30mm (约 1.6:1)。 -7. 直接输出优化后的提示词,不要包含任何解释。""" +7. 直接输出优化后的提示词,不要包含任何解释。 +如果用户要求输入文字,则用双引号把文字包裹起来,文字是中文""" try: if progress_callback: