On Wed, Aug 7, 2019, at 00:49, Remco Viëtor wrote:

> Still, if there would be a possibility to tell dt which lenses you actually 
> possess, it might be possible to get the XMP field filled out automatically, 
> which would be useful, especially in relation with lensfun/lens correction.

Well, for what it's worth, attached are crudely abstracted versions of the Lua 
scriptst I'm currently using for managing old manual lenses on my Olympus 
cameras. I use the copyright fields in-camera to assign a short lens ID string 
(and theoretically also an aperture value, but in reality I rarely take the 
trouble to set this; it defaults to maximum). When a "dumb" lens is used, the 
field in my camera RAW files contains "None", so on import I check for this and 
flag the image with the "red" color code for utility purposes, and then search 
a list of my lenses for a matching ID to map to a lens name.

On export, images with the "red" flag have the contents of that field filled 
with the lens name by exiftool, for posterity. It's an ugly, dirty, clumsy 
hack, but it works pretty well for me, and could probably be adapted to use 
with other cameras and workflows. Oh, it also adds a lightable module for 
manually filling in this information, since I often forget to actually change 
the settings in-camera and need to fix it later... that might be the most 
generally useful part. :)

Anyway, if anybody wants to create something more user-friendly based on this, 
it can be considered public domain for that purpose. Short of that, it should 
be considered pseudo-code... please don't attempt to use it if you aren't 
already comfortable with Lua scripting.

-- 
jys
____________________________________________________________________________
darktable user mailing list
to unsubscribe send a mail to [email protected]

local dt = require "darktable"
local my_lenses = require "_mystuff/myLenses"

dt.register_event("post-import-image",
  function (event, image)
    if image.exif_lens == "None" then -- Apply a red label to any import missing lens info
      image.red = true
      if not (image.creator == "") then -- Check for anything matching a lens ID in this field
        local found_lens = Nil
        for i, lens_record in ipairs(my_lenses) do
          if lens_record["id"] == image.creator then
            found_lens = lens_record
          end
        end
        if found_lens then
          image.exif_lens = found_lens.name
          image.exif_focal_length = found_lens.fl
          if image.rights == "" then               -- Did I also manually set an f-number in camera?
            image.exif_aperture = found_lens.fnum  -- If not, just use the f_num value from the lens db
          else
            image.exif_aperture = image.rights
          end
        end
      end
    end
    image.creator = "" -- Clear these fields now that we're done abusing them 
    image.rights = ""
  end
)

dt.register_event("intermediate-export-image",
  function (event, image, filename, format, storage)
    if format.mime == "image/jpeg" then
      local lens_exif = ""
      if image.red == true then
        lens_exif = "'-LensModel=" .. image.exif_lens .. "' '-FocalLength=" .. image.exif_focal_length .. "' '-FNumber=" .. image.exif_aperture .. "' '-MaxApertureValue=" .. image.exif_aperture .. "' '-LensInfo=" .. image.exif_focal_length .. " " .. image.exif_focal_length .. " " .. image.exif_aperture .. " " .. image.exif_aperture .. "' "
      end
        os.execute("exiftool -overwrite_original -v -m " .. lens_exif .. filename )
    end
  end
)


local dt = require "darktable"

local lens_db = { -- Create a table of records for each lens
  {id = Nil, name = "None", fl = "", fnum = ""},
  {id = "1", name = "koifisheye 7.5mm f/3.5", fl = "7.5", fnum = "3.5"},
  {id = "2", name = "blechinon super ultragon 50mm f/1.4", fl = "50", fnum = "1.4"},
  {id = "3", name = "fubagon 25mm f/1.9", fl = "25", fnum = "1.9"},
}

local lens_list = {} -- Make a pretty list of names for combobox
for i, lens_record in ipairs(lens_db) do
  lens_list[i] = lens_record["name"]
end

local fl_entry = dt.new_widget("entry"){
  placeholder = "0",
  editable = true,
  tooltip = "Lens focal length"
}

local fnum_entry = dt.new_widget("entry"){
  placeholder = "0",
  editable = true,
  tooltip = "Lens f/number"
}

local name_combobox = dt.new_widget("combobox"){
  changed_callback = function (self)
    local lens_record = lens_db[self.selected]
    if lens_record then
      fl_entry.text = lens_record["fl"]
      fnum_entry.text = lens_record["fnum"]
    end
  end,
  editable = true,
  table.unpack(lens_list)
}

local apply_button = dt.new_widget("button"){
  label = " apply ",
  clicked_callback = function (_)
    local counter = 0
    for i, image in ipairs(dt.gui.action_images) do
      image.exif_lens = name_combobox.value
      image.exif_focal_length = fl_entry.text
      image.exif_aperture = fnum_entry.text
      counter = i -- Just take the last index
    end
    dt.print("lens data applied to "..counter.." images")
  end
}

dt.register_lib(
  "myLenses",     -- Module name
  "myLenses",     -- name
  true,                -- expandable
  false,               -- resetable
  {[dt.gui.views.lighttable] = {"DT_UI_CONTAINER_PANEL_RIGHT_CENTER", 1}},
  dt.new_widget("box"){
    orientation = "vertical",
    name_combobox,
    dt.new_widget("box"){
      orientation = "horizontal",
      apply_button, fl_entry, fnum_entry,
    },
  },
  nil,-- view_enter
  nil -- view_leave
)

return lens_db -- Export lens data to other scripts that require this one

Reply via email to