Skip to content

Commit 5eac8e6

Browse files
committed
Add D3DShot types
from python/typeshed#8652
1 parent dfa583b commit 5eac8e6

17 files changed

+427
-0
lines changed

typings/d3dshot/__init__.pyi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from d3dshot.capture_output import CaptureOutputs as CaptureOutputs
2+
from d3dshot.d3dshot import D3DShot as D3DShot
3+
4+
pil_is_available: bool
5+
numpy_is_available: bool
6+
pytorch_is_available: bool
7+
pytorch_gpu_is_available: bool
8+
capture_output_mapping: dict[str, CaptureOutputs]
9+
capture_outputs: list[str]
10+
11+
12+
def determine_available_capture_outputs() -> list[CaptureOutputs]: ...
13+
def create(capture_output: str = ..., frame_buffer_size: int = ...) -> D3DShot: ...

typings/d3dshot/capture_output.pyi

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import enum
2+
from typing import Any
3+
4+
from _typeshed import Incomplete
5+
from PIL.Image import Image
6+
from typing_extensions import TypeAlias
7+
8+
Frame: TypeAlias = Any
9+
# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor
10+
Pointer: TypeAlias = Incomplete
11+
12+
13+
class CaptureOutputs(enum.Enum):
14+
PIL: int
15+
NUMPY: int
16+
NUMPY_FLOAT: int
17+
PYTORCH: int
18+
PYTORCH_FLOAT: int
19+
PYTORCH_GPU: int
20+
PYTORCH_FLOAT_GPU: int
21+
22+
23+
class CaptureOutputError(BaseException):
24+
...
25+
26+
27+
class CaptureOutput:
28+
backend: CaptureOutput
29+
def __init__(self, backend: CaptureOutputs = ...) -> None: ...
30+
31+
def process(
32+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
33+
) -> Frame: ...
34+
def to_pil(self, frame: Frame) -> Image: ...
35+
def stack(self, frames: list[Frame], stack_dimension) -> Frame: ...

