From 3400df2d522e9823977452520e53fa9cdfa5a487 Mon Sep 17 00:00:00 2001 From: 283375 Date: Thu, 12 Oct 2023 18:08:54 +0800 Subject: [PATCH] refactor!: remove `utils.convert_to_srgb` --- src/arcaea_offline_ocr/utils.py | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/arcaea_offline_ocr/utils.py b/src/arcaea_offline_ocr/utils.py index d7466d2..9fa9390 100644 --- a/src/arcaea_offline_ocr/utils.py +++ b/src/arcaea_offline_ocr/utils.py @@ -1,10 +1,8 @@ -import io from collections.abc import Iterable from typing import Callable, TypeVar, Union, overload import cv2 import numpy as np -from PIL import Image, ImageCms from .types import XYWHRect @@ -46,25 +44,3 @@ def apply_factor(item, factor: float): return item * factor elif isinstance(item, Iterable): return item.__class__([i * factor for i in item]) - - -def convert_to_srgb(pil_img: Image.Image): - """ - Convert PIL image to sRGB color space (if possible) - and save the converted file. - - https://stackoverflow.com/a/65667797/16484891 - - CC BY-SA 4.0 - """ - icc = pil_img.info.get("icc_profile", "") - icc_conv = "" - - 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