[libcamera-devel,7/7] qcam: dng_writer: Record camera model

Message ID 20200806130937.2991606-8-niklas.soderlund@ragnatech.se
State Accepted
Headers show
Series
  • libcamera: Allow for user-friendly names in applications
Related show

Commit Message

Niklas Söderlund Aug. 6, 2020, 1:09 p.m. UTC
Record the model property of the camera if available.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/qcam/dng_writer.cpp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

Laurent Pinchart Aug. 8, 2020, 8:27 p.m. UTC | #1
Hi Niklas,

Thank you for the patch.

On Thu, Aug 06, 2020 at 03:09:37PM +0200, Niklas Söderlund wrote:
> Record the model property of the camera if available.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
>  src/qcam/dng_writer.cpp | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp
> index b5b81f0637b545af..3556dad16fd71b64 100644
> --- a/src/qcam/dng_writer.cpp
> +++ b/src/qcam/dng_writer.cpp
> @@ -15,6 +15,7 @@
>  
>  #include <libcamera/control_ids.h>
>  #include <libcamera/formats.h>
> +#include <libcamera/property_ids.h>
>  
>  using namespace libcamera;
>  
> @@ -352,6 +353,8 @@ int DNGWriter::write(const char *filename, const Camera *camera,
>  		     const ControlList &metadata,
>  		     const FrameBuffer *buffer, const void *data)
>  {
> +	const ControlList &cameraProperties = camera->properties();
> +
>  	const auto it = formatInfo.find(config.pixelFormat);
>  	if (it == formatInfo.cend()) {
>  		std::cerr << "Unsupported pixel format" << std::endl;
> @@ -386,9 +389,13 @@ int DNGWriter::write(const char *filename, const Camera *camera,
>  	TIFFSetField(tif, TIFFTAG_DNGBACKWARDVERSION, version);
>  	TIFFSetField(tif, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
>  	TIFFSetField(tif, TIFFTAG_MAKE, "libcamera");
> -	/* \todo Report a real model string instead of id. */
> -	TIFFSetField(tif, TIFFTAG_MODEL, camera->id().c_str());
> -	TIFFSetField(tif, TIFFTAG_UNIQUECAMERAMODEL, camera->id().c_str());
> +
> +	if (cameraProperties.contains(properties::Model)) {
> +		std::string model = cameraProperties.get(properties::Model);
> +		TIFFSetField(tif, TIFFTAG_MODEL, model.c_str());
> +		TIFFSetField(tif, TIFFTAG_UNIQUECAMERAMODEL, model.c_str());
> +	}

I'll review this after the discussion on the model properties completes,
but please be already aware that these two TIFF fields are defined as
ASCII strings, not UTF-8.

> +
>  	TIFFSetField(tif, TIFFTAG_SOFTWARE, "qcam");
>  	TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
>

Patch

diff --git a/src/qcam/dng_writer.cpp b/src/qcam/dng_writer.cpp
index b5b81f0637b545af..3556dad16fd71b64 100644
--- a/src/qcam/dng_writer.cpp
+++ b/src/qcam/dng_writer.cpp
@@ -15,6 +15,7 @@ 
 
 #include <libcamera/control_ids.h>
 #include <libcamera/formats.h>
+#include <libcamera/property_ids.h>
 
 using namespace libcamera;
 
@@ -352,6 +353,8 @@  int DNGWriter::write(const char *filename, const Camera *camera,
 		     const ControlList &metadata,
 		     const FrameBuffer *buffer, const void *data)
 {
+	const ControlList &cameraProperties = camera->properties();
+
 	const auto it = formatInfo.find(config.pixelFormat);
 	if (it == formatInfo.cend()) {
 		std::cerr << "Unsupported pixel format" << std::endl;
@@ -386,9 +389,13 @@  int DNGWriter::write(const char *filename, const Camera *camera,
 	TIFFSetField(tif, TIFFTAG_DNGBACKWARDVERSION, version);
 	TIFFSetField(tif, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
 	TIFFSetField(tif, TIFFTAG_MAKE, "libcamera");
-	/* \todo Report a real model string instead of id. */
-	TIFFSetField(tif, TIFFTAG_MODEL, camera->id().c_str());
-	TIFFSetField(tif, TIFFTAG_UNIQUECAMERAMODEL, camera->id().c_str());
+
+	if (cameraProperties.contains(properties::Model)) {
+		std::string model = cameraProperties.get(properties::Model);
+		TIFFSetField(tif, TIFFTAG_MODEL, model.c_str());
+		TIFFSetField(tif, TIFFTAG_UNIQUECAMERAMODEL, model.c_str());
+	}
+
 	TIFFSetField(tif, TIFFTAG_SOFTWARE, "qcam");
 	TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);