From fbf1cef6d1f190ec0035a73967ec27d8b0471376 Mon Sep 17 00:00:00 2001 From: maryla-uc Date: Fri, 23 Aug 2024 18:39:52 +0200 Subject: [PATCH] avifgainmaputil: ignore the alt image icc when --ignore-profile is set (#2411) --- apps/avifgainmaputil/imageio.cc | 3 +++ tests/test_cmd_avifgainmaputil.sh | 24 ++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/apps/avifgainmaputil/imageio.cc b/apps/avifgainmaputil/imageio.cc index ce64437493..1711e6a638 100644 --- a/apps/avifgainmaputil/imageio.cc +++ b/apps/avifgainmaputil/imageio.cc @@ -163,6 +163,9 @@ avifResult ReadAvif(avifDecoder* decoder, const std::string& input_filename, } if (ignore_profile) { avifRWDataFree(&decoder->image->icc); + if (decoder->image->gainMap) { + avifRWDataFree(&decoder->image->gainMap->altICC); + } } return AVIF_RESULT_OK; diff --git a/tests/test_cmd_avifgainmaputil.sh b/tests/test_cmd_avifgainmaputil.sh index 08acaf72ab..096aad5f84 100755 --- a/tests/test_cmd_avifgainmaputil.sh +++ b/tests/test_cmd_avifgainmaputil.sh @@ -26,22 +26,27 @@ else fi AVIFGAINMAPUTIL="${BINARY_DIR}/avifgainmaputil" +AVIFENC="${BINARY_DIR}/avifenc" ARE_IMAGES_EQUAL="${BINARY_DIR}/tests/are_images_equal" # Input file paths. INPUT_AVIF_GAINMAP_SDR="${TESTDATA_DIR}/seine_sdr_gainmap_srgb.avif" INPUT_AVIF_GAINMAP_HDR="${TESTDATA_DIR}/seine_hdr_gainmap_srgb.avif" INPUT_AVIF_GAINMAP_HDR2020="${TESTDATA_DIR}/seine_hdr_rec2020.avif" -JPEG_AVIF_GAINMAP_SDR="${TESTDATA_DIR}/seine_sdr_gainmap_srgb.jpg" +INPUT_JPEG_AVIF_GAINMAP_SDR="${TESTDATA_DIR}/seine_sdr_gainmap_srgb.jpg" +AVIF_GAINMAP_SDR_WITH_ICC="${TESTDATA_DIR}/seine_sdr_gainmap_srgb_icc.jpg" # generated below # Output file names. AVIF_OUTPUT="avif_test_cmd_avifgainmaputil_output.avif" JPEG_OUTPUT="avif_test_cmd_avifgainmaputil_output.jpg" PNG_OUTPUT="avif_test_cmd_avifgainmaputil_output.png" +# generate another input file used in tests below +"${AVIFENC}" "${INPUT_JPEG_AVIF_GAINMAP_SDR}" "${AVIF_GAINMAP_SDR_WITH_ICC}" --qcolor 90 --qgain-map 90 + # Cleanup cleanup() { pushd ${TMP_DIR} - rm -- "${AVIF_OUTPUT}" "${JPEG_OUTPUT}" "${PNG_OUTPUT}" + rm -- "${AVIF_OUTPUT}" "${JPEG_OUTPUT}" "${PNG_OUTPUT}" "${AVIF_GAINMAP_SDR_WITH_ICC}" popd } trap cleanup EXIT @@ -57,9 +62,9 @@ pushd ${TMP_DIR} "${AVIFGAINMAPUTIL}" combine "${INPUT_AVIF_GAINMAP_SDR}" "${INPUT_AVIF_GAINMAP_HDR}" "${AVIF_OUTPUT}" \ -q 50 --downscaling 2 --yuv-gain-map 400 - "${AVIFGAINMAPUTIL}" combine "${JPEG_AVIF_GAINMAP_SDR}" "${INPUT_AVIF_GAINMAP_HDR}" "${AVIF_OUTPUT}" \ + "${AVIFGAINMAPUTIL}" combine "${INPUT_JPEG_AVIF_GAINMAP_SDR}" "${INPUT_AVIF_GAINMAP_HDR}" "${AVIF_OUTPUT}" \ -q 50 --qgain-map 90 && exit 1 # should fail because icc profiles are not supported - "${AVIFGAINMAPUTIL}" combine "${JPEG_AVIF_GAINMAP_SDR}" "${INPUT_AVIF_GAINMAP_HDR}" "${AVIF_OUTPUT}" \ + "${AVIFGAINMAPUTIL}" combine "${INPUT_JPEG_AVIF_GAINMAP_SDR}" "${INPUT_AVIF_GAINMAP_HDR}" "${AVIF_OUTPUT}" \ -q 50 --qgain-map 90 --ignore-profile "${AVIFGAINMAPUTIL}" combine "${INPUT_AVIF_GAINMAP_SDR}" "${INPUT_AVIF_GAINMAP_HDR2020}" "${AVIF_OUTPUT}" \ -q 50 --downscaling 2 --yuv-gain-map 400 @@ -68,14 +73,17 @@ pushd ${TMP_DIR} -q 90 --qgain-map 90 "${AVIFGAINMAPUTIL}" tonemap "${AVIF_OUTPUT}" "${PNG_OUTPUT}" --headroom 0 "${AVIFGAINMAPUTIL}" tonemap "${INPUT_AVIF_GAINMAP_SDR}" "${PNG_OUTPUT}" --headroom 0 --clli 400,500 - "${ARE_IMAGES_EQUAL}" "${PNG_OUTPUT}" "${JPEG_AVIF_GAINMAP_SDR}" 0 40 + "${ARE_IMAGES_EQUAL}" "${PNG_OUTPUT}" "${INPUT_JPEG_AVIF_GAINMAP_SDR}" 0 40 "${AVIFGAINMAPUTIL}" swapbase "${INPUT_AVIF_GAINMAP_SDR}" "${AVIF_OUTPUT}" --qcolor 90 --qgain-map 90 + # should fail because icc profiles are not supported + "${AVIFGAINMAPUTIL}" swapbase "${AVIF_GAINMAP_SDR_WITH_ICC}" "${AVIF_OUTPUT}" --qcolor 90 --qgain-map 90 && exit 1 + "${AVIFGAINMAPUTIL}" swapbase "${AVIF_GAINMAP_SDR_WITH_ICC}" "${AVIF_OUTPUT}" --qcolor 90 --qgain-map 90 --ignore-profile - "${AVIFGAINMAPUTIL}" convert "${JPEG_AVIF_GAINMAP_SDR}" "${AVIF_OUTPUT}" + "${AVIFGAINMAPUTIL}" convert "${INPUT_JPEG_AVIF_GAINMAP_SDR}" "${AVIF_OUTPUT}" # should fail because icc profiles are not supported - "${AVIFGAINMAPUTIL}" convert "${JPEG_AVIF_GAINMAP_SDR}" "${AVIF_OUTPUT}" --swap-base && exit 1 - "${AVIFGAINMAPUTIL}" convert "${JPEG_AVIF_GAINMAP_SDR}" "${AVIF_OUTPUT}" --swap-base --ignore-profile \ + "${AVIFGAINMAPUTIL}" convert "${INPUT_JPEG_AVIF_GAINMAP_SDR}" "${AVIF_OUTPUT}" --swap-base && exit 1 + "${AVIFGAINMAPUTIL}" convert "${INPUT_JPEG_AVIF_GAINMAP_SDR}" "${AVIF_OUTPUT}" --swap-base --ignore-profile \ --cicp 2/3/4 popd