typings/d3dshot/capture_outputs/__init__.pyi

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import numpy as np
2+
import numpy.typing as npt
3+
from _typeshed import Incomplete
4+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
5+
from PIL.Image import Image
6+
from typing_extensions import TypeAlias
7+
8+
Pointer: TypeAlias = Incomplete
9+
NDArray: TypeAlias = npt.NDArray[np.int32]
10+
11+
12+
class NumpyCaptureOutput(CaptureOutput):
13+
def __init__(self) -> None: ...
14+
15+
def process(
16+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
17+
) -> NDArray: ...
18+
def to_pil(self, frame: NDArray) -> Image: ...
19+
def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ...
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import numpy as np
2+
import numpy.typing as npt
3+
from _typeshed import Incomplete
4+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
5+
from PIL.Image import Image
6+
from typing_extensions import TypeAlias
7+
8+
Pointer: TypeAlias = Incomplete
9+
NDArray: TypeAlias = npt.NDArray[np.float32]
10+
11+
12+
class NumpyFloatCaptureOutput(CaptureOutput):
13+
def __init__(self) -> None: ...
14+
15+
def process(
16+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
17+
) -> NDArray: ...
18+
def to_pil(self, frame: NDArray) -> Image: ...
19+
def stack(self, frames: list[NDArray] | NDArray, stack_dimension: int) -> NDArray: ...
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from _typeshed import Incomplete
2+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
3+
from PIL.Image import Image
4+
from typing_extensions import TypeAlias
5+
6+
Pointer: TypeAlias = Incomplete
7+
8+
9+
class PILCaptureOutput(CaptureOutput):
10+
def __init__(self) -> None: ...
11+
12+
def process(
13+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
14+
) -> Image: ...
15+
def to_pil(self, frame: Image) -> Image: ...
16+
def stack(self, frames: list[Image], stack_dimension: int) -> list[Image]: ...
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import torch
2+
from _typeshed import Incomplete
3+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
4+
from PIL.Image import Image
5+
from typing_extensions import TypeAlias
6+
7+
Pointer: TypeAlias = Incomplete
8+
9+
10+
class PytorchCaptureOutput(CaptureOutput):
11+
def __init__(self) -> None: ...
12+
13+
def process(
14+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
15+
) -> torch.Tensor: ...
16+
def to_pil(self, frame: torch.Tensor) -> Image: ...
17+
def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ...
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import torch
2+
from _typeshed import Incomplete
3+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
4+
from PIL.Image import Image
5+
from typing_extensions import TypeAlias
6+
7+
Pointer: TypeAlias = Incomplete
8+
9+
10+
class PytorchFloatCaptureOutput(CaptureOutput):
11+
def __init__(self) -> None: ...
12+
13+
def process(
14+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
15+
) -> torch.Tensor: ...
16+
def to_pil(self, frame: torch.Tensor) -> Image: ...
17+
def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ...
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import torch
2+
from _typeshed import Incomplete
3+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
4+
from PIL.Image import Image
5+
from typing_extensions import TypeAlias
6+
7+
Pointer: TypeAlias = Incomplete
8+
9+
10+
class PytorchFloatGPUCaptureOutput(CaptureOutput):
11+
device: Incomplete
12+
def __init__(self) -> None: ...
13+
14+
def process(
15+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
16+
) -> torch.Tensor: ...
17+
def to_pil(self, frame: torch.Tensor) -> Image: ...
18+
def stack(self, frames: list[torch.Tensor], stack_dimension: int) -> torch.Tensor: ...
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import torch
2+
from _typeshed import Incomplete
3+
from d3dshot.capture_output import CaptureOutput as CaptureOutput
4+
from PIL.Image import Image
5+
from typing_extensions import TypeAlias
6+
7+
Pointer: TypeAlias = Incomplete
8+
9+
10+
class PytorchGPUCaptureOutput(CaptureOutput):
11+
device: torch.device
12+
def __init__(self) -> None: ...
13+
14+
def process(
15+
self, pointer: Pointer, size: int, width: int, height: int, region: tuple[int, int, int, int], rotation: int
16+
) -> torch.Tensor: ...
17+
def to_pil(self, frame: torch.Tensor) -> Image: ...
18+
def stack(self, frames: list[torch.Tensor], stack_dimension: int): ...

typings/d3dshot/d3dshot.pyi

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from collections import deque
2+
from typing import Any
3+
4+
from d3dshot.capture_output import CaptureOutput as CaptureOutput, CaptureOutputs as CaptureOutputs
5+
from d3dshot.display import Display as Display
6+
from typing_extensions import TypeAlias
7+
8+
Frame: TypeAlias = Any
9+
# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor
10+
11+
12+
class D3DShot:
13+
displays: list[Display]
14+
display: Display
15+
capture_output: CaptureOutput
16+
frame_buffer_size: int
17+
frame_buffer: deque[Frame]
18+
previous_screenshot: Frame | None
19+
region: tuple[int, int, int, int] | None
20+
21+
def __init__(
22+
self,
23+
capture_output: CaptureOutputs = ...,
24+
frame_buffer_size: int = ...,
25+
pil_is_available: bool = ...,
26+
numpy_is_available: bool = ...,
27+
pytorch_is_available: bool = ...,
28+
pytorch_gpu_is_available: bool = ...,
29+
) -> None: ...
30+
@property
31+
def is_capturing(self) -> bool: ...
32+
def get_latest_frame(self) -> Frame | None: ...
33+
def get_frame(self, frame_index: int) -> Frame | None: ...
34+
def get_frames(self, frame_indices: list[int]) -> list[Frame]: ...
35+
def get_frame_stack(self, frame_indices: list[int], stack_dimension: str | None = ...) -> Frame: ...
36+
def screenshot(self, region: tuple[int, int, int, int] | None = ...) -> Frame | None: ...
37+
38+
def screenshot_to_disk(
39+
self, directory: str | None = ..., file_name: str | None = ..., region: tuple[int, int, int, int] | None = ...
40+
) -> str: ...
41+
def frame_buffer_to_disk(self, directory: str | None = ...) -> None: ...
42+
def capture(self, target_fps: int = ..., region: tuple[int, int, int, int] | None = ...) -> bool: ...
43+
def screenshot_every(self, interval: float, region: tuple[int, int, int, int] | None = ...) -> bool: ...
44+
45+
def screenshot_to_disk_every(
46+
self, interval: float, directory: str | None = ..., region: tuple[int, int, int, int] | None = ...
47+
) -> bool: ...
48+
def stop(self) -> bool: ...
49+
def benchmark(self) -> None: ...
50+
def detect_displays(self) -> None: ...

