Skip to content

Commit d075fb7

Browse files
committed
official/apply_camera_style - fixed pattern matching bug that allowed
camera styles to be applied twice fixed pattern matching bug affecting Canon EOS R, RP, and R5 Added more debugging statements to pattern matching functions
1 parent c95547c commit d075fb7

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

official/apply_camera_style.lua

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@
3434
Bill Ferguson <wpferguson@gmail.com>
3535
3636
CHANGES
37+
38+
20251202 - fixed pattern matching bugs affecting Canon EOS R? series
39+
styles and styles being applied twice if images are reimported
40+
41+
Added more debugging statements to pattern matching functions
3742
]]
3843

3944
local dt = require "darktable"
4045
local du = require "lib/dtutils"
4146
-- local df = require "lib/dtutils.file"
42-
-- local ds = require "lib/dtutils.string"
47+
local ds = require "lib/dtutils.string"
4348
-- local dtsys = require "lib/dtutils.system"
4449
local log = require "lib/dtutils.log"
4550
-- local debug = require "darktable.debug"
@@ -50,7 +55,7 @@ local log = require "lib/dtutils.log"
5055
-- - - - - - - - - - - - - - - - - - - - - - - -
5156

5257
local MODULE <const> = "apply_camera_style"
53-
local DEFAULT_LOG_LEVEL <const> = log.info
58+
local DEFAULT_LOG_LEVEL <const> = log.warn
5459
local TMP_DIR <const> = dt.configuration.tmp_dir
5560
local STYLE_PREFIX <const> = "_l10n_darktable|_l10n_camera styles|"
5661
local MAKER = 3
@@ -154,24 +159,32 @@ local function process_pattern(pattern)
154159

155160
local log_level = set_log_level(acs.log_level)
156161

162+
log.msg(log.debug, "input pattern is " .. pattern)
163+
157164
pattern = string.lower(pattern)
165+
log.msg(log.debug, "lower case pattern is " .. pattern)
158166
-- strip off series
159167
pattern = string.gsub(pattern, " series$", "?")
168+
log.msg(log.debug, "series stripped off pattern is " .. pattern)
160169
-- match a character
161-
if string.match(pattern, "?$") then
170+
if string.match(pattern, "r%?%?$") then
162171
-- handle EOS R case
163-
pattern = string.gsub(pattern, "?", ".?")
172+
pattern = string.gsub(pattern, "%?%?", ".?")
173+
log.msg(log.debug, "matched EOS R pattern is " .. pattern)
164174
else
165175
pattern = string.gsub(pattern, "?", ".")
176+
log.msg(log.debug, "didn't match EOS R pattern is " .. pattern)
166177
end
167-
pattern = string.gsub(pattern, " ", " ?")
168178
-- escape dashes
169179
pattern = string.gsub(pattern, "%-", "%%-")
180+
log.msg(log.debug, "escape dashes conditional pattern is " .. pattern)
170181
-- make spaces optional
171182
pattern = string.gsub(pattern, " ", " ?")
172183
-- until we end up with a set, I'll defer set processing, i.e. [...]
184+
--log.msg(log.debug, "make spaces conditional again? pattern is " .. pattern)
173185
-- anchor the pattern to ensure we don't short match
174186
pattern = "^" .. pattern .. "$"
187+
log.msg(log.debug, "anchored pattern is " .. pattern)
175188

176189
restore_log_level(log_level)
177190

@@ -326,9 +339,11 @@ local function has_style_tag(image, tag_name)
326339
log.msg(log.debug, "looking for tag " .. tag_name)
327340

328341
for _, tag in ipairs(image:get_tags()) do
329-
log.msg(log.debug, "checking against " .. tag.name)
330-
if tag.name == tag_name then
331-
log.msg(log.debug, "matched tag " .. tag_name)
342+
log.msg(log.debug, "got attached tag " .. tag.name)
343+
local cleaned_tag_name = string.gsub(tag_name, "_l10n_", "")
344+
log.msg(log.debug, "checking against " .. cleaned_tag_name)
345+
if ds.sanitize_lua(tag.name) == cleaned_tag_name then
346+
log.msg(log.debug, "matched tag " .. cleaned_tag_name)
332347
result = true
333348
end
334349
end
@@ -358,7 +373,7 @@ local function mangle_model(model)
358373
model = string.gsub(model, "eos 1200d", "eos rebel t5")
359374
model = string.gsub(model, "eos 1300d", "eos rebel t6")
360375
model = string.gsub(model, "eos 2000d", "eos rebel t7")
361-
log.msg(log.debug, "mandle model returning " .. model)
376+
log.msg(log.debug, "mangle model returning " .. model)
362377
end
363378

364379
restore_log_level(log_level)
@@ -389,14 +404,15 @@ local function apply_style_to_images(images)
389404
if acs.styles[maker] then
390405
local no_match = true
391406
for i, pattern in ipairs(acs.styles[maker].patterns) do
407+
log.msg(log.debug, "pattern is " .. pattern)
392408
if string.match(model, pattern) or
393409
(i == #acs.styles[maker].patterns and string.match(pattern, "generic")) then
394410
local tag_name = "darktable|style|" .. acs.styles[maker].styles[i].name
395411
if not has_style_tag(image, tag_name) then
396412
image:apply_style(acs.styles[maker].styles[i])
397-
no_match = false
398413
log.msg(log.info, "applied style " .. acs.styles[maker].styles[i].name .. " to " .. image.filename)
399414
end
415+
no_match = false
400416
log.log_level(loglevel)
401417
break
402418
end

0 commit comments

Comments
 (0)