diff --git a/ui/designer/components/ocrQueue.ui b/ui/designer/components/ocrQueue.ui index e6deb4b..2c1e9de 100644 --- a/ui/designer/components/ocrQueue.ui +++ b/ui/designer/components/ocrQueue.ui @@ -29,9 +29,9 @@ - + - icc.ignore + icc.useQt diff --git a/ui/designer/components/ocrQueue_ui.py b/ui/designer/components/ocrQueue_ui.py index 459bb67..238e98d 100644 --- a/ui/designer/components/ocrQueue_ui.py +++ b/ui/designer/components/ocrQueue_ui.py @@ -38,10 +38,10 @@ class Ui_OcrQueue(object): self.groupBox.setObjectName(u"groupBox") self.verticalLayout = QVBoxLayout(self.groupBox) self.verticalLayout.setObjectName(u"verticalLayout") - self.iccIgnoreRadioButton = QRadioButton(self.groupBox) - self.iccIgnoreRadioButton.setObjectName(u"iccIgnoreRadioButton") + self.iccUseQtRadioButton = QRadioButton(self.groupBox) + self.iccUseQtRadioButton.setObjectName(u"iccUseQtRadioButton") - self.verticalLayout.addWidget(self.iccIgnoreRadioButton) + self.verticalLayout.addWidget(self.iccUseQtRadioButton) self.iccUsePILRadioButton = QRadioButton(self.groupBox) self.iccUsePILRadioButton.setObjectName(u"iccUsePILRadioButton") @@ -155,7 +155,7 @@ class Ui_OcrQueue(object): def retranslateUi(self, OcrQueue): self.groupBox_3.setTitle(QCoreApplication.translate("OcrQueue", u"queue.title", None)) self.groupBox.setTitle(QCoreApplication.translate("OcrQueue", u"iccOptionsGroupBox", None)) - self.iccIgnoreRadioButton.setText(QCoreApplication.translate("OcrQueue", u"icc.ignore", None)) + self.iccUseQtRadioButton.setText(QCoreApplication.translate("OcrQueue", u"icc.useQt", None)) self.iccUsePILRadioButton.setText(QCoreApplication.translate("OcrQueue", u"icc.usePIL", None)) self.iccTryFixRadioButton.setText(QCoreApplication.translate("OcrQueue", u"icc.tryFix", None)) self.ocr_addImageButton.setText(QCoreApplication.translate("OcrQueue", u"queue.addImageButton", None)) diff --git a/ui/extends/components/ocrQueue.py b/ui/extends/components/ocrQueue.py index 4fb89ed..efcc404 100644 --- a/ui/extends/components/ocrQueue.py +++ b/ui/extends/components/ocrQueue.py @@ -7,7 +7,6 @@ from arcaea_offline.database import Database from arcaea_offline.models import Chart, Score from arcaea_offline_ocr.b30.shared import B30OcrResultItem from arcaea_offline_ocr.device.common import DeviceOcrResult -from arcaea_offline_ocr.utils import convert_to_srgb from PIL import Image from PIL.ImageQt import ImageQt from PySide6.QtCore import ( @@ -25,6 +24,7 @@ from PySide6.QtCore import ( ) from PySide6.QtGui import QImage, QPixmap +from ui.extends.ocr import convert_to_srgb from ui.extends.shared.delegates.chartDelegate import ChartDelegate from ui.extends.shared.delegates.imageDelegate import ImageDelegate from ui.extends.shared.delegates.scoreDelegate import ScoreDelegate @@ -46,7 +46,7 @@ class OcrRunnable(QRunnable): class IccOption(IntEnum): - Ignore = 0 + UseQt = 0 UsePIL = 1 TryFix = 2 diff --git a/ui/extends/ocr/__init__.py b/ui/extends/ocr/__init__.py index bda9d16..1b532b6 100644 --- a/ui/extends/ocr/__init__.py +++ b/ui/extends/ocr/__init__.py @@ -1,28 +1,27 @@ +import io + +from PIL import Image, ImageCms + from .build_phash import build_image_phash_database -try: - import json - from arcaea_offline_ocr.device.v1.definition import DeviceV1 - from arcaea_offline_ocr.device.v2.definition import DeviceV2 +def convert_to_srgb(pil_img: Image.Image): + """ + Convert PIL image to sRGB color space (if possible) + and save the converted file. - def load_devices_json(filepath: str) -> list[DeviceV1]: - with open(filepath, "r", encoding="utf-8") as f: - file_content = f.read() - if len(file_content) == 0: - return [] - content = json.loads(file_content) - assert isinstance(content, list) - devices = [] - for item in content: - version = item["version"] - if version == 1: - devices.append(DeviceV1(**item)) - elif version == 2: - devices.append(DeviceV2(**item)) - return devices + https://stackoverflow.com/a/65667797/16484891 -except Exception: + CC BY-SA 4.0 + """ + icc = pil_img.info.get("icc_profile", "") + icc_conv = "" - def load_devices_json(*args, **kwargs): - pass + if icc: + io_handle = io.BytesIO(icc) # virtual file + src_profile = ImageCms.ImageCmsProfile(io_handle) + dst_profile = ImageCms.createProfile("sRGB") + img_conv = ImageCms.profileToProfile(pil_img, src_profile, dst_profile) + icc_conv = img_conv.info.get("icc_profile", "") + + return img_conv if icc != icc_conv else pil_img diff --git a/ui/implements/components/ocrQueue.py b/ui/implements/components/ocrQueue.py index 2292889..d917afd 100644 --- a/ui/implements/components/ocrQueue.py +++ b/ui/implements/components/ocrQueue.py @@ -43,7 +43,7 @@ class OcrQueue(Ui_OcrQueue, QWidget): self.iccOptionButtonGroup = QButtonGroup(self) self.iccOptionButtonGroup.buttonToggled.connect(self.updateIccOption) - self.iccOptionButtonGroup.addButton(self.iccIgnoreRadioButton, 0) + self.iccOptionButtonGroup.addButton(self.iccUseQtRadioButton, 0) self.iccOptionButtonGroup.addButton(self.iccUsePILRadioButton, 1) self.iccOptionButtonGroup.addButton(self.iccTryFixRadioButton, 2) self.updateIccOption() diff --git a/ui/resources/lang/en_US.ts b/ui/resources/lang/en_US.ts index 5698f4b..60cd6b7 100644 --- a/ui/resources/lang/en_US.ts +++ b/ui/resources/lang/en_US.ts @@ -225,8 +225,8 @@ - icc.ignore - Ignore + icc.useQt + Use Qt @@ -477,12 +477,9 @@ validation - - - - - - + + + resetButton Reset @@ -517,37 +514,22 @@ validation Database URL - + ocr.title OCR - - ocr.devicesJson.label - Default devices.json - - - - ocr.deviceUuid.label - Default device - - - + ocr.knnModelFile.label Default KNearest model - + ocr.b30KnnModelFile.label Default B30 KNearest model - - ocr.siftDatabaseFile.label - Default SIFT database file - - - + ocr.phashDatabaseFile.label Default image PHash database @@ -1201,17 +1183,17 @@ validation Calculate to Step - + calculate.toStep.playResultLabel Play result - + calculate.toStep.calculatePlayResultFromScoreButton Calculate from Score - + calculate.toStep.resultLabel Result @@ -1221,17 +1203,17 @@ validation Detailed log output - + calculate.fromStep Calculate from Step - + calculate.fromStep.targetStepLabel Target step value - + calculate.fromStep.resultLabel Result (play rating) diff --git a/ui/resources/lang/zh_CN.ts b/ui/resources/lang/zh_CN.ts index 5b62aa3..47eb270 100644 --- a/ui/resources/lang/zh_CN.ts +++ b/ui/resources/lang/zh_CN.ts @@ -225,13 +225,13 @@ - icc.ignore - 忽略 + icc.useQt + 使用 Qt icc.usePIL - 使用 PIL 读取 + 使用 PIL @@ -476,12 +476,9 @@ - - - - - - + + + resetButton 重置 @@ -516,37 +513,22 @@ 数据库 URL - + ocr.title OCR - - ocr.devicesJson.label - 默认设备定义文件 - - - - ocr.deviceUuid.label - 默认设备 - - - + ocr.knnModelFile.label 默认 KNearest 模型 - + ocr.b30KnnModelFile.label 默认 B30 KNearest 模型 - - ocr.siftDatabaseFile.label - 默认 SIFT 特征值数据库 - - - + ocr.phashDatabaseFile.label 默认图像 PHash 数据库 @@ -1200,17 +1182,17 @@ 正算 - + calculate.toStep.playResultLabel 单曲 PTT - + calculate.toStep.calculatePlayResultFromScoreButton 从分数计算 - + calculate.toStep.resultLabel 结果 @@ -1220,17 +1202,17 @@ 详细日志输出 - + calculate.fromStep 逆算 - + calculate.fromStep.targetStepLabel 目标 STEP 值 - + calculate.fromStep.resultLabel 结果(单曲 PTT)