File indexing completed on 2025-01-05 03:56:31

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 28/08/2021
0007  * Description : Extraction of focus points by exiftool data - Panasonic devices
0008  *
0009  * SPDX-FileCopyrightText: 2021-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2021 by Phuoc Khanh Le <phuockhanhnk94 at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "focuspoints_extractor.h"
0017 
0018 // Local includes
0019 
0020 #include "digikam_debug.h"
0021 
0022 namespace Digikam
0023 {
0024 
0025 const float RATIO_POINT_IMAGE = 1 / 120; // this is a guess
0026 
0027 // Internal function to create af point from meta data
0028 namespace PanasonicInternal
0029 {
0030 
0031 FocusPoint create_af_point(float af_x_position,
0032                            float af_y_position,
0033                            float afPointWidth,
0034                            float afPointHeight)
0035 {
0036     return FocusPoint(af_x_position,
0037                       af_y_position,
0038                       afPointWidth  * RATIO_POINT_IMAGE,
0039                       afPointHeight * RATIO_POINT_IMAGE,
0040                       FocusPoint::TypePoint::SelectedInFocus);
0041 }
0042 
0043 } // namespace PanasonicInternal
0044 
0045 FocusPointsExtractor::ListAFPoints FocusPointsExtractor::getAFPoints_panasonic() const
0046 {
0047     QString TagNameRoot     = QLatin1String("MakerNotes.Panasonic.Camera");
0048 
0049     // Get size image
0050 
0051     QVariant imageWidth     = findValue(QLatin1String("File.File.Image.ImageWidth"));
0052     QVariant imageHeight    = findValue(QLatin1String("File.File.Image.ImageHeight"));
0053 
0054     if (imageWidth.isNull() || imageHeight.isNull())
0055     {
0056         qCDebug(DIGIKAM_METAENGINE_LOG) << "FocusPointsExtractor: invalid Panasonic image sizes.";
0057 
0058         return getAFPoints_exif();
0059     }
0060 
0061     setOriginalSize(QSize(imageWidth.toInt(), imageHeight.toInt()));
0062 
0063     // Get af point
0064 
0065     QStringList af_position = findValue(TagNameRoot, QLatin1String("AFPointPosition")).toString().split(QLatin1String(" "));
0066 
0067     if (af_position.isEmpty() || (af_position.count() == 1))
0068     {
0069         qCDebug(DIGIKAM_METAENGINE_LOG) << "FocusPointsExtractor: invalid positions from Panasonic makernotes.";
0070 
0071         return getAFPoints_exif();
0072     }
0073 
0074     qCDebug(DIGIKAM_METAENGINE_LOG) << "FocusPointsExtractor: Panasonic Makernotes Focus Location:" << af_position;
0075 
0076     float af_x_position = af_position[0].toFloat();
0077     float af_y_position = af_position[1].toFloat();
0078 
0079     // Get size of af points
0080 
0081     float afPointWidth  = imageWidth.toFloat()  * RATIO_POINT_IMAGE;
0082     float afPointHeight = imageHeight.toFloat() * RATIO_POINT_IMAGE;
0083 
0084     // Add point
0085 
0086     ListAFPoints points;
0087     FocusPoint afpoint  = PanasonicInternal::create_af_point(
0088                                                              af_x_position,
0089                                                              af_y_position,
0090                                                              afPointWidth,
0091                                                              afPointHeight
0092                                                             );
0093 
0094     if (afpoint.getRect().isValid())
0095     {
0096         points << afpoint;
0097     }
0098 
0099     return points;
0100 }
0101 
0102 } // namespace Digikam