Update gimp metrics and getters

This commit is contained in:
BlankCheng
2024-01-26 16:39:13 +08:00
parent e5a5ff4588
commit 50f7669e59
4 changed files with 84 additions and 5 deletions

View File

@@ -20,3 +20,11 @@ from .vlc import is_vlc_playing, is_vlc_recordings_folder, is_vlc_fullscreen, co
compare_videos
from .thunderbird import check_thunderbird_prefs, check_thunderbird_filter
from .vscode import compare_text_file, compare_config, compare_answer, is_extension_installed, check_json_settings, check_json_keybindings
from .gimp import (
check_brightness_decrease_and_structure_sim,
check_contrast_increase_and_structure_sim,
check_saturation_increase_and_structure_sim,
check_file_exists_and_structure_sim,
check_triangle_position,
check_structure_sim,
)

View File

@@ -2,6 +2,7 @@ import os
from PIL import Image, ImageStat
from skimage.metrics import structural_similarity as ssim
import numpy as np
import sexpdata
def get_gimp_export_path():
@@ -286,6 +287,8 @@ def check_structure_sim(src_path, tgt_path):
Check if the structure of the two images are similar
gimp:2a729ded-3296-423d-aec4-7dd55ed5fbb3
"""
print("src_path:", src_path)
print("tgt_path:", tgt_path)
img_src = Image.open(src_path)
img_tgt = Image.open(tgt_path)
structure_same = structure_check_by_ssim(img_src, img_tgt)
@@ -312,10 +315,46 @@ def check_contrast_increase_and_structure_sim(src_path, tgt_path):
return higher_contrast and structure_same
def check_config_status(actual_config_path, rule):
"""
Check if the GIMP status is as expected
"""
with open(actual_config_path, 'r') as f:
content = f.readlines()
for line in content:
if line.startswith('#') or line == '\n':
continue
items = line.strip().lstrip('(').rstrip(')\n').split()
if isinstance(rule["key"], str):
if items[0] == rule["key"] and items[-1] == rule["value"]:
return True
elif isinstance(rule["key"], list) and len(rule["key"]) == 2:
if items[0] == rule["key"][0] \
and items[1] == rule["key"][1] \
and items[-1] == rule["value"]:
return True
return False
if __name__ == "__main__":
image1_path = "../Downloads/1.png"
image2_path = "../Downloads/edited_darker.png"
actual_config_path = "../../../cache/sessionrc_test"
rule = {
"key": "hide-docks",
"value": "no"
}
print(check_config_status(actual_config_path, rule))
decrease_brightness(image1_path, image2_path)
actual_config_path = "../../../cache/action-history_test"
rule = {
"key": ["history-item", "\"filters-vignette\""],
"value": "1"
}
print(check_config_status(actual_config_path, rule))
increase_saturation(image1_path, image2_path)
actual_config_path = "../../../cache/gimprc_test"
rule = {
"key": "undo-levels",
"value": "100"
}
print(check_config_status(actual_config_path, rule))