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 - Sony 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 = 120; // this is a guess
0026 
0027 // Internal function to create af point from meta data
0028 namespace SonyInternal
0029 {
0030 
0031 FocusPoint create_af_point(float imageWidth,
0032                            float imageHeight,
0033                            float afPointWidth,
0034                            float afPointHeight,
0035                            float af_x_position,
0036                            float af_y_position)
0037 {
0038     return FocusPoint(af_x_position / imageWidth,
0039                       af_y_position / imageHeight,
0040                       afPointWidth,
0041                       afPointHeight,
0042                       FocusPoint::TypePoint::SelectedInFocus);
0043 }
0044 
0045 } // namespace SonyInternal
0046 
0047 // Main function to extract af point
0048 FocusPointsExtractor::ListAFPoints FocusPointsExtractor::getAFPoints_sony() const
0049 {
0050     QString TagNameRoot = QLatin1String("MakerNotes.Sony.Camera");
0051 
0052     QStringList af_info = findValue(TagNameRoot, QLatin1String("FocusLocation")).toString().split(QLatin1String(" "));
0053 
0054     if (af_info.size() < 5)
0055     {
0056         qCDebug(DIGIKAM_METAENGINE_LOG) << "FocusPointsExtractor: Unsupported Sony Camera.";
0057 
0058         return getAFPoints_exif();
0059     }
0060 
0061     qCDebug(DIGIKAM_METAENGINE_LOG) << "FocusPointsExtractor: Sony Makernotes Focus Location:" << af_info;
0062 
0063     // Get size image
0064 
0065     float afImageWidth  = af_info[0].toFloat();
0066     float afImageHeight = af_info[1].toFloat();
0067 
0068     // Get size of af points
0069 
0070     float afPointWidth  = afImageWidth  * RATIO_POINT_IMAGE;
0071     float afPointHeight = afImageHeight * RATIO_POINT_IMAGE;
0072 
0073     // Get coordinate of af points
0074 
0075     float af_x_position = af_info[3].toFloat();
0076     float af_y_position = af_info[4].toFloat();
0077 
0078     ListAFPoints points;
0079     FocusPoint afpoint  = SonyInternal::create_af_point(
0080                                                         afImageWidth,
0081                                                         afImageHeight,
0082                                                         afPointWidth,
0083                                                         afPointHeight,
0084                                                         af_x_position,
0085                                                         af_y_position
0086                                                        );
0087 
0088     if (afpoint.getRect().isValid())
0089     {
0090         points << afpoint;
0091     }
0092 
0093     return points;
0094 }
0095 
0096 } // namespace Digikam