Skip to content

Commit 19c0495

Browse files
committed
HDRMerge: allow non-word characters in filenames
Previous filename generation led to e.g timestamps like 20:00:03 getting cut apart.
1 parent f4c2a41 commit 19c0495

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

contrib/HDRMerge.lua

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,20 @@ local function InRange(test, low, high) --tests if test value is within range of
138138
end
139139
end
140140

141-
local function GetFileName(full_path) --Parses a full path (path/filename_identifier.extension) into individual parts
142-
--[[Input: Folder1/Folder2/Folder3/Img_0001.CR2
141+
local function FileNameParts(filename_ext) --Parses a filename (filename_identifier.extension) into individual parts
142+
--[[Input: Img_0001.CR2
143143
144144
Returns:
145-
path: Folder1/Folder2/Folder3/
146145
filename: Img_0001
147146
identifier: 0001
148-
extension: .CR2
149147
150148
EX:
151-
path_1, file_1, id_1, ext_1 = GetFileName(full_path_1)
149+
file_1, id_1 = FileNameParts(im_filename)
152150
]]
153-
local path = string.match(full_path, '.*[\\/]')
154-
local filename = string.gsub(string.match(full_path, '[%w-_]*%.') , '%.' , '' )
155-
local identifier = string.match(filename, '%d*$')
156-
local extension = string.match(full_path, '%.%w*')
157-
return path, filename, identifier, extension
151+
local ext_idx = string.find(filename_ext, '%.[^%.]*$')
152+
local filename = string.sub(filename_ext, 1, ext_idx and ext_idx - 1 or nil)
153+
local identifier = string.match(filename, '%d*$') or ''
154+
return filename, identifier
158155
end
159156

160157
local function CleanSpaces(text) --removes spaces from the front and back of passed in text
@@ -222,25 +219,28 @@ local function DoBatch(prog_table, images, output_arg)
222219
-- Copy program arguments
223220
for k, v in pairs(prog_table) do prog[k] = v end
224221
local out_path = ''
225-
local smallest_id = math.huge
222+
local smallest_id_n = math.huge
226223
local smallest_name = ''
227-
local largest_id = 0
224+
local largest_id_n = -1
225+
local largest_id = ''
228226
local source_raw = {}
229227
local image_files = {}
230228
for _,image in ipairs(images) do --loop to concat the images string, also track the image indexes for use in creating the final image name (eg; IMG_1034-1037.dng)
231229
if not image.is_hdr then
232-
num_images = num_images + 1
233230
local curr_image = image.path..os_path_seperator..image.filename
234231
table.insert(image_files, df.sanitize_filename(curr_image))
235-
_unused, source_name, source_id = GetFileName(image.filename)
236-
source_id = tonumber(source_id) or 0
237-
if source_id < smallest_id then
232+
source_name, source_id = FileNameParts(image.filename)
233+
local source_id_n = tonumber(source_id) or 0
234+
if source_id_n < smallest_id_n then
238235
out_path = image.path
239-
smallest_id = source_id
236+
smallest_id_n = source_id_n
240237
smallest_name = source_name
241238
source_raw = image
242239
end
243-
if source_id > largest_id then largest_id = source_id end
240+
if source_id_n > largest_id_n then
241+
largest_id = source_id
242+
largest_id_n = source_id_n
243+
end
244244
end
245245
end
246246
if #image_files < 2 then

0 commit comments

Comments
 (0)