@@ -542,11 +542,14 @@ local PLACEHOLDERS = {"ROLL.NAME",
542542 " FILE.FOLDER" ,
543543 " FILE.NAME" ,
544544 " FILE.EXTENSION" ,
545- " ID" ,
545+ " ID" ,
546+ " IMAGE.ID" ,
547+ " IMAGE.ID.NEXT" ,
546548 " VERSION" ,
547549 " VERSION.IF.MULTI" ,
548550 " VERSION.NAME" ,
549551 " DARKTABLE.VERSION" ,
552+ " Xmp.darktable.version" ,
550553 " DARKTABLE.NAME" , -- Not Implemented
551554 " SEQUENCE" ,
552555 " WIDTH.SENSOR" ,
@@ -612,10 +615,15 @@ local PLACEHOLDERS = {"ROLL.NAME",
612615 " LABELS" ,
613616 " LABELS.ICONS" , -- Not Implemented
614617 " TITLE" ,
618+ " Xmp.dc.title" ,
615619 " DESCRIPTION" ,
620+ " Xmp.dc.description" ,
616621 " CREATOR" ,
622+ " Xmp.dc.creator" ,
617623 " PUBLISHER" ,
624+ " Xmp.dc.publisher" ,
618625 " RIGHTS" ,
626+ " Xmp.dc.rights" ,
619627 " TAGS" , -- Not Implemented
620628 " SIDECAR.TXT" , -- Not Implemented
621629 " FOLDER.PICTURES" ,
@@ -652,6 +660,37 @@ local function get_colorlabels(image)
652660 return labels
653661end
654662
663+ -- handle the ROLL.NAME[n] case
664+
665+ local function build_rollname_substitution_list (image , variable_string )
666+ local old_log_level = log .log_level ()
667+ log .log_level (dtutils_string .log_level )
668+
669+ for match in string.gmatch (variable_string , " %$%(.-%)?%)" ) do -- grab each complete variable
670+ log .msg (log .info , " match is " .. match )
671+
672+ local var = string.match (match , " %$%((.-%)?)%)" ) -- strip of the leading $( and trailing )
673+ log .msg (log .info , " var is " .. var )
674+
675+ local element = nil
676+
677+ if string.match (var , " ROLL.NAME%[" ) then
678+ element = string.match (var , " %[(%d)%]" )
679+
680+ local path = du .split (image .film .path , dt .configuration .running_os ~= " windows" and " /" or " \\ " )
681+
682+ element = tonumber (element ) + 1 -- add one because c arrays are 0 based and lua are 1 based
683+
684+ if element > # path then
685+ log .msg (log .warn , " ROLL.NAME element requested was more than number of elements in film roll" )
686+ substitutes [var ] = " "
687+ else
688+ substitutes [var ] = path [(# path + 1 ) - element ]
689+ end
690+ end
691+ end
692+ end
693+
655694-- find the $CATEGORYn and $CATEGORY[n,m] requests and add them to the substitute list
656695
657696local function build_category_substitution_list (image , variable_string )
@@ -768,10 +807,13 @@ function dtutils_string.build_substitute_list(image, sequence, variable_string,
768807 dtutils_string .get_basename (image .filename ),-- FILE.NAME
769808 dtutils_string .get_filetype (image .filename ),-- FILE.EXTENSION
770809 image .id , -- ID
810+ image .id , -- IMAGE.ID
811+ dt .database [# dt .database ].id + 1 , -- IMAGE.ID.NEXT
771812 image .duplicate_index , -- VERSION
772813 version_multi , -- VERSION.IF_MULTI
773814 image .version_name and image .version_name or " " , -- VERSION.NAME
774815 dt .configuration .version , -- DARKTABLE.VERSION
816+ dt .configuration .version , -- Xmp.darktable.version
775817 " " , -- DARKTABLE.NAME
776818 string.format (" %04d" , sequence ), -- SEQUENCE
777819 image .width , -- WIDTH.SENSOR
@@ -837,10 +879,15 @@ function dtutils_string.build_substitute_list(image, sequence, variable_string,
837879 labels , -- LABELS
838880 " " , -- LABELS.ICONS - wont be implemented
839881 image .title and image .title or " " , -- TITLE
882+ image .title and image .title or " " , -- Xmp.dc.title
840883 image .description and image .description or " " , -- DESCRIPTION
884+ image .description and image .description or " " , -- Xmp.dc.description
841885 image .creator and image .creator or " " , -- CREATOR
886+ image .creator and image .creator or " " , -- Xmp.dc.creator
842887 image .publisher and image .publisher or " " , -- PUBLISHER
888+ image .publisher and image .publisher or " " , -- Xmp.dc.publisher
843889 image .rights and image .rights or " " , -- RIGHTS
890+ image .rights and image .rights or " " , -- Xmp.dc.rights
844891 " " , -- TAGS - wont be implemented
845892 " " , -- SIDECAR.TXT - wont be implemented
846893 pictures_folder , -- FOLDER.PICTURES
@@ -862,6 +909,7 @@ function dtutils_string.build_substitute_list(image, sequence, variable_string,
862909 -- do category substitutions separately
863910
864911 build_category_substitution_list (image , variable_string )
912+ build_rollname_substitution_list (image , variable_string )
865913
866914 log .log_level (old_log_level )
867915end
@@ -889,10 +937,13 @@ function dtutils_string.get_substitution_tooltip()
889937 _ (" $(FILE.NAME) - basename of the input image" ),
890938 _ (" $(FILE.EXTENSION) - extension of the input image" ),
891939 _ (" $(ID) - image ID" ),
940+ _ (" $(IMAGE.ID) - image ID" ),
941+ _ (" $(IMAGE.ID.NEXT) - next image ID to be assigned on import" ),
892942 _ (" $(VERSION) - duplicate version" ),
893943 _ (" $(VERSION.IF_MULTI) - same as $(VERSION) but null string if only one version exists" ),
894944 _ (" $(VERSION.NAME) - version name from metadata" ),
895945 _ (" $(DARKTABLE.VERSION) - current darktable version" ),
946+ _ (" $(Xmp.darktable.version) - current darktable version" ),
896947 -- _("$(DARKTABLE.NAME) - darktable name"), -- not implemented
897948 _ (" $(SEQUENCE[n,m]) - sequence number, n: number of digits, m: start number" ),
898949 _ (" $(WIDTH.SENSOR) - image sensor width" ),
@@ -957,10 +1008,15 @@ function dtutils_string.get_substitution_tooltip()
9571008 _ (" $(LABELS) - color labels as text" ),
9581009 -- _("$(LABELS.ICONS) - color labels as icons"),-- not implemented
9591010 _ (" $(TITLE) - title from metadata" ),
1011+ _ (" $(Xmp.dc.title) - title from metadata" ),
9601012 _ (" $(DESCRIPTION) - description from metadata" ),
1013+ _ (" $(Xmp.dc.description) - description from metadata" ),
9611014 _ (" $(CREATOR) - creator from metadata" ),
1015+ _ (" $(Xmp.dc.creator) - creator from metadata" ),
9621016 _ (" $(PUBLISHER) - publisher from metadata" ),
1017+ _ (" $(Xmp.dc.publisher) - publisher from metadata" ),
9631018 _ (" $(RIGHTS) - rights from metadata" ),
1019+ _ (" $(Xmp.dc.rights) - rights from metadata" ),
9641020 -- _("$(TAGS) - tags as set in metadata settings"),
9651021 _ (" $(CATEGORY[n,category]) - subtag of level n in hierarchical tags" ),
9661022 _ (" $(SIDECAR_TXT) - contents of .txt sidecar file, if present" ),
@@ -1010,6 +1066,11 @@ local function treat(var_string)
10101066 if not ret_val then ret_val = " " end
10111067 log .msg (log .info , " ret_val is " .. ret_val )
10121068
1069+ elseif string.match (var_string , " ROLL.NAME%[" ) then
1070+ ret_val = substitutes [var_string ]
1071+ if not ret_val then ret_val = " " end
1072+ log .msg (log .info , " ret_val is " .. ret_val )
1073+
10131074 elseif string.match (var_string , " SEQUENCE%[" ) then
10141075 local width , start = string.match (var_string , " (%d+),(%d+)" )
10151076 local seq_val = tonumber (substitutes [var ])
@@ -1243,6 +1304,49 @@ function dtutils_string.substitute(image, sequence, variable_string, username, p
12431304 return str
12441305end
12451306
1307+ dtutils_string .libdoc .functions [" format_exposure" ] = {
1308+ Name = [[ format_exposure]] ,
1309+ Synopsis = [[ format exif_exposure from dt_lua_image_t to an exposure time]] ,
1310+ Usage = [[ local ds = require "lib/dtutils.string"
1311+ ds.format_exposure(image.exif_exposure)
1312+ image.exif_exposure - dt_lua_image_t exif exposure field
1313+ Description = [[format_exposure takes the EXIF exposure field and formats it into an exposure string]] ,
1314+ Return_Value = [[ result - string - the EXIF exposure formatted as an exposure string]] ,
1315+ Limitations = [[ ]] ,
1316+ Example = [[ ]] ,
1317+ See_Also = [[ https://docs.darktable.org/usermanual/4.6/en/special-topics/variables/]] ,
1318+ Reference = [[ ]] ,
1319+ License = [[ ]] ,
1320+ Copyright = [[ ]] ,
1321+ }
1322+
1323+ local function _nearbyintf (v )
1324+ return math.floor (v + .5 )
1325+ end
1326+
1327+ function dtutils_string .format_exposure (exif_exposure )
1328+ result = nil
1329+
1330+ if exif_exposure > 1.0 then
1331+ if _nearbyintf (exif_exposure ) == exif_exposure then
1332+ result = string.format (" %.0f″" , exif_exposure )
1333+ else
1334+ result = string.format (" %.1f″" , exif_exposure )
1335+ end
1336+ -- catch everything below 0.3 seconds
1337+ elseif exif_exposure < 0.2 then
1338+ result = string.format (" 1/%.0f" , 1.0 / exif_exposure )
1339+ -- catch 1/2, 1/3, ...
1340+ elseif _nearbyintf (1.0 / exif_exposure ) == (1.0 / exif_exposure ) then
1341+ result = string.format (" 1/%.0f" , 1.0 / exif_exposure )
1342+ -- catch 1/1.3, 1/1.6, ...
1343+ elseif (10 * _nearbyintf (10.0 / exif_exposure )) == _nearbyintf (100.0 / exif_exposure ) then
1344+ result = string.format (" 1/%.1f" , 1.0 / exif_exposure )
1345+ else
1346+ result = string.format (" %.1f″" , exif_exposure )
1347+ end
12461348
1349+ return result
1350+ end
12471351
12481352return dtutils_string
0 commit comments