Skip to content

Commit dd90210

Browse files
committed
Improve BitBlt:
- recovery for 2 windows with same name of same executable - clearer message for the above case
1 parent 1874c78 commit dd90210

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/AutoSplit.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,10 @@ def __get_capture_for_comparison(self):
791791
if self.settings_dict["capture_method"] == CaptureMethodEnum.VIDEO_CAPTURE_DEVICE:
792792
self.live_image.setText("Waiting for capture device...")
793793
else:
794-
self.live_image.setText("Trying to recover window...")
794+
message = "Trying to recover window..."
795+
if self.settings_dict["capture_method"] == CaptureMethodEnum.BITBLT:
796+
message += "\n(captured window may be incompatible with BitBlt)"
797+
self.live_image.setText(message)
795798
recovered = self.capture_method.recover_window(self.settings_dict["captured_window_title"])
796799
if recovered:
797800
capture, _ = self.capture_method.get_frame()

src/capture_method/BitBltCaptureMethod.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
PW_RENDERFULLCONTENT = 0x00000002
1818

1919

20+
def is_blank(image: MatLike):
21+
"""
22+
BitBlt can return a balnk buffer. Either because the target is unsupported,
23+
or because there's two windows of the same name for the same executable.
24+
"""
25+
return not image.any()
26+
27+
2028
class BitBltCaptureMethod(CaptureMethodBase):
2129
name = "BitBlt"
2230
short_description = "fastest, least compatible"
@@ -61,11 +69,15 @@ def get_frame(self) -> tuple[MatLike | None, bool]:
6169
win32con.SRCCOPY,
6270
)
6371
image = np.frombuffer(cast(bytes, bitmap.GetBitmapBits(True)), dtype=np.uint8)
64-
image.shape = (selection["height"], selection["width"], BGRA_CHANNEL_COUNT)
6572
except (win32ui.error, pywintypes.error):
6673
# Invalid handle or the window was closed while it was being manipulated
6774
return None, False
6875

76+
if is_blank(image):
77+
image = None
78+
else:
79+
image.shape = (selection["height"], selection["width"], BGRA_CHANNEL_COUNT)
80+
6981
# Cleanup DC and handle
7082
try_delete_dc(dc_object)
7183
try_delete_dc(compatible_dc)

0 commit comments

Comments
 (0)