Skip to content

Commit cc6066c

Browse files
committed
Merge branch 'dev' of https://github.com/Toufool/Auto-Split into show-errors-outside-main-thread
2 parents 25dece7 + 393ca84 commit cc6066c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/AutoSplit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ def excepthook(exceptionType: Type[BaseException], exception: BaseException, tra
12361236
sys.exit(0)
12371237
error_messages.exceptionTraceback(
12381238
"AutoSplit encountered an unhandled exception and will try to recover, "
1239-
f"however, there is no guarantee everything will work correctly. {CREATE_NEW_ISSUE_MESSAGE}",
1239+
f"however, there is no guarantee everything will work properly. {CREATE_NEW_ISSUE_MESSAGE}",
12401240
exception)
12411241

12421242

src/compare.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def compare_l2_norm_masked(source, capture, mask) -> float:
7272
# The L2 Error is summed across all pixels, so this normalizes
7373
max_error = (3 * np.count_nonzero(mask) * 255 * 255) ** 0.5
7474

75+
if not max_error:
76+
return 0
7577
return 1 - (error / max_error)
7678

7779
def compare_template(source, capture) -> float:
@@ -155,10 +157,20 @@ def compare_phash_masked(source, capture, mask):
155157
source_hash = imagehash.phash(source)
156158
capture_hash = imagehash.phash(capture)
157159

160+
if not source_hash + capture_hash:
161+
return 0
158162
return 1 - ((source_hash - capture_hash) / 64.0)
159163

160164

161165
def checkIfImageHasTransparency(image):
162-
# TODO check for first transparent pixel, no need to iterate through the whole image
163166
# Check if there's a transparency channel (4th channel) and if at least one pixel is transparent (< 255)
164-
return image.shape[2] == 4 and np.mean(image[:, :, 3]) != 255
167+
if image.shape[2] != 4:
168+
return False
169+
mean = np.mean(image[:, :, 3])
170+
if mean == 0:
171+
# Non-transparent images code path is usually faster and simpler, so let's return that
172+
return False
173+
# TODO error message if all pixels are transparent
174+
# (the image appears as all black in windows, so it's not obvious for the user what they did wrong)
175+
176+
return mean != 255

0 commit comments

Comments
 (0)