From 5751fce50ead2e7d576fe93f4669c1477156b558 Mon Sep 17 00:00:00 2001 From: SamSamFR Date: Wed, 7 Aug 2013 01:42:18 +0200 Subject: [PATCH] fix major BUG : changeOrder can bump inferior photo to head. Plus: added MPixel to the size comparison the comparison between head and new, based on a sequence of parameters, should be lexicographical. Only proceed to next if current parameters are found equal ! As it was, an inferior new photo could be bumped to head. eg : image A is raw, but not rated. image B is a jpg export, rated 4 stars, and the rating option is set. When this function analyses B, it does not enter the RAW comparison block, goes on, then compares superior to A in the RATING block. more elegant solution would be to build a function (like act) from the activated options, which is then used to map photos to tuple (RAW, MPixels, size, ...), then use lexicographical order on that tuple. But I've just started using Lua today to fix that plugin and I don't know how to do it that way, so I just added a plain boolean "continueOrder" ... About MPixels : exporting a jpg to a smaller res can very well result in larger fileSize. On the other hand, one never upsamples a file when exporting. So using MPixels before fileSize is a good idea. --- src/Teekesselchen.lua | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/Teekesselchen.lua b/src/Teekesselchen.lua index fefad25..6a92866 100644 --- a/src/Teekesselchen.lua +++ b/src/Teekesselchen.lua @@ -64,27 +64,43 @@ local function markDuplicateEnv(settings, keyword) if #tree == 1 then tree[1]:addKeyword(keyword) end + local continueOrder = true -- eg. if size has been found < to head, set to false and don't try further order changes that could fuck it up. if uF then -- deal with raw preference if pRaw then - if tree[1]:getRawMetadata("fileFormat") ~= "RAW" then - if photo:getRawMetadata("fileFormat") == "RAW" then + local HisRaw, NisRaw = tree[1]:getRawMetadata("fileFormat")=="RAW", photo:getRawMetadata("fileFormat")=="RAW" + if not HisRaw and NisRaw then changeOrder(tree,photo) return true - end end + continueOrder = (HisRaw == NisRaw) end -- deal with file size - if pL then + if pL and continueOrder then local sizeHead = tree[1]:getRawMetadata("fileSize") local sizeNew = photo:getRawMetadata("fileSize") - if sizeNew > sizeHead then - changeOrder(tree,photo) - return true + local function getMP(p) -- get MegaPixels count from photo + local l = {} + p:getFormattedMetadata("dimensions"):gsub("(%d+)%s*x%s*(%d+)", function (x,y) table.insert(l,x*y*1e-6) end) + return l[1] end - end - -- deal with rating - if pR then + local MPhead, MPNew = getMP(tree[1]), getMP(photo) + if MPhead and MPNew then + if MPNew > MPhead then + changeOrder(tree, photo) + return true + end + continueOrder = (MPhead==MPNew) + else if sizeNew and sizeNew > sizeHead then + changeOrder(tree,photo) + return true + else if sizeNew then + continueOrder = (sizeNew == sizeHead) + end + end + end + end -- deal with rating + if pR and continueOrder then local ratingHead = tree[1]:getRawMetadata("rating") local ratingNew = photo:getRawMetadata("rating") if ratingHead == nil then ratingHead = 0 end @@ -95,7 +111,7 @@ local function markDuplicateEnv(settings, keyword) end end -- deal with virtual copies - if not iVC then + if not iVC and continueOrder then if tree[1]:getRawMetadata("isVirtualCopy") then if not photo:getRawMetadata("isVirtualCopy") then changeOrder(tree,photo)