mirror of
https://github.com/Xevion/v6-place.git
synced 2025-12-09 14:09:09 -06:00
Add environment constants file, fix pixel differencing function
This commit is contained in:
5
constants.py
Normal file
5
constants.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
class Environment:
|
||||||
|
WEBSOCKET_ADDRESS = "WEBSOCKET_ADDRESS"
|
||||||
|
CANVAS_WIDTH = "CANVAS_WIDTH"
|
||||||
|
CANVAS_HEIGHT = "CANVAS_HEIGHT"
|
||||||
|
SOURCE_FILE = "SOURCE_FILE"
|
||||||
@@ -1,20 +1,13 @@
|
|||||||
from typing import List, Tuple
|
import os
|
||||||
from pixel_types import RGB
|
from typing import List
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
from constants import Environment
|
||||||
def overlay_transparent(source: Image, layer: Image, differences: bool = False) -> List[Tuple[int, int]]:
|
from pixel_types import Pixel
|
||||||
"""
|
|
||||||
Given an image, it wil be modified in-place to layer a (potentially transparent) Image on top.
|
|
||||||
|
|
||||||
:param source: The source image to be modified.
|
|
||||||
:param layer: The layer to implant upon it.
|
|
||||||
:return: If specified, a list of tuples indicating pixel locations will be returned.
|
|
||||||
"""
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
|
||||||
def get_pixel_differences(source: Image, target: Image) -> List[Tuple[int, int, RGB]]:
|
def get_pixel_differences(source: Image, target: Image) -> List[Pixel]:
|
||||||
"""
|
"""
|
||||||
Returns a list of pixels (location & color) that must be changed to match `source` to `target`.
|
Returns a list of pixels (location & color) that must be changed to match `source` to `target`.
|
||||||
|
|
||||||
@@ -22,9 +15,9 @@ def get_pixel_differences(source: Image, target: Image) -> List[Tuple[int, int,
|
|||||||
:param target: The target image (what we want to have).
|
:param target: The target image (what we want to have).
|
||||||
:return: A list of pixels in tuples.
|
:return: A list of pixels in tuples.
|
||||||
"""
|
"""
|
||||||
|
width, height = int(os.getenv(Environment.CANVAS_HEIGHT)), int(os.getenv(Environment.CANVAS_HEIGHT))
|
||||||
source_pixels = source.load()
|
source_pixels = source.load()
|
||||||
target_pixels = target.load()
|
target_pixels = target.load()
|
||||||
height, width = source.shape
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
for y in range(width):
|
for y in range(width):
|
||||||
|
|||||||
Reference in New Issue
Block a user