1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 28/08/2021
* Description : Extraction of focus points by exiftool data - Nikon devices
*
* SPDX-FileCopyrightText: 2021-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
* SPDX-FileCopyrightText: 2021 by Phuoc Khanh Le <phuockhanhnk94 at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "focuspoints_extractor.h"
// Local includes
#include "digikam_debug.h"
namespace Digikam
{
// Internal function to create af point from meta data
namespace NikonInternal
{
FocusPoint create_af_point(float imageWidth,
float imageHeight,
float afPointWidth,
float afPointHeight,
float af_x_position,
float af_y_position)
{
return FocusPoint(af_x_position / imageWidth,
af_y_position / imageHeight,
afPointWidth / imageWidth,
afPointHeight / imageHeight,
FocusPoint::TypePoint::SelectedInFocus);
}
} // namespace NikonInternal
// Main function to extract af point
FocusPointsExtractor::ListAFPoints FocusPointsExtractor::getAFPoints_nikon() const
{
QString TagNameRoot = QLatin1String("MakerNotes.Nikon.Camera");
// Filter model
QString model = findValue(QLatin1String("EXIF.IFD0.Camera.Model")).toString().toLower();<--- Shadow variable
if (!model.contains(QLatin1String("nikon z"), Qt::CaseInsensitive))
{
qCDebug(DIGIKAM_METAENGINE_LOG) << "FocusPointsExtractor: unsupported Nikon Camera.";
return getAFPoints_exif();
}
// Get image size
QVariant imageWidth, imageHeight;
imageWidth = findValueFirstMatch(
QStringList()
<< QLatin1String("MakerNotes.Nikon.Camera.AFImageWidth")
<< QLatin1String("EXIF.ExifIFD.Image.ExifImageWidth")
);
imageHeight = findValueFirstMatch(
QStringList()
<< QLatin1String("MakerNotes.Nikon.Camera.AFImageHeight")
<< QLatin1String("EXIF.ExifIFD.Image.ExifImageHeight")
);
if (imageWidth.isNull() || imageHeight.isNull())
{
qCDebug(DIGIKAM_METAENGINE_LOG) << "FocusPointsExtractor: invalid Nikon image sizes.";
return getAFPoints_exif();
}
setOriginalSize(QSize(imageWidth.toInt(), imageHeight.toInt()));
if (model.compare(QLatin1String("nikon z 5"), Qt::CaseInsensitive) == 0)
{
QStringList afPointUsed = findValueFirstMatch(
QStringList()
<< QLatin1String("MakerNotes.Nikon.Camera.AFPointsUsed"),
true
).toStringList();
if (!afPointUsed.isEmpty())
{
ListAFPoints points;
float xOffset = imageWidth.toInt() / 11.5F;
float yOffset = imageHeight.toInt() / 11.0F;
float xShift = imageWidth.toInt() / 6.5F;
float yShift = imageHeight.toInt() / 7.0F;
for (const QString& np : EXIV2_AS_CONST(afPointUsed))
{
if (np.size() < 2)
{
continue;
}
float xPosition = (np.mid(1).toInt() - 1) * xOffset + xShift;
float yPosition = (np[0].unicode() - 0x41) * yOffset + yShift;
FocusPoint afpoint = NikonInternal::create_af_point(
imageWidth.toFloat(),
imageHeight.toFloat(),
xOffset - 40.0F,
yOffset - 40.0F,
xPosition,
yPosition
);
if (afpoint.getRect().isValid())
{
points << afpoint;
}
}
return points;
}
}
// Get size of point
QVariant afPointWidth = findValue(TagNameRoot, QLatin1String("AFAreaWidth"));
QVariant afPointHeight = findValue(TagNameRoot, QLatin1String("AFAreaHeight"));
if ((afPointWidth.isNull()) || (afPointHeight.isNull()))
{
qCDebug(DIGIKAM_METAENGINE_LOG) << "FocusPointsExtractor: invalid sizes from Nikon makernotes.";
return getAFPoints_exif();
}
// Get coordinate of af points
QVariant af_x_position = findValue(TagNameRoot, QLatin1String("AFAreaXPosition"));
QVariant af_y_position = findValue(TagNameRoot, QLatin1String("AFAreaYPosition"));
if (af_x_position.isNull() || af_y_position.isNull())
{
qCDebug(DIGIKAM_METAENGINE_LOG) << "FocusPointsExtractor: invalid positions from Nikon makernotes.";
return getAFPoints_exif();
}
qCDebug(DIGIKAM_METAENGINE_LOG) << "FocusPointsExtractor: Nikon Makernotes Focus Location:" << af_x_position
<< af_y_position
<< afPointWidth
<< afPointHeight;
ListAFPoints points;
FocusPoint afpoint = NikonInternal::create_af_point(
imageWidth.toFloat(),
imageHeight.toFloat(),
afPointWidth.toFloat(),
afPointHeight.toFloat(),
af_x_position.toFloat(),
af_y_position.toFloat()
);
if (afpoint.getRect().isValid())
{
points << afpoint;
}
return points;
}
} // namspace Digikam
|