2018-03-30 18:19:23 -07:00
|
|
|
import numpy as np
|
|
|
|
from PIL import Image
|
2022-02-12 23:47:23 +08:00
|
|
|
from typing import Iterable
|
2018-12-24 12:37:51 -08:00
|
|
|
|
2021-01-06 10:39:34 -08:00
|
|
|
from manimlib.utils.file_ops import find_file
|
2021-01-02 20:47:51 -08:00
|
|
|
from manimlib.utils.directories import get_raster_image_dir
|
|
|
|
from manimlib.utils.directories import get_vector_image_dir
|
2018-03-30 18:19:23 -07:00
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2022-02-12 23:47:23 +08:00
|
|
|
def get_full_raster_image_path(image_file_name: str) -> str:
|
2021-01-06 10:39:34 -08:00
|
|
|
return find_file(
|
2018-03-30 18:19:23 -07:00
|
|
|
image_file_name,
|
2021-01-05 23:14:16 -08:00
|
|
|
directories=[get_raster_image_dir()],
|
2021-03-27 11:55:58 -07:00
|
|
|
extensions=[".jpg", ".jpeg", ".png", ".gif", ""]
|
2019-01-24 22:24:01 -08:00
|
|
|
)
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-30 18:19:23 -07:00
|
|
|
|
2022-02-12 23:47:23 +08:00
|
|
|
def get_full_vector_image_path(image_file_name: str) -> str:
|
2021-01-06 10:39:34 -08:00
|
|
|
return find_file(
|
2021-01-02 20:47:51 -08:00
|
|
|
image_file_name,
|
2021-01-05 23:14:16 -08:00
|
|
|
directories=[get_vector_image_dir()],
|
2021-02-09 16:56:47 -08:00
|
|
|
extensions=[".svg", ".xdv", ""],
|
2021-01-02 20:47:51 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-02-12 23:47:23 +08:00
|
|
|
def drag_pixels(frames: Iterable) -> list:
|
2018-03-30 18:19:23 -07:00
|
|
|
curr = frames[0]
|
|
|
|
new_frames = []
|
|
|
|
for frame in frames:
|
|
|
|
curr += (curr == 0) * np.array(frame)
|
|
|
|
new_frames.append(np.array(curr))
|
|
|
|
return new_frames
|
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2022-02-12 23:47:23 +08:00
|
|
|
def invert_image(image: Iterable) -> Image:
|
2018-03-30 18:19:23 -07:00
|
|
|
arr = np.array(image)
|
|
|
|
arr = (255 * np.ones(arr.shape)).astype(arr.dtype) - arr
|
2018-04-06 13:58:59 -07:00
|
|
|
return Image.fromarray(arr)
|