From e55810809e439d4dd89a6c05cd77106492c7ea87 Mon Sep 17 00:00:00 2001 From: tsuky_chen <91684733+chenjix@users.noreply.github.com> Date: Sun, 8 Jun 2025 22:12:56 +0800 Subject: [PATCH] Fix libreoffice impress evaluation (#209) Co-authored-by: chenjix <211250101@smail.nju.edu.cn> --- desktop_env/evaluators/metrics/slides.py | 19 +++++++++++++++++-- desktop_env/evaluators/metrics/vlc.py | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/desktop_env/evaluators/metrics/slides.py b/desktop_env/evaluators/metrics/slides.py index 90eea64..307752f 100644 --- a/desktop_env/evaluators/metrics/slides.py +++ b/desktop_env/evaluators/metrics/slides.py @@ -389,10 +389,22 @@ def evaluate_presentation_fill_to_rgb_distance(pptx_file, rules): except: original_rgb = None + def get_rgb_from_color(color): + try: + if hasattr(color, "rgb"): + return color.rgb + else: + return None + except: + return None + def slide_fill_distance_to_rgb(_slide, _rgb, _original_rgb): fill = _slide.background.fill if fill.type == 1: - r1, g1, b1 = fill.fore_color.rgb + color_rgb = get_rgb_from_color(fill.fore_color) + if color_rgb is None: + return 1 + r1, g1, b1 = color_rgb r2, g2, b2 = _rgb if _original_rgb is not None: @@ -404,7 +416,10 @@ def evaluate_presentation_fill_to_rgb_distance(pptx_file, rules): elif fill.type == 5: master_fill = _slide.slide_layout.slide_master.background.fill if master_fill.type == 1: - r1, g1, b1 = master_fill.fore_color.rgb + color_rgb = get_rgb_from_color(master_fill.fore_color) + if color_rgb is None: + return 1 + r1, g1, b1 = color_rgb else: return 1 r2, g2, b2 = _rgb diff --git a/desktop_env/evaluators/metrics/vlc.py b/desktop_env/evaluators/metrics/vlc.py index 94892bd..5af7b50 100644 --- a/desktop_env/evaluators/metrics/vlc.py +++ b/desktop_env/evaluators/metrics/vlc.py @@ -117,7 +117,7 @@ def compare_images(image1_path, image2_path, **options): similarity_index = ssim(image1_array, image2_array) epsilon = 0.01 - if base_score is None: + if base_score is not None: if similarity_index >= base_score + epsilon: return (similarity_index - base_score) / (1 - base_score) else: