From faacebf20fab79f76b4b44eaf9194c69085b5b50 Mon Sep 17 00:00:00 2001 From: themanyfaceddemon Date: Sun, 28 Jul 2024 15:56:20 +0300 Subject: [PATCH] Revert "Texture cleanup" This reverts commit 3c17de27339f316d7a132077f38fbabc7964f161. --- Code/systems/texture_system/__init__.py | 1 - Code/systems/texture_system/texture_system.py | 51 ++++++++----------- Tests/Texture/TextureSystem.py | 2 +- requirements.txt | 1 - 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/Code/systems/texture_system/__init__.py b/Code/systems/texture_system/__init__.py index a3efc7d..76df2f1 100644 --- a/Code/systems/texture_system/__init__.py +++ b/Code/systems/texture_system/__init__.py @@ -1,2 +1 @@ -from systems.texture_system.texture import Texture from systems.texture_system.texture_system import TextureSystem diff --git a/Code/systems/texture_system/texture_system.py b/Code/systems/texture_system/texture_system.py index 487a3eb..0b101e0 100644 --- a/Code/systems/texture_system/texture_system.py +++ b/Code/systems/texture_system/texture_system.py @@ -3,7 +3,6 @@ import pickle from typing import Any, Dict, List, Optional, Tuple, Union -import numpy as np import yaml from PIL import Image, ImageSequence @@ -43,19 +42,16 @@ def _slice_image(image: Image.Image, frame_width: int, frame_height: int, num_fr List[Image.Image]: Список кадров. """ frames = [] - image_width, image_height = image.size + image_width, _ = image.size for i in range(num_frames): + row = (i * frame_width) // image_width col = (i * frame_width) % image_width - row = (i * frame_width) // image_width * frame_height - box = (col, row, col + frame_width, row + frame_height) - - if box[3] > image_height: - break - - frame = image.crop(box).convert("RGBA") + box = (col, row * frame_height, col + frame_width, row * frame_height + frame_height) + frame = image.crop(box) + frame = frame.convert("RGBA") frames.append(frame) - + return frames @staticmethod @@ -173,25 +169,22 @@ def get_image_recolor(path: str, state: str, color: Tuple[int, int, int, int] = image = TextureSystem._get_compiled(path, state, color, False) if image: return image - - with Image.open(f"{path}/{state}.png") as img: - img = img.convert("RGBA") - img_data = np.array(img) - - # Создание маски для непрозрачных пикселей - mask = img_data[:, :, 3] != 0 - - # Применение цвета к пикселям - img_data[mask] = ( - img_data[mask, 0] * color[0] // 255, - img_data[mask, 0] * color[1] // 255, - img_data[mask, 0] * color[2] // 255, - img_data[mask, 3] - ) - - new_img = Image.fromarray(img_data, 'RGBA') - new_img.save(f"{path}/{state}_compiled_{TextureSystem._get_color_str(color)}.png") - return new_img + + with Image.open(f"{path}/{state}.png") as image: + image = image.convert("RGBA") + new_colored_image = [ + ( + int(pixel[0] * color[0] / 255), + int(pixel[0] * color[1] / 255), + int(pixel[0] * color[2] / 255), + pixel[3] + ) if pixel[3] != 0 else pixel + for pixel in image.getdata() + ] + + image.putdata(new_colored_image) + image.save(f"{path}/{state}_compiled_{TextureSystem._get_color_str(color)}.png") + return image @staticmethod def get_image(path: str, state: str) -> Image.Image: diff --git a/Tests/Texture/TextureSystem.py b/Tests/Texture/TextureSystem.py index 62751e4..e9e54c2 100644 --- a/Tests/Texture/TextureSystem.py +++ b/Tests/Texture/TextureSystem.py @@ -7,7 +7,7 @@ import yaml from PIL import Image -from Code.systems.texture_system import TextureSystem +from Code.texture_system import TextureSystem class TestTextureSystem(unittest.TestCase): diff --git a/requirements.txt b/requirements.txt index fc0232e..2a91214 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,3 @@ Pillow PyQt6 PyYAML requests -numpy