From a017599620d1df7ccdeefba8cd9b2153f8bca25d Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 3 Sep 2022 13:06:53 -0400 Subject: [PATCH] Add D3DShot types from https://github.com/python/typeshed/pull/8652 --- typings/d3dshot/__init__.pyi | 13 +++ typings/d3dshot/capture_output.pyi | 35 +++++++ typings/d3dshot/capture_outputs/__init__.pyi | 0 .../capture_outputs/numpy_capture_output.pyi | 19 ++++ .../numpy_float_capture_output.pyi | 19 ++++ .../capture_outputs/pil_capture_output.pyi | 16 +++ .../pytorch_capture_output.pyi | 17 ++++ .../pytorch_float_capture_output.pyi | 17 ++++ .../pytorch_float_gpu_capture_output.pyi | 18 ++++ .../pytorch_gpu_capture_output.pyi | 18 ++++ typings/d3dshot/d3dshot.pyi | 50 ++++++++++ typings/d3dshot/display.pyi | 48 +++++++++ typings/d3dshot/dll/__init__.pyi | 0 typings/d3dshot/dll/d3d.pyi | 44 +++++++++ typings/d3dshot/dll/dxgi.pyi | 98 +++++++++++++++++++ typings/d3dshot/dll/shcore.pyi | 1 + typings/d3dshot/dll/user32.pyi | 14 +++ 17 files changed, 427 insertions(+) create mode 100644 typings/d3dshot/__init__.pyi create mode 100644 typings/d3dshot/capture_output.pyi create mode 100644 typings/d3dshot/capture_outputs/__init__.pyi create mode 100644 typings/d3dshot/capture_outputs/numpy_capture_output.pyi create mode 100644 typings/d3dshot/capture_outputs/numpy_float_capture_output.pyi create mode 100644 typings/d3dshot/capture_outputs/pil_capture_output.pyi create mode 100644 typings/d3dshot/capture_outputs/pytorch_capture_output.pyi create mode 100644 typings/d3dshot/capture_outputs/pytorch_float_capture_output.pyi create mode 100644 typings/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi create mode 100644 typings/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi create mode 100644 typings/d3dshot/d3dshot.pyi create mode 100644 typings/d3dshot/display.pyi create mode 100644 typings/d3dshot/dll/__init__.pyi create mode 100644 typings/d3dshot/dll/d3d.pyi create mode 100644 typings/d3dshot/dll/dxgi.pyi create mode 100644 typings/d3dshot/dll/shcore.pyi create mode 100644 typings/d3dshot/dll/user32.pyi diff --git a/typings/d3dshot/__init__.pyi b/typings/d3dshot/__init__.pyi new file mode 100644 index 00000000..882abe1f --- /dev/null +++ b/typings/d3dshot/__init__.pyi @@ -0,0 +1,13 @@ +from d3dshot.capture_output import CaptureOutputs as CaptureOutputs +from d3dshot.d3dshot import D3DShot as D3DShot + +pil_is_available: bool +numpy_is_available: bool +pytorch_is_available: bool +pytorch_gpu_is_available: bool +capture_output_mapping: dict[str, CaptureOutputs] +capture_outputs: list[str] + + +def determine_available_capture_outputs() -> list[CaptureOutputs]: ... +def create(capture_output: str = ..., frame_buffer_size: int = ...) -> D3DShot: ... diff --git a/typings/d3dshot/capture_output.pyi b/typings/d3dshot/capture_output.pyi new file mode 100644 index 00000000..ec338a77 --- /dev/null +++ b/typings/d3dshot/capture_output.pyi @@ -0,0 +1,35 @@ +import enum +from typing import Any + +from _typeshed import Incomplete +from PIL.Image import Image +from typing_extensions import TypeAlias + +Frame: TypeAlias = Any +# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor +Pointer: TypeAlias = Incomplete + + +class CaptureOutputs(enum.Enum): + PIL: int + NUMPY: int + NUMPY_FLOAT: int + PYTORCH: int + PYTORCH_FLOAT: int + PYTORCH_GPU: int + PYTORCH_FLOAT_GPU: int + + +class CaptureOutputError(BaseException): + ... + + +class CaptureOutput: + backend: CaptureOutput + def __init__(self, backend: CaptureOutputs = ...) -> None: ... + + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> Frame: ... + def to_pil(self, frame: Frame) -> Image: ... + def stack(self, frames: list[Frame], stack_dimension) -> Frame: ... diff --git a/typings/d3dshot/capture_outputs/__init__.pyi b/typings/d3dshot/capture_outputs/__init__.pyi new file mode 100644 index 00000000..e69de29b diff --git a/typings/d3dshot/capture_outputs/numpy_capture_output.pyi b/typings/d3dshot/capture_outputs/numpy_capture_output.pyi new file mode 100644 index 00000000..e165ef32 --- /dev/null +++ b/typings/d3dshot/capture_outputs/numpy_capture_output.pyi @@ -0,0 +1,19 @@ +import numpy as np +import numpy.typing as npt +from _typeshed import Incomplete +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image +from typing_extensions import TypeAlias + +Pointer: TypeAlias = Incomplete +NDArray: TypeAlias = npt.NDArray[np.int32] + + +class NumpyCaptureOutput(CaptureOutput): + def __init__(self) -> None: ... + + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> NDArray: ... + def to_pil(self, frame: NDArray) -> Image: ... + def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ... diff --git a/typings/d3dshot/capture_outputs/numpy_float_capture_output.pyi b/typings/d3dshot/capture_outputs/numpy_float_capture_output.pyi new file mode 100644 index 00000000..96226290 --- /dev/null +++ b/typings/d3dshot/capture_outputs/numpy_float_capture_output.pyi @@ -0,0 +1,19 @@ +import numpy as np +import numpy.typing as npt +from _typeshed import Incomplete +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image +from typing_extensions import TypeAlias + +Pointer: TypeAlias = Incomplete +NDArray: TypeAlias = npt.NDArray[np.float32] + + +class NumpyFloatCaptureOutput(CaptureOutput): + def __init__(self) -> None: ... + + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> NDArray: ... + def to_pil(self, frame: NDArray) -> Image: ... + def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ... diff --git a/typings/d3dshot/capture_outputs/pil_capture_output.pyi b/typings/d3dshot/capture_outputs/pil_capture_output.pyi new file mode 100644 index 00000000..553d48bf --- /dev/null +++ b/typings/d3dshot/capture_outputs/pil_capture_output.pyi @@ -0,0 +1,16 @@ +from _typeshed import Incomplete +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image +from typing_extensions import TypeAlias + +Pointer: TypeAlias = Incomplete + + +class PILCaptureOutput(CaptureOutput): + def __init__(self) -> None: ... + + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> Image: ... + def to_pil(self, frame: Image) -> Image: ... + def stack(self, frames: list[Image], stack_dimension: int) -> list[Image]: ... diff --git a/typings/d3dshot/capture_outputs/pytorch_capture_output.pyi b/typings/d3dshot/capture_outputs/pytorch_capture_output.pyi new file mode 100644 index 00000000..fde2eb95 --- /dev/null +++ b/typings/d3dshot/capture_outputs/pytorch_capture_output.pyi @@ -0,0 +1,17 @@ +import torch +from _typeshed import Incomplete +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image +from typing_extensions import TypeAlias + +Pointer: TypeAlias = Incomplete + + +class PytorchCaptureOutput(CaptureOutput): + def __init__(self) -> None: ... + + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> torch.Tensor: ... + def to_pil(self, frame: torch.Tensor) -> Image: ... + def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ... diff --git a/typings/d3dshot/capture_outputs/pytorch_float_capture_output.pyi b/typings/d3dshot/capture_outputs/pytorch_float_capture_output.pyi new file mode 100644 index 00000000..e6264993 --- /dev/null +++ b/typings/d3dshot/capture_outputs/pytorch_float_capture_output.pyi @@ -0,0 +1,17 @@ +import torch +from _typeshed import Incomplete +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image +from typing_extensions import TypeAlias + +Pointer: TypeAlias = Incomplete + + +class PytorchFloatCaptureOutput(CaptureOutput): + def __init__(self) -> None: ... + + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> torch.Tensor: ... + def to_pil(self, frame: torch.Tensor) -> Image: ... + def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ... diff --git a/typings/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi b/typings/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi new file mode 100644 index 00000000..ec685f18 --- /dev/null +++ b/typings/d3dshot/capture_outputs/pytorch_float_gpu_capture_output.pyi @@ -0,0 +1,18 @@ +import torch +from _typeshed import Incomplete +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image +from typing_extensions import TypeAlias + +Pointer: TypeAlias = Incomplete + + +class PytorchFloatGPUCaptureOutput(CaptureOutput): + device: Incomplete + def __init__(self) -> None: ... + + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> torch.Tensor: ... + def to_pil(self, frame: torch.Tensor) -> Image: ... + def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ... diff --git a/typings/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi b/typings/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi new file mode 100644 index 00000000..e8cbfb11 --- /dev/null +++ b/typings/d3dshot/capture_outputs/pytorch_gpu_capture_output.pyi @@ -0,0 +1,18 @@ +import torch +from _typeshed import Incomplete +from d3dshot.capture_output import CaptureOutput as CaptureOutput +from PIL.Image import Image +from typing_extensions import TypeAlias + +Pointer: TypeAlias = Incomplete + + +class PytorchGPUCaptureOutput(CaptureOutput): + device: torch.device + def __init__(self) -> None: ... + + def process( + self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int + ) -> torch.Tensor: ... + def to_pil(self, frame: torch.Tensor) -> Image: ... + def stack(self, frames: list[torch.Tensor], stack_dimension: int): ... diff --git a/typings/d3dshot/d3dshot.pyi b/typings/d3dshot/d3dshot.pyi new file mode 100644 index 00000000..bea62ad8 --- /dev/null +++ b/typings/d3dshot/d3dshot.pyi @@ -0,0 +1,50 @@ +from collections import deque +from typing import Any + +from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutputs as CaptureOutputs +from d3dshot.display import Display as Display +from typing_extensions import TypeAlias + +Frame: TypeAlias = Any +# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor + + +class D3DShot: + displays: list[Display] + display: Display + capture_output: CaptureOutput + frame_buffer_size: int + frame_buffer: deque[Frame] + previous_screenshot: Frame | None + region: tuple[int, int, int, int] | None + + def __init__( + self, + capture_output: CaptureOutputs = ..., + frame_buffer_size: int = ..., + pil_is_available: bool = ..., + numpy_is_available: bool = ..., + pytorch_is_available: bool = ..., + pytorch_gpu_is_available: bool = ..., + ) -> None: ... + @property + def is_capturing(self) -> bool: ... + def get_latest_frame(self) -> Frame | None: ... + def get_frame(self, frame_index: int) -> Frame | None: ... + def get_frames(self, frame_indices: list[int]) -> list[Frame]: ... + def get_frame_stack(self, frame_indices: list[int], stack_dimension: str | None = ...) -> Frame: ... + def screenshot(self, region: tuple[int, int, int, int] | None = ...) -> Frame | None: ... + + def screenshot_to_disk( + self, directory: str | None = ..., file_name: str | None = ..., region: tuple[int, int, int, int] | None = ... + ) -> str: ... + def frame_buffer_to_disk(self, directory: str | None = ...) -> None: ... + def capture(self, target_fps: int = ..., region: tuple[int, int, int, int] | None = ...) -> bool: ... + def screenshot_every(self, interval: float, region: tuple[int, int, int, int] | None = ...) -> bool: ... + + def screenshot_to_disk_every( + self, interval: float, directory: str | None = ..., region: tuple[int, int, int, int] | None = ... + ) -> bool: ... + def stop(self) -> bool: ... + def benchmark(self) -> None: ... + def detect_displays(self) -> None: ... diff --git a/typings/d3dshot/display.pyi b/typings/d3dshot/display.pyi new file mode 100644 index 00000000..f2df9ab9 --- /dev/null +++ b/typings/d3dshot/display.pyi @@ -0,0 +1,48 @@ +from collections.abc import Callable +from typing import Any, Literal + +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +Frame: TypeAlias = Any +# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor +Pointer: TypeAlias = Incomplete + + +class Display: + name: str + adapter_name: str + resolution: tuple[int, int] + position: dict[Literal["left", "top", "right", "bottom"], int] + rotation: int + scale_factor: int + is_primary: bool + hmonitor: int + dxgi_output: Incomplete | None + dxgi_adapter: Incomplete | None + d3d_device: Incomplete # ctypes.POINTER(ID3D11Device)() + d3d_device_context: Incomplete # ctypes.POINTER(ID3D11DeviceContext)() + dxgi_output_duplication: Incomplete # ctypes.POINTER(IDXGIOutputDuplication)() + + def __init__( + self, + name: str | None = ..., + adapter_name: str | None = ..., + resolution: tuple[int, int] | None = ..., + position: dict[Literal["left", "top", "right", "bottom"], int] | None = ..., + rotation: int | None = ..., + scale_factor: int | None = ..., + is_primary: bool = ..., + hmonitor: int | None = ..., + dxgi_output: Incomplete | None = ..., + dxgi_adapter: Incomplete | None = ..., + ) -> None: ... + + def capture( + self, + # Incomplete: dxgi_mapped_rect.pBits + process_func: Callable[[Pointer, int, int, int, tuple[int, int, int, int], int], Frame | None] | None, + region: tuple[int, int, int, int] = ..., + ) -> Frame: ... + @classmethod + def discover_displays(cls) -> list[Display]: ... diff --git a/typings/d3dshot/dll/__init__.pyi b/typings/d3dshot/dll/__init__.pyi new file mode 100644 index 00000000..e69de29b diff --git a/typings/d3dshot/dll/d3d.pyi b/typings/d3dshot/dll/d3d.pyi new file mode 100644 index 00000000..c11a7e3b --- /dev/null +++ b/typings/d3dshot/dll/d3d.pyi @@ -0,0 +1,44 @@ +import ctypes + +import comtypes +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +Pointer: TypeAlias = Incomplete + + +class DXGI_SAMPLE_DESC(ctypes.Structure): + ... + + +class D3D11_BOX(ctypes.Structure): + ... + + +class D3D11_TEXTURE2D_DESC(ctypes.Structure): + ... + + +class ID3D11DeviceChild(comtypes.IUnknown): + ... + + +class ID3D11Resource(ID3D11DeviceChild): + ... + + +class ID3D11Texture2D(ID3D11Resource): + ... + + +class ID3D11DeviceContext(ID3D11DeviceChild): + ... + + +class ID3D11Device(comtypes.IUnknown): + ... + + +def initialize_d3d_device(dxgi_adapter: Pointer) -> tuple[Pointer, Pointer]: ... +def describe_d3d11_texture_2d(d3d11_texture_2d: Pointer) -> D3D11_TEXTURE2D_DESC: ... +def prepare_d3d11_texture_2d_for_cpu(d3d11_texture_2d: Pointer, d3d_device: Pointer) -> Pointer: ... diff --git a/typings/d3dshot/dll/dxgi.pyi b/typings/d3dshot/dll/dxgi.pyi new file mode 100644 index 00000000..7947d5bc --- /dev/null +++ b/typings/d3dshot/dll/dxgi.pyi @@ -0,0 +1,98 @@ +import ctypes +from collections.abc import Callable +from typing import Any + +import comtypes +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +Frame: TypeAlias = Any +# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor +Pointer: TypeAlias = Incomplete + + +class LUID(ctypes.Structure): + ... + + +class DXGI_ADAPTER_DESC1(ctypes.Structure): + ... + + +class DXGI_OUTPUT_DESC(ctypes.Structure): + ... + + +class DXGI_OUTDUPL_POINTER_POSITION(ctypes.Structure): + ... + + +class DXGI_OUTDUPL_FRAME_INFO(ctypes.Structure): + ... + + +class DXGI_MAPPED_RECT(ctypes.Structure): + ... + + +class IDXGIObject(comtypes.IUnknown): + ... + + +class IDXGIDeviceSubObject(IDXGIObject): + ... + + +class IDXGIResource(IDXGIDeviceSubObject): + ... + + +class IDXGISurface(IDXGIDeviceSubObject): + ... + + +class IDXGIOutputDuplication(IDXGIObject): + ... + + +class IDXGIOutput(IDXGIObject): + ... + + +class IDXGIOutput1(IDXGIOutput): + ... + + +class IDXGIAdapter(IDXGIObject): + ... + + +class IDXGIAdapter1(IDXGIAdapter): + ... + + +class IDXGIFactory(IDXGIObject): + ... + + +class IDXGIFactory1(IDXGIFactory): + ... + + +def initialize_dxgi_factory() -> Pointer: ... # ctypes.POINTER(IDXGIFactory1)(handle.value) +def discover_dxgi_adapters(dxgi_factory: Pointer) -> list[Pointer]: ... +def describe_dxgi_adapter(dxgi_adapter: Pointer) -> Pointer: ... +def discover_dxgi_outputs(dxgi_adapter: Pointer) -> list[Pointer]: ... +def describe_dxgi_output(dxgi_output: Pointer) -> Pointer: ... +def initialize_dxgi_output_duplication(dxgi_output: Pointer, d3d_device: Pointer) -> Pointer: ... + + +def get_dxgi_output_duplication_frame( + dxgi_output_duplication: Pointer, + d3d_device: Pointer, + process_func: Callable[[Pointer, int, int, int, tuple[int, int, int, int], int], Frame | None] | None = ..., + width: int = ..., + height: int = ..., + region: tuple[int, int, int, int] | None = ..., + rotation: int = ..., +) -> Frame: ... diff --git a/typings/d3dshot/dll/shcore.pyi b/typings/d3dshot/dll/shcore.pyi new file mode 100644 index 00000000..15a24dba --- /dev/null +++ b/typings/d3dshot/dll/shcore.pyi @@ -0,0 +1 @@ +def get_scale_factor_for_monitor(hmonitor: int) -> float: ... diff --git a/typings/d3dshot/dll/user32.pyi b/typings/d3dshot/dll/user32.pyi new file mode 100644 index 00000000..b9720356 --- /dev/null +++ b/typings/d3dshot/dll/user32.pyi @@ -0,0 +1,14 @@ +import ctypes + +from _typeshed import Incomplete +from typing_extensions import TypeAlias + +Pointer: TypeAlias = Incomplete + + +class DISPLAY_DEVICE(ctypes.Structure): + ... + + +def get_display_device_name_mapping() -> dict[str, tuple[str, bool]]: ... +def get_hmonitor_by_point(x: int, y: int) -> Pointer: ... # ctypes.windll.user32.MonitorFromPoint(point, 0)