Warning, /games/libkdegames/src/carddecks/tools/CompareSVGs.cmake is written in an unsupported language. File is not indexed.
0001 # SPDX-FileCopyrightText: 2023 Friedrich W. H. Kossebau <kossebau@kde.org>
0002 #
0003 # SPDX-License-Identifier: BSD-3-Clause
0004
0005 set(id ${ID})
0006 set(render_tool ${RENDERELEMENT})
0007 set(rcompare_tool ${COMPARE})
0008 set(old_file ${OLD_FILE})
0009 set(new_file ${NEW_FILE})
0010 set(work_dir "${WORKING_DIR}/${id}/check")
0011
0012 if (NOT EXISTS "${old_file}")
0013 message(FATAL_ERROR "Old file ${old_file} does not exist")
0014 endif()
0015 if (NOT EXISTS "${new_file}")
0016 message(FATAL_ERROR "New file ${new_file} does not exist")
0017 endif()
0018
0019 # generate list of card element ids
0020 set(rank "king" "queen" "jack" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10")
0021 set(suit "club" "spade" "diamond" "heart")
0022
0023 set(card_ids "back")
0024 foreach(s ${suit})
0025 foreach(r ${rank})
0026 list(APPEND card_ids "${r}_${s}")
0027 endforeach()
0028 endforeach()
0029
0030 # ensure working dir
0031 make_directory(${work_dir})
0032
0033 # compare rendering for each card type
0034 foreach(c ${card_ids})
0035 # generate PNG for original
0036 set(old_png_file "${c}_old.png")
0037 execute_process(
0038 COMMAND ${render_tool} ${old_file} ${c} 200 200 ${old_png_file}
0039 WORKING_DIRECTORY ${work_dir}
0040 )
0041 # generate PNG for modified
0042 set(new_png_file "${c}_new.png")
0043 execute_process(
0044 COMMAND ${render_tool} ${new_file} ${c} 200 200 ${new_png_file}
0045 WORKING_DIRECTORY ${work_dir}
0046 )
0047
0048 # compare
0049 execute_process(
0050 COMMAND ${rcompare_tool}
0051 -metric MAE
0052 ${old_png_file}
0053 ${new_png_file}
0054 /dev/null # no use for difference image
0055 WORKING_DIRECTORY ${work_dir}
0056 OUTPUT_VARIABLE compare_output
0057 ERROR_VARIABLE compare_output
0058 )
0059 string(REGEX MATCH "^[0-9]*(\\.[0-9]*)?" compare_result "${compare_output}")
0060 if("${compare_result}" STRGREATER 0)
0061 message(STATUS "Difference for ${id}, element ${c}: ${compare_result}")
0062 endif()
0063 endforeach()