I got a new phone Samsung Galaxy S22 which is able to shoot raws (dng format). The dedicated app from Samsung for raws, called Expert Raw, unfortunately cannot be imported in darktable:
Anyway, the dngs from the default camera app can be opened. Apparently they do not contain metadata for lens correction. I therefore started to build a lensfun entry and here the problems started.
As the phone has four cameras (one front, three rear) the standard lensfun entries are not compatible as they require a single crop factor over all “lenses”. These are not identical for the four cameras. Moreover the dng is agnostic to the actual camera used. Thus darktable will not know which camera is used and cannot apply the camera specific corrections.
However from the dng metadata the correct camera can be derived as each camera has a different focal length (and different pixel sizes). I therefore wrote a small script which adds the “lens” information to the dng metadata.
cat /usr/local/bin/modify_dngs.sh
#!/usr/bin/env bash
BASE_DIR="/mnt/media/georg/Bilder/import/Galaxy S22"
CAM_MODEL="SM-S901B"
# Ultra wide: 2.2 mm
exiftool -overwrite_original -r -ext dng \
-if '$Model eq "'"$CAM_MODEL"'" and $FocalLength# == 2.2' \
-LensMake="Samsung" \
-LensModel="ultra wide rear" \
-Model="SM-S901B-uw" \
"$BASE_DIR"
# Wide: 5.4 mm
exiftool -overwrite_original -r -ext dng \
-if '$Model eq "'"$CAM_MODEL"'" and $FocalLength# == 5.4' \
-LensMake="Samsung" \
-LensModel="wide rear" \
-Model="SM-S901B-w" \
"$BASE_DIR"
# Tele: 7 mm
exiftool -overwrite_original -r -ext dng \
-if '$Model eq "'"$CAM_MODEL"'" and $FocalLength# == 7' \
-LensMake="Samsung" \
-LensModel="tele rear" \
-Model="SM-S901B-t" \
"$BASE_DIR"
# Front: 3.3 mm
exiftool -overwrite_original -r -ext dng \
-if '$Model eq "'"$CAM_MODEL"'" and $FocalLength# == 3.3' \
-LensMake="Samsung S22" \
-LensModel="front" \
-Model="SM-S901B-f" \
"$BASE_DIR"
touch "$BASE_DIR/modify_dngs_last_run" # gives a quick check when script was run for the last time
exit 0 # required as exiftools throws an exit code of 2 if no file is changed
Basically we change the camera model to one of four subtypes and introduce the camera information also as LensModel.
With this it is now possible to create four sets of lensfun entries which cover the four possibilities:
~/.local/share/lensfun$ cat s22_all.xml
<lensdatabase version="1">
<camera>
<maker>Samsung</maker>
<model>SM-S901B-w</model>
<model lang="en">Galaxy S22 wide</model>
<mount>samsung-S22-w</mount>
<cropfactor>4.25</cropfactor>
</camera>
<lens>
<maker>Samsung</maker>
<model>Samsung S22 wide</model>
<model lang="en">fixed lens</model>
<model lang="de">festes Objektiv</model>
<mount>samsung-S22-w</mount>
<type>rectilinear</type>
<cropfactor>4.25</cropfactor>
<aspect-ratio>4:3</aspect-ratio>
<calibration>
<distortion model="ptlens" focal="5.4" a="-0.003" b="0.000" c="0.031"/>
<tca model="poly3" focal="5.4" br="0.0000233" vr="0.9999704" bb="-0.0000653" vb="1.0000950"/>
<vignetting model="pa" focal="5.4" aperture="1.8" distance="10" k1="-0.1496052" k2="0.2121462" k3="-0.1891344"/>
<vignetting model="pa" focal="5.4" aperture="1.8" distance="1000" k1="-0.1496052" k2="0.2121462" k3="-0.1891344"/>
</calibration>
</lens>
<camera>
<maker>Samsung</maker>
<model>SM-S901B-uw</model>
<model lang="en">Galaxy S22 ultra wide</model>
<mount>samsung-S22-uw</mount>
<cropfactor>5.9</cropfactor>
</camera>
<lens>
<maker>Samsung</maker>
<model>Samsung S22 ultra wide</model>
<model lang="en">fixed lens</model>
<model lang="de">festes Objektiv</model>
<mount>samsung-S22-uw</mount>
<type>rectilinear</type>
<cropfactor>5.9</cropfactor>
<aspect-ratio>4:3</aspect-ratio>
<calibration>
<distortion model="ptlens" focal="2.2" a="-0.082" b="0.165" c="-0.085" />
<tca model="poly3" focal="2.2" br="0.0000065" vr="1.0001798" bb="-0.0000500" vb="1.0002138" />
</calibration>
</lens>
<camera>
<maker>Samsung</maker>
<model>SM-S901B-t</model>
<model lang="en">Galaxy S22 tele</model>
<mount>samsung-S22-t</mount>
<cropfactor>9.85</cropfactor>
</camera>
<lens>
<maker>Samsung</maker>
<model>Samsung S22 tele</model>
<model lang="en">fixed lens</model>
<model lang="de">festes Objektiv</model>
<mount>samsung-S22-t</mount>
<type>rectilinear</type>
<cropfactor>9.85</cropfactor>
<aspect-ratio>4:3</aspect-ratio>
<calibration>
<distortion model="ptlens" focal="7.0" a="-0.008" b="0.039" c="-0.048" />
<tca model="poly3" focal="7.0" br="0.0000474" vr="0.9996693" bb="-0.0000918" vb="1.0002451" />
<vignetting model="pa" focal="7.0" aperture="2.4" distance="10" k1="-0.0629400" k2="0.0418255" k3="-0.0825312" />
<vignetting model="pa" focal="7.0" aperture="2.4" distance="1000" k1="-0.0629400" k2="0.0418255" k3="-0.0825312" />
</calibration>
</lens>
<camera>
<maker>Samsung</maker>
<model>SM-S901B-f</model>
<model lang="en">Galaxy S22 front</model>
<mount>samsung-S22-f</mount>
<cropfactor>7.57</cropfactor>
</camera>
<lens>
<maker>Samsung</maker>
<model>Samsung S22 front</model>
<model lang="en">fixed lens</model>
<model lang="de">festes Objektiv</model>
<mount>samsung-S22-f</mount>
<type>rectilinear</type>
<cropfactor>7.57</cropfactor>
<aspect-ratio>4:3</aspect-ratio>
<calibration>
<distortion model="ptlens" focal="3.3" a="-0.006" b="0.003" c="0.025" />
</calibration>
</lens>
</lensdatabase>
With these settings the correct camera will be automatically selected when doing edits in darktable.
In my workflow I use syncthing to synchronize the raws from my smartphone to my main computer. With the following two systemd services the folder is checked on the computer for changes and “ameliorates” the freshly arriving dng files.
cat /etc/systemd/system/import_dir_watch.service
[Unit]
Description=Run script when files change in /mnt/media/georg/Bilder/import/Galaxy S22
[Service]
Type=oneshot
Restart=on-failure
RestartSec=5
ExecStart=/usr/local/bin/modify_dngs.sh
# Trigger when anything in the directory changes
# PathChanged=/mnt/media/georg/Bilder/import/Galaxy S22
# or to trigger on new/removed files:
PathModified=/mnt/media/georg/Bilder/import/Galaxy S22
Unit=import_dir_watch.service
# Avoid hitting a limit caused by syncthing synchronization
TriggerLimitIntervalSec=1s
TriggerLimitBurst=100
[Install]
WantedBy=multi-user.targetx
I did a few test over the weekend it it worked quite nicely.
The issue might be of broader and growing concern as most smartphones have several cameras now and in most cases the raws will not embed the correction information. To cover smartphone raws in future it could be required to create a new format of xml which would allow the matching of smartphone and camera in one run without the necessity to manipulate the dng metadata beforehand.
Greetings!

