From 7e8340c526a264a98efcd2917a9e5e1663fcc04a Mon Sep 17 00:00:00 2001 From: Krzysztof Kotowicz Date: Fri, 20 Sep 2024 11:38:24 +0200 Subject: [PATCH] Don't overwrite existing stack slots (that way the first matching image in a stack will be used, vs the last one). --- contrib/ultrahdr.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/contrib/ultrahdr.lua b/contrib/ultrahdr.lua index 5f0ca6f..cba1cc9 100644 --- a/contrib/ultrahdr.lua +++ b/contrib/ultrahdr.lua @@ -216,15 +216,21 @@ local function get_stacks(images, encoding_variant) if extra_image_extension and df.get_filetype(v.filename) == extra_image_extension then is_extra = true end - -- we assume every image in the stack is generated from the same source image file + -- We assume every image in the stack is generated from the same source image file local key = df.chop_filetype(v.path .. PS .. v.filename) if stacks[key] == nil then stacks[key] = {} end - if extra_image_content_type and (stacks[key]["sdr"] or is_extra) then - stacks[key][extra_image_content_type] = v + if extra_image_content_type and (is_extra or stacks[key]["sdr"]) then + -- Don't overwrite existing entries + if not stacks[key][extra_image_content_type] then + stacks[key][extra_image_content_type] = v + end elseif not is_extra then - stacks[key]["sdr"] = v + -- Don't overwrite existing entries + if not stacks[key]["sdr"] then + stacks[key]["sdr"] = v + end end end -- remove invalid stacks