Skip to content

Commit 77a03d9

Browse files
njhollinghurstnaushir
authored andcommitted
image: Add Subject Distance to EXIF data, to encode Lens Position
This is the only bit of AF metadata that seems to match a standard Exif tag. [XXX Because of numerical/API differences, the JPEG and DNG versions can encode slightly different values.] Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
1 parent eca5a3c commit 77a03d9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

image/dng.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* dng.cpp - Save raw image as DNG file.
66
*/
77

8+
#include <limits>
89
#include <map>
910

1011
#include <libcamera/control_ids.h>
@@ -314,6 +315,13 @@ void dng_save(std::vector<libcamera::Span<uint8_t>> const &mem, StreamInfo const
314315
TIFFSetField(tif, EXIFTAG_ISOSPEEDRATINGS, 1, &iso);
315316
TIFFSetField(tif, EXIFTAG_EXPOSURETIME, exp_time);
316317

318+
auto lp = metadata.get(libcamera::controls::LensPosition);
319+
if (lp)
320+
{
321+
double dist = (*lp > 0.0) ? (1.0 / *lp) : std::numeric_limits<double>::infinity();
322+
TIFFSetField(tif, EXIFTAG_SUBJECTDISTANCE, dist);
323+
}
324+
317325
TIFFCheckpointDirectory(tif);
318326
offset_exififd = TIFFCurrentDirOffset(tif);
319327
TIFFWriteDirectory(tif);

image/jpeg.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,13 @@ static void create_exif_data(std::vector<libcamera::Span<uint8_t>> const &mem,
488488
LOG(2, "Ag " << *ag << " Dg " << *dg << " Total " << gain);
489489
exif_set_short(entry->data, exif_byte_order, 100 * gain);
490490
}
491+
auto lp = metadata.get(libcamera::controls::LensPosition);
492+
if (lp)
493+
{
494+
entry = exif_create_tag(exif, EXIF_IFD_EXIF, EXIF_TAG_SUBJECT_DISTANCE);
495+
ExifRational dist = { 1000, (ExifLong)(1000.0 * *lp) };
496+
exif_set_rational(entry->data, exif_byte_order, dist);
497+
}
491498

492499
// Command-line supplied tags.
493500
for (auto &exif_item : options->exif)

0 commit comments

Comments
 (0)