[libcamera-devel] [PATCH] qcam: dng_writer: Record creation time in the EXIF directory

Laurent Pinchart laurent.pinchart at ideasonboard.com
Thu Jun 11 20:46:57 CEST 2020


Hi Niklas,

On Thu, Jun 11, 2020 at 08:37:25PM +0200, Niklas Söderlund wrote:
> On 2020-06-11 05:47:52 +0300, Laurent Pinchart wrote:
> > On Thu, Jun 11, 2020 at 03:46:14AM +0200, Niklas Söderlund wrote:
> > > If the EXIF directory is empty due to no metadata being available tools
> > > such as tiffinfo complains that the directory is malformed.
> > > 
> > >     TIFFFetchDirectory: Sanity check on directory count failed, this is probably not a valid IFD offset.
> > >     TIFFReadCustomDirectory: Failed to read custom directory at offset 0.
> > > 
> > > Always record the creation time in the EXIF directory instead of adding
> > > complexity to skip creating the EXIF directory if there is no metadata
> > > to record. This ensures there are at least one entry in the EXIF
> > > directory and that makes tiffinfo happy.
> > > 
> > > Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
> > > ---
> > >  src/qcam/dng_writer.cpp | 11 +++++++++++
> > >  1 file changed, 11 insertions(+)
> > > 
> > > diff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp
> > > index 330b169af25b7ac7..c1c3833740d96630 100644
> > > --- a/src/qcam/dng_writer.cpp
> > > +++ b/src/qcam/dng_writer.cpp
> > > @@ -426,6 +426,17 @@ int DNGWriter::write(const char *filename, const Camera *camera,
> > >  	/* Create a new IFD for the EXIF data and fill it. */
> > >  	TIFFCreateEXIFDirectory(tif);
> > >  
> > > +	/* Store creation time. */
> > > +	time_t rawtime;
> > > +	struct tm *timeinfo;
> > > +	char strTime[20];
> > > +
> > > +	time(&rawtime);
> > 
> > Could we use the timestamp from the buffer instead ?
> 
> We can't as the timestamp in the buffer is copied from the v4l2 buffer 
> and not guaranteed to be an offset from the epoch.

So how do we fix that ? :-) It's not a prerequisite for this patch, but
it seems to me that the problem needs to be addressed. We should also
add a \todo here to mention that the timestamp should come from the
buffer.

> > > +	timeinfo = localtime(&rawtime);
> > > +	strftime(strTime, 20, "%Y:%m:%d %H:%M:%S", timeinfo);
> > 
> > How are time zones supposed to be handled ?
> 
> The documentation states noting about timezones so I think the best 
> option is the use the local timezone of the device running qcam.

How about the OffsetTime, OffsetTimeOriginal and OffsetTimeDigitized
tags ?

> > > +
> > > +	TIFFSetField(tif, EXIFTAG_DATETIMEDIGITIZED, strTime);
> > 
> > Should we also set EXIFTAG_DATETIMEORIGINAL to the same value ?
> 
> We should will send a v2.
> 
> > > +
> > >  	if (metadata.contains(controls::AnalogueGain)) {
> > >  		float gain = metadata.get(controls::AnalogueGain);
> > >  		uint16_t iso = std::min(std::max(gain * 100, 0.0f), 65535.0f);

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list