typings/d3dshot/display.pyi

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from collections.abc import Callable
2+
from typing import Any, Literal
3+
4+
from _typeshed import Incomplete
5+
from typing_extensions import TypeAlias
6+
7+
Frame: TypeAlias = Any
8+
# Frame: TypeAlias = Image | npt.NDArray[np.int32] | npt.NDArray[np.float32] | torch.Tensor
9+
Pointer: TypeAlias = Incomplete
10+
11+
12+
class Display:
13+
name: str
14+
adapter_name: str
15+
resolution: tuple[int, int]
16+
position: dict[Literal["left", "top", "right", "bottom"], int]
17+
rotation: int
18+
scale_factor: int
19+
is_primary: bool
20+
hmonitor: int
21+
dxgi_output: Incomplete | None
22+
dxgi_adapter: Incomplete | None
23+
d3d_device: Incomplete # ctypes.POINTER(ID3D11Device)()
24+
d3d_device_context: Incomplete # ctypes.POINTER(ID3D11DeviceContext)()
25+
dxgi_output_duplication: Incomplete # ctypes.POINTER(IDXGIOutputDuplication)()
26+
27+
def __init__(
28+
self,
29+
name: str | None = ...,
30+
adapter_name: str | None = ...,
31+
resolution: tuple[int, int] | None = ...,
32+
position: dict[Literal["left", "top", "right", "bottom"], int] | None = ...,
33+
rotation: int | None = ...,
34+
scale_factor: int | None = ...,
35+
is_primary: bool = ...,
36+
hmonitor: int | None = ...,
37+
dxgi_output: Incomplete | None = ...,
38+
dxgi_adapter: Incomplete | None = ...,
39+
) -> None: ...
40+
41+
def capture(
42+
self,
43+
# Incomplete: dxgi_mapped_rect.pBits
44+
process_func: Callable[[Pointer, int, int, int, tuple[int, int, int, int], int], Frame | None] | None,
45+
region: tuple[int, int, int, int] = ...,
46+
) -> Frame: ...
47+
@classmethod
48+
def discover_displays(cls) -> list[Display]: ...

typings/d3dshot/dll/__init__.pyi

Whitespace-only changes.

typings/d3dshot/dll/d3d.pyi

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import ctypes
2+
3+
import comtypes
4+
from _typeshed import Incomplete
5+
from typing_extensions import TypeAlias
6+
7+
Pointer: TypeAlias = Incomplete
8+
9+
10+
class DXGI_SAMPLE_DESC(ctypes.Structure):
11+
...
12+
13+
14+
class D3D11_BOX(ctypes.Structure):
15+
...
16+
17+
18+
class D3D11_TEXTURE2D_DESC(ctypes.Structure):
19+
...
20+
21+
22+
class ID3D11DeviceChild(comtypes.IUnknown):
23+
...
24+
25+
26+
class ID3D11Resource(ID3D11DeviceChild):
27+
...
28+
29+
30+
class ID3D11Texture2D(ID3D11Resource):
31+
...
32+
33+
34+
class ID3D11DeviceContext(ID3D11DeviceChild):
35+
...
36+
37+
38+
class ID3D11Device(comtypes.IUnknown):
39+
...
40+
41+
42+
def initialize_d3d_device(dxgi_adapter: Pointer) -> tuple[Pointer, Pointer]: ...
43+
def describe_d3d11_texture_2d(d3d11_texture_2d: Pointer) -> D3D11_TEXTURE2D_DESC: ...
44+
def prepare_d3d11_texture_2d_for_cpu(d3d11_texture_2d: Pointer, d3d_device: Pointer) -> Pointer: ...

0 commit comments

Comments
 (0)