Skip to content

Commit

Permalink
Revert "Texture cleanup"
Browse files Browse the repository at this point in the history
This reverts commit 3c17de2.
  • Loading branch information
themanyfaceddemon committed Jul 28, 2024
1 parent f547ae5 commit faacebf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 32 deletions.
1 change: 0 additions & 1 deletion Code/systems/texture_system/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from systems.texture_system.texture import Texture
from systems.texture_system.texture_system import TextureSystem
51 changes: 22 additions & 29 deletions Code/systems/texture_system/texture_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Tests/Texture/TextureSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ Pillow
PyQt6
PyYAML
requests
numpy

0 comments on commit faacebf

Please sign in to comment.