mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-07-01 12:26:26 +00:00
chore: minor improvements
This commit is contained in:
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user