From 1697aa3e4b87d375b77d3d4a15706c44567255cf Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Wed, 18 Dec 2024 19:49:53 +0300 Subject: [PATCH] fixed RUFFs RUF052 Signed-off-by: Alexander Piskun --- libheif/linux_build_libs.py | 82 ++++++++++++------------- pillow_heif/as_plugin.py | 32 +++++----- pillow_heif/heif.py | 118 ++++++++++++++++++------------------ pillow_heif/misc.py | 71 +++++++++++----------- tests/metadata_exif_test.py | 6 +- tests/orientation_test.py | 16 ++--- 6 files changed, 161 insertions(+), 164 deletions(-) diff --git a/libheif/linux_build_libs.py b/libheif/linux_build_libs.py index b21a5b60..617a3b11 100644 --- a/libheif/linux_build_libs.py +++ b/libheif/linux_build_libs.py @@ -50,13 +50,13 @@ def download_file(url: str, out_path: str) -> bool: def download_extract_to(url: str, out_path: str, strip: bool = True): makedirs(out_path, exist_ok=True) - _archive_path = path.join(out_path, "download.tar.gz") - download_file(url, _archive_path) - _tar_cmd = f"tar -xf {_archive_path} -C {out_path}" + archive_path = path.join(out_path, "download.tar.gz") + download_file(url, archive_path) + tar_cmd = f"tar -xf {archive_path} -C {out_path}" if strip: - _tar_cmd += " --strip-components 1" - run(_tar_cmd.split(), check=True) - remove(_archive_path) + tar_cmd += " --strip-components 1" + run(tar_cmd.split(), check=True) + remove(archive_path) def tool_check_version(name: str, min_version: str) -> bool: @@ -64,8 +64,8 @@ def tool_check_version(name: str, min_version: str) -> bool: _ = run([name, "--version"], stdout=PIPE, stderr=DEVNULL, check=True) except (CalledProcessError, FileNotFoundError): return False - _regexp = r"version\s*(\d+(\.\d+){2})" if name == "nasm" else r"(\d+(\.\d+){2})$" # cmake - m_groups = search(_regexp, _.stdout.decode("utf-8"), flags=MULTILINE + IGNORECASE) + v_regexp = r"version\s*(\d+(\.\d+){2})" if name == "nasm" else r"(\d+(\.\d+){2})$" # cmake + m_groups = search(v_regexp, _.stdout.decode("utf-8"), flags=MULTILINE + IGNORECASE) if m_groups is None: return False current_version = tuple(map(int, str(m_groups.groups()[0]).split("."))) @@ -82,18 +82,18 @@ def check_install_nasm(version: str): if tool_check_version("nasm", version): return True print(f"Can not find `nasm` with version >={version}, installing...") - _tool_path = path.join(BUILD_DIR, "nasm") - if path.isdir(_tool_path): + tool_path = path.join(BUILD_DIR, "nasm") + if path.isdir(tool_path): print("Cache found for nasm", flush=True) - chdir(_tool_path) + chdir(tool_path) else: - download_extract_to(f"https://www.nasm.us/pub/nasm/releasebuilds/{version}/nasm-{version}.tar.gz", _tool_path) - chdir(_tool_path) + download_extract_to(f"https://www.nasm.us/pub/nasm/releasebuilds/{version}/nasm-{version}.tar.gz", tool_path) + chdir(tool_path) run(["./configure"], check=True) run("make".split(), check=True) run("make install".split(), check=True) run("nasm --version".split(), check=True) - run(f"chmod -R 774 {_tool_path}".split(), check=True) + run(f"chmod -R 774 {tool_path}".split(), check=True) return True @@ -105,10 +105,10 @@ def is_musllinux() -> bool: def is_library_installed(name: str) -> bool: if name.find("main") != -1 and name.find("reference") != -1: raise Exception("`name` param can not contain `main` and `reference` substrings.") - _r = run(f"gcc -l{name}".split(), stdout=PIPE, stderr=STDOUT, check=False) - if _r.stdout: - _ = _r.stdout.decode("utf-8") - if _.find("main") != -1 and _.find("reference") != -1: + result = run(f"gcc -l{name}".split(), stdout=PIPE, stderr=STDOUT, check=False) + if result.stdout: + decoded_result = result.stdout.decode("utf-8") + if decoded_result.find("main") != -1 and decoded_result.find("reference") != -1: return True return False @@ -121,43 +121,43 @@ def run_print_if_error(args) -> None: def build_lib_linux(url: str, name: str): - _lib_path = path.join(BUILD_DIR, name) - if path.isdir(_lib_path): + lib_path = path.join(BUILD_DIR, name) + if path.isdir(lib_path): print(f"Cache found for {name}", flush=True) - chdir(path.join(_lib_path, "build")) if name != "x265" else chdir(_lib_path) + chdir(path.join(lib_path, "build")) if name != "x265" else chdir(lib_path) else: - _hide_build_process = True - _script_dir = path.dirname(path.abspath(__file__)) - _linux_dir = path.join(_script_dir, "linux") + hide_build_process = True + script_dir = path.dirname(path.abspath(__file__)) + linux_dir = path.join(script_dir, "linux") if name == "x265": - download_extract_to(url, _lib_path) - chdir(_lib_path) + download_extract_to(url, lib_path) + chdir(lib_path) else: - _build_path = path.join(_lib_path, "build") - makedirs(_build_path) + build_path = path.join(lib_path, "build") + makedirs(build_path) if name == "aom": - download_extract_to(url, path.join(_lib_path, "aom"), False) + download_extract_to(url, path.join(lib_path, "aom"), False) if is_musllinux(): - patch_path = path.join(_linux_dir, "aom-musl/fix-stack-size-e53da0b-2.patch") - chdir(path.join(_lib_path, "aom")) + patch_path = path.join(linux_dir, "aom-musl/fix-stack-size-e53da0b-2.patch") + chdir(path.join(lib_path, "aom")) run(f"patch -p 1 -i {patch_path}".split(), check=True) else: - download_extract_to(url, _lib_path) + download_extract_to(url, lib_path) if name == "libde265": # noqa - chdir(_lib_path) + chdir(lib_path) # for patch in ( # "libde265/CVE-2022-1253.patch", # ): - # patch_path = path.join(_linux_dir, patch) + # patch_path = path.join(linux_dir, patch) # run(f"patch -p 1 -i {patch_path}".split(), check=True) elif name == "libheif": - chdir(_lib_path) + chdir(lib_path) # for patch in ( # "libheif/001-void-unused-variable.patch", # ): - # patch_path = path.join(_linux_dir, patch) + # patch_path = path.join(linux_dir, patch) # run(f"patch -p 1 -i {patch_path}".split(), check=True) - chdir(_build_path) + chdir(build_path) print(f"Preconfiguring {name}...", flush=True) if name == "aom": cmake_args = "-DENABLE_TESTS=0 -DENABLE_TOOLS=0 -DENABLE_EXAMPLES=0 -DENABLE_DOCS=0".split() @@ -215,12 +215,12 @@ def build_lib_linux(url: str, name: str): "-DWITH_EXAMPLES=OFF " "-DBUILD_TESTING=OFF".split() ) - _hide_build_process = False + hide_build_process = False if is_musllinux(): cmake_args += [f"-DCMAKE_INSTALL_LIBDIR={INSTALL_DIR_LIBS}/lib"] run(["cmake", *cmake_args], check=True) print(f"{name} configured. building...", flush=True) - if _hide_build_process: + if hide_build_process: run_print_if_error("make -j4".split()) else: run("make -j4".split(), check=True) @@ -233,7 +233,7 @@ def build_lib_linux(url: str, name: str): def build_libs() -> None: - _original_dir = getcwd() + original_dir = getcwd() try: if not tool_check_version("cmake", "3.16.3"): raise ValueError("Can not find `cmake` with version >=3.16.3") @@ -257,7 +257,7 @@ def build_libs() -> None: print("libde265 already installed.") build_lib_linux(LIBHEIF_URL, "libheif") finally: - chdir(_original_dir) + chdir(original_dir) if __name__ == "__main__": diff --git a/pillow_heif/as_plugin.py b/pillow_heif/as_plugin.py index 324d6430..a443f4e3 100644 --- a/pillow_heif/as_plugin.py +++ b/pillow_heif/as_plugin.py @@ -45,12 +45,12 @@ def __init__(self, *args, **kwargs): def _open(self): try: # when Pillow starts supporting 16-bit multichannel images change `convert_hdr_to_8bit` to False - _heif_file = HeifFile(self.fp, convert_hdr_to_8bit=True, hdr_to_16bit=True, remove_stride=False) + heif_file = HeifFile(self.fp, convert_hdr_to_8bit=True, hdr_to_16bit=True, remove_stride=False) except (OSError, ValueError, SyntaxError, RuntimeError, EOFError) as exception: raise SyntaxError(str(exception)) from None - self.custom_mimetype = _heif_file.mimetype - self._heif_file = _heif_file - self.__frame = _heif_file.primary_index + self.custom_mimetype = heif_file.mimetype + self._heif_file = heif_file + self.__frame = heif_file.primary_index self._init_from_heif_file(self.__frame) self.tile = [] @@ -100,9 +100,9 @@ def seek(self, frame: int): # https://github.com/python-pillow/Pillow/issues/8439 self.im = Image.core.new(self._mode, self._size) # pylint: disable=too-many-function-args - _exif = getattr(self, "_exif", None) # Pillow 9.2+ do no reload exif between frames. - if _exif is not None and getattr(_exif, "_loaded", None): - _exif._loaded = False # pylint: disable=protected-access + exif = getattr(self, "_exif", None) # Pillow 9.2+ do no reload exif between frames. + if exif is not None and getattr(exif, "_loaded", None): + exif._loaded = False # pylint: disable=protected-access def tell(self) -> int: return self.__frame @@ -269,15 +269,13 @@ def __save_all(im: Image.Image, fp: IO[bytes], compression_format: HeifCompressi def _pil_encode_image(ctx: CtxEncode, img: Image.Image, primary: bool, **kwargs) -> None: if img.size[0] <= 0 or img.size[1] <= 0: raise ValueError("Empty images are not supported.") - _info = img.info.copy() - _info["exif"] = _exif_from_pillow(img) - _info["xmp"] = _xmp_from_pillow(img) - _info.update(**kwargs) - _info["primary"] = primary + info = img.info.copy() + info["exif"] = _exif_from_pillow(img) + info["xmp"] = _xmp_from_pillow(img) + info.update(**kwargs) + info["primary"] = primary if img.mode == "YCbCr": - ctx.add_image_ycbcr(img, image_orientation=_get_orientation_for_encoder(_info), **_info) + ctx.add_image_ycbcr(img, image_orientation=_get_orientation_for_encoder(info), **info) else: - _img = _pil_to_supported_mode(img) - ctx.add_image( - _img.size, _img.mode, _img.tobytes(), image_orientation=_get_orientation_for_encoder(_info), **_info - ) + img = _pil_to_supported_mode(img) + ctx.add_image(img.size, img.mode, img.tobytes(), image_orientation=_get_orientation_for_encoder(info), **info) diff --git a/pillow_heif/heif.py b/pillow_heif/heif.py index ddecd1b4..1c1b1eb3 100644 --- a/pillow_heif/heif.py +++ b/pillow_heif/heif.py @@ -120,9 +120,9 @@ class HeifDepthImage(BaseImage): def __init__(self, c_image): super().__init__(c_image) - _metadata: dict = c_image.metadata + metadata: dict = c_image.metadata self.info = { - "metadata": _metadata, + "metadata": metadata, } save_colorspace_chroma(c_image, self.info) @@ -151,48 +151,48 @@ class HeifImage(BaseImage): def __init__(self, c_image): super().__init__(c_image) - _metadata: list[dict] = c_image.metadata - _exif = _retrieve_exif(_metadata) - _xmp = _retrieve_xmp(_metadata) - _thumbnails: list[int | None] = [i for i in c_image.thumbnails if i is not None] if options.THUMBNAILS else [] - _depth_images: list[HeifDepthImage | None] = ( + metadata: list[dict] = c_image.metadata + exif = _retrieve_exif(metadata) + xmp = _retrieve_xmp(metadata) + thumbnails: list[int | None] = [i for i in c_image.thumbnails if i is not None] if options.THUMBNAILS else [] + depth_images: list[HeifDepthImage | None] = ( [HeifDepthImage(i) for i in c_image.depth_image_list if i is not None] if options.DEPTH_IMAGES else [] ) self.info = { "primary": bool(c_image.primary), "bit_depth": int(c_image.bit_depth), - "exif": _exif, - "metadata": _metadata, - "thumbnails": _thumbnails, - "depth_images": _depth_images, + "exif": exif, + "metadata": metadata, + "thumbnails": thumbnails, + "depth_images": depth_images, } if options.AUX_IMAGES: - _ctx_aux_info = {} + ctx_aux_info = {} for aux_id in c_image.aux_image_ids: aux_type = c_image.get_aux_type(aux_id) - if aux_type not in _ctx_aux_info: - _ctx_aux_info[aux_type] = [] - _ctx_aux_info[aux_type].append(aux_id) - self.info["aux"] = _ctx_aux_info - _heif_meta = _get_heif_meta(c_image) - if _xmp: - self.info["xmp"] = _xmp - if _heif_meta: - self.info["heif"] = _heif_meta + if aux_type not in ctx_aux_info: + ctx_aux_info[aux_type] = [] + ctx_aux_info[aux_type].append(aux_id) + self.info["aux"] = ctx_aux_info + heif_meta = _get_heif_meta(c_image) + if xmp: + self.info["xmp"] = xmp + if heif_meta: + self.info["heif"] = heif_meta save_colorspace_chroma(c_image, self.info) - _color_profile: dict[str, Any] = c_image.color_profile - if _color_profile: - if _color_profile["type"] in ("rICC", "prof"): - self.info["icc_profile"] = _color_profile["data"] - self.info["icc_profile_type"] = _color_profile["type"] + color_profile: dict[str, Any] = c_image.color_profile + if color_profile: + if color_profile["type"] in ("rICC", "prof"): + self.info["icc_profile"] = color_profile["data"] + self.info["icc_profile_type"] = color_profile["type"] else: - self.info["nclx_profile"] = _color_profile["data"] + self.info["nclx_profile"] = color_profile["data"] def __repr__(self): - _bytes = f"{len(self.data)} bytes" if self._data or isinstance(self._c_image, MimCImage) else "no" + s_bytes = f"{len(self.data)} bytes" if self._data or isinstance(self._c_image, MimCImage) else "no" return ( f"<{self.__class__.__name__} {self.size[0]}x{self.size[1]} {self.mode} " - f"with {_bytes} image data and {len(self.info.get('thumbnails', []))} thumbnails>" + f"with {s_bytes} image data and {len(self.info.get('thumbnails', []))} thumbnails>" ) @property @@ -449,20 +449,20 @@ def add_from_pillow(self, image: Image.Image) -> HeifImage: """ if image.size[0] <= 0 or image.size[1] <= 0: raise ValueError("Empty images are not supported.") - _info = image.info.copy() - _info["exif"] = _exif_from_pillow(image) - _xmp = _xmp_from_pillow(image) - if _xmp: - _info["xmp"] = _xmp - original_orientation = set_orientation(_info) - _img = _pil_to_supported_mode(image) + info = image.info.copy() + info["exif"] = _exif_from_pillow(image) + xmp = _xmp_from_pillow(image) + if xmp: + info["xmp"] = xmp + original_orientation = set_orientation(info) + img = _pil_to_supported_mode(image) if original_orientation is not None and original_orientation != 1: - _img = _rotate_pil(_img, original_orientation) - _img.load() + img = _rotate_pil(img, original_orientation) + img.load() added_image = self.add_frombytes( - _img.mode, - _img.size, - _img.tobytes(), + img.mode, + img.size, + img.tobytes(), ) for key in ["bit_depth", "thumbnails", "icc_profile", "icc_profile_type"]: if key in image.info: @@ -471,9 +471,9 @@ def add_from_pillow(self, image: Image.Image) -> HeifImage: if key in image.info: added_image.info[key] = deepcopy(image.info[key]) added_image.info["exif"] = _exif_from_pillow(image) - _xmp = _xmp_from_pillow(image) - if _xmp: - added_image.info["xmp"] = _xmp + im_xmp = _xmp_from_pillow(image) + if im_xmp: + added_image.info["xmp"] = im_xmp return added_image @property @@ -497,11 +497,11 @@ def __setstate__(self, state): added_image.info = im_info def __copy(self): - _im_copy = HeifFile() - _im_copy._images = copy(self._images) # pylint: disable=protected-access - _im_copy.mimetype = self.mimetype - _im_copy.primary_index = self.primary_index - return _im_copy + im_copy = HeifFile() + im_copy._images = copy(self._images) # pylint: disable=protected-access + im_copy.mimetype = self.mimetype + im_copy.primary_index = self.primary_index + return im_copy def get_aux_image(self, aux_id): """`get_aux_image`` method of the primary :class:`~pillow_heif.HeifImage` in the container. @@ -522,10 +522,10 @@ def is_supported(fp) -> bool: :returns: A boolean indicating if the object can be opened. """ - __data = _get_bytes(fp, 12) - if __data[4:8] != b"ftyp": + f_data = _get_bytes(fp, 12) + if f_data[4:8] != b"ftyp": return False - return get_file_mimetype(__data) != "" + return get_file_mimetype(f_data) != "" def open_heif(fp, convert_hdr_to_8bit=True, bgr_mode=False, **kwargs) -> HeifFile: @@ -603,18 +603,18 @@ def _encode_images(images: list[HeifImage], fp, **kwargs) -> None: ctx_write = CtxEncode(compression_format, **kwargs) for i, img in enumerate(images_to_save): img.load() - _info = img.info.copy() - _info["primary"] = False + info = img.info.copy() + info["primary"] = False if i == primary_index: - _info.update(**kwargs) - _info["primary"] = True - _info.pop("stride", 0) + info.update(**kwargs) + info["primary"] = True + info.pop("stride", 0) ctx_write.add_image( img.size, img.mode, img.data, - image_orientation=_get_orientation_for_encoder(_info), - **_info, + image_orientation=_get_orientation_for_encoder(info), + **info, stride=img.stride, ) ctx_write.save(fp) diff --git a/pillow_heif/misc.py b/pillow_heif/misc.py index 08c01e73..21b4d57e 100644 --- a/pillow_heif/misc.py +++ b/pillow_heif/misc.py @@ -160,9 +160,9 @@ def _get_orientation(info: dict, reset: bool = False) -> int | None: if unpack(endian_mark + "H", tif_tag[pointer : pointer + 2])[0] != 274: continue value = tif_tag[pointer + 8 : pointer + 12] - _original_orientation = unpack(endian_mark + "H", value[0:2])[0] - if _original_orientation != 1: - original_orientation = _original_orientation + t_original_orientation = unpack(endian_mark + "H", value[0:2])[0] + if t_original_orientation != 1: + original_orientation = t_original_orientation if not reset: break p_value = pointer + 8 @@ -217,36 +217,36 @@ def _get_bytes(fp, length=None) -> bytes: def _retrieve_exif(metadata: list[dict]) -> bytes | None: - _result = None - _purge = [] + result = None + purge = [] for i, md_block in enumerate(metadata): if md_block["type"] == "Exif": - _purge.append(i) + purge.append(i) skip_size = int.from_bytes(md_block["data"][:4], byteorder="big", signed=False) skip_size += 4 # skip 4 bytes with offset if len(md_block["data"]) - skip_size <= 4: # bad EXIF data, skip first 4 bytes skip_size = 4 elif skip_size >= 6 and md_block["data"][skip_size - 6 : skip_size] == b"Exif\x00\x00": skip_size -= 6 - _data = md_block["data"][skip_size:] - if not _result and _data: - _result = _data - for i in reversed(_purge): + data = md_block["data"][skip_size:] + if not result and data: + result = data + for i in reversed(purge): del metadata[i] - return _result + return result def _retrieve_xmp(metadata: list[dict]) -> bytes | None: - _result = None - _purge = [] + result = None + purge = [] for i, md_block in enumerate(metadata): if md_block["type"] == "mime": - _purge.append(i) - if not _result: + purge.append(i) + if not result: _result = md_block["data"] - for i in reversed(_purge): + for i in reversed(purge): del metadata[i] - return _result + return result def _exif_from_pillow(img: Image.Image) -> bytes | None: @@ -260,24 +260,24 @@ def _exif_from_pillow(img: Image.Image) -> bytes | None: def _xmp_from_pillow(img: Image.Image) -> bytes | None: - _xmp = None + im_xmp = None if "xmp" in img.info: - _xmp = img.info["xmp"] + im_xmp = img.info["xmp"] elif "XML:com.adobe.xmp" in img.info: # PNG - _xmp = img.info["XML:com.adobe.xmp"] + im_xmp = img.info["XML:com.adobe.xmp"] elif hasattr(img, "tag_v2"): # TIFF if 700 in img.tag_v2: - _xmp = img.tag_v2[700] + im_xmp = img.tag_v2[700] elif hasattr(img, "applist"): # JPEG for segment, content in img.applist: if segment == "APP1": marker, xmp_tags = content.rsplit(b"\x00", 1) if marker == b"http://ns.adobe.com/xap/1.0/": - _xmp = xmp_tags + im_xmp = xmp_tags break - if isinstance(_xmp, str): - _xmp = _xmp.encode("utf-8") - return _xmp + if isinstance(im_xmp, str): + _xmp = im_xmp.encode("utf-8") + return im_xmp def _pil_to_supported_mode(img: Image.Image) -> Image.Image: @@ -353,12 +353,12 @@ def __get_camera_intrinsic_matrix(values: tuple | None): def _get_heif_meta(c_image) -> dict: r = {} - _camera_intrinsic_matrix = __get_camera_intrinsic_matrix(c_image.camera_intrinsic_matrix) - if _camera_intrinsic_matrix: - r["camera_intrinsic_matrix"] = _camera_intrinsic_matrix - _camera_extrinsic_matrix_rot = c_image.camera_extrinsic_matrix_rot - if _camera_extrinsic_matrix_rot: - r["camera_extrinsic_matrix_rot"] = _camera_extrinsic_matrix_rot + camera_intrinsic_matrix = __get_camera_intrinsic_matrix(c_image.camera_intrinsic_matrix) + if camera_intrinsic_matrix: + r["camera_intrinsic_matrix"] = camera_intrinsic_matrix + camera_extrinsic_matrix_rot = c_image.camera_extrinsic_matrix_rot + if camera_extrinsic_matrix_rot: + r["camera_extrinsic_matrix_rot"] = camera_extrinsic_matrix_rot return r @@ -381,8 +381,7 @@ def __init__(self, compression_format: HeifCompressionFormat, **kwargs): if chroma: enc_params["chroma"] = chroma for key, value in enc_params.items(): - _value = value if isinstance(value, str) else str(value) - self.ctx_write.set_parameter(key, _value) + self.ctx_write.set_parameter(key, value if isinstance(value, str) else str(value)) def add_image(self, size: tuple[int, int], mode: str, data, **kwargs) -> None: """Adds image to the encoder.""" @@ -415,9 +414,9 @@ def add_image_ycbcr(self, img: Image.Image, **kwargs) -> None: def _finish_add_image(self, im_out, size: tuple[int, int], **kwargs): # set ICC color profile - __icc_profile = kwargs.get("icc_profile") - if __icc_profile is not None: - im_out.set_icc_profile(kwargs.get("icc_profile_type", "prof"), __icc_profile) + icc_profile = kwargs.get("icc_profile") + if icc_profile is not None: + im_out.set_icc_profile(kwargs.get("icc_profile_type", "prof"), icc_profile) # set NCLX color profile if kwargs.get("nclx_profile"): im_out.set_nclx_profile( diff --git a/tests/metadata_exif_test.py b/tests/metadata_exif_test.py index d346c611..179ba7f7 100644 --- a/tests/metadata_exif_test.py +++ b/tests/metadata_exif_test.py @@ -25,10 +25,10 @@ ) def test_exif_from_pillow(im_format, save_format): def pil_image_with_exif(): - _exif = Image.Exif() - _exif[0x010E] = exif_desc_value + im_exif = Image.Exif() + im_exif[0x010E] = exif_desc_value _ = BytesIO() - Image.new("RGB", (16, 16), 0).save(_, format=im_format, exif=_exif) + Image.new("RGB", (16, 16), 0).save(_, format=im_format, exif=im_exif) return _ exif_desc_value = "this is a desc" diff --git a/tests/orientation_test.py b/tests/orientation_test.py index 98c85ddf..19010549 100644 --- a/tests/orientation_test.py +++ b/tests/orientation_test.py @@ -103,8 +103,8 @@ def test_heif_exif_orientation(orientation): assert im_heif.info["original_orientation"] == orientation im_heif_exif = im_heif.getexif() assert 0x0112 not in im_heif_exif or im_heif_exif[0x0112] == 1 - _im = pillow_heif.misc._rotate_pil(im, orientation) - assert_image_similar(_im, im_heif) + im_result = pillow_heif.misc._rotate_pil(im, orientation) + assert_image_similar(im_result, im_heif) @pytest.mark.skipif(not hevc_enc(), reason="Requires HEVC encoder.") @@ -117,12 +117,12 @@ def test_heif_xmp_orientation(orientation): # Image will be automatically rotated by XMP value before saving. im.save(out_im_heif, format="HEIF", xmp=xmp.encode("utf-8"), quality=-1) im_heif = Image.open(out_im_heif) - _im = pillow_heif.misc._rotate_pil(im, orientation) + im_result = pillow_heif.misc._rotate_pil(im, orientation) if orientation == 1: assert im_heif.info["original_orientation"] is None else: assert im_heif.info["original_orientation"] == orientation - assert_image_similar(_im, im_heif) + assert_image_similar(im_result, im_heif) @pytest.mark.skipif(not hevc_enc(), reason="Requires HEVC encoder.") @@ -135,12 +135,12 @@ def test_heif_xmp_orientation_exiftool(orientation): # Image will be automatically rotated by EXIF value before saving. im.save(out_im_heif, format="HEIF", xmp=xmp.encode("utf-8"), quality=-1) im_heif = Image.open(out_im_heif) - _im = pillow_heif.misc._rotate_pil(im, orientation) + im_result = pillow_heif.misc._rotate_pil(im, orientation) if orientation != 1: assert im_heif.info["original_orientation"] == orientation else: assert im_heif.info["original_orientation"] is None - assert_image_similar(_im, im_heif) + assert_image_similar(im_result, im_heif) @pytest.mark.skipif(not hevc_enc(), reason="Requires HEVC encoder.") @@ -155,12 +155,12 @@ def test_heif_xmp_orientation_with_exif_eq_1(orientation): # Image will be automatically rotated by XMP value before saving. im.save(out_im_heif, format="HEIF", exif=exif_data.tobytes(), xmp=xmp.encode("utf-8"), quality=-1) im_heif = Image.open(out_im_heif) - _im = pillow_heif.misc._rotate_pil(im, orientation) + im_result = pillow_heif.misc._rotate_pil(im, orientation) if orientation != 1: assert im_heif.info["original_orientation"] == orientation else: assert im_heif.info["original_orientation"] is None - assert_image_similar(_im, im_heif) + assert_image_similar(im_result, im_heif) @pytest.mark.skipif(not hevc_enc(), reason="Requires HEVC encoder